PolicyStriveController.java 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. package com.qdport.controller;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONArray;
  4. import com.alibaba.fastjson.JSONObject;
  5. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  6. import com.qdport.entity.PolicyTodo;
  7. import com.qdport.enums.QDPortEnum;
  8. import com.qdport.modules.system.entity.SysUser;
  9. import com.qdport.modules.system.service.TSysUserService;
  10. import com.qdport.service.PolicyFileService;
  11. import com.qdport.service.PolicyTodoService;
  12. import com.qdport.service.impl.PolicySystemService;
  13. import com.qdport.util.StringUtil;
  14. import com.qdport.vo.PolicyFileVO;
  15. import lombok.AllArgsConstructor;
  16. import com.qdport.entity.PolicyStrive;
  17. import com.qdport.service.PolicyStriveService;
  18. import com.qdport.query.PolicyStriveQuery;
  19. import com.qdport.vo.PolicyStriveVO;
  20. import com.qdport.wrapper.PolicyStriveWrapper;
  21. import org.springframework.transaction.annotation.Transactional;
  22. import org.springframework.web.bind.annotation.*;
  23. import io.swagger.annotations.Api;
  24. import io.swagger.annotations.ApiOperation;
  25. import io.swagger.annotations.ApiParam;
  26. import com.qdport.core.tool.api.R;
  27. import com.qdport.core.tool.utils.Func;
  28. import com.qdport.core.boot.ctrl.QdportController;
  29. import com.baomidou.mybatisplus.core.metadata.IPage;
  30. import javax.validation.Valid;
  31. import java.math.BigDecimal;
  32. import java.math.RoundingMode;
  33. import java.util.Date;
  34. import java.util.List;
  35. import java.util.Map;
  36. /**
  37. * 政策争取
  38. *
  39. * @author yuheng
  40. * @since 1.0.0 2024-10-14
  41. */
  42. @RestController
  43. @RequestMapping("qdport-zcgx/strive")
  44. @Api(value = "政策争取", tags = "政策争取")
  45. @AllArgsConstructor
  46. public class PolicyStriveController extends QdportController {
  47. private final PolicyStriveService policyStriveService;
  48. private final TSysUserService sysUserService;
  49. private final PolicySystemService policySystemService;
  50. private final PolicyFileService policyFileService;
  51. private final PolicyTodoService policyTodoService;
  52. /**
  53. * 分页
  54. */
  55. @GetMapping("page")
  56. @ApiOperation(value = "分页", notes = "分页")
  57. public R<IPage<PolicyStriveVO>> page(@Valid PolicyStriveQuery query) {
  58. IPage<PolicyStriveVO> page = policyStriveService.page(query);
  59. List<PolicyStriveVO> records = page.getRecords();
  60. for (PolicyStriveVO model : records) {
  61. SysUser createUser = sysUserService.getById(model.getCreateId());
  62. Map<String, String> resultMap = policySystemService.getDeptNameAndCompanyName(createUser.getDeptId());
  63. model.setDeptName(resultMap.get("deptName"));
  64. model.setCompanyName(resultMap.get("companyName"));
  65. List<PolicyFileVO> fileList = policyFileService.getFileList(model.getId().toString(), QDPortEnum.POLICY_FILE_REFTYPE_POLICY_STRIVE.getValue());
  66. model.setFileList(fileList);
  67. }
  68. return R.data(page);
  69. }
  70. /**
  71. * 详情
  72. */
  73. @GetMapping("{id}")
  74. @ApiOperation(value = "详情", notes = "id")
  75. public R<PolicyStriveVO> get(@PathVariable("id") Long id) {
  76. PolicyStrive entity = policyStriveService.getById(id);
  77. PolicyStriveVO vo = PolicyStriveWrapper.build().entityVO(entity);
  78. SysUser createUser = sysUserService.getById(entity.getCreateId());
  79. Map<String, String> resultMap = policySystemService.getDeptNameAndCompanyName(createUser.getDeptId());
  80. vo.setDeptName(resultMap.get("deptName"));
  81. vo.setCompanyName(resultMap.get("companyName"));
  82. List<PolicyFileVO> fileList = policyFileService.getFileList(entity.getId().toString(), QDPortEnum.POLICY_FILE_REFTYPE_POLICY_STRIVE.getValue());
  83. vo.setFileList(fileList);
  84. return R.data(vo);
  85. }
  86. /**
  87. * 新增
  88. */
  89. @PostMapping("/save")
  90. @ApiOperation(value = "新增", notes = "传入PolicyStrive")
  91. @Transactional(rollbackFor = Exception.class)
  92. public R save(@RequestBody PolicyStriveVO vo) {
  93. vo.setStatus(QDPortEnum.POLICY_STRIVE_STATUS_ACTIVE.getValue());
  94. policyStriveService.save(vo);
  95. return R.success("保存成功");
  96. }
  97. @PostMapping("/saveDone")
  98. @ApiOperation(value = "新增", notes = "传入PolicyStrive")
  99. @Transactional(rollbackFor = Exception.class)
  100. public R saveDone(@RequestBody PolicyStriveVO vo) {
  101. vo.setStatus(QDPortEnum.POLICY_STRIVE_STATUS_DONE.getValue());
  102. policyStriveService.save(vo);
  103. return R.success("保存成功");
  104. }
  105. @PostMapping("/saveApprove")
  106. @ApiOperation(value = "新增并且提交", notes = "传入PolicyStrive")
  107. @Transactional(rollbackFor = Exception.class)
  108. public R saveApprove(@RequestBody PolicyStriveVO vo) {
  109. if (StringUtil.isEmpty(vo.getId())) {
  110. vo.setStatus(QDPortEnum.POLICY_STRIVE_STATUS_APPROVE.getValue());
  111. policyStriveService.save(vo);
  112. } else {
  113. vo.setStatus(QDPortEnum.POLICY_STRIVE_STATUS_APPROVE.getValue());
  114. policyStriveService.update(vo);
  115. }
  116. policyTodoService.save(vo);
  117. return R.success("新增并且提交成功");
  118. }
  119. /**
  120. * 修改
  121. */
  122. @PostMapping("/update")
  123. public R update(@RequestBody @Valid PolicyStriveVO vo) {
  124. policyStriveService.update(vo);
  125. return R.success("更新成功");
  126. }
  127. @PostMapping("/updateById")
  128. @ApiOperation(value = "月度维护、奖励分配", notes = "传入PolicyStrive")
  129. public R updateById(@RequestBody @Valid PolicyStriveVO vo) {
  130. if (vo.getIsReward() == 1) {
  131. String partPersonArr = vo.getPartPersonArr();
  132. JSONArray array = JSON.parseArray(partPersonArr);
  133. BigDecimal total = BigDecimal.ZERO;
  134. for (Object object : array) {
  135. JSONObject obj = (JSONObject) object;
  136. BigDecimal reward = obj.getBigDecimal("reward");
  137. if (StringUtil.isEmpty(reward)) {
  138. continue;
  139. }
  140. total = total.add(reward);
  141. }
  142. if (vo.getRewardScore().compareTo(total) < 0) {
  143. return R.fail("分配总金额超出奖励标准");
  144. }
  145. }
  146. policyStriveService.updateById(vo);
  147. return R.success("更新成功");
  148. }
  149. @PostMapping("/withdraw")
  150. @Transactional(rollbackFor = Exception.class)
  151. public R withdraw(@RequestBody @Valid PolicyStriveVO vo) {
  152. vo.setStatus(QDPortEnum.POLICY_STRIVE_STATUS_ACTIVE.getValue());
  153. vo.setUpdateTime(new Date());
  154. policyStriveService.updateById(vo);
  155. QueryWrapper<PolicyTodo> todoQueryWrapper = new QueryWrapper<>();
  156. todoQueryWrapper.eq("REF_ID", vo.getId());
  157. todoQueryWrapper.eq("REF_TYPE", QDPortEnum.POLICY_TODO_REFTYPE_POLICY_STRIVE.getValue());
  158. todoQueryWrapper.eq("TODO_USER_ID", 1);
  159. todoQueryWrapper.eq("TODO_TYPE", QDPortEnum.POLICY_TODO_TYPE_APPROVE.getValue());
  160. todoQueryWrapper.eq("STATUS", QDPortEnum.POLICY_TODO_STATUS_ACTIVE.getValue());
  161. PolicyTodo todo = new PolicyTodo();
  162. todo.setStatus(QDPortEnum.POLICY_TODO_STATUS_CANCEL.getValue());
  163. policyTodoService.update(todo, todoQueryWrapper);
  164. return R.success("撤回成功");
  165. }
  166. @PostMapping("/approve")
  167. @Transactional(rollbackFor = Exception.class)
  168. public R approve(@RequestBody @Valid PolicyStriveVO vo) {
  169. vo.setStatus(QDPortEnum.POLICY_STRIVE_STATUS_DONE.getValue());
  170. vo.setUpdateTime(new Date());
  171. policyStriveService.updateById(vo);
  172. QueryWrapper<PolicyTodo> todoQueryWrapper = new QueryWrapper<>();
  173. todoQueryWrapper.eq("REF_ID", vo.getId());
  174. todoQueryWrapper.eq("REF_TYPE", QDPortEnum.POLICY_TODO_REFTYPE_POLICY_STRIVE.getValue());
  175. todoQueryWrapper.eq("TODO_USER_ID", 1);
  176. todoQueryWrapper.eq("TODO_TYPE", QDPortEnum.POLICY_TODO_TYPE_APPROVE.getValue());
  177. todoQueryWrapper.eq("STATUS", QDPortEnum.POLICY_TODO_STATUS_ACTIVE.getValue());
  178. PolicyTodo todo = new PolicyTodo();
  179. todo.setStatus(QDPortEnum.POLICY_TODO_STATUS_DONE.getValue());
  180. policyTodoService.update(todo, todoQueryWrapper);
  181. return R.success("更新成功");
  182. }
  183. @PostMapping("/refuse")
  184. @Transactional(rollbackFor = Exception.class)
  185. public R refuse(@RequestBody @Valid PolicyStriveVO vo) {
  186. vo.setStatus(QDPortEnum.POLICY_STRIVE_STATUS_INACTIVE.getValue());
  187. vo.setUpdateTime(new Date());
  188. policyStriveService.updateById(vo);
  189. QueryWrapper<PolicyTodo> todoQueryWrapper = new QueryWrapper<>();
  190. todoQueryWrapper.eq("REF_ID", vo.getId());
  191. todoQueryWrapper.eq("REF_TYPE", QDPortEnum.POLICY_TODO_REFTYPE_POLICY_STRIVE.getValue());
  192. todoQueryWrapper.eq("TODO_USER_ID", 1);
  193. todoQueryWrapper.eq("TODO_TYPE", QDPortEnum.POLICY_TODO_TYPE_APPROVE.getValue());
  194. todoQueryWrapper.eq("STATUS", QDPortEnum.POLICY_TODO_STATUS_ACTIVE.getValue());
  195. PolicyTodo todo = new PolicyTodo();
  196. todo.setStatus(QDPortEnum.POLICY_TODO_STATUS_DONE.getValue());
  197. policyTodoService.update(todo, todoQueryWrapper);
  198. return R.success("更新成功");
  199. }
  200. /**
  201. * 删除
  202. */
  203. @PostMapping("/remove")
  204. @ApiOperation(value = "逻辑删除", notes = "传入ids")
  205. public R delete(@ApiParam(value = "主键集合", required = true) @RequestParam(name = "ids") String ids) {
  206. List<Long> idList = Func.toLongList(ids);
  207. policyStriveService.delete(idList);
  208. return R.success("删除成功");
  209. }
  210. @PostMapping("/calculate")
  211. public R calculate(@RequestBody @Valid PolicyStriveVO vo) {
  212. BigDecimal rewardRadix = vo.getRewardRadix();
  213. BigDecimal implementScore = vo.getImplementScore();
  214. BigDecimal promotionScore = vo.getPromotionScore();
  215. BigDecimal striveScore = vo.getStriveScore();
  216. BigDecimal number = rewardRadix.multiply(implementScore)
  217. .multiply(promotionScore).multiply(striveScore).setScale(2, RoundingMode.HALF_UP);
  218. return R.data(number);
  219. }
  220. }