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 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(); } }