WarehouseServiceImpl.java 12.1 KB
package com.huaheng.pc.config.warehouse.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.pc.config.FilterConfigHeader.service.FilterConfigHeaderService;
import com.huaheng.pc.config.address.service.AddressService;
import com.huaheng.pc.config.configValue.service.ConfigValueService;
import com.huaheng.pc.config.containerType.service.ContainerTypeService;
import com.huaheng.pc.config.cycleCountPreference.service.CycleCountPreferenceService;
import com.huaheng.pc.config.locationType.service.LocationTypeService;
import com.huaheng.pc.config.receiptPreference.service.ReceiptPreferenceService;
import com.huaheng.pc.config.receiptType.service.ReceiptTypeService;
import com.huaheng.pc.config.shipmentPreference.service.ShipmentPreferenceService;
import com.huaheng.pc.config.shipmentType.service.ShipmentTypeService;
import com.huaheng.pc.config.statusFlow.service.StatusFlowHeaderService;
import com.huaheng.pc.config.warehouse.domain.Warehouse;
import com.huaheng.pc.config.warehouse.mapper.WarehouseMapper;
import com.huaheng.pc.config.warehouse.mapper.WarehouseU8Mapper;
import com.huaheng.pc.config.warehouseCompany.domain.WarehouseCompany;
import com.huaheng.pc.config.warehouseCompany.service.WarehouseCompanyService;
import com.huaheng.pc.config.waveMaster.service.WaveMasterService;
import com.huaheng.pc.config.zone.service.ZoneService;
import com.huaheng.pc.system.dict.service.IDictTypeService;
import com.huaheng.pc.system.menu.service.IMenuService;
import com.huaheng.pc.system.role.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

@Service("WarehouseService")
public class WarehouseServiceImpl extends ServiceImpl<WarehouseMapper, Warehouse> implements WarehouseService {

    @Resource
    private AddressService addressService;
    @Resource
    private ConfigValueService configValueService;
    @Resource
    private ContainerTypeService containerTypeService;
    @Resource
    private CycleCountPreferenceService cycleCountPreferenceService;
    @Resource
    private LocationTypeService locationTypeService;
    @Resource
    private ReceiptPreferenceService receiptPreferenceService;
    @Resource
    private ReceiptTypeService receiptTypeService;
    @Resource
    private ShipmentPreferenceService shipmentPreferenceService;
    @Resource
    private ShipmentTypeService shipmentTypeService;
    @Resource
    private WarehouseU8Mapper warehouseWuMapper;
    @Resource
    private WarehouseCompanyService warehouseCompanyService;
    @Autowired
    private IRoleService roleService;
    @Autowired
    private IDictTypeService dictTypeService;
    @Autowired
    private IMenuService menuService;
    @Autowired
    private FilterConfigHeaderService filterConfigHeaderService;
    @Autowired
    private StatusFlowHeaderService statusFlowHeaderService;
    @Autowired
    private WaveMasterService waveMasterService;
    @Autowired
    private ZoneService zoneService;

    @Resource
    private WarehouseMapper warehouseMapper;

    @Override
    public List<Map<String, Object>> getWarehouseList(Integer id) {
        /**
         *  查询仓库的code、name、enable
         */
        LambdaQueryWrapper<Warehouse> lambdaQueryWrapper = Wrappers.lambdaQueryNoWarehouse();
        lambdaQueryWrapper.select(Warehouse::getCode, Warehouse::getName, Warehouse::getEnable);
        List<Map<String, Object>> warehouseList = warehouseMapper.selectMaps(lambdaQueryWrapper);

        LambdaQueryWrapper<WarehouseCompany> lambdaQueryWrapper1 = Wrappers.lambdaQuery();
        lambdaQueryWrapper1.select(WarehouseCompany::getCompanyCode,WarehouseCompany::getWarehouseCode)
                .eq(WarehouseCompany::getCompanyId,id);
        List<Map<String, Object>> warehouseCompanies = warehouseCompanyService.listMaps(lambdaQueryWrapper1);

        for(Map<String, Object> item : warehouseList){
            item.put("flag",false);
            item.put("value", item.get("code").toString());
            for (Map<String, Object> warehouseI:warehouseCompanies)           {
                if (item.get("code").toString().equals(warehouseI.get("warehouseCode").toString()))               {
                    item.put("flag",true);
                    break;
                }
            }
        }
        return warehouseList;
    }

