package com.xhpc.order.service.impl;

import cn.hutool.core.date.DateUtil;
import com.xhpc.common.core.utils.SecurityUtils;
import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.common.redis.service.RedisService;
import com.xhpc.common.security.service.TokenService;
import com.xhpc.common.util.UserTypeUtil;
import com.xhpc.order.domain.XhpcInspection;
import com.xhpc.order.mapper.XhpcInspectionMapper;
import com.xhpc.order.service.IXhpcInspectionService;
import com.xhpc.system.api.domain.SysUser;
import com.xhpc.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.*;

@Service
public class XhpcInspectionServiceImpl implements IXhpcInspectionService {

    @Autowired
    private XhpcInspectionMapper xhpcInspectionMapper;
    @Autowired
    private TokenService tokenService;
    @Autowired
    private RedisService redisService;


    @Override
    public Map<String, Object> getInspectionList(Long stationId, String time) {
        String today = DateUtil.today();
        Map<String, Object> map =new HashMap<>();
        List<Map<String, Object>> list =new ArrayList<>();
        if(time==null || "".equals(time)){
            list = xhpcInspectionMapper.getInspectionList(stationId, today);
            //单独获取整体场站数据
            Map<String, Object> zt = xhpcInspectionMapper.getInspectionZTList(stationId, today);
            map.put("ZT",zt);
            map.put("data",list);
        }else{
            list = xhpcInspectionMapper.getInspectionList(stationId, time);
            Map<String, Object> zt = xhpcInspectionMapper.getInspectionZTList(stationId, time);
            map.put("ZT",zt);
            map.put("data",list);
        }
        return map;
    }

