zouyu
7 天以前 3793ba4a9b6be8faa6df0d4a76c06763ac03f873
inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderServiceImpl.java
@@ -26,6 +26,7 @@
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.api.IfsApiUtils;
@@ -37,12 +38,14 @@
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;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletResponse;
@@ -309,9 +312,10 @@
                }
            }
        });
        //是否为原材料下单
        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);
@@ -349,47 +353,51 @@
            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));
                    }
                }
            }
        }
@@ -513,9 +521,10 @@
    @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);
@@ -547,12 +556,9 @@
     * @return
     */
    @Override
    public void getIfsOrder() {
        HashMap<String, Object> map = new HashMap<>();
        map.put("LOCATION_NO","1302");
        map.put("STATE_DB","To be Inspected");
    public void getIfsOrder(Map<String, Object> map,Boolean isSplitOrder) {
        List<Map<String, Object>> inventory = ifsApiUtils.getInventory(JSONUtil.toJsonStr(map));
        if(inventory.size() == 0) {
        if(inventory.isEmpty()) {
            return;
        }
        // 进行保存
@@ -637,6 +643,9 @@
            );
            if(count == 0) {
                ifsInventoryQuantity.setIsFirst(0);
                if(isSplitOrder){
                    ifsInventoryQuantity.setIsSplitOrder(1);
                }
                // 查询产业链检测数据
                String industryChainAttrFields = IndustryChainUtils.getIndustryChainAttrFields(ifsInventoryQuantity.getOrderNo(),
                        ifsInventoryQuantity.getLineNo(),
@@ -719,7 +728,7 @@
     * @param id
     */
    @Transactional
    public void updateIfsInventoryQuantity(Integer id) {
    public void updateIfsInventoryQuantity(Long id) {
        ifsInventoryQuantityMapper.update(null, Wrappers.<IfsInventoryQuantity>lambdaUpdate()
                .set(IfsInventoryQuantity::getIsRegister, 1)
                .eq(IfsInventoryQuantity::getId, id));
@@ -1146,6 +1155,173 @@
    }
    /**
     * ifs移库操作
     * @param inventoryQuantity
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class,isolation = Isolation.READ_COMMITTED)
    public String moveRawMaterial(IfsInventoryQuantity inventoryQuantity) {
        //查询ifs订单详情
        IfsInventoryQuantity one = ifsInventoryQuantityMapper.selectById(inventoryQuantity.getId());
        String toLocation;
        // 登记采购检验结果STD
        if (one.getIsRegister().equals(0)) {
            Map<String, Object> resultMap = new HashMap<>();
            List<Map<String, Object>> resultList = new ArrayList<>();
            Map<String, Object> map = new HashMap<>();
            map.put("ORDER_NO", one.getOrderNo()); // 采购订单号
            map.put("LINE_NO", one.getLineNo()); // 行号
            map.put("RELEASE_NO", one.getReleaseNo()); // 下达号
            map.put("RECEIPT_NO", one.getReceiptNo()); // 接收号
            map.put("PURCH_QTY", one.getQtyToInspect()); // 要检验的采购数量
            resultList.add(map);
            resultMap.put("RECORD_ID", UUID.randomUUID().toString());
            resultMap.put("SYSCODE", "LIMS");
            resultMap.put("SYSMODEL", "登记采购检验结果");
            resultMap.put("BATCH_INFO", resultList);
            Result result = ifsApiUtils.getProcurementResults(JSONUtil.toJsonStr(resultMap));
            if (result.getCode() != 200) {
                throw new ErrorException("IFS登记采购检验结果失败: " + result.getMessage());
            }
            //如果是拆分订单,则将同一接收号的订单标记已登记校验
            if(one.getIsSplitOrder()==1){
                //查询其余拆分的订单
                List<IfsInventoryQuantity> quantityList = ifsInventoryQuantityMapper.selectList(Wrappers.<IfsInventoryQuantity>lambdaQuery()
                        .eq(IfsInventoryQuantity::getOrderNo, one.getOrderNo())
                        .eq(IfsInventoryQuantity::getPartNo, one.getPartNo())
                        .eq(IfsInventoryQuantity::getLineNo, one.getLineNo())
                        .eq(IfsInventoryQuantity::getReleaseNo, one.getReleaseNo())
                        .eq(IfsInventoryQuantity::getReceiptNo, one.getReceiptNo())
                        .eq(IfsInventoryQuantity::getIsSplitOrder, 1)
                );
                if(Objects.nonNull(quantityList) && !quantityList.isEmpty()){
                    //修改采购订单登记状态
                    List<Long> ids = quantityList.stream().map(IfsInventoryQuantity::getId).collect(Collectors.toList());
                    ifsInventoryQuantityMapper.update(null,Wrappers.<IfsInventoryQuantity>lambdaUpdate()
                            .set(IfsInventoryQuantity::getIsRegister,1)
                            .in(IfsInventoryQuantity::getId, ids)
                    );
                }
            }else{
                this.updateIfsInventoryQuantity(one.getId());
            }
        }
        /**
         * TODO 后续需要调用IFS的接口 移入的库位号 toLocation
         */
        // 检验后移库
        //1301:原材料合格库,CP-02-001:成品库
        toLocation = StringUtils.equals(inventoryQuantity.getOrderType(), OrderType.RAW.getValue())?"1301":"CP-02-001";
        Map<String, Object> moveResultMap = new HashMap<>();
        List<Map<String, Object>> moveResultList = new ArrayList<>();
        Map<String, Object> moveMap = new HashMap<>();
        moveMap.put("ORDER_NO", one.getOrderNo()); // 采购订单号
        moveMap.put("LINE_NO", one.getLineNo());
        moveMap.put("RELEASE_NO", one.getReleaseNo());
        moveMap.put("RECEIPT_NO", one.getReceiptNo());
        moveMap.put("PART_NO", one.getPartNo());
        moveMap.put("QTY", one.getPurQtyInStore());
        moveMap.put("LOCATION_NO", one.getLocationNo());
        moveMap.put("TO_LOCATION_NO", toLocation);
        moveMap.put("LOT_BATCH_NO", one.getLotBatchNo());
        moveMap.put("SERIAL_NO", one.getSerialNo());
        moveMap.put("WAIV_DEV_REJ_NO", one.getWaivDevRejNo());
        moveMap.put("ENG_CHG_LEVEL", one.getEngChgLevel());
        moveMap.put("ACTIVITY_SEQ", one.getActivitySeq());
        moveResultList.add(moveMap);
        moveResultMap.put("RECORD_ID", UUID.randomUUID().toString());
        moveResultMap.put("SYSCODE", "LIMS");
        moveResultMap.put("SYSMODEL", "检验后移库");
        moveResultMap.put("BATCH_INFO", moveResultList);
        Result result1 = ifsApiUtils.moveReceipt(JSONUtil.toJsonStr(moveResultMap));
        // 如果有必须为零件指定批号报错需要重新提交移库信息去指定批号
        if (result1.getCode() != 200) {
            String message = result1.getMessage();
            if (message.contains("必须为零件") && message.contains("指定批号")) {
                updaeBatch(one, toLocation);
            } else {
                throw new ErrorException("IFS检验后移库失败: " + result1.getMessage());
            }
        }
        return toLocation;
    }
    /**
     * 先修改采购订单批次号, 后进行移库操作
     * @param one
     * @param toLocation
     */
    private void updaeBatch(IfsInventoryQuantity one, String toLocation) {
        if (one.getIsUpdateBatch().equals(0)) {
            // 先修改批次号后进行移库
            Map<String, Object> resultMap = new HashMap<>();
            List<Map<String, Object>> resultList = new ArrayList<>();
            Map<String, Object> map = new HashMap<>();
            map.put("ORDER_NO", one.getOrderNo()); // 采购订单号
            map.put("LINE_NO", one.getLineNo()); // 行号
            map.put("RELEASE_NO", one.getReleaseNo()); // 下达号
            map.put("RECEIPT_NO", one.getReceiptNo()); // 接收号
            map.put("PART_NO", one.getPartNo()); //零件号
            map.put("CONFIGURATION_ID", one.getConfigurationId()); // 配置标识
            map.put("LOCATION_NO", one.getLocationNo()); // 库位号
            map.put("LOT_BATCH_NO", one.getLotBatchNo());// 批次号
            map.put("NEW_LOT_BATCH_NO", one.getUpdateBatchNo()); // 目标批次号
            map.put("SERIAL_NO", one.getSerialNo()); // 序列号
            map.put("ENG_CHG_LEVEL", one.getEngChgLevel()); // 版本号
            map.put("WAIV_DEV_REJ_NO", one.getWaivDevRejNo()); // wdr号
            map.put("ACTIVITY_SEQ", one.getActivitySeq()); // 活动序号
            map.put("QTY_TO_CHANGE", one.getQtyArrived()); // 变更数量
            resultList.add(map);
            resultMap.put("RECORD_ID", UUID.randomUUID().toString());
            resultMap.put("SYSCODE", "LIMS");
            resultMap.put("SYSMODEL", "修改采购订单批次号");
            resultMap.put("BATCH_INFO", resultList);
            Result result = ifsApiUtils.updateMoveReceiptLot(JSONUtil.toJsonStr(resultMap));
            if (result.getCode() != 200) {
                throw new ErrorException("IFS修改批次号失败: " + result.getMessage());
            }
            ifsInventoryQuantityMapper.update(null, Wrappers.<IfsInventoryQuantity>lambdaUpdate()
                    .set(IfsInventoryQuantity::getIsUpdateBatch, 1)
                    .eq(IfsInventoryQuantity::getId, one.getId()));
        }
        Map<String, Object> moveResultMap = new HashMap<>();
        List<Map<String, Object>> moveResultList = new ArrayList<>();
        Map<String, Object> moveMap = new HashMap<>();
        moveMap.put("ORDER_NO", one.getOrderNo()); // 采购订单号
        moveMap.put("LINE_NO", one.getLineNo());
        moveMap.put("RELEASE_NO", one.getReleaseNo());
        moveMap.put("RECEIPT_NO", one.getReceiptNo());
        moveMap.put("PART_NO", one.getPartNo());
        moveMap.put("QTY", one.getQtyArrived());
        moveMap.put("LOCATION_NO", one.getLocationNo());
        moveMap.put("TO_LOCATION_NO", toLocation);
        moveMap.put("LOT_BATCH_NO", one.getUpdateBatchNo());
        moveMap.put("SERIAL_NO", one.getSerialNo());
        moveMap.put("WAIV_DEV_REJ_NO", one.getWaivDevRejNo());
        moveMap.put("ENG_CHG_LEVEL", one.getEngChgLevel());
        moveMap.put("ACTIVITY_SEQ", one.getActivitySeq());
        moveResultList.add(moveMap);
        moveResultMap.put("RECORD_ID", UUID.randomUUID().toString());
        moveResultMap.put("SYSCODE", "LIMS");
        moveResultMap.put("SYSMODEL", "检验后移库");
        moveResultMap.put("BATCH_INFO", moveResultList);
        Result result1 = ifsApiUtils.moveReceipt(JSONUtil.toJsonStr(moveResultMap));
        if (result1.getCode() != 200) {
            throw new ErrorException("IFS检验后移库失败: " + result1.getMessage());
        }
    }
}