|
@@ -3,6 +3,7 @@ package org.dromara.riskctrl.service.impl;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
+import jakarta.annotation.Resource;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.dromara.common.core.constant.SystemConstants;
|
|
import org.dromara.common.core.constant.SystemConstants;
|
|
@@ -12,6 +13,7 @@ import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
import org.dromara.riskctrl.domain.SafetyHazard;
|
|
import org.dromara.riskctrl.domain.SafetyHazard;
|
|
|
import org.dromara.riskctrl.domain.bo.SafetyHazardBo;
|
|
import org.dromara.riskctrl.domain.bo.SafetyHazardBo;
|
|
|
|
|
+import org.dromara.riskctrl.domain.vo.SafetyHazardStatsVo;
|
|
|
import org.dromara.riskctrl.domain.vo.SafetyHazardVo;
|
|
import org.dromara.riskctrl.domain.vo.SafetyHazardVo;
|
|
|
import org.dromara.riskctrl.mapper.SafetyHazardMapper;
|
|
import org.dromara.riskctrl.mapper.SafetyHazardMapper;
|
|
|
import org.dromara.riskctrl.service.ISafetyHazardService;
|
|
import org.dromara.riskctrl.service.ISafetyHazardService;
|
|
@@ -31,6 +33,7 @@ import java.util.*;
|
|
|
@Service
|
|
@Service
|
|
|
public class SafetyHazardServiceImpl implements ISafetyHazardService {
|
|
public class SafetyHazardServiceImpl implements ISafetyHazardService {
|
|
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
private final SafetyHazardMapper baseMapper;
|
|
private final SafetyHazardMapper baseMapper;
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -47,15 +50,21 @@ public class SafetyHazardServiceImpl implements ISafetyHazardService {
|
|
|
private LambdaQueryWrapper<SafetyHazard> buildQueryWrapper(SafetyHazardBo bo) {
|
|
private LambdaQueryWrapper<SafetyHazard> buildQueryWrapper(SafetyHazardBo bo) {
|
|
|
Map<String, Object> params = bo.getParams();
|
|
Map<String, Object> params = bo.getParams();
|
|
|
LambdaQueryWrapper<SafetyHazard> wrapper = Wrappers.lambdaQuery();
|
|
LambdaQueryWrapper<SafetyHazard> wrapper = Wrappers.lambdaQuery();
|
|
|
|
|
+
|
|
|
wrapper.eq(SafetyHazard::getDelFlag, SystemConstants.NORMAL)
|
|
wrapper.eq(SafetyHazard::getDelFlag, SystemConstants.NORMAL)
|
|
|
.eq(StringUtils.isNotBlank(bo.getHazardNo()), SafetyHazard::getHazardNo, bo.getHazardNo())
|
|
.eq(StringUtils.isNotBlank(bo.getHazardNo()), SafetyHazard::getHazardNo, bo.getHazardNo())
|
|
|
.like(StringUtils.isNotBlank(bo.getHazardName()), SafetyHazard::getHazardName, bo.getHazardName())
|
|
.like(StringUtils.isNotBlank(bo.getHazardName()), SafetyHazard::getHazardName, bo.getHazardName())
|
|
|
.eq(StringUtils.isNotBlank(bo.getHazardType()), SafetyHazard::getHazardType, bo.getHazardType())
|
|
.eq(StringUtils.isNotBlank(bo.getHazardType()), SafetyHazard::getHazardType, bo.getHazardType())
|
|
|
.eq(StringUtils.isNotBlank(bo.getRiskLevel()), SafetyHazard::getRiskLevel, bo.getRiskLevel())
|
|
.eq(StringUtils.isNotBlank(bo.getRiskLevel()), SafetyHazard::getRiskLevel, bo.getRiskLevel())
|
|
|
.eq(StringUtils.isNotBlank(bo.getProcessStatus()), SafetyHazard::getProcessStatus, bo.getProcessStatus())
|
|
.eq(StringUtils.isNotBlank(bo.getProcessStatus()), SafetyHazard::getProcessStatus, bo.getProcessStatus())
|
|
|
|
|
+ .and(StringUtils.isNotBlank(bo.getKeyword()), w -> w
|
|
|
|
|
+ .like(SafetyHazard::getHazardNo, bo.getKeyword())
|
|
|
|
|
+ .or()
|
|
|
|
|
+ .like(SafetyHazard::getHazardName, bo.getKeyword()))
|
|
|
.between(params.get("beginTime") != null && params.get("endTime") != null,
|
|
.between(params.get("beginTime") != null && params.get("endTime") != null,
|
|
|
SafetyHazard::getCreateTime, params.get("beginTime"), params.get("endTime"))
|
|
SafetyHazard::getCreateTime, params.get("beginTime"), params.get("endTime"))
|
|
|
.orderByDesc(SafetyHazard::getCreateTime);
|
|
.orderByDesc(SafetyHazard::getCreateTime);
|
|
|
|
|
+
|
|
|
return wrapper;
|
|
return wrapper;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -68,7 +77,8 @@ public class SafetyHazardServiceImpl implements ISafetyHazardService {
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public int insertHazard(SafetyHazardBo bo) {
|
|
public int insertHazard(SafetyHazardBo bo) {
|
|
|
SafetyHazard hazard = MapstructUtils.convert(bo, SafetyHazard.class);
|
|
SafetyHazard hazard = MapstructUtils.convert(bo, SafetyHazard.class);
|
|
|
- hazard.setHazardNo("HZ" + new SimpleDateFormat("yyyyMMdd").format(new Date()) + UUID.randomUUID().toString().replace("-", "").substring(0, 6));
|
|
|
|
|
|
|
+ hazard.setHazardNo("HZ" + new SimpleDateFormat("yyyyMMdd").format(new Date())
|
|
|
|
|
+ + UUID.randomUUID().toString().replace("-", "").substring(0, 6));
|
|
|
if (hazard.getProcessStatus() == null) {
|
|
if (hazard.getProcessStatus() == null) {
|
|
|
hazard.setProcessStatus("待处理");
|
|
hazard.setProcessStatus("待处理");
|
|
|
}
|
|
}
|
|
@@ -84,11 +94,12 @@ public class SafetyHazardServiceImpl implements ISafetyHazardService {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public int processHazard(Long hazardId, String processStatus, String processResult) {
|
|
|
|
|
|
|
+ public int processHazard(Long hazardId, String processStatus, String processResult, String processUser) {
|
|
|
SafetyHazard hazard = new SafetyHazard();
|
|
SafetyHazard hazard = new SafetyHazard();
|
|
|
hazard.setHazardId(hazardId);
|
|
hazard.setHazardId(hazardId);
|
|
|
hazard.setProcessStatus(processStatus);
|
|
hazard.setProcessStatus(processStatus);
|
|
|
hazard.setProcessResult(processResult);
|
|
hazard.setProcessResult(processResult);
|
|
|
|
|
+ hazard.setProcessUser(processUser);
|
|
|
hazard.setProcessTime(new Date());
|
|
hazard.setProcessTime(new Date());
|
|
|
return baseMapper.updateById(hazard);
|
|
return baseMapper.updateById(hazard);
|
|
|
}
|
|
}
|
|
@@ -100,37 +111,64 @@ public class SafetyHazardServiceImpl implements ISafetyHazardService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public Map<String, Object> selectHazardStats() {
|
|
|
|
|
- LambdaQueryWrapper<SafetyHazard> wrapper = Wrappers.lambdaQuery();
|
|
|
|
|
- wrapper.eq(SafetyHazard::getDelFlag, SystemConstants.NORMAL);
|
|
|
|
|
|
|
+ public SafetyHazardStatsVo selectHazardStats(SafetyHazardBo bo) {
|
|
|
|
|
+ LambdaQueryWrapper<SafetyHazard> baseWrapper = buildQueryWrapper(bo);
|
|
|
|
|
|
|
|
- long total = baseMapper.selectCount(wrapper);
|
|
|
|
|
- long unprocessed = baseMapper.selectCount(wrapper.clone()
|
|
|
|
|
|
|
+ long total = baseMapper.selectCount(baseWrapper);
|
|
|
|
|
+
|
|
|
|
|
+ long unprocessed = baseMapper.selectCount(baseWrapper.clone()
|
|
|
.in(SafetyHazard::getProcessStatus, List.of("待处理", "处理中")));
|
|
.in(SafetyHazard::getProcessStatus, List.of("待处理", "处理中")));
|
|
|
- long processed = baseMapper.selectCount(wrapper.clone()
|
|
|
|
|
|
|
+
|
|
|
|
|
+ long processed = baseMapper.selectCount(baseWrapper.clone()
|
|
|
.eq(SafetyHazard::getProcessStatus, "已处理"));
|
|
.eq(SafetyHazard::getProcessStatus, "已处理"));
|
|
|
|
|
|
|
|
- Map<String, Object> stats = new LinkedHashMap<>();
|
|
|
|
|
- stats.put("total", total);
|
|
|
|
|
- stats.put("unprocessed", unprocessed);
|
|
|
|
|
- stats.put("processed", processed);
|
|
|
|
|
- return stats;
|
|
|
|
|
|
|
+ SafetyHazardStatsVo vo = new SafetyHazardStatsVo();
|
|
|
|
|
+ vo.setTotalCount(total);
|
|
|
|
|
+ vo.setUnprocessedCount(unprocessed);
|
|
|
|
|
+ vo.setProcessedCount(processed);
|
|
|
|
|
+ return vo;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public List<Map<String, Object>> selectMonthlyTrend(int months) {
|
|
public List<Map<String, Object>> selectMonthlyTrend(int months) {
|
|
|
List<Map<String, Object>> trend = new ArrayList<>();
|
|
List<Map<String, Object>> trend = new ArrayList<>();
|
|
|
|
|
+
|
|
|
for (int i = months - 1; i >= 0; i--) {
|
|
for (int i = months - 1; i >= 0; i--) {
|
|
|
Calendar cal = Calendar.getInstance();
|
|
Calendar cal = Calendar.getInstance();
|
|
|
cal.add(Calendar.MONTH, -i);
|
|
cal.add(Calendar.MONTH, -i);
|
|
|
- String month = new SimpleDateFormat("yyyy-MM").format(cal.getTime());
|
|
|
|
|
- LambdaQueryWrapper<SafetyHazard> wrapper = Wrappers.lambdaQuery();
|
|
|
|
|
- wrapper.eq(SafetyHazard::getDelFlag, SystemConstants.NORMAL)
|
|
|
|
|
- .likeRight(SafetyHazard::getCreateTime, month);
|
|
|
|
|
|
|
|
|
|
- long total = baseMapper.selectCount(wrapper);
|
|
|
|
|
- long closed = baseMapper.selectCount(wrapper.clone()
|
|
|
|
|
- .eq(SafetyHazard::getProcessStatus, "已处理"));
|
|
|
|
|
|
|
+ // 当前月开始时间
|
|
|
|
|
+ Calendar beginCal = (Calendar) cal.clone();
|
|
|
|
|
+ beginCal.set(Calendar.DAY_OF_MONTH, 1);
|
|
|
|
|
+ beginCal.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
|
|
+ beginCal.set(Calendar.MINUTE, 0);
|
|
|
|
|
+ beginCal.set(Calendar.SECOND, 0);
|
|
|
|
|
+ beginCal.set(Calendar.MILLISECOND, 0);
|
|
|
|
|
+
|
|
|
|
|
+ // 当前月结束时间
|
|
|
|
|
+ Calendar endCal = (Calendar) cal.clone();
|
|
|
|
|
+ endCal.set(Calendar.DAY_OF_MONTH, endCal.getActualMaximum(Calendar.DAY_OF_MONTH));
|
|
|
|
|
+ endCal.set(Calendar.HOUR_OF_DAY, 23);
|
|
|
|
|
+ endCal.set(Calendar.MINUTE, 59);
|
|
|
|
|
+ endCal.set(Calendar.SECOND, 59);
|
|
|
|
|
+ endCal.set(Calendar.MILLISECOND, 999);
|
|
|
|
|
+
|
|
|
|
|
+ Date beginTime = beginCal.getTime();
|
|
|
|
|
+ Date endTime = endCal.getTime();
|
|
|
|
|
+
|
|
|
|
|
+ LambdaQueryWrapper<SafetyHazard> baseWrapper = Wrappers.lambdaQuery();
|
|
|
|
|
+ baseWrapper.eq(SafetyHazard::getDelFlag, SystemConstants.NORMAL)
|
|
|
|
|
+ .between(SafetyHazard::getCreateTime, beginTime, endTime);
|
|
|
|
|
+
|
|
|
|
|
+ long total = baseMapper.selectCount(baseWrapper);
|
|
|
|
|
+ long closed = baseMapper.selectCount(
|
|
|
|
|
+ Wrappers.<SafetyHazard>lambdaQuery()
|
|
|
|
|
+ .eq(SafetyHazard::getDelFlag, SystemConstants.NORMAL)
|
|
|
|
|
+ .between(SafetyHazard::getCreateTime, beginTime, endTime)
|
|
|
|
|
+ .eq(SafetyHazard::getProcessStatus, "已处理")
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ String month = new SimpleDateFormat("yyyy-MM").format(cal.getTime());
|
|
|
|
|
|
|
|
Map<String, Object> item = new LinkedHashMap<>();
|
|
Map<String, Object> item = new LinkedHashMap<>();
|
|
|
item.put("month", month);
|
|
item.put("month", month);
|
|
@@ -138,6 +176,7 @@ public class SafetyHazardServiceImpl implements ISafetyHazardService {
|
|
|
item.put("closed", closed);
|
|
item.put("closed", closed);
|
|
|
trend.add(item);
|
|
trend.add(item);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
return trend;
|
|
return trend;
|
|
|
}
|
|
}
|
|
|
|
|
|