| | |
| | | |
| | | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.qc.seedquality.vo.MesQcSeedQualitySubmitReqVO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.pro.batch.MesProBatchDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.qc.seedquality.*; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.batch.MesWmBatchDO; |
| | | import cn.iocoder.yudao.module.mes.dal.mysql.qc.seedquality.*; |
| | | import cn.iocoder.yudao.module.mes.enums.wm.MesWmStockStateEnum; |
| | | import cn.iocoder.yudao.module.mes.service.pro.batch.MesProBatchService; |
| | | import cn.iocoder.yudao.module.mes.service.wm.batch.MesWmBatchService; |
| | | import cn.iocoder.yudao.module.mes.service.wm.materialstock.MesWmMaterialStockService; |
| | | import jakarta.annotation.Resource; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.jdbc.BadSqlGrammarException; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import java.time.LocalDateTime; |
| | | import java.util.*; |
| | | |
| | | @Service @Validated |
| | | @Service @Validated @Slf4j |
| | | public class MesQcSeedQualityServiceImpl implements MesQcSeedQualityService { |
| | | private static final Set<String> REQUIRED = Set.of("purity", "cleanliness", "germination_rate", "moisture"); |
| | | @Resource private MesQcSeedQualityMapper qualityMapper; |
| | | @Resource private MesQcSeedQualityIndicatorMapper indicatorMapper; |
| | | @Resource private MesProBatchService proBatchService; |
| | | @Resource private MesWmBatchService mesWmBatchService; |
| | | @Resource private MesWmMaterialStockService materialStockService; |
| | | |
| | | @Override @Transactional(rollbackFor = Exception.class) |
| | | public Long submit(MesQcSeedQualitySubmitReqVO reqVO) { |
| | |
| | | if (!codes.equals(REQUIRED)) throw new IllegalArgumentException("四项指标不完整"); |
| | | quality.setResult(passed ? 1 : 2); |
| | | qualityMapper.updateById(quality); |
| | | // 质检合格 → 库存整批由暂存库(待质检)转为合格库(正式库存) |
| | | if (passed) { |
| | | MesProBatchDO proBatch = proBatchService.getBatchByCode(reqVO.getBatchCode()); |
| | | if (proBatch != null) { |
| | | MesWmBatchDO wmBatch = mesWmBatchService.getOrCreateByProBatch(proBatch); |
| | | if (wmBatch != null) { |
| | | int updated = materialStockService.updateStockStateByBatchId(wmBatch.getId(), |
| | | MesWmStockStateEnum.QUALIFIED.getState(), MesWmStockStateEnum.TEMP.getState()); |
| | | log.info("[submit][质检合格,批次 {} 库存由暂存库转合格库,影响 {} 条]", reqVO.getBatchCode(), updated); |
| | | } |
| | | } |
| | | } |
| | | // 库位由后台配置服务接管,当前版本保留审计闭环,禁止前端传入库位。 |
| | | return quality.getId(); |
| | | } |
| | | |
| | | @Override |
| | | public List<MesQcSeedQualityDO> getQualityByBatchCode(String batchCode) { |
| | | try { |
| | | return qualityMapper.selectListByBatchCode(batchCode); |
| | | } catch (BadSqlGrammarException ex) { |
| | | // 种子质检表未初始化时容错,不阻塞公开溯源 |
| | | log.warn("[getQualityByBatchCode][种子质检表未初始化,批次 {} 查询失败: {}]", batchCode, ex.getMessage()); |
| | | return List.of(); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public List<MesQcSeedQualityIndicatorDO> getIndicatorsByQualityId(Long qualityId) { |
| | | try { |
| | | return indicatorMapper.selectListByQualityId(qualityId); |
| | | } catch (BadSqlGrammarException ex) { |
| | | // 种子质检表未初始化时容错 |
| | | log.warn("[getIndicatorsByQualityId][种子质检指标表未初始化,质检 {} 查询失败: {}]", qualityId, ex.getMessage()); |
| | | return List.of(); |
| | | } |
| | | } |
| | | } |