package com.jsowell.thirdparty.amap.service.impl;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.jsowell.common.constant.Constants;
import com.jsowell.common.util.PageUtils;
import com.jsowell.common.util.StringUtils;
import com.jsowell.pile.domain.OrderBasicInfo;
import com.jsowell.pile.domain.PileBasicInfo;
import com.jsowell.pile.domain.PileStationInfo;
import com.jsowell.pile.dto.amap.GetStationInfoDTO;
import com.jsowell.pile.service.*;
import com.jsowell.pile.vo.base.ConnectorInfoVO;
import com.jsowell.pile.vo.base.PileInfoVO;
import com.jsowell.pile.vo.uniapp.customer.BillingPriceVO;
import com.jsowell.pile.vo.web.BillingDetailVO;
import com.jsowell.pile.vo.web.BillingTemplateVO;
import com.jsowell.pile.vo.web.PileModelInfoVO;
import com.jsowell.thirdparty.amap.domain.*;
import com.jsowell.thirdparty.amap.service.AMapService;
import com.jsowell.thirdparty.amap.util.AMapUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StopWatch;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.stream.Collectors;

/**
 * 高德地图Service
 *
 * @author Lemon
 * @Date 2023/6/14 13:54
 */
@Slf4j
@Service
public class AMapServiceImpl implements AMapService {

    @Autowired
    private PileStationInfoService pileStationInfoService;

    @Autowired
    private PileConnectorInfoService pileConnectorInfoService;

    @Autowired
    private PileBillingTemplateService pileBillingTemplateService;

    @Autowired
    private PileBasicInfoService pileBasicInfoService;

    @Autowired
    private PileModelInfoService pileModelInfoService;

    @Autowired
    private OrderBasicInfoService orderBasicInfoService;

