PolicyCaseController.java 9.5 KB

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