|
|
|
@ -5,6 +5,7 @@ import lombok.RequiredArgsConstructor;
|
|
|
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
|
|
import org.apache.dubbo.config.annotation.DubboService;
|
|
|
|
|
import org.dromara.common.core.exception.ServiceException;
|
|
|
|
|
import org.dromara.common.core.utils.DateUtils;
|
|
|
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
|
|
|
import org.dromara.common.core.utils.uuid.IdUtils;
|
|
|
|
|
import org.dromara.common.satoken.utils.LoginHelper;
|
|
|
|
@ -29,6 +30,8 @@ import org.dromara.qms.domain.bo.QcUnqualifiedReviewBo;
|
|
|
|
|
import org.dromara.qms.domain.bo.QcUnqualifiedRecordBo;
|
|
|
|
|
import org.dromara.qms.domain.vo.QcInspectionResultVo;
|
|
|
|
|
import org.dromara.common.core.utils.MapstructUtils;
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
@ -145,22 +148,48 @@ public class QcPDAServiceImpl implements IQcPDAService {
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public Boolean submitInspection(QcInspectionMainBo bo) {
|
|
|
|
|
// 根据传入的检验ID查询主记录信息
|
|
|
|
|
QcInspectionMainVo main = qcInspectionMainService.queryById(bo.getInspectionId());
|
|
|
|
|
Long inspectionId = bo.getInspectionId();
|
|
|
|
|
Date nowDate = DateUtils.getNowDate();
|
|
|
|
|
String username = LoginHelper.getUsername();
|
|
|
|
|
QcInspectionMainVo main = qcInspectionMainService.queryById(inspectionId);
|
|
|
|
|
if (main == null) {
|
|
|
|
|
// 如果未找到对应的主记录,抛出异常提示任务不存在
|
|
|
|
|
throw new ServiceException("任务不存在!");
|
|
|
|
|
throw new ServiceException("此质检任务不存在!");
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isNotEmpty(main.getStatus()) && main.getStatus().equals("1")) {
|
|
|
|
|
throw new ServiceException("此质检任务已质检!");
|
|
|
|
|
}
|
|
|
|
|
List<QcInspectionResultBo> results = bo.getResults();
|
|
|
|
|
if (results.isEmpty()) {
|
|
|
|
|
throw new ServiceException("请提交质检任务详情!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 标记是否存在不合格项,默认为false(合格)
|
|
|
|
|
boolean isUnqualified = false;
|
|
|
|
|
// 遍历提交的所有检测结果
|
|
|
|
|
for (QcInspectionResultBo resultBo : bo.getResults()) {
|
|
|
|
|
for (QcInspectionResultBo resultBo : results) {
|
|
|
|
|
Long resultId = resultBo.getResultId();
|
|
|
|
|
// 根据结果ID查询已有的结果详情
|
|
|
|
|
QcInspectionResultVo existingResult = qcInspectionResultService.queryById(resultBo.getResultId());
|
|
|
|
|
if (existingResult == null || !existingResult.getInspectionId().equals(bo.getInspectionId())) {
|
|
|
|
|
QcInspectionResultVo existingResult = qcInspectionResultService.queryById(resultId);
|
|
|
|
|
if (existingResult == null || !existingResult.getInspectionId().equals(inspectionId)) {
|
|
|
|
|
// 如果结果不存在或不属于当前检验任务,则视为无效ID,抛出异常
|
|
|
|
|
throw new ServiceException("结果不存在或不属于当前检验任务!");
|
|
|
|
|
}
|
|
|
|
|
String detectType = existingResult.getDetectType();
|
|
|
|
|
if (detectType.equals("1")){
|
|
|
|
|
BigDecimal upperLimit = existingResult.getUpperLimit();
|
|
|
|
|
BigDecimal lowerLimit = existingResult.getLowerLimit();
|
|
|
|
|
BigDecimal detectValue = resultBo.getDetectValue();
|
|
|
|
|
//标准值判断
|
|
|
|
|
boolean isWithinRange = (detectValue.compareTo(lowerLimit) >= 0) && (detectValue.compareTo(upperLimit) <= 0);
|
|
|
|
|
if (isWithinRange) {
|
|
|
|
|
resultBo.setDetectResult("0");
|
|
|
|
|
} else {
|
|
|
|
|
resultBo.setDetectResult("1");
|
|
|
|
|
}
|
|
|
|
|
//标准规格值判断
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 将修改后的对象转换为BO并调用服务进行持久化更新
|
|
|
|
|
qcInspectionResultService.updateByBo(resultBo);
|
|
|
|
|
|
|
|
|
@ -177,6 +206,9 @@ public class QcPDAServiceImpl implements IQcPDAService {
|
|
|
|
|
// 设置质检结果:'1'表示不合格,'0'表示合格
|
|
|
|
|
bo.setResult(isUnqualified ? "1" : "0");
|
|
|
|
|
// 更新主记录
|
|
|
|
|
bo.setInspector(username);
|
|
|
|
|
bo.setInspectionStartTime(nowDate);
|
|
|
|
|
bo.setInspectionEndTime(nowDate);
|
|
|
|
|
qcInspectionMainService.updateByBo(bo);
|
|
|
|
|
|
|
|
|
|
// 如果存在不合格项,则需要创建不合格评审流程及相关记录
|
|
|
|
@ -198,22 +230,15 @@ public class QcPDAServiceImpl implements IQcPDAService {
|
|
|
|
|
reviewBo.setMaterialName(main.getMaterialName());
|
|
|
|
|
// 复制物料编码
|
|
|
|
|
reviewBo.setMaterialCode(main.getMaterialCode());
|
|
|
|
|
// reviewBo.setMaterialSpec(main.getMaterialSpec());
|
|
|
|
|
|
|
|
|
|
reviewBo.setSupplierName(main.getSupplierName());
|
|
|
|
|
// 复制检验数量
|
|
|
|
|
reviewBo.setInspectionQty(main.getInspectionQty());
|
|
|
|
|
// 假设条形码作为批次号使用
|
|
|
|
|
reviewBo.setBatchNo(main.getBarcode());
|
|
|
|
|
// 设置当前登录用户的用户名作为检验员
|
|
|
|
|
reviewBo.setInspector(LoginHelper.getUsername());
|
|
|
|
|
// 设置当前用户的ID作为检验员ID
|
|
|
|
|
reviewBo.setInspectorId(LoginHelper.getUserId());
|
|
|
|
|
// 记录当前日期为生产日期
|
|
|
|
|
reviewBo.setProductionDate(new Date());
|
|
|
|
|
// TODO: 可根据需求补充其他必要字段
|
|
|
|
|
|
|
|
|
|
// 插入不合格评审记录到数据库
|
|
|
|
|
Boolean b = qcUnqualifiedReviewService.insertByBo(reviewBo);
|
|
|
|
|
qcUnqualifiedReviewService.insertByBo(reviewBo);
|
|
|
|
|
|
|
|
|
|
// 再次遍历所有检测结果,针对每个不合格项创建详细记录
|
|
|
|
|
for (QcInspectionResultBo resultBo : bo.getResults()) {
|
|
|
|
@ -230,7 +255,7 @@ public class QcPDAServiceImpl implements IQcPDAService {
|
|
|
|
|
// 设置检验位置
|
|
|
|
|
recordBo.setInspectionPosition(resultBo.getInspectionPosition());
|
|
|
|
|
// 转换分类名称为Long类型并设置
|
|
|
|
|
recordBo.setCategoryName(Long.valueOf(resultBo.getCategoryName()));
|
|
|
|
|
recordBo.setCategoryName(resultBo.getCategoryName());
|
|
|
|
|
// 设置类型ID
|
|
|
|
|
recordBo.setTypeId(resultBo.getTypeId());
|
|
|
|
|
// recordBo.setInspectionMethod(); // 如果需要可补充检验方法字段
|
|
|
|
|