package com.gkhy.labRiskManage.domain.basic.service.impl;
|
|
import com.gkhy.labRiskManage.api.controller.basic.dto.repDto.OldRiskAssessQueryReqBO;
|
import com.gkhy.labRiskManage.api.controller.basic.dto.respDto.OldRiskAssessQueryRespDTO;
|
import com.gkhy.labRiskManage.commons.domain.SearchResult;
|
import com.gkhy.labRiskManage.commons.enums.ResultCode;
|
import com.gkhy.labRiskManage.commons.enums.StatusEnum;
|
import com.gkhy.labRiskManage.commons.exception.BusinessException;
|
import com.gkhy.labRiskManage.commons.utils.BeanCopyUtils;
|
import com.gkhy.labRiskManage.domain.account.model.dto.UserInfoDomainDTO;
|
import com.gkhy.labRiskManage.domain.account.service.UserDomainService;
|
import com.gkhy.labRiskManage.domain.basic.entity.OldRiskAssess;
|
import com.gkhy.labRiskManage.domain.basic.repository.jpa.OldRiskAssessRepository;
|
import com.gkhy.labRiskManage.domain.basic.service.OldRiskAssessService;
|
import org.apache.poi.hssf.usermodel.*;
|
import org.apache.poi.ss.usermodel.*;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.Sort;
|
import org.springframework.data.jpa.domain.Specification;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.util.ObjectUtils;
|
import org.springframework.web.multipart.MultipartFile;
|
|
import javax.persistence.criteria.CriteriaBuilder;
|
import javax.persistence.criteria.CriteriaQuery;
|
import javax.persistence.criteria.Predicate;
|
import javax.persistence.criteria.Root;
|
import java.io.File;
|
import java.io.FileOutputStream;
|
import java.io.IOException;
|
import java.text.NumberFormat;
|
import java.time.LocalDateTime;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
|
/**
|
* 基础仪器设备表
|
*/
|
@Service
|
public class OldRiskAssessServiceImpl implements OldRiskAssessService {
|
|
@Autowired
|
private UserDomainService userDomainService;
|
|
@Autowired
|
private OldRiskAssessRepository repository;
|
|
|
|
@Override
|
public int insertOldRiskAssess(Long currentUserId, OldRiskAssess oldRiskAssess) {
|
|
if (ObjectUtils.isEmpty(oldRiskAssess)){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"要保存的数据不能为空");
|
}
|
if (ObjectUtils.isEmpty(oldRiskAssess.getRegion())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"区域不能为空");
|
}
|
if (ObjectUtils.isEmpty(oldRiskAssess.getPotentialAccident())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"潜在事故不能为空");
|
}
|
if (ObjectUtils.isEmpty(oldRiskAssess.getDangerReason())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"危险、危害因素不能为空");
|
}
|
if (ObjectUtils.isEmpty(oldRiskAssess.getTriggerFactor())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"触发条件不能为空");
|
}
|
if (ObjectUtils.isEmpty(oldRiskAssess.getAccidentResult())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"事故后果不能为空");
|
}
|
if (ObjectUtils.isEmpty(oldRiskAssess.getL())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"L数值不能为空");
|
}
|
if (ObjectUtils.isEmpty(oldRiskAssess.getD())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"D数值不能为空");
|
}
|
if (ObjectUtils.isEmpty(oldRiskAssess.getC())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"C数值不能为空");
|
}
|
if (ObjectUtils.isEmpty(oldRiskAssess.getE())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"E数值不能为空");
|
}
|
if (ObjectUtils.isEmpty(oldRiskAssess.getDangerLevel())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"危险等级不能为空");
|
}
|
if (ObjectUtils.isEmpty(oldRiskAssess.getControlMeasure())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"现有安全控制措施不能为空");
|
}
|
if (ObjectUtils.isEmpty(oldRiskAssess.getControlLevel())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"管控层级不能为空");
|
}
|
|
LocalDateTime nowDate = LocalDateTime.now();
|
oldRiskAssess.setUpdateTime(nowDate);
|
oldRiskAssess.setCreateTime(nowDate);
|
oldRiskAssess.setCreateByUserId(currentUserId);
|
oldRiskAssess.setUpdateByUserId(currentUserId);
|
oldRiskAssess.setDeleteStatus((byte)0);
|
|
OldRiskAssess saveResult = repository.save(oldRiskAssess);
|
if (ObjectUtils.isEmpty(saveResult)){
|
return StatusEnum.FAIL.getCode();
|
}
|
|
return StatusEnum.SUCCESS.getCode();
|
}
|
|
@Override
|
public int updateOldRiskAssess(Long currentUserId, OldRiskAssess oldRiskAssess) {
|
|
OldRiskAssess oldRiskAssessById = repository.getOldRiskAssessById(oldRiskAssess.getId());
|
if (ObjectUtils.isEmpty(oldRiskAssessById)){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"要修改的数据不存在,或已被删除");
|
}
|
if (ObjectUtils.isEmpty(oldRiskAssess.getRegion())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"区域不能为空");
|
}
|
if (ObjectUtils.isEmpty(oldRiskAssess.getPotentialAccident())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"潜在事故不能为空");
|
}
|
if (ObjectUtils.isEmpty(oldRiskAssess.getDangerReason())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"危险、危害因素不能为空");
|
}
|
if (ObjectUtils.isEmpty(oldRiskAssess.getTriggerFactor())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"触发条件不能为空");
|
}
|
if (ObjectUtils.isEmpty(oldRiskAssess.getAccidentResult())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"事故后果不能为空");
|
}
|
if (ObjectUtils.isEmpty(oldRiskAssess.getL())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"L数值不能为空");
|
}
|
if (ObjectUtils.isEmpty(oldRiskAssess.getD())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"D数值不能为空");
|
}
|
if (ObjectUtils.isEmpty(oldRiskAssess.getC())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"C数值不能为空");
|
}
|
if (ObjectUtils.isEmpty(oldRiskAssess.getE())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"E数值不能为空");
|
}
|
if (ObjectUtils.isEmpty(oldRiskAssess.getDangerLevel())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"危险等级不能为空");
|
}
|
if (ObjectUtils.isEmpty(oldRiskAssess.getControlMeasure())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"现有安全控制措施不能为空");
|
}
|
if (ObjectUtils.isEmpty(oldRiskAssess.getControlLevel())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"管控层级不能为空");
|
}
|
|
LocalDateTime nowDate = LocalDateTime.now();
|
oldRiskAssessById.setUpdateTime(nowDate);
|
oldRiskAssessById.setDeleteStatus((byte)0);
|
oldRiskAssessById.setUpdateByUserId(currentUserId);
|
oldRiskAssessById.setUpdateTime(nowDate);
|
|
oldRiskAssessById.setRegion(oldRiskAssess.getRegion());
|
oldRiskAssessById.setPotentialAccident(oldRiskAssess.getPotentialAccident());
|
oldRiskAssessById.setDangerReason(oldRiskAssess.getDangerReason());
|
oldRiskAssessById.setTriggerFactor(oldRiskAssess.getTriggerFactor());
|
oldRiskAssessById.setAccidentResult(oldRiskAssess.getAccidentResult());
|
oldRiskAssessById.setL(oldRiskAssess.getL());
|
oldRiskAssessById.setE(oldRiskAssess.getE());
|
oldRiskAssessById.setD(oldRiskAssess.getD());
|
oldRiskAssessById.setC(oldRiskAssess.getC());
|
oldRiskAssessById.setDangerLevel(oldRiskAssess.getDangerLevel());
|
oldRiskAssessById.setControlMeasure(oldRiskAssess.getControlMeasure());
|
oldRiskAssessById.setControlLevel(oldRiskAssess.getControlLevel());
|
|
OldRiskAssess saveResult = repository.save(oldRiskAssessById);
|
if (ObjectUtils.isEmpty(saveResult)){
|
return StatusEnum.FAIL.getCode();
|
}
|
|
return StatusEnum.SUCCESS.getCode();
|
}
|
|
@Override
|
public int deleteOldRiskAssess(Long currentUserId, Long id) {
|
if (currentUserId < 0){
|
throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"当前用户无效,请重新登陆");
|
}
|
if (ObjectUtils.isEmpty(id)){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"请选择正常的数据进行删除");
|
}
|
OldRiskAssess oldRiskAssessById = repository.getOldRiskAssessById(id);
|
if (ObjectUtils.isEmpty(oldRiskAssessById)){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"要删除的数据不存在,或已被删除");
|
}
|
UserInfoDomainDTO userInfoById = userDomainService.getUserInfoById(currentUserId);
|
|
LocalDateTime date = LocalDateTime.now();
|
//设置数据为删除
|
oldRiskAssessById.setDeleteStatus(StatusEnum.DELETED.getCode().byteValue());
|
oldRiskAssessById.setUpdateByUserId(userInfoById.getId());
|
oldRiskAssessById.setUpdateTime(date);
|
|
OldRiskAssess deleteResult = repository.save(oldRiskAssessById);
|
|
if (ObjectUtils.isEmpty(deleteResult)){
|
return StatusEnum.FAIL.getCode();
|
}
|
|
return StatusEnum.SUCCESS.getCode();
|
}
|
|
@Transactional
|
@Override
|
public int importOldRiskAssess(Long currentUserId, MultipartFile file) {
|
|
if (currentUserId < 0){
|
throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"当前用户无效,请重新登陆");
|
}
|
//根据路径获取这个操作excel的实例
|
HSSFWorkbook wb = null;
|
List<OldRiskAssess> list = new ArrayList<>();
|
try {
|
wb = new HSSFWorkbook(file.getInputStream());
|
//根据页面index 获取sheet页
|
HSSFSheet sheet = wb.getSheetAt(0);
|
HSSFRow row = null;
|
//循环sheet页中数据从第二行开始,第一行是标题
|
|
LocalDateTime nowDate = LocalDateTime.now();
|
for (int i = 1; i <= sheet.getPhysicalNumberOfRows()-1; i++) {
|
//获取每一行数据
|
row = sheet.getRow(i);
|
OldRiskAssess oldRiskAssess = new OldRiskAssess();
|
oldRiskAssess.setUpdateTime(nowDate);
|
oldRiskAssess.setCreateTime(nowDate);
|
oldRiskAssess.setCreateByUserId(currentUserId);
|
oldRiskAssess.setUpdateByUserId(currentUserId);
|
oldRiskAssess.setDeleteStatus((byte)0);
|
|
if (ObjectUtils.isEmpty(row.getCell(1))){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() , "第"+ (i+1) +"行:区域不能为空");
|
}
|
if (ObjectUtils.isEmpty(row.getCell(2))){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"第"+ (i+1) +"行:潜在事故不能为空");
|
}
|
if (ObjectUtils.isEmpty(row.getCell(3))){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"第"+ (i+1) +"行:危险、危害因素不能为空");
|
}
|
if (ObjectUtils.isEmpty(row.getCell(4))){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"第"+ (i+1) +"行:触发条件不能为空");
|
}
|
if (ObjectUtils.isEmpty(row.getCell(5))){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"第"+ (i+1) +"行:事故后果不能为空");
|
}
|
if (ObjectUtils.isEmpty(row.getCell(6))){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"第"+ (i+1) +"行:L数值不能为空");
|
}
|
if (ObjectUtils.isEmpty(row.getCell(7))){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"第"+ (i+1) +"行:D数值不能为空");
|
}
|
if (ObjectUtils.isEmpty(row.getCell(8))){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"第"+ (i+1) +"行:C数值不能为空");
|
}
|
if (ObjectUtils.isEmpty(row.getCell(9))){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"第"+ (i+1) +"行:E数值不能为空");
|
}
|
if (ObjectUtils.isEmpty(row.getCell(10))){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"第"+ (i+1) +"行:危险等级不能为空");
|
}
|
if (ObjectUtils.isEmpty(row.getCell(11))){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"第"+ (i+1) +"行:现有安全控制措施不能为空");
|
}
|
if (ObjectUtils.isEmpty(row.getCell(12))){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"第"+ (i+1) +"行:管控层级不能为空");
|
}
|
|
oldRiskAssess.setRegion(row.getCell(1).toString());
|
oldRiskAssess.setPotentialAccident(row.getCell(2).toString());
|
oldRiskAssess.setDangerReason(row.getCell(3).toString());
|
oldRiskAssess.setTriggerFactor(row.getCell(4).toString());
|
oldRiskAssess.setAccidentResult(row.getCell(5).toString());
|
oldRiskAssess.setDangerLevel(row.getCell(10).toString());
|
oldRiskAssess.setControlMeasure(row.getCell(11).toString());
|
oldRiskAssess.setControlLevel(row.getCell(12).toString());
|
|
double cellL = row.getCell(6).getNumericCellValue();
|
double cellE = row.getCell(7).getNumericCellValue();
|
double cellC = row.getCell(8).getNumericCellValue();
|
double cellD = row.getCell(9).getNumericCellValue();
|
NumberFormat nf = NumberFormat.getInstance();
|
String L = nf.format(cellL);
|
String E = nf.format(cellE);
|
String C = nf.format(cellC);
|
String D = nf.format(cellD);
|
// if (L.indexOf(",") >= 0) {
|
// L = L.replace(",", "");
|
// }
|
oldRiskAssess.setL(L);
|
oldRiskAssess.setE(E);
|
oldRiskAssess.setC(C);
|
oldRiskAssess.setD(D);
|
|
list.add(oldRiskAssess);
|
}
|
} catch (IOException e) {
|
throw new RuntimeException(e);
|
}
|
|
for (OldRiskAssess oldRiskAssess : list) {
|
OldRiskAssess save = repository.save(oldRiskAssess);
|
if (ObjectUtils.isEmpty(save)){
|
throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"导入出错");
|
}
|
}
|
|
return StatusEnum.SUCCESS.getCode();
|
}
|
|
@Override
|
public int exportOldRiskAssess(Long currentUserId, OldRiskAssessQueryReqBO queryReqDO) {
|
|
//组装查询条件
|
Specification<OldRiskAssess> specification = new Specification<OldRiskAssess>() {
|
@Override
|
public Predicate toPredicate(Root<OldRiskAssess> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
|
List<Predicate> predicateList = new ArrayList<>();
|
if(queryReqDO.getRegion() != null && !queryReqDO.getRegion().equals("")){
|
predicateList.add(criteriaBuilder.like(root.get("region"),'%'+ queryReqDO.getRegion() +'%'));
|
}
|
if(queryReqDO.getPotentialAccident() != null && !queryReqDO.getPotentialAccident().equals("")){
|
predicateList.add(criteriaBuilder.like(root.get("potentialAccident"),'%'+queryReqDO.getPotentialAccident() +'%'));
|
}
|
if(queryReqDO.getDangerReason() != null && !queryReqDO.getDangerReason().equals("")){
|
predicateList.add(criteriaBuilder.like(root.get("dangerReason"),'%'+queryReqDO.getDangerReason() +'%'));
|
}
|
if(queryReqDO.getTriggerFactor() != null && !queryReqDO.getTriggerFactor().equals("")){
|
predicateList.add(criteriaBuilder.like(root.get("triggerFactor"),'%'+queryReqDO.getTriggerFactor() +'%'));
|
}
|
if(queryReqDO.getAccidentResult() != null && !queryReqDO.getAccidentResult().equals("")){
|
predicateList.add(criteriaBuilder.like(root.get("accidentResult"),'%'+queryReqDO.getAccidentResult() +'%'));
|
}
|
if(queryReqDO.getDangerLevel() != null && !queryReqDO.getDangerLevel().equals("")){
|
predicateList.add(criteriaBuilder.like(root.get("dangerLevel"),'%'+queryReqDO.getDangerLevel() +'%'));
|
}
|
if(queryReqDO.getControlMeasure() != null && !queryReqDO.getControlMeasure().equals("")){
|
predicateList.add(criteriaBuilder.like(root.get("controlMeasure"),'%'+queryReqDO.getControlMeasure() +'%'));
|
}
|
if(queryReqDO.getControlLevel() != null && !queryReqDO.getControlLevel().equals("")){
|
predicateList.add(criteriaBuilder.like(root.get("controlLevel"),'%'+queryReqDO.getControlLevel() +'%'));
|
}
|
predicateList.add(criteriaBuilder.equal(root.get("deleteStatus"),StatusEnum.DELETE_NOT.getCode()));
|
//返回组装的条件
|
return criteriaBuilder.and(predicateList.toArray(predicateList.toArray(new Predicate[0])));
|
}
|
};
|
List<OldRiskAssess> list = repository.findAll(specification);
|
|
//创建工作薄
|
HSSFWorkbook workbook = new HSSFWorkbook();
|
//创建sheet
|
HSSFSheet sheet=workbook.createSheet("评分标准");
|
//创建第一行
|
HSSFRow header = sheet.createRow(0);
|
//创建单元格并插入表头
|
HSSFCell cell = null;
|
String[] infos={"编号","区域","潜在事故","危险、有害因素","触发条件","事故后果","L","E","C","D",
|
"危险等级","现有安全控制措施(工程技术、管理、培训教育、个体防护、应急处置)","管控层级(公司级、部门级、岗位级)"};
|
for(int i = 0; i < infos.length; i++){
|
cell = header.createCell(i);
|
cell.setCellValue(infos[i]);
|
}
|
|
//写入数据
|
for (int j = 1; j < list.size(); j++) {
|
OldRiskAssess oldRiskAssess = list.get(j - 1);
|
HSSFRow row = sheet.createRow(j);
|
cell= row.createCell(0);
|
cell.setCellValue(j);
|
cell = row.createCell(1);
|
cell.setCellValue(oldRiskAssess.getRegion());
|
cell = row.createCell(2);
|
cell.setCellValue(oldRiskAssess.getPotentialAccident());
|
cell = row.createCell(3);
|
cell.setCellValue(oldRiskAssess.getDangerReason());
|
cell = row.createCell(4);
|
cell.setCellValue(oldRiskAssess.getTriggerFactor());
|
cell = row.createCell(5);
|
cell.setCellValue(oldRiskAssess.getAccidentResult());
|
cell = row.createCell(6);
|
cell.setCellValue(oldRiskAssess.getL());
|
cell = row.createCell(7);
|
cell.setCellValue(oldRiskAssess.getE());
|
cell = row.createCell(8);
|
cell.setCellValue(oldRiskAssess.getC());
|
cell = row.createCell(9);
|
cell.setCellValue(oldRiskAssess.getD());
|
cell = row.createCell(10);
|
cell.setCellValue(oldRiskAssess.getDangerLevel());
|
cell = row.createCell(11);
|
cell.setCellValue(oldRiskAssess.getControlMeasure());
|
cell = row.createCell(12);
|
cell.setCellValue(oldRiskAssess.getControlLevel());
|
}
|
|
// 保存Excel文件
|
try{
|
// 获取桌面路径
|
String desktopPath = System.getProperty("user.home") + "/Desktop/";
|
// 导出文件名
|
String fileName = desktopPath + "评分标准.xlsx";
|
FileOutputStream fileOutputStream = new FileOutputStream(new File(fileName));
|
// 将工作簿写入文件
|
workbook.write(fileOutputStream);
|
workbook.close();
|
fileOutputStream.close();
|
} catch (Exception e) {
|
e.printStackTrace();
|
}finally{
|
if (workbook != null){
|
try {
|
workbook.close();
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
}
|
}
|
return StatusEnum.SUCCESS.getCode();
|
}
|
|
@Override
|
public SearchResult<OldRiskAssessQueryRespDTO> getOldRiskAssessPage(Long currentUserId, OldRiskAssessQueryReqBO queryReqDO) {
|
|
//校验参数
|
if (ObjectUtils.isEmpty(queryReqDO.getPageSize())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"分页信息不能为空");
|
}
|
if (ObjectUtils.isEmpty(queryReqDO.getPageIndex())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"分页信息不能为空");
|
}
|
SearchResult searchResult = new SearchResult<>();
|
|
//组装查询条件
|
Specification<OldRiskAssess> specification = new Specification<OldRiskAssess>() {
|
@Override
|
public Predicate toPredicate(Root<OldRiskAssess> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
|
List<Predicate> predicateList = new ArrayList<>();
|
if(queryReqDO.getRegion() != null && !queryReqDO.getRegion().equals("")){
|
predicateList.add(criteriaBuilder.like(root.get("region"),'%'+ queryReqDO.getRegion() +'%'));
|
}
|
if(queryReqDO.getPotentialAccident() != null && !queryReqDO.getPotentialAccident().equals("")){
|
predicateList.add(criteriaBuilder.like(root.get("potentialAccident"),'%'+queryReqDO.getPotentialAccident() +'%'));
|
}
|
if(queryReqDO.getDangerReason() != null && !queryReqDO.getDangerReason().equals("")){
|
predicateList.add(criteriaBuilder.like(root.get("dangerReason"),'%'+queryReqDO.getDangerReason() +'%'));
|
}
|
if(queryReqDO.getTriggerFactor() != null && !queryReqDO.getTriggerFactor().equals("")){
|
predicateList.add(criteriaBuilder.like(root.get("triggerFactor"),'%'+queryReqDO.getTriggerFactor() +'%'));
|
}
|
if(queryReqDO.getAccidentResult() != null && !queryReqDO.getAccidentResult().equals("")){
|
predicateList.add(criteriaBuilder.like(root.get("accidentResult"),'%'+queryReqDO.getAccidentResult() +'%'));
|
}
|
if(queryReqDO.getDangerLevel() != null && !queryReqDO.getDangerLevel().equals("")){
|
predicateList.add(criteriaBuilder.like(root.get("dangerLevel"),'%'+queryReqDO.getDangerLevel() +'%'));
|
}
|
if(queryReqDO.getControlMeasure() != null && !queryReqDO.getControlMeasure().equals("")){
|
predicateList.add(criteriaBuilder.like(root.get("controlMeasure"),'%'+queryReqDO.getControlMeasure() +'%'));
|
}
|
if(queryReqDO.getControlLevel() != null && !queryReqDO.getControlLevel().equals("")){
|
predicateList.add(criteriaBuilder.like(root.get("controlLevel"),'%'+queryReqDO.getControlLevel() +'%'));
|
}
|
predicateList.add(criteriaBuilder.equal(root.get("deleteStatus"),StatusEnum.DELETE_NOT.getCode()));
|
//返回组装的条件
|
return criteriaBuilder.and(predicateList.toArray(predicateList.toArray(new Predicate[0])));
|
}
|
};
|
|
PageRequest page = PageRequest.of(queryReqDO.getPageIndex() - 1, queryReqDO.getPageSize(), Sort.Direction.DESC, "updateTime");
|
|
Page<OldRiskAssess> pageResult = repository.findAll(specification, page);
|
List<OldRiskAssessQueryRespDTO> oldRiskAssessQueryRespDTO = BeanCopyUtils.copyBeanList(pageResult.getContent(), OldRiskAssessQueryRespDTO.class);
|
|
List<UserInfoDomainDTO> userList = userDomainService.getUserList();
|
for (OldRiskAssessQueryRespDTO oldRiskAssess : oldRiskAssessQueryRespDTO) {
|
for (UserInfoDomainDTO userInfo : userList) {
|
if (userInfo.getId() == oldRiskAssess.getCreateByUserId()){
|
oldRiskAssess.setCreateByUserName(userInfo.getRealName());
|
}
|
if (userInfo.getId() == oldRiskAssess.getUpdateByUserId()){
|
oldRiskAssess.setUpdateByUserName(userInfo.getRealName());
|
}
|
}
|
}
|
|
|
searchResult.setTotal(pageResult.getTotalElements());
|
searchResult.setData(oldRiskAssessQueryRespDTO);
|
|
return searchResult;
|
}
|
|
|
|
|
}
|