123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- package com.ims.eval.controller;
- import cn.hutool.core.convert.Convert;
- import cn.hutool.core.util.IdUtil;
- import cn.hutool.core.util.ObjectUtil;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.core.metadata.IPage;
- import com.ims.common.utils.StringUtils;
- import com.ims.eval.config.CustomException;
- import com.ims.eval.entity.EvaluationDeptIndicator;
- import com.ims.eval.entity.EvaluationDeptIndicatorItem;
- import com.ims.eval.entity.OrganizationEvaluationInfo;
- import com.ims.eval.entity.dto.result.R;
- import com.ims.eval.entity.EvaluationDept;
- import com.ims.eval.service.IEvaluationDeptIndicatorItemService;
- import com.ims.eval.service.IEvaluationDeptIndicatorService;
- import com.ims.eval.service.IEvaluationDeptService;
- import io.swagger.annotations.ApiOperation;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
- import java.util.*;
- import java.util.stream.Collectors;
- import static java.util.stream.Collectors.collectingAndThen;
- import static java.util.stream.Collectors.toCollection;
- /**
- * 考评部门配置
- *
- * @author hlf
- * @date 2023/4/25 9:34
- * 文件说明:
- */
- @RestController
- @RequestMapping("//evaluation-dept")
- public class EvaluationDeptController {
- @Autowired
- private IEvaluationDeptService evaluationDeptService;
- @Autowired
- private IEvaluationDeptIndicatorService evaluationDeptIndicatorService;
- @Autowired
- private IEvaluationDeptIndicatorItemService evaluationDeptIndicatorItemService;
- /**
- * 考评部门配置列表信息(分页)
- *
- * @param pageNum 当前记录起始索引
- * @param pageSize 每页显示记录数
- * @param deptName 部门名称
- * @param annual 年度
- * @return 结果
- */
- //@ImsPreAuth("eval:evaluationDept:view")
- @GetMapping(value = "list")
- public R list(
- @RequestParam(value = "pageNum") Integer pageNum,
- @RequestParam(value = "pageSize") Integer pageSize,
- @RequestParam(value = "deptName", required = false) String deptName,
- @RequestParam(value = "annual", required = false) String annual) {
- IPage<EvaluationDept> list = evaluationDeptService.listPage(pageNum, pageSize, deptName, annual);
- List<EvaluationDept> evaluationDeptList = list.getRecords();
- for (EvaluationDept evaluationDept : evaluationDeptList) {
- List<EvaluationDeptIndicator> evaluationDeptIndicatorList = evaluationDeptIndicatorService.selectEvaluationDeptIndicatorListByEvaluationDeptId(evaluationDept.getId());
- for (EvaluationDeptIndicator evaluationDeptIndicator : evaluationDeptIndicatorList) {
- List<EvaluationDeptIndicatorItem> evaluationDeptIndicatorItemList = evaluationDeptIndicatorItemService.selectEvaluationDeptIndicatorItemListByEvaluationDeptIndicatorId(evaluationDeptIndicator.getId());
- evaluationDeptIndicator.setEvaluationDeptIndicatorItemList(evaluationDeptIndicatorItemList);
- }
- evaluationDept.setEvaluationDeptIndicatorList(evaluationDeptIndicatorList);
- }
- return R.ok().data(list);
- }
- /**
- * 考评部门配置信息
- *
- * @param deptId 部门主键
- * @param annual 年度
- * @return 结果
- */
- //@ImsPreAuth("eval:evaluationDept:view")
- @GetMapping(value = "listAll")
- public R listAll(
- @RequestParam(value = "deptId", required = false) String deptId,
- @RequestParam(value = "annual", required = false) String annual) {
- List<EvaluationDept> list = evaluationDeptService.listAll(deptId, annual);
- for (EvaluationDept evaluationDept : list) {
- List<EvaluationDeptIndicator> evaluationDeptIndicatorList = evaluationDeptIndicatorService.selectEvaluationDeptIndicatorListByEvaluationDeptId(evaluationDept.getId());
- for (EvaluationDeptIndicator evaluationDeptIndicator : evaluationDeptIndicatorList) {
- List<EvaluationDeptIndicatorItem> evaluationDeptIndicatorItemList = evaluationDeptIndicatorItemService.selectEvaluationDeptIndicatorItemListByEvaluationDeptIndicatorId(evaluationDeptIndicator.getId());
- evaluationDeptIndicator.setEvaluationDeptIndicatorItemList(evaluationDeptIndicatorItemList);
- }
- evaluationDept.setEvaluationDeptIndicatorList(evaluationDeptIndicatorList);
- }
- return R.ok().data(list);
- }
- /**
- * 新增/修改考评部门配置信息
- *
- * @param dept 考评部门实体
- * @return 结果
- */
- //@ImsPreAuth("eval:evaluationDept:edit")
- @PostMapping(value = "/save")
- @ApiOperation(value = "新增(修改)", notes = "新增(修改)")
- public R addAll(@RequestBody EvaluationDept dept) {
- try {
- boolean b;
- if (StringUtils.isEmpty(dept.getId())) {
- String edId = Convert.toStr(IdUtil.getSnowflake(1, 1).nextId());
- dept.setId(edId);
- //默认启用
- dept.setEnable(true);
- //新增部门配置信息
- b = evaluationDeptService.save(dept);
- for (EvaluationDeptIndicator evaluationDeptIndicator : dept.getEvaluationDeptIndicatorList()) {
- if (evaluationDeptIndicator.getEvaluationDeptIndicatorItemList().size() > 0) {
- String ediId = Convert.toStr(IdUtil.getSnowflake(1, 1).nextId());
- evaluationDeptIndicator.setId(ediId);
- evaluationDeptIndicator.setEvaluationDeptId(edId);
- //新增部门指标信息
- b = evaluationDeptIndicatorService.save(evaluationDeptIndicator);
- for (EvaluationDeptIndicatorItem evaluationDeptIndicatorItem : evaluationDeptIndicator.getEvaluationDeptIndicatorItemList()) {
- String ediiId = Convert.toStr(IdUtil.getSnowflake(1, 1).nextId());
- evaluationDeptIndicatorItem.setId(ediiId);
- evaluationDeptIndicatorItem.setEvaluationDeptId(edId);
- evaluationDeptIndicatorItem.setEvaluationDeptIndicatorId(ediId);
- evaluationDeptIndicatorItem.setIndicatorName(evaluationDeptIndicator.getIndicatorName());
- evaluationDeptIndicatorItem.setIndicatorCode(evaluationDeptIndicator.getIndicatorCode());
- //新增部门指标项信息
- b = evaluationDeptIndicatorItemService.save(evaluationDeptIndicatorItem);
- }
- }
- }
- } else {
- //默认启用
- dept.setEnable(true);
- b = evaluationDeptService.updateById(dept);
- Iterator<EvaluationDeptIndicator> iterator = dept.getEvaluationDeptIndicatorList().iterator();
- while (iterator.hasNext()) {
- EvaluationDeptIndicator evaluationDeptIndicator = iterator.next();
- //是否有指标项
- if (evaluationDeptIndicator.getEvaluationDeptIndicatorItemList().size() > 0) {
- //是否有主键
- if (StringUtils.isEmpty(evaluationDeptIndicator.getId())) {
- String ediId = Convert.toStr(IdUtil.getSnowflake(1, 1).nextId());
- evaluationDeptIndicator.setId(ediId);
- evaluationDeptIndicator.setEvaluationDeptId(dept.getId());
- //新增部门指标信息
- b = evaluationDeptIndicatorService.save(evaluationDeptIndicator);
- for (EvaluationDeptIndicatorItem evaluationDeptIndicatorItem : evaluationDeptIndicator.getEvaluationDeptIndicatorItemList()) {
- String ediiId = Convert.toStr(IdUtil.getSnowflake(1, 1).nextId());
- evaluationDeptIndicatorItem.setId(ediiId);
- evaluationDeptIndicatorItem.setEvaluationDeptId(dept.getId());
- evaluationDeptIndicatorItem.setEvaluationDeptIndicatorId(ediId);
- evaluationDeptIndicatorItem.setIndicatorName(evaluationDeptIndicator.getIndicatorName());
- evaluationDeptIndicatorItem.setIndicatorCode(evaluationDeptIndicator.getIndicatorCode());
- //新增部门指标项信息
- b = evaluationDeptIndicatorItemService.save(evaluationDeptIndicatorItem);
- }
- } else {
- b = evaluationDeptIndicatorService.updateById(evaluationDeptIndicator);
- for (EvaluationDeptIndicatorItem evaluationDeptIndicatorItem : evaluationDeptIndicator.getEvaluationDeptIndicatorItemList()) {
- if (StringUtils.isEmpty(evaluationDeptIndicatorItem.getId())) {
- String ediiId = Convert.toStr(IdUtil.getSnowflake(1, 1).nextId());
- evaluationDeptIndicatorItem.setId(ediiId);
- evaluationDeptIndicatorItem.setEvaluationDeptId(dept.getId());
- evaluationDeptIndicatorItem.setEvaluationDeptIndicatorId(evaluationDeptIndicator.getId());
- evaluationDeptIndicatorItem.setIndicatorName(evaluationDeptIndicator.getIndicatorName());
- evaluationDeptIndicatorItem.setIndicatorCode(evaluationDeptIndicator.getIndicatorCode());
- //新增部门指标信息
- b = evaluationDeptIndicatorItemService.save(evaluationDeptIndicatorItem);
- } else {
- b = evaluationDeptIndicatorItemService.updateById(evaluationDeptIndicatorItem);
- }
- }
- }
- } else {
- boolean flag = evaluationDeptIndicatorService.removeById(evaluationDeptIndicator.getId());
- if (flag) {
- iterator.remove();
- }
- }
- }
- }
- if (b) {
- return R.ok().data(b);
- } else {
- return R.error().data("保存失败!");
- }
- } catch (CustomException e) {
- return R.customError(e.getMessage()).data("失败!");
- }
- }
- /**
- * 批量删除考评部门配置信息
- *
- * @param ids
- * @return
- */
- //@ImsPreAuth("eval:evaluationDept:remove")
- @PostMapping(value = "/removeAll/{ids}")
- @ApiOperation(value = "批量删除", notes = "批量删除")
- public R deleteAll(@PathVariable("ids") String ids) {
- String[] strings = ids.split(",");
- boolean b;
- b = evaluationDeptService.removeByIds(Arrays.asList(strings));
- for (String id : strings) {
- QueryWrapper<EvaluationDeptIndicator> qw1 = new QueryWrapper<>();
- if (StringUtils.isNotEmpty(id)) {
- qw1.lambda().eq(EvaluationDeptIndicator::getEvaluationDeptId, id);
- }
- b = evaluationDeptIndicatorService.remove(qw1);
- QueryWrapper<EvaluationDeptIndicatorItem> qw2 = new QueryWrapper<>();
- if (StringUtils.isNotEmpty(id)) {
- qw2.lambda().eq(EvaluationDeptIndicatorItem::getEvaluationDeptId, id);
- }
- b = evaluationDeptIndicatorItemService.remove(qw2);
- }
- if (b) {
- return R.ok().data(b);
- } else {
- return R.error().data("删除失败!");
- }
- }
- /**
- * 删除考评部门指标项信息
- *
- * @param id
- * @return
- */
- //@ImsPreAuth("eval:evaluationDept:remove")
- @PostMapping(value = "/remove/{id}")
- @ApiOperation(value = "删除", notes = "删除")
- public R delete(@PathVariable("id") String id) {
- boolean b = evaluationDeptIndicatorItemService.removeById(id);
- if (b) {
- return R.ok().data(b);
- } else {
- return R.error().data("删除失败!");
- }
- }
- }
|