| | |
| | | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.basic.dto.InventoryDetailDTO; |
| | | import com.ruoyi.basic.mapper.IfsInventoryQuantityMapper; |
| | | import com.ruoyi.basic.mapper.StandardProductListMapper; |
| | | import com.ruoyi.basic.mapper.StructureItemParameterMapper; |
| | |
| | | import com.ruoyi.common.constant.InsOrderTypeConstants; |
| | | import com.ruoyi.common.core.domain.Result; |
| | | import com.ruoyi.common.core.domain.entity.User; |
| | | import com.ruoyi.common.enums.OrderType; |
| | | import com.ruoyi.common.numgen.NumberGenerator; |
| | | import com.ruoyi.common.utils.*; |
| | | import com.ruoyi.common.utils.LimsDateUtil; |
| | | import com.ruoyi.common.utils.QueryWrappers; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.api.IfsApiUtils; |
| | | import com.ruoyi.framework.exception.ErrorException; |
| | | import com.ruoyi.inspect.dto.*; |
| | |
| | | import com.ruoyi.inspect.service.InsOrderStateService; |
| | | import com.ruoyi.inspect.service.InsProductService; |
| | | import com.ruoyi.inspect.service.InsSampleService; |
| | | import com.ruoyi.inspect.vo.IfsOrderVO; |
| | | import com.ruoyi.inspect.vo.InsOrderPrintingVo; |
| | | import com.ruoyi.system.mapper.UserMapper; |
| | | import lombok.AllArgsConstructor; |
| | |
| | | } |
| | | } |
| | | }); |
| | | //是否为原材料下单 |
| | | if (insOrder.getTypeSource() != null && insOrder.getTypeSource().equals(1)) { |
| | | // 原材料下单: 委托人就是报检人, 生产单位就是供应商单位 |
| | | //原材料下单或外购成品下单 |
| | | if (Objects.nonNull(insOrder.getTypeSource())&&Objects.nonNull(insOrder.getIfsInventoryId())) { |
| | | // 委托人就是报检人, 生产单位就是供应商单位 |
| | | IfsInventoryQuantity ifsInventoryQuantity = ifsInventoryQuantityMapper.selectById(insOrder.getIfsInventoryId()); |
| | | Integer declareUserId = ifsInventoryQuantity.getDeclareUserId(); |
| | | User user = userMapper.selectById(declareUserId); |
| | |
| | | upInsOrderOfState(insOrder); |
| | | |
| | | // 分配检验人 |
| | | upInsOrder(insOrder.getId(), null, appointed != null ? appointed.toString() : null, SecurityUtils.getUserId().intValue(), "原材料"); |
| | | String sonLaboratory = insOrder.getTypeSource().equals(1)?"原材料":"成品实验室"; |
| | | upInsOrder(insOrder.getId(), null, appointed != null ? appointed.toString() : null, SecurityUtils.getUserId().intValue(), sonLaboratory); |
| | | |
| | | // 根据零件号判断是否是辅材 |
| | | boolean isRaw = false; |
| | | StructureTestObject productObject = insOrderMapper.selectProductByPartNo(ifsInventoryQuantity.getPartNo()); |
| | | // 查询产品 |
| | | if (productObject != null && StrUtil.isNotBlank(productObject.getObjectType()) && productObject.getObjectType().equals("1")) { |
| | | isRaw = true; |
| | | } else { |
| | | // 查询对象 |
| | | StructureTestObject testObject = insOrderMapper.selectByPartNo(ifsInventoryQuantity.getPartNo()); |
| | | if (testObject != null && StrUtil.isNotBlank(testObject.getObjectType()) && testObject.getObjectType().equals("1")) { |
| | | //是否为原材料下单 |
| | | if(insOrder.getTypeSource().equals(1)){ |
| | | // 根据零件号判断是否是辅材 |
| | | boolean isRaw = false; |
| | | StructureTestObject productObject = insOrderMapper.selectProductByPartNo(ifsInventoryQuantity.getPartNo()); |
| | | // 查询产品 |
| | | if (productObject != null && StrUtil.isNotBlank(productObject.getObjectType()) && productObject.getObjectType().equals("1")) { |
| | | isRaw = true; |
| | | } else { |
| | | // 查询对象 |
| | | StructureTestObject testObject = insOrderMapper.selectByPartNo(ifsInventoryQuantity.getPartNo()); |
| | | if (testObject != null && StrUtil.isNotBlank(testObject.getObjectType()) && testObject.getObjectType().equals("1")) { |
| | | isRaw = true; |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (isRaw) { |
| | | // 获取当前季度的开始时间和结束时间 |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | // 获取当前月份 |
| | | int month = now.getMonthValue(); |
| | | // 确定当前季度的开始月份 |
| | | int startMonth = (month - 1) / 3 * 3 + 1; |
| | | // 构造季度的开始时间 |
| | | LocalDateTime startOfQuarter = LocalDateTime.of(now.getYear(), Month.of(startMonth), 1, 0, 0); |
| | | // 计算下一个季度的开始时间 |
| | | LocalDateTime startOfNextQuarter = startOfQuarter.plusMonths(3); |
| | | // 计算当前季度的结束时间 |
| | | LocalDateTime endOfQuarter = startOfNextQuarter.minusSeconds(1); |
| | | if (isRaw) { |
| | | // 获取当前季度的开始时间和结束时间 |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | // 获取当前月份 |
| | | int month = now.getMonthValue(); |
| | | // 确定当前季度的开始月份 |
| | | int startMonth = (month - 1) / 3 * 3 + 1; |
| | | // 构造季度的开始时间 |
| | | LocalDateTime startOfQuarter = LocalDateTime.of(now.getYear(), Month.of(startMonth), 1, 0, 0); |
| | | // 计算下一个季度的开始时间 |
| | | LocalDateTime startOfNextQuarter = startOfQuarter.plusMonths(3); |
| | | // 计算当前季度的结束时间 |
| | | LocalDateTime endOfQuarter = startOfNextQuarter.minusSeconds(1); |
| | | |
| | | // 根据下单的规格型号判断是否为季度首次出现 |
| | | Integer count = ifsInventoryQuantityMapper.selectIsFirst(insOrder.getPartDetail(), |
| | | ifsInventoryQuantity.getSupplierName(), |
| | | startOfNextQuarter, |
| | | endOfQuarter); |
| | | // 根据下单的规格型号判断是否为季度首次出现 |
| | | Integer count = ifsInventoryQuantityMapper.selectIsFirst(insOrder.getPartDetail(), |
| | | ifsInventoryQuantity.getSupplierName(), |
| | | startOfNextQuarter, |
| | | endOfQuarter); |
| | | |
| | | if(count == 0) { |
| | | ifsInventoryQuantity.setIsFirst(1); |
| | | ifsInventoryQuantityMapper.update(null, Wrappers.<IfsInventoryQuantity>lambdaUpdate() |
| | | .eq(IfsInventoryQuantity::getId, insOrder.getIfsInventoryId()) |
| | | .set(IfsInventoryQuantity::getIsFirst, 1)); |
| | | if (count == 0) { |
| | | ifsInventoryQuantity.setIsFirst(1); |
| | | ifsInventoryQuantityMapper.update(null, Wrappers.<IfsInventoryQuantity>lambdaUpdate() |
| | | .eq(IfsInventoryQuantity::getId, insOrder.getIfsInventoryId()) |
| | | .set(IfsInventoryQuantity::getIsFirst, 1)); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | @Override |
| | | public Map<String, Object> getInsOrderAndSample(Integer id, String laboratory) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | InsOrder insOrder = insOrderMapper.selectById(id); |
| | | // InsOrder insOrder = insOrderMapper.selectById(id); |
| | | IfsOrderVO ifsOrderVO = insOrderMapper.selectOrderInfoById(id); |
| | | List<SampleProductDto> list = insSampleMapper.getInsOrderAndSample(id, laboratory); |
| | | map.put("insOrder", insOrder); |
| | | map.put("insOrder", ifsOrderVO); |
| | | map.put("sampleProduct", list); |
| | | //查询所有记录模版去重 |
| | | List<Map<Integer, Object>> list2 = insOrderMapper.selectReportModelByOrderId(id, laboratory); |
| | |
| | | if(isSplitOrder){ |
| | | ifsInventoryQuantity.setIsSplitOrder(1); |
| | | } |
| | | //todo:不清楚用途,暂时屏蔽掉 |
| | | // 查询产业链检测数据 |
| | | // String industryChainAttrFields = IndustryChainUtils.getIndustryChainAttrFields(ifsInventoryQuantity.getOrderNo(), |
| | | // ifsInventoryQuantity.getLineNo(), |
| | | // ifsInventoryQuantity.getReleaseNo()); |
| | | // ifsInventoryQuantity.setIndustryChain(industryChainAttrFields); |
| | | |
| | | ifsInventoryQuantityMapper.insert(ifsInventoryQuantity); |
| | | } |
| | | } |
| | |
| | | ifsInventoryQuantity.setIsCopper(1); |
| | | ifsInventoryQuantity.setIsQuarter(0); |
| | | ifsInventoryQuantity.setInspectStatus(0); |
| | | //铜材料下单默认值 |
| | | ifsInventoryQuantity.setOrderType(OrderType.RAW.getValue()); |
| | | ifsInventoryQuantity.setMaterialProp("01Cu"); |
| | | |
| | | ifsInventoryQuantity.setQtyArrived(insOrder.getQtyArrived()); |
| | | ifsInventoryQuantity.setBuyUnitMeas(insOrder.getBuyUnitMeas()); |
| | |
| | | |
| | | ifsInventoryQuantityMapper.insert(ifsInventoryQuantity); |
| | | |
| | | |
| | | insOrder.setIfsInventoryId(ifsInventoryQuantity.getId()); |
| | | insOrder.setState(1); |
| | | |
| | | |
| | | upInsOrderOfState(insOrder); |
| | | upInsOrder(insOrder.getId(), null, appointed != null ? appointed.toString() : null, SecurityUtils.getUserId().intValue(), "原材料"); |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Boolean updateInsOrder(InsOrderUpdateDto insOrderUpdateDto) { |
| | | InsOrder currentOrder = insOrderMapper.selectById(insOrderUpdateDto.getInsOrder().getId()); |
| | | if (currentOrder == null || !Objects.equals(currentOrder.getState(), 2)) { |
| | | throw new ErrorException("只有退回的检验单可以修改"); |
| | | } |
| | | boolean hasSelectedProduct = CollectionUtils.isNotEmpty(insOrderUpdateDto.getSampleProduct()) |
| | | && insOrderUpdateDto.getSampleProduct().stream() |
| | | .filter(sample -> CollectionUtils.isNotEmpty(sample.getInsProduct())) |
| | | .flatMap(sample -> sample.getInsProduct().stream()) |
| | | .anyMatch(product -> Objects.equals(product.getState(), 1)); |
| | | if (!hasSelectedProduct) { |
| | | throw new ErrorException("请至少选择一个检验项"); |
| | | } |
| | | |
| | | // 修改订单 |
| | | insOrderUpdateDto.getInsOrder().setState(0); |
| | | insOrderUpdateDto.getInsOrder().setTell(""); |
| | |
| | | |
| | | // 修改检验项 |
| | | for (SampleProductDto sampleProductDto : insOrderUpdateDto.getSampleProduct()) { |
| | | Long sampleCount = insSampleMapper.selectCount(Wrappers.<InsSample>lambdaQuery() |
| | | .eq(InsSample::getId, sampleProductDto.getId()) |
| | | .eq(InsSample::getInsOrderId, insOrderUpdateDto.getInsOrder().getId())); |
| | | if (sampleCount == 0) { |
| | | throw new ErrorException("检验样品数据异常"); |
| | | } |
| | | |
| | | insSampleService.update(Wrappers.<InsSample>lambdaUpdate() |
| | | .eq(InsSample::getId, sampleProductDto.getId()) |
| | | .set(InsSample::getSpecialStandardMethod, sampleProductDto.getSpecialStandardMethod())); |
| | | |
| | | insProductService.updateBatchById(sampleProductDto.getInsProduct()); |
| | | List<InsProduct> products = sampleProductDto.getInsProduct(); |
| | | if (CollectionUtils.isEmpty(products)) { |
| | | continue; |
| | | } |
| | | |
| | | Set<Integer> productIds = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery() |
| | | .eq(InsProduct::getInsSampleId, sampleProductDto.getId())) |
| | | .stream() |
| | | .map(InsProduct::getId) |
| | | .collect(Collectors.toSet()); |
| | | if (products.stream().anyMatch(product -> product.getId() != null && !productIds.contains(product.getId()))) { |
| | | throw new ErrorException("检验项数据异常"); |
| | | } |
| | | |
| | | List<Integer> removedIds = products.stream() |
| | | .filter(product -> product.getId() != null && !Objects.equals(product.getState(), 1)) |
| | | .map(InsProduct::getId) |
| | | .collect(Collectors.toList()); |
| | | if (CollectionUtils.isNotEmpty(removedIds)) { |
| | | insProductService.removeByIds(removedIds); |
| | | } |
| | | |
| | | List<InsProduct> existingProducts = products.stream() |
| | | .filter(product -> product.getId() != null && Objects.equals(product.getState(), 1)) |
| | | .collect(Collectors.toList()); |
| | | if (CollectionUtils.isNotEmpty(existingProducts)) { |
| | | insProductService.updateBatchById(existingProducts); |
| | | } |
| | | |
| | | List<InsProduct> newProducts = products.stream() |
| | | .filter(product -> product.getId() == null && Objects.equals(product.getState(), 1)) |
| | | .collect(Collectors.toList()); |
| | | addInsProductMethod(sampleProductDto.getId(), newProducts); |
| | | } |
| | | |
| | | return true; |
| | |
| | | @Override |
| | | public List<InsOrderPrintingVo> labelOrderPrinting(List<Integer> ids) { |
| | | return insOrderMapper.labelOrderPrinting(ids); |
| | | } |
| | | |
| | | @Override |
| | | public List<InventoryDetailDTO> labelOutsideOrderPrinting(List<Integer> ids) { |
| | | return insOrderMapper.labelOutsideOrderPrinting(ids); |
| | | } |
| | | |
| | | /** |
| | |
| | | * TODO 后续需要调用IFS的接口 移入的库位号 toLocation |
| | | */ |
| | | // 检验后移库 |
| | | toLocation = "1301"; |
| | | //1301:原材料合格库,CP-02-001:成品库 |
| | | if(StringUtils.equals(inventoryQuantity.getOrderType(), OrderType.RAW.getValue())){ |
| | | toLocation = "1301"; |
| | | }else if(StringUtils.equals(inventoryQuantity.getOrderType(), OrderType.WG.getValue())){ |
| | | toLocation = "CP-02-001"; |
| | | }else{ |
| | | toLocation = "1301"; |
| | | } |
| | | Map<String, Object> moveResultMap = new HashMap<>(); |
| | | List<Map<String, Object>> moveResultList = new ArrayList<>(); |
| | | Map<String, Object> moveMap = new HashMap<>(); |