| | |
| | | |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.ruoyi.inspect.event.NewJuOrderPlacedEvent; |
| | | import com.ruoyi.inspect.mapper.InsOrderStandardTemplateMapper; |
| | | import com.ruoyi.inspect.mapper.InsSampleMapper; |
| | | import com.ruoyi.inspect.pojo.InsOrder; |
| | | import com.ruoyi.inspect.pojo.InsOrderStandardTemplate; |
| | | import com.ruoyi.inspect.pojo.InsSample; |
| | | import com.ruoyi.inspect.service.InsOrderService; |
| | | import com.ruoyi.process.mapper.InspectionOrderDetailMapper; |
| | | import com.ruoyi.process.mapper.InspectionOrderMapper; |
| | | import com.ruoyi.process.pojo.InspectionOrder; |
| | | import com.ruoyi.process.pojo.InspectionOrderDetail; |
| | | import lombok.AllArgsConstructor; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.context.event.EventListener; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.time.LocalDate; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 新聚成品下单成功后,自动生成一条检验委托单。 |
| | |
| | | |
| | | private final InsOrderService insOrderService; |
| | | private final InspectionOrderMapper inspectionOrderMapper; |
| | | private final InspectionOrderDetailMapper inspectionOrderDetailMapper; |
| | | private final InsSampleMapper insSampleMapper; |
| | | private final InsOrderStandardTemplateMapper insOrderStandardTemplateMapper; |
| | | |
| | | @EventListener |
| | | public void onNewJuOrderPlaced(NewJuOrderPlacedEvent event) { |
| | |
| | | .eq(InspectionOrder::getInsOrderId, order.getId()).last("limit 1")); |
| | | if (existingOrder != null) { |
| | | existingOrder.setEntrustCode(order.getEntrustCode()); |
| | | existingOrder.setBatchNo(order.getBatchNo()); |
| | | existingOrder.setSampleName(StringUtils.isNotBlank(order.getSampleView()) ? order.getSampleView() : order.getSample()); |
| | | existingOrder.setProduction(order.getProduction()); |
| | | existingOrder.setQuantity(order.getTestQuantity()); |
| | |
| | | InspectionOrder inspectionOrder = new InspectionOrder(); |
| | | inspectionOrder.setInsOrderId(order.getId()); |
| | | inspectionOrder.setEntrustCode(order.getEntrustCode()); |
| | | inspectionOrder.setBatchNo(order.getBatchNo()); |
| | | // 试样名称优先取报告展示字段 |
| | | inspectionOrder.setSampleName(StringUtils.isNotBlank(order.getSampleView()) |
| | | ? order.getSampleView() : order.getSample()); |
| | |
| | | } |
| | | // 报告文件与约定时间生成时为空,后续在检验委托单页面编辑/上传 |
| | | inspectionOrderMapper.insert(inspectionOrder); |
| | | createDetailRow(inspectionOrder, order); |
| | | } |
| | | |
| | | /** |
| | | * 下单即生成一行样品明细,批量下单后整批样品直接汇总在同一张委托书里。 |
| | | */ |
| | | private void createDetailRow(InspectionOrder inspectionOrder, InsOrder order) { |
| | | InspectionOrderDetail detail = new InspectionOrderDetail(); |
| | | detail.setInspectionOrderId(inspectionOrder.getInspectionOrderId()); |
| | | detail.setSampleName(inspectionOrder.getSampleName()); |
| | | detail.setQuantity(order.getTestQuantity()); |
| | | detail.setSampleStatus(inspectionOrder.getSampleStatus()); |
| | | detail.setTestStandard(order.getSample()); |
| | | |
| | | List<InsSample> samples = insSampleMapper.selectList(Wrappers.<InsSample>lambdaQuery() |
| | | .eq(InsSample::getInsOrderId, order.getId()) |
| | | .orderByAsc(InsSample::getId)); |
| | | if (!samples.isEmpty()) { |
| | | detail.setSampleNumber(samples.get(0).getSampleCode()); |
| | | } |
| | | String testItem = insOrderStandardTemplateMapper.selectList( |
| | | Wrappers.<InsOrderStandardTemplate>lambdaQuery() |
| | | .eq(InsOrderStandardTemplate::getInsOrderId, order.getId()) |
| | | .orderByAsc(InsOrderStandardTemplate::getSort, InsOrderStandardTemplate::getId)) |
| | | .stream() |
| | | .map(InsOrderStandardTemplate::getName) |
| | | .filter(StringUtils::isNotBlank) |
| | | .collect(Collectors.joining("、")); |
| | | detail.setTestItem(testItem); |
| | | inspectionOrderDetailMapper.insert(detail); |
| | | } |
| | | } |