package com.zd.security.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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.FileConfigUtils;
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.CheckHazardBo;
import com.zd.security.api.dto.CheckHazardApplyDto;
import com.zd.security.api.dto.UploadDto;
import com.zd.security.api.vo.CheckHazardApplyVo;
import com.zd.security.api.vo.CheckHazardVo;
import com.zd.security.api.vo.CheckManageVo;
import com.zd.security.api.vo.CheckRectifyApplyVo;
import com.zd.security.entity.*;
import com.zd.security.scope.DataPermission;
import com.zd.security.scope.DataPermissionAspect;
import com.zd.security.service.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
*
* 隐患表 前端控制器
*
*
* @author cyl
* @since 2023-04-19
*/
@RestController
@RequestMapping("/checkHazard")
public class CheckHazardController extends AbstractController {
@Autowired
private CheckHazardService checkHazardService;
@Autowired
private CheckRectifyService checkRectifyService;
@Autowired
private CheckManageService checkManageService;
@Autowired
private UploadService uploadService;
@Autowired
private FileConfigUtils fileConfigUtils;
@Autowired
private CheckStaffUserService checkStaffUserService;
@Autowired
private CheckMemberService checkMemberService;
/**
* 通过巡查管理Id获取
* @param checkHazard
* @return
*/
@GetMapping(value = "/findByCheckHazardList")
public ResultData find(CheckHazard checkHazard) {
//查询条件
QueryWrapper wrapper = new QueryWrapper <>();
//过滤物理删除数据及正序叙
wrapper.lambda().eq(CheckHazard::getIsDeleted, Boolean.FALSE)
.eq(CheckHazard::getCheckManageId,checkHazard.getCheckManageId()).orderByAsc(CheckHazard::getId);
List checkHazardList = checkHazardService.list(wrapper);
return ResultData.success(checkHazardList);
}
/**
* 添加数据
* @param checkHazardBo
* @return
*/
@Log(title = "安全服务-测试添加", businessType = BusinessType.INSERT)
@PostMapping(value = "/add")
public ResultData add(@RequestBody CheckHazardBo checkHazardBo) {
Optional.ofNullable(checkHazardBo.getCheckHazardDtoList()).orElseGet(Collections::emptyList)
.stream()
.forEach(a->{
//参数检查
paramCheck.notNull(a)
.notNull(a.getHazardLevel())
.strNotEmpty(a.getHazardCheckPro())
.strNotEmpty(a.getHazardDescribe());
});
checkHazardService.addHazard(checkHazardBo);
return ResultData.success("操作成功");
}
/**
* 获取数据列表list(院校巡查和实验室自查)
* @param checkHazardBo
* @return
*/
@DataPermission()
@PreAuthorize(hasPermi = PerPrefix.SECURITY_CHECKHAZARD + PerFun.LIST)
@GetMapping(value = "/list")
public ResultData list(CheckHazardBo checkHazardBo) {
//参数检查
List userList = DataPermissionAspect.threadLocal.get(); // 获取数据
checkHazardBo.setUserList(userList);
DataPermissionAspect.threadLocal.remove();
Page page = checkHazardService.checkHazardList(checkHazardBo);
return ResultData.success(page);
}
/**
* 获取数据列表list(院校巡查和实验室自查)已完成
* @param checkHazardBo
* @return
*/
@DataPermission()
@PreAuthorize(hasPermi = PerPrefix.SECURITY_CHECKHAZARD + PerFun.LIST)
@GetMapping(value = "/overList")
public ResultData overList(CheckHazardBo checkHazardBo) {
//参数检查
List userList = DataPermissionAspect.threadLocal.get(); // 获取数据
checkHazardBo.setUserList(userList);
DataPermissionAspect.threadLocal.remove();
Page page = checkHazardService.overList(checkHazardBo);
return ResultData.success(page);
}
/**
* 获取数据列表list(院校巡查和实验室自查)待整改
* @param checkHazardBo
* @return
*/
@DataPermission(roleKey="rectifyGentle")
@PreAuthorize(hasPermi = PerPrefix.SECURITY_CHECKHAZARD + PerFun.LIST)
@GetMapping(value = "/rectifyList")
public ResultData rectifyList(CheckHazardBo checkHazardBo) {
//参数检查
List userList = DataPermissionAspect.threadLocal.get(); // 获取数据
checkHazardBo.setUserList(userList);
DataPermissionAspect.threadLocal.remove();
Page page = checkHazardService.rectifyList(checkHazardBo);
return ResultData.success(page);
}
/**
* 获取数据列表list(院校巡查和实验室自查)待复核
* @param checkHazardBo
* @return
*/
@DataPermission(roleKey="checkGentle")
@PreAuthorize(hasPermi = PerPrefix.SECURITY_CHECKHAZARD + PerFun.LIST)
@GetMapping(value = "/recheckList")
public ResultData recheckList(CheckHazardBo checkHazardBo) {
//参数检查
List userList = DataPermissionAspect.threadLocal.get(); // 获取数据
checkHazardBo.setUserList(userList);
DataPermissionAspect.threadLocal.remove();
Page page = checkHazardService.recheckList(checkHazardBo);
return ResultData.success(page);
}
/**
* 获取数据列表list(小程序接口)
* @param checkHazardBo
* @return
*/
@DataPermission()
@GetMapping(value = "/appHazardList")
public ResultData appHazardList(CheckHazardBo checkHazardBo) {
//参数检查
List userList = DataPermissionAspect.threadLocal.get(); // 获取数据
checkHazardBo.setUserList(userList);
DataPermissionAspect.threadLocal.remove();
Page page = checkHazardService.checkHazardList(checkHazardBo);
return ResultData.success(page);
}
/**
* 获取数据列表list(批量审批查询列表)
* @param checkHazardBo
* @return
*/
@PreAuthorize(hasPermi = PerPrefix.SECURITY_CHECKHAZARD + PerFun.APPROVE)
@GetMapping(value = "/batchApprovalList")
public ResultData batchApprovalList(CheckHazardBo checkHazardBo) {
checkHazardBo.setUserId(getCurrentUserId());
Page page = checkHazardService.batchApprovalList(checkHazardBo);
return ResultData.success(page);
}
/**
* 获取数据列表list(院校巡查和实验室自查)
* @param checkHazardBo
* @return
*/
@PreAuthorize(hasPermi = PerPrefix.SECURITY_CHECKHAZARD + PerFun.LIST)
@GetMapping(value = "/appList")
public ResultData appList(CheckHazardBo checkHazardBo) {
Page page = checkHazardService.checkHazardAppList(checkHazardBo);
return ResultData.success(page);
}
/**
* 获取数据列表list(小程序接口)
* @param checkHazardBo
* @return
*/
@GetMapping(value = "/appCheckHazardList")
public ResultData appCheckHazardList(CheckHazardBo checkHazardBo) {
checkHazardBo.setAppFlag(1);
Page page = checkHazardService.checkHazardAppList(checkHazardBo);
return ResultData.success(page);
}
/**
* 获取数据详情(院校巡查和实验室自查)
* @param id
* @return
*/
@PreAuthorize(hasPermi = PerPrefix.SECURITY_CHECKHAZARD + PerFun.QUERY)
@GetMapping(value = "/getHazardById")
public ResultData getHazardById(Long id){
CheckHazardApplyVo checkHazardApplyVo = new CheckHazardApplyVo();
CheckHazard checkHazard = checkHazardService.getById(id);
StringBuilder stringBuffer = new StringBuilder();
if(StringUtils.isNotNull(checkHazard.getHazardCheckCode1())){
stringBuffer.append(checkHazard.getHazardCheckCode1()+""+checkHazard.getHazardCheckName1());
}
if(StringUtils.isNotNull(checkHazard.getHazardCheckCode2())){
stringBuffer.append("—"+checkHazard.getHazardCheckCode2()+""+checkHazard.getHazardCheckName2());
}
if(StringUtils.isNotNull(checkHazard.getHazardCheckCode3())){
stringBuffer.append("—"+checkHazard.getHazardCheckCode3()+""+checkHazard.getHazardCheckName3());
}
if(StringUtils.isNotNull(checkHazard.getHazardCheckCode())){
stringBuffer.append("—"+checkHazard.getHazardCheckCode()+""+checkHazard.getHazardCheckName());
}
//查询巡查管理的基础数据
CheckManageVo checkManageVo = checkManageService.findCheckManage(checkHazard.getCheckManageId());
BeanUtils.copyProperties(checkManageVo,checkHazardApplyVo);
//复制整改数据到大的对象里
BeanUtils.copyProperties(checkHazard,checkHazardApplyVo.getCheckHazardApplyDto());
CheckHazardBo checkHazardBo = new CheckHazardBo();
checkHazardBo.setSubId(checkManageVo.getSubId());
checkHazardBo.setHazardCheckPro(checkHazard.getHazardCheckPro());
//这里需要统计检查项历史数据
checkHazardApplyVo.getCheckHazardApplyDto().setHazardCheckCount(checkHazardService.countHazardNum(checkHazardBo));
if(StringUtils.isNotNull(stringBuffer)){
checkHazardApplyVo.getCheckHazardApplyDto().setHazardCheckProStr(stringBuffer.toString());
}
//这里需要查询身份
getRectifyCheck(checkHazardApplyVo.getCheckHazardApplyDto(),checkManageVo.getSubId(),checkHazard.getHazardType(),checkManageVo.getCheckPlanId());
//补全图片查询
if(checkHazardApplyVo.getCheckHazardApplyDto()!=null){
QueryWrapper uploadWrap = new QueryWrapper <>();
uploadWrap.lambda().eq(Upload::getSource,2).eq(Upload::getKeyId,checkHazardApplyVo.getCheckHazardApplyDto().getId());
List uploadList = uploadService.list(uploadWrap);
Function ,List> function = fun->Optional.ofNullable(fun).orElseGet(Collections::emptyList)
.stream()
.map(a->{
UploadDto uploadDto = new UploadDto();
BeanUtils.copyProperties(a,uploadDto);
uploadDto.setFileUrl(uploadDto.getFileUrl());
uploadDto.setViewFileUrl(fileConfigUtils.getFileDomainAdmin()+uploadDto.getFileUrl());
return uploadDto;
}).collect(Collectors.toList());
checkHazardApplyVo.getCheckHazardApplyDto().setUploadDtoList(function.apply(uploadList));
}
//查询条件
QueryWrapper wrapper = new QueryWrapper <>();
if(StringUtils.isNotNull(checkHazard.getId())){
wrapper.lambda().eq(CheckRectify::getIsDeleted,Boolean.FALSE)
.eq(CheckRectify::getCheckHazardId,checkHazard.getId())
.orderByAsc(CheckRectify::getId);
List checkRectify = checkRectifyService.list(wrapper);
if(checkRectify!=null && !checkRectify.isEmpty()){
for(CheckRectify checkRectify1:checkRectify){
if(StringUtils.isNotNull(checkRectify1.getReviewedBy())){
//拆分整改内容
CheckRectifyApplyVo checkRectifyApplyVo = new CheckRectifyApplyVo();
checkRectifyApplyVo.setApplyFlag(1);
checkRectifyApplyVo.setId(checkRectify1.getId());
checkRectifyApplyVo.setRectifyType(checkRectify1.getRectifyType());
checkRectifyApplyVo.setRectifyResult(checkRectify1.getRectifyResult());
checkRectifyApplyVo.setRectifyMeasure(checkRectify1.getRectifyMeasure());
checkRectifyApplyVo.setCreateBy(checkRectify1.getCreateBy());
checkRectifyApplyVo.setCreateName(checkRectify1.getCreateName());
checkRectifyApplyVo.setCreateTime(checkRectify1.getCreateTime());
checkHazardApplyVo.getCheckRectifyApplyList().add(checkRectifyApplyVo);
//查询整改图片
checkRectifyApplyVo.setUploadDtoList(funDto(checkRectify1.getId()));
//拆分复核内容
CheckRectifyApplyVo checkRectifyExamineVo = new CheckRectifyApplyVo();
checkRectifyExamineVo.setApplyFlag(2);
checkRectifyExamineVo.setExamineResult(checkRectify1.getExamineResult());
checkRectifyExamineVo.setExamineOpinion(checkRectify1.getExamineOpinion());
checkRectifyExamineVo.setReviewedBy(checkRectify1.getReviewedBy());
checkRectifyExamineVo.setReviewedName(checkRectify1.getReviewedName());
checkRectifyExamineVo.setReviewedTime(checkRectify1.getReviewedTime());
checkHazardApplyVo.getCheckRectifyApplyList().add(checkRectifyExamineVo);
}else{
//整改内容
CheckRectifyApplyVo checkRectifyApplyVo = new CheckRectifyApplyVo();
checkRectifyApplyVo.setApplyFlag(1);
checkRectifyApplyVo.setId(checkRectify1.getId());
checkRectifyApplyVo.setRectifyType(checkRectify1.getRectifyType());
checkRectifyApplyVo.setRectifyResult(checkRectify1.getRectifyResult());
checkRectifyApplyVo.setRectifyMeasure(checkRectify1.getRectifyMeasure());
checkHazardApplyVo.getCheckRectifyApplyList().add(checkRectifyApplyVo);
checkRectifyApplyVo.setCreateBy(checkRectify1.getCreateBy());
checkRectifyApplyVo.setCreateName(checkRectify1.getCreateName());
checkRectifyApplyVo.setCreateTime(checkRectify1.getCreateTime());
//查询整改图片
checkRectifyApplyVo.setUploadDtoList(funDto(checkRectify1.getId()));
}
}
}
}
checkHazardApplyVo.setRectifyNotice(checkManageVo.getRectifyNotice());
return ResultData.success(checkHazardApplyVo);
}
/**
* 获取数据详情(小程序接口)
* @param id
* @return
*/
@GetMapping(value = "/getAppHazardById")
public ResultData getAppHazardById(Long id){
CheckHazardApplyVo checkHazardApplyVo = new CheckHazardApplyVo();
CheckHazard checkHazard = checkHazardService.getById(id);
StringBuilder stringBuffer = new StringBuilder();
if(StringUtils.isNotNull(checkHazard.getHazardCheckCode1())){
stringBuffer.append(checkHazard.getHazardCheckCode1()+""+checkHazard.getHazardCheckName1());
}
if(StringUtils.isNotNull(checkHazard.getHazardCheckCode2())){
stringBuffer.append("—"+checkHazard.getHazardCheckCode2()+""+checkHazard.getHazardCheckName2());
}
if(StringUtils.isNotNull(checkHazard.getHazardCheckCode3())){
stringBuffer.append("—"+checkHazard.getHazardCheckCode3()+""+checkHazard.getHazardCheckName3());
}
if(StringUtils.isNotNull(checkHazard.getHazardCheckCode())){
stringBuffer.append("—"+checkHazard.getHazardCheckCode()+""+checkHazard.getHazardCheckName());
}
//查询巡查管理的基础数据
CheckManageVo checkManageVo = checkManageService.findCheckManage(checkHazard.getCheckManageId());
BeanUtils.copyProperties(checkManageVo,checkHazardApplyVo);
//复制整改数据到大的对象里
BeanUtils.copyProperties(checkHazard,checkHazardApplyVo.getCheckHazardApplyDto());
CheckHazardBo checkHazardBo = new CheckHazardBo();
checkHazardBo.setSubId(checkManageVo.getSubId());
checkHazardBo.setHazardCheckPro(checkHazard.getHazardCheckPro());
//这里需要统计检查项历史数据
checkHazardApplyVo.getCheckHazardApplyDto().setHazardCheckCount(checkHazardService.countHazardNum(checkHazardBo));
if(StringUtils.isNotNull(stringBuffer)){
checkHazardApplyVo.getCheckHazardApplyDto().setHazardCheckProStr(stringBuffer.toString());
}
//这里需要查询身份
getRectifyCheck(checkHazardApplyVo.getCheckHazardApplyDto(),checkManageVo.getSubId(),checkHazard.getHazardType(),checkManageVo.getCheckPlanId());
//补全图片查询
if(checkHazardApplyVo.getCheckHazardApplyDto()!=null){
QueryWrapper uploadWrap = new QueryWrapper <>();
uploadWrap.lambda().eq(Upload::getSource,2).eq(Upload::getKeyId,checkHazardApplyVo.getCheckHazardApplyDto().getId());
List uploadList = uploadService.list(uploadWrap);
Function ,List> function = fun->Optional.ofNullable(fun).orElseGet(Collections::emptyList)
.stream()
.map(a->{
UploadDto uploadDto = new UploadDto();
BeanUtils.copyProperties(a,uploadDto);
uploadDto.setFileUrl(uploadDto.getFileUrl());
uploadDto.setViewFileUrl(fileConfigUtils.getFileDomainAdmin()+uploadDto.getFileUrl());
return uploadDto;
}).collect(Collectors.toList());
checkHazardApplyVo.getCheckHazardApplyDto().setUploadDtoList(function.apply(uploadList));
}
//查询条件
QueryWrapper wrapper = new QueryWrapper <>();
if(StringUtils.isNotNull(checkHazard.getId())){
wrapper.lambda().eq(CheckRectify::getIsDeleted,Boolean.FALSE)
.eq(CheckRectify::getCheckHazardId,checkHazard.getId())
.orderByAsc(CheckRectify::getId);
List checkRectify = checkRectifyService.list(wrapper);
if(checkRectify!=null && !checkRectify.isEmpty()){
for(CheckRectify checkRectify1:checkRectify){
if(StringUtils.isNotNull(checkRectify1.getReviewedBy())){
//拆分整改内容
CheckRectifyApplyVo checkRectifyApplyVo = new CheckRectifyApplyVo();
checkRectifyApplyVo.setApplyFlag(1);
checkRectifyApplyVo.setId(checkRectify1.getId());
checkRectifyApplyVo.setRectifyType(checkRectify1.getRectifyType());
checkRectifyApplyVo.setRectifyResult(checkRectify1.getRectifyResult());
checkRectifyApplyVo.setRectifyMeasure(checkRectify1.getRectifyMeasure());
checkRectifyApplyVo.setCreateBy(checkRectify1.getCreateBy());
checkRectifyApplyVo.setCreateName(checkRectify1.getCreateName());
checkRectifyApplyVo.setCreateTime(checkRectify1.getCreateTime());
checkHazardApplyVo.getCheckRectifyApplyList().add(checkRectifyApplyVo);
//查询整改图片
checkRectifyApplyVo.setUploadDtoList(funDto(checkRectify1.getId()));
//拆分复核内容
CheckRectifyApplyVo checkRectifyExamineVo = new CheckRectifyApplyVo();
checkRectifyExamineVo.setApplyFlag(2);
checkRectifyExamineVo.setExamineResult(checkRectify1.getExamineResult());
checkRectifyExamineVo.setExamineOpinion(checkRectify1.getExamineOpinion());
checkRectifyExamineVo.setReviewedBy(checkRectify1.getReviewedBy());
checkRectifyExamineVo.setReviewedName(checkRectify1.getReviewedName());
checkRectifyExamineVo.setReviewedTime(checkRectify1.getReviewedTime());
checkHazardApplyVo.getCheckRectifyApplyList().add(checkRectifyExamineVo);
}else{
//整改内容
CheckRectifyApplyVo checkRectifyApplyVo = new CheckRectifyApplyVo();
checkRectifyApplyVo.setApplyFlag(1);
checkRectifyApplyVo.setId(checkRectify1.getId());
checkRectifyApplyVo.setRectifyType(checkRectify1.getRectifyType());
checkRectifyApplyVo.setRectifyResult(checkRectify1.getRectifyResult());
checkRectifyApplyVo.setRectifyMeasure(checkRectify1.getRectifyMeasure());
checkHazardApplyVo.getCheckRectifyApplyList().add(checkRectifyApplyVo);
checkRectifyApplyVo.setCreateBy(checkRectify1.getCreateBy());
checkRectifyApplyVo.setCreateName(checkRectify1.getCreateName());
checkRectifyApplyVo.setCreateTime(checkRectify1.getCreateTime());
//查询整改图片
checkRectifyApplyVo.setUploadDtoList(funDto(checkRectify1.getId()));
}
}
}
}
return ResultData.success(checkHazardApplyVo);
}
//查询登录人当前的隐患是否有整改身份和检查身份
private void getRectifyCheck(CheckHazardApplyDto applyDto,Long subId,Integer hazardType,Long checkPlanId){
if(hazardType.intValue()==2){
//查询自查检查身份
List checkStaffUserAppList = checkStaffUserService.list(new LambdaQueryWrapper ()
.eq(CheckStaffUser::getUserId,getCurrentUserId()).eq(CheckStaffUser::getStaffType,1)
.eq(CheckStaffUser::getSubId,subId));
if(checkStaffUserAppList!=null && !checkStaffUserAppList.isEmpty()){
applyDto.setApplyGentle(Boolean.TRUE);
}
}else{
//查询院校巡查身份
List checkMemberList = checkMemberService.list(new LambdaQueryWrapper ()
.eq(CheckMember::getCheckPlanId,checkPlanId).eq(CheckMember::getUserId,getCurrentUserId()));
if(checkMemberList!=null && !checkMemberList.isEmpty()){
applyDto.setApplyGentle(Boolean.TRUE);
}
}
//查询整改身份
List checkStaffUserRecList = checkStaffUserService.list(new LambdaQueryWrapper ()
.eq(CheckStaffUser::getUserId,getCurrentUserId()).eq(CheckStaffUser::getStaffType,2)
.eq(CheckStaffUser::getSubId,subId));
if(checkStaffUserRecList!=null && !checkStaffUserRecList.isEmpty()){
applyDto.setRectifyGentle(Boolean.TRUE);
}
}
public List funDto(Long id){
Function,List> function = fun->Optional.ofNullable(fun).orElseGet(Collections::emptyList)
.stream()
.map(a->{
UploadDto uploadDto = new UploadDto();
BeanUtils.copyProperties(a,uploadDto);
return uploadDto;
}).collect(Collectors.toList());
QueryWrapper uploadWrap = new QueryWrapper <>();
uploadWrap.lambda().eq(Upload::getSource,3).eq(Upload::getKeyId,id);
List uploadList = uploadService.list(uploadWrap);
return function.apply(uploadList);
}
/**
* 获取数据列表list(暂无法整改)
* @param checkHazardBo
* @return
*/
@DataPermission()
@PreAuthorize(hasPermi = PerPrefix.SECURITY_CHECKHAZARD + PerFun.LIST)
@GetMapping(value = "/unableRectifyList")
public ResultData unableRectifyList(CheckHazardBo checkHazardBo) {
//参数检查
List userList = DataPermissionAspect.threadLocal.get(); // 获取数据
checkHazardBo.setUserList(userList);
DataPermissionAspect.threadLocal.remove();
Page page = checkHazardService.unableRectifyList(checkHazardBo);;
return ResultData.success(page);
}
/**
* 统计隐患数量
* @param checkHazardBo
* @return
*/
@GetMapping(value = "/countHazardNum")
public ResultData countHazardNum(CheckHazardBo checkHazardBo) {
return ResultData.success(checkHazardService.countHazardNum(checkHazardBo));
}
/**
* 统计隐患数量
* @param checkHazardBo
* @return
*/
@GetMapping(value = "/rectifySchedule")
public ResultData rectifySchedule(CheckHazardBo checkHazardBo) {
return ResultData.success(checkHazardService.rectifySchedule(checkHazardBo.getCheckManageId()));
}
/**
* 安全隐患整改逾期数据标记
* @return
*/
@GetMapping(value = "/overdue")
public ResultData overdue() {
checkHazardService.overdue();
return ResultData.success();
}
}