ShippingCombinationService.java 4.39 KB
package com.huaheng.pc.shipment.shippingCombination.service;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.huaheng.common.utils.Wrappers;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.pc.config.FilterConfigDetail.domain.FilterConfigDetail;
import com.huaheng.pc.config.FilterConfigDetail.service.FilterConfigDetailService;
import com.huaheng.pc.config.configValue.domain.ConfigValue;
import com.huaheng.pc.config.configValue.service.ConfigValueService;
import com.huaheng.pc.config.material.domain.Material;
import com.huaheng.pc.config.material.service.MaterialServiceImpl;
import com.huaheng.pc.config.materialType.domain.MaterialType;
import com.huaheng.pc.config.materialType.service.MaterialTypeService;
import com.huaheng.pc.config.shipmentPreference.domain.ShipmentPreference;
import com.huaheng.pc.config.shipmentPreference.service.ShipmentPreferenceService;
import com.huaheng.pc.inventory.inventoryDetail.domain.InventoryDetail;
import com.huaheng.pc.inventory.inventoryDetail.service.InventoryDetailService;
import com.huaheng.pc.shipment.shipmentDetail.domain.ShipmentDetail;
import com.huaheng.pc.shipment.shippingCombination.domain.ShippingCombinationDetailModel;
import com.huaheng.pc.shipment.shippingCombination.mapper.ShippingCombinationMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;


@Service
public class ShippingCombinationService {

    @Resource
    private ShippingCombinationMapper shippingCombinationMapper;
    @Resource
    InventoryDetailService inventoryDetailService;
    @Resource
    ConfigValueService configValueService;
    @Resource
    FilterConfigDetailService filterConfigDetailService;
    @Resource
    ShipmentPreferenceService shipmentPreferenceService;
    @Resource
    MaterialServiceImpl materialService;
    @Resource
    MaterialTypeService materialTypeService;



    //根据分配规则查找库存
    public List<InventoryDetail> getInventorys(ShipmentDetail shipmentDetail) {
        String warehouseCode = shipmentDetail.getWarehouseCode();
        String companyCode = shipmentDetail.getCompanyCode();
        String materialCode = shipmentDetail.getMaterialCode();
        String inventorySts = shipmentDetail.getInventorySts();
        int shipmentId = shipmentDetail.getShipmentId();
        if(StringUtils.isEmpty(warehouseCode)) {
            throw new ServiceException("出库详情没有仓库编码");
        }
        if(StringUtils.isEmpty(companyCode)) {
            throw new ServiceException("出库详情没有货主编码");
        }
        if(StringUtils.isEmpty(materialCode)) {
            throw new ServiceException("出库详情没有物料编码");
        }
        if(StringUtils.isEmpty(inventorySts)) {
            throw new ServiceException("出库详情没有物料品质");
        }
        LambdaQueryWrapper<InventoryDetail> inventoryDetailLambdaQueryWrapper =Wrappers.lambdaQuery();
        inventoryDetailLambdaQueryWrapper.eq(InventoryDetail::getWarehouseCode, warehouseCode)
                                        .eq(InventoryDetail::getCompanyCode, companyCode)
                                        .eq(InventoryDetail::getMaterialCode, materialCode)
//                                        .eq(InventoryDetail::getBatch, shipmentDetail.getBatch())
                                        .eq(InventoryDetail::getInventorySts, inventorySts);
//                .eq(StringUtils.isNotEmpty(shipmentDetail.getMoCode()),InventoryDetail::getMoCode, shipmentDetail.getMoCode());
        if(StringUtils.isEmpty(shipmentDetail.getMoCode())){
            inventoryDetailLambdaQueryWrapper.apply(" (moCode is null or moCode='')");
        }
        if(StringUtils.isNotEmpty(shipmentDetail.getMoCode())){
            inventoryDetailLambdaQueryWrapper.apply(" (moCode is null or moCode='' or moCode='"+shipmentDetail.getMoCode()+"')");
        }

        List<InventoryDetail> inventoryDetailList = inventoryDetailService.list(inventoryDetailLambdaQueryWrapper);

        return inventoryDetailList;
    }

    public List<ShippingCombinationDetailModel> selectOfView(ShippingCombinationDetailModel shippingCombinationDetailModel) {
        return shippingCombinationMapper.selectOfView(shippingCombinationDetailModel);
    }
}