InputInfoController.java 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. package com.fjs.scenic.controller.system;
  2. import cn.hutool.core.util.ObjectUtil;
  3. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  4. import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
  5. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  6. import com.fjs.scenic.controller.common.BaseController;
  7. import com.fjs.scenic.dto.InputInfoDto;
  8. import com.fjs.scenic.dto.InputInfoPageParam;
  9. import com.fjs.scenic.entity.system.InpIncome;
  10. import com.fjs.scenic.entity.system.InputInfo;
  11. import com.fjs.scenic.entity.system.Manage;
  12. import com.fjs.scenic.entity.system.TypeAuthority;
  13. import com.fjs.scenic.service.system.InpIncomeService;
  14. import com.fjs.scenic.service.system.InputInfoService;
  15. import com.fjs.scenic.service.system.TypeAuthorityService;
  16. import com.fjs.scenic.service.system.impl.ManageServiceImpl;
  17. import com.fjs.scenic.utils.Cons;
  18. import com.fjs.scenic.utils.ReturnResult;
  19. import org.springframework.beans.factory.annotation.Autowired;
  20. import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
  21. import org.springframework.transaction.annotation.Transactional;
  22. import org.springframework.util.Assert;
  23. import org.springframework.util.StringUtils;
  24. import org.springframework.web.bind.annotation.*;
  25. import org.springframework.web.servlet.ModelAndView;
  26. import javax.servlet.http.HttpServletRequest;
  27. import javax.servlet.http.HttpSession;
  28. import javax.validation.Valid;
  29. import java.security.Principal;
  30. import java.time.LocalDate;
  31. import java.util.Date;
  32. import java.util.List;
  33. import java.util.stream.Collectors;
  34. /**
  35. * This class is used for ...
  36. *
  37. * @author lfj
  38. * @version 1.0
  39. * @CreateDate ${date} ${time}
  40. */
  41. @RestController
  42. @RequestMapping("/inputInfo")
  43. public class InputInfoController {
  44. @Autowired
  45. private InputInfoService inputInfoService;
  46. @Autowired
  47. private InpIncomeService inpIncomeService;
  48. @Autowired
  49. private ManageServiceImpl manageService;
  50. @Autowired
  51. private TypeAuthorityService typeAuthorityService;
  52. @GetMapping("/index")
  53. public ModelAndView sceniclist() {
  54. return new ModelAndView("system/inputInfo");
  55. }
  56. @PostMapping("/add")
  57. @Transactional(rollbackFor = Exception.class)
  58. public ReturnResult add(@Valid @RequestBody List<InputInfoDto> inputInfoDtos, Principal principal) {
  59. String account = principal.getName();
  60. Manage manage = manageService.getMangerByAccount(account);
  61. for (InputInfoDto inputInfoDto : inputInfoDtos) {
  62. inputInfoDto.setCreateTime(LocalDate.now());
  63. inputInfoDto.setManager(manage.getName());
  64. int sum = inputInfoService.count(new LambdaQueryWrapper<InputInfo>()
  65. .eq(InputInfo::getStaticDate, inputInfoDto.getStaticDate())
  66. .eq(InputInfo::getScenic, inputInfoDto.getScenic()));
  67. Assert.isTrue(sum == 0, "请勿重复添加");
  68. inputInfoService.save(inputInfoDto);
  69. if (inputInfoDto.getIncome() != null) {
  70. for (InpIncome inpIncome : inputInfoDto.getIncome()) {
  71. inpIncome.setInputInfoId(inputInfoDto.getId());
  72. inpIncomeService.save(inpIncome);
  73. }
  74. }
  75. }
  76. return ReturnResult.ok();
  77. }
  78. @PostMapping("/edit")
  79. @Transactional(rollbackFor = Exception.class)
  80. public ReturnResult edit(@RequestBody List<InputInfoDto> inputInfoDtos) {
  81. InputInfoDto inputInfoDto = inputInfoDtos.get(0);
  82. inputInfoService.updateById(inputInfoDto);
  83. if (inputInfoDto.getIncome() != null) {
  84. inpIncomeService.updateBatchById(inputInfoDto.getIncome());
  85. }
  86. return ReturnResult.ok();
  87. }
  88. @PostMapping("/page")
  89. public ReturnResult page(@RequestBody InputInfoPageParam param) {
  90. return ReturnResult.ok(inputInfoService
  91. .page(new Page<>(param.getCurrentPage(), param.getPageSize()), new LambdaQueryWrapper<InputInfo>()
  92. .gt(ObjectUtil.isNotEmpty(param.getStartCreateTime()), InputInfo::getCreateTime, param.getStartCreateTime())
  93. .le(ObjectUtil.isNotEmpty(param.getEndtCreateTime()), InputInfo::getCreateTime, param.getEndtCreateTime())
  94. .gt(ObjectUtil.isNotEmpty(param.getStartStaticDate()), InputInfo::getStaticDate, param.getStartStaticDate())
  95. .le(ObjectUtil.isNotEmpty(param.getEndStaticDate()), InputInfo::getStaticDate, param.getEndStaticDate())
  96. .in(ObjectUtil.isNotEmpty(param.getScenics()), InputInfo::getScenic, param.getScenics())
  97. .eq(ObjectUtil.isNotEmpty(param.getManager()), InputInfo::getManager, param.getManager())
  98. )
  99. );
  100. }
  101. @PostMapping("/del")
  102. @ResponseBody
  103. public ReturnResult del(int id) {
  104. inpIncomeService.remove(new LambdaQueryWrapper<InpIncome>().eq(InpIncome::getInputInfoId, id));
  105. return ReturnResult.ok(inputInfoService.removeById(id));
  106. }
  107. @PostMapping("/getTypeAuthority")
  108. public ReturnResult getTypeAuthority(Principal principal) {
  109. String account = principal.getName();
  110. Manage manage = manageService.getMangerByAccount(account);
  111. List<TypeAuthority> typeAuthorities = typeAuthorityService.list(new LambdaQueryWrapper<TypeAuthority>()
  112. .eq(TypeAuthority::getManager, manage.getId())
  113. .eq(TypeAuthority::getAuthority, Cons.TYPE_AUTHORITY.ALL));
  114. if (typeAuthorities.isEmpty()) {
  115. return ReturnResult.ok();
  116. }
  117. return ReturnResult.ok(typeAuthorities.stream().map(TypeAuthority::getScenic).collect(Collectors.toList()));
  118. }
  119. /**
  120. * 获取 income
  121. *
  122. * @param id
  123. * @return
  124. */
  125. @PostMapping("/get")
  126. public ReturnResult get(Integer id) {
  127. return ReturnResult.ok(inpIncomeService.list(new LambdaQueryWrapper<InpIncome>().eq(InpIncome::getInputInfoId, id)));
  128. }
  129. }