|
|
@@ -12,6 +12,7 @@ import org.dromara.common.core.utils.StringUtils;
|
|
|
import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
import org.dromara.risk.domain.RiskInspectionTask;
|
|
|
+import org.dromara.risk.domain.RiskInspectionTaskItem;
|
|
|
import org.dromara.risk.domain.bo.RiskInspectionTaskBo;
|
|
|
import org.dromara.risk.domain.RiskInspectionRecord;
|
|
|
import org.dromara.risk.domain.RiskInspectionTaskItem;
|
|
|
@@ -155,6 +156,10 @@ public class RiskInspectionTaskServiceImpl implements IRiskInspectionTaskService
|
|
|
RiskInspectionTask add = MapstructUtils.convert(bo, RiskInspectionTask.class);
|
|
|
int row = baseMapper.insert(add);
|
|
|
bo.setId(add.getId());
|
|
|
+ // 保存巡检项目列表
|
|
|
+ if (bo.getItemList() != null && !bo.getItemList().isEmpty()) {
|
|
|
+ saveTaskItems(add.getId(), bo.getItemList());
|
|
|
+ }
|
|
|
return row;
|
|
|
}
|
|
|
|
|
|
@@ -167,7 +172,31 @@ public class RiskInspectionTaskServiceImpl implements IRiskInspectionTaskService
|
|
|
bo.setBizType("risk");
|
|
|
}
|
|
|
RiskInspectionTask update = MapstructUtils.convert(bo, RiskInspectionTask.class);
|
|
|
- return baseMapper.updateById(update);
|
|
|
+ int row = baseMapper.updateById(update);
|
|
|
+ // 全量替换巡检项目:先删后插(简单可靠,避免增量同步的复杂性)
|
|
|
+ if (bo.getItemList() != null) {
|
|
|
+ taskItemMapper.delete(Wrappers.<RiskInspectionTaskItem>lambdaQuery()
|
|
|
+ .eq(RiskInspectionTaskItem::getTaskId, bo.getId()));
|
|
|
+ if (!bo.getItemList().isEmpty()) {
|
|
|
+ saveTaskItems(bo.getId(), bo.getItemList());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return row;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存巡检项目列表(设置 taskId + 排序号 + 租户)
|
|
|
+ */
|
|
|
+ private void saveTaskItems(Long taskId, java.util.List<RiskInspectionTaskItem> itemList) {
|
|
|
+ for (int i = 0; i < itemList.size(); i++) {
|
|
|
+ RiskInspectionTaskItem item = itemList.get(i);
|
|
|
+ item.setId(null); // 强制新增,避免前端传旧 id 导致 update 失败
|
|
|
+ item.setTaskId(taskId);
|
|
|
+ if (item.getSortOrder() == null) {
|
|
|
+ item.setSortOrder(i);
|
|
|
+ }
|
|
|
+ taskItemMapper.insert(item);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -315,6 +344,10 @@ public class RiskInspectionTaskServiceImpl implements IRiskInspectionTaskService
|
|
|
|
|
|
/**
|
|
|
* 移动端-校验二维码
|
|
|
+ * <p>
|
|
|
+ * 二维码内容格式:「设备编码 [分隔符] 时间」
|
|
|
+ * 设备编码部分必须等于 task.punchDeviceCode(开启扫码打卡时必填)
|
|
|
+ * 时间部分必须是 yyyy-MM-dd HH:mm:ss 格式,误差 ±24h 内视为有效
|
|
|
*/
|
|
|
@Override
|
|
|
public boolean verifyQrCode(Long taskId, String qrCode) {
|
|
|
@@ -322,10 +355,41 @@ public class RiskInspectionTaskServiceImpl implements IRiskInspectionTaskService
|
|
|
return false;
|
|
|
}
|
|
|
RiskInspectionTask task = baseMapper.selectById(taskId);
|
|
|
- if (task == null || StringUtils.isBlank(task.getQrCode())) {
|
|
|
+ if (task == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ String content = qrCode.trim();
|
|
|
+ // 解析「设备编码」与「时间」两个部分
|
|
|
+ String[] parts = content.split("[\\s|\\n\\r,;]+", 2);
|
|
|
+ if (parts.length < 2) {
|
|
|
+ // 只有一个部分,按传统方式整体比对
|
|
|
+ return StringUtils.isNotBlank(task.getQrCode())
|
|
|
+ && task.getQrCode().trim().equals(content);
|
|
|
+ }
|
|
|
+ String deviceCode = parts[0].trim();
|
|
|
+ String timeStr = parts[1].trim();
|
|
|
+ // 1. 校验设备编码
|
|
|
+ if (StringUtils.isNotBlank(task.getPunchDeviceCode())
|
|
|
+ && !task.getPunchDeviceCode().trim().equalsIgnoreCase(deviceCode)) {
|
|
|
+ log.warn("扫码设备编码不匹配: taskId={}, expected={}, actual={}",
|
|
|
+ taskId, task.getPunchDeviceCode(), deviceCode);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ // 2. 校验时间(误差 ±24 小时)
|
|
|
+ try {
|
|
|
+ java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ Date qrTime = sdf.parse(timeStr);
|
|
|
+ long diffMs = Math.abs(System.currentTimeMillis() - qrTime.getTime());
|
|
|
+ long oneDayMs = 24L * 60 * 60 * 1000;
|
|
|
+ if (diffMs > oneDayMs) {
|
|
|
+ log.warn("二维码时间超出有效期: taskId={}, qrTime={}", taskId, timeStr);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ } catch (java.text.ParseException e) {
|
|
|
+ log.warn("二维码时间格式不合法: taskId={}, timeStr={}", taskId, timeStr);
|
|
|
return false;
|
|
|
}
|
|
|
- return task.getQrCode().trim().equals(qrCode.trim());
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
/**
|