package com.ims.eval.controller; import cn.hutool.json.JSONArray; import cn.hutool.json.JSONUtil; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ims.common.utils.StringUtils; import com.ims.eval.config.CustomException; import com.ims.eval.entity.DeptAssessmentDeclaration; import com.ims.eval.entity.EvaluationDept; import com.ims.eval.entity.dto.request.UserDTO; import com.ims.eval.entity.dto.result.R; import com.ims.eval.service.IDeptAssessmentDeclarationService; import com.ims.eval.service.IEvaluationDeptService; import com.ims.eval.service.IUserService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import java.util.ArrayList; import java.util.Arrays; import java.util.List; /** * 考评部门配置 * * @author hlf * @date 2023/7/14 16:54 * 文件说明: */ @Slf4j @RestController @RequestMapping("//evaluation-dept-allocation") public class DepartmentAllocationController { @Autowired private IEvaluationDeptService evaluationDeptService; @Autowired private HttpServletRequest request; @Autowired private IUserService userService; @Autowired private IDeptAssessmentDeclarationService deptAssessmentDeclarationService; /** * 考评部门配置列表信息(分页) * * @param pageNum 当前记录起始索引 * @param pageSize 每页显示记录数 * @param deptName 部门名称 * @param chargePersonName 部门领导名称 * @return 结果 */ @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 = "chargePersonName", required = false) String chargePersonName) { QueryWrapper qw = new QueryWrapper<>(); if (StringUtils.isNotEmpty(deptName)) { qw.lambda().like(EvaluationDept::getDeptName, deptName); } if (StringUtils.isNotEmpty(chargePersonName)) { qw.lambda().like(EvaluationDept::getChargePersonName, chargePersonName); } qw.lambda().orderByAsc(EvaluationDept::getSerialNumber); Page page = new Page<>(pageNum, pageSize); IPage list = evaluationDeptService.page(page, qw); return R.ok().data(list); } /** * 考评部门配置信息 * * @return 结果 */ @GetMapping(value = "/listAll") public R listAll() { QueryWrapper qw = new QueryWrapper<>(); qw.lambda().eq(EvaluationDept::getJxjgkhsbType, "1"); qw.lambda().orderByAsc(EvaluationDept::getSerialNumber); List list = evaluationDeptService.list(qw); return R.ok().data(list); } /** * 新增/修改考评部门配置信息 * * @param evaluationDept 考评部门配置实体 * @return 结果 */ @PostMapping(value = "/save") public R addAll(@RequestBody EvaluationDept evaluationDept) { try { if (StringUtils.isEmpty(evaluationDept.getId())) { QueryWrapper qw = new QueryWrapper<>(); if (StringUtils.isNotEmpty(evaluationDept.getParentId())) { qw.lambda().eq(EvaluationDept::getParentId, evaluationDept.getParentId()); } if (StringUtils.isNotEmpty(evaluationDept.getDeptId())) { qw.lambda().eq(EvaluationDept::getDeptId, evaluationDept.getDeptId()); } EvaluationDept obj = evaluationDeptService.getOne(qw); if (obj != null) { return R.error("部门重复,请重新添加!"); } } if (StringUtils.isNotEmpty(evaluationDept.getId())) { QueryWrapper qw = new QueryWrapper<>(); if (StringUtils.isNotEmpty(evaluationDept.getDeptId())) { qw.lambda().eq(DeptAssessmentDeclaration::getDeptId, evaluationDept.getDeptId()); } List list = new ArrayList<>(); List deptAssessmentDeclarationList = deptAssessmentDeclarationService.list(qw); for (DeptAssessmentDeclaration deptAssessmentDeclaration : deptAssessmentDeclarationList) { if (!"流程已结束".equals(deptAssessmentDeclaration.getStage())) { deptAssessmentDeclaration.setDeptLeaderId(evaluationDept.getChargePersonId()); deptAssessmentDeclaration.setDeptLeaderName(evaluationDept.getChargePersonName()); list.add(deptAssessmentDeclaration); } } deptAssessmentDeclarationService.updateBatchById(list); } boolean b = evaluationDeptService.saveOrUpdate(evaluationDept); if (b) { return R.ok().data(b); } else { return R.error("保存失败!"); } } catch (CustomException e) { return R.customError(e.getMessage()).data("失败!"); } } /** * 获取部门领导 * * @return 结果 */ @GetMapping(value = "/getDepartmentLeader/{id}") public R getDepartmentLeader(@PathVariable String id) { JSONObject jsonArr = userService.pageList(1, 500, id, "", "", "", "", "", request); JSONObject jsonArr1 = (JSONObject) jsonArr.get("data"); JSONArray array = JSONUtil.parseArray(jsonArr1.get("records")); List list = JSONUtil.toList(array, UserDTO.class); return R.ok().data(list); } /** * 批量删除考评部门配置信息 * * @param ids 主键s * @return 结果 */ @PostMapping(value = "/removeAll/{ids}") public R deleteAll(@PathVariable("ids") String ids) { try { String[] strings = ids.split(","); boolean b = evaluationDeptService.removeByIds(Arrays.asList(strings)); if (b) { return R.ok().data(b); } else { return R.error("删除失败!"); } } catch (CustomException e) { return R.customError(e.getMessage()).data("失败!"); } } }