| | |
| | | import cn.iocoder.yudao.module.mes.service.qc.oqc.MesQcOqcService; |
| | | import cn.iocoder.yudao.module.mes.service.qc.rqc.MesQcRqcService; |
| | | import cn.iocoder.yudao.module.system.api.dict.DictDataApi; |
| | | import cn.iocoder.yudao.module.system.api.storage.StorageAttachmentApi; |
| | | import jakarta.annotation.Resource; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | @Resource |
| | | private DictDataApi dictDataApi; |
| | | |
| | | @Resource |
| | | private StorageAttachmentApi storageAttachmentApi; |
| | | |
| | | /** 过程检验行附件的存储关联类型(与 MesQcAttachmentController 保持一致) */ |
| | | private static final String IPQC_DETAIL_RECORD_TYPE = "mes_qc_ipqc_detail_attachment"; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Long createIndicatorResult(MesQcIndicatorResultSaveReqVO createReqVO) { |
| | |
| | | List<MesQcIndicatorResultDetailDO> details = BeanUtils.toBean(updateReqVO.getItems(), |
| | | MesQcIndicatorResultDetailDO.class); |
| | | resultDetailService.createOrUpdateDetailList(details); |
| | | // 2.3 过程检验支持手工增删检验行:删除本次未提交的明细,并清理其行附件关联 |
| | | if (MesQcTypeEnum.IPQC.getType().equals(updateReqVO.getQcType())) { |
| | | deleteIndicatorDetailsRemoved(updateReqVO.getId(), updateReqVO.getItems()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 删除本次保存中已被移除的过程检验行(行附件一并解绑) |
| | | */ |
| | | private void deleteIndicatorDetailsRemoved(Long resultId, List<MesQcIndicatorResultSaveReqVO.Item> items) { |
| | | Set<Long> keepIds = convertSet(items, MesQcIndicatorResultSaveReqVO.Item::getId); |
| | | List<Long> removedIds = resultDetailService.getDetailListByResultId(resultId).stream() |
| | | .map(MesQcIndicatorResultDetailDO::getId) |
| | | .filter(id -> id != null && !keepIds.contains(id)) |
| | | .toList(); |
| | | if (CollUtil.isEmpty(removedIds)) { |
| | | return; |
| | | } |
| | | removedIds.forEach(detailId -> |
| | | storageAttachmentApi.bindAttachments("file", IPQC_DETAIL_RECORD_TYPE, detailId, Collections.emptyList())); |
| | | resultDetailService.deleteDetailList(removedIds); |
| | | } |
| | | |
| | | @Override |
| | |
| | | return resultMapper.selectCountByQcIdAndType(qcId, qcType); |
| | | } |
| | | |
| | | /** |
| | | * 获取指定质检单下的检验结果列表 |
| | | * |
| | | * @param qcId 质检单 ID |
| | | * @param qcType 质检类型 |
| | | * @return 结果列表 |
| | | */ |
| | | @Override |
| | | public List<MesQcIndicatorResultDO> getIndicatorResultListByQcIdAndType(Long qcId, Integer qcType) { |
| | | return resultMapper.selectListByQcIdAndType(qcId, qcType); |
| | | } |
| | | |
| | | @Override |
| | | public List<MesQcIndicatorResultDO> getIndicatorResultListByQcIdsAndType(List<Long> qcIds, Integer qcType) { |
| | | if (CollUtil.isEmpty(qcIds)) { |
| | | return Collections.emptyList(); |
| | | } |
| | | return resultMapper.selectListByQcIdsAndType(qcIds, qcType); |
| | | } |
| | | |
| | | @Override |
| | | public List<MesQcIndicatorResultDetailDO> getIndicatorResultDetailListByResultIds(List<Long> resultIds) { |
| | | if (CollUtil.isEmpty(resultIds)) { |
| | | return Collections.emptyList(); |
| | | } |
| | | return resultDetailService.getDetailListByResultIds(resultIds); |
| | | } |
| | | |
| | | @Override |
| | | public void validateIndicatorResultExistsByQcIdAndType(Long qcId, Integer qcType) { |
| | | Long resultCount = getIndicatorResultCountByQcIdAndType(qcId, qcType); |