    /**
     * 高德拉取充电站静态数据
     * @param dto
     * @return
     */
    @Override
    public List<AMapStationInfo> getStationInfos(GetStationInfoDTO dto) throws ExecutionException, InterruptedException {
        StopWatch sw = new StopWatch();
        // List<AMapStationInfo> resultList = new ArrayList<>();

        int pageNo = dto.getCurrentPage() == null ? 1 : dto.getCurrentPage();
        int pageSize = dto.getPageSize() == null ? 20 : dto.getPageSize();
        // 设置分页参数
        PageUtils.startPage(pageNo, pageSize);
        // 查询站点信息
        sw.start("查询站点信息");
        List<PileStationInfo> stationInfos = pileStationInfoService.getStationInfosByAmap(dto);

        PageInfo<PileStationInfo> pageInfo = new PageInfo<>(stationInfos);
        sw.stop();
        if (CollectionUtils.isEmpty(pageInfo.getList())) {
            return new ArrayList<>();
        }
        // 拼装高德格式数据
        sw.start("拼装高德格式数据");

        // 使用自定义ForkJoinPool
        List<AMapStationInfo> resultList = new ForkJoinPool(4).submit(() ->
                stationInfos.parallelStream().map(x -> {
                    try {
                        return assembleAMapData(x);
                    } catch (ExecutionException | InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }).collect(Collectors.toList())
        ).fork().join();

        sw.stop();
        log.info("接口耗时：{}, 详情:{}", sw.getTotalTimeMillis(), sw.prettyPrint());
        return resultList;
    }


    @Override
    public List<AMapStationInfo> getStationInfosV2(GetStationInfoDTO dto) {
        StopWatch sw = new StopWatch();
        sw.start("查询站点信息");
        List<AMapStationInfo> resultList = Lists.newArrayList();
        // 设置分页参数
        int pageNo = dto.getCurrentPage() == null ? 1 : dto.getCurrentPage();
        int pageSize = dto.getPageSize() == null ? 20 : dto.getPageSize();
        PageUtils.startPage(pageNo, pageSize);

        // 第一次查询，得到站点
        List<PileStationInfo> stationInfos = pileStationInfoService.getStationInfosByAmap(dto);
        PageInfo<PileStationInfo> pageInfo = new PageInfo<>(stationInfos);
        List<PileStationInfo> stationList = pageInfo.getList();
        if (CollectionUtils.isEmpty(stationList)) {
            return resultList;
        }
        // 站点id
        List<String> stationIdList = stationList.stream().map(x -> String.valueOf(x.getId())).collect(Collectors.toList());

        // 第二次查询，得到计费模板信息
        Map<String, List<AMapPriceChargingInfo>> priceInfoMap = getPriceInfoByStationIdList(stationIdList);

        // 第三次查询，得到充电桩
        Map<String, List<AMapEquipmentInfo>> equipmentInfoMap = getPileListByStationIdList(stationIdList);

        // 拼装数据
        List<AMapDiscountPriceChargingInfo> discountInfoList;
        List<AMapPictures> picturesList;
        AMapStationInfo aMapInfo;
        for (PileStationInfo stationInfo : stationList) {
            String stationId = String.valueOf(stationInfo.getId());
            // 判断当前站点计费模板是否为空
            List<AMapPriceChargingInfo> aMapPriceChargingInfos = priceInfoMap.get(stationId);
            if (CollectionUtils.isEmpty(aMapPriceChargingInfos)) {
                continue;
            }

            aMapInfo = new AMapStationInfo();

            aMapInfo.setStationID(stationId);
            aMapInfo.setOperatorID(Constants.OPERATORID_LIANLIAN);
            aMapInfo.setEquipmentOwnerID(Constants.OPERATORID_LIANLIAN);
            aMapInfo.setOperatorName(Constants.JSOWELL);
            if (StringUtils.isNotBlank(stationInfo.getOperatorName())) {
                // 如果设置的运营商品牌不为空，就用所设置的运营商品牌
                aMapInfo.setOperatorName(stationInfo.getOperatorName());
            }
            aMapInfo.setStationName(stationInfo.getStationName());
            if (StringUtils.isNotBlank(stationInfo.getAMapStationName())) {
                // 如果设置的推送高德的站点名称描述不为空，就用站点名称描述
                aMapInfo.setStationName(stationInfo.getAMapStationName());
            }
            aMapInfo.setCountryCode(stationInfo.getCountryCode());
            if (StringUtils.isNotBlank(stationInfo.getParkFeeDescribe())) {
                // 停车费率描述
                aMapInfo.setParkFee(stationInfo.getParkFeeDescribe());
            }
            aMapInfo.setAreaCode(stationInfo.getAreaCode());
            aMapInfo.setServiceTel(stationInfo.getStationTel());
            aMapInfo.setAddress(stationInfo.getAddress());
            aMapInfo.setStationType(Integer.parseInt(stationInfo.getStationType()));
            aMapInfo.setStationStatus(Integer.parseInt(stationInfo.getStationStatus()));
            Integer openType = Integer.parseInt(stationInfo.getPublicFlag()) == 0 ? 7 : 0;
            aMapInfo.setOpenType(openType);
            aMapInfo.setParkNums(0);
            aMapInfo.setStationLng(new BigDecimal(stationInfo.getStationLng()).setScale(6, RoundingMode.HALF_UP));
            aMapInfo.setStationLat(new BigDecimal(stationInfo.getStationLat()).setScale(6, RoundingMode.HALF_UP));
            String construction = stationInfo.getConstruction();
            if (StringUtils.equals("12", construction) || StringUtils.equals("13", construction) ||
                    StringUtils.equals("14", construction) || StringUtils.equals("15", construction)) {
                construction = "255";
            }
            aMapInfo.setConstruction(Integer.parseInt(construction));
            aMapInfo.setBusineHours(stationInfo.getBusinessHours());

            // 计费模板
            aMapInfo.setPriceChargingInfo(aMapPriceChargingInfos);
            // 站点设备信息
            List<AMapEquipmentInfo> equipmentInfos = equipmentInfoMap.get(stationId);
            aMapInfo.setEquipmentInfos(equipmentInfos);
            // 站点充电优惠价格(目前无优惠措施)
            AMapDiscountPriceChargingInfo info;
            discountInfoList = Lists.newArrayList();
            for (AMapPriceChargingInfo aMapPriceChargingInfo : aMapPriceChargingInfos) {
                info = new AMapDiscountPriceChargingInfo();
                info.setDiscountTime(aMapPriceChargingInfo.getFeeTime());
                info.setDiscountServiceFee(aMapPriceChargingInfo.getServiceFee());
                info.setDiscountElectricityFee(aMapPriceChargingInfo.getElectricityFee());

                discountInfoList.add(info);
            }
            aMapInfo.setDiscountPriceChargingInfo(discountInfoList);

            // 站点图片
            picturesList = Lists.newArrayList();
            AMapPictures aMapPictures;
            String pictures = stationInfo.getPictures();
            if (StringUtils.isNotBlank(pictures)) {
                List<String> picList = Lists.newArrayList(pictures.split(","));
                for (int i = 0; i < picList.size(); i++) {
                    String s = picList.get(i);
                    aMapPictures = new AMapPictures();
                    aMapPictures.setUrl(s);
                    aMapPictures.setTitle(Constants.ONE);
                    aMapPictures.setPicID(String.valueOf(i + 1));
                    picturesList.add(aMapPictures);
                }
            } else {
                aMapPictures = new AMapPictures();
                aMapPictures.setUrl("");
                aMapPictures.setTitle("");
                aMapPictures.setPicID("");
                picturesList.add(aMapPictures);
            }
            aMapInfo.setPictures(picturesList);

            int fastTotal = 0;
            int slowTotal = 0;

            for (AMapEquipmentInfo equipmentInfo : equipmentInfos) {
                Integer equipmentType = equipmentInfo.getEquipmentType();
                if (equipmentType == 1) {
                    fastTotal += 1;
                }
                if (equipmentType == 2) {
                    slowTotal += 1;
                }
            }


            aMapInfo.setFastEquipmentNum(fastTotal);
            aMapInfo.setSlowEquipmentNum(slowTotal);
            resultList.add(aMapInfo);
        }
        sw.stop();
        log.info("接口耗时：{}, 详情:{}", sw.getTotalTimeMillis(), sw.prettyPrint());
        return resultList;
    }

    /**
     * 推送站点信息
     * 站点状态如有变化，（上线、下线）调用此接口
     * @param stationIds 站点idList
     * @param status 更改站点状态（1：上线，0：下线）
     * @return
     */
    @Override
    public String pushStationInfo(List<String> stationIds, String status) throws Exception {
        // 拼装业务参数
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status", status);
        jsonObject.put("idList", stationIds);

        String SPI = "amap.charging.pushStationInfo";

        Map<String, String> map = AMapUtils.generateParamMap(jsonObject, SPI);

        // 调用高德接口
        return AMapUtils.sendPost(map);
    }

    /**
     * 拼装高德需要的格式数据
     * @param stationInfo 站点信息
     * @return 高度需要的数据格式
     */
    private AMapStationInfo assembleAMapData(PileStationInfo stationInfo) throws ExecutionException, InterruptedException {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start("拼装高德需要的格式数据-设置参数");
        AMapStationInfo aMapInfo = new AMapStationInfo();
        Long stationInfoId = stationInfo.getId();
        aMapInfo.setStationID(String.valueOf(stationInfoId));
        aMapInfo.setOperatorID("");
        aMapInfo.setEquipmentOwnerID("");
        aMapInfo.setOperatorName("");
        aMapInfo.setStationName(stationInfo.getStationName());
        aMapInfo.setCountryCode(stationInfo.getCountryCode());
        aMapInfo.setAreaCode(stationInfo.getAreaCode());
        aMapInfo.setAddress(stationInfo.getAddress());
        aMapInfo.setServiceTel(stationInfo.getServiceTel());
        aMapInfo.setStationType(Integer.parseInt(stationInfo.getStationType()));
        aMapInfo.setStationStatus(Integer.parseInt(stationInfo.getStationStatus()));
        Integer openType = Integer.parseInt(stationInfo.getPublicFlag()) == 0 ? 7 : 0;
        aMapInfo.setOpenType(openType);
        aMapInfo.setParkNums(0);
        aMapInfo.setStationLng(new BigDecimal(stationInfo.getStationLng()).setScale(6, RoundingMode.HALF_UP));
        aMapInfo.setStationLat(new BigDecimal(stationInfo.getStationLat()).setScale(6, RoundingMode.HALF_UP));
        String construction = stationInfo.getConstruction();
        if (StringUtils.equals("12", construction) || StringUtils.equals("13", construction) ||
                StringUtils.equals("14", construction) || StringUtils.equals("15", construction)) {
            construction = "255";
        }
        aMapInfo.setConstruction(Integer.parseInt(construction));
        aMapInfo.setBusineHours(stationInfo.getBusinessHours());
        stopWatch.stop();

        stopWatch.start("拼装高德需要的格式数据-查询数据");
        // 根据站点id查询计费模板
        CompletableFuture<List<AMapPriceChargingInfo>> future1 = CompletableFuture.supplyAsync(() -> getPriceInfoByStationId(String.valueOf(stationInfoId)));

        // 根据站点id查询快、慢充设备数量
        CompletableFuture<Map<String, Integer>> future2 = CompletableFuture.supplyAsync(() -> pileConnectorInfoService.getPileTypeNum(stationInfoId));

        // 根据站点查询站点下所有桩
        CompletableFuture<List<AMapEquipmentInfo>> future3 = CompletableFuture.supplyAsync(() -> getPileListByStationId(String.valueOf(stationInfoId)));

        CompletableFuture<Void> all = CompletableFuture.allOf(future1, future2, future3);
        // .join()和.get()都会阻塞并获取线程的执行情况
        // .join()会抛出未经检查的异常，不会强制开发者处理异常 .get()会抛出检查异常，需要开发者处理
        all.join();

        aMapInfo.setPriceChargingInfo(future1.get());
        Map<String, Integer> pileNumMap = future2.get();
        aMapInfo.setFastEquipmentNum(pileNumMap.get("fastTotal"));
        aMapInfo.setSlowEquipmentNum(pileNumMap.get("slowTotal"));

        aMapInfo.setEquipmentInfos(future3.get());

        stopWatch.stop();

        if (stopWatch.getTotalTimeMillis() > 100) {
            log.info("高德查询-拼装高德数据耗时大于100ms:{}, 详细:{}, stationInfo:{}", stopWatch.getTotalTimeMillis(), stopWatch.prettyPrint(), JSON.toJSONString(stationInfo));
        }
        return aMapInfo;
    }

    private String prettyPrintBySecond(StopWatch stopWatch) {
        StopWatch.TaskInfo[] taskInfos = stopWatch.getTaskInfo();
        StringBuilder sb = new StringBuilder();
        sb.append('\n');
        sb.append("StopWatch '").append(stopWatch.getId()).append("': running time = ").append(stopWatch.getTotalTimeMillis()).append(" ms");
        sb.append('\n');
        if (taskInfos.length < 1) {
            sb.append("No task info kept");
        } else {
            sb.append("---------------------------------------------\n");
            sb.append("s         %     Task name\n");
            sb.append("---------------------------------------------\n");
            NumberFormat nf = NumberFormat.getNumberInstance();
            nf.setMinimumFractionDigits(3);
            nf.setGroupingUsed(false);
            NumberFormat pf = NumberFormat.getPercentInstance();
            pf.setMinimumIntegerDigits(2);
            pf.setMinimumFractionDigits(2);
            pf.setGroupingUsed(false);
            for (StopWatch.TaskInfo task : taskInfos) {
                sb.append(nf.format(task.getTimeSeconds())).append("  ");
                sb.append(pf.format((double) task.getTimeNanos() / stopWatch.getTotalTimeNanos())).append("  ");
                sb.append(task.getTaskName()).append("\n");
            }
        }
        return sb.toString();
    }


    /**
     * 商家推送充电设备动态数据
     * @param stationId 充电站id
     * @return
     * @throws Exception
     */
    @Override
    public String pushChargingDeviceDynamics(String stationId) throws Exception {
        // 根据站点id查询枪口信息
        List<AMapConnectorStatusInfo> connectorStatusInfoList = Lists.newArrayList();
        AMapConnectorStatusInfo info;
        List<ConnectorInfoVO> connectorList = pileConnectorInfoService.getUniAppConnectorList(Long.parseLong(stationId));
        for (ConnectorInfoVO connectorInfoVO : connectorList) {
            info = new AMapConnectorStatusInfo();
            info.setConnectorID(connectorInfoVO.getPileConnectorCode());
            info.setEquipmentID(connectorInfoVO.getPileSn());
            info.setStatus(connectorInfoVO.getConnectorStatus());
            connectorStatusInfoList.add(info);
        }

        Map<String, Integer> pileNumMap = pileConnectorInfoService.getPileTypeNum(connectorList);
        // 拼装业务参数
        JSONObject json = new JSONObject();
        json.put("stationID", stationId);
        json.put("fast_free", pileNumMap.get("fastFree"));
        json.put("fast_total", pileNumMap.get("fastTotal"));
        json.put("slow_free", pileNumMap.get("slowFree"));
        json.put("slow_total", pileNumMap.get("slowTotal"));
        json.put("connectorStatusInfo", connectorStatusInfoList);

        String SPI = "amap.charging.pushStationStatus";

        Map<String, String> map = AMapUtils.generateParamMap(json, SPI);

        // 调用高德接口
        return AMapUtils.sendPost(map);
    }

    /**
     * 商家推送充电订单信息
     * @param orderCode
     * @return
     */
    @Override
    public String pushChargingOrderInfo(String orderCode) {
        // 根据订单编号查询信息
        OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode);

        // 拼装业务参数
        JSONObject json = new JSONObject();
        json.put("", "");


        return null;
    }



