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

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.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.domain.Address;
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.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.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 WarehouseMapper warehouseMapper;
    @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;

    @Override
    public List<Map<String, Object>> getWarehouseList(Integer id) {
        /**
         *  查询仓库的code、name、enable
         */
        LambdaQueryWrapper<Warehouse> lambdaQueryWrapper = Wrappers.lambdaQuery();
        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();
        for (Warehouse warehouse : warehouses)
        {
            for (Warehouse userWarehouse: userWarhouses)
            {
                if (warehouse.getCode().equals(userWarehouse.getCode()))
                {
                    warehouse.setFlag(true);
                    break;
                }
            }
        }
        return warehouses;
    }

    /**
     * 复制仓库
     * @param warehouseCode 仓库编码
     * @param newWarehouseCode 新仓库编码
     */
    @Override
    @Transactional
    public Boolean warehouseCopy(String warehouseCode, String newWarehouseCode) {
//        if(warehouseCode.equals(newWarehouseCode)){
//            throw new ServiceException("登录仓库不能复制");
//        }
//        LambdaQueryWrapper<Address> lambdaQueryWrapper = Wrappers.lambdaQuery();
//        lambdaQueryWrapper.eq(Address::getWarehouseCode,newWarehouseCode);
//        List<Address> addresses = addressService.list(lambdaQueryWrapper);
//        if(addresses !=null || addresses.size()>0){
//            throw new ServiceException("输入仓库非新建仓库");
//        }
        /* 复制地址表*/
        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 (!dictTypeService.dictTypeCopy(warehouseCode, newWarehouseCode)){
            throw new ServiceException("复制字典数据表失败");
        }
        /* 复制菜单*/
        if (!menuService.menuCopy(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;
    }
}