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 query = new LambdaQueryWrapper<>(); query.eq(DmsDanganGengxinShenqingEntity::getFlowId, flowId) .eq(DmsDanganGengxinShenqingEntity::getFlowTaskId, taskId) .isNull(DmsDanganGengxinShenqingEntity::getDeleteMark); List 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 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 query = new LambdaQueryWrapper<>(); query.eq(DmsDanganGengxinShenqingDanganheEntity::getForeignId, gengxinShenqingId) .isNull(DmsDanganGengxinShenqingDanganheEntity::getDeleteMark); List danganheList = gengxinDanganheMapper.selectList(query); for (DmsDanganGengxinShenqingDanganheEntity gengxinDanganhe : danganheList) { String danganheBianhao = trimToEmpty(gengxinDanganhe.getDanganheBianhao()); if (danganheBianhao.isEmpty()) { continue; } LambdaUpdateWrapper 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(); } }