package com.xhpc.evcs.cdjgpc.api;

import cn.hutool.core.date.DateUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.xhpc.common.api.ChargingStationService;
import com.xhpc.common.api.PowerPileService;
import com.xhpc.common.api.dto.ChargingStationDto;
import com.xhpc.common.core.domain.R;
import com.xhpc.common.data.redis.CacheRateModel;
import com.xhpc.common.data.redis.CacheRealtimeData;
import com.xhpc.common.domain.XhpcTerminal;
import com.xhpc.evcs.cdjgpc.dto.*;
import com.xhpc.evcs.domain.AuthSecretToken;
import com.xhpc.evcs.domain.XhpcInternetUser;
import com.xhpc.evcs.domain.XhpcStationInternetBlacklist;
import com.xhpc.evcs.dto.*;
import com.xhpc.evcs.encryption.Aes128Cbc;
import com.xhpc.evcs.encryption.EvcsConst;
import com.xhpc.evcs.jpa.AuthSecretTokenRepository;
import com.xhpc.evcs.jpa.XhpcInternetUserRepository;
import com.xhpc.evcs.jpa.XhpcStationInternetBlacklistRepository;
import com.xhpc.evcs.jpa.XhpcTerminalRepository;
import com.xhpc.evcs.notification.CoreDispatcher;
import com.xhpc.evcs.cdjgpc.dto.CDRequirementInfo;
import com.xhpc.evcs.cdjgpc.dto.CDTaskInfo;
import com.xhpc.evcs.utils.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import static cn.hutool.core.util.NumberUtil.isInteger;
import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS;
import javax.annotation.Resource;

import java.math.BigDecimal;
import java.time.Instant;
import java.util.*;
import java.util.stream.Collectors;

import static com.xhpc.evcs.domain.AuthSecretToken.SECRET_TOKEN_TYPE_IN;
import static com.xhpc.evcs.domain.AuthSecretToken.SECRET_TOKEN_TYPE_OUT;

/**
 * @author yuyang
 * @date 2023-09-07 16:12
 */
@Slf4j
@RestController
public class CDNotificationStationInfoController extends CoreDispatcher {


    @Resource
    AuthSecretTokenRepository authSecretTokenRepository;
    @Resource
    XhpcInternetUserRepository xhpcInternetUserRepository;
    @Resource
    XhpcStationInternetBlacklistRepository xhpcStationInternetBlacklistRepo;
    @Resource
    XhpcTerminalRepository terminalRepository;
    @Resource
    PowerPileService powerPileService;

    @Resource
    ChargingStationService chargingStationService;

    //充电站信息变化推送（我们平台推送成都市平台）   --已推送
    //自己调用接口
    @PostMapping("/v10/getNotificationStationInfo")
    public R getNotificationStationInfo(@RequestBody Map<String, Object> map){
        try{
            String chargingStationId = map.get("chargingStationId").toString();
            AuthSecretToken authSecretTokenOut =
                authSecretTokenRepository.findByOperatorId3irdptyAndOperatorIdAndSecretTokenType(
                        "MA6CC2LK7", "MA6DFCTD5", SECRET_TOKEN_TYPE_OUT).orElse(null); //todo
        // maybe对接第三方
        if (authSecretTokenOut != null) {
            //获取场站信息
            String key = "cdjgpc:station:".concat(chargingStationId)+".notification";
            CDStationInfo cdStationInfo =REDIS.getCacheObject(key);
            cdStationInfo.setEquipmentInfos(new ArrayList<>());
            //查询场站是桩是否对应上
            ChargingStationDto stationDto = REDIS.getCacheObject("station:"+chargingStationId);

            CacheRateModel cacheRateModel = REDIS.getCacheObject("rateModel:" + stationDto.getRateModelId());

            StringBuilder price = new StringBuilder();
            StringBuilder svcPrice = new StringBuilder();

            Integer t1Price = cacheRateModel.getT1Price();
            Integer t1SvcPrice = cacheRateModel.getT1SvcPrice();
            Integer t2Price = cacheRateModel.getT2Price();
            Integer t2SvcPrice = cacheRateModel.getT2SvcPrice();
            Integer t3Price = cacheRateModel.getT3Price();
            Integer t3SvcPrice = cacheRateModel.getT3SvcPrice();
            Integer t4Price = cacheRateModel.getT4Price();
            Integer t4SvcPrice = cacheRateModel.getT4SvcPrice();

            if(cacheRateModel.getTfPricesSeq() !=null && cacheRateModel.getTfPricesSeq().length>0){
                price.append("{");
                svcPrice.append("{");
                for (int i = 0; i < cacheRateModel.getTfPricesSeq().length; i++) {
                    String time = getTime(i);
                    String s = cacheRateModel.getTfPricesSeq()[i];

                    if("00".equals(s)){
                        price.append(time).append(t1Price.toString()).append(",");
                        svcPrice.append(time).append(t1SvcPrice.toString()).append(",");
                    }else if("01".equals(s)){
                        price.append(time).append(t2Price.toString()).append(",");
                        svcPrice.append(time).append(t2SvcPrice.toString()).append(",");
                    }else if("02".equals(s)){
                        price.append(time).append(t3Price.toString()).append(",");
                        svcPrice.append(time).append(t3SvcPrice.toString()).append(",");
                    }else{
                        price.append(time).append(t4Price.toString()).append(",");
                        svcPrice.append(time).append(t4SvcPrice.toString()).append(",");
                    }
                }
                price.deleteCharAt(price.length()-1).append("}");
                svcPrice.deleteCharAt(price.length()-1).append("}");
            }
            cdStationInfo.setElectricityFee(price.toString());
            cdStationInfo.setServiceFee(svcPrice.toString());

            Set<String> pks = stationDto.getPiles();
            if (pks != null) {
                List<CDEquipmentInfo> cdEquipmentInfos = new ArrayList<>();
                for (String pileNo : pks) {
                    String pk = "pile:".concat(pileNo);
                    String skey = "cdjgpc:".concat(pk)+".notification";
                    CDEquipmentInfo cdEquipmentInfo = REDIS.getCacheObject(skey);
                    if(cdEquipmentInfo==null || "".equals(cdEquipmentInfo.getEquipmentID())){
                         log.info("该场站下面："+pileNo+"桩未录入");
                    }else{
                        cdEquipmentInfos.add(cdEquipmentInfo);
                    }
                }
                cdStationInfo.setEquipmentInfos(cdEquipmentInfos);
            }
            cdStationInfo.setSwapMatchCarsName(null);
            CommonRequest<CDStationInfo> commonRequest = new CommonRequest<>();
            Map<String,Object> mapStationInfo =new HashMap<>();
            mapStationInfo.put("StationInfo",cdStationInfo);
            String data =JSONUtil.toJSONString(mapStationInfo);
           // System.out.println("=======data========"+data);
            commonRequest.setData(data);
            String result =ok(commonRequest,"/notification_stationInfo",authSecretTokenOut);
           // System.out.println("=======result========"+result);
        }
        }catch (Exception e){
            e.printStackTrace();
        }
        return R.ok();
    }

