|
@@ -1,10 +1,13 @@
|
|
|
package org.dromara.risk.service.impl;
|
|
package org.dromara.risk.service.impl;
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.dromara.common.core.exception.ServiceException;
|
|
|
import org.dromara.common.core.utils.MapstructUtils;
|
|
import org.dromara.common.core.utils.MapstructUtils;
|
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
|
import org.dromara.common.satoken.utils.LoginHelper;
|
|
import org.dromara.common.satoken.utils.LoginHelper;
|
|
@@ -19,7 +22,9 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.Assert;
|
|
import org.springframework.util.Assert;
|
|
|
|
|
|
|
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 巡检打卡记录 业务层实现
|
|
* 巡检打卡记录 业务层实现
|
|
@@ -31,6 +36,15 @@ import java.util.Date;
|
|
|
@Service
|
|
@Service
|
|
|
public class RiskInspectionRecordServiceImpl implements IRiskInspectionRecordService {
|
|
public class RiskInspectionRecordServiceImpl implements IRiskInspectionRecordService {
|
|
|
|
|
|
|
|
|
|
+ /** 审核状态:待审核(巡检人提交后默认) */
|
|
|
|
|
+ private static final String AUDIT_PENDING = "待审核";
|
|
|
|
|
+ /** 审核状态:审核通过 */
|
|
|
|
|
+ private static final String AUDIT_PASS = "审核通过";
|
|
|
|
|
+ /** 审核状态:审核不通过 */
|
|
|
|
|
+ private static final String AUDIT_REJECT = "审核不通过";
|
|
|
|
|
+
|
|
|
|
|
+ private static final List<String> AUDIT_STATUSES = Arrays.asList(AUDIT_PENDING, AUDIT_PASS, AUDIT_REJECT);
|
|
|
|
|
+
|
|
|
private final RiskInspectionRecordMapper baseMapper;
|
|
private final RiskInspectionRecordMapper baseMapper;
|
|
|
private final RiskInspectionTaskMapper taskMapper;
|
|
private final RiskInspectionTaskMapper taskMapper;
|
|
|
|
|
|
|
@@ -106,8 +120,9 @@ public class RiskInspectionRecordServiceImpl implements IRiskInspectionRecordSer
|
|
|
rec.setProblemCount(problem);
|
|
rec.setProblemCount(problem);
|
|
|
rec.setResult(overallResult);
|
|
rec.setResult(overallResult);
|
|
|
|
|
|
|
|
- // 6. 记录状态
|
|
|
|
|
|
|
+ // 6. 记录状态 + 审核状态
|
|
|
rec.setRecordStatus(hasAbnormal ? "异常打卡" : "已打卡");
|
|
rec.setRecordStatus(hasAbnormal ? "异常打卡" : "已打卡");
|
|
|
|
|
+ rec.setAuditStatus(AUDIT_PENDING);
|
|
|
|
|
|
|
|
// 7. 写主表
|
|
// 7. 写主表
|
|
|
baseMapper.insert(rec);
|
|
baseMapper.insert(rec);
|
|
@@ -141,4 +156,84 @@ public class RiskInspectionRecordServiceImpl implements IRiskInspectionRecordSer
|
|
|
public RiskInspectionRecordVo queryById(Long id) {
|
|
public RiskInspectionRecordVo queryById(Long id) {
|
|
|
return baseMapper.selectVoById(id);
|
|
return baseMapper.selectVoById(id);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 审核巡检打卡记录
|
|
|
|
|
+ * <p>
|
|
|
|
|
+ * 流程:
|
|
|
|
|
+ * 1. 校验记录存在
|
|
|
|
|
+ * 2. 校验 auditStatus 合法 (待审核/审核通过/审核不通过)
|
|
|
|
|
+ * 3. 校验:审核不通过时 auditOpinion 不能为空
|
|
|
|
|
+ * 4. 设置审核时间=now,审核人=当前登录用户(若未传)
|
|
|
|
|
+ * 5. 审计不通过后,巡检记录 recordStatus 同步标记为"审核不通过",
|
|
|
|
|
+ * 移动端可基于此状态允许巡检人重新打卡修改
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public boolean auditRecord(Long id, String auditStatus, Long auditorId, String auditorName, String auditOpinion) {
|
|
|
|
|
+ Assert.notNull(id, "打卡记录ID不能为空");
|
|
|
|
|
+ if (StrUtil.isBlank(auditStatus)) {
|
|
|
|
|
+ throw new ServiceException("审核结果不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!AUDIT_STATUSES.contains(auditStatus)) {
|
|
|
|
|
+ throw new ServiceException("审核结果不合法,可选值: " + AUDIT_STATUSES);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (AUDIT_REJECT.equals(auditStatus) && StrUtil.isBlank(auditOpinion)) {
|
|
|
|
|
+ throw new ServiceException("审核不通过时必须填写原因");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ RiskInspectionRecord exist = baseMapper.selectById(id);
|
|
|
|
|
+ Assert.notNull(exist, "打卡记录不存在: " + id);
|
|
|
|
|
+ if (AUDIT_PENDING.equals(exist.getAuditStatus())) {
|
|
|
|
|
+ // 允许从"待审核" -> 通过/不通过
|
|
|
|
|
+ } else if (StrUtil.isBlank(exist.getAuditStatus())) {
|
|
|
|
|
+ // 兼容存量数据:从未审核状态进入
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 已审核过的记录,允许从"审核不通过"重新审核为"审核通过"
|
|
|
|
|
+ if (AUDIT_REJECT.equals(exist.getAuditStatus()) && AUDIT_PASS.equals(auditStatus)) {
|
|
|
|
|
+ // OK,允许
|
|
|
|
|
+ } else {
|
|
|
|
|
+ throw new ServiceException("当前审核状态(" + exist.getAuditStatus() + ")不允许再次审核");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 审核人信息:前端未传则自动取当前登录用户
|
|
|
|
|
+ Long finalAuditorId = auditorId;
|
|
|
|
|
+ String finalAuditorName = auditorName;
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (finalAuditorId == null) {
|
|
|
|
|
+ finalAuditorId = LoginHelper.getUserId();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StrUtil.isBlank(finalAuditorName)) {
|
|
|
|
|
+ finalAuditorName = LoginHelper.getUsername();
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception ignore) {
|
|
|
|
|
+ // 移动端/免登录场景:留空
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ RiskInspectionRecord update = new RiskInspectionRecord();
|
|
|
|
|
+ update.setId(id);
|
|
|
|
|
+ update.setAuditStatus(auditStatus);
|
|
|
|
|
+ update.setAuditorId(finalAuditorId);
|
|
|
|
|
+ update.setAuditorName(finalAuditorName);
|
|
|
|
|
+ update.setAuditTime(new Date());
|
|
|
|
|
+ update.setAuditOpinion(auditOpinion);
|
|
|
|
|
+
|
|
|
|
|
+ // 同步记录状态:审核不通过时,recordStatus 标记为"审核不通过"
|
|
|
|
|
+ // (前端列表按 recordStatus 着色,审核通过/不通过均显眼呈现)
|
|
|
|
|
+ if (AUDIT_REJECT.equals(auditStatus)) {
|
|
|
|
|
+ update.setRecordStatus("审核不通过");
|
|
|
|
|
+ } else if (AUDIT_PASS.equals(auditStatus)) {
|
|
|
|
|
+ // 不覆盖已有的"异常打卡/已打卡"等业务状态,仅在原本无意义时设置为"审核通过"
|
|
|
|
|
+ if (StrUtil.isBlank(exist.getRecordStatus())
|
|
|
|
|
+ || AUDIT_PENDING.equals(exist.getRecordStatus())) {
|
|
|
|
|
+ update.setRecordStatus("审核通过");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ int row = baseMapper.updateById(update);
|
|
|
|
|
+ log.info("巡检审核完成 recordId={} auditStatus={} auditor={} opinion={}",
|
|
|
|
|
+ id, auditStatus, finalAuditorName, auditOpinion);
|
|
|
|
|
+ return row > 0;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|