    /**
     * 根据站点id查询计费模板
     * @param StationId
     * @return
     */
    private List<AMapPriceChargingInfo> getPriceInfoByStationId(String StationId) {
        List<AMapPriceChargingInfo> priceList = new ArrayList<>();
        // 查询计费模板
        List<BillingPriceVO> billingPriceList = pileBillingTemplateService.queryBillingPrice(StationId);
        for (BillingPriceVO billingPriceVO : billingPriceList) {
            AMapPriceChargingInfo info = new AMapPriceChargingInfo();
            info.setFeeTime(billingPriceVO.getStartTime() + "-" + billingPriceVO.getEndTime()); // 时间段
            info.setElectricityFee(new BigDecimal(billingPriceVO.getElectricityPrice()).setScale(4, RoundingMode.HALF_UP)); // 电费
            info.setServiceFee(new BigDecimal(billingPriceVO.getServicePrice()).setScale(4, RoundingMode.HALF_UP)); // 服务费

            priceList.add(info);
        }
        return priceList;
    }

    /**
     * 通过站点idList查询对应的计费模板
     * @param stationIdList
     * @return
     */
    private Map<String, List<AMapPriceChargingInfo>> getPriceInfoByStationIdList(List<String> stationIdList) {
        Map<String, List<AMapPriceChargingInfo>> resultMap = Maps.newHashMap();

        List<BillingTemplateVO> list = pileBillingTemplateService.selectBillingTemplateByStationIdList(stationIdList);
        if (CollectionUtils.isEmpty(list)) {
            return resultMap;
        }

        List<AMapPriceChargingInfo> priceList;
        AMapPriceChargingInfo info;
        for (BillingTemplateVO billingTemplateVO : list) {
            // billingTemplateVO 站点计费模板
            priceList = Lists.newArrayList();
            List<BillingDetailVO> billingDetailList = billingTemplateVO.getBillingDetailList();
            for (BillingDetailVO billingDetailVO : billingDetailList) {
                // billingDetailVO 计费模板的尖峰平谷详细信息
                List<String> applyTime = billingDetailVO.getApplyTime();
                for (String s : applyTime) {
                    info = new AMapPriceChargingInfo();
                    info.setFeeTime(s);
                    info.setElectricityFee(billingDetailVO.getElectricityPrice().setScale(4, BigDecimal.ROUND_HALF_UP));
                    info.setServiceFee(billingDetailVO.getServicePrice().setScale(4, BigDecimal.ROUND_HALF_UP));
                    priceList.add(info);
                }
            }
            resultMap.put(billingTemplateVO.getStationId(), priceList);
        }
        return resultMap;
    }



