| package com.moral.api.controller; | 
|   | 
| import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
| import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; | 
| import com.moral.api.entity.Organization; | 
| import com.moral.api.entity.ServicesScope; | 
| import com.moral.api.mapper.OrganizationMapper; | 
| import com.moral.api.service.HistoryDailyService; | 
| import com.moral.api.service.HistoryHourlyService; | 
| import com.moral.api.service.HistoryMonthlyService; | 
| import com.moral.api.service.ServicesScopeService; | 
| import com.moral.constant.Constants; | 
| import com.moral.constant.ResponseCodeEnum; | 
| import com.moral.constant.ResultMessage; | 
| import com.moral.util.DateUtils; | 
| import com.moral.util.WebUtils; | 
| import io.swagger.annotations.Api; | 
| import lombok.extern.slf4j.Slf4j; | 
| import org.springframework.web.bind.annotation.*; | 
|   | 
| import javax.annotation.Resource; | 
| import javax.servlet.http.HttpServletRequest; | 
| import java.text.ParseException; | 
| import java.text.SimpleDateFormat; | 
| import java.util.*; | 
|   | 
| /** | 
|  * @program: screen | 
|  * @description: 图表数据 | 
|  * @author: lizijie | 
|  * @create: 2021-11-10 16:05 | 
|  **/ | 
| @Slf4j | 
| @Api(tags = {"设备小时数据"}) | 
| @RestController | 
| @CrossOrigin(origins = "*", maxAge = 3600) | 
| @RequestMapping("/chart") | 
| public class ChartController { | 
|   | 
|     @Resource | 
|     private OrganizationMapper organizationMapper; | 
|   | 
|     @Resource | 
|     private HistoryHourlyService historyHourlyService; | 
|   | 
|     @Resource | 
|     private HistoryDailyService historyDailyService; | 
|   | 
|     @Resource | 
|     private HistoryMonthlyService historyMonthlyService; | 
|   | 
|     @Resource | 
|     private ServicesScopeService servicesScopeService; | 
|   | 
|     @RequestMapping(value = "getThermodynamicDiagramDataByCondition", method = RequestMethod.GET) | 
|     @ResponseBody | 
|     public ResultMessage getThermodynamicDiagramDataByCondition(HttpServletRequest request) throws ParseException { | 
|         Map<String, Object> parameters = WebUtils.getParametersStartingWith(request,null); | 
|         Object orgid = parameters.get("organization_id"); | 
|         Object sensorCode = parameters.get("sensor_code"); | 
|         Object type = parameters.get("type"); | 
|         if (ObjectUtils.isEmpty(orgid) || ObjectUtils.isEmpty(sensorCode) || ObjectUtils.isEmpty(type)){ | 
|             return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|         } | 
|         Organization organization = organizationMapper.selectById(Integer.parseInt(orgid.toString())); | 
|         if (ObjectUtils.isEmpty(organization)){ | 
|             return ResultMessage.fail(ResponseCodeEnum.ORGANIZATION_NOT_EXIST.getCode(), ResponseCodeEnum.ORGANIZATION_NOT_EXIST.getMsg()); | 
|         } | 
|         Map<String, Object> resultMap = new HashMap<>(); | 
|         List<Map<String,Object>> resultList = new ArrayList<>(); | 
|         if (type.equals("hourly")){ | 
|             Object time = parameters.get("time"); | 
|             if (ObjectUtils.isEmpty(time)){ | 
|                 return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|             } | 
|             resultMap = historyHourlyService.getThermodynamicDiagramDataByOrgIdSensorCodeTime(parameters); | 
|             return ResultMessage.ok(resultMap); | 
|         } | 
|         if (type.equals("daily")){ | 
|             Object time = parameters.get("time"); | 
|             if (ObjectUtils.isEmpty(time)){ | 
|                 return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|             } | 
|             resultMap = historyDailyService.getThermodynamicDiagramDataByOrgIdSensorCodeTime(parameters); | 
|             return ResultMessage.ok(resultMap); | 
|         } | 
|         if (type.equals("monthly")){ | 
|             Object time = parameters.get("time"); | 
|             if (ObjectUtils.isEmpty(time)){ | 
|                 return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|             } | 
|             resultMap = historyMonthlyService.getThermodynamicDiagramDataByOrgIdSensorCodeTime(parameters); | 
|             return ResultMessage.ok(resultMap); | 
|         } | 
|         if (type.equals("custom")){ | 
|             String startTime = parameters.get("startTime").toString(); | 
|             String endTime = parameters.get("endTime").toString(); | 
|             if (ObjectUtils.isEmpty(startTime) || ObjectUtils.isEmpty(endTime)){ | 
|                 return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|             } | 
|             if (startTime.length() == 13){ | 
|                 SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//24小时制 | 
|                 long newTime1 = simpleDateFormat.parse(startTime+":00:00").getTime(); | 
|                 long newTime2 = simpleDateFormat.parse(endTime+":00:00").getTime(); | 
|                 Long result = newTime2 - newTime1; //获取两时间相差的毫秒数 | 
|                 long nd = 1000 * 24 * 60 * 60; | 
|                 long nh = 1000 * 60 * 60; | 
|                 long nm = 1000 * 60; | 
|                 long hour = result / nh; //获取相差的小时数 | 
|                 if (hour+1>12){ | 
|                     return ResultMessage.fail(-1, "时间不能超过12小时"); | 
|                 } | 
|                 if (hour<0){ | 
|                     return ResultMessage.fail(ResponseCodeEnum.TIME_FORMAT_INVALID.getCode(), ResponseCodeEnum.TIME_FORMAT_INVALID.getMsg()); | 
|                 } | 
|                 parameters.put("hour",hour); | 
|                 resultList = historyHourlyService.getThermodynamicDiagramDataByOrgIdSensorCodeTimeslot(parameters); | 
|                 return ResultMessage.ok(resultList); | 
|             } | 
|             if (startTime.length() == 10){ | 
|                 long days = DateUtils.getQuotByDays(startTime, endTime); | 
|                 if (days+1>12){ | 
|                     return ResultMessage.fail(-1, "时间不能超过12天"); | 
|                 } | 
|                 parameters.put("days",days); | 
|                 resultList = historyDailyService.getThermodynamicDiagramDataByOrgIdSensorCodeTimeSlot(parameters); | 
|                 return ResultMessage.ok(resultList); | 
|             } | 
|             if (startTime.length() == 7){ | 
|                 SimpleDateFormat df = new SimpleDateFormat("yyyy-MM"); | 
|                 Date satrtTimeDate = df.parse(startTime); | 
|                 Date endTimeDate = df.parse(endTime); | 
|                 long months = DateUtils.getMonth(satrtTimeDate,endTimeDate); //获取相差的小时数 | 
|                 if (months+1>12){ | 
|                     return ResultMessage.fail(-1, "时间不能超过12月"); | 
|                 } | 
|                 parameters.put("months",months); | 
|                 resultList = historyMonthlyService.getThermodynamicDiagramDataByOrgIdSensorCodeTimeSlot(parameters); | 
|                 return ResultMessage.ok(resultList); | 
|             } | 
|         } | 
|         return ResultMessage.ok(resultMap); | 
|     } | 
|   | 
|     @RequestMapping(value = "getThermodynamicDiagramDataByConditionV2", method = RequestMethod.GET) | 
|     @ResponseBody | 
|     public ResultMessage getThermodynamicDiagramDataByConditionV2(HttpServletRequest request) throws ParseException { | 
|         Map<String, Object> parameters = WebUtils.getParametersStartingWith(request,null); | 
|         Object servicesScopeId = parameters.get("servicesScopeId"); | 
|         Object sensorCode = parameters.get("sensor_code"); | 
|         Object type = parameters.get("type"); | 
|         if (ObjectUtils.isEmpty(servicesScopeId) || ObjectUtils.isEmpty(sensorCode) || ObjectUtils.isEmpty(type)){ | 
|             return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|         } | 
|         QueryWrapper<ServicesScope> servicesScopeQueryWrapper = new QueryWrapper<>(); | 
|         servicesScopeQueryWrapper.eq("is_delete",Constants.NOT_DELETE); | 
|         servicesScopeQueryWrapper.eq("id",servicesScopeId); | 
|         ServicesScope servicesScope = servicesScopeService.getOne(servicesScopeQueryWrapper); | 
|         if (ObjectUtils.isEmpty(servicesScope)){ | 
|             return ResultMessage.fail(ResponseCodeEnum.ORGANIZATION_NOT_EXIST.getCode(), ResponseCodeEnum.ORGANIZATION_NOT_EXIST.getMsg()); | 
|         } | 
|         Map<String, Object> resultMap = new HashMap<>(); | 
|         List<Map<String,Object>> resultList = new ArrayList<>(); | 
|         if (type.equals("hourly")){ | 
|             Object time = parameters.get("time"); | 
|             if (ObjectUtils.isEmpty(time)){ | 
|                 return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|             } | 
|             resultMap = historyHourlyService.getThermodynamicDiagramDataByOrgIdSensorCodeTimeV2(parameters); | 
|             return ResultMessage.ok(resultMap); | 
|         } | 
|         if (type.equals("daily")){ | 
|             Object time = parameters.get("time"); | 
|             if (ObjectUtils.isEmpty(time)){ | 
|                 return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|             } | 
|             resultMap = historyDailyService.getThermodynamicDiagramDataByOrgIdSensorCodeTimeV2(parameters); | 
|             return ResultMessage.ok(resultMap); | 
|         } | 
|         if (type.equals("monthly")){ | 
|             Object time = parameters.get("time"); | 
|             if (ObjectUtils.isEmpty(time)){ | 
|                 return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|             } | 
|             resultMap = historyMonthlyService.getThermodynamicDiagramDataByOrgIdSensorCodeTimeV2(parameters); | 
|             return ResultMessage.ok(resultMap); | 
|         } | 
|         if (type.equals("custom")){ | 
|             String startTime = parameters.get("startTime").toString(); | 
|             String endTime = parameters.get("endTime").toString(); | 
|             if (ObjectUtils.isEmpty(startTime) || ObjectUtils.isEmpty(endTime)){ | 
|                 return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|             } | 
|             if (startTime.length() == 13){ | 
|                 SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//24小时制 | 
|                 long newTime1 = simpleDateFormat.parse(startTime+":00:00").getTime(); | 
|                 long newTime2 = simpleDateFormat.parse(endTime+":00:00").getTime(); | 
|                 Long result = newTime2 - newTime1; //获取两时间相差的毫秒数 | 
|                 long nd = 1000 * 24 * 60 * 60; | 
|                 long nh = 1000 * 60 * 60; | 
|                 long nm = 1000 * 60; | 
|                 long hour = result / nh; //获取相差的小时数 | 
|                 if (hour+1>12){ | 
|                     return ResultMessage.fail(-1, "时间不能超过12小时"); | 
|                 } | 
|                 if (hour<0){ | 
|                     return ResultMessage.fail(ResponseCodeEnum.TIME_FORMAT_INVALID.getCode(), ResponseCodeEnum.TIME_FORMAT_INVALID.getMsg()); | 
|                 } | 
|                 parameters.put("hour",hour); | 
|                 resultList = historyHourlyService.getThermodynamicDiagramDataByOrgIdSensorCodeTimeslotV2(parameters); | 
|                 return ResultMessage.ok(resultList); | 
|             } | 
|             if (startTime.length() == 10){ | 
|                 long days = DateUtils.getQuotByDays(startTime, endTime); | 
|                 if (days+1>12){ | 
|                     return ResultMessage.fail(-1, "时间不能超过12天"); | 
|                 } | 
|                 parameters.put("days",days); | 
|                 resultList = historyDailyService.getThermodynamicDiagramDataByOrgIdSensorCodeTimeSlotV2(parameters); | 
|                 return ResultMessage.ok(resultList); | 
|             } | 
|             if (startTime.length() == 7){ | 
|                 SimpleDateFormat df = new SimpleDateFormat("yyyy-MM"); | 
|                 Date satrtTimeDate = df.parse(startTime); | 
|                 Date endTimeDate = df.parse(endTime); | 
|                 long months = DateUtils.getMonth(satrtTimeDate,endTimeDate); //获取相差的小时数 | 
|                 if (months+1>12){ | 
|                     return ResultMessage.fail(-1, "时间不能超过12月"); | 
|                 } | 
|                 parameters.put("months",months); | 
|                 resultList = historyMonthlyService.getThermodynamicDiagramDataByOrgIdSensorCodeTimeSlotV2(parameters); | 
|                 return ResultMessage.ok(resultList); | 
|             } | 
|         } | 
|         return ResultMessage.ok(resultMap); | 
|     } | 
|   | 
|     @RequestMapping(value = "returnDataTest", method = RequestMethod.GET) | 
|     @ResponseBody | 
|     public ResultMessage returnDataTest(HttpServletRequest request) throws ParseException { | 
|         List bigList = new ArrayList(); | 
|         Map<String,Object> resultMap = new HashMap<>(); | 
|         List<List> boundList = new ArrayList<>(); | 
|         /*boundList.add(120.70980239181193); | 
|         boundList.add(31.329143000000002); | 
|         boundList.add(120.74077860818807); | 
|         boundList.add(31.356963);*/ | 
|         /*List<Double> boundList1 = new ArrayList<>(); | 
|         List<Double> boundList2 = new ArrayList<>(); | 
|         List<Double> boundList3 = new ArrayList<>(); | 
|         List<Double> boundList4 = new ArrayList<>(); | 
|         List<Double> boundList5 = new ArrayList<>(); | 
|         List<Double> boundList6 = new ArrayList<>(); | 
|         List<Double> boundList7 = new ArrayList<>(); | 
|         List<Double> boundList8 = new ArrayList<>(); | 
|         List<Double> boundList9 = new ArrayList<>(); | 
|         boundList1.add(120.975221); | 
|         boundList1.add(31.413145); | 
|         boundList2.add(120.977021); | 
|         boundList2.add(31.411345); | 
|         boundList3.add(120.979174); | 
|         boundList3.add(31.333362); | 
|         boundList4.add(120.977374); | 
|         boundList4.add(31.331562); | 
|         boundList5.add(120.913768); | 
|         boundList5.add(31.347918); | 
|         boundList6.add(120.870665); | 
|         boundList6.add(31.341063); | 
|         boundList7.add(120.868865); | 
|         boundList7.add(31.342863); | 
|         boundList8.add(120.896371); | 
|         boundList8.add(31.409264); | 
|         boundList9.add(120.898171); | 
|         boundList9.add(31.411064); | 
|         List<List> boundList_middle = new ArrayList<>(); | 
|         boundList_middle.add(boundList1); | 
|         boundList_middle.add(boundList2); | 
|         boundList_middle.add(boundList3); | 
|         boundList_middle.add(boundList4); | 
|         boundList_middle.add(boundList5); | 
|         boundList_middle.add(boundList6); | 
|         boundList_middle.add(boundList7); | 
|         boundList_middle.add(boundList8); | 
|         boundList_middle.add(boundList9);*/ | 
|         String boundList_middle = "[[[120.975221,31.413145],[120.977021,31.411345],[120.979174,31.333362],[120.977374,31.331562],[120.913768,31.347918],[120.870665,31.341063],[120.868865,31.342863],[120.896371,31.409264],[120.898171,31.411064]]]"; | 
|         List<String> boundList_middle2 = new ArrayList<>(); | 
|         boundList_middle2.add(boundList_middle); | 
|         resultMap.put("bound",boundList_middle); | 
|         resultMap.put("time","2021-12-10 08:00:00"); | 
|         List<Double> centerPointList = new ArrayList<>(); | 
|         centerPointList.add(120.934824838); | 
|         centerPointList.add(31.37834580); | 
|         resultMap.put("centerPoint",centerPointList); | 
|         List<Double> list1 = new ArrayList<>(); | 
|         list1.add(120.975221); | 
|         list1.add(31.411345); | 
|         list1.add(1.0); | 
|         List<Double> list2 = new ArrayList<>(); | 
|         list2.add(120.870665); | 
|         list2.add(31.342863); | 
|         list2.add(4.0); | 
|         List<Double> list3 = new ArrayList<>(); | 
|         list3.add(120.898171); | 
|         list3.add(31.409264); | 
|         list3.add(2.0); | 
|         List<Double> list4 = new ArrayList<>(); | 
|         list4.add(120.913768); | 
|         list4.add(31.349718); | 
|         list4.add(3.0); | 
|         List<Double> list5 = new ArrayList<>(); | 
|         list5.add(120.977374); | 
|         list5.add(31.333362); | 
|         list5.add(2.0); | 
|         List list12345 = new ArrayList(); | 
|         list12345.add(list1); | 
|         list12345.add(list2); | 
|         list12345.add(list3); | 
|         list12345.add(list4); | 
|         list12345.add(list5); | 
|         resultMap.put("list",list12345); | 
|         for (int i=0;i<10;i++){ | 
|             resultMap.put("time","2021-12-10 0"+i+":00:00"); | 
|             bigList.add(resultMap); | 
|         } | 
|   | 
|         return ResultMessage.ok(bigList); | 
|     } | 
|   | 
| } |