package com.zd.security.controller; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.zd.common.core.annotation.Log; import com.zd.common.core.annotation.PreAuthorize; import com.zd.common.core.log.BusinessType; import com.zd.common.core.utils.StringUtils; import com.zd.common.core.web.controller.AbstractController; import com.zd.model.domain.ResultData; import com.zd.model.domain.per.PerFun; import com.zd.model.domain.per.PerPrefix; import com.zd.security.api.bo.CheckRectifyBo; import com.zd.security.api.dto.NoticeSendDto; import com.zd.security.api.vo.CheckRectifyVo; import com.zd.security.entity.CheckHazard; import com.zd.security.entity.CheckManage; import com.zd.security.entity.CheckRectify; import com.zd.security.entity.CheckStaffUser; import com.zd.security.scope.DataPermission; import com.zd.security.scope.DataPermissionAspect; import com.zd.security.service.*; import com.zd.security.service.impl.WordService; import io.swagger.annotations.ApiOperation; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; /** *

* 整改表 前端控制器 *

* * @author cyl * @since 2023-04-19 */ @RestController @RequestMapping("/checkRectify") public class CheckRectifyController extends AbstractController { @Autowired private CheckHazardService checkHazardService; @Autowired private CheckRectifyService checkRectifyService; @Autowired private WordService wordService; @Autowired private UploadService uploadService; @Autowired private CheckManageService checkManageService; @Autowired private NoticeConfigService noticeConfigService; @Autowired private CheckStaffUserService checkStaffUserService; /** * 整改提交 * @param checkRectifyBo * @return */ @Log(title = "安全服务-整改添加", businessType = BusinessType.INSERT) @PostMapping(value = "/addOrApprove") public ResultData addOrApprove(@RequestBody CheckRectifyBo checkRectifyBo) { //判断整改是否有id,如果有,说明是整改审核,如果没有,就是整改提交。 if(StringUtils.isNotNull(checkRectifyBo.getId())){ CheckRectify checkRectify = new CheckRectify(); BeanUtils.copyProperties(checkRectifyBo,checkRectify); checkRectify.setReviewedBy(getCurrentUserId()); checkRectify.setReviewedName(getCurrentUserName()); checkRectify.setReviewedTime(LocalDateTime.now()); checkRectifyService.saveOrUpdate(checkRectify); //这里对隐患表需要做响应的修改 CheckRectify newCheckRectify = checkRectifyService.getById(checkRectifyBo.getId()); CheckHazard checkHazard = new CheckHazard(); checkHazard.setId(newCheckRectify.getCheckHazardId()); if(checkRectifyBo.getExamineResult()==1){ checkHazard.setRectifyStatus(1); checkHazard.setExamineResult(1); checkHazard.setOverdueStatus(0); }else{ checkHazard.setRectifyStatus(2); checkHazard.setExamineResult(0); } checkHazardService.saveOrUpdate(checkHazard); //同步整改进度到巡查管理表 CheckHazard checkHazardManage = checkHazardService.getById(checkHazard.getId()); checkManageService.update(new LambdaUpdateWrapper ().eq(CheckManage::getId,checkHazardManage.getCheckManageId()) .set(CheckManage::getRectifySchedule,checkHazardService.rectifySchedule(checkHazardManage.getCheckManageId()))); //这里需要调用老韩的接口,前提是当前巡查管理下的隐患全部流程结束的时候。(只有院校巡查的时候调用) sendEndProcess(checkHazardManage.getCheckManageId()); //审批需要给整改人发送消息通知 sendByZgMsg(checkHazardManage.getCheckManageId(),checkRectifyBo.getExamineResult()); return ResultData.success("操作成功"); }else{ CheckRectify checkRectify = new CheckRectify(); BeanUtils.copyProperties(checkRectifyBo,checkRectify); checkRectify.setCreateName(getCurrentUserName()); checkRectify.setIsDeleted(Boolean.FALSE); checkRectifyService.save(checkRectify); //这里需要判断一下整改的提交的类型 if(checkRectifyBo.getRectifyResult()==1){ //已整改执行的代码,这里对隐患表需要做响应的修改 CheckRectify newCheckRectify = checkRectifyService.getById(checkRectify.getId()); CheckHazard checkHazard = new CheckHazard(); checkHazard.setId(newCheckRectify.getCheckHazardId()); checkHazard.setRectifyStatus(3); checkHazard.setExamineResult(2); checkHazard.setRectifyUserid(getCurrentUserId()); checkHazard.setRectifyName(getCurrentUserName()); checkHazard.setRectifyTime(LocalDateTime.now()); checkHazardService.saveOrUpdate(checkHazard); //同步整改进度到巡查管理表 CheckHazard checkHazardManage = checkHazardService.getById(checkHazard.getId()); checkManageService.update(new LambdaUpdateWrapper ().eq(CheckManage::getId,checkHazardManage.getCheckManageId()) .set(CheckManage::getRectifySchedule,checkHazardService.rectifySchedule(checkHazardManage.getCheckManageId()))); }else{ //暂无法整改执行的代码,这里对隐患表需要做响应的修改 CheckRectify newCheckRectify = checkRectifyService.getById(checkRectify.getId()); CheckHazard checkHazard = new CheckHazard(); checkHazard.setId(newCheckRectify.getCheckHazardId()); checkHazard.setRectifyStatus(4); checkHazard.setExamineResult(null); checkHazard.setOverdueStatus(0); checkHazard.setRectifyName(getCurrentUserName()); checkHazard.setRectifyTime(LocalDateTime.now()); checkHazardService.saveOrUpdate(checkHazard); //同步整改进度到巡查管理表 CheckHazard checkHazardManage = checkHazardService.getById(checkHazard.getId()); checkManageService.update(new LambdaUpdateWrapper ().eq(CheckManage::getId,checkHazardManage.getCheckManageId()) .set(CheckManage::getRectifySchedule,checkHazardService.rectifySchedule(checkHazardManage.getCheckManageId()))); //这里需要调用老韩的接口,前提是当前巡查管理下的隐患全部流程结束的时候。(只有院校巡查的时候调用) sendEndProcess(checkHazardManage.getCheckManageId()); } //这里调用上传图片的接口 Optional.ofNullable(checkRectifyBo.getUploadDtoList()).orElseGet(Collections::emptyList) .stream() .forEach(a->{ a.setKeyId(checkRectify.getId()); a.setFileType(2); a.setSource(3); uploadService.addUpload(a); }); return ResultData.success("操作成功"); } } //流程完毕,需要调用老韩接口 private void sendEndProcess(Long checkManageId){ List rectifyStatus = new ArrayList <>(); rectifyStatus.add(2); rectifyStatus.add(3); //2是待整改,3是待复核 如果没有这两个类型的数据,就说明所有的流程全部执行完毕 List checkHazards = checkHazardService.list(new LambdaQueryWrapper().eq(CheckHazard::getCheckManageId, checkManageId) .in(CheckHazard::getRectifyStatus,rectifyStatus).eq(CheckHazard::getCheckFlag,0)); if(checkHazards==null || checkHazards.isEmpty()){ //这里调用老韩的接口 checkManageService.checkPlanStatus(checkManageId); } } /** * 批量审批 * @param checkRectifyList * @return */ @Log(title = "安全服务-批量审批", businessType = BusinessType.INSERT) @PostMapping(value = "/batchApprove") public ResultData batchApprove(@RequestBody List checkRectifyList) { Optional.ofNullable(checkRectifyList).orElseGet(Collections::emptyList) .stream() .forEach(a->{ if(StringUtils.isNotNull(a.getId())){ CheckRectify checkRectify = new CheckRectify(); BeanUtils.copyProperties(a,checkRectify); checkRectify.setReviewedName(getCurrentUserName()); checkRectify.setReviewedBy(getCurrentUserId()); checkRectify.setReviewedTime(LocalDateTime.now()); checkRectifyService.saveOrUpdate(checkRectify); //修改隐患表 CheckHazard checkHazard = new CheckHazard(); checkHazard.setId(a.getCheckHazardId()); if(a.getExamineResult()==1){ checkHazard.setRectifyStatus(1); checkHazard.setExamineResult(1); checkHazard.setOverdueStatus(0); }else{ checkHazard.setRectifyStatus(2); checkHazard.setExamineResult(0); } checkHazardService.saveOrUpdate(checkHazard); CheckHazard checkHazard1 = checkHazardService.getById(a.getCheckHazardId()); //同步整改进度到巡查管理表 checkManageService.update(new LambdaUpdateWrapper ().eq(CheckManage::getId,checkHazard1.getCheckManageId()) .set(CheckManage::getRectifySchedule,checkHazardService.rectifySchedule(checkHazard1.getCheckManageId()))); //这里需要调用老韩的接口,前提是当前巡查管理下的隐患全部流程结束的时候。(只有院校巡查的时候调用) sendEndProcess(checkHazard1.getCheckManageId()); //审批需要给整改人发送消息通知 sendByZgMsg(checkHazard1.getCheckManageId(),a.getExamineResult()); } }); return ResultData.success("操作成功"); } //整改消息发送通知方法 private void sendByZgMsg(Long checkManageId,Integer examineResult){ //发送整改消息消息 NoticeSendDto noticeSendDto = new NoticeSendDto(); noticeSendDto.setNoticeType(3); if(examineResult.intValue()==1){ noticeSendDto.setAgreeOrReject(1); }else{ noticeSendDto.setAgreeOrReject(0); } //根据manageId查询巡查管理信息 CheckManage checkManage = checkManageService.getById(checkManageId); if(StringUtils.isNotNull(checkManage)){ //这里根据实验室id查询对应的整改人员列表 List checkStaffUserList = checkStaffUserService.list(new LambdaQueryWrapper () .eq(CheckStaffUser::getStaffType,2).eq(CheckStaffUser::getSubId,checkManage.getSubId())); StringBuilder stringBuffer = new StringBuilder(); for(CheckStaffUser checkStaffUser:checkStaffUserList){ stringBuffer.append(",").append(checkStaffUser.getUserId()); } if(stringBuffer.length()>0){ noticeSendDto.setUserIds(stringBuffer.substring(1)); noticeConfigService.sendMsg(noticeSendDto); } } } /** * 获取整改数据列表list * @param checkRectifyBo * @return */ @DataPermission(roleKey="checkGentle") @PreAuthorize(hasPermi = PerPrefix.SECURITY_RECTIFY + PerFun.LIST) @GetMapping(value = "/list") public ResultData list(CheckRectifyBo checkRectifyBo) { //参数检查 List userList = DataPermissionAspect.threadLocal.get(); // 获取数据 checkRectifyBo.setUserList(userList); DataPermissionAspect.threadLocal.remove(); Page page = checkRectifyService.selCheckRectifyList(checkRectifyBo); return ResultData.success(page); } /** * 查看整改报告 */ // @PreAuthorize(hasPermi = PerPrefix.SECURITY_RECTIFY + PerFun.QUERY) @ApiOperation(value = "查看整改报告") @GetMapping("/viewReport/{id}") public ResultData viewReport(@PathVariable("id") Long id) { return ResultData.success(checkRectifyService.viewReport(id)); } /** * 小程序单个 生成整改报告 */ //@PreAuthorize(hasPermi = PerPrefix.LABORATORY_CHECKOPTION + PerFun.CHECKREPORT) // @PreAuthorize(hasPermi = PerPrefix.SECURITY_RECTIFY + PerFun.EXPORT) @ApiOperation(value = "生成整改报告") @RequestMapping("/genReport/{id}") public void genReport(@PathVariable("id") Long id, HttpServletResponse response, HttpServletRequest request) { wordService.genReport(id, response, request); } /** * 小程序单个 生成整改报告压缩文件 */ // @PreAuthorize(hasPermi = PerPrefix.SECURITY_RECTIFY + PerFun.EXPORT) @ApiOperation(value = "生成整改报告压缩文件") @RequestMapping("/genReport/zip/{idListStr}") public void genReportZip(@PathVariable("idListStr") String idListStr, HttpServletResponse response, HttpServletRequest request) { String[] idList = idListStr.split(","); wordService.genReportZip(idList, response, request); } }