    /**
     * 根据站点查询站点下所有桩
     * @param stationId
     * @return
     */
    private List<AMapEquipmentInfo> getPileListByStationId(String stationId) {
        List<AMapEquipmentInfo> pileList = new ArrayList<>();
        // 根据站点查询站点下所有桩
        List<PileBasicInfo> pileBasicInfoList = pileBasicInfoService.getPileListByStationId(String.valueOf(stationId));
        if (CollectionUtils.isEmpty(pileBasicInfoList)) {
            return new ArrayList<>();
        }
        for (PileBasicInfo pileBasicInfo : pileBasicInfoList) {
            AMapEquipmentInfo info = new AMapEquipmentInfo();

            info.setEquipmentID(pileBasicInfo.getSn());
            info.setManufacturerName("举视");
            // 查询型号
            PileModelInfoVO modelInfo = pileModelInfoService.getPileModelInfoByModelId(pileBasicInfo.getModelId());

            info.setEquipmentType(Integer.parseInt(modelInfo.getSpeedType()));
            info.setPower(new BigDecimal(modelInfo.getRatedPower()).setScale(1, BigDecimal.ROUND_HALF_UP));

            List<AMapConnectorInfo> aMapConnectorInfos = getConnectorListBySN(pileBasicInfo.getSn());

            info.setConnectorInfos(aMapConnectorInfos);

            pileList.add(info);
        }
        return pileList;
    }

