EvaluationDeptController.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. package com.ims.eval.controller;
  2. import cn.hutool.core.convert.Convert;
  3. import cn.hutool.core.util.IdUtil;
  4. import cn.hutool.core.util.ObjectUtil;
  5. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  6. import com.baomidou.mybatisplus.core.metadata.IPage;
  7. import com.ims.common.utils.StringUtils;
  8. import com.ims.eval.config.CustomException;
  9. import com.ims.eval.entity.EvaluationDeptIndicator;
  10. import com.ims.eval.entity.EvaluationDeptIndicatorItem;
  11. import com.ims.eval.entity.OrganizationEvaluationInfo;
  12. import com.ims.eval.entity.dto.result.R;
  13. import com.ims.eval.entity.EvaluationDept;
  14. import com.ims.eval.service.IEvaluationDeptIndicatorItemService;
  15. import com.ims.eval.service.IEvaluationDeptIndicatorService;
  16. import com.ims.eval.service.IEvaluationDeptService;
  17. import io.swagger.annotations.ApiOperation;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.web.bind.annotation.*;
  20. import java.util.*;
  21. import java.util.stream.Collectors;
  22. import static java.util.stream.Collectors.collectingAndThen;
  23. import static java.util.stream.Collectors.toCollection;
  24. /**
  25. * 考评部门配置
  26. *
  27. * @author hlf
  28. * @date 2023/4/25 9:34
  29. * 文件说明:
  30. */
  31. @RestController
  32. @RequestMapping("//evaluation-dept")
  33. public class EvaluationDeptController {
  34. @Autowired
  35. private IEvaluationDeptService evaluationDeptService;
  36. @Autowired
  37. private IEvaluationDeptIndicatorService evaluationDeptIndicatorService;
  38. @Autowired
  39. private IEvaluationDeptIndicatorItemService evaluationDeptIndicatorItemService;
  40. /**
  41. * 考评部门配置列表信息(分页)
  42. *
  43. * @param pageNum 当前记录起始索引
  44. * @param pageSize 每页显示记录数
  45. * @param deptName 部门名称
  46. * @param annual 年度
  47. * @return 结果
  48. */
  49. //@ImsPreAuth("eval:evaluationDept:view")
  50. @GetMapping(value = "list")
  51. public R list(
  52. @RequestParam(value = "pageNum") Integer pageNum,
  53. @RequestParam(value = "pageSize") Integer pageSize,
  54. @RequestParam(value = "deptName", required = false) String deptName,
  55. @RequestParam(value = "annual", required = false) String annual) {
  56. IPage<EvaluationDept> list = evaluationDeptService.listPage(pageNum, pageSize, deptName, annual);
  57. List<EvaluationDept> evaluationDeptList = list.getRecords();
  58. for (EvaluationDept evaluationDept : evaluationDeptList) {
  59. List<EvaluationDeptIndicator> evaluationDeptIndicatorList = evaluationDeptIndicatorService.selectEvaluationDeptIndicatorListByEvaluationDeptId(evaluationDept.getId());
  60. for (EvaluationDeptIndicator evaluationDeptIndicator : evaluationDeptIndicatorList) {
  61. List<EvaluationDeptIndicatorItem> evaluationDeptIndicatorItemList = evaluationDeptIndicatorItemService.selectEvaluationDeptIndicatorItemListByEvaluationDeptIndicatorId(evaluationDeptIndicator.getId());
  62. evaluationDeptIndicator.setEvaluationDeptIndicatorItemList(evaluationDeptIndicatorItemList);
  63. }
  64. evaluationDept.setEvaluationDeptIndicatorList(evaluationDeptIndicatorList);
  65. }
  66. return R.ok().data(list);
  67. }
  68. /**
  69. * 考评部门配置信息
  70. *
  71. * @param deptId 部门主键
  72. * @param annual 年度
  73. * @return 结果
  74. */
  75. //@ImsPreAuth("eval:evaluationDept:view")
  76. @GetMapping(value = "listAll")
  77. public R listAll(
  78. @RequestParam(value = "deptId", required = false) String deptId,
  79. @RequestParam(value = "annual", required = false) String annual) {
  80. List<EvaluationDept> list = evaluationDeptService.listAll(deptId, annual);
  81. for (EvaluationDept evaluationDept : list) {
  82. List<EvaluationDeptIndicator> evaluationDeptIndicatorList = evaluationDeptIndicatorService.selectEvaluationDeptIndicatorListByEvaluationDeptId(evaluationDept.getId());
  83. for (EvaluationDeptIndicator evaluationDeptIndicator : evaluationDeptIndicatorList) {
  84. List<EvaluationDeptIndicatorItem> evaluationDeptIndicatorItemList = evaluationDeptIndicatorItemService.selectEvaluationDeptIndicatorItemListByEvaluationDeptIndicatorId(evaluationDeptIndicator.getId());
  85. evaluationDeptIndicator.setEvaluationDeptIndicatorItemList(evaluationDeptIndicatorItemList);
  86. }
  87. evaluationDept.setEvaluationDeptIndicatorList(evaluationDeptIndicatorList);
  88. }
  89. return R.ok().data(list);
  90. }
  91. /**
  92. * 新增/修改考评部门配置信息
  93. *
  94. * @param dept 考评部门实体
  95. * @return 结果
  96. */
  97. //@ImsPreAuth("eval:evaluationDept:edit")
  98. @PostMapping(value = "/save")
  99. @ApiOperation(value = "新增(修改)", notes = "新增(修改)")
  100. public R addAll(@RequestBody EvaluationDept dept) {
  101. try {
  102. boolean b;
  103. if (StringUtils.isEmpty(dept.getId())) {
  104. String edId = Convert.toStr(IdUtil.getSnowflake(1, 1).nextId());
  105. dept.setId(edId);
  106. //默认启用
  107. dept.setEnable(true);
  108. //新增部门配置信息
  109. b = evaluationDeptService.save(dept);
  110. for (EvaluationDeptIndicator evaluationDeptIndicator : dept.getEvaluationDeptIndicatorList()) {
  111. if (evaluationDeptIndicator.getEvaluationDeptIndicatorItemList().size() > 0) {
  112. String ediId = Convert.toStr(IdUtil.getSnowflake(1, 1).nextId());
  113. evaluationDeptIndicator.setId(ediId);
  114. evaluationDeptIndicator.setEvaluationDeptId(edId);
  115. //新增部门指标信息
  116. b = evaluationDeptIndicatorService.save(evaluationDeptIndicator);
  117. for (EvaluationDeptIndicatorItem evaluationDeptIndicatorItem : evaluationDeptIndicator.getEvaluationDeptIndicatorItemList()) {
  118. String ediiId = Convert.toStr(IdUtil.getSnowflake(1, 1).nextId());
  119. evaluationDeptIndicatorItem.setId(ediiId);
  120. evaluationDeptIndicatorItem.setEvaluationDeptId(edId);
  121. evaluationDeptIndicatorItem.setEvaluationDeptIndicatorId(ediId);
  122. evaluationDeptIndicatorItem.setIndicatorName(evaluationDeptIndicator.getIndicatorName());
  123. evaluationDeptIndicatorItem.setIndicatorCode(evaluationDeptIndicator.getIndicatorCode());
  124. //新增部门指标项信息
  125. b = evaluationDeptIndicatorItemService.save(evaluationDeptIndicatorItem);
  126. }
  127. }
  128. }
  129. } else {
  130. //默认启用
  131. dept.setEnable(true);
  132. b = evaluationDeptService.updateById(dept);
  133. Iterator<EvaluationDeptIndicator> iterator = dept.getEvaluationDeptIndicatorList().iterator();
  134. while (iterator.hasNext()) {
  135. EvaluationDeptIndicator evaluationDeptIndicator = iterator.next();
  136. //是否有指标项
  137. if (evaluationDeptIndicator.getEvaluationDeptIndicatorItemList().size() > 0) {
  138. //是否有主键
  139. if (StringUtils.isEmpty(evaluationDeptIndicator.getId())) {
  140. String ediId = Convert.toStr(IdUtil.getSnowflake(1, 1).nextId());
  141. evaluationDeptIndicator.setId(ediId);
  142. evaluationDeptIndicator.setEvaluationDeptId(dept.getId());
  143. //新增部门指标信息
  144. b = evaluationDeptIndicatorService.save(evaluationDeptIndicator);
  145. for (EvaluationDeptIndicatorItem evaluationDeptIndicatorItem : evaluationDeptIndicator.getEvaluationDeptIndicatorItemList()) {
  146. String ediiId = Convert.toStr(IdUtil.getSnowflake(1, 1).nextId());
  147. evaluationDeptIndicatorItem.setId(ediiId);
  148. evaluationDeptIndicatorItem.setEvaluationDeptId(dept.getId());
  149. evaluationDeptIndicatorItem.setEvaluationDeptIndicatorId(ediId);
  150. evaluationDeptIndicatorItem.setIndicatorName(evaluationDeptIndicator.getIndicatorName());
  151. evaluationDeptIndicatorItem.setIndicatorCode(evaluationDeptIndicator.getIndicatorCode());
  152. //新增部门指标项信息
  153. b = evaluationDeptIndicatorItemService.save(evaluationDeptIndicatorItem);
  154. }
  155. } else {
  156. b = evaluationDeptIndicatorService.updateById(evaluationDeptIndicator);
  157. for (EvaluationDeptIndicatorItem evaluationDeptIndicatorItem : evaluationDeptIndicator.getEvaluationDeptIndicatorItemList()) {
  158. if (StringUtils.isEmpty(evaluationDeptIndicatorItem.getId())) {
  159. String ediiId = Convert.toStr(IdUtil.getSnowflake(1, 1).nextId());
  160. evaluationDeptIndicatorItem.setId(ediiId);
  161. evaluationDeptIndicatorItem.setEvaluationDeptId(dept.getId());
  162. evaluationDeptIndicatorItem.setEvaluationDeptIndicatorId(evaluationDeptIndicator.getId());
  163. evaluationDeptIndicatorItem.setIndicatorName(evaluationDeptIndicator.getIndicatorName());
  164. evaluationDeptIndicatorItem.setIndicatorCode(evaluationDeptIndicator.getIndicatorCode());
  165. //新增部门指标信息
  166. b = evaluationDeptIndicatorItemService.save(evaluationDeptIndicatorItem);
  167. } else {
  168. b = evaluationDeptIndicatorItemService.updateById(evaluationDeptIndicatorItem);
  169. }
  170. }
  171. }
  172. } else {
  173. boolean flag = evaluationDeptIndicatorService.removeById(evaluationDeptIndicator.getId());
  174. if (flag) {
  175. iterator.remove();
  176. }
  177. }
  178. }
  179. }
  180. if (b) {
  181. return R.ok().data(b);
  182. } else {
  183. return R.error().data("保存失败!");
  184. }
  185. } catch (CustomException e) {
  186. return R.customError(e.getMessage()).data("失败!");
  187. }
  188. }
  189. /**
  190. * 批量删除考评部门配置信息
  191. *
  192. * @param ids
  193. * @return
  194. */
  195. //@ImsPreAuth("eval:evaluationDept:remove")
  196. @PostMapping(value = "/removeAll/{ids}")
  197. @ApiOperation(value = "批量删除", notes = "批量删除")
  198. public R deleteAll(@PathVariable("ids") String ids) {
  199. String[] strings = ids.split(",");
  200. boolean b;
  201. b = evaluationDeptService.removeByIds(Arrays.asList(strings));
  202. for (String id : strings) {
  203. QueryWrapper<EvaluationDeptIndicator> qw1 = new QueryWrapper<>();
  204. if (StringUtils.isNotEmpty(id)) {
  205. qw1.lambda().eq(EvaluationDeptIndicator::getEvaluationDeptId, id);
  206. }
  207. b = evaluationDeptIndicatorService.remove(qw1);
  208. QueryWrapper<EvaluationDeptIndicatorItem> qw2 = new QueryWrapper<>();
  209. if (StringUtils.isNotEmpty(id)) {
  210. qw2.lambda().eq(EvaluationDeptIndicatorItem::getEvaluationDeptId, id);
  211. }
  212. b = evaluationDeptIndicatorItemService.remove(qw2);
  213. }
  214. if (b) {
  215. return R.ok().data(b);
  216. } else {
  217. return R.error().data("删除失败!");
  218. }
  219. }
  220. /**
  221. * 删除考评部门指标项信息
  222. *
  223. * @param id
  224. * @return
  225. */
  226. //@ImsPreAuth("eval:evaluationDept:remove")
  227. @PostMapping(value = "/remove/{id}")
  228. @ApiOperation(value = "删除", notes = "删除")
  229. public R delete(@PathVariable("id") String id) {
  230. boolean b = evaluationDeptIndicatorItemService.removeById(id);
  231. if (b) {
  232. return R.ok().data(b);
  233. } else {
  234. return R.error().data("删除失败!");
  235. }
  236. }
  237. }