StationService.java 4.5 KB
package com.huaheng.pc.config.station.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.pc.config.container.domain.Container;
import com.huaheng.pc.config.container.service.ContainerService;
import com.huaheng.pc.config.location.domain.Location;
import com.huaheng.pc.config.location.service.LocationService;
import com.huaheng.pc.config.material.domain.Material;
import com.huaheng.pc.config.material.service.MaterialService;
import com.huaheng.pc.config.station.domain.StationType;
import com.huaheng.pc.inventory.inventoryDetail.domain.InventoryDetail;
import com.huaheng.pc.inventory.inventoryDetail.service.InventoryDetailService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaheng.pc.config.station.domain.Station;
import com.huaheng.pc.config.station.mapper.StationMapper;
/**
 * Created by Enzo Cotter on 2019/10/11.
 */


@Service
public class StationService extends ServiceImpl<StationMapper, Station> {
    @Resource
    private InventoryDetailService inventoryDetailService;
    @Resource
    private MaterialService materialService;
    @Resource
    private ContainerService containerService;
    @Resource
    private LocationService locationService;

    @Resource
    private StationService stationService;

    public Map<String, Object> StationFromType(StationType stationType) {
        String containerCode = stationType.getContainerCode();
        int type = Integer.parseInt(stationType.getType());
        Container container = containerService.getContainerByCode(containerCode);
        Map<String, Object> map = new HashMap<>();
        if(container == null) {
            return map;
        }
        String locationCode = container.getLocationCode();
        if(StringUtils.isEmpty(locationCode)) {
            return map;
        }
        LambdaQueryWrapper<Location> locationLambdaQueryWrapper = Wrappers.lambdaQuery();
        locationLambdaQueryWrapper.eq(Location::getCode, locationCode)
                .eq(Location::getWarehouseCode, ShiroUtils.getWarehouseCode());
        Location location1 = locationService.getOne(locationLambdaQueryWrapper);
        if(location1 == null) {
            return map;
        }

        LambdaQueryWrapper<InventoryDetail> inventoryDetailLambdaQueryWrapper=Wrappers.lambdaQuery();
        inventoryDetailLambdaQueryWrapper.eq(InventoryDetail::getContainerCode,containerCode).eq(InventoryDetail::getLocationCode,locationCode);
        List<InventoryDetail> list1 = inventoryDetailService.list(inventoryDetailLambdaQueryWrapper);
        Material one1=new Material();
        if (list1.size()>0){
            LambdaQueryWrapper<Material> materialLambdaQueryWrapper=Wrappers.lambdaQuery();
            materialLambdaQueryWrapper.eq(Material::getCode,list1.get(0).getMaterialCode());
            one1 = materialService.getOne(materialLambdaQueryWrapper);
        }
        LambdaQueryWrapper<Station> queryWrapper = Wrappers.lambdaQuery();
        if(type == QuantityConstant.STATION_PICK_AND_OUT) {
            queryWrapper.in(Station::getType,
                    QuantityConstant.STATION_OUT, QuantityConstant.STATION_PICK);
        } else {
            queryWrapper.eq(Station::getType, type);
        }
        queryWrapper.eq(Station::getArea, location1.getArea()).eq(StringUtils.isNotEmpty(one1.getSpec()),
                Station::getDestination, one1.getSpec());
        List<Station> stationList = stationService.list(queryWrapper);
        if (stationList==null || stationList.size()<=0||list1.size()>1)
        {
            queryWrapper = Wrappers.lambdaQuery();
            queryWrapper.eq(Station::getArea, location1.getArea()).eq(Station::getType, type);
            stationList = stationService.list(queryWrapper);
        }
        List<Map<String, Object>> list = new ArrayList<>();
        for (Station station : stationList) {
            Map<String, Object> resultMap = new HashMap<>();
            resultMap.put("id", station.getCode());
            resultMap.put("text", station.getName());
            list.add(resultMap);
            map.put("hhh",station.getCode());
        }
        map.put("results", list);

        return map;
    }

}