    @Override
    public List<Warehouse> selectWarehouseByUserId(Integer userId)
    {
        List<Warehouse> userWarhouses = warehouseMapper.selectWarehouseByUserId(userId);
        List<Warehouse> warehouses = warehouseMapper.selectWarehouseAll();
        if(userWarhouses==null || userWarhouses.size()==0)
        {
//            return userWarhouses;
        }
        for (Warehouse warehouse : warehouses)
        {
            for (Warehouse userWarehouse: userWarhouses)
            {
                if (userWarehouse!=null&&warehouse.getCode().equals(userWarehouse.getCode()))
                {
                    warehouse.setFlag(true);
                    break;
                }
            }
        }
        return warehouses;
    }

    @Override
    public List<Map<String, Object>> getWarehouseCodeList(String code) {
        /**
         *  查询仓库的code、name、enable
         */
        LambdaQueryWrapper<Warehouse> lambdaQueryWrapper = Wrappers.lambdaQueryNoWarehouse();
        lambdaQueryWrapper.select(Warehouse::getCode, Warehouse::getName, Warehouse::getEnable,Warehouse::getDeleted);
        List<Map<String, Object>> warehouseList = warehouseMapper.selectMaps(lambdaQueryWrapper);
        Iterator<Map<String, Object>> it = warehouseList.iterator();
        while (it.hasNext()){
            Map item = it.next();
            if (item.get("deleted") != null && (Boolean)item.get("deleted") == true){
                it.remove();
                continue;
            }
            if (code.equals(item.get("code").toString())){
                item.put("flag",true);
            }else {
                item.put("flag",false);
            }
        }
        return warehouseList;
    }

