inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderServiceImpl.java
@@ -25,6 +25,7 @@
import com.ruoyi.basic.pojo.StandardProductList;
import com.ruoyi.basic.pojo.StructureItemParameter;
import com.ruoyi.basic.pojo.StructureTestObject;
import com.ruoyi.common.config.ifs.IfsProperties;
import com.ruoyi.common.constant.InsOrderTypeConstants;
import com.ruoyi.common.core.domain.Result;
import com.ruoyi.common.core.domain.entity.User;
@@ -34,12 +35,14 @@
import com.ruoyi.common.utils.api.IfsApiUtils;
import com.ruoyi.framework.exception.ErrorException;
import com.ruoyi.inspect.dto.*;
import com.ruoyi.inspect.event.InsOrderDeletingEvent;
import com.ruoyi.inspect.mapper.*;
import com.ruoyi.inspect.pojo.*;
import com.ruoyi.inspect.service.InsOrderService;
import com.ruoyi.inspect.service.InsOrderStateService;
import com.ruoyi.inspect.service.InsProductService;
import com.ruoyi.inspect.service.InsSampleService;
import com.ruoyi.inspect.service.OutsourceOrderFlowService;
import com.ruoyi.inspect.vo.IfsOrderVO;
import com.ruoyi.inspect.vo.InsOrderPrintingVo;
import com.ruoyi.system.mapper.UserMapper;
@@ -47,6 +50,7 @@
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;
@@ -87,8 +91,10 @@
    private InsUnqualifiedRetestProductMapper insUnqualifiedRetestProductMapper;
    private IfsApiUtils ifsApiUtils;
    private SpotCheckQuarterItemMapper spotCheckQuarterItemMapper;
    private ApplicationEventPublisher applicationEventPublisher;
    private StandardProductListMapper standardProductListMapper;
    private StructureItemParameterMapper structureItemParameterMapper;
    private OutsourceOrderFlowService outsourceOrderFlowService;
    //获取检验下单数据
