刘光辉
昨天 bb638871a7fb692d80f1b7a758f991dc0879002c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package jnpf.limsService.impl;
 
import jnpf.audit.sdk.annotation.AuditLog;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import jnpf.exception.DataException;
import jnpf.limsEntity.LimsShebeiJiliangQijuEntity;
import jnpf.limsEntity.LimsShebeiYiqiJiaozhunNeibuEntity;
import jnpf.limsMapper.LimsShebeiJiliangQijuMapper;
import jnpf.limsMapper.LimsShebeiYiqiJiaozhunNeibuMapper;
import jnpf.limsService.LimsShebeiYiqiJiaozhunNeibuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
@Service
public class LimsShebeiYiqiJiaozhunNeibuServiceImpl implements LimsShebeiYiqiJiaozhunNeibuService {
 
    private static final String BIZ_STATUS_YIJIAOZHUN = "yijiaozhun";
 
    @Autowired
    private LimsShebeiYiqiJiaozhunNeibuMapper jiaozhunNeibuMapper;
 
    @Autowired
    private LimsShebeiJiliangQijuMapper jiliangQijuMapper;
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    @AuditLog(action = "CALIBRATION_SYNC", label = "同步内部校准结果", bizType = "SHEBEI_YIQI",
            bizCodeExpr = "#flowId", bizCodeRequired = false, targetTable = "lims_shebei_yiqi_qiju",
            targetIdExpr = "T(jnpf.limsService.support.LimsAuditTargetIds).qijuByInternalCalibrationFlow(#flowId, #taskId)",
            diff = true, entityClass = LimsShebeiJiliangQijuEntity.class)
    public void syncToQiju(String flowId, String taskId) throws DataException {
        String resolvedFlowId = trimToEmpty(flowId);
        String resolvedTaskId = trimToEmpty(taskId);
        if (resolvedFlowId.isEmpty()) {
            throw new DataException("流程ID(flow_id)不能为空");
        }
        if (resolvedTaskId.isEmpty()) {
            throw new DataException("流程任务ID(task_id)不能为空");
        }
 
        LambdaQueryWrapper<LimsShebeiYiqiJiaozhunNeibuEntity> query = new LambdaQueryWrapper<>();
        query.eq(LimsShebeiYiqiJiaozhunNeibuEntity::getFlowId, resolvedFlowId)
                .eq(LimsShebeiYiqiJiaozhunNeibuEntity::getFlowTaskId, resolvedTaskId);
        LimsShebeiYiqiJiaozhunNeibuEntity jiaozhun = jiaozhunNeibuMapper.selectOne(query);
        if (jiaozhun == null) {
            throw new DataException("未找到关联的内部校准记录:flow_id=" + resolvedFlowId + ", task_id=" + resolvedTaskId);
        }
 
        String qijuId = trimToEmpty(jiaozhun.getQijuId());
        if (qijuId.isEmpty()) {
            throw new DataException("内部校准记录未关联计量器具");
        }
        if (jiliangQijuMapper.selectById(qijuId) == null) {
            throw new DataException("计量器具不存在:" + qijuId);
        }
 
        LambdaUpdateWrapper<LimsShebeiJiliangQijuEntity> update = new LambdaUpdateWrapper<>();
        update.eq(LimsShebeiJiliangQijuEntity::getId, qijuId)
                .set(LimsShebeiJiliangQijuEntity::getBizStatus, BIZ_STATUS_YIJIAOZHUN)
                .set(LimsShebeiJiliangQijuEntity::getJiandingRiqi, jiaozhun.getJiandingRiqi())
                .set(LimsShebeiJiliangQijuEntity::getJiliangShijian, jiaozhun.getJiandingRiqi())
                .set(LimsShebeiJiliangQijuEntity::getJiliangYouxiaoqi, jiaozhun.getYouxiaoqi());
        if (jiliangQijuMapper.update(null, update) != 1) {
            throw new DataException("计量器具校准信息更新失败,请刷新后重试");
        }
    }
 
    private String trimToEmpty(String value) {
        return value == null ? "" : value.trim();
    }
}