    @Override
    public void timing() {
        List<Map<String, Object>> list = xhpcInspectionMapper.getChargingStationList(0,null,"000000");
        for (int k = 0; k <list.size() ; k++) {
            Map<String, Object> stringMap = list.get(k);
            Long stationId = Long.valueOf(stringMap.get("stationId").toString());
            //查询没有删除的场站，进行生成每日巡检任务
            List<Map<String, Object>> mapList = xhpcInspectionMapper.getInspectionChargingStation(stationId);
            for (int i = 0; i <mapList.size() ; i++) {
                Map<String, Object> map = mapList.get(i);
                String today = DateUtil.today();
                Long chargingStationId = Long.valueOf(map.get("chargingStationId").toString());
                Long terminalId = Long.valueOf(map.get("terminalId").toString());
                if(i==0){

                    XhpcInspection xhpcInspection6 = new XhpcInspection();
                    xhpcInspection6.setName("场站整体照片");
                    xhpcInspection6.setTerminalId(terminalId);
                    xhpcInspection6.setChargingStationId(chargingStationId);
                    xhpcInspection6.setStatus(0);
                    xhpcInspection6.setType(7);
                    xhpcInspection6.setDataTime(today);
                    xhpcInspection6.setCreateTime(new Date());
                    xhpcInspection6.setTenantId("000000");
                    xhpcInspectionMapper.installInspection(xhpcInspection6);

                    XhpcInspection xhpcInspection = new XhpcInspection();
                    xhpcInspection.setName("箱变");
                    xhpcInspection.setChargingStationId(chargingStationId);
                    xhpcInspection.setTerminalId(terminalId);
                    xhpcInspection.setStatus(0);
                    xhpcInspection.setType(1);
                    xhpcInspection.setDataTime(today);
                    xhpcInspection.setCreateTime(new Date());
                    xhpcInspection.setTenantId("000000");
                    xhpcInspectionMapper.installInspection(xhpcInspection);

                    XhpcInspection xhpcInspection1 = new XhpcInspection();
                    xhpcInspection1.setName("监控");
                    xhpcInspection1.setTerminalId(terminalId);
                    xhpcInspection1.setChargingStationId(chargingStationId);
                    xhpcInspection1.setStatus(0);
                    xhpcInspection1.setType(2);
                    xhpcInspection1.setDataTime(today);
                    xhpcInspection1.setCreateTime(new Date());
                    xhpcInspection1.setTenantId("000000");
                    xhpcInspectionMapper.installInspection(xhpcInspection1);

                    XhpcInspection xhpcInspection2 = new XhpcInspection();
                    xhpcInspection2.setName("道闸");
                    xhpcInspection2.setTerminalId(terminalId);
                    xhpcInspection2.setChargingStationId(chargingStationId);
                    xhpcInspection2.setStatus(0);
                    xhpcInspection2.setType(3);
                    xhpcInspection2.setDataTime(today);
                    xhpcInspection2.setCreateTime(new Date());
                    xhpcInspection2.setTenantId("000000");
                    xhpcInspectionMapper.installInspection(xhpcInspection2);

                    XhpcInspection xhpcInspection3 = new XhpcInspection();
                    xhpcInspection3.setName("远程连接");
                    xhpcInspection3.setTerminalId(terminalId);
                    xhpcInspection3.setChargingStationId(chargingStationId);
                    xhpcInspection3.setStatus(0);
                    xhpcInspection3.setType(4);
                    xhpcInspection3.setDataTime(today);
                    xhpcInspection3.setCreateTime(new Date());
                    xhpcInspection3.setTenantId("000000");
                    xhpcInspectionMapper.installInspection(xhpcInspection3);

                    XhpcInspection xhpcInspection4 = new XhpcInspection();
                    xhpcInspection4.setName("消防设备");
                    xhpcInspection4.setTerminalId(terminalId);
                    xhpcInspection4.setChargingStationId(chargingStationId);
                    xhpcInspection4.setStatus(0);
                    xhpcInspection4.setType(5);
                    xhpcInspection4.setDataTime(today);
                    xhpcInspection4.setCreateTime(new Date());
                    xhpcInspection4.setTenantId("000000");
                    xhpcInspectionMapper.installInspection(xhpcInspection4);

                    XhpcInspection xhpcInspection5 = new XhpcInspection();
                    xhpcInspection5.setName("车档及防撞杆");
                    xhpcInspection5.setTerminalId(terminalId);
                    xhpcInspection5.setChargingStationId(chargingStationId);
                    xhpcInspection5.setStatus(0);
                    xhpcInspection5.setType(6);
                    xhpcInspection5.setDataTime(today);
                    xhpcInspection5.setCreateTime(new Date());
                    xhpcInspection5.setTenantId("000000");
                    xhpcInspectionMapper.installInspection(xhpcInspection5);

                }
                XhpcInspection xhpcInspection = new XhpcInspection();
                xhpcInspection.setName(map.get("name").toString());
                xhpcInspection.setChargingStationId(chargingStationId);
                xhpcInspection.setTerminalId(terminalId);
                xhpcInspection.setCreateTime(new Date());
                xhpcInspection.setTenantId("000000");
                String statusY = map.get("status").toString();
                if("0".equals(statusY)){
                    xhpcInspection.setStatus(0);
                }else{
                    xhpcInspection.setStatus(3);
                    if(map.get("prompt")!=null){
                        xhpcInspection.setErrorName(map.get("prompt").toString());
                    }
                }
                xhpcInspection.setType(0);
                xhpcInspection.setDataTime(today);
                xhpcInspectionMapper.installInspection(xhpcInspection);
            }
        }
    }

    @Override
    public AjaxResult getInspectionById(Long stationId, String id,Long inspectionId) {
        //'0 桩 1箱变 2监控 3道闸 4 远程连接'
        int type =0;
        if(id.equals("XB")){
            type=1;
        }else if(id.equals("DZ")){
            type=3;
        }else if(id.equals("JK")){
            type=2;
        }else if(id.equals("YC")){
            type=4;
        }else if(id.equals("XF")){
            type=5;
        }else if(id.equals("CD")){
            type=6;
        }else if(id.equals("ZT")){
            type=7;
        }

        Map<String, Object> map =xhpcInspectionMapper.getInspectionById(stationId,inspectionId,type);
        return AjaxResult.success(map);

    }

    @Override
    public AjaxResult addInspection(HttpServletRequest request, XhpcInspection xhpcInspection) {

        LoginUser loginUser = tokenService.getLoginUser(request);

        XhpcInspection xhpcInspection1 = xhpcInspectionMapper.getXhpcInspectionById(xhpcInspection.getInspectionId());
        if(xhpcInspection1 !=null && xhpcInspection1.getType()==7){
            //所有type!=7相同场站和时间，没有巡检的变成已巡检
            xhpcInspectionMapper.updateXhpcInspectionType(xhpcInspection1.getChargingStationId(),xhpcInspection1.getDataTime());
        }
        xhpcInspection.setUserId(loginUser.getUserid());
        xhpcInspectionMapper.updateInspection(xhpcInspection);
        return AjaxResult.success();
    }

