|
|
|
@ -9,18 +9,32 @@ import com.github.yulichang.toolkit.JoinWrappers;
|
|
|
|
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.dromara.qms.domain.QcInspectionTemplate;
|
|
|
|
|
import org.dromara.qms.domain.QcInspectionType;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import org.dromara.qms.domain.bo.QcInspectionMainBo;
|
|
|
|
|
import org.dromara.qms.domain.vo.QcInspectionMainVo;
|
|
|
|
|
import org.dromara.qms.domain.QcInspectionMain;
|
|
|
|
|
import org.dromara.qms.mapper.QcInspectionMainMapper;
|
|
|
|
|
import org.dromara.qms.service.IQcInspectionMainService;
|
|
|
|
|
import org.dromara.qms.service.IQcUnqualifiedReviewService;
|
|
|
|
|
import org.dromara.qms.service.IQcInspectionResultService;
|
|
|
|
|
import org.dromara.qms.domain.QcInspectionResult;
|
|
|
|
|
import org.dromara.qms.domain.vo.QcInspectionResultVo;
|
|
|
|
|
import org.dromara.qms.domain.vo.QcInspectionItemDetailVo;
|
|
|
|
|
import org.dromara.qms.domain.bo.QcUnqualifiedReviewBo;
|
|
|
|
|
import org.dromara.qms.domain.bo.QcInspectionResultBo;
|
|
|
|
|
import org.dromara.qms.utils.QcInspectionResultCalculator;
|
|
|
|
|
import org.dromara.common.satoken.utils.LoginHelper;
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 质检主表Service业务层处理
|
|
|
|
@ -28,11 +42,15 @@ import java.util.Collection;
|
|
|
|
|
* @author zch
|
|
|
|
|
* @date 2025-07-14
|
|
|
|
|
*/
|
|
|
|
|
@Slf4j
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
@Service
|
|
|
|
|
public class QcInspectionMainServiceImpl implements IQcInspectionMainService {
|
|
|
|
|
|
|
|
|
|
private final QcInspectionMainMapper baseMapper;
|
|
|
|
|
private final IQcUnqualifiedReviewService qcUnqualifiedReviewService;
|
|
|
|
|
private final IQcInspectionResultService qcInspectionResultService;
|
|
|
|
|
private final QcUnqualifiedGeneratorService qcUnqualifiedGeneratorService;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询质检主表
|
|
|
|
@ -157,4 +175,207 @@ public class QcInspectionMainServiceImpl implements IQcInspectionMainService {
|
|
|
|
|
}
|
|
|
|
|
return baseMapper.deleteByIds(ids) > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 分页查询未处理质检任务列表 (for PDA)
|
|
|
|
|
* 过滤未处理任务并支持用户权限
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public TableDataInfo<QcInspectionMainVo> queryPageUnprocessedTasks(QcInspectionMainBo bo, PageQuery pageQuery) {
|
|
|
|
|
// 设置查询条件:只查询未处理的任务
|
|
|
|
|
bo.setStatus(0L); // 单据状态(0未处理/1完成)
|
|
|
|
|
return queryPageList(bo, pageQuery);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询质检详情包括子表检测项 (for PDA)
|
|
|
|
|
* 关联查询检测项明细数据
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public QcInspectionMainVo queryByIdWithResults(Long inspectionId) {
|
|
|
|
|
QcInspectionMainVo mainVo = queryById(inspectionId);
|
|
|
|
|
if (mainVo != null) {
|
|
|
|
|
// 查询关联的检测项结果明细
|
|
|
|
|
QcInspectionResultBo resultBo = new QcInspectionResultBo();
|
|
|
|
|
resultBo.setInspectionId(inspectionId);
|
|
|
|
|
List<QcInspectionResultVo> results = qcInspectionResultService.queryList(resultBo);
|
|
|
|
|
|
|
|
|
|
// 将检测项结果设置到主表VO中
|
|
|
|
|
// 注意:这里假设QcInspectionMainVo有results字段,如果没有需要添加
|
|
|
|
|
// mainVo.setResults(results);
|
|
|
|
|
}
|
|
|
|
|
return mainVo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 提交质检结果 (for PDA)
|
|
|
|
|
* 包含数据验证、结果计算、不合格品生成逻辑
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public Boolean submitInspectionResult(QcInspectionMainBo bo) {
|
|
|
|
|
try {
|
|
|
|
|
// 1. 验证质检数据的完整性
|
|
|
|
|
if (!validateInspectionData(bo)) {
|
|
|
|
|
log.error("质检数据验证失败: {}", bo.getInspectionId());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 2. 查询检测项数据
|
|
|
|
|
List<QcInspectionItemDetailVo> inspectionItems = getInspectionItems(bo.getInspectionId());
|
|
|
|
|
|
|
|
|
|
// 3. 计算检测项结果状态
|
|
|
|
|
Long overallResult = QcInspectionResultCalculator.calculateOverallResult(inspectionItems);
|
|
|
|
|
|
|
|
|
|
// 4. 更新质检主表结果
|
|
|
|
|
bo.setResult(overallResult);
|
|
|
|
|
bo.setStatus(1L); // 设置为已完成
|
|
|
|
|
bo.setInspectionTime(new Date());
|
|
|
|
|
bo.setUpdateBy(LoginHelper.getUserId());
|
|
|
|
|
bo.setUpdateTime(new Date());
|
|
|
|
|
|
|
|
|
|
// 计算合格数和不合格数
|
|
|
|
|
calculateQualifiedQuantities(bo, inspectionItems);
|
|
|
|
|
|
|
|
|
|
Boolean updated = updateByBo(bo);
|
|
|
|
|
if (!updated) {
|
|
|
|
|
log.error("更新质检主表失败: {}", bo.getInspectionId());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 5. 如果存在不合格项,自动生成不合格品评审任务
|
|
|
|
|
if (QcInspectionResultCalculator.RESULT_STATUS_UNQUALIFIED.equals(overallResult)) {
|
|
|
|
|
QcInspectionMainVo inspectionVo = queryById(bo.getInspectionId());
|
|
|
|
|
Boolean generated = qcUnqualifiedGeneratorService.autoGenerateUnqualifiedReview(inspectionVo, inspectionItems);
|
|
|
|
|
if (!generated) {
|
|
|
|
|
log.warn("生成不合格品评审任务失败,但质检结果已保存: {}", bo.getInspectionId());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.info("质检结果提交成功: 任务ID={}, 结果={}", bo.getInspectionId(),
|
|
|
|
|
overallResult == 0 ? "合格" : "不合格");
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("提交质检结果异常: {}", bo.getInspectionId(), e);
|
|
|
|
|
throw e; // 让事务回滚
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 分页查询质检任务历史记录 (for PDA)
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public TableDataInfo<QcInspectionMainVo> queryPageTaskHistory(QcInspectionMainBo bo, PageQuery pageQuery) {
|
|
|
|
|
// 设置查询条件:只查询已完成的任务
|
|
|
|
|
bo.setStatus(1L); // 单据状态(0未处理/1完成)
|
|
|
|
|
return queryPageList(bo, pageQuery);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 分页查询用户分派的质检任务 (for PDA)
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public TableDataInfo<QcInspectionMainVo> queryPageUserTasks(String inspector, PageQuery pageQuery) {
|
|
|
|
|
QcInspectionMainBo bo = new QcInspectionMainBo();
|
|
|
|
|
//TODO:考虑质检人是填id还是name
|
|
|
|
|
bo.setInspector(inspector);
|
|
|
|
|
return queryPageList(bo, pageQuery);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 验证质检数据的完整性和业务规则 (for PDA)
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public Boolean validateInspectionData(QcInspectionMainBo bo) {
|
|
|
|
|
QcInspectionResultCalculator.ValidationResult result = QcInspectionResultCalculator.validateInspectionData(bo);
|
|
|
|
|
|
|
|
|
|
if (result.hasErrors()) {
|
|
|
|
|
log.warn("质检数据验证失败: {}, 错误: {}", bo.getInspectionId(), result.getErrors());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 验证检测项数据
|
|
|
|
|
List<QcInspectionItemDetailVo> inspectionItems = getInspectionItems(bo.getInspectionId());
|
|
|
|
|
QcInspectionResultCalculator.ValidationResult itemsResult = QcInspectionResultCalculator.validateInspectionItems(inspectionItems);
|
|
|
|
|
|
|
|
|
|
if (itemsResult.hasErrors()) {
|
|
|
|
|
log.warn("检测项数据验证失败: {}, 错误: {}", bo.getInspectionId(), itemsResult.getErrors());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取检测项数据
|
|
|
|
|
* 这里需要根据实际的数据结构来实现
|
|
|
|
|
*/
|
|
|
|
|
private List<QcInspectionItemDetailVo> getInspectionItems(Long inspectionId) {
|
|
|
|
|
// 这里应该查询检测项明细数据
|
|
|
|
|
// 由于没有具体的检测项明细表结构,这里返回空列表
|
|
|
|
|
// 实际实现中需要根据具体的表结构来查询
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
QcInspectionResultBo resultBo = new QcInspectionResultBo();
|
|
|
|
|
resultBo.setInspectionId(inspectionId);
|
|
|
|
|
List<QcInspectionResultVo> results = qcInspectionResultService.queryList(resultBo);
|
|
|
|
|
|
|
|
|
|
// 将QcInspectionResultVo转换为QcInspectionItemDetailVo
|
|
|
|
|
List<QcInspectionItemDetailVo> items = new ArrayList<>();
|
|
|
|
|
for (QcInspectionResultVo result : results) {
|
|
|
|
|
QcInspectionItemDetailVo item = convertToItemDetail(result);
|
|
|
|
|
items.add(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return items;
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("获取检测项数据失败: {}", inspectionId, e);
|
|
|
|
|
return new ArrayList<>();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 将QcInspectionResultVo转换为QcInspectionItemDetailVo
|
|
|
|
|
*/
|
|
|
|
|
private QcInspectionItemDetailVo convertToItemDetail(QcInspectionResultVo result) {
|
|
|
|
|
QcInspectionItemDetailVo item = new QcInspectionItemDetailVo();
|
|
|
|
|
|
|
|
|
|
// 这里需要根据实际的字段映射来转换
|
|
|
|
|
// 由于没有看到QcInspectionResultVo的具体结构,这里只是示例
|
|
|
|
|
item.setItemId(result.getResultId());
|
|
|
|
|
// item.setItemCode(result.getItemCode());
|
|
|
|
|
// item.setItemName(result.getItemName());
|
|
|
|
|
// ... 其他字段映射
|
|
|
|
|
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 计算合格数和不合格数
|
|
|
|
|
*/
|
|
|
|
|
private void calculateQualifiedQuantities(QcInspectionMainBo bo, List<QcInspectionItemDetailVo> inspectionItems) {
|
|
|
|
|
if (inspectionItems == null || inspectionItems.isEmpty()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 计算不合格项数量
|
|
|
|
|
long unqualifiedCount = inspectionItems.stream()
|
|
|
|
|
.filter(item -> QcInspectionResultCalculator.RESULT_STATUS_UNQUALIFIED.equals(
|
|
|
|
|
QcInspectionResultCalculator.calculateItemResultStatus(item)))
|
|
|
|
|
.count();
|
|
|
|
|
BigDecimal unqualifiedCountBigDecimal = BigDecimal.valueOf(unqualifiedCount);
|
|
|
|
|
|
|
|
|
|
// 设置不合格数量
|
|
|
|
|
bo.setUnqualifiedQty(unqualifiedCountBigDecimal);
|
|
|
|
|
|
|
|
|
|
// 计算合格数量(总检测数量 - 不合格数量)
|
|
|
|
|
BigDecimal totalQty = bo.getInspectionQty();
|
|
|
|
|
if (totalQty != null) {
|
|
|
|
|
|
|
|
|
|
// bo.setQualifiedQty(totalQty - unqualifiedCount);
|
|
|
|
|
BigDecimal subtract = totalQty.subtract(unqualifiedCountBigDecimal);
|
|
|
|
|
bo.setQualifiedQty(subtract);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|