    /**
     * 查询站点设备信息-高德
     * @param stationIdList
     * @return
     */
    @Override
    public Map<String, List<AMapEquipmentInfo>> getPileListByStationIdList(List<String> stationIdList) {
        Map<String, List<AMapEquipmentInfo>> resultMap = Maps.newHashMap();
        List<PileInfoVO> pileInfoVOS = pileBasicInfoService.queryPileDetailList(stationIdList);
        if (CollectionUtils.isEmpty(pileInfoVOS)) {
            return resultMap;
        }
        // 根据站点id分组
        Map<String, List<PileInfoVO>> stationMap = pileInfoVOS.stream().collect(Collectors.groupingBy(PileInfoVO::getStationId));

        // 处理结果集
        List<AMapEquipmentInfo> pileList;
        AMapEquipmentInfo info;
        List<AMapConnectorInfo> connectorInfos;
        AMapConnectorInfo connectorInfo;
        for (Map.Entry<String, List<PileInfoVO>> entry : stationMap.entrySet()) {
            String stationId = entry.getKey();
            // 枪口维度的数据
            List<PileInfoVO> pileInfoList = entry.getValue();
            if (CollectionUtils.isEmpty(pileInfoList)) {
                continue;
            }
            pileList = Lists.newArrayList();

            Map<String, List<PileInfoVO>> pileMap = pileInfoList.stream().collect(Collectors.groupingBy(PileInfoVO::getPileSn));

            for (Map.Entry<String, List<PileInfoVO>> pile : pileMap.entrySet()) {
                info = new AMapEquipmentInfo();
                String pileSn = pile.getKey();
                List<PileInfoVO> value = pile.getValue();
                PileInfoVO pileInfoVO = value.get(0);
                info.setEquipmentID(pileSn);
                info.setManufacturerName(Constants.JSOWELL);
                info.setEquipmentType(Integer.valueOf(pileInfoVO.getSpeedType()));
                info.setPower(new BigDecimal(pileInfoVO.getRatedPower()).setScale(1, BigDecimal.ROUND_HALF_UP));
                connectorInfos = Lists.newArrayList();
                for (PileInfoVO infoVO : value) {
                    connectorInfo = new AMapConnectorInfo();
                    connectorInfo.setConnectorID(infoVO.getPileConnectorCode());
                    Integer connectorType = Integer.parseInt(infoVO.getSpeedType()) == 1 ? 4 : 3;
                    connectorInfo.setConnectorType(connectorType);
                    connectorInfo.setPower(new BigDecimal(infoVO.getRatedPower()).setScale(1, RoundingMode.HALF_UP));
                    connectorInfo.setCurrent(Integer.parseInt(infoVO.getRatedCurrent()));
                    connectorInfo.setBrandDesc(Constants.JSOWELL);
                    connectorInfo.setNationalStandard(2);
                    connectorInfo.setVoltageLowerLimits(0);
                    connectorInfo.setVoltageUpperLimits(Integer.parseInt(infoVO.getRatedVoltage()));
                    connectorInfos.add(connectorInfo);
                }
                info.setConnectorInfos(connectorInfos);
                pileList.add(info);
            }
            resultMap.put(stationId, pileList);
        }
        return resultMap;
    }


