刘光辉
15 小时以前 34981c30a78e8bbd7791131059a9210f9928b62c
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
75
76
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.LimsShebeiYiqiQijuBaofeiEntity;
import jnpf.limsMapper.LimsShebeiJiliangQijuMapper;
import jnpf.limsMapper.LimsShebeiYiqiQijuBaofeiMapper;
import jnpf.limsService.LimsShebeiYiqiQijuBaofeiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.List;
 
@Service
public class LimsShebeiYiqiQijuBaofeiServiceImpl implements LimsShebeiYiqiQijuBaofeiService {
 
    private static final String BIZ_STATUS_YIBAOFEI = "yibaofei";
 
    @Autowired
    private LimsShebeiYiqiQijuBaofeiMapper qijuBaofeiMapper;
 
    @Autowired
    private LimsShebeiJiliangQijuMapper jiliangQijuMapper;
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    @AuditLog(action = "SCRAP", label = "器具报废", bizType = "SHEBEI_YIQI",
            bizCodeExpr = "#flowId", bizCodeRequired = false, targetTable = "lims_shebei_yiqi_qiju",
            targetIdExpr = "T(jnpf.limsService.support.LimsAuditTargetIds).qijuByScrapFlow(#flowId, #taskId)",
            diff = true, entityClass = LimsShebeiJiliangQijuEntity.class)
    public void baofeiQiju(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<LimsShebeiYiqiQijuBaofeiEntity> query = new LambdaQueryWrapper<>();
        query.eq(LimsShebeiYiqiQijuBaofeiEntity::getFlowId, resolvedFlowId)
                .eq(LimsShebeiYiqiQijuBaofeiEntity::getFlowTaskId, resolvedTaskId);
        List<LimsShebeiYiqiQijuBaofeiEntity> baofeiList = qijuBaofeiMapper.selectList(query);
        if (baofeiList.isEmpty()) {
            throw new DataException("未找到关联的器具报废申请:flow_id=" + resolvedFlowId + ", task_id=" + resolvedTaskId);
        }
        if (baofeiList.size() > 1) {
            throw new DataException("多个器具报废申请关联同一流程任务:task_id=" + resolvedTaskId);
        }
 
        String qijuId = trimToEmpty(baofeiList.get(0).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_YIBAOFEI);
        if (jiliangQijuMapper.update(null, update) != 1) {
            throw new DataException("计量器具报废状态更新失败,请刷新后重试");
        }
    }
 
    private String trimToEmpty(String value) {
        return value == null ? "" : value.trim();
    }
}