package com.prolog.eis.service.container.impl;

import com.prolog.eis.dao.container.ContainerInfoMapper;
import com.prolog.eis.dto.contaienr.Poses;
import com.prolog.eis.service.feign.RouteFeignService;
import com.prolog.eis.model.container.ContainerInfo;
import com.prolog.eis.router.vo.ContainerLocationVo;
import com.prolog.eis.service.container.SimulationService;
import com.prolog.eis.service.feign.RouteFeignService;
import com.prolog.framework.utils.MapUtils;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @version 1.0.0
 * date:2023/2/28
 * @author：王昭
 */
@Slf4j
@Service
@AllArgsConstructor
public class SimulationServiceImpl implements SimulationService {
    private final ContainerInfoMapper containerInfoMapper;
    private final RouteFeignService plgFeignRouteService;
    @Override
    public Map<String, Object> inventoryData() throws Exception {
        List<ContainerInfo> containerInfos = containerInfoMapper.findByMap(new HashMap<>(),ContainerInfo.class);
        List<String> containerNoList = containerInfos.stream().map(ContainerInfo::getContainerNo).collect(Collectors.toList());
        List<ContainerLocationVo> locationByContainerList = plgFeignRouteService.findLocationByContainerList(containerNoList);
        List<Poses> posesList = locationByContainerList.stream().map(locationByContainer -> {
            Poses poses = new Poses();
            poses.setNumber(locationByContainer.getContainerNo());
            poses.setPos(locationByContainer.getCurrentLocation());
            poses.setBusinesses_attribute(locationByContainer.getBusinessProperty());
            return poses;
        }).collect(Collectors.toList());
        Map<String, Object> poses = MapUtils.put("poses", posesList).getMap();
        return MapUtils.put("code", 0).put("msg_value",poses).getMap();
    }
}
