PolicyCaseController.java 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. package com.qdport.controller;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.qdport.entity.PolicyStrive;
  4. import com.qdport.entity.PolicyTodo;
  5. import com.qdport.enums.QDPortEnum;
  6. import com.qdport.modules.system.entity.SysUser;
  7. import com.qdport.modules.system.service.TSysUserService;
  8. import com.qdport.service.PolicyFileService;
  9. import com.qdport.service.PolicyStriveService;
  10. import com.qdport.service.PolicyTodoService;
  11. import com.qdport.service.impl.PolicySystemService;
  12. import com.qdport.util.StringUtil;
  13. import com.qdport.vo.PolicyFileVO;
  14. import lombok.AllArgsConstructor;
  15. import com.qdport.entity.PolicyCase;
  16. import com.qdport.service.PolicyCaseService;
  17. import com.qdport.query.PolicyCaseQuery;
  18. import com.qdport.vo.PolicyCaseVO;
  19. import com.qdport.wrapper.PolicyCaseWrapper;
  20. import org.springframework.transaction.annotation.Transactional;
  21. import org.springframework.web.bind.annotation.*;
  22. import io.swagger.annotations.Api;
  23. import io.swagger.annotations.ApiOperation;
  24. import io.swagger.annotations.ApiParam;
  25. import com.qdport.core.tool.api.R;
  26. import com.qdport.core.tool.utils.Func;
  27. import com.qdport.core.boot.ctrl.QdportController;
  28. import com.baomidou.mybatisplus.core.metadata.IPage;
  29. import javax.validation.Valid;
  30. import java.util.Date;
  31. import java.util.List;
  32. import java.util.Map;
  33. /**
  34. * 案例分享
  35. *
  36. * @author yuheng
  37. * @since 1.0.0 2024-10-17
  38. */
  39. @RestController
  40. @RequestMapping("qdport-zcgx/case")
  41. @Api(value = "案例分享", tags = "案例分享")
  42. @AllArgsConstructor
  43. public class PolicyCaseController extends QdportController {
  44. private final PolicyCaseService policyCaseService;
  45. private final TSysUserService sysUserService;
  46. private final PolicySystemService policySystemService;
  47. private final PolicyFileService policyFileService;
  48. private final PolicyTodoService policyTodoService;
  49. private final PolicyStriveService policyStriveService;
  50. /**
  51. * 分页
  52. */
  53. @GetMapping("page")
  54. @ApiOperation(value = "分页", notes = "分页")
  55. public R<IPage<PolicyCaseVO>> page(@Valid PolicyCaseQuery query){
  56. IPage<PolicyCaseVO> page = policyCaseService.page(query);
  57. List<PolicyCaseVO> records = page.getRecords();
  58. for (PolicyCaseVO model : records) {
  59. SysUser createUser = sysUserService.getById(model.getCreateId());
  60. Map<String, String> resultMap = policySystemService.getDeptNameAndCompanyName(createUser.getDeptId());
  61. model.setDeptName(resultMap.get("deptName"));
  62. model.setCompanyName(resultMap.get("companyName"));
  63. List<PolicyFileVO> fileList = policyFileService.getFileList(model.getId().toString(), QDPortEnum.POLICY_FILE_REFTYPE_POLICY_STRIVE.getValue());
  64. model.setFileList(fileList);
  65. PolicyStrive strive = policyStriveService.getById(model.getStriveId());
  66. model.setPolicyStrive(strive);
  67. }
  68. return R.data(page);
  69. }
  70. /**
  71. * 详情
  72. */
  73. @GetMapping("{id}")
  74. @ApiOperation(value = "详情", notes = "id")
  75. public R<PolicyCaseVO> get(@PathVariable("id") Long id){
  76. PolicyCase entity = policyCaseService.getById(id);
  77. PolicyCaseVO vo = PolicyCaseWrapper.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 = "传入PolicyCase")
  91. public R save(@RequestBody PolicyCaseVO vo){
  92. vo.setStatus(QDPortEnum.POLICY_CASE_STATUS_ACTIVE.getValue());
  93. policyCaseService.save(vo);
  94. return R.success("保存成功");
  95. }
  96. @PostMapping("/saveDone")
  97. @ApiOperation(value = "新增", notes = "传入PolicyStrive")
  98. @Transactional(rollbackFor = Exception.class)
  99. public R saveDone(@RequestBody PolicyCaseVO vo) {
  100. vo.setStatus(QDPortEnum.POLICY_CASE_STATUS_DONE.getValue());
  101. policyCaseService.save(vo);
  102. return R.success("保存成功");
  103. }
  104. @PostMapping("/saveApprove")
  105. @ApiOperation(value = "新增并且提交", notes = "传入PolicyStrive")
  106. @Transactional(rollbackFor = Exception.class)
  107. public R saveApprove(@RequestBody PolicyCaseVO vo) {
  108. if (StringUtil.isEmpty(vo.getId())) {
  109. vo.setStatus(QDPortEnum.POLICY_CASE_STATUS_APPROVE.getValue());
  110. policyCaseService.save(vo);
  111. } else {
  112. vo.setStatus(QDPortEnum.POLICY_CASE_STATUS_APPROVE.getValue());
  113. policyCaseService.update(vo);
  114. }
  115. PolicyStrive strive = policyStriveService.getById(vo.getStriveId());
  116. vo.setPolicyStrive(strive);
  117. policyTodoService.save(vo);
  118. return R.success("新增并且提交成功");
  119. }
  120. /**
  121. * 修改
  122. */
  123. @PostMapping("/update")
  124. public R update(@RequestBody @Valid PolicyCaseVO vo){
  125. policyCaseService.update(vo);
  126. return R.success("更新成功");
  127. }
  128. @PostMapping("/withdraw")
  129. @Transactional(rollbackFor = Exception.class)
  130. public R withdraw(@RequestBody @Valid PolicyCaseVO vo) {
  131. vo.setStatus(QDPortEnum.POLICY_CASE_STATUS_ACTIVE.getValue());
  132. vo.setUpdateTime(new Date());
  133. policyCaseService.updateById(vo);
  134. QueryWrapper<PolicyTodo> todoQueryWrapper = new QueryWrapper<>();
  135. todoQueryWrapper.eq("REF_ID", vo.getId());
  136. todoQueryWrapper.eq("REF_TYPE", QDPortEnum.POLICY_TODO_REFTYPE_POLICY_CASE.getValue());
  137. todoQueryWrapper.eq("TODO_USER_ID", 1);
  138. todoQueryWrapper.eq("TODO_TYPE", QDPortEnum.POLICY_TODO_TYPE_APPROVE.getValue());
  139. todoQueryWrapper.eq("STATUS", QDPortEnum.POLICY_TODO_STATUS_ACTIVE.getValue());
  140. PolicyTodo todo = new PolicyTodo();
  141. todo.setStatus(QDPortEnum.POLICY_TODO_STATUS_CANCEL.getValue());
  142. policyTodoService.update(todo, todoQueryWrapper);
  143. return R.success("撤回成功");
  144. }
  145. @PostMapping("/approve")
  146. @Transactional(rollbackFor = Exception.class)
  147. public R approve(@RequestBody @Valid PolicyCaseVO vo) {
  148. vo.setStatus(QDPortEnum.POLICY_CASE_STATUS_DONE.getValue());
  149. vo.setUpdateTime(new Date());
  150. policyCaseService.updateById(vo);
  151. QueryWrapper<PolicyTodo> todoQueryWrapper = new QueryWrapper<>();
  152. todoQueryWrapper.eq("REF_ID", vo.getId());
  153. todoQueryWrapper.eq("REF_TYPE", QDPortEnum.POLICY_TODO_REFTYPE_POLICY_CASE.getValue());
  154. todoQueryWrapper.eq("TODO_USER_ID", 1);
  155. todoQueryWrapper.eq("TODO_TYPE", QDPortEnum.POLICY_TODO_TYPE_APPROVE.getValue());
  156. todoQueryWrapper.eq("STATUS", QDPortEnum.POLICY_TODO_STATUS_ACTIVE.getValue());
  157. PolicyTodo todo = new PolicyTodo();
  158. todo.setStatus(QDPortEnum.POLICY_TODO_STATUS_DONE.getValue());
  159. policyTodoService.update(todo, todoQueryWrapper);
  160. return R.success("更新成功");
  161. }
  162. @PostMapping("/refuse")
  163. @Transactional(rollbackFor = Exception.class)
  164. public R refuse(@RequestBody @Valid PolicyCaseVO vo) {
  165. vo.setStatus(QDPortEnum.POLICY_CASE_STATUS_INACTIVE.getValue());
  166. vo.setUpdateTime(new Date());
  167. policyCaseService.updateById(vo);
  168. QueryWrapper<PolicyTodo> todoQueryWrapper = new QueryWrapper<>();
  169. todoQueryWrapper.eq("REF_ID", vo.getId());
  170. todoQueryWrapper.eq("REF_TYPE", QDPortEnum.POLICY_TODO_REFTYPE_POLICY_CASE.getValue());
  171. todoQueryWrapper.eq("TODO_USER_ID", 1);
  172. todoQueryWrapper.eq("TODO_TYPE", QDPortEnum.POLICY_TODO_TYPE_APPROVE.getValue());
  173. todoQueryWrapper.eq("STATUS", QDPortEnum.POLICY_TODO_STATUS_ACTIVE.getValue());
  174. PolicyTodo todo = new PolicyTodo();
  175. todo.setStatus(QDPortEnum.POLICY_TODO_STATUS_DONE.getValue());
  176. policyTodoService.update(todo, todoQueryWrapper);
  177. return R.success("更新成功");
  178. }
  179. /**
  180. * 删除
  181. */
  182. @PostMapping("/remove")
  183. @ApiOperation(value = "逻辑删除", notes = "传入ids")
  184. public R delete(@ApiParam(value = "主键集合", required = true) @RequestParam(name = "ids") String ids){
  185. List<Long> idList = Func.toLongList(ids);
  186. policyCaseService.delete(idList);
  187. return R.success("删除成功");
  188. }
  189. }