    /**
     * 复制仓库
     * @param warehouseCode 仓库编码
     * @param newWarehouseCode 新仓库编码
     */
    @Override
    @Transactional
    public Boolean warehouseCopy(String warehouseCode, String newWarehouseCode) {
        /* 复制地址表*/
        /*if (!addressService.addressCopy(warehouseCode, newWarehouseCode)){
            throw new ServiceException("复制地址表失败 该仓库已存在地址表");
        }*/
        /* 复制系统参数配置表*/
        if (!configValueService.configValueCopy(warehouseCode, newWarehouseCode)){
            throw new ServiceException("复制系统参数配置表失败");
        }
        /* 复制容器类型表*/
       /* if (!containerTypeService.containerTypeCopy(warehouseCode, newWarehouseCode)){
            throw new ServiceException("复制容器类型表失败");
        }
        *//* 复制库位类型表*//*
        if (!locationTypeService.locationTypeCopy(warehouseCode, newWarehouseCode)){
            throw new ServiceException("复制库位类型表失败");
        }
        *//* 复制库区表*//*
        if (!zoneService.zoneCopy(warehouseCode, newWarehouseCode)){
            throw new ServiceException("复制库区类型表失败");
        }*/
        /* 复制盘点首选项表*/
        if (!cycleCountPreferenceService.cycleCountPreferenceCopy(warehouseCode, newWarehouseCode)){
            throw new ServiceException("复制盘点首选项表失败");
        }
        /* 复制入库首选项*/
        if (!receiptPreferenceService.receiptPreferenceCopy(warehouseCode, newWarehouseCode)){
            throw new ServiceException("复制入库首选项表失败");
        }
        /* 复制出库首选项*/
        if (!shipmentPreferenceService.shipmentPreferenceCopy(warehouseCode, newWarehouseCode)){
            throw new ServiceException("复制出库首选项表失败");
        }
        /* 复制入库类型*/
        /*if (!receiptTypeService.receiptTypeCopy(warehouseCode, newWarehouseCode)){
            throw new ServiceException("复制入库类型表失败");
        }*/
        /* 复制出库类型*/
        /*if (!shipmentTypeService.ShipmentTypeCopy(warehouseCode, newWarehouseCode)){
            throw new ServiceException("复制出库类型表失败");
        }*/
        /* 复制仓库货主关系*/
        /*if (warehouseMapper.companyCopy(warehouseCode, newWarehouseCode) < 1){
            throw new ServiceException("复制仓库货主关系表失败");
        }*/
        /* 复制仓库用户关系*/
        if (warehouseMapper.userCopy(warehouseCode, newWarehouseCode) < 1){
            throw new ServiceException("复制仓库用户关系表失败");
        }
        /* 复制角色*/
        /*if (!roleService.roleCopy(warehouseCode, newWarehouseCode)){
            throw new ServiceException("复制角色表失败");
        }*/
        /* 复制菜单*/
        /*if (!menuService.menuCopy(warehouseCode, newWarehouseCode)){
            throw new ServiceException("复制菜单表失败");
        }*/
        /* 复制角色菜单*/
        /*if (!roleService.roleMenuCopy(warehouseCode, newWarehouseCode)){
            throw new ServiceException("复制角色菜单失败");
        }*/
        /* 复制字典数据*/
        if (!dictTypeService.dictTypeCopy(warehouseCode, newWarehouseCode)){
            throw new ServiceException("复制字典数据表失败");
        }
        /* 复制流程*/
        if (!statusFlowHeaderService.statusFlowCopy(warehouseCode, newWarehouseCode)){
            throw new ServiceException("复制流程表失败");
        }
        /* 复制规则配置*/
        if (!filterConfigHeaderService.filterConfigCopy(warehouseCode, newWarehouseCode)){
            throw new ServiceException("复制规则配置表失败");
        }
        /* 复制波次配置*/
        /*if (!waveMasterService.waveMasterCopy(warehouseCode, newWarehouseCode)){
            throw new ServiceException("复制波次配置表失败");
        }*/
        return true;
    }

    @Override
    public List<Warehouse> selectListEntityByEqual(Warehouse condition) {
        return warehouseMapper.selectListEntityByEqual(condition);
    }


    public List<Warehouse> getWarehouse(){
        LambdaQueryWrapper<Warehouse> lambdaQueryWrapper = Wrappers.lambdaQueryNoWarehouse();
        lambdaQueryWrapper
                .eq(Warehouse::getDeleted,false)
                .orderByAsc(Warehouse::getCreated);
        List<Warehouse>  warehouseList = list(lambdaQueryWrapper);
        return warehouseList;
    }

    @Override
    public List<Map<String, Object>> getWarehouseMap(){
        LambdaQueryWrapper<Warehouse> warehouse = Wrappers.lambdaQueryNoWarehouse();
        warehouse.select(Warehouse::getCode,Warehouse::getName,Warehouse::getEnable, Warehouse::getDeleted);
        List<Map<String, Object>> warehouseList = listMaps(warehouse);
        Iterator<Map<String, Object>> it = warehouseList.iterator();
        while (it.hasNext()){
            Map item = it.next();
            if (item.get("deleted") != null && (Boolean) item.get("deleted")){
                it.remove();
                continue;
            }
            item.put("value",item.get("code").toString());
            item.put("flag", item.get("deleted"));
        }
        return warehouseList;
    }

    public String getWarehouseNameByCode(String code){
        if(StringUtils.isNotEmpty(code)){
            LambdaQueryWrapper<Warehouse> warehouse = Wrappers.lambdaQueryNoWarehouse();
            warehouse.eq(Warehouse::getCode,code);
            warehouse.last("limit 1");
            Warehouse warehouse1=this.getOne(warehouse);
            if(warehouse1!=null){
                return warehouse1.getName();
            }
        }
        return null;
    }
}