刘光辉
4 小时以前 06f314545ac3514d7ce28939920866ae8188d31c
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package jnpf.dmsService.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import jnpf.dmsEntity.DmsDanganCundangShenqingDanganheEntity;
import jnpf.dmsEntity.DmsDanganCundangShenqingEntity;
import jnpf.dmsEntity.DmsDanganGengxinShenqingDanganheEntity;
import jnpf.dmsEntity.DmsDanganGengxinShenqingEntity;
import jnpf.dmsMapper.DmsDanganCundangShenqingDanganheMapper;
import jnpf.dmsMapper.DmsDanganCundangShenqingMapper;
import jnpf.dmsMapper.DmsDanganGengxinShenqingDanganheMapper;
import jnpf.dmsMapper.DmsDanganGengxinShenqingMapper;
import jnpf.dmsService.DmsDanganGengxinShenqingTongguoService;
import jnpf.exception.DataException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.List;
 
@Service
@RequiredArgsConstructor
public class DmsDanganGengxinShenqingTongguoServiceImpl
        implements DmsDanganGengxinShenqingTongguoService {
 
    private final DmsDanganGengxinShenqingMapper gengxinShenqingMapper;
    private final DmsDanganGengxinShenqingDanganheMapper gengxinDanganheMapper;
    private final DmsDanganCundangShenqingMapper cundangShenqingMapper;
    private final DmsDanganCundangShenqingDanganheMapper cundangDanganheMapper;
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void tongguo(String flowId, String taskId) throws DataException {
        DmsDanganGengxinShenqingEntity gengxin = findApplication(
                requireValue(flowId, "流程ID(flow_id)"), requireValue(taskId, "流程任务ID(task_id)"));
        String cundangShenqingId = requireValue(gengxin.getCundangShenqingId(), "存档申请ID(cundang_shenqing_id)");
 
        syncCundangShenqing(gengxin, cundangShenqingId);
        syncDanganhe(gengxin.getId(), cundangShenqingId);
    }
 
    private DmsDanganGengxinShenqingEntity findApplication(String flowId, String taskId) throws DataException {
        LambdaQueryWrapper<DmsDanganGengxinShenqingEntity> query = new LambdaQueryWrapper<>();
        query.eq(DmsDanganGengxinShenqingEntity::getFlowId, flowId)
                .eq(DmsDanganGengxinShenqingEntity::getFlowTaskId, taskId)
                .isNull(DmsDanganGengxinShenqingEntity::getDeleteMark);
        List<DmsDanganGengxinShenqingEntity> applications = gengxinShenqingMapper.selectList(query);
        if (applications.isEmpty()) {
            throw new DataException("未找到档案信息更新申请:flow_id=" + flowId + ", task_id=" + taskId);
        }
        if (applications.size() > 1) {
            throw new DataException("flow_id与task_id关联了多条档案信息更新申请,无法确认通过记录");
        }
        return applications.get(0);
    }
 
    private void syncCundangShenqing(DmsDanganGengxinShenqingEntity gengxin, String cundangShenqingId)
            throws DataException {
        LambdaUpdateWrapper<DmsDanganCundangShenqingEntity> update = new LambdaUpdateWrapper<>();
        update.eq(DmsDanganCundangShenqingEntity::getId, cundangShenqingId)
                .isNull(DmsDanganCundangShenqingEntity::getDeleteMark)
                .set(DmsDanganCundangShenqingEntity::getDanganMingcheng, gengxin.getDanganMingcheng())
                .set(DmsDanganCundangShenqingEntity::getWenjianLeixing, gengxin.getWenjianLeixing())
                .set(DmsDanganCundangShenqingEntity::getDanganheWeizhi, gengxin.getDanganheWeizhi())
                .set(DmsDanganCundangShenqingEntity::getGuidangYouxiaoqi, gengxin.getGuidangYouxiaoqi())
                .set(DmsDanganCundangShenqingEntity::getGuidangBumen, gengxin.getGuidangBumen())
                .set(DmsDanganCundangShenqingEntity::getBeizhu, gengxin.getBeizhu())
                .set(DmsDanganCundangShenqingEntity::getGuidangShijian, gengxin.getGuidangShijian())
                .set(DmsDanganCundangShenqingEntity::getBaocunZhouqi, gengxin.getBaocunZhouqi())
                .set(DmsDanganCundangShenqingEntity::getBaocunZhouqiQita, gengxin.getBaocunZhouqiQita());
        if (cundangShenqingMapper.update(null, update) != 1) {
            throw new DataException("未找到关联的原始档案存档申请,无法同步更新信息");
        }
    }
 
    private void syncDanganhe(String gengxinShenqingId, String cundangShenqingId) {
        LambdaQueryWrapper<DmsDanganGengxinShenqingDanganheEntity> query = new LambdaQueryWrapper<>();
        query.eq(DmsDanganGengxinShenqingDanganheEntity::getForeignId, gengxinShenqingId)
                .isNull(DmsDanganGengxinShenqingDanganheEntity::getDeleteMark);
        List<DmsDanganGengxinShenqingDanganheEntity> danganheList = gengxinDanganheMapper.selectList(query);
        for (DmsDanganGengxinShenqingDanganheEntity gengxinDanganhe : danganheList) {
            String danganheBianhao = trimToEmpty(gengxinDanganhe.getDanganheBianhao());
            if (danganheBianhao.isEmpty()) {
                continue;
            }
            LambdaUpdateWrapper<DmsDanganCundangShenqingDanganheEntity> update = new LambdaUpdateWrapper<>();
            update.eq(DmsDanganCundangShenqingDanganheEntity::getForeignId, cundangShenqingId)
                    .eq(DmsDanganCundangShenqingDanganheEntity::getDanganheBianhao, danganheBianhao)
                    .isNull(DmsDanganCundangShenqingDanganheEntity::getDeleteMark)
                    .set(DmsDanganCundangShenqingDanganheEntity::getDanganheLeibie, gengxinDanganhe.getDanganheLeibie())
                    .set(DmsDanganCundangShenqingDanganheEntity::getDanganheMingcheng, gengxinDanganhe.getDanganheMingcheng())
                    .set(DmsDanganCundangShenqingDanganheEntity::getGuishuBumen, gengxinDanganhe.getGuishuBumen())
                    .set(DmsDanganCundangShenqingDanganheEntity::getDanganheWeizhi, gengxinDanganhe.getDanganheWeizhi());
            cundangDanganheMapper.update(null, update);
        }
    }
 
    private String requireValue(String value, String fieldName) throws DataException {
        String resolved = trimToEmpty(value);
        if (resolved.isEmpty()) {
            throw new DataException(fieldName + "不能为空");
        }
        return resolved;
    }
 
    private String trimToEmpty(String value) {
        return value == null ? "" : value.trim();
    }
}