CheckRectifyController.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. package com.zd.security.controller;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  4. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  5. import com.zd.common.core.annotation.Log;
  6. import com.zd.common.core.annotation.PreAuthorize;
  7. import com.zd.common.core.log.BusinessType;
  8. import com.zd.common.core.utils.StringUtils;
  9. import com.zd.common.core.web.controller.AbstractController;
  10. import com.zd.model.domain.ResultData;
  11. import com.zd.model.domain.per.PerFun;
  12. import com.zd.model.domain.per.PerPrefix;
  13. import com.zd.security.api.bo.CheckRectifyBo;
  14. import com.zd.security.api.dto.NoticeSendDto;
  15. import com.zd.security.api.vo.CheckRectifyVo;
  16. import com.zd.security.entity.CheckHazard;
  17. import com.zd.security.entity.CheckManage;
  18. import com.zd.security.entity.CheckRectify;
  19. import com.zd.security.entity.CheckStaffUser;
  20. import com.zd.security.scope.DataPermission;
  21. import com.zd.security.scope.DataPermissionAspect;
  22. import com.zd.security.service.*;
  23. import com.zd.security.service.impl.WordService;
  24. import io.swagger.annotations.ApiOperation;
  25. import org.springframework.beans.BeanUtils;
  26. import org.springframework.beans.factory.annotation.Autowired;
  27. import org.springframework.web.bind.annotation.*;
  28. import javax.servlet.http.HttpServletRequest;
  29. import javax.servlet.http.HttpServletResponse;
  30. import java.time.LocalDateTime;
  31. import java.util.ArrayList;
  32. import java.util.Collections;
  33. import java.util.List;
  34. import java.util.Optional;
  35. import java.util.concurrent.locks.Lock;
  36. import java.util.concurrent.locks.ReentrantLock;
  37. /**
  38. * <p>
  39. * 整改表 前端控制器
  40. * </p>
  41. *
  42. * @author cyl
  43. * @since 2023-04-19
  44. */
  45. @RestController
  46. @RequestMapping("/checkRectify")
  47. public class CheckRectifyController extends AbstractController {
  48. @Autowired
  49. private CheckHazardService checkHazardService;
  50. @Autowired
  51. private CheckRectifyService checkRectifyService;
  52. @Autowired
  53. private WordService wordService;
  54. @Autowired
  55. private UploadService uploadService;
  56. @Autowired
  57. private CheckManageService checkManageService;
  58. @Autowired
  59. private NoticeConfigService noticeConfigService;
  60. @Autowired
  61. private CheckStaffUserService checkStaffUserService;
  62. /**
  63. * 整改提交
  64. * @param checkRectifyBo
  65. * @return
  66. */
  67. @Log(title = "安全服务-整改添加", businessType = BusinessType.INSERT)
  68. @PostMapping(value = "/addOrApprove")
  69. public ResultData addOrApprove(@RequestBody CheckRectifyBo checkRectifyBo) {
  70. //判断整改是否有id,如果有,说明是整改审核,如果没有,就是整改提交。
  71. if(StringUtils.isNotNull(checkRectifyBo.getId())){
  72. CheckRectify checkRectify = new CheckRectify();
  73. BeanUtils.copyProperties(checkRectifyBo,checkRectify);
  74. checkRectify.setReviewedBy(getCurrentUserId());
  75. checkRectify.setReviewedName(getCurrentUserName());
  76. checkRectify.setReviewedTime(LocalDateTime.now());
  77. checkRectifyService.saveOrUpdate(checkRectify);
  78. //这里对隐患表需要做响应的修改
  79. CheckRectify newCheckRectify = checkRectifyService.getById(checkRectifyBo.getId());
  80. CheckHazard checkHazard = new CheckHazard();
  81. checkHazard.setId(newCheckRectify.getCheckHazardId());
  82. if(checkRectifyBo.getExamineResult()==1){
  83. checkHazard.setRectifyStatus(1);
  84. checkHazard.setExamineResult(1);
  85. checkHazard.setOverdueStatus(0);
  86. }else{
  87. checkHazard.setRectifyStatus(2);
  88. checkHazard.setExamineResult(0);
  89. }
  90. checkHazardService.saveOrUpdate(checkHazard);
  91. //同步整改进度到巡查管理表
  92. CheckHazard checkHazardManage = checkHazardService.getById(checkHazard.getId());
  93. checkManageService.update(new LambdaUpdateWrapper <CheckManage>().eq(CheckManage::getId,checkHazardManage.getCheckManageId())
  94. .set(CheckManage::getRectifySchedule,checkHazardService.rectifySchedule(checkHazardManage.getCheckManageId())));
  95. //这里需要调用老韩的接口,前提是当前巡查管理下的隐患全部流程结束的时候。(只有院校巡查的时候调用)
  96. sendEndProcess(checkHazardManage.getCheckManageId());
  97. //审批需要给整改人发送消息通知
  98. sendByZgMsg(checkHazardManage.getCheckManageId(),checkRectifyBo.getExamineResult());
  99. return ResultData.success("操作成功");
  100. }else{
  101. CheckRectify checkRectify = new CheckRectify();
  102. BeanUtils.copyProperties(checkRectifyBo,checkRectify);
  103. checkRectify.setCreateName(getCurrentUserName());
  104. checkRectify.setIsDeleted(Boolean.FALSE);
  105. checkRectifyService.save(checkRectify);
  106. //这里需要判断一下整改的提交的类型
  107. if(checkRectifyBo.getRectifyResult()==1){
  108. //已整改执行的代码,这里对隐患表需要做响应的修改
  109. CheckRectify newCheckRectify = checkRectifyService.getById(checkRectify.getId());
  110. CheckHazard checkHazard = new CheckHazard();
  111. checkHazard.setId(newCheckRectify.getCheckHazardId());
  112. checkHazard.setRectifyStatus(3);
  113. checkHazard.setExamineResult(2);
  114. checkHazard.setRectifyUserid(getCurrentUserId());
  115. checkHazard.setRectifyName(getCurrentUserName());
  116. checkHazard.setRectifyTime(LocalDateTime.now());
  117. checkHazardService.saveOrUpdate(checkHazard);
  118. //同步整改进度到巡查管理表
  119. CheckHazard checkHazardManage = checkHazardService.getById(checkHazard.getId());
  120. checkManageService.update(new LambdaUpdateWrapper <CheckManage>().eq(CheckManage::getId,checkHazardManage.getCheckManageId())
  121. .set(CheckManage::getRectifySchedule,checkHazardService.rectifySchedule(checkHazardManage.getCheckManageId())));
  122. }else{
  123. //暂无法整改执行的代码,这里对隐患表需要做响应的修改
  124. CheckRectify newCheckRectify = checkRectifyService.getById(checkRectify.getId());
  125. CheckHazard checkHazard = new CheckHazard();
  126. checkHazard.setId(newCheckRectify.getCheckHazardId());
  127. checkHazard.setRectifyStatus(4);
  128. checkHazard.setExamineResult(null);
  129. checkHazard.setOverdueStatus(0);
  130. checkHazard.setRectifyName(getCurrentUserName());
  131. checkHazard.setRectifyTime(LocalDateTime.now());
  132. checkHazardService.saveOrUpdate(checkHazard);
  133. //同步整改进度到巡查管理表
  134. CheckHazard checkHazardManage = checkHazardService.getById(checkHazard.getId());
  135. checkManageService.update(new LambdaUpdateWrapper <CheckManage>().eq(CheckManage::getId,checkHazardManage.getCheckManageId())
  136. .set(CheckManage::getRectifySchedule,checkHazardService.rectifySchedule(checkHazardManage.getCheckManageId())));
  137. //这里需要调用老韩的接口,前提是当前巡查管理下的隐患全部流程结束的时候。(只有院校巡查的时候调用)
  138. sendEndProcess(checkHazardManage.getCheckManageId());
  139. }
  140. //这里调用上传图片的接口
  141. Optional.ofNullable(checkRectifyBo.getUploadDtoList()).orElseGet(Collections::emptyList)
  142. .stream()
  143. .forEach(a->{
  144. a.setKeyId(checkRectify.getId());
  145. a.setFileType(2);
  146. a.setSource(3);
  147. uploadService.addUpload(a);
  148. });
  149. return ResultData.success("操作成功");
  150. }
  151. }
  152. //流程完毕,需要调用老韩接口
  153. private void sendEndProcess(Long checkManageId){
  154. List<Integer> rectifyStatus = new ArrayList <>();
  155. rectifyStatus.add(2);
  156. rectifyStatus.add(3);
  157. //2是待整改,3是待复核 如果没有这两个类型的数据,就说明所有的流程全部执行完毕
  158. List<CheckHazard> checkHazards = checkHazardService.list(new LambdaQueryWrapper<CheckHazard>().eq(CheckHazard::getCheckManageId, checkManageId)
  159. .in(CheckHazard::getRectifyStatus,rectifyStatus).eq(CheckHazard::getCheckFlag,0));
  160. if(checkHazards==null || checkHazards.isEmpty()){
  161. //这里调用老韩的接口
  162. checkManageService.checkPlanStatus(checkManageId);
  163. }
  164. }
  165. /**
  166. * 批量审批
  167. * @param checkRectifyList
  168. * @return
  169. */
  170. @Log(title = "安全服务-批量审批", businessType = BusinessType.INSERT)
  171. @PostMapping(value = "/batchApprove")
  172. public ResultData batchApprove(@RequestBody List<CheckRectifyBo> checkRectifyList) {
  173. Optional.ofNullable(checkRectifyList).orElseGet(Collections::emptyList)
  174. .stream()
  175. .forEach(a->{
  176. if(StringUtils.isNotNull(a.getId())){
  177. CheckRectify checkRectify = new CheckRectify();
  178. BeanUtils.copyProperties(a,checkRectify);
  179. checkRectify.setReviewedName(getCurrentUserName());
  180. checkRectify.setReviewedBy(getCurrentUserId());
  181. checkRectify.setReviewedTime(LocalDateTime.now());
  182. checkRectifyService.saveOrUpdate(checkRectify);
  183. //修改隐患表
  184. CheckHazard checkHazard = new CheckHazard();
  185. checkHazard.setId(a.getCheckHazardId());
  186. if(a.getExamineResult()==1){
  187. checkHazard.setRectifyStatus(1);
  188. checkHazard.setExamineResult(1);
  189. checkHazard.setOverdueStatus(0);
  190. }else{
  191. checkHazard.setRectifyStatus(2);
  192. checkHazard.setExamineResult(0);
  193. }
  194. checkHazardService.saveOrUpdate(checkHazard);
  195. CheckHazard checkHazard1 = checkHazardService.getById(a.getCheckHazardId());
  196. //同步整改进度到巡查管理表
  197. checkManageService.update(new LambdaUpdateWrapper <CheckManage>().eq(CheckManage::getId,checkHazard1.getCheckManageId())
  198. .set(CheckManage::getRectifySchedule,checkHazardService.rectifySchedule(checkHazard1.getCheckManageId())));
  199. //这里需要调用老韩的接口,前提是当前巡查管理下的隐患全部流程结束的时候。(只有院校巡查的时候调用)
  200. sendEndProcess(checkHazard1.getCheckManageId());
  201. //审批需要给整改人发送消息通知
  202. sendByZgMsg(checkHazard1.getCheckManageId(),a.getExamineResult());
  203. }
  204. });
  205. return ResultData.success("操作成功");
  206. }
  207. //整改消息发送通知方法
  208. private void sendByZgMsg(Long checkManageId,Integer examineResult){
  209. //发送整改消息消息
  210. NoticeSendDto noticeSendDto = new NoticeSendDto();
  211. noticeSendDto.setNoticeType(3);
  212. if(examineResult.intValue()==1){
  213. noticeSendDto.setAgreeOrReject(1);
  214. }else{
  215. noticeSendDto.setAgreeOrReject(0);
  216. }
  217. //根据manageId查询巡查管理信息
  218. CheckManage checkManage = checkManageService.getById(checkManageId);
  219. if(StringUtils.isNotNull(checkManage)){
  220. //这里根据实验室id查询对应的整改人员列表
  221. List<CheckStaffUser> checkStaffUserList = checkStaffUserService.list(new LambdaQueryWrapper <CheckStaffUser>()
  222. .eq(CheckStaffUser::getStaffType,2).eq(CheckStaffUser::getSubId,checkManage.getSubId()));
  223. StringBuilder stringBuffer = new StringBuilder();
  224. for(CheckStaffUser checkStaffUser:checkStaffUserList){
  225. stringBuffer.append(",").append(checkStaffUser.getUserId());
  226. }
  227. if(stringBuffer.length()>0){
  228. noticeSendDto.setUserIds(stringBuffer.substring(1));
  229. noticeConfigService.sendMsg(noticeSendDto);
  230. }
  231. }
  232. }
  233. /**
  234. * 获取整改数据列表list
  235. * @param checkRectifyBo
  236. * @return
  237. */
  238. @DataPermission(roleKey="checkGentle")
  239. @PreAuthorize(hasPermi = PerPrefix.SECURITY_RECTIFY + PerFun.LIST)
  240. @GetMapping(value = "/list")
  241. public ResultData list(CheckRectifyBo checkRectifyBo) {
  242. //参数检查
  243. List<Long> userList = DataPermissionAspect.threadLocal.get(); // 获取数据
  244. checkRectifyBo.setUserList(userList);
  245. DataPermissionAspect.threadLocal.remove();
  246. Page <CheckRectifyVo> page = checkRectifyService.selCheckRectifyList(checkRectifyBo);
  247. return ResultData.success(page);
  248. }
  249. /**
  250. * 查看整改报告
  251. */
  252. // @PreAuthorize(hasPermi = PerPrefix.SECURITY_RECTIFY + PerFun.QUERY)
  253. @ApiOperation(value = "查看整改报告")
  254. @GetMapping("/viewReport/{id}")
  255. public ResultData viewReport(@PathVariable("id") Long id) {
  256. return ResultData.success(checkRectifyService.viewReport(id));
  257. }
  258. /**
  259. * 小程序单个 生成整改报告
  260. */
  261. //@PreAuthorize(hasPermi = PerPrefix.LABORATORY_CHECKOPTION + PerFun.CHECKREPORT)
  262. // @PreAuthorize(hasPermi = PerPrefix.SECURITY_RECTIFY + PerFun.EXPORT)
  263. @ApiOperation(value = "生成整改报告")
  264. @RequestMapping("/genReport/{id}")
  265. public void genReport(@PathVariable("id") Long id, HttpServletResponse response, HttpServletRequest request) {
  266. wordService.genReport(id, response, request);
  267. }
  268. /**
  269. * 小程序单个 生成整改报告压缩文件
  270. */
  271. // @PreAuthorize(hasPermi = PerPrefix.SECURITY_RECTIFY + PerFun.EXPORT)
  272. @ApiOperation(value = "生成整改报告压缩文件")
  273. @RequestMapping("/genReport/zip/{idListStr}")
  274. public void genReportZip(@PathVariable("idListStr") String idListStr, HttpServletResponse response, HttpServletRequest request) {
  275. String[] idList = idListStr.split(",");
  276. wordService.genReportZip(idList, response, request);
  277. }
  278. }