|
|
|
@ -9,54 +9,34 @@ 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业务层处理
|
|
|
|
|
* 质检任务Service业务层处理
|
|
|
|
|
*
|
|
|
|
|
* @author zch
|
|
|
|
|
* @date 2025-07-14
|
|
|
|
|
* @date 2025-07-24
|
|
|
|
|
*/
|
|
|
|
|
@Slf4j
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
@Service
|
|
|
|
|
public class QcInspectionMainServiceImpl implements IQcInspectionMainService {
|
|
|
|
|
|
|
|
|
|
private final QcInspectionMainMapper baseMapper;
|
|
|
|
|
private final IQcUnqualifiedReviewService qcUnqualifiedReviewService;
|
|
|
|
|
private final IQcInspectionResultService qcInspectionResultService;
|
|
|
|
|
private final QcUnqualifiedGeneratorService qcUnqualifiedGeneratorService;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询质检主表
|
|
|
|
|
* 查询质检任务
|
|
|
|
|
*
|
|
|
|
|
* @param inspectionId 主键
|
|
|
|
|
* @return 质检主表
|
|
|
|
|
* @return 质检任务
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public QcInspectionMainVo queryById(Long inspectionId){
|
|
|
|
@ -64,11 +44,11 @@ public class QcInspectionMainServiceImpl implements IQcInspectionMainService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 分页查询质检主表列表
|
|
|
|
|
* 分页查询质检任务列表
|
|
|
|
|
*
|
|
|
|
|
* @param bo 查询条件
|
|
|
|
|
* @param pageQuery 分页参数
|
|
|
|
|
* @return 质检主表分页列表
|
|
|
|
|
* @return 质检任务分页列表
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public TableDataInfo<QcInspectionMainVo> queryPageList(QcInspectionMainBo bo, PageQuery pageQuery) {
|
|
|
|
@ -78,10 +58,10 @@ public class QcInspectionMainServiceImpl implements IQcInspectionMainService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询符合条件的质检主表列表
|
|
|
|
|
* 查询符合条件的质检任务列表
|
|
|
|
|
*
|
|
|
|
|
* @param bo 查询条件
|
|
|
|
|
* @return 质检主表列表
|
|
|
|
|
* @return 质检任务列表
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public List<QcInspectionMainVo> queryList(QcInspectionMainBo bo) {
|
|
|
|
@ -93,13 +73,9 @@ public class QcInspectionMainServiceImpl implements IQcInspectionMainService {
|
|
|
|
|
Map<String, Object> params = bo.getParams();
|
|
|
|
|
MPJLambdaWrapper<QcInspectionMain> lqw = JoinWrappers.lambda(QcInspectionMain.class)
|
|
|
|
|
.selectAll(QcInspectionMain.class)
|
|
|
|
|
|
|
|
|
|
//关联检测类型
|
|
|
|
|
.select(QcInspectionType::getTypeName, QcInspectionType::getQcInspectionType, QcInspectionType::getTypeCode)
|
|
|
|
|
.leftJoin(QcInspectionType.class, QcInspectionType::getTypeId, QcInspectionMain::getTypeId)
|
|
|
|
|
|
|
|
|
|
.eq(bo.getInspectionId() != null, QcInspectionMain::getInspectionId, bo.getInspectionId())
|
|
|
|
|
.eq(bo.getInspectionId() != null, QcInspectionMain::getInspectionId, bo.getInspectionId())
|
|
|
|
|
.eq(StringUtils.isNotBlank(bo.getInspectionNo()), QcInspectionMain::getInspectionNo, bo.getInspectionNo())
|
|
|
|
|
.eq(bo.getTemplateId() != null, QcInspectionMain::getTemplateId, bo.getTemplateId())
|
|
|
|
|
.eq(StringUtils.isNotBlank(bo.getMaterialCode()), QcInspectionMain::getMaterialCode, bo.getMaterialCode())
|
|
|
|
|
.eq(StringUtils.isNotBlank(bo.getMaterialType()), QcInspectionMain::getMaterialType, bo.getMaterialType())
|
|
|
|
|
.like(StringUtils.isNotBlank(bo.getMaterialName()), QcInspectionMain::getMaterialName, bo.getMaterialName())
|
|
|
|
@ -110,7 +86,7 @@ public class QcInspectionMainServiceImpl implements IQcInspectionMainService {
|
|
|
|
|
.eq(bo.getUnqualifiedQty() != null, QcInspectionMain::getUnqualifiedQty, bo.getUnqualifiedQty())
|
|
|
|
|
.eq(bo.getResult() != null, QcInspectionMain::getResult, bo.getResult())
|
|
|
|
|
.eq(StringUtils.isNotBlank(bo.getWorkshop()), QcInspectionMain::getWorkshop, bo.getWorkshop())
|
|
|
|
|
.eq(bo.getTypeId() != null, QcInspectionMain::getTypeId, bo.getTypeId())
|
|
|
|
|
.eq(bo.getInspectionType() != null, QcInspectionMain::getInspectionType, bo.getInspectionType())
|
|
|
|
|
.eq(bo.getStatus() != null, QcInspectionMain::getStatus, bo.getStatus())
|
|
|
|
|
.eq(StringUtils.isNotBlank(bo.getInspector()), QcInspectionMain::getInspector, bo.getInspector())
|
|
|
|
|
.eq(StringUtils.isNotBlank(bo.getShift()), QcInspectionMain::getShift, bo.getShift())
|
|
|
|
@ -125,9 +101,9 @@ public class QcInspectionMainServiceImpl implements IQcInspectionMainService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 新增质检主表
|
|
|
|
|
* 新增质检任务
|
|
|
|
|
*
|
|
|
|
|
* @param bo 质检主表
|
|
|
|
|
* @param bo 质检任务
|
|
|
|
|
* @return 是否新增成功
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
@ -142,9 +118,9 @@ public class QcInspectionMainServiceImpl implements IQcInspectionMainService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 修改质检主表
|
|
|
|
|
* 修改质检任务
|
|
|
|
|
*
|
|
|
|
|
* @param bo 质检主表
|
|
|
|
|
* @param bo 质检任务
|
|
|
|
|
* @return 是否修改成功
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
@ -162,7 +138,7 @@ public class QcInspectionMainServiceImpl implements IQcInspectionMainService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 校验并批量删除质检主表信息
|
|
|
|
|
* 校验并批量删除质检任务信息
|
|
|
|
|
*
|
|
|
|
|
* @param ids 待删除的主键集合
|
|
|
|
|
* @param isValid 是否进行有效性校验
|
|
|
|
@ -175,207 +151,4 @@ 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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|