WarehouseServiceImpl.java 2.73 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.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 org.springframework.stereotype.Service;

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 WarehouseMapper warehouseMapper;
    @Resource
    private WarehouseCompanyService warehouseCompanyService;

    @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)
                .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> warehouseId:warehouseCompanies)           {
                if (item.get("code").toString().equals(warehouseId.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;
    }

}