ShippingCombinationService.java 7.16 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.common.utils.security.ShiroUtils;
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.shipmentHeader.domain.ShipmentHeader;
import com.huaheng.pc.shipment.shipmentHeader.service.ShipmentHeaderService;
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;
    @Resource
    private ShipmentHeaderService shipmentHeaderService;



    //根据分配规则查找库存
    public List<InventoryDetail> getInventorys(ShipmentDetail shipmentDetail) {
        String warehouseCode = shipmentDetail.getWarehouseCode();
        String companyCode = shipmentDetail.getCompanyCode();
        String materialCode = shipmentDetail.getMaterialCode();
        String inventorySts = shipmentDetail.getInventorySts();
        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())&&!ShiroUtils.getWarehouseCode().equals("KS0001")){
            inventoryDetailLambdaQueryWrapper.apply(" (moCode is null or moCode='')");
        }
        if(StringUtils.isNotEmpty(shipmentDetail.getMoCode())&&!ShiroUtils.getWarehouseCode().equals("KS0001")){
            inventoryDetailLambdaQueryWrapper.apply(" (moCode is null or moCode='' or moCode='"+shipmentDetail.getMoCode()+"')");
        }

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

        return inventoryDetailList;
    }

    public List<InventoryDetail> getInventoryAutoKS(ShipmentDetail shipmentDetail) {
        ShipmentHeader shipmentHeader = shipmentHeaderService.getOne(new LambdaQueryWrapper<ShipmentHeader>()
                .eq(ShipmentHeader::getCode, shipmentDetail.getShipmentCode())
                .eq(ShipmentHeader::getWarehouseCode,shipmentDetail.getWarehouseCode())
        );
        if(StringUtils.isEmpty(shipmentHeader.getWarehouseCode())) {
            throw new ServiceException("出库详情没有仓库编码");
        }
        if(StringUtils.isEmpty(shipmentHeader.getCompanyCode())) {
            throw new ServiceException("出库详情没有货主编码");
        }
        if(StringUtils.isEmpty(shipmentDetail.getMaterialCode())) {
            throw new ServiceException("出库详情没有物料编码");
        }
        if(StringUtils.isEmpty(shipmentDetail.getInventorySts())) {
            throw new ServiceException("出库详情没有物料品质");
        }
        LambdaQueryWrapper<InventoryDetail> inventoryDetailLambdaQueryWrapper =Wrappers.lambdaQuery();
        //匹配 warehouseCode、companyCode、uWarehouseCode、MoCode、materialCode、inventorySts
        inventoryDetailLambdaQueryWrapper.eq(InventoryDetail::getWarehouseCode, shipmentHeader.getWarehouseCode())
                .eq(InventoryDetail::getCompanyCode, shipmentHeader.getCompanyCode())
                .eq(StringUtils.isNotEmpty(shipmentHeader.getUWarehouseCode()),InventoryDetail::getUWarehouseCode,shipmentHeader.getUWarehouseCode())
//                .eq(StringUtils.isNotEmpty(shipmentDetail.getMoCode()),InventoryDetail::getMoCode,shipmentDetail.getMoCode())
                .eq(InventoryDetail::getMaterialCode, shipmentDetail.getMaterialCode())
                .eq(InventoryDetail::getInventorySts, shipmentDetail.getInventorySts());
        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()+"')");
        }
        inventoryDetailLambdaQueryWrapper.apply(" (uWarehouseCode not in('ksaiersenweId','kshhhanjieweId'))");
        List<InventoryDetail> inventoryDetailList = inventoryDetailService.list(inventoryDetailLambdaQueryWrapper);
        return inventoryDetailList;
    }

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