    /**
     * 查询充电站信息(成都市平台调用我们平台)    --已推送
     * @param commonRequest
     * @return
     * @throws Exception
     */
    @PostMapping("/v10/query_stations_info")
    public CommonResponse queryStationsInfo(@RequestBody(required = false) CommonRequest<PageRequest> commonRequest) {

       // System.out.println("================查询充电站信息=======================");
        CommonResponse resp = new CommonResponse();
        try{
            //当前页数
            PageRequest pageRequest = commonRequest.transformDataType(PageRequest.class);
            Integer pageNo = pageRequest.getPageNo();
            CDPageStationsInfoResponse response = new CDPageStationsInfoResponse();
            response.setPageNo(pageNo);
            //页码总数
            String operatorId = commonRequest.getOperatorId();
            Instant now = Instant.now();
            XhpcInternetUser xhpcInternetUser =
                    xhpcInternetUserRepository
                            .findByOperatorIdEvcsLikeAndCooperationStartTimeBeforeAndCooperationEndTimeAfter(operatorId, now, now);
            Long internetUserId = xhpcInternetUser.getInternetUserId();
            List<XhpcStationInternetBlacklist> xhpcStationInternetBlacklist =
                    xhpcStationInternetBlacklistRepo.findByInternetUserId(internetUserId);
            List<String> stationKeys = new ArrayList<>(REDIS.keys("station:*"));
            List<String> validStationKeys = new ArrayList<>();
            for (String stationKey : stationKeys) {
                boolean isValid = true;
                //查询不合作的电桩
                for (XhpcStationInternetBlacklist xhpcStationInternetBlack : xhpcStationInternetBlacklist) {
                    if (stationKey.substring(8).equals(xhpcStationInternetBlack.getChargingStationId().toString())) {
                        isValid = false;
                    }
                }
                ChargingStationDto chargingStationDto = REDIS.getCacheObject(stationKey);
                if (chargingStationDto.getPiles() != null) {
                    if (isValid) {
                        validStationKeys.add(stationKey);
                    }
                }
            }
            if (validStationKeys.size() > 0) {
                Integer pageSize = pageRequest.getPageSize();
                int totalPage = validStationKeys.size() % pageSize == 0 ? validStationKeys.size() / pageSize :
                        (validStationKeys.size() / pageSize) + 1;
                response.setPageCount(totalPage);
            }
            //总记录条数
            response.setItemSize(validStationKeys.size());

            //充电站信息列表
            List<CDStationInfo> stationInfos = new ArrayList<>();
            //计算每页开始索引
            int startIndex = -1;
            int endIndex = -1;
            if (pageNo == 1 && validStationKeys.size() <= 10) {
                startIndex = 0;
                endIndex = validStationKeys.size() - 1;
            } else {
                Integer pageSize = pageRequest.getPageSize();
                startIndex = (pageNo - 1) * pageSize;
                endIndex = startIndex + (pageSize - 1);
            }
            for (int i = startIndex; i <= endIndex; i++) {
                String stationKey = null;
                try {
                    stationKey = validStationKeys.get(i);
                } catch (Exception e) {
                    continue;
                }
                String stationId = stationKey.replace("station:", "");
                stationInfos.add(getNotificationStationInfo(stationId));
            }
            response.setStationInfos(stationInfos);
            resp.setRet("0");
            resp.setMsg("Query station info success");
            resp.setData(JSONUtil.toJSONString(response));

        }catch (Exception e){
            e.printStackTrace();
        }

        return resp;
    }


