| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732 |
- package com.welampiot.controller;
- import com.welampiot.common.BaseResult;
- import com.welampiot.common.InterfaceResultEnum;
- import com.welampiot.dto.GWRSDevDTO;
- import com.welampiot.dto.*;
- import com.welampiot.service.*;
- import com.welampiot.utils.ToolUtils;
- import com.welampiot.vo.*;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.CrossOrigin;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.RestController;
- import javax.servlet.http.HttpServletRequest;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.*;
- /**
- * ClassName: NewLampPoleController
- * Package: com.welampiot.controller
- * Description:
- *
- * @Author: zhj_Start
- * @Create: 2023/4/11 - 19:53
- * @Version: v1.0
- */
- @RestController
- @CrossOrigin
- @RequestMapping("/newLampPole")
- public class NewLampPoleController {
- @Autowired
- private WifiService wifiService;
- @Autowired
- private WifiInfoLogService wifiInfoLogService;
- @Autowired
- private EnvmonitorService envmonitorService;
- @Autowired
- private ScreenService screenService;
- @Autowired
- private ToolUtils toolUtils;
- @Autowired
- private LampPoleService lampPoleService;
- @Autowired
- private OperationLogService operationLogService;
- @Autowired
- private LampService lampService;
- @Autowired
- private LampInfoLogService lampInfoLogService;
- @Autowired
- private LampPoleAlarmLogService lampPoleAlarmLogService;
- @RequestMapping(value = "/info",method = RequestMethod.POST)
- public BaseResult info(HttpServletRequest request){
- Integer version = request.getParameter("version") == null ? 0 : Integer.parseInt(request.getParameter("version"));
- LampPoleInfoVO lampPoleInfoVO = new LampPoleInfoVO();
- List sectionList = toolUtils.getSectionList(request);
- LampPoleVO lampPoleVO = new LampPoleVO();
- lampPoleVO.setSectionList(sectionList);
- List<LampPoleDTO> listByVO = lampPoleService.getListByVO(lampPoleVO);
- lampPoleInfoVO.setDeviceCount(listByVO.size());
- lampPoleInfoVO.setRunCount(listByVO.size());
- lampPoleInfoVO.setWifiCount(listByVO.size());
- lampPoleInfoVO.setEmCount(0);
- for (LampPoleDTO l:listByVO) {
- // String devType = l.getDevType();
- // List split = Arrays.asList(devType.split(","));
- // if (split.contains("5")) lampPoleInfoVO.setEmCount(lampPoleInfoVO.getEmCount()+1);;
- }
- // $data['loopCount'] = $this->Loop_model->get_count(array('sectionid'=>$sectionId));
- // $id_arr = array_column($lampPoleList, 'id');
- // $temp_l = [];
- // if (!empty($id_arr)) {
- // $sql = 'select lamp_pole_id,max(updatetime),status,id,devtype from lamp_pole_alarm_log where lamp_pole_id in ('.implode(',', $id_arr).') and (status = 0 or status = 1) group by lamp_pole_id';
- // $l_list = $this->db->query($sql)->result_array();
- // foreach ($l_list as $key => $value) {
- // // if ($value['status'] != 1 && $value['status'] != 0) continue;
- // $temp_l[$value['lamp_pole_id']] = $value;
- // }
- // }
- //
- // $lampPoleId = array();
- // foreach ($lampPoleList as $lampPole) {
- // $data['deviceCount'] += 1;
- // $data['runCount'] += 1;
- // if (time() - strtotime($lampPole['createtime']) <= 3600*24*30) {
- // $data['newCount'] += 1;
- // }
- // $typeArr = explode(',', $lampPole['devtype']);
- // if (in_array('0', $typeArr)) $data['lampCount'] += 1;
- // if (in_array('1', $typeArr)) $data['videoCount'] += 1;
- // if (in_array('2', $typeArr)) $data['wifiCount'] += 1;
- // if (in_array('4', $typeArr)) $data['screenCount'] += 1;
- // if (in_array('5', $typeArr)) $data['emCount'] += 1;
- // if (in_array('6', $typeArr)) $data['chargeCount'] += 1;
- // if (in_array('7', $typeArr)) $data['weatherCount'] += 1;
- // if (in_array('9', $typeArr)) $data['radioCount'] += 1;
- // if (in_array('14', $typeArr)) $data['waterImmersionCount'] += 1;
- // if (in_array('18', $typeArr)) $data['tiltCount'] += 1;
- // if (in_array('15', $typeArr)) $data['lockCount'] += 1;
- // if (isset($temp_l[$lampPole['id']])) {
- // $data['faultCount'] += 1;
- // $data['runCount'] -= 1;
- // }
- //
- // $lampPoleId[] = $lampPole['id'];
- // }
- //
- // if (!empty($lampPoleId)) {
- // // smart_lock_dev_info
- // $res = $this->db->query('select count(*) as total from smart_lock_dev_info where lamp_pole_id in ('.implode(',', $lampPoleId).')')->row_array();
- // $data['lockCount'] = intval($res['total']);
- //
- // $lampinfoList = $this->Lampinfo_model->get_list(array('lamp_pole_id'=>$lampPoleId),'id');
- // $lampId = array();
- // $data['lampCount'] = count($lampinfoList);
- // foreach ($lampinfoList as $l) {
- // $lampId[] = $l['id'];
- // }
- // if (!empty($lampId)) {
- // $join = array(
- // array('table'=>'lamp_info_log_new as t1','cond'=>'t1.updatetime = LI.updatetime AND t1.lampid = LI.lampid','type'=>'inner')
- // );
- // $sql = "select day_gener_energy,month_gener_energy,used_energy_total from lamp_info_log_new a where a.lampid in (".implode(',', $lampId).")";
- // $lampInfoLogList = $this->db->query($sql)->result_array();
- // foreach ($lampInfoLogList as $lampLog) {
- // $data['dayCom'] += $lampLog['day_gener_energy'];
- // $data['monthCom'] += $lampLog['month_gener_energy'];
- // $data['totalCom'] += $lampLog['used_energy_total'];
- // }
- // }
- // }
- // $data['dayCom'] = round($data['dayCom'],1);
- // $data['monthCom'] = round($data['monthCom'],1);
- // $data['totalCom'] = round($data['totalCom'],1);
- return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,lampPoleInfoVO);
- }
- /**
- * 获取云盒列表
- * @param request
- * @return
- */
- @RequestMapping(value = "/wifiList", method = RequestMethod.POST)
- public BaseResult<WifiDTO> wifiList(HttpServletRequest request){
- Integer page = request.getParameter("page") == null ? 1 : Integer.parseInt(request.getParameter("page"));
- Integer count = request.getParameter("count") == null ? 16 : Integer.parseInt(request.getParameter("count"));
- Integer online = request.getParameter("online") == null || request.getParameter("online").length() == 0 ? null : Integer.parseInt(request.getParameter("online"));
- String keyword = request.getParameter("keyword") == null ? "" : request.getParameter("keyword");
- WifiDTO dto = new WifiDTO();
- dto.setPage(count * (page - 1));
- dto.setCount(count);
- dto.setKeyword(keyword);
- if (online != null) dto.setOnlineState(online);
- dto.setSectionList(toolUtils.getSectionList(request));
- WifiVO vo = wifiService.getWifiList(dto);
- return BaseResult.success(vo);
- }
- /**
- * 获取云盒数据概览
- * @param request
- * @return
- */
- @RequestMapping(value = "/wifiInfo", method = RequestMethod.POST)
- public BaseResult<WifiDTO> wifiInfo(HttpServletRequest request){
- WifiDTO dto = new WifiDTO();
- dto.setSectionList(toolUtils.getSectionList(request));
- WifiVO vo = wifiService.getWifiInfo(dto);
- return BaseResult.success(vo);
- }
- /**
- * 获取云盒电源设置
- * @param request
- * @return
- */
- @RequestMapping(value = "/wifiOutInfo", method = RequestMethod.POST)
- public BaseResult<WifiDTO> wifiOutInfo(HttpServletRequest request){
- Integer version = request.getParameter("version") == null ? 0 : Integer.parseInt(request.getParameter("version"));
- Integer id = request.getParameter("id") == null ? 0 : Integer.parseInt(request.getParameter("id"));
- WifiOutInfoVO vo = wifiService.getWifiOutInfo(id, toolUtils.getSectionList(request));
- if (vo == null) return toolUtils.response(InterfaceResultEnum.PARAM_FAIL,version);
- return BaseResult.success(vo);
- }
- /**
- * 获取云盒输出统计数据
- * @param request
- * @return
- */
- @RequestMapping(value = "/wifiOutStatistics", method = RequestMethod.POST)
- public BaseResult wifiOutStatistics(HttpServletRequest request) throws ParseException {
- int version = request.getParameter("version") == null ? 0 : Integer.parseInt(request.getParameter("version"));
- int id = request.getParameter("id") == null ? 0 : Integer.parseInt(request.getParameter("id"));
- if (id == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
- int dateType = request.getParameter("dateType") == null ? 0 : Integer.parseInt(request.getParameter("dateType"));
- int dataType = request.getParameter("dataType") == null ? 0 : Integer.parseInt(request.getParameter("dataType"));
- WifiInfoLogDTO dto = new WifiInfoLogDTO();
- dto.setWifiId(id);
- dto.setDataType(dataType);
- Integer timezone = wifiInfoLogService.getTimezoneById(dto);
- if (timezone == null) return toolUtils.response(InterfaceResultEnum.PARAM_FAIL,version);
- long l = System.currentTimeMillis() - timezone * 3600 * 1000;
- long startTime = 0L;
- long endTime = 0L;
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- if (dateType == 0){ // 1 天
- startTime = l - 24 * 3600 * 1000;
- endTime = l;
- }else if (dateType == 1){ // 3 天
- startTime = l - 24 * 3600 * 1000 * 3;
- endTime = l;
- }else if (dateType == 2){ // 7 天
- startTime = l - 24 * 3600 * 1000 * 7;
- endTime = l;
- }else if (dateType == 3){ // 14 天
- startTime = l - 24 * 3600 * 1000 * 14;
- endTime = l;
- }else if (dateType == 4){ // 日期选择 最多30天
- String date = (String) toolUtils.getRequestContent(request,"date",2);
- if (date.length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_DATE_ERROR,version);
- List<String> split = Arrays.asList(date.split("/"));
- System.out.println(split);
- System.out.println(split.get(0));
- System.out.println(split.get(1));
- try {
- startTime = simpleDateFormat.parse(split.get(0) + " 00:00:00").getTime();
- } catch (ParseException e) {
- throw new RuntimeException(e);
- }
- endTime = simpleDateFormat.parse(split.get(1) + " 23:59:59").getTime();
- if (endTime < startTime) toolUtils.response(InterfaceResultEnum.LACK_DATE_FORMAT_ERROR,version);
- if (endTime - startTime > 29L * 24 * 3600 * 1000) toolUtils.response(InterfaceResultEnum.LACK_DATE_RANGE_ERROR,version);
- startTime -= timezone * 3600 * 1000;
- endTime -= timezone * 3600 * 1000;
- }
- HashMap<String, Integer> objectObjectHashMap = new HashMap<>();
- long timeT = startTime;
- int i = 0;
- List<Object> dateList = new ArrayList<>();
- List<Object> volList = new ArrayList<>();
- List<Object> curList = new ArrayList<>();
- List<Object> powerList = new ArrayList<>();
- List<Object> comList = new ArrayList<>();
- List<WifiInfoLogDTO> list = new ArrayList<>();
- simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:00:00");
- while (timeT < endTime){
- objectObjectHashMap.put(simpleDateFormat.format(new Date(timeT)),i);
- dateList.add(simpleDateFormat.format(new Date(timeT + timezone * 3600 * 1000)));
- volList.add(0);
- powerList.add(0);
- comList.add(0);
- curList.add(0);
- list.add(null);
- timeT += 3600 * 1000;
- i ++;
- }
- SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- String startDate = simpleDateFormat.format(new Date(startTime));
- String endDate = simpleDateFormat.format(new Date(endTime));
- dto.setStartDate(startDate);
- dto.setEndDate(endDate);
- List<WifiInfoLogDTO> wifiOutStatisticsByDTO = wifiInfoLogService.getWifiOutStatisticsByDTO(dto);
- for (WifiInfoLogDTO wifiInfoLogDTO : wifiOutStatisticsByDTO) {
- Date date = new Date(simpleDateFormat2.parse(wifiInfoLogDTO.getUpdateTime()).getTime());
- String s = simpleDateFormat.format(date);
- if (objectObjectHashMap.containsKey(s)){
- Integer integer = objectObjectHashMap.get(s);
- list.set(integer,wifiInfoLogDTO);
- }
- }
- for (WifiInfoLogDTO wifiInfoLogDTO : list) {
- if (wifiInfoLogDTO != null){
- Date date = new Date(simpleDateFormat2.parse(wifiInfoLogDTO.getUpdateTime()).getTime());
- String s = simpleDateFormat.format(date);
- Integer integer = null;
- if (objectObjectHashMap.containsKey(s)){
- integer = objectObjectHashMap.get(s);
- list.set(integer,wifiInfoLogDTO);
- }
- if (dto.getDataType() != null){
- switch (dto.getDataType()){
- case 5:
- if (wifiInfoLogDTO.getCurrentC() != null && !wifiInfoLogDTO.getCurrentC().equals("0") && integer != null) {
- curList.set(integer, Float.valueOf(wifiInfoLogDTO.getCurrentC()));
- }
- if (wifiInfoLogDTO.getVoltageC() != null && !wifiInfoLogDTO.getVoltageC().equals("0") && integer != null) {
- volList.set(integer, Float.valueOf(wifiInfoLogDTO.getVoltageC()));
- }
- if (wifiInfoLogDTO.getPowerC() != null && !wifiInfoLogDTO.getPowerC().equals("0")&& integer != null) {
- powerList.set(integer, Float.valueOf(wifiInfoLogDTO.getPowerC()));
- }
- if (wifiInfoLogDTO.getTotalComC() != null && !wifiInfoLogDTO.getTotalComC().equals("0") && integer != null) {
- comList.set(integer, Float.valueOf(wifiInfoLogDTO.getTotalComC()));
- }
- break;
- case 4:
- if (wifiInfoLogDTO.getCurrentB() != null && !wifiInfoLogDTO.getCurrentB().equals("0") && integer != null) {
- curList.set(integer, Float.valueOf(wifiInfoLogDTO.getCurrentB()));
- }
- if (wifiInfoLogDTO.getVoltageB() != null && !wifiInfoLogDTO.getVoltageB().equals("0") && integer != null) {
- volList.set(integer, Float.valueOf(wifiInfoLogDTO.getVoltageB()));
- }
- if (wifiInfoLogDTO.getPowerB() != null && !wifiInfoLogDTO.getPowerB().equals("0") && integer != null) {
- powerList.set(integer, Float.valueOf(wifiInfoLogDTO.getPowerB()));
- }
- if (wifiInfoLogDTO.getTotalComB() != null &&! wifiInfoLogDTO.getTotalComB().equals("0") && integer != null) {
- comList.set(integer, Float.valueOf(wifiInfoLogDTO.getTotalComB()));
- }
- break;
- case 3 :
- if (wifiInfoLogDTO.getLna3Cur() != null && !wifiInfoLogDTO.getLna3Cur().equals("0") && integer != null){
- curList.set(integer,Float.valueOf(wifiInfoLogDTO.getLna3Cur()));
- }
- if (wifiInfoLogDTO.getLna3Vol() != null && !wifiInfoLogDTO.getLna3Vol().equals("0") && integer != null){
- volList.set(integer,Float.valueOf(wifiInfoLogDTO.getLna3Vol()));
- }
- break;
- case 2 :
- if (wifiInfoLogDTO.getLna2Cur() != null && !wifiInfoLogDTO.getLna2Cur().equals("0") && integer != null){
- curList.set(integer,Float.valueOf(wifiInfoLogDTO.getLna2Cur()));
- }
- if (wifiInfoLogDTO.getLna2Vol() != null && !wifiInfoLogDTO.getLna2Vol().equals("0") && integer != null){
- volList.set(integer,Float.valueOf(wifiInfoLogDTO.getLna2Vol()));
- }
- break;
- case 1 :
- if (wifiInfoLogDTO.getLna1Cur() != null && !wifiInfoLogDTO.getLna1Cur().equals("0") && integer != null){
- curList.set(integer,Float.valueOf(wifiInfoLogDTO.getLna1Cur()));
- }
- if (wifiInfoLogDTO.getLna1Vol() != null && !wifiInfoLogDTO.getLna1Vol().equals("0") && integer != null){
- volList.set(integer,Float.valueOf(wifiInfoLogDTO.getLna1Vol()));
- }
- break;
- case 0 :
- if (wifiInfoLogDTO.getCurrent() != null && !wifiInfoLogDTO.getCurrent().equals("0") && integer != null){
- curList.set(integer,Float.valueOf(wifiInfoLogDTO.getCurrent()));
- }
- if (wifiInfoLogDTO.getVoltage() != null && !wifiInfoLogDTO.getVoltage().equals("0") && integer != null){
- volList.set(integer,Float.valueOf(wifiInfoLogDTO.getVoltage()));
- }
- if (wifiInfoLogDTO.getPower() != null && !wifiInfoLogDTO.getPower().equals("0") && integer != null){
- powerList.set(integer,Float.valueOf(wifiInfoLogDTO.getPower()));
- }
- if (wifiInfoLogDTO.getTotalComA() != null && !wifiInfoLogDTO.getTotalComA().equals("0") && integer != null){
- comList.set(integer,Float.valueOf(wifiInfoLogDTO.getTotalComA()));
- }
- break;
- }
- }
- date = new Date(simpleDateFormat2.parse(wifiInfoLogDTO.getUpdateTime()).getTime() + timezone * 3600 * 1000);
- wifiInfoLogDTO.setUpdateTime(simpleDateFormat.format(date));
- }
- }
- WifiInfoLogVO wifiInfoLogVO = new WifiInfoLogVO();
- wifiInfoLogVO.setCurArr(curList);
- wifiInfoLogVO.setVolArr(volList);
- wifiInfoLogVO.setPowerArr(powerList);
- wifiInfoLogVO.setDateArr(dateList);
- wifiInfoLogVO.setComArr(comList);
- return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,wifiInfoLogVO);
- }
- /**
- * 获取气象站数据列表
- * @param request
- * @return
- */
- @RequestMapping(value = "/weatherList", method = RequestMethod.POST)
- public BaseResult<EnvmonitorDTO> weatherList(HttpServletRequest request){
- Integer page = request.getParameter("page") == null ? 1 : Integer.parseInt(request.getParameter("page"));
- Integer count = request.getParameter("count") == null ? 16 : Integer.parseInt(request.getParameter("count"));
- Integer online = request.getParameter("online") == null ? 0 : Integer.parseInt(request.getParameter("online"));
- EnvmonitorDTO dto = new EnvmonitorDTO();
- dto.setPage(count * (page - 1));
- dto.setCount(count);
- dto.setOnline(online);
- dto.setSectionList(toolUtils.getSectionList(request));
- EnvmonitorVO vo = envmonitorService.getWeatherList(dto);
- return BaseResult.success(vo);
- }
- /**
- * 获取气象站概览数据
- * @param request
- * @return
- */
- @RequestMapping(value = "/weatherInfo", method = RequestMethod.POST,produces = "application/json;charset=utf-8")
- public BaseResult<EnvmonitorDTO> weatherInfo(HttpServletRequest request){
- EnvmonitorDTO dto = new EnvmonitorDTO();
- dto.setSectionList(toolUtils.getSectionList(request));
- EnvmonitorVO vo = envmonitorService.getDeviceCountBySectionList(dto);
- return BaseResult.success(vo);
- }
- /**
- * 获取广告列表
- * @param request
- * @return
- */
- @RequestMapping(value = "/screenList", method = RequestMethod.POST)
- public BaseResult<ScreenDTO> screenList(HttpServletRequest request){
- Integer page = request.getParameter("page") == null ? 1 : Integer.parseInt(request.getParameter("page"));
- Integer count = request.getParameter("count") == null ? 16 : Integer.parseInt(request.getParameter("count"));
- Integer online = request.getParameter("online") == null ? 0 : Integer.parseInt(request.getParameter("online"));
- ScreenDTO dto = new ScreenDTO();
- dto.setPage(count * (page - 1));
- dto.setCount(count);
- dto.setOnline(online);
- dto.setSectionList(toolUtils.getSectionList(request));
- ScreenVO vo = screenService.getScreenList(dto);
- return BaseResult.success(vo);
- }
- /**
- * 操作日志列表
- * @param request
- * @return
- */
- @RequestMapping(value = "/logList", method = RequestMethod.POST)
- public BaseResult<OperationLogDTO> logList(HttpServletRequest request){
- String keyword = request.getParameter("keyword") == null ? "" : request.getParameter("keyword");
- String username = request.getParameter("username") == null ? "" : request.getParameter("username");
- int page = request.getParameter("page") == null ? 1 : Integer.parseInt(request.getParameter("page"));
- int count = request.getParameter("count") == null ? 16 : Integer.parseInt(request.getParameter("count"));
- int operaType = request.getParameter("operaType") == null ? 0 : Integer.parseInt(request.getParameter("operaType"));
- int devType = request.getParameter("devType") == null ? 0 : Integer.parseInt(request.getParameter("devType"));
- OperationLogVO vo = new OperationLogVO();
- vo.setKeyword(keyword);
- vo.setOffset(count * (page - 1));
- vo.setLimit(count);
- vo.setOperaType(operaType);
- vo.setDevType(devType);
- vo.setUsername(username);
- OperationLogVO logVO = operationLogService.getLogListByVO(vo);
- return BaseResult.success(logVO);
- }
- /**
- * 删除日志信息
- * @param request
- * @return
- */
- @RequestMapping(value = "/delLog", method = RequestMethod.POST)
- public BaseResult delLog(HttpServletRequest request){
- Integer version = request.getParameter("version") == null ? 0 : Integer.parseInt(request.getParameter("version"));
- String logId = request.getParameter("logId");
- if (logId == null || logId.length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
- String[] split = logId.split(",");
- for (String id :split) {
- int l = Integer.parseInt(id);
- operationLogService.deleteLogListById(l);
- }
- return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
- }
- /**
- * 获取灯控日志信息
- * @param request
- * @return
- */
- @RequestMapping(value = "/lampDataHistory", method = RequestMethod.POST)
- public BaseResult lampDataHistory(HttpServletRequest request) throws ParseException {
- Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
- // List sectionList = toolUtils.getSectionList(request);lampId
- Integer lampId = (Integer) toolUtils.getRequestContent(request,"lampId",1);
- if (lampId == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
- LampInfoDTO detailsById = lampService.getDetailsById(lampId, version);
- if (detailsById == null) return toolUtils.response(InterfaceResultEnum.PARAM_FAIL,version);
- Integer dateType = (Integer) toolUtils.getRequestContent(request,"dateType",1);
- long l = System.currentTimeMillis()-detailsById.getTimezone()*3600*1000;
- Long startTime = 0L;
- Long endTime = 0L;
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- if (dateType == 0){ // 1 天
- startTime = l - 24*3600*1000;
- endTime = l;
- }else if (dateType == 1){ // 3 天
- startTime = l - 24*3600*1000*3;
- endTime = l;
- }else if (dateType == 2){ // 7 天
- startTime = l - 24*3600*1000*7;
- endTime = l;
- }else if (dateType == 3){ // 14 天
- startTime = l - 24*3600*1000*14;
- endTime = l;
- }else if (dateType == 4){ // 日期选择 最多30天
- String date = (String) toolUtils.getRequestContent(request,"date",2);
- if (date.length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_DATE_ERROR,version);
- List<String> split = Arrays.asList(date.split("/"));
- System.out.println(split.toString());
- System.out.println(split.get(0));
- System.out.println(split.get(1));
- startTime = simpleDateFormat.parse(split.get(0) + " 00:00:00").getTime();
- endTime = simpleDateFormat.parse(split.get(1) + " 23:59:59").getTime();
- if (endTime < startTime) toolUtils.response(InterfaceResultEnum.LACK_DATE_FORMAT_ERROR,version);
- if (endTime - startTime > 29*24*3600*1000) toolUtils.response(InterfaceResultEnum.LACK_DATE_RANGE_ERROR,version);
- startTime -= detailsById.getTimezone()*3600*1000;
- endTime -= detailsById.getTimezone()*3600*1000;
- }
- HashMap<String, Integer> objectObjectHashMap = new HashMap<>();
- Long timeT = startTime;
- int i = 0;
- ArrayList<Object> dateList = new ArrayList<>();
- ArrayList<Object> volList = new ArrayList<>();
- ArrayList<Object> curList = new ArrayList<>();
- ArrayList<Object> powerList = new ArrayList<>();
- ArrayList<Object> lightList = new ArrayList<>();
- ArrayList<LampInfoLogDTO> list = new ArrayList<>();
- simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:00:00");
- while (timeT < endTime){
- objectObjectHashMap.put(simpleDateFormat.format(new Date(timeT)).toString(),i);
- dateList.add(simpleDateFormat.format(new Date(timeT+detailsById.getTimezone()*3600*1000)).toString());
- volList.add(0);
- powerList.add(0);
- lightList.add(0);
- curList.add(0);
- list.add(null);
- timeT += 3600*1000;
- i ++;
- }
- SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- String startDate = simpleDateFormat.format(new Date(startTime));
- String endDate = simpleDateFormat.format(new Date(endTime));
- LampLogVO lampLogVO = new LampLogVO();
- lampLogVO.setLampId(lampId);
- lampLogVO.setStartDate(startDate);
- lampLogVO.setEndDate(endDate);
- List<LampInfoLogDTO> listByVO = lampInfoLogService.getListByVO(lampLogVO);
- for (LampInfoLogDTO lampInfoLogDTO :listByVO) {
- Date date = new Date(simpleDateFormat2.parse(lampInfoLogDTO.getUpdateTime()).getTime());
- String s = simpleDateFormat.format(date).toString();
- System.out.println(s);
- if (objectObjectHashMap.containsKey(s)){
- Integer integer = objectObjectHashMap.get(s);
- list.set(integer,lampInfoLogDTO);
- }
- }
- LampLogVO lampLogVO1 = new LampLogVO();
- Float maxCur = Float.valueOf(lampLogVO1.getMaxCur() == null ? "0" : lampLogVO1.getMaxCur());
- Float maxPower = Float.valueOf(lampLogVO1.getMaxPower() == null ? "0":lampLogVO1.getMaxPower());
- Integer maxLight = Integer.valueOf(lampLogVO1.getMaxLight() == null ? "0":lampLogVO1.getMaxLight());
- Float maxVol = Float.valueOf(lampLogVO1.getMaxVol()==null?"0":lampLogVO1.getMaxVol());
- ArrayList<Object> logList = new ArrayList<>();
- for (LampInfoLogDTO lampInfoLogDTO:list) {
- if (lampInfoLogDTO != null){
- Date date = new Date(simpleDateFormat2.parse(lampInfoLogDTO.getUpdateTime()).getTime());
- String s = simpleDateFormat.format(date).toString();
- System.out.println(s);
- Integer integer = null;
- if (objectObjectHashMap.containsKey(s)){
- integer = objectObjectHashMap.get(s);
- list.set(integer,lampInfoLogDTO);
- }
- if (lampInfoLogDTO.getCurrent() != null && !lampInfoLogDTO.getCurrent().equals("0") && integer != null){
- curList.set(integer,Float.valueOf(lampInfoLogDTO.getCurrent()));
- if (maxCur < Float.valueOf(lampInfoLogDTO.getCurrent()))maxCur = Float.valueOf(lampInfoLogDTO.getCurrent());
- }
- if (lampInfoLogDTO.getVoltage() != null && !lampInfoLogDTO.getVoltage().equals("0") && integer != null){
- volList.set(integer,Float.valueOf(lampInfoLogDTO.getVoltage()));
- if (maxVol < Float.valueOf(lampInfoLogDTO.getVoltage()))maxVol = Float.valueOf(lampInfoLogDTO.getVoltage());
- }
- if (lampInfoLogDTO.getDimValue() != null && !lampInfoLogDTO.getDimValue().equals("0") && integer != null){
- lightList.set(integer,Integer.valueOf(lampInfoLogDTO.getDimValue()));
- if (maxLight < Integer.valueOf(lampInfoLogDTO.getDimValue()))maxLight = Integer.valueOf(lampInfoLogDTO.getDimValue());
- }
- if (lampInfoLogDTO.getPower() != null && !lampInfoLogDTO.getPower().equals("0") && integer != null){
- powerList.set(integer,Float.valueOf(lampInfoLogDTO.getPower()));
- if (maxPower < Float.valueOf(lampInfoLogDTO.getPower()))maxPower = Float.valueOf(lampInfoLogDTO.getPower());
- }
- if (maxLight.intValue() < Integer.valueOf(lampInfoLogDTO.getDimValue()).intValue())maxLight = Integer.valueOf(lampInfoLogDTO.getDimValue());
- date = new Date(simpleDateFormat2.parse(lampInfoLogDTO.getUpdateTime()).getTime()+detailsById.getTimezone()*3600*1000);
- lampInfoLogDTO.setUpdateTime(simpleDateFormat.format(date).toString());
- logList.add(lampInfoLogDTO);
- }
- }
- lampLogVO1.setCurList(curList);
- lampLogVO1.setVolList(volList);
- lampLogVO1.setPowerList(powerList);
- lampLogVO1.setLightList(lightList);
- lampLogVO1.setDateList(dateList);
- lampLogVO1.setList(logList);
- lampLogVO1.setStep(3600);
- lampLogVO1.setMaxCur(maxCur.toString());
- lampLogVO1.setMaxLight(maxLight.toString());
- lampLogVO1.setMaxPower(maxPower.toString());
- lampLogVO1.setMaxVol(maxVol.toString());
- return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,lampLogVO1);
- }
- /**
- * 灯杆列表
- * @param request
- * @return
- */
- @RequestMapping(value = "/lampPoleList", method = RequestMethod.POST)
- public BaseResult lampPoleList(HttpServletRequest request) {
- Integer version = request.getParameter("version") == null ? 0 : Integer.parseInt(request.getParameter("version"));
- Integer isInspec = request.getParameter("isInspec") == null || request.getParameter("isInspec").length() == 0 ? null : Integer.parseInt(request.getParameter("isInspec"));
- String keyword = request.getParameter("keyword") == null ? "" : request.getParameter("keyword");
- List sectionList = toolUtils.getSectionList(request);
- Integer page = request.getParameter("page") == null ? 1 : Integer.parseInt(request.getParameter("page"));
- Integer count = request.getParameter("count") == null ? 16 : Integer.parseInt(request.getParameter("count"));
- Integer limit = count;
- Integer offset = (page-1)*count;
- LampPoleVO lampPoleVO = new LampPoleVO();
- lampPoleVO.setVersion(version);
- lampPoleVO.setSectionList(sectionList);
- lampPoleVO.setLimit(limit);
- lampPoleVO.setOffset(offset);
- if (isInspec != null) lampPoleVO.setIsInspec(isInspec);
- if (keyword != null && keyword.length() != 0) lampPoleVO.setKeyword(keyword);
- List<LampPoleDTO> lampPoleDTOS = lampPoleService.lampPoleList(lampPoleVO);
- ListResponseVO listResponseVO = new ListResponseVO();
- listResponseVO.setList(lampPoleDTOS);
- listResponseVO.setTotal(lampPoleService.lampPoleCount(lampPoleVO));
- return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,listResponseVO);
- }
- /**
- * 灯杆详情
- * @param request
- * @return
- */
- @RequestMapping(value = "/lampPoleInfo", method = RequestMethod.POST)
- public BaseResult lampPoleInfo(HttpServletRequest request) throws ParseException {
- Integer version = request.getParameter("version") == null ? 0 : Integer.parseInt(request.getParameter("version"));
- List sectionList = toolUtils.getSectionList(request);
- LampPoleVO lampPoleVO = new LampPoleVO();
- lampPoleVO.setSectionList(sectionList);
- List<LampPoleDTO> listByVO = lampPoleService.getListByVO(lampPoleVO);
- ArrayList<Integer> lampPoleIds = new ArrayList<>();
- lampPoleIds.add(0);
- for (LampPoleDTO l :listByVO) {
- lampPoleIds.add(l.getId());
- }
- Integer countByLampPoleIdList = lampPoleAlarmLogService.getCountByLampPoleIdList(lampPoleIds);
- LampPoleInfoVO lampPoleInfoVO = new LampPoleInfoVO();
- lampPoleInfoVO.setDeviceCount(listByVO.size());
- lampPoleInfoVO.setRunCount(listByVO.size()-countByLampPoleIdList);
- lampPoleInfoVO.setFaultCount(countByLampPoleIdList);
- int newCount = 0;
- for (LampPoleDTO l :listByVO) {
- if (l.getCreateTime() != null){
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- Date date = sdf.parse(l.getCreateTime());
- long time = date.getTime();
- if (System.currentTimeMillis() - time <= 3600*24*30*1000){
- newCount ++;
- }
- }
- }
- lampPoleInfoVO.setNewCount(newCount);
- lampPoleInfoVO.setDisableCount(0);
- return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,lampPoleInfoVO);
- }
- /**
- * 云盒气象站RS485设备信息列表
- * @param request
- * @return
- */
- @RequestMapping(value = "/GWRS485DevList",method = RequestMethod.POST)
- public BaseResult GWRS485DevList(HttpServletRequest request) {
- Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
- ArrayList<GWRSDevDTO> gWRSDevDTOS = new ArrayList<>();
- GWRSDevDTO gWRSDevDTO = new GWRSDevDTO();
- gWRSDevDTO.setId(1);
- gWRSDevDTO.setName("百叶箱 X 6");
- gWRSDevDTOS.add(gWRSDevDTO);
- gWRSDevDTO = new GWRSDevDTO();
- gWRSDevDTO.setId(2);
- gWRSDevDTO.setName("风向");
- gWRSDevDTOS.add(gWRSDevDTO);
- gWRSDevDTO = new GWRSDevDTO();
- gWRSDevDTO.setId(3);
- gWRSDevDTO.setName("风速");
- gWRSDevDTOS.add(gWRSDevDTO);
- gWRSDevDTO = new GWRSDevDTO();
- gWRSDevDTO.setId(4);
- gWRSDevDTO.setName("雨量");
- gWRSDevDTOS.add(gWRSDevDTO);
- gWRSDevDTO = new GWRSDevDTO();
- gWRSDevDTO.setId(5);
- gWRSDevDTO.setName("太阳辐射");
- gWRSDevDTOS.add(gWRSDevDTO);
- gWRSDevDTO = new GWRSDevDTO();
- gWRSDevDTO.setId(6);
- gWRSDevDTO.setName("百叶箱 X 10");
- gWRSDevDTOS.add(gWRSDevDTO);
- gWRSDevDTO = new GWRSDevDTO();
- gWRSDevDTO.setId(7);
- gWRSDevDTO.setName("超声波风速风向");
- gWRSDevDTOS.add(gWRSDevDTO);
- ListResponseVO listResponseVO = new ListResponseVO();
- listResponseVO.setList(gWRSDevDTOS);
- return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,listResponseVO);
- }
- }
|