    /**
     * 根据桩号查询枪口列表
     * @param pileSn
     * @return
     */
    private List<AMapConnectorInfo> getConnectorListBySN(String pileSn) {
        List<AMapConnectorInfo> list = new ArrayList<>();

        // 根据桩号查询枪口列表
        List<ConnectorInfoVO> connectorInfoList = pileConnectorInfoService.selectConnectorInfoList(pileSn);
        if (CollectionUtils.isEmpty(connectorInfoList)) {
            return new ArrayList<>();
        }

        for (ConnectorInfoVO connectorInfoVO : connectorInfoList) {
            AMapConnectorInfo aMapConnectorInfo = new AMapConnectorInfo();

            aMapConnectorInfo.setConnectorID(connectorInfoVO.getPileConnectorCode());

            Integer connectorType = Integer.parseInt(connectorInfoVO.getChargingType()) == 1 ? 4 : 3;
            aMapConnectorInfo.setConnectorType(connectorType);
            aMapConnectorInfo.setVoltageLowerLimits(0);
            aMapConnectorInfo.setVoltageUpperLimits(Integer.parseInt(connectorInfoVO.getRatedVoltage()));
            aMapConnectorInfo.setCurrent(Integer.parseInt(connectorInfoVO.getRatedCurrent()));
            aMapConnectorInfo.setPower(new BigDecimal(connectorInfoVO.getRatedPower()).setScale(1, RoundingMode.HALF_UP));
            aMapConnectorInfo.setNationalStandard(2);
            aMapConnectorInfo.setBrandDesc("举视");

            list.add(aMapConnectorInfo);
        }
        return list;
    }
}
