CheckClapController.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. package com.zd.security.controller;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  4. import com.zd.common.core.annotation.Log;
  5. import com.zd.common.core.annotation.PreAuthorize;
  6. import com.zd.common.core.log.BusinessType;
  7. import com.zd.common.core.utils.FileConfigUtils;
  8. import com.zd.common.core.utils.SecurityUtils;
  9. import com.zd.common.core.utils.StringUtils;
  10. import com.zd.common.core.web.controller.AbstractController;
  11. import com.zd.laboratory.api.entity.LabSubjectEntity;
  12. import com.zd.laboratory.api.feign.RemoteSubQueryService;
  13. import com.zd.model.domain.R;
  14. import com.zd.model.domain.ResultData;
  15. import com.zd.model.domain.per.PerFun;
  16. import com.zd.model.domain.per.PerPrefix;
  17. import com.zd.security.api.bo.CheckClapBo;
  18. import com.zd.security.api.dto.UploadDto;
  19. import com.zd.security.api.vo.CheckClapVo;
  20. import com.zd.security.entity.CheckClap;
  21. import com.zd.security.entity.CheckStaffUser;
  22. import com.zd.security.entity.Upload;
  23. import com.zd.security.scope.DataPermission;
  24. import com.zd.security.scope.DataPermissionAspect;
  25. import com.zd.security.service.CheckClapService;
  26. import com.zd.security.service.CheckStaffUserService;
  27. import com.zd.security.service.UploadService;
  28. import com.zd.system.api.feign.RemoteUserService;
  29. import org.springframework.beans.BeanUtils;
  30. import org.springframework.beans.factory.annotation.Autowired;
  31. import org.springframework.web.bind.annotation.*;
  32. import java.text.SimpleDateFormat;
  33. import java.time.LocalDateTime;
  34. import java.time.ZoneOffset;
  35. import java.time.temporal.ChronoField;
  36. import java.util.*;
  37. import java.util.concurrent.locks.Lock;
  38. import java.util.concurrent.locks.ReentrantLock;
  39. import java.util.function.Function;
  40. import java.util.function.Predicate;
  41. import java.util.stream.Collectors;
  42. /**
  43. * <p>
  44. * 随手拍 前端控制器
  45. * </p>
  46. *
  47. * @author cyl
  48. * @since 2023-04-19
  49. */
  50. @RestController
  51. @RequestMapping("/checkClap")
  52. public class CheckClapController extends AbstractController {
  53. @Autowired
  54. private CheckClapService checkClapService;
  55. @Autowired
  56. private RemoteUserService remoteUserService;
  57. @Autowired
  58. private RemoteSubQueryService remoteSubQueryService;
  59. @Autowired
  60. private UploadService uploadService;
  61. @Autowired
  62. private FileConfigUtils fileConfigUtils;
  63. @Autowired
  64. private CheckStaffUserService checkStaffUserService;
  65. /**
  66. * 获取随手拍数据列表list
  67. * @param checkClapBo
  68. * @return
  69. */
  70. // @DataPermission(tableAlias = "", permissionStr = PerPrefix.SECURITY_CLAP)
  71. @DataPermission(roleKey="rectifyGentle")
  72. @PreAuthorize(hasPermi = PerPrefix.SECURITY_CLAP + PerFun.LIST)
  73. @GetMapping(value = "/list")
  74. public ResultData list(CheckClapBo checkClapBo) {
  75. //参数检查
  76. List<Long> userList = DataPermissionAspect.threadLocal.get(); // 获取数据
  77. checkClapBo.setUserList(userList);
  78. DataPermissionAspect.threadLocal.remove();
  79. Page <CheckClapVo> page = checkClapService.selCheckClapList(checkClapBo);
  80. return ResultData.success(page);
  81. }
  82. /**
  83. * 获取随手拍数据列表list (小程序接口)
  84. * @param checkClapBo
  85. * @return
  86. */
  87. @DataPermission(roleKey="rectifyGentle")
  88. @GetMapping(value = "/appList")
  89. public ResultData appList(CheckClapBo checkClapBo) {
  90. //参数检查
  91. List<Long> userList = DataPermissionAspect.threadLocal.get(); // 获取数据
  92. checkClapBo.setUserList(userList);
  93. DataPermissionAspect.threadLocal.remove();
  94. checkClapBo.setMyRelated(1);
  95. Page <CheckClapVo> page = checkClapService.selCheckClapList(checkClapBo);
  96. Optional.ofNullable(page.getRecords()).orElseGet(Collections::emptyList)
  97. .stream()
  98. .forEach(a->{
  99. timeProcessing(a);
  100. });
  101. return ResultData.success(page);
  102. }
  103. public void timeProcessing(CheckClapVo a){
  104. long nowTime = new Date().getTime()-1800000;
  105. long timestamp = a.getCreateTime().toInstant(ZoneOffset.of("+8")).toEpochMilli();
  106. if(nowTime<=timestamp){
  107. a.setTimeFlag("刚刚");
  108. }else{
  109. a.setTimeFlag(a.getCreateTime().get(ChronoField.HOUR_OF_DAY)+":"+a.getCreateTime().get(ChronoField.MINUTE_OF_HOUR));
  110. long nowTime3 = new Date().getTime()-86400000;
  111. long timestamp3 = a.getCreateTime().toInstant(ZoneOffset.of("+8")).toEpochMilli();
  112. if(nowTime3>=timestamp3){
  113. //获取本条数据的年月日时间
  114. String month3 = (a.getCreateTime().get(ChronoField.MONTH_OF_YEAR)+"").length()==1?"0"+a.getCreateTime().get(ChronoField.MONTH_OF_YEAR):a.getCreateTime().get(ChronoField.MONTH_OF_YEAR)+"";
  115. a.setTimeFlag(a.getCreateTime().get(ChronoField.YEAR)+"-"+month3+"-"+a.getCreateTime().get(ChronoField.DAY_OF_MONTH));
  116. }
  117. //昨天的时间计算
  118. recentTime(a,-1);
  119. //前天的时间计算
  120. recentTime(a,-2);
  121. }
  122. }
  123. public void recentTime(CheckClapVo a,Integer time){
  124. //time 是-1 就减一天,如果是-2就减两天
  125. //昨天的时间计算
  126. SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd");//设置格式
  127. Calendar calendar1 = Calendar.getInstance(); //创建Calendar 的实例
  128. calendar1.add(Calendar.DAY_OF_MONTH, time); //当前时间减去一天,即一天前的时间
  129. String nowTime1 = simpleDateFormat1.format(calendar1.getTime());
  130. //获取本条数据的年月日时间
  131. String month1 = (a.getCreateTime().get(ChronoField.MONTH_OF_YEAR)+"").length()==1?"0"+a.getCreateTime().get(ChronoField.MONTH_OF_YEAR):a.getCreateTime().get(ChronoField.MONTH_OF_YEAR)+"";
  132. String timestamp1 = a.getCreateTime().get(ChronoField.YEAR)+"-"+month1+"-"+a.getCreateTime().get(ChronoField.DAY_OF_MONTH);
  133. if(nowTime1.equals(timestamp1)){
  134. if(time.intValue()==-1){
  135. a.setTimeFlag("昨天");
  136. }
  137. if(time.intValue()==-2){
  138. a.setTimeFlag("前天");
  139. }
  140. }
  141. }
  142. /**
  143. * 获取随手拍上报记录数据列表list
  144. * @param checkClapBo
  145. * @return
  146. */
  147. @GetMapping(value = "/mylist")
  148. public ResultData mylist(CheckClapBo checkClapBo) {
  149. //查询条件
  150. QueryWrapper<CheckClap> wrapperClap = new QueryWrapper <>();
  151. //整改状态
  152. if(StringUtils.isNotNull(checkClapBo.getRectifyStatus())){
  153. wrapperClap.lambda().eq(CheckClap::getRectifyStatus,checkClapBo.getRectifyStatus());
  154. }
  155. if(StringUtils.isNotNull(checkClapBo.getSearchValue())){
  156. wrapperClap.lambda().and(wrapper->wrapper.like(CheckClap::getSubName,checkClapBo.getSearchValue())
  157. .or().like(CheckClap::getRoomNum,checkClapBo.getSearchValue()).or().like(CheckClap::getCreateName,checkClapBo.getSearchValue()));
  158. }
  159. if(StringUtils.isNotNull(checkClapBo.getDeptId())){
  160. wrapperClap.lambda().eq(CheckClap::getDeptId,checkClapBo.getDeptId());
  161. }
  162. wrapperClap.ge(StringUtils.isNotEmpty(checkClapBo.getBeginTime()),"create_time",checkClapBo.getBeginTime())
  163. .le(StringUtils.isNotEmpty(checkClapBo.getEndTime()),"create_time",checkClapBo.getEndTime());
  164. //过滤物理删除数据及倒叙
  165. if(StringUtils.isNotNull(checkClapBo.getUpTimeOrder()) && 1==checkClapBo.getUpTimeOrder().intValue()){
  166. wrapperClap.lambda().orderByAsc(CheckClap::getCreateTime);
  167. }else if(StringUtils.isNotNull(checkClapBo.getUpTimeOrder()) && 2==checkClapBo.getUpTimeOrder().intValue()){
  168. wrapperClap.lambda().orderByDesc(CheckClap::getCreateTime);
  169. }else if(StringUtils.isNotNull(checkClapBo.getZgTimeOrder()) && 1==checkClapBo.getZgTimeOrder().intValue()){
  170. wrapperClap.lambda().orderByAsc(CheckClap::getRectifyTime);
  171. }else if(StringUtils.isNotNull(checkClapBo.getZgTimeOrder()) && 2==checkClapBo.getZgTimeOrder().intValue()){
  172. wrapperClap.lambda().orderByDesc(CheckClap::getRectifyTime);
  173. }else{
  174. wrapperClap.lambda().orderByDesc(CheckClap::getId);
  175. }
  176. wrapperClap.lambda().eq(CheckClap::getIsDeleted, Boolean.FALSE).eq(CheckClap::getCreateBy,SecurityUtils.getUserId());
  177. Page <CheckClap> page = checkClapService.page(new Page<>(checkClapBo.getPageNum(), checkClapBo.getPageSize()), wrapperClap);
  178. List<CheckClapVo> checkClapVoList = com.zd.common.core.utils.BeanUtils.copyList2List(page.getRecords(), CheckClapVo.class);
  179. BeanUtils.copyProperties(page.getRecords(),checkClapVoList);
  180. Page <CheckClapVo> pageVo = new Page <>();
  181. BeanUtils.copyProperties(page,pageVo);
  182. pageVo.setRecords(checkClapVoList);
  183. Optional.ofNullable(pageVo.getRecords()).orElseGet(Collections::emptyList)
  184. .stream()
  185. .forEach(a->{
  186. timeProcessing(a);
  187. });
  188. return ResultData.success(pageVo);
  189. }
  190. /**
  191. * 添加数据
  192. * @param checkClapBo
  193. * @return
  194. */
  195. @PreAuthorize(hasPermi = PerPrefix.SECURITY_CLAP + PerFun.ADD)
  196. @Log(title = "安全服务-随手拍添加", businessType = BusinessType.INSERT)
  197. @PostMapping(value = "/add")
  198. public ResultData add(@RequestBody CheckClapBo checkClapBo) {
  199. //参数检查
  200. paramCheck.notNull(checkClapBo)
  201. .notNull(checkClapBo.getDeptId())
  202. .notNull(checkClapBo.getSubId())
  203. .notNull(checkClapBo.getImgDtoList());
  204. //请求实验室的服务接口,实验室的安全责任人用户id
  205. List<Long> subIds = new ArrayList <>();
  206. subIds.add(checkClapBo.getSubId());
  207. R <List <LabSubjectEntity>> subList = remoteSubQueryService.listByIds(subIds);
  208. StringBuilder userNames = new StringBuilder();
  209. Long[] adminInfo = new Long[2];
  210. if(subList.getCode()==200 && subList.getData().size()>0){
  211. adminInfo[0] = subList.getData().get(0).getId();
  212. adminInfo[1] = subList.getData().get(0).getAdminId();
  213. String[] safeUserIds = subList.getData().get(0).getSafeUserId().split(",");
  214. for(int i=0;i<safeUserIds.length;i++){
  215. if(StringUtils.isNotEmpty(safeUserIds[i])){
  216. ResultData<Map <String,Object>> userInfo = remoteUserService.getUserMapInfoByUserId(Long.parseLong(safeUserIds[i]));
  217. if(userInfo.getCode()==200){
  218. userNames.append(",");
  219. userNames.append(userInfo.getData().get("userName"));
  220. }
  221. }
  222. }
  223. }
  224. CheckClap checkClap = new CheckClap();
  225. BeanUtils.copyProperties(checkClapBo,checkClap);
  226. checkClap.setRoomNum(subList.getData().get(0).getRoom());
  227. if(userNames.length()>0){
  228. checkClap.setSafetyPeople(userNames.substring(1));
  229. }
  230. //这里需要先去根据实验室id,查询检查人员配置的整改人员信息,如果有,就是查询回来的这个人整改,如果没有,就默认当前实验室的负责人
  231. checkClap.setCanRectifyIds(rectUserInfo(adminInfo));
  232. checkClap.setIsDeleted(Boolean.FALSE);
  233. checkClap.setCreateName(SecurityUtils.getNickName());
  234. if(checkClapService.save(checkClap)) {
  235. //保存成功后,需要调用上传图片的功能
  236. Optional.ofNullable(checkClapBo.getImgDtoList()).orElseGet(Collections::emptyList)
  237. .stream()
  238. .forEach(a->{
  239. a.setKeyId(checkClap.getId());
  240. a.setFileType(2);
  241. a.setSource(4);
  242. uploadService.addUpload(a);
  243. });
  244. return ResultData.success("操作成功");
  245. }
  246. return ResultData.fail("操作失败");
  247. }
  248. /**
  249. * 添加数据(小程序接口)
  250. * @param checkClapBo
  251. * @return
  252. */
  253. @Log(title = "安全服务-随手拍添加", businessType = BusinessType.INSERT)
  254. @PostMapping(value = "/appAdd")
  255. public ResultData appAdd(@RequestBody CheckClapBo checkClapBo) {
  256. //参数检查
  257. paramCheck.notNull(checkClapBo)
  258. .notNull(checkClapBo.getDeptId())
  259. .notNull(checkClapBo.getSubId())
  260. .notNull(checkClapBo.getImgDtoList());
  261. //请求实验室的服务接口,实验室的安全责任人用户id
  262. List<Long> subIds = new ArrayList <>();
  263. subIds.add(checkClapBo.getSubId());
  264. R <List <LabSubjectEntity>> subList = remoteSubQueryService.listByIds(subIds);
  265. StringBuilder userNames = new StringBuilder();
  266. Long[] adminInfo = new Long[2];
  267. if(subList.getCode()==200 && subList.getData().size()>0){
  268. adminInfo[0] = subList.getData().get(0).getId();
  269. adminInfo[1] = subList.getData().get(0).getAdminId();
  270. String[] safeUserIds = subList.getData().get(0).getSafeUserId().split(",");
  271. for(int i=0;i<safeUserIds.length;i++){
  272. if(StringUtils.isNotEmpty(safeUserIds[i])){
  273. ResultData<Map <String,Object>> userInfo = remoteUserService.getUserMapInfoByUserId(Long.parseLong(safeUserIds[i]));
  274. if(userInfo.getCode()==200){
  275. userNames.append(",");
  276. userNames.append(userInfo.getData().get("userName"));
  277. }
  278. }
  279. }
  280. }
  281. CheckClap checkClap = new CheckClap();
  282. BeanUtils.copyProperties(checkClapBo,checkClap);
  283. checkClap.setRoomNum(subList.getData().get(0).getRoom());
  284. if(userNames.length()>0){
  285. checkClap.setSafetyPeople(userNames.substring(1));
  286. }
  287. //这里需要先去根据实验室id,查询检查人员配置的整改人员信息,如果有,就是查询回来的这个人整改,如果没有,就默认当前实验室的负责人
  288. checkClap.setCanRectifyIds(rectUserInfo(adminInfo));
  289. checkClap.setIsDeleted(Boolean.FALSE);
  290. checkClap.setCreateName(SecurityUtils.getNickName());
  291. if(checkClapService.save(checkClap)) {
  292. //保存成功后,需要调用上传图片的功能
  293. Optional.ofNullable(checkClapBo.getImgDtoList()).orElseGet(Collections::emptyList)
  294. .stream()
  295. .forEach(a->{
  296. a.setKeyId(checkClap.getId());
  297. a.setFileType(2);
  298. a.setSource(4);
  299. uploadService.addUpload(a);
  300. });
  301. return ResultData.success("操作成功");
  302. }
  303. return ResultData.fail("操作失败");
  304. }
  305. public String rectUserInfo(Long[] adminInfo){
  306. //查询条件
  307. QueryWrapper <CheckStaffUser> wrapperUser = new QueryWrapper <>();
  308. //过滤物理删除数据及正序叙
  309. wrapperUser.lambda().eq(CheckStaffUser::getIsDeleted, Boolean.FALSE).eq(CheckStaffUser::getStaffType,2)
  310. .eq(CheckStaffUser::getSubId,adminInfo[0]);
  311. List<CheckStaffUser> userList = checkStaffUserService.list(wrapperUser);
  312. StringBuilder userIds = new StringBuilder();
  313. if(userList!=null && !userList.isEmpty()){
  314. Optional.ofNullable(userList).orElseGet(Collections::emptyList)
  315. .stream()
  316. .forEach(a->{
  317. userIds.append(",");
  318. userIds.append(a.getUserId());
  319. });
  320. }else{
  321. userIds.append(adminInfo[1]);
  322. }
  323. if(userIds.length()>0){
  324. return userIds.substring(1);
  325. }
  326. return "";
  327. }
  328. /**
  329. * 通过ID获取
  330. * @param id
  331. * @return
  332. */
  333. @PreAuthorize(hasPermi = PerPrefix.SECURITY_CLAP + PerFun.QUERY)
  334. @GetMapping(value = "/findById")
  335. public ResultData find(Long id) {
  336. CheckClap checkClap = checkClapService.getById(id);
  337. CheckClapVo checkClapVo = new CheckClapVo();
  338. BeanUtils.copyProperties(checkClap,checkClapVo);
  339. checkClapVo.setYhDtoList(funDto(checkClapVo.getId(),4));
  340. checkClapVo.setZgDtoList(funDto(checkClapVo.getId(),5));
  341. //这里需要校验一下,查看的时候,是否有身份整改当前的这条数据。
  342. Predicate <String> predicate = a->Arrays.asList(a.split(",")).stream().filter(b->b.equals(getCurrentUserId()+"")).count()>0;
  343. if(StringUtils.isNotNull(checkClap.getCanRectifyIds()) && predicate.test(checkClap.getCanRectifyIds())){
  344. checkClapVo.setRectifyGentle(Boolean.TRUE);
  345. }else{
  346. checkClapVo.setRectifyGentle(Boolean.FALSE);
  347. }
  348. return ResultData.success(checkClapVo);
  349. }
  350. /**
  351. * 通过ID获取(小程序接口)
  352. * @param id
  353. * @return
  354. */
  355. @GetMapping(value = "/appFindById")
  356. public ResultData appFindById(Long id) {
  357. CheckClap checkClap = checkClapService.getById(id);
  358. CheckClapVo checkClapVo = new CheckClapVo();
  359. BeanUtils.copyProperties(checkClap,checkClapVo);
  360. checkClapVo.setYhDtoList(funDto(checkClapVo.getId(),4));
  361. checkClapVo.setZgDtoList(funDto(checkClapVo.getId(),5));
  362. //这里需要校验一下,查看的时候,是否有身份整改当前的这条数据。
  363. Predicate <String> predicate = a->Arrays.asList(a.split(",")).stream().filter(b->b.equals(getCurrentUserId()+"")).count()>0;
  364. if(StringUtils.isNotNull(checkClap.getCanRectifyIds()) && predicate.test(checkClap.getCanRectifyIds())){
  365. checkClapVo.setRectifyGentle(Boolean.TRUE);
  366. }else{
  367. checkClapVo.setRectifyGentle(Boolean.FALSE);
  368. }
  369. return ResultData.success(checkClapVo);
  370. }
  371. public List<UploadDto> funDto(Long id,Integer source){
  372. Function <List<Upload>,List<UploadDto>> function = fun->Optional.ofNullable(fun).orElseGet(Collections::emptyList)
  373. .stream()
  374. .map(a->{
  375. UploadDto uploadDto = new UploadDto();
  376. BeanUtils.copyProperties(a,uploadDto);
  377. uploadDto.setFileUrl(uploadDto.getFileUrl());
  378. uploadDto.setViewFileUrl(fileConfigUtils.getFileDomainAdmin()+uploadDto.getFileUrl());
  379. return uploadDto;
  380. }).collect(Collectors.toList());
  381. QueryWrapper <Upload> uploadWrap = new QueryWrapper <>();
  382. uploadWrap.lambda().eq(Upload::getSource,source).eq(Upload::getKeyId,id);
  383. List<Upload> uploadList = uploadService.list(uploadWrap);
  384. return function.apply(uploadList);
  385. }
  386. @Log(title = "安全服务-随手拍审核", businessType = BusinessType.UPDATE)
  387. @PostMapping(value = "/clapApprove")
  388. public ResultData update(@RequestBody CheckClapBo checkClapBo) {
  389. //参数检查
  390. paramCheck.notNull(checkClapBo).notNull(checkClapBo.getRectifyStatus());
  391. CheckClap checkClap = new CheckClap();
  392. BeanUtils.copyProperties(checkClapBo,checkClap);
  393. checkClap.setRectifyTime(LocalDateTime.now());
  394. checkClap.setRectifyId(getCurrentUserId());
  395. checkClap.setRectifyPeople(SecurityUtils.getNickName());
  396. if(checkClapService.saveOrUpdate(checkClap)) {
  397. //这里需要上传整改或无法整改照片。稍后补充
  398. Optional.ofNullable(checkClapBo.getImgDtoList()).orElseGet(Collections::emptyList)
  399. .stream()
  400. .forEach(a->{
  401. a.setKeyId(checkClap.getId());
  402. a.setFileType(2);
  403. a.setSource(5);
  404. uploadService.addUpload(a);
  405. });
  406. return ResultData.success("操作成功");
  407. }
  408. return ResultData.fail("操作失败");
  409. }
  410. }