    /**
     * 设备充电中状态变化推送(我们平台推送成都市平台)  --已推送
     * 实时数据没15秒一帧
     */
    @PostMapping("/v10/getNotificationConnectorChargeStatus")
    public void getNotificationConnectorChargeStatus(@RequestBody Map<String, Object> orderMap){
        //System.out.println("==================设备充电中状态变化推送(我们平台推送成都市平台) ==========================");
        //先查订单号 在查实时数据 最后计算金额
        try {
            String orderNo = orderMap.get("orderNo").toString();
            CacheRealtimeData lord = REDIS.getCacheObject("order:"+orderNo+".lord");
            String formatTime = DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss");
            Map<String, Object> cacheMap =REDIS.getCacheMap("order:"+orderNo+".notification");
            if(cacheMap==null || cacheMap.get("startTime")==null || "".equals(cacheMap.get("startTime"))){
                cacheMap.put("lastPushTime", formatTime);
            }else{
                cacheMap.put("lastPushTime", cacheMap.get("pushTime"));
            }
            cacheMap.put("pushTime", formatTime);
            CDConnectorChargeStatusInfo cdConnectorChargeStatusInfo = new CDConnectorChargeStatusInfo();
            Map<String, Object> cacheMapOrder = REDIS.getCacheMap("order:"+orderNo);
            if(cacheMap.get("startTime")==null ){
                if(cacheMapOrder !=null && cacheMapOrder.get("startTime")!=null){
                    cdConnectorChargeStatusInfo.setStartTime(cacheMapOrder.get("startTime").toString());
                    cacheMap.put("startTime", cacheMapOrder.get("startTime").toString());
                }
            }else{
                cdConnectorChargeStatusInfo.setStartTime(cacheMap.get("startTime").toString());
            }
            if(cacheMapOrder !=null && cacheMapOrder.get("status")!=null){
                if("已结束".equals(cacheMapOrder.get("status").toString())){
                    cdConnectorChargeStatusInfo.setConnectorStatus(1);
                    cdConnectorChargeStatusInfo.setOrderStatus(4);
                }else{
                    cdConnectorChargeStatusInfo.setConnectorStatus(3);
                    cdConnectorChargeStatusInfo.setOrderStatus(2);
                }
            }
            REDIS.setCacheMap("order:"+orderNo+".notification",cacheMap);
            cdConnectorChargeStatusInfo.setStartChargeSeq(lord.getOrderNo());
            cdConnectorChargeStatusInfo.setConnectorID(lord.getPileNo()+lord.getGunId());
            cdConnectorChargeStatusInfo.setCurrentA((double)(lord.getWorkingCurrent()/10));
            cdConnectorChargeStatusInfo.setVoltageA((double)(lord.getWorkingVoltage()/10));
            cdConnectorChargeStatusInfo.setSoc((double)lord.getSoc());
            cdConnectorChargeStatusInfo.setEndTime(formatTime);
            cdConnectorChargeStatusInfo.setPushTime(formatTime);
            cdConnectorChargeStatusInfo.setLastPushTime(cacheMap.get("lastPushTime").toString());
            BigDecimal chargingDegree = new BigDecimal(lord.getChargingDegree()).divide(new BigDecimal(10000).setScale(2, BigDecimal.ROUND_UP));
            BigDecimal amountCharged = new BigDecimal(lord.getAmountCharged()).divide(new BigDecimal(10000).setScale(2, BigDecimal.ROUND_UP));
            cdConnectorChargeStatusInfo.setTotalPower(chargingDegree.doubleValue());
            cdConnectorChargeStatusInfo.setTotalMoney(amountCharged.doubleValue());

            String key = "pile:"+orderNo.substring(0,14);
            Map<String, Object> cachePile = REDIS.getCacheMap(key);
            String stationId = cachePile.get("stationId").toString();
            cdConnectorChargeStatusInfo.setEquipmentID(orderNo.substring(0,14));
            cdConnectorChargeStatusInfo.setStationID(stationId);

            String stationSey = "cdjgpc:station:".concat(stationId)+".notification";
            CDStationInfo cdStationInfo =REDIS.getCacheObject(stationSey);
            cdConnectorChargeStatusInfo.setOperatorID(cdStationInfo.getOperatorId());
            cdConnectorChargeStatusInfo.setEquipmentOwnerID(cdStationInfo.getEquipmentOwnerId());


            Map<String, Object> cacheOrder = REDIS.getCacheMap("order:" + orderNo);

            if(cacheOrder !=null && cacheOrder.get("rateModelId") !=null){
                CacheRateModel rateModel = REDIS.getCacheObject("rateModel:" + cacheOrder.get("rateModelId").toString());
                if(rateModel.getT1SvcPrice().equals(rateModel.getT2SvcPrice()) && rateModel.getT3SvcPrice().equals(rateModel.getT4SvcPrice()) &&
                        rateModel.getT1SvcPrice().equals(rateModel.getT3SvcPrice())){

                    BigDecimal divide = new BigDecimal(rateModel.getT1SvcPrice()).divide(new BigDecimal(100000)).setScale(2, BigDecimal.ROUND_UP);

                    BigDecimal bigDecimal = chargingDegree.multiply(divide).setScale(2, BigDecimal.ROUND_UP);
                    cdConnectorChargeStatusInfo.setSeviceMoney(bigDecimal.doubleValue());
                    BigDecimal subtract = amountCharged.subtract(bigDecimal);
                    cdConnectorChargeStatusInfo.setElecMoney(subtract.doubleValue());
                }else{
                    //暂时不考虑不同服务费 默认为0.2
                    BigDecimal multiply = chargingDegree.multiply(new BigDecimal(0.2)).setScale(2, BigDecimal.ROUND_UP);;
                    cdConnectorChargeStatusInfo.setSeviceMoney(multiply.doubleValue());
                    BigDecimal subtract = amountCharged.subtract(multiply);
                    cdConnectorChargeStatusInfo.setElecMoney(subtract.doubleValue());
                }
                AuthSecretToken authSecretTokenOut = authSecretTokenRepository.findByOperatorId3irdptyAndSecretTokenType("MA6CC2LK7", SECRET_TOKEN_TYPE_OUT).orElse(null);
                Map<String, Object> map =new HashMap<>();
                map.put("ConnectorChargeStatusInfo",cdConnectorChargeStatusInfo);
                String data = JSONUtil.toJSONString(map);
                CommonRequest<ConnectorStatusInfoReq> commonRequest = new CommonRequest<>();
                commonRequest.setData(data);
                String result = ok(commonRequest, "/notification_connector_charge_status", authSecretTokenOut);
               // System.out.println("===设备充电中状态变化推送====result========"+result);
            }
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
    }


    /**
     * 设备接口状态查询(成都市平台调用我们平台)  --已调用
     * @param commonRequest
     * @return
     * @throws Exception
     */
    @PostMapping("/v10/query_station_status")
    public CommonResponse queryStationsStatus(@RequestBody CommonRequest<StationStatusRequest> commonRequest) throws Exception {

        CommonResponse resp = new CommonResponse();
        resp.setRet(EvcsConst.RET_FAIL);
        StationStatusRequest stationStatusRequest = JSONUtil.readParams(commonRequest.getData(), StationStatusRequest.class);
        if (stationStatusRequest == null) {
            resp.setMsg("Request or token params validation failed");
        } else {
            String[] stationIDs = stationStatusRequest.getStationIds();
            List<CDStationStatusInfo> cdStationStatusInfos = new ArrayList<>();
            //Loading data through redis at first.
            Collection<String> guns = REDIS.keys("gun:*");
            List<String> gunsNewList = new ArrayList<>();
            for (String value : guns) {
                gunsNewList.add(value.substring(4));
            }
            List<String> gunsIds = new ArrayList<>();
            for (String value : gunsNewList) {
                if (value.length() == 16) {
                    gunsIds.add(value);
                }
            }
            Map<String, Integer> statusMap = new HashMap<>();
            String[] keys = {"离线", "空闲", "故障"};
            Integer[] values = {0, 1, 255};
            for (int i = 0; i < keys.length; i++) {
                statusMap.put(keys[i], values[i]);
            }

            List<XhpcTerminal> terminalList = terminalRepository.selectStatusBySql();
            Map<String,Integer> terminalDBMap = terminalList.stream().collect(Collectors.toMap(XhpcTerminal::getSerialNumber,XhpcTerminal::getStatus));

            for (String stationID : stationIDs) {
                ChargingStationDto chargingStationDto = REDIS.getCacheObject("station:" + stationID);
                CDStationInfo cdStationInfo =REDIS.getCacheObject("cdjgpc:station:"+stationID+".notification");

                Set<String> pileIds = new HashSet<>();
                if (null != chargingStationDto) {
                    pileIds = chargingStationDto.getPiles();
                }
                boolean existsGun = false;
                List<CDConnectorStatusInfo> connectorStatusInfos = new ArrayList<>();
                for (String pileId : pileIds) {
                    for (String value : gunsIds) {
                        if (pileId.equals(value.substring(0, 14))) {
                            existsGun = true;
                            CDConnectorStatusInfo cdConnectorStatusInfo = new CDConnectorStatusInfo();
                            Integer gunStatus = terminalDBMap.get(value);
                            if (gunStatus == null){
                                existsGun = false;
                            } else {
                                if (gunStatus == 0){
                                    Object status = REDIS.getCacheMapValue("gun:" + value, "status");
                                    if (isInteger(status.toString())) {
                                        cdConnectorStatusInfo.setStatus(3);
                                    } else {
                                        cdConnectorStatusInfo.setStatus(statusMap.get(status));
                                    }
                                } else {
                                    cdConnectorStatusInfo.setStatus(0);
                                }
                                cdConnectorStatusInfo.setConnectorID(value);
                                cdConnectorStatusInfo.setEquipmentClassification(1);
                                cdConnectorStatusInfo.setOperatorID(cdStationInfo.getOperatorId());
                                cdConnectorStatusInfo.setEquipmentOwnerID(cdStationInfo.getEquipmentOwnerId());
                                cdConnectorStatusInfo.setStationID(cdStationInfo.getStationId());
                                cdConnectorStatusInfo.setEquipmentID(cdStationInfo.getOperatorId());
                                connectorStatusInfos.add(cdConnectorStatusInfo);
                            }
                        }
                    }
                }
                if (existsGun) {
                    CDStationStatusInfo cdStationStatusInfo = new CDStationStatusInfo();
                    cdStationStatusInfo.setStationID(stationID);
                    cdStationStatusInfo.setConnectorStatusInfos(connectorStatusInfos);
                    cdStationStatusInfo.setOperatorID(cdStationInfo.getOperatorId());
                    cdStationStatusInfo.setEquipmentOnwerID(cdStationInfo.getEquipmentOwnerId());
                    cdStationStatusInfos.add(cdStationStatusInfo);
                }
            }
            CDStationStatusInfoWrapper stationStatusInfoWrappers = new CDStationStatusInfoWrapper();
            stationStatusInfoWrappers.setTotal(cdStationStatusInfos.size());
            if (cdStationStatusInfos.size() != 0) {
                stationStatusInfoWrappers.setStationStatusInfos(cdStationStatusInfos);
            }
            resp.setRet("0");
            resp.setMsg("Query station status success");
            Map<String,Object> mapStationInfo =new HashMap<>();
            mapStationInfo.put("StationStats",stationStatusInfoWrappers);
            resp.setData(JSONUtil.toJSONString(mapStationInfo));
        }
        return resp;
    }


    /**
     * 查询统计信息(成都市平台调用我们平台)  --已调用
     * @param commonRequest
     * @return
     * @throws Exception
     */
    @PostMapping("/v10/query_station_stats")
    public CommonResponse queryStationsStats(@RequestBody CommonRequest<StationStatsRequest> commonRequest) throws Exception{
        CommonResponse resp = new CommonResponse();
        resp.setRet(EvcsConst.RET_FAIL);
        StationStatsRequest stationStatsRequest = JSONUtil.readParams(commonRequest.getData(), StationStatsRequest.class);
        if (stationStatsRequest == null) {
            resp.setMsg("Request or token params validation failed");
            resp.setRet("4002");
        } else {
            R r = powerPileService.queryStationStats(Long.valueOf(stationStatsRequest.getStationID()), stationStatsRequest.getStartTime(), stationStatsRequest.getEndTime());
            if(r.getCode() !=200){
                resp.setRet("-1");
                resp.setMsg("系统繁忙，此时请求方稍后重试");
                return resp;
            }
            String key ="cdjgpc:station:"+stationStatsRequest.getStationID()+".queryStationStats";
            CDStationStatslnfo stationStatsInfo =REDIS.getCacheObject(key);
            Map<String,Object> mapStationInfo =new HashMap<>();
            mapStationInfo.put("StationStats",stationStatsInfo);
            resp.setRet("0");
            resp.setData(JSONUtil.toJSONString(mapStationInfo));
            resp.setMsg("Query station info success");
            REDIS.deleteObject(key);
        }
        return resp;
    }


    /**
     * 站点费率变化tuisong(我们平台调用成都市平台) --已推送
     * @return
     * @throws Exception
     */
    @PostMapping("/v10/getNotificationStationFee")
    public void getNotificationStationFee() throws Exception {
        AuthSecretToken authSecretTokenOut =
                authSecretTokenRepository.findByOperatorId3irdptyAndOperatorIdAndSecretTokenType(
                        "MA6CC2LK7", "MA6DFCTD5", SECRET_TOKEN_TYPE_OUT).orElse(null);
        // maybe对接第三方
        if (authSecretTokenOut != null) {
            List<String> stationKeys = new ArrayList<>(REDIS.keys("cdjgpc:stationFee:*"));
            for (String stationKey : stationKeys) {
                CDStationFee cdStationFeeRequest = REDIS.getCacheObject(stationKey);
                Map<String, Object> map =new HashMap<>();
                map.put("StationFee",cdStationFeeRequest);
                String data = JSONUtil.toJSONString(map);
                CommonRequest<CDStationFee> commonRequest = new CommonRequest<>();
                commonRequest.setData(data);
                String ok = ok(commonRequest, "/notification_stationFee", authSecretTokenOut);
                //log.info("===============notification_stationFee=================="+ok);
                REDIS.deleteObject(stationKey);
            }
        }
    }

    /**
     * 查询站点费率(成都市平台调用我们平台)
     * @param commonRequest
     * @return
     * @throws Exception
     */
    @PostMapping("/v10/query_station_fee")
    public CommonResponse queryStationFee(@RequestBody CommonRequest<CDStationFeeRequest> commonRequest) throws Exception{
        CommonResponse resp = new CommonResponse();
        resp.setRet(EvcsConst.RET_FAIL);
        CDStationFeeRequest stationFeeRequest = JSONUtil.readParams(commonRequest.getData(), CDStationFeeRequest.class);
        if (stationFeeRequest == null) {
            resp.setMsg("Request or token params validation failed");
            resp.setRet("4002");
        } else {
            String[] stationIDs = stationFeeRequest.getStationIDs();
            if(stationIDs !=null && stationIDs.length>0){
                List<CDStationFee> cdStationFeeList =new ArrayList<>();
                for (int i = 0; i < stationIDs.length; i++) {
                    String stationID = stationIDs[i];
                    String skey = "cdjgpc:stationFeeRequest:".concat(stationID);
                    CDStationFee cdStationFeeRequest = REDIS.getCacheObject(skey);
                    cdStationFeeList.add(cdStationFeeRequest);
                }
                resp.setData(JSONUtil.toJSONString(cdStationFeeList));
                resp.setRet("0");
            }else{
                resp.setRet("-1");
                resp.setMsg("系统繁忙，此时请求方稍后重试");
            }
        }
        return resp;
    }


    /**
     * 查询充电设备运行统计计信息  --已调用
     * @param commonRequest
     * @return
     * @throws Exception
     */
    @PostMapping("/v10/query_SupEquipment_stats_info")
    public CommonResponse querySupEquipmentStatsInfo(@RequestBody CommonRequest<CDQuerySupEquipmentStatsInfoRequest> commonRequest)throws Exception{

        CommonResponse resp = new CommonResponse();
        resp.setRet(EvcsConst.RET_FAIL);
        StationStatsRequest stationStatsRequest = JSONUtil.readParams(commonRequest.getData(), StationStatsRequest.class);
        if (stationStatsRequest == null) {
            resp.setMsg("Request or token params validation failed");
            resp.setRet("4002");
        } else {
            R r = powerPileService.querySupEquipmentStatsInfo(Long.valueOf(stationStatsRequest.getStationID()), stationStatsRequest.getStartTime(), stationStatsRequest.getEndTime());
            if(r.getCode() !=200){
                resp.setRet("-1");
                resp.setMsg("系统繁忙，此时请求方稍后重试");
                return resp;
            }
            String key ="cdjgpc:station:"+stationStatsRequest.getStationID()+".querySupEquipmentStatsInfo";
            List<CDSuqEquipmentStatslnfo> cdSuqEquipmentStatslnfos =REDIS.getCacheObject(key);
            Map<String,Object> mapStationInfo =new HashMap<>();
            mapStationInfo.put("EquipmentStatsInfos",cdSuqEquipmentStatslnfos);
            resp.setRet("0");
            resp.setData(JSONUtil.toJSONString(mapStationInfo));
            resp.setMsg("Query station info success");
            REDIS.deleteObject(key);
        }
        return resp;
    }

    /**
     * 查询充电设备接口运行统计计信息  --已调用
     * @param commonRequest
     * @return
     * @throws Exception
     */
    @PostMapping("/v10/query_connector_stats_info")
    public CommonResponse queryConnectorStatsInfo(@RequestBody CommonRequest<CDQuerySupEquipmentStatsInfoRequest> commonRequest)throws Exception{
        CommonResponse resp = new CommonResponse();
        resp.setRet(EvcsConst.RET_FAIL);
        CDQuerySupEquipmentStatsInfoRequest stationStatsRequest = JSONUtil.readParams(commonRequest.getData(), CDQuerySupEquipmentStatsInfoRequest.class);
        if (stationStatsRequest == null) {
            resp.setMsg("Request or token params validation failed");
            resp.setRet("4002");
        } else {
            R r = powerPileService.queryConnectorStatsInfo(Long.valueOf(stationStatsRequest.getStationID()), stationStatsRequest.getStartTime(), stationStatsRequest.getEndTime());
            if(r.getCode() !=200){
                resp.setRet("-1");
                resp.setMsg("系统繁忙，此时请求方稍后重试");
                return resp;
            }
            String key ="cdjgpc:station:"+stationStatsRequest.getStationID()+".queryConnectorStatsInfo";
            List<CDSupConnectorStatslnfo> cdSuqEquipmentStatslnfos =REDIS.getCacheObject(key);
            Map<String,Object> mapStationInfo =new HashMap<>();
            mapStationInfo.put("ConnectorStatsInfos",cdSuqEquipmentStatslnfos);
            resp.setRet("0");
            resp.setData(JSONUtil.toJSONString(mapStationInfo));
            resp.setMsg("Query station info success");
            REDIS.deleteObject(key);
        }
        return resp;
    }

    /**
     * 查询充电站功率统计信息  --已调用
     * @param commonRequest
     * @return
     * @throws Exception
     */
    @PostMapping("/v10/supervise_query_station_power_info")
    public CommonResponse superviseQueryStationPowerInfo(@RequestBody CommonRequest<CDSuperviseQueryStationPowerInfoRequest> commonRequest)throws Exception{

        CommonResponse resp = new CommonResponse();
        resp.setRet(EvcsConst.RET_FAIL);
        CDSuperviseQueryStationPowerInfoRequest stationStatsRequest = JSONUtil.readParams(commonRequest.getData(), CDSuperviseQueryStationPowerInfoRequest.class);
        if (stationStatsRequest == null) {
            resp.setMsg("Request or token params validation failed");
            resp.setRet("4002");
        } else {
            String replace = UUID.randomUUID().toString().replace("-", "");

            R r = powerPileService.getSuperviseQueryStationPowerInfo(stationStatsRequest.getStationIDs(), stationStatsRequest.getDataTime(),replace);
            if(r.getCode() !=200){
                resp.setRet("-1");
                resp.setMsg("系统繁忙，此时请求方稍后重试");
                return resp;
            }
            String key ="cdjgpc:station:"+replace+".getSuperviseQueryStationPowerInfo";
            List<CDSupStationPowerInfo> cdSuqEquipmentStatslnfos =REDIS.getCacheObject(key);
            Map<String,Object> mapStationInfo =new HashMap<>();
            mapStationInfo.put("StationPowerInfos",cdSuqEquipmentStatslnfos);
            resp.setRet("0");
            resp.setData(JSONUtil.toJSONString(mapStationInfo));
            resp.setMsg("Query station info success");
            REDIS.deleteObject(key);
        }
        return resp;
    }

    /**
     * 查询充电设备功率统计信息---一调用
     * @param commonRequest
     * @return
     * @throws Exception
     */
    @PostMapping("/v10/supervise_query_equipment_power_info")
    public CommonResponse superviseQueryEquipmentPowerInfo(@RequestBody CommonRequest<CDSuperviseQueryEquipmentPowerInfoRequest> commonRequest)throws Exception{

        CommonResponse resp = new CommonResponse();
        resp.setRet(EvcsConst.RET_FAIL);
        CDSuperviseQueryEquipmentPowerInfoRequest stationStatsRequest = JSONUtil.readParams(commonRequest.getData(), CDSuperviseQueryEquipmentPowerInfoRequest.class);
        if (stationStatsRequest == null) {
            resp.setMsg("Request or token params validation failed");
            resp.setRet("4002");
        } else {
            String replace = UUID.randomUUID().toString().replace("-", "");
            R r = powerPileService.getSuperviseQueryEquipmentPowerInfo(stationStatsRequest.getStationID(), stationStatsRequest.getDataTime(),replace);
            if(r.getCode() !=200){
                resp.setRet("-1");
                resp.setMsg("系统繁忙，此时请求方稍后重试");
                return resp;
            }

            String key ="cdjgpc:station:"+replace+".getSuperviseQueryEquipmentPowerInfo";
            List<CDSupEquipmentPowerInfo> cdSuqEquipmentStatslnfos =REDIS.getCacheObject(key);
            Map<String,Object> mapStationInfo =new HashMap<>();
            mapStationInfo.put("EquipmentPowerInfos",cdSuqEquipmentStatslnfos);
            resp.setRet("0");
            resp.setData(JSONUtil.toJSONString(mapStationInfo));
            resp.setMsg("Query station info success");
            REDIS.deleteObject(key);
        }
        return resp;
    }

    /**
     * 查询充电事故
     * @param commonRequest
     * @return
     * @throws Exception
     */
    @PostMapping("/v10/supervise_query_accident_info")
    public CommonResponse superviseQueryAccidentInfo(@RequestBody(required = false) CommonRequest<PageRequest> commonRequest)throws Exception {
        CommonResponse resp = new CommonResponse();
        resp.setRet(EvcsConst.RET_FAIL);

        //当前页数
        PageRequest pageRequest = commonRequest.transformDataType(PageRequest.class);
        Integer pageNo = pageRequest.getPageNo();
        CDSupEquipmentAccidentInfoResponse response = new CDSupEquipmentAccidentInfoResponse();
        response.setPageNo(pageNo);
        //页码总数
        Instant now = Instant.now();
        String replace = UUID.randomUUID().toString().replace("-", "");
        //获取事故数据
        R r = powerPileService.getSuperviseQueryAccidentInfo(pageRequest.getLastQueryTime(),replace);
        if(r.getCode() !=200){
            resp.setRet("-1");
            resp.setMsg("系统繁忙，此时请求方稍后重试");
            return resp;
        }
        String key ="cdjgpc:station:"+replace+".getSuperviseQueryAccidentInfo";
        List<CDSupEquipmentAccidentInfo> cdSupEquipmentAccidentInfos =REDIS.getCacheObject(key);

        List<CDSupEquipmentAccidentInfo> equipmentAccidentInfoList =new ArrayList<>();

        if (cdSupEquipmentAccidentInfos.size() > 0) {
            Integer pageSize = pageRequest.getPageSize();
            int totalPage = cdSupEquipmentAccidentInfos.size() % pageSize == 0 ? cdSupEquipmentAccidentInfos.size() / pageSize :
                    (cdSupEquipmentAccidentInfos.size() / pageSize) + 1;
            response.setPageCount(totalPage);
        }
        //总记录条数
        response.setItemSize(cdSupEquipmentAccidentInfos.size());

        //计算每页开始索引
        int startIndex = -1;
        int endIndex = -1;
        if (pageNo == 1 && cdSupEquipmentAccidentInfos.size() <= 10) {
            startIndex = 0;
            endIndex = cdSupEquipmentAccidentInfos.size() - 1;
        } else {
            Integer pageSize = pageRequest.getPageSize();
            startIndex = (pageNo - 1) * pageSize;
            endIndex = startIndex + (pageSize - 1);
        }
        for (int i = startIndex; i <= endIndex; i++) {
            CDSupEquipmentAccidentInfo cdSupEquipmentAccidentInfo = cdSupEquipmentAccidentInfos.get(i);
            String[] split = cdSupEquipmentAccidentInfo.getPicturesName().split(",");
            cdSupEquipmentAccidentInfo.setPictures(split);
            String[] split1 = cdSupEquipmentAccidentInfo.getAnalysisReportName().split(",");
            cdSupEquipmentAccidentInfo.setAnalysisReport(split1);
            equipmentAccidentInfoList.add(cdSupEquipmentAccidentInfo);
        }
        Map<String,Object> mapStationInfo =new HashMap<>();
        mapStationInfo.put("EquipmentAccidentInfos",equipmentAccidentInfoList);
        resp.setRet("0");
        resp.setData(JSONUtil.toJSONString(mapStationInfo));
        resp.setMsg("Query station info success");
        REDIS.deleteObject(key);
        return resp;
    }


        //组合场站数据
    public CDStationInfo getNotificationStationInfo(String stationId){

        String key = "cdjgpc:station:".concat(stationId)+".notification";
        CDStationInfo cdStationInfo = REDIS.getCacheObject(key);
        cdStationInfo.setEquipmentInfos(new ArrayList<>());
        //查询场站是桩是否对应上
        ChargingStationDto stationDto = REDIS.getCacheObject("station:"+stationId);
        Set<String> pks = stationDto.getPiles();
        if (pks != null) {
            List<CDEquipmentInfo> cdEquipmentInfos = new ArrayList<>();
            for (String pileNo : pks) {
                String pk = "pile:".concat(pileNo);
                String skey = "cdjgpc:".concat(pk) + ".notification";
                CDEquipmentInfo cdEquipmentInfo = REDIS.getCacheObject(skey);
                cdEquipmentInfos.add(cdEquipmentInfo);
            }
            cdStationInfo.setEquipmentInfos(cdEquipmentInfos);
            REDIS.setCacheObject(key, cdStationInfo);
        }
        return cdStationInfo;
    }


    /**
     * 需求通知推送
     * @param commonRequest
     * @return
     * @throws Exception
     */
    @PostMapping("/v10/notification_requirement")
    public CommonResponse notificationRequirement(@RequestBody(required = false) CommonRequest<CDRequirementInfo> commonRequest)throws Exception {
        CommonResponse resp = new CommonResponse();
        resp.setRet(EvcsConst.RET_FAIL);
        CDRequirementInfo cdRequirementInfo = JSONUtil.readParams(commonRequest.getData(), CDRequirementInfo.class);
        if (cdRequirementInfo == null) {
            resp.setMsg("Request or token params validation failed");
            resp.setRet("4002");
        } else {
            List<CDRequirementInfoList> list = cdRequirementInfo.getList();
            List<Map<String,String>> mapList =new ArrayList<>();
            for (int i = 0; i < list.size(); i++) {
                CDRequirementInfoList cdRequirementInfoList = list.get(i);
                Map<String,String> map =new HashMap<>();
                map.put("startTime",cdRequirementInfoList.getStartTime());
                map.put("endTime",cdRequirementInfoList.getEndTime());
                map.put("res",cdRequirementInfoList.getRes().toString());
                mapList.add(map);
            }
            String name="";
            if(!"".equals(cdRequirementInfo.getName()) || cdRequirementInfo.getName() !=null){
                name =cdRequirementInfo.getName();
            }
            String area="";
            if(!"".equals(cdRequirementInfo.getArea()) || cdRequirementInfo.getArea() !=null){
                area =cdRequirementInfo.getArea();
            }
            String code="";
            if(!"".equals(cdRequirementInfo.getCode()) || cdRequirementInfo.getCode() !=null){
                code =cdRequirementInfo.getCode();
            }
            String requireDate="";
            if(!"".equals(cdRequirementInfo.getRequireDate()) || cdRequirementInfo.getRequireDate() !=null){
                requireDate =cdRequirementInfo.getRequireDate();
            }
            String releaseTime="";
            if(!"".equals(cdRequirementInfo.getReleaseTime()) || cdRequirementInfo.getReleaseTime() !=null){
                releaseTime =cdRequirementInfo.getReleaseTime();
            }
            String deliveryTime="";
            if(!"".equals(cdRequirementInfo.getDeliveryTime()) || cdRequirementInfo.getDeliveryTime() !=null){
                deliveryTime =cdRequirementInfo.getDeliveryTime();
            }
            String dataYu = JSONUtil.toJSONString(mapList);

            R r = chargingStationService.addRequirementInfo(name, area, code, dataYu, requireDate,releaseTime, deliveryTime);
            if(r.getCode()==200){
                resp.setMsg("已接收数据");
                resp.setRet("0");
            }else{
                resp.setRet("-1");
                resp.setMsg("系统繁忙，此时请求方稍后重试");
            }
        }
        return resp;
    }

    /**
     * 需求通知推送
     * @param commonRequest
     * @return
     * @throws Exception
     */
    @PostMapping("/v10/notification_task")
    public CommonResponse  notificationTask(@RequestBody(required = false) CommonRequest<CDTaskInfo> commonRequest)throws Exception {
        CommonResponse resp = new CommonResponse();
        resp.setRet(EvcsConst.RET_FAIL);
        CDTaskInfo cdTaskInfo = JSONUtil.readParams(commonRequest.getData(), CDTaskInfo.class);
        if (cdTaskInfo == null) {
            resp.setMsg("Request or token params validation failed");
            resp.setRet("4002");
        } else {

            List<CDRequirementInfoList> list = cdTaskInfo.getList();
            List<Map<String,String>> mapList =new ArrayList<>();
            for (int i = 0; i < list.size(); i++) {
                CDRequirementInfoList cdRequirementInfoList = list.get(i);
                Map<String,String> map =new HashMap<>();
                map.put("startTime",cdRequirementInfoList.getStartTime());
                map.put("endTime",cdRequirementInfoList.getEndTime());
                map.put("res",cdRequirementInfoList.getRes().toString());
                mapList.add(map);
            }
            String dataYu = JSONUtil.toJSONString(mapList);
            R r = chargingStationService.addNotificationTask(cdTaskInfo.getTaskName(), cdTaskInfo.getTaskCode(), cdTaskInfo.getDemandDate(), cdTaskInfo.getStationID(), cdTaskInfo.getOperatorID(), cdTaskInfo.getEquipmentOwnerID(), cdTaskInfo.getEleNo(),dataYu,cdTaskInfo.getDeliveryTime());
            if(r.getCode()==200){
                resp.setMsg("已接收数据");
                resp.setRet("0");
            }else{
                resp.setRet("-1");
                resp.setMsg("系统繁忙，此时请求方稍后重试");
            }
        }
        return resp;
    }





    //数据加密处理
    @PostMapping("/v10/getEncrytReqout")
    public R getEncrytReqout(){
        try{
//            CommonRequest<StationStatusRequest> commonRequest = new CommonRequest<>();
//            commonRequest.setOperatorId("MA6CC2LK7");
//            StationStatsRequest stationStatsRequest = new StationStatsRequest();
//            stationStatsRequest.setStationID("20");
//            stationStatsRequest.setStartTime("2023-10-01");
//            stationStatsRequest.setEndTime("2023-10-12");
//            StationStatusRequest stationStatsRequest =new StationStatusRequest();
//            String [] st ={"20"};
//            stationStatsRequest.setStationIds(st);

//            CDQuerySupEquipmentStatsInfoRequest cdQuerySupEquipmentStatsInfoRequest = new CDQuerySupEquipmentStatsInfoRequest();
//            cdQuerySupEquipmentStatsInfoRequest.setStationID("20");
//            cdQuerySupEquipmentStatsInfoRequest.setStartTime("2023-10-01");
//            cdQuerySupEquipmentStatsInfoRequest.setEndTime("2023-10-13");

//            CDSuperviseQueryStationPowerInfoRequest cdSuperviseQueryStationPowerInfoRequest = new CDSuperviseQueryStationPowerInfoRequest();
//            String [] st ={"20"};
//            cdSuperviseQueryStationPowerInfoRequest.setStationIDs(st);
//            cdSuperviseQueryStationPowerInfoRequest.setDataTime("2023-10-13");

//            CDSuperviseQueryEquipmentPowerInfoRequest cdSuperviseQueryEquipmentPowerInfoRequest = new CDSuperviseQueryEquipmentPowerInfoRequest();
//            cdSuperviseQueryEquipmentPowerInfoRequest.setStationID("20");
//            cdSuperviseQueryEquipmentPowerInfoRequest.setDataTime("2023-10-13");
//            CDEquipAuthRequest equipAuthRequest = new CDEquipAuthRequest();
//            equipAuthRequest.setEquipAuthSeq("MA6DFCTD5202310161544441234");
//            equipAuthRequest.setConnectorId("8083600020000101");
//            equipAuthRequest.setQRCode("12312312312323");


//            String data = JSONUtil.toJSONString(equipAuthRequest);
//            System.out.println("===data==="+data);
//            commonRequest.setData(data);
//            AuthSecretToken authSecretTokenOut =authSecretTokenRepository.findByOperatorId3irdptyAndOperatorIdAndSecretTokenType(
//                            "MA6CC2LK7", "MA6DFCTD5", SECRET_TOKEN_TYPE_IN).orElse(null);
//            String tData = encryptReqOut(authSecretTokenOut.getDataSecret(), authSecretTokenOut.getDataSecretIV(),
//                    authSecretTokenOut.getSigSecret(), commonRequest);
//            System.out.println("===tData==="+tData);

//            CommonRequest<EquipBizRequest> commonRequest = new CommonRequest<>();
//
//            EquipBizRequest equipBizRequest =new EquipBizRequest();
//            equipBizRequest.setEquipBizSeq("MA25CNM3800000");
//            equipBizRequest.setConnectorId("8083600001000801");
//             Map<String,Object> map =new HashMap<>();
//             map.put("PageNo","1");
//             map.put("PageSize","10");
//            String data = JSONUtil.toJSONString(equipBizRequest);
//
//            String data111 = Aes128Cbc.encrypt(data, "8LpncubmWiPCzY3V", "av6A8QdnRaVRMXu6");
//            commonRequest.setData(data);
//            commonRequest.setOperatorId("MA25CNM38");
//            AuthSecretToken authSecretTokenOut =authSecretTokenRepository.findByOperatorId3irdptyAndOperatorIdAndSecretTokenType(
//                            "MA25CNM38", "MA6DFCTD5", SECRET_TOKEN_TYPE_IN).orElse(null);
//
//            String result = okYu(commonRequest, "/query_stations_info", authSecretTokenOut,"MA25CNM38");
//
//
//            System.out.println("==========result=============="+result);


            String rawData = "NR0oe4La+0SLizVoKCDfRkj37avo59qzZBUm7BFSmU+XA81uaP2614Vjbb7VvhRRumS4LwHu6CR981cKMxNM5xCGT+yjGgDwRG4B6xnEJ9upiW7iathKmMrN3lZBkvzstkKcx502kVSMy4x82RBkHXmS6nTFnfwbX1jI706L3pUvmNTtrYMH2Qvi6IOgG7AX/uhMVsvDOHZAAb5o66c/DfkfZBkWHSVWfmlgkwzuwkdktJQJOwOTM25jXotML7hLi0n7HPfmWPlpmye/cn/KVRBiUjxlvINzTIoz3dXw3SlV0zJC72zVd9I/cD2WBkFM53WmsPIDARGSGlj22rNVRx6fhff1CzmTP/NovUXiaNWb1F9PsVHluOUVZZ2x571jbHbc5+SR1JHu2NT5zNIzlk4HPfx0/eXjSBhtAsutnow9O5fDkSb/pa1gNkB3n6DMnJnyLuqFazUiYcqVPQlyl2J0EsMafQAbkNLeGr3tuNEEsywzWIeP35EceedIC2msRqTWkC02cXStCMlG5pVDyKFQe7pmT7LSXw8OGk348W43TGN0VTAhufvz5SeHAmVsoGgzvL7bCekPVhI3mC778Wa2Bag6tnV6xkEi40dlTwvVRD/0ycZ9XxEuOhlji3NMtOdECoE8YJSyN5FfN4253+xthr1UXCORShasYJLs00MByWL0H9wUFEHG7o/ZLJV8QVibfAF8qGF997UJsdieyGWQHjltFwCRUGp1St+lskZa8LCNI8TlUtf2ti5GfjIXfN5YXTgVK5DFBNe4wrw+n4+v17TBUIESwOmLnXqwE9IePQAY5gASYA5rfQfCvL1qCvvqM6/ccPxg3hFmQzoL4b9Jnx5OGCvy42dn8TXkQMm2ngJBd6av2+F5cNKe4ABw";
            String dataSecret="8LpncubmWiPCzY3V";
            String dataSecretIV="av6A8QdnRaVRMXu6";
           String data =  Aes128Cbc.encrypt(rawData, dataSecret, dataSecretIV);

            System.out.println("========解密==data=============="+data);

        }catch (Exception e){
            e.printStackTrace();
        }
       return R.fail();
    }

    private String getTime(Integer number){
        String time ="";
        if(number ==0){
            time ="00:00:00-00:30:00:";
        }else if(number ==1) {
            time = "00:30:00-01:00:00:";
        }else if(number ==2) {
            time = "01:00:00-01:30:00:";
        }else if(number ==3) {
            time = "01:30:00-02:00:00:";
        }else if(number ==4) {
            time = "02:00:00-02:30:00:";
        }else if(number ==5) {
            time = "02:30:00-03:00:00:";
        }else if(number ==6) {
            time = "03:00:00-03:30:00:";
        }else if(number ==7) {
            time = "03:30:00-04:00:00:";
        }else if(number ==8) {
            time = "04:00:00-04:30:00:";
        }else if(number ==9) {
            time = "04:30:00-05:00:00:";
        }else if(number ==10) {
            time = "05:00:00-05:30:00:";
        }else if(number ==11) {
            time = "05:30:00-06:00:00:";
        }else if(number ==12) {
            time = "06:00:00-06:30:00:";
        }else if(number ==13) {
            time = "06:30:00-07:00:00:";
        }else if(number ==14) {
            time = "07:00:00-07:30:00:";
        }else if(number ==15) {
            time = "07:30:00-08:00:00:";
        }else if(number ==16) {
            time = "08:00:00-08:30:00:";
        }else if(number ==17) {
            time = "08:30:00-09:00:00:";
        }else if(number ==18) {
            time = "09:00:00-09:30:00:";
        }else if(number ==19) {
            time = "09:30:00-10:00:00:";
        }else if(number ==20) {
            time = "10:00:00-10:30:00:";
        }else if(number ==21) {
            time = "10:30:00-11:00:00:";
        }else if(number ==22) {
            time = "11:00:00-11:30:00:";
        }else if(number ==23) {
            time = "11:30:00-12:00:00:";
        }else if(number ==24) {
            time = "12:00:00-12:30:00:";
        }else if(number ==25) {
            time = "12:30:00-13:00:00:";
        }else if(number ==26) {
            time = "13:00:00-13:30:00:";
        }else if(number ==27) {
            time = "13:30:00-14:00:00:";
        }else if(number ==28) {
            time = "14:00:00-14:30:00:";
        }else if(number ==29) {
            time = "14:30:00-15:00:00:";
        }else if(number ==30){
            time ="15:00:00-15:30:00:";
        }else if(number ==31) {
            time = "15:30:00-16:00:00:";
        }else if(number ==32) {
            time = "16:00:00-16:30:00:";
        }else if(number ==33) {
            time = "16:30:00-17:00:00:";
        }else if(number ==34) {
            time = "17:00:00-17:30:00:";
        }else if(number ==35) {
            time = "17:30:00-18:00:00:";
        }else if(number ==36) {
            time = "18:00:00-18:30:00:";
        }else if(number ==37) {
            time = "18:30:00-19:00:00:";
        }else if(number ==38) {
            time = "19:00:00-19:30:00:";
        }else if(number ==39) {
            time = "19:30:00-20:00:00:";
        }else if(number ==40){
            time ="20:00:00-20:30:00:";
        }else if(number ==41) {
            time = "20:30:00-21:00:00:";
        }else if(number ==42) {
            time = "21:00:00-21:30:00:";
        }else if(number ==43) {
            time = "21:30:00-22:00:00";
        }else if(number ==44) {
            time = "22:00:00-22:30:00:";
        }else if(number ==45) {
            time = "22:30:00-23:00:00:";
        }else if(number ==46) {
            time = "23:00:00-23:30:00";
        }else if(number ==47) {
            time = "23:30:00-24:00:00:";
        }
        return time;
    }
}
