刘光辉
14 小时以前 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
package jnpf.limsService.impl;
 
import jnpf.audit.sdk.annotation.AuditLog;
 
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import jnpf.exception.DataException;
import jnpf.limsEntity.LimsShebeiYiqiWeibaoEntity;
import jnpf.limsEntity.LimsShebeiYiqiWeibaoZixiangEntity;
import jnpf.limsMapper.LimsShebeiYiqiWeibaoMapper;
import jnpf.limsMapper.LimsShebeiYiqiWeibaoZixiangMapper;
import jnpf.limsService.LimsShebeiYiqiWeibaoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
@Service
public class LimsShebeiYiqiWeibaoServiceImpl implements LimsShebeiYiqiWeibaoService {
 
    @Autowired
    private LimsShebeiYiqiWeibaoMapper weibaoMapper;
 
    @Autowired
    private LimsShebeiYiqiWeibaoZixiangMapper weibaoZixiangMapper;
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    @AuditLog(action = "MAINTENANCE_SYNC", label = "同步仪器维保子项", bizType = "SHEBEI_YIQI",
            bizCodeExpr = "#result > 0 ? #weibaoId : ''", targetTable = "lims_shebei_yiqi_weibao_zixiang",
            targetIdExpr = "T(jnpf.limsService.support.LimsAuditTargetIds).firstMaintenanceItem(#weibaoId)",
            diff = true, entityClass = LimsShebeiYiqiWeibaoZixiangEntity.class)
    public int syncToZixiang(String weibaoId) throws DataException {
        String id = trimToEmpty(weibaoId);
        if (id.isEmpty()) {
            throw new DataException("维保记录ID(weibao_id)不能为空");
        }
 
        LimsShebeiYiqiWeibaoEntity weibao = weibaoMapper.selectById(id);
        if (weibao == null) {
            throw new DataException("维保记录不存在:" + id);
        }
 
        LambdaUpdateWrapper<LimsShebeiYiqiWeibaoZixiangEntity> update = new LambdaUpdateWrapper<>();
        update.eq(LimsShebeiYiqiWeibaoZixiangEntity::getForeignId, id)
                .set(LimsShebeiYiqiWeibaoZixiangEntity::getYiqiId, weibao.getYiqiId())
                .set(LimsShebeiYiqiWeibaoZixiangEntity::getYiqiMingcheng, weibao.getYiqiMingcheng())
                .set(LimsShebeiYiqiWeibaoZixiangEntity::getYiqiBianhao, weibao.getYiqiBianhao())
                .set(LimsShebeiYiqiWeibaoZixiangEntity::getWeihuRen, weibao.getWeihuRen())
                .set(LimsShebeiYiqiWeibaoZixiangEntity::getWeihuRiqi, weibao.getWeihuRiqi())
                .set(LimsShebeiYiqiWeibaoZixiangEntity::getBeizhu, weibao.getBeizhu());
        int updated = weibaoZixiangMapper.update(null, update);
        if (updated <= 0) {
            throw new DataException("未找到关联的维保子项:" + id);
        }
        return updated;
    }
 
    private String trimToEmpty(String value) {
        return value == null ? "" : value.trim();
    }
}