package jnpf.limsService.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import jnpf.audit.sdk.annotation.AuditLog;
|
import jnpf.base.service.SuperServiceImpl;
|
import jnpf.exception.DataException;
|
import jnpf.limsEntity.LimsShebeiYiqiJiliangEntity;
|
import jnpf.limsEntity.LimsShebeiYiqiXinxiEntity;
|
import jnpf.limsEntity.LimsShebeiYiqiYanzhengEntity;
|
import jnpf.limsMapper.LimsShebeiYiqiJiliangMapper;
|
import jnpf.limsMapper.LimsShebeiYiqiXinxiMapper;
|
import jnpf.limsMapper.LimsShebeiYiqiYanzhengMapper;
|
import jnpf.limsService.LimsShebeiYiqiXinxiService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.time.LocalDate;
|
import java.time.LocalDateTime;
|
import java.util.ArrayList;
|
import java.util.LinkedHashSet;
|
import java.util.List;
|
import java.util.Set;
|
|
@Service
|
public class LimsShebeiYiqiXinxiServiceImpl
|
extends SuperServiceImpl<LimsShebeiYiqiXinxiMapper, LimsShebeiYiqiXinxiEntity>
|
implements LimsShebeiYiqiXinxiService {
|
|
private static final String BIZ_STATUS_YIBAOFEI = "yibaofei";
|
private static final String XINGNENG_ZHUANGTAI_ZHUNYONG = "zhunyong";
|
@Autowired
|
private LimsShebeiYiqiYanzhengMapper limsShebeiYiqiYanzhengMapper;
|
|
@Autowired
|
private LimsShebeiYiqiJiliangMapper limsShebeiYiqiJiliangMapper;
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
@AuditLog(action = "SCRAP", label = "仪器报废", bizType = "SHEBEI_YIQI",
|
bizCodeExpr = "#yiqiId", bizCodeRequired = false, targetTable = "lims_shebei_yiqi_xinxi",
|
targetIdExpr = "#yiqiId", diff = true, entityClass = LimsShebeiYiqiXinxiEntity.class)
|
public void baofei(String yiqiId) throws DataException {
|
String id = trimToEmpty(yiqiId);
|
if (id.isEmpty()) {
|
throw new DataException("仪器ID(yiqi_id)不能为空");
|
}
|
|
LimsShebeiYiqiXinxiEntity yiqi = this.getById(id);
|
if (yiqi == null) {
|
throw new DataException("仪器信息不存在:" + id);
|
}
|
|
LimsShebeiYiqiXinxiEntity update = new LimsShebeiYiqiXinxiEntity();
|
update.setId(id);
|
update.setBizStatus(BIZ_STATUS_YIBAOFEI);
|
if (!this.updateById(update)) {
|
throw new DataException("仪器报废失败,请刷新后重试");
|
}
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
@AuditLog(action = "ENABLE", label = "仪器批量启用", bizType = "SHEBEI_YIQI",
|
bizCodeExpr = "", bizCodeRequired = false, targetTable = "lims_shebei_yiqi_xinxi",
|
targetIdExpr = "#yiqiIds[0]", diff = true,
|
entityClass = LimsShebeiYiqiXinxiEntity.class)
|
public int qiyong(List<String> yiqiIds) throws DataException {
|
List<String> ids = normalizeIds(yiqiIds);
|
if (ids.isEmpty()) {
|
throw new DataException("仪器ID列表(yiqi_ids)不能为空");
|
}
|
|
LimsShebeiYiqiXinxiEntity update = new LimsShebeiYiqiXinxiEntity();
|
update.setXingnengZhuangtai(XINGNENG_ZHUANGTAI_ZHUNYONG);
|
LambdaUpdateWrapper<LimsShebeiYiqiXinxiEntity> wrapper = new LambdaUpdateWrapper<>();
|
wrapper.in(LimsShebeiYiqiXinxiEntity::getId, ids);
|
int updated = this.baseMapper.update(update, wrapper);
|
if (updated <= 0) {
|
throw new DataException("未找到可启用的仪器信息");
|
}
|
return updated;
|
}
|
|
@Override
|
public void checkTodayJiaoyan(String yiqiId, LocalDateTime jiaoyanShijian) throws DataException {
|
String id = trimToEmpty(yiqiId);
|
if (id.isEmpty()) {
|
throw new DataException("仪器ID(yiqi_id)不能为空");
|
}
|
if (jiaoyanShijian == null) {
|
throw new DataException("校准时间(jiaoyan_shijian)不能为空");
|
}
|
|
LocalDateTime startTime = jiaoyanShijian.toLocalDate().atStartOfDay();
|
LocalDateTime endTime = startTime.plusDays(1);
|
if (this.baseMapper.existsTodayJiaoyan(id, startTime, endTime)) {
|
throw new DataException("该仪器设备今日已校准过,不需要重复校准!");
|
}
|
}
|
|
@Override
|
public void checkShiyong(String yiqiId) throws DataException {
|
String id = trimToEmpty(yiqiId);
|
if (id.isEmpty()) {
|
throw new DataException("仪器ID(yiqi_id)不能为空");
|
}
|
|
LocalDateTime startTime = LocalDate.now().atStartOfDay();
|
LocalDateTime endTime = startTime.plusDays(1);
|
if (this.baseMapper.requiresTodayJiaoyan(id, startTime, endTime)) {
|
throw new DataException("该仪器设备今日需要校准,请进行日常校准!");
|
}
|
if (this.baseMapper.existsUsingYiqi(id)) {
|
throw new DataException("该仪器设备正在使用,请稍后!");
|
}
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
@AuditLog(action = "VERIFY_CONFIRM", label = "确认仪器验证", bizType = "SHEBEI_YIQI",
|
bizCodeExpr = "#yanzhengId", bizCodeRequired = false, targetTable = "lims_shebei_yiqi_xinxi",
|
targetIdExpr = "T(jnpf.limsService.support.LimsAuditTargetIds).yiqiByVerification(#yanzhengId)",
|
diff = true, entityClass = LimsShebeiYiqiXinxiEntity.class)
|
public void confirmYanzheng(String yanzhengId) throws DataException {
|
String id = trimToEmpty(yanzhengId);
|
if (id.isEmpty()) {
|
throw new DataException("仪器验证ID(yanzheng_id)不能为空");
|
}
|
|
LimsShebeiYiqiYanzhengEntity yanzheng = limsShebeiYiqiYanzhengMapper.selectById(id);
|
if (yanzheng == null) {
|
throw new DataException("仪器验证记录不存在:" + id);
|
}
|
|
LimsShebeiYiqiXinxiEntity update = new LimsShebeiYiqiXinxiEntity();
|
update.setShangciYanzhengShijian(yanzheng.getShangciYanzhengShijian());
|
update.setXiaciYanzhengShijian(yanzheng.getXiaciYanzhengShijian());
|
update.setYanzhengZhouqi(yanzheng.getYanzhengZhouqi());
|
update.setYanzhengShijianDanwei(yanzheng.getYanzhengShijianDanwei());
|
update.setTiqianTixingShijian(yanzheng.getTiqianTixingShijian());
|
update.setTixingShijianDanwei(yanzheng.getTixingShijianDanwei());
|
update.setYanzhengTixingRiqi(yanzheng.getYanzhengTixingRiqi());
|
updateYiqiXinxi(yanzheng.getYiqiId(), update, id, "仪器验证记录");
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
@AuditLog(action = "MEASURE_CONFIRM", label = "确认仪器计量", bizType = "SHEBEI_YIQI",
|
bizCodeExpr = "#jiliangId", bizCodeRequired = false, targetTable = "lims_shebei_yiqi_xinxi",
|
targetIdExpr = "T(jnpf.limsService.support.LimsAuditTargetIds).yiqiByMeasurement(#jiliangId)",
|
diff = true, entityClass = LimsShebeiYiqiXinxiEntity.class)
|
public void confirmJiliang(String jiliangId) throws DataException {
|
String id = trimToEmpty(jiliangId);
|
if (id.isEmpty()) {
|
throw new DataException("仪器计量ID(jiliang_id)不能为空");
|
}
|
|
LimsShebeiYiqiJiliangEntity jiliang = limsShebeiYiqiJiliangMapper.selectById(id);
|
if (jiliang == null) {
|
throw new DataException("仪器计量记录不存在:" + id);
|
}
|
|
LimsShebeiYiqiXinxiEntity update = new LimsShebeiYiqiXinxiEntity();
|
update.setShangciJiliangShijian(jiliang.getShangciJiliangShijian());
|
update.setXiaciJiliangShijian(jiliang.getXiaciJiliangShijian());
|
update.setJiliangZhouqi(jiliang.getJiliangZhouqi());
|
update.setJiliangShijianDanwei(jiliang.getJiliangShijianDanwei());
|
update.setTiqianTixingShijian(jiliang.getTiqianTixingShijian());
|
update.setTixingShijianDanwei(jiliang.getTixingShijianDanwei());
|
update.setJiliangTixingRiqi(jiliang.getJiliangTixingRiqi());
|
updateYiqiXinxi(jiliang.getYiqiId(), update, id, "仪器计量记录");
|
}
|
|
private void updateYiqiXinxi(String yiqiId, LimsShebeiYiqiXinxiEntity update,
|
String recordId, String recordDescription) throws DataException {
|
yiqiId = trimToEmpty(yiqiId);
|
if (yiqiId.isEmpty()) {
|
throw new DataException(recordDescription + "未关联仪器(yiqi_id):" + recordId);
|
}
|
if (this.getById(yiqiId) == null) {
|
throw new DataException("关联仪器信息不存在:" + yiqiId);
|
}
|
|
update.setId(yiqiId);
|
if (!this.updateById(update)) {
|
throw new DataException(recordDescription + "同步仪器信息失败,请刷新后重试");
|
}
|
}
|
|
private List<String> normalizeIds(List<String> yiqiIds) {
|
Set<String> ids = new LinkedHashSet<>();
|
if (yiqiIds == null) {
|
return new ArrayList<>(ids);
|
}
|
for (String yiqiId : yiqiIds) {
|
String id = trimToEmpty(yiqiId);
|
if (!id.isEmpty()) {
|
ids.add(id);
|
}
|
}
|
return new ArrayList<>(ids);
|
}
|
|
private String trimToEmpty(String value) {
|
return value == null ? "" : value.trim();
|
}
|
|
}
|