123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456 |
- package com.welampiot.controller;
- import com.welampiot.common.BaseResult;
- import com.welampiot.common.InterfaceResultEnum;
- 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;
- @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 ? 0 : 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);
- 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<WifiInfoLogDTO> wifiOutStatistics(HttpServletRequest request){
- Integer id = request.getParameter("id") == null ? 0 : Integer.parseInt(request.getParameter("id"));
- Integer version = request.getParameter("version") == null ? 0 : Integer.parseInt(request.getParameter("version"));
- Integer dateType = request.getParameter("dateType") == null ? 0 : Integer.parseInt(request.getParameter("dateType"));
- Integer date = request.getParameter("date") == null ? 0 : Integer.parseInt(request.getParameter("date"));
- Integer dataType = request.getParameter("dataType") == null ? 0 : Integer.parseInt(request.getParameter("dataType"));
- WifiInfoLogDTO dto = new WifiInfoLogDTO();
- dto.setWifiId(id);
- dto.setDateType(dateType);
- dto.setDate(date);
- dto.setDataType(dataType);
- dto.setSectionList(toolUtils.getSectionList(request));
- WifiInfoLogVO vo = wifiInfoLogService.getWifiOutStatisticsByDTO(dto);
- if (vo == null) return toolUtils.response(InterfaceResultEnum.PARAM_FAIL,version);
- return BaseResult.success(vo);
- }
- /**
- * 获取气象站数据列表
- * @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);
- 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);
- }
- }
|