    @Override
    public List<Map<String, Object>> getStationList(HttpServletRequest request) {


        Date startTime1 = DateUtil.beginOfDay(new Date());
        String startTime = DateUtil.format(startTime1,"yyyy-MM-dd HH:mm:ss");
        //一天的结束，结果：2017-03-01 23:59:59
        Date endTime1 = DateUtil.endOfDay(new Date());
        String endTime = DateUtil.format(endTime1,"yyyy-MM-dd HH:mm:ss");
        Long chargingStationId =null;
        //判断登录用户是系统用户还是运维人员
        LoginUser loginUser = tokenService.getLoginUser(request);

        String tenantId = loginUser.getTenantId();
        Long logUserId = SecurityUtils.getUserId();
        SysUser sysUser = loginUser.getSysUser();
        List<Map<String, Object>> mapList =new ArrayList<>();
        System.out.println("======111================");
        if(tenantId !=null && !"".equals(tenantId)){
            if(sysUser.getUserId() !=UserTypeUtil.USER_ID){
                Long logOperatorId = sysUser.getOperatorId();
                if ("01".equals(sysUser.getUserType())) {
                    mapList= xhpcInspectionMapper.getChargingStationEmptyOrder(1,logOperatorId,tenantId,startTime,endTime);
                }else{
                    System.out.println("======222================");
                    mapList= xhpcInspectionMapper.getChargingStationEmptyOrder(2,logUserId,tenantId,startTime,endTime);
                }
            }else{
                mapList= xhpcInspectionMapper.getChargingStationEmptyOrder(0,null,tenantId,startTime,endTime);
            }
        }
        //桩的状态
        for (int j = 0; j < mapList.size(); j++) {
            Map<String, Object> objectMap = mapList.get(j);
            Long stationId = Long.valueOf(objectMap.get("stationId").toString());
            List<Map<String, Object>> list = xhpcInspectionMapper.getWXXhpcTerminalMassage(stationId);
            int normal=0;
            int offline=0;
            int fault=0;
            int unknown=0;
            if (list != null && list.size() > 0) {
                for (int i = 0; i < list.size(); i++) {
                    Map<String, Object> map = list.get(i);
                    //终端状态用 redis数据
                    if(map.get("serialNumber") !=null){
                        Map<String, Object> cacheMap =redisService.getCacheMap("gun:"+map.get("serialNumber").toString());
                        if(!cacheMap.isEmpty()){
                            if ("离线".equals(cacheMap.get("status").toString())){
                                offline++;
                            }else if("故障".equals(cacheMap.get("status").toString())){
                                fault++;
                            }else if("空闲".equals(cacheMap.get("status").toString()) || "插枪".equals(cacheMap.get("status").toString())){
                                normal++;
                            }else{
                                normal++;
                            }
                        }else{
                            unknown++;
                        }
                    }else{
                        unknown++;
                    }
                }
            }
            objectMap.put("normal", normal);
            objectMap.put("offline", offline);
            objectMap.put("fault", fault);
            objectMap.put("unknown", unknown);

            if(tenantId !=null && !"".equals(tenantId)){
                if(sysUser.getUserId() !=UserTypeUtil.USER_ID){
                    Long logOperatorId = sysUser.getOperatorId();
                    if ("01".equals(sysUser.getUserType())) {
                        String today = DateUtil.today();
                        Map<String, Object> todayOrderMap = xhpcInspectionMapper.getChargingStationOrder(today,1,logOperatorId,tenantId,stationId);
                        objectMap.putAll(todayOrderMap);
                    }else{
                        String today = DateUtil.today();
                        Map<String, Object> todayOrderMap = xhpcInspectionMapper.getChargingStationOrder(today,2,logOperatorId,tenantId,stationId);
                        objectMap.putAll(todayOrderMap);
                    }
                }else{
                    String today = DateUtil.today();
                    Map<String, Object> todayOrderMap = xhpcInspectionMapper.getChargingStationOrder(today,0,null,tenantId,stationId);
                    objectMap.putAll(todayOrderMap);
                }
            }
        }
        return mapList;
    }

    @Override
    public List<Map<String, Object>> getInspectionUserList(HttpServletRequest request) {
        LoginUser loginUser = tokenService.getLoginUser(request);
        Long logUserId = loginUser.getUserid();
        List<Map<String, Object>> inspectionUserList = xhpcInspectionMapper.getInspectionUserList(logUserId);
        return inspectionUserList;
    }

    @Override
    public Map<String, Object> getDataBoard(HttpServletRequest request) {


        LoginUser loginUser = tokenService.getLoginUser(request);
        Map<String, Object> map1 = new HashMap<>();
        if(loginUser==null){
            map1.put("stationSum",0);
            map1.put("abnormalStation",0);
            map1.put("todayOrder",0);
            map1.put("emptyOrderRate",0);
            map1.put("completionRate",0);
            map1.put("onlineRate","0%");
            System.out.println("======4444================");
            return map1;
        }

        String tenantId = loginUser.getTenantId();
        Long logUserId = SecurityUtils.getUserId();
        SysUser sysUser = loginUser.getSysUser();
        if(tenantId !=null && !"".equals(tenantId)){
                //单个场站空订单率
                if(sysUser.getUserId() !=UserTypeUtil.USER_ID){
                    Long logOperatorId = sysUser.getOperatorId();
                    if ("01".equals(sysUser.getUserType())) {
                        //运营商看自己的场站
                        int stationSum = xhpcInspectionMapper.stationSum(1,logOperatorId,tenantId);
                        map1.put("stationSum",stationSum);

                        String today = DateUtil.today();
                        Integer abnormalStation = xhpcInspectionMapper.abnormalStation(today,1,logOperatorId,tenantId);
                        if(abnormalStation==null){
                            map1.put("abnormalStation",0);
                        }else{
                            map1.put("abnormalStation",abnormalStation);
                        }
                        Map<String, Object> todayOrderMap = xhpcInspectionMapper.todayOrder(today,1,logOperatorId,tenantId);

                        int todayOrder = Integer.valueOf(todayOrderMap.get("todayOrder").toString());
                        map1.put("todayOrder",todayOrder);
                        map1.put("actPowerPrice",new BigDecimal(todayOrderMap.get("actPowerPrice").toString()));
                        map1.put("actServicePrice",new BigDecimal(todayOrderMap.get("actServicePrice").toString()));
                        map1.put("actTotalPrice",new BigDecimal(todayOrderMap.get("actTotalPrice").toString()));
                        map1.put("totalPower",new BigDecimal(todayOrderMap.get("totalPower").toString()));
                        int emptyOrderRate = xhpcInspectionMapper.emptyOrderRate(today,1,logOperatorId,tenantId);
                        if(emptyOrderRate==0){
                            map1.put("emptyOrderRate",0);
                        }else{
                            double result = (double) todayOrder / emptyOrderRate;
                            String formatted = String.format("%.2f", result);
                            map1.put("emptyOrderRate",formatted);
                        }
                        String completionRate = xhpcInspectionMapper.completionRate(today,1,logOperatorId,tenantId);
                        map1.put("completionRate",completionRate);

                        List<Map<String, Object>> mapList = xhpcInspectionMapper.getChargingStationList(1,logOperatorId,tenantId);
                        int normal=0;
                        for (int j = 0; j < mapList.size(); j++) {
                            Map<String, Object> objectMap = mapList.get(j);
                            Long stationId = Long.valueOf(objectMap.get("stationId").toString());
                            List<Map<String, Object>> list = xhpcInspectionMapper.getWXXhpcTerminalMassage(stationId);
                            if (list != null && list.size() > 0) {
                                for (int i = 0; i < list.size(); i++) {
                                    Map<String, Object> map = list.get(i);
                                    //终端状态用 redis数据
                                    if(map.get("serialNumber") !=null){
                                        Map<String, Object> cacheMap =redisService.getCacheMap("gun:"+map.get("serialNumber").toString());
                                        if(!cacheMap.isEmpty()){
                                            if ("离线".equals(cacheMap.get("status").toString())){
                                            }else if("故障".equals(cacheMap.get("status").toString())){
                                            }else if("空闲".equals(cacheMap.get("status").toString()) || "插枪".equals(cacheMap.get("status").toString())){
                                                normal++;
                                            }else{
                                                normal++;
                                            }
                                        }else{

                                        }
                                    }else{
                                    }
                                }
                            }
                        }

                        BigDecimal bigDecimal = xhpcInspectionMapper.onlineRate(normal,1,logOperatorId,tenantId);
                        map1.put("onlineRate",bigDecimal+"%");
                    }else{
                        System.out.println("======5555================");
                        //场站总数量
                        int stationSum = xhpcInspectionMapper.stationSum(2,logUserId,tenantId);
                        map1.put("stationSum",stationSum);
                        String today = DateUtil.today();
                        Integer abnormalStation = xhpcInspectionMapper.abnormalStation(today,2,logOperatorId,tenantId);
                        if(abnormalStation==null){
                            map1.put("abnormalStation",0);
                        }else{
                            map1.put("abnormalStation",abnormalStation);
                        }
                        Map<String, Object> todayOrderMap =  xhpcInspectionMapper.todayOrder(today,2,logOperatorId,tenantId);
                        int todayOrder = Integer.valueOf(todayOrderMap.get("todayOrder").toString());
                        map1.put("todayOrder",todayOrder);
                        map1.put("actPowerPrice",new BigDecimal(todayOrderMap.get("actPowerPrice").toString()));
                        map1.put("actServicePrice",new BigDecimal(todayOrderMap.get("actServicePrice").toString()));
                        map1.put("actTotalPrice",new BigDecimal(todayOrderMap.get("actTotalPrice").toString()));
                        map1.put("totalPower",new BigDecimal(todayOrderMap.get("totalPower").toString()));

                        int emptyOrderRate = xhpcInspectionMapper.emptyOrderRate(today,2,logOperatorId,tenantId);
                        if(emptyOrderRate==0){
                            map1.put("emptyOrderRate",0);
                        }else{
                            double result = (double) todayOrder / emptyOrderRate;
                            String formatted = String.format("%.2f", result);
                            map1.put("emptyOrderRate",formatted);
                        }
                        String completionRate = xhpcInspectionMapper.completionRate(today,2,logOperatorId,tenantId);
                        map1.put("completionRate",completionRate);

                        List<Map<String, Object>> mapList = xhpcInspectionMapper.getChargingStationList(2,logOperatorId,tenantId);
                        int normal=0;
                        for (int j = 0; j < mapList.size(); j++) {
                            Map<String, Object> objectMap = mapList.get(j);
                            Long stationId = Long.valueOf(objectMap.get("stationId").toString());
                            List<Map<String, Object>> list = xhpcInspectionMapper.getWXXhpcTerminalMassage(stationId);
                            if (list != null && list.size() > 0) {
                                for (int i = 0; i < list.size(); i++) {
                                    Map<String, Object> map = list.get(i);
                                    //终端状态用 redis数据
                                    if(map.get("serialNumber") !=null){
                                        Map<String, Object> cacheMap =redisService.getCacheMap("gun:"+map.get("serialNumber").toString());
                                        if(!cacheMap.isEmpty()){
                                            if ("离线".equals(cacheMap.get("status").toString())){
                                            }else if("故障".equals(cacheMap.get("status").toString())){
                                            }else if("空闲".equals(cacheMap.get("status").toString()) || "插枪".equals(cacheMap.get("status").toString())){
                                                normal++;
                                            }else{
                                                normal++;
                                            }
                                        }else{

                                        }
                                    }else{
                                    }
                                }
                            }
                        }

                        BigDecimal bigDecimal = xhpcInspectionMapper.onlineRate(normal,2,logOperatorId,tenantId);
                        map1.put("onlineRate",bigDecimal+"%");

                    }
                }else{
                    //全部桩
                    int stationSum = xhpcInspectionMapper.stationSum(0,null,tenantId);
                    map1.put("stationSum",stationSum);
                    String today = DateUtil.today();
                    Integer abnormalStation = xhpcInspectionMapper.abnormalStation(today,0,null,tenantId);
                    if(abnormalStation==null){
                        map1.put("abnormalStation",0);
                    }else{
                        map1.put("abnormalStation",abnormalStation);
                    }
                    Map<String, Object> todayOrderMap =  xhpcInspectionMapper.todayOrder(today,0,null,tenantId);
                    int todayOrder = Integer.valueOf(todayOrderMap.get("todayOrder").toString());
                    map1.put("todayOrder",todayOrder);
                    map1.put("actPowerPrice",new BigDecimal(todayOrderMap.get("actPowerPrice").toString()));
                    map1.put("actServicePrice",new BigDecimal(todayOrderMap.get("actServicePrice").toString()));
                    map1.put("actTotalPrice",new BigDecimal(todayOrderMap.get("actTotalPrice").toString()));
                    map1.put("totalPower",new BigDecimal(todayOrderMap.get("totalPower").toString()));

                    int emptyOrderRate = xhpcInspectionMapper.emptyOrderRate(today,0,null,tenantId);
                    if(emptyOrderRate==0){
                        map1.put("emptyOrderRate",0);
                    }else{
                        double result = (double) todayOrder / emptyOrderRate;
                        String formatted = String.format("%.2f", result);
                        map1.put("emptyOrderRate",formatted);
                    }
                    String completionRate = xhpcInspectionMapper.completionRate(today,0,null,tenantId);
                    map1.put("completionRate",completionRate);

                    List<Map<String, Object>> mapList = xhpcInspectionMapper.getChargingStationList(0,null,tenantId);
                    int normal=0;
                    for (int j = 0; j < mapList.size(); j++) {
                        Map<String, Object> objectMap = mapList.get(j);
                        Long stationId = Long.valueOf(objectMap.get("stationId").toString());
                        List<Map<String, Object>> list = xhpcInspectionMapper.getWXXhpcTerminalMassage(stationId);
                        if (list != null && list.size() > 0) {
                            for (int i = 0; i < list.size(); i++) {
                                Map<String, Object> map = list.get(i);
                                //终端状态用 redis数据
                                if(map.get("serialNumber") !=null){
                                    Map<String, Object> cacheMap =redisService.getCacheMap("gun:"+map.get("serialNumber").toString());
                                    if(!cacheMap.isEmpty()){
                                        if ("离线".equals(cacheMap.get("status").toString())){
                                        }else if("故障".equals(cacheMap.get("status").toString())){
                                        }else if("空闲".equals(cacheMap.get("status").toString()) || "插枪".equals(cacheMap.get("status").toString())){
                                            normal++;
                                        }else{
                                            normal++;
                                        }
                                    }else{

                                    }
                                }else{
                                }
                            }
                        }
                    }

                    BigDecimal bigDecimal = xhpcInspectionMapper.onlineRate(normal,0,null,tenantId);
                    map1.put("onlineRate",bigDecimal+"%");
                }
        }
        return map1;
    }

    @Override
    public List<Map<String, Object>> getStationInspectionList(HttpServletRequest request, String startTime, String endTime) {

        LoginUser loginUser = tokenService.getLoginUser(request);

        String tenantId = loginUser.getTenantId();
        Long logUserId = SecurityUtils.getUserId();
        SysUser sysUser = loginUser.getSysUser();
        List<Map<String, Object>> mapList =new ArrayList<>();
        if(tenantId !=null && !"".equals(tenantId)){
            if(sysUser.getUserId() !=UserTypeUtil.USER_ID){
                Long logOperatorId = sysUser.getOperatorId();
                if ("01".equals(sysUser.getUserType())) {
                    mapList= xhpcInspectionMapper.getStationInspectionList(1,logOperatorId,tenantId,startTime,endTime);
                }else{
                    mapList= xhpcInspectionMapper.getStationInspectionList(2,logUserId,tenantId,startTime,endTime);
                }
            }else{
                mapList= xhpcInspectionMapper.getStationInspectionList(0,null,tenantId,startTime,endTime);
            }
        }
        return mapList;
    }

    @Override
    public List<Map<String, Object>> getStationInspectionDateList(Long stationId, String time) {
        String today = DateUtil.today();
        List<Map<String, Object>> list =new ArrayList<>();
        if(time==null || "".equals(time)){
            list = xhpcInspectionMapper.getStationInspectionDateList(stationId, today);
        }else{
            list = xhpcInspectionMapper.getStationInspectionDateList(stationId, time);
        }
        return list;
    }

    @Override
    public Map<String, Object> getStationInspectionMoonList(Long stationId, String time) {
        String today = DateUtil.today();
        List<Map<String, Object>> list =xhpcInspectionMapper.getStationInspectionDateList(stationId, today);
        Map<String, Object> mapList =new HashMap<>();
        for (int i = 0; i <list.size() ; i++) {
            Map<String, Object> map = list.get(i);
            String name = map.get("name").toString();
            List<Map<String, Object>> stationInspectionMoonList = xhpcInspectionMapper.getStationInspectionMoonList(stationId, time, name);
            mapList.put(name,stationInspectionMoonList);
        }
        return mapList;
    }

    BigDecimal toBigDecimal(Object obj) {
        if (obj == null) return BigDecimal.ZERO;
        String str = obj.toString().trim();
        if (str.isEmpty() || "null".equalsIgnoreCase(str)) return BigDecimal.ZERO;
        // 去除千位分隔符（逗号）
        str = str.replace(",", "");
        return new BigDecimal(str);
    }
    public static void main(String[] args) {
        String today = DateUtil.today();
        System.out.println("-------"+today);

    }
}