@@ -215,6 +221,7 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int addInsOrder(List<SampleProductDto> list, InsOrder insOrder) {
        initOutsourceOrderSource(insOrder);
        // todo: 下单判断抽样计划的唯一性
        if (insOrder.getQuarterItemId() != null) {
            Long quarterItemCount = insOrderMapper.selectCount(Wrappers.<InsOrder>lambdaQuery()
@@ -405,6 +412,21 @@
        return insOrder.getId();
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteReturnedOrder(Integer insOrderId) {
        InsOrder order = insOrderMapper.selectById(insOrderId);
        if (order == null) {
            throw new ErrorException("成品订单不存在");
        }
        if (!(Integer.valueOf(2).equals(order.getState()) || Integer.valueOf(3).equals(order.getState()))) {
            throw new ErrorException("只有退回或撤销订单才能删除");
        }
        Integer operatorId = SecurityUtils.getUserId().intValue();
        applicationEventPublisher.publishEvent(new InsOrderDeletingEvent(insOrderId, operatorId, LocalDateTime.now()));
        return removeById(insOrderId);
    }
    /**
     * 添加检验项
     *
@@ -438,16 +460,16 @@
    @Override
    public Map<String, Object> getInsOrder(Integer id) {
        Map<String, Object> map = new HashMap<>();
        InsOrder insOrder = insOrderMapper.selectById(id);
        IfsOrderVO ifsOrderVO = insOrderMapper.selectOrderInfoById(id);
        List<SampleProductDto> list;
        // 判断是否是进厂报告免检
        if (insOrder.getIsExemption().equals(1)) {
        if (ifsOrderVO.getIsExemption().equals(1)) {
            list = insSampleMapper.selectExemptionByOrderId(id);
        } else {
            list = insSampleMapper.selectSampleProductListByOrderId2(id);
        }
        Map<String, Object> map1 = insSampleMapper.selectInsOrder(id);
        map.put("insOrder", insOrder);
        map.put("insOrder", ifsOrderVO);
        map.put("sampleProduct", list);
        map.put("insOrderTemplate", map1);
        return map;
@@ -526,6 +548,16 @@
        Map<String, Object> map = new HashMap<>();
//        InsOrder insOrder = insOrderMapper.selectById(id);
        IfsOrderVO ifsOrderVO = insOrderMapper.selectOrderInfoById(id);
        // 详情同时返回有效处理流程,供检测页面统一选择布局及校验规则。
        if (ifsOrderVO != null) {
            ifsOrderVO.setFlowOrderType(ifsOrderVO.getIfsOrderType());
            if (ifsOrderVO.getIfsInventoryId() != null) {
                IfsInventoryQuantity quantity = ifsInventoryQuantityMapper.selectById(ifsOrderVO.getIfsInventoryId());
                if (quantity != null) {
                    ifsOrderVO.setFlowOrderType(outsourceOrderFlowService.resolve(quantity.getOrderType(), quantity.getMaterialProp()));
                }
            }
        }
        List<SampleProductDto> list = insSampleMapper.getInsOrderAndSample(id, laboratory);
        map.put("insOrder", ifsOrderVO);
        map.put("sampleProduct", list);
@@ -533,6 +565,19 @@
        List<Map<Integer, Object>> list2 = insOrderMapper.selectReportModelByOrderId(id, laboratory);
        map.put("reportModel", list2);
        return map;
    }
    /** 保存前读取真实销售订单,纠正外协下单来源,避免前端缓存影响实验室分配。 */
    private void initOutsourceOrderSource(InsOrder insOrder) {
        if (insOrder.getIfsInventoryId() == null) {
            return;
        }
        IfsInventoryQuantity quantity = ifsInventoryQuantityMapper.selectById(insOrder.getIfsInventoryId());
        if (quantity == null) {
            throw new ErrorException("找不到销售订单信息");
        }
        insOrder.setTypeSource(outsourceOrderFlowService.resolveTypeSource(
                quantity.getOrderType(), quantity.getMaterialProp(), insOrder.getTypeSource()));
    }
    @Override
@@ -561,7 +606,7 @@
     */
    @Override
    public void getIfsOrder(Map<String, Object> map, Boolean isSplitOrder) {
        List<Map<String, Object>> inventory = ifsApiUtils.getInventory(JSONUtil.toJsonStr(map));
        List<Map<String, Object>> inventory = ifsApiUtils.getInventory(map);
        if (inventory.isEmpty()) {
            return;
        }
@@ -625,8 +670,8 @@
            if (map1.get("APPROVED_DATE") != null) {
                ifsInventoryQuantity.setApprovedDate(LocalDateTime.parse(map1.get("APPROVED_DATE").toString(), dateTimeFormatter)); // 审批日期
            }
            ifsInventoryQuantity.setReqCeater(map1.get("REQ_CEATER") == null ? "" : map1.get("REQ_CEATER").toString()); // 采购申请创建人
            ifsInventoryQuantity.setReqCeaterName(map1.get("REQ_CEATER_NAME") == null ? "" : map1.get("REQ_CEATER_NAME").toString()); // 采购申请创建人名称
            ifsInventoryQuantity.setReqCeater(map1.get("REQ_CREATER") == null ? "" : map1.get("REQ_CREATER").toString()); // 采购申请创建人
            ifsInventoryQuantity.setReqCeaterName(map1.get("REQ_CREATER_NAME") == null ? "" : map1.get("REQ_CREATER_NAME").toString()); // 采购申请创建人名称
            ifsInventoryQuantity.setLineRemarks(map1.get("LINE_REMARKS") == null ? "" : map1.get("LINE_REMARKS").toString()); // 采购订单行备注
            ifsInventoryQuantity.setBuyUnitMeas(map1.get("BUY_UNIT_MEAS") == null ? "" : map1.get("BUY_UNIT_MEAS").toString()); // 采购单位
            ifsInventoryQuantity.setReceiverDate(LocalDateTime.now()); // 接收日期
@@ -807,6 +852,8 @@
        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());
@@ -1204,7 +1251,7 @@
            resultMap.put("SYSCODE", "LIMS");
            resultMap.put("SYSMODEL", "登记采购检验结果");
            resultMap.put("BATCH_INFO", resultList);
            Result result = ifsApiUtils.getProcurementResults(JSONUtil.toJsonStr(resultMap));
            Result result = ifsApiUtils.getProcurementResults(one.getContract(),JSONUtil.toJsonStr(resultMap));
            if (result.getCode() != 200) {
                throw new ErrorException("IFS登记采购检验结果失败: " + result.getMessage());
            }
@@ -1235,8 +1282,14 @@
         * TODO 后续需要调用IFS的接口 移入的库位号 toLocation
         */
        // 检验后移库
        //1301:原材料合格库,CP-02-001:成品库
        toLocation = StringUtils.equals(inventoryQuantity.getOrderType(), OrderType.RAW.getValue()) ? "1301" : "CP-02-001";
        //1.根据ifs域获取对应库位配置
        IfsProperties properties = ifsApiUtils.getPropByContract(one.getContract());
        //2.判断订单类型是否为原材料
        if(StringUtils.equals(outsourceOrderFlowService.resolve(one.getOrderType(), one.getMaterialProp()), OrderType.RAW.getValue())){
            toLocation = properties.getRawQualifiedLocation();
        }else{
            toLocation = properties.getProductQualifiedLocation();
        }
        Map<String, Object> moveResultMap = new HashMap<>();
        List<Map<String, Object>> moveResultList = new ArrayList<>();
        Map<String, Object> moveMap = new HashMap<>();
@@ -1259,7 +1312,7 @@
        moveResultMap.put("SYSMODEL", "检验后移库");
        moveResultMap.put("BATCH_INFO", moveResultList);
        Result result1 = ifsApiUtils.moveReceipt(JSONUtil.toJsonStr(moveResultMap));
        Result result1 = ifsApiUtils.moveReceipt(one.getContract(),JSONUtil.toJsonStr(moveResultMap));
        // 如果有必须为零件指定批号报错需要重新提交移库信息去指定批号
        if (result1.getCode() != 200) {
            String message = result1.getMessage();
@@ -1274,6 +1327,11 @@
                .set(IfsInventoryQuantity::getState, 2)
                .eq(IfsInventoryQuantity::getId, inventoryQuantity.getId()));
        return toLocation;
    }
    @Override
    public Map<String, Object> getInsOrderList(List<Integer> selectOrderIds) {
        return insOrderMapper.selectOrderInfoByIds(selectOrderIds);
    }
@@ -1309,7 +1367,7 @@
            resultMap.put("SYSMODEL", "修改采购订单批次号");
            resultMap.put("BATCH_INFO", resultList);
            Result result = ifsApiUtils.updateMoveReceiptLot(JSONUtil.toJsonStr(resultMap));
            Result result = ifsApiUtils.updateMoveReceiptLot(one.getContract(),JSONUtil.toJsonStr(resultMap));
            if (result.getCode() != 200) {
                throw new ErrorException("IFS修改批次号失败: " + result.getMessage());
@@ -1341,7 +1399,7 @@
        moveResultMap.put("SYSMODEL", "检验后移库");
        moveResultMap.put("BATCH_INFO", moveResultList);
        Result result1 = ifsApiUtils.moveReceipt(JSONUtil.toJsonStr(moveResultMap));
        Result result1 = ifsApiUtils.moveReceipt(one.getContract(),JSONUtil.toJsonStr(moveResultMap));
        if (result1.getCode() != 200) {
            throw new ErrorException("IFS检验后移库失败: " + result1.getMessage());
        }