NewLampPoleController.java 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. package com.welampiot.controller;
  2. import com.welampiot.common.BaseResult;
  3. import com.welampiot.common.InterfaceResultEnum;
  4. import com.welampiot.dto.GWRSDevDTO;
  5. import com.welampiot.dto.*;
  6. import com.welampiot.service.*;
  7. import com.welampiot.utils.ToolUtils;
  8. import com.welampiot.vo.*;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.web.bind.annotation.CrossOrigin;
  11. import org.springframework.web.bind.annotation.RequestMapping;
  12. import org.springframework.web.bind.annotation.RequestMethod;
  13. import org.springframework.web.bind.annotation.RestController;
  14. import javax.servlet.http.HttpServletRequest;
  15. import java.text.ParseException;
  16. import java.text.SimpleDateFormat;
  17. import java.util.*;
  18. /**
  19. * ClassName: NewLampPoleController
  20. * Package: com.welampiot.controller
  21. * Description:
  22. *
  23. * @Author: zhj_Start
  24. * @Create: 2023/4/11 - 19:53
  25. * @Version: v1.0
  26. */
  27. @RestController
  28. @CrossOrigin
  29. @RequestMapping("/newLampPole")
  30. public class NewLampPoleController {
  31. @Autowired
  32. private WifiService wifiService;
  33. @Autowired
  34. private WifiInfoLogService wifiInfoLogService;
  35. @Autowired
  36. private EnvmonitorService envmonitorService;
  37. @Autowired
  38. private ScreenService screenService;
  39. @Autowired
  40. private ToolUtils toolUtils;
  41. @Autowired
  42. private LampPoleService lampPoleService;
  43. @Autowired
  44. private OperationLogService operationLogService;
  45. @Autowired
  46. private LampService lampService;
  47. @Autowired
  48. private LampInfoLogService lampInfoLogService;
  49. @Autowired
  50. private LampPoleAlarmLogService lampPoleAlarmLogService;
  51. @RequestMapping(value = "/info",method = RequestMethod.POST)
  52. public BaseResult info(HttpServletRequest request){
  53. Integer version = request.getParameter("version") == null ? 0 : Integer.parseInt(request.getParameter("version"));
  54. LampPoleInfoVO lampPoleInfoVO = new LampPoleInfoVO();
  55. List sectionList = toolUtils.getSectionList(request);
  56. LampPoleVO lampPoleVO = new LampPoleVO();
  57. lampPoleVO.setSectionList(sectionList);
  58. List<LampPoleDTO> listByVO = lampPoleService.getListByVO(lampPoleVO);
  59. lampPoleInfoVO.setDeviceCount(listByVO.size());
  60. lampPoleInfoVO.setRunCount(listByVO.size());
  61. lampPoleInfoVO.setWifiCount(listByVO.size());
  62. lampPoleInfoVO.setEmCount(0);
  63. for (LampPoleDTO l:listByVO) {
  64. // String devType = l.getDevType();
  65. // List split = Arrays.asList(devType.split(","));
  66. // if (split.contains("5")) lampPoleInfoVO.setEmCount(lampPoleInfoVO.getEmCount()+1);;
  67. }
  68. // $data['loopCount'] = $this->Loop_model->get_count(array('sectionid'=>$sectionId));
  69. // $id_arr = array_column($lampPoleList, 'id');
  70. // $temp_l = [];
  71. // if (!empty($id_arr)) {
  72. // $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';
  73. // $l_list = $this->db->query($sql)->result_array();
  74. // foreach ($l_list as $key => $value) {
  75. // // if ($value['status'] != 1 && $value['status'] != 0) continue;
  76. // $temp_l[$value['lamp_pole_id']] = $value;
  77. // }
  78. // }
  79. //
  80. // $lampPoleId = array();
  81. // foreach ($lampPoleList as $lampPole) {
  82. // $data['deviceCount'] += 1;
  83. // $data['runCount'] += 1;
  84. // if (time() - strtotime($lampPole['createtime']) <= 3600*24*30) {
  85. // $data['newCount'] += 1;
  86. // }
  87. // $typeArr = explode(',', $lampPole['devtype']);
  88. // if (in_array('0', $typeArr)) $data['lampCount'] += 1;
  89. // if (in_array('1', $typeArr)) $data['videoCount'] += 1;
  90. // if (in_array('2', $typeArr)) $data['wifiCount'] += 1;
  91. // if (in_array('4', $typeArr)) $data['screenCount'] += 1;
  92. // if (in_array('5', $typeArr)) $data['emCount'] += 1;
  93. // if (in_array('6', $typeArr)) $data['chargeCount'] += 1;
  94. // if (in_array('7', $typeArr)) $data['weatherCount'] += 1;
  95. // if (in_array('9', $typeArr)) $data['radioCount'] += 1;
  96. // if (in_array('14', $typeArr)) $data['waterImmersionCount'] += 1;
  97. // if (in_array('18', $typeArr)) $data['tiltCount'] += 1;
  98. // if (in_array('15', $typeArr)) $data['lockCount'] += 1;
  99. // if (isset($temp_l[$lampPole['id']])) {
  100. // $data['faultCount'] += 1;
  101. // $data['runCount'] -= 1;
  102. // }
  103. //
  104. // $lampPoleId[] = $lampPole['id'];
  105. // }
  106. //
  107. // if (!empty($lampPoleId)) {
  108. // // smart_lock_dev_info
  109. // $res = $this->db->query('select count(*) as total from smart_lock_dev_info where lamp_pole_id in ('.implode(',', $lampPoleId).')')->row_array();
  110. // $data['lockCount'] = intval($res['total']);
  111. //
  112. // $lampinfoList = $this->Lampinfo_model->get_list(array('lamp_pole_id'=>$lampPoleId),'id');
  113. // $lampId = array();
  114. // $data['lampCount'] = count($lampinfoList);
  115. // foreach ($lampinfoList as $l) {
  116. // $lampId[] = $l['id'];
  117. // }
  118. // if (!empty($lampId)) {
  119. // $join = array(
  120. // array('table'=>'lamp_info_log_new as t1','cond'=>'t1.updatetime = LI.updatetime AND t1.lampid = LI.lampid','type'=>'inner')
  121. // );
  122. // $sql = "select day_gener_energy,month_gener_energy,used_energy_total from lamp_info_log_new a where a.lampid in (".implode(',', $lampId).")";
  123. // $lampInfoLogList = $this->db->query($sql)->result_array();
  124. // foreach ($lampInfoLogList as $lampLog) {
  125. // $data['dayCom'] += $lampLog['day_gener_energy'];
  126. // $data['monthCom'] += $lampLog['month_gener_energy'];
  127. // $data['totalCom'] += $lampLog['used_energy_total'];
  128. // }
  129. // }
  130. // }
  131. // $data['dayCom'] = round($data['dayCom'],1);
  132. // $data['monthCom'] = round($data['monthCom'],1);
  133. // $data['totalCom'] = round($data['totalCom'],1);
  134. return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,lampPoleInfoVO);
  135. }
  136. /**
  137. * 获取云盒列表
  138. * @param request
  139. * @return
  140. */
  141. @RequestMapping(value = "/wifiList", method = RequestMethod.POST)
  142. public BaseResult<WifiDTO> wifiList(HttpServletRequest request){
  143. Integer page = request.getParameter("page") == null ? 1 : Integer.parseInt(request.getParameter("page"));
  144. Integer count = request.getParameter("count") == null ? 16 : Integer.parseInt(request.getParameter("count"));
  145. Integer online = request.getParameter("online") == null || request.getParameter("online").length() == 0 ? null : Integer.parseInt(request.getParameter("online"));
  146. String keyword = request.getParameter("keyword") == null ? "" : request.getParameter("keyword");
  147. WifiDTO dto = new WifiDTO();
  148. dto.setPage(count * (page - 1));
  149. dto.setCount(count);
  150. dto.setKeyword(keyword);
  151. if (online != null) dto.setOnlineState(online);
  152. dto.setSectionList(toolUtils.getSectionList(request));
  153. WifiVO vo = wifiService.getWifiList(dto);
  154. return BaseResult.success(vo);
  155. }
  156. /**
  157. * 获取云盒数据概览
  158. * @param request
  159. * @return
  160. */
  161. @RequestMapping(value = "/wifiInfo", method = RequestMethod.POST)
  162. public BaseResult<WifiDTO> wifiInfo(HttpServletRequest request){
  163. WifiDTO dto = new WifiDTO();
  164. dto.setSectionList(toolUtils.getSectionList(request));
  165. WifiVO vo = wifiService.getWifiInfo(dto);
  166. return BaseResult.success(vo);
  167. }
  168. /**
  169. * 获取云盒电源设置
  170. * @param request
  171. * @return
  172. */
  173. @RequestMapping(value = "/wifiOutInfo", method = RequestMethod.POST)
  174. public BaseResult<WifiDTO> wifiOutInfo(HttpServletRequest request){
  175. Integer version = request.getParameter("version") == null ? 0 : Integer.parseInt(request.getParameter("version"));
  176. Integer id = request.getParameter("id") == null ? 0 : Integer.parseInt(request.getParameter("id"));
  177. WifiOutInfoVO vo = wifiService.getWifiOutInfo(id, toolUtils.getSectionList(request));
  178. if (vo == null) return toolUtils.response(InterfaceResultEnum.PARAM_FAIL,version);
  179. return BaseResult.success(vo);
  180. }
  181. /**
  182. * 获取云盒输出统计数据
  183. * @param request
  184. * @return
  185. */
  186. @RequestMapping(value = "/wifiOutStatistics", method = RequestMethod.POST)
  187. public BaseResult wifiOutStatistics(HttpServletRequest request) throws ParseException {
  188. int version = request.getParameter("version") == null ? 0 : Integer.parseInt(request.getParameter("version"));
  189. int id = request.getParameter("id") == null ? 0 : Integer.parseInt(request.getParameter("id"));
  190. if (id == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
  191. int dateType = request.getParameter("dateType") == null ? 0 : Integer.parseInt(request.getParameter("dateType"));
  192. int dataType = request.getParameter("dataType") == null ? 0 : Integer.parseInt(request.getParameter("dataType"));
  193. WifiInfoLogDTO dto = new WifiInfoLogDTO();
  194. dto.setWifiId(id);
  195. dto.setDataType(dataType);
  196. Integer timezone = wifiInfoLogService.getTimezoneById(dto);
  197. if (timezone == null) return toolUtils.response(InterfaceResultEnum.PARAM_FAIL,version);
  198. long l = System.currentTimeMillis() - timezone * 3600 * 1000;
  199. long startTime = 0L;
  200. long endTime = 0L;
  201. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  202. if (dateType == 0){ // 1 天
  203. startTime = l - 24 * 3600 * 1000;
  204. endTime = l;
  205. }else if (dateType == 1){ // 3 天
  206. startTime = l - 24 * 3600 * 1000 * 3;
  207. endTime = l;
  208. }else if (dateType == 2){ // 7 天
  209. startTime = l - 24 * 3600 * 1000 * 7;
  210. endTime = l;
  211. }else if (dateType == 3){ // 14 天
  212. startTime = l - 24 * 3600 * 1000 * 14;
  213. endTime = l;
  214. }else if (dateType == 4){ // 日期选择 最多30天
  215. String date = (String) toolUtils.getRequestContent(request,"date",2);
  216. if (date.length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_DATE_ERROR,version);
  217. List<String> split = Arrays.asList(date.split("/"));
  218. System.out.println(split);
  219. System.out.println(split.get(0));
  220. System.out.println(split.get(1));
  221. try {
  222. startTime = simpleDateFormat.parse(split.get(0) + " 00:00:00").getTime();
  223. } catch (ParseException e) {
  224. throw new RuntimeException(e);
  225. }
  226. endTime = simpleDateFormat.parse(split.get(1) + " 23:59:59").getTime();
  227. if (endTime < startTime) toolUtils.response(InterfaceResultEnum.LACK_DATE_FORMAT_ERROR,version);
  228. if (endTime - startTime > 29L * 24 * 3600 * 1000) toolUtils.response(InterfaceResultEnum.LACK_DATE_RANGE_ERROR,version);
  229. startTime -= timezone * 3600 * 1000;
  230. endTime -= timezone * 3600 * 1000;
  231. }
  232. HashMap<String, Integer> objectObjectHashMap = new HashMap<>();
  233. long timeT = startTime;
  234. int i = 0;
  235. List<Object> dateList = new ArrayList<>();
  236. List<Object> volList = new ArrayList<>();
  237. List<Object> curList = new ArrayList<>();
  238. List<Object> powerList = new ArrayList<>();
  239. List<Object> comList = new ArrayList<>();
  240. List<WifiInfoLogDTO> list = new ArrayList<>();
  241. simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:00:00");
  242. while (timeT < endTime){
  243. objectObjectHashMap.put(simpleDateFormat.format(new Date(timeT)),i);
  244. dateList.add(simpleDateFormat.format(new Date(timeT + timezone * 3600 * 1000)));
  245. volList.add(0);
  246. powerList.add(0);
  247. comList.add(0);
  248. curList.add(0);
  249. list.add(null);
  250. timeT += 3600 * 1000;
  251. i ++;
  252. }
  253. SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  254. String startDate = simpleDateFormat.format(new Date(startTime));
  255. String endDate = simpleDateFormat.format(new Date(endTime));
  256. dto.setStartDate(startDate);
  257. dto.setEndDate(endDate);
  258. List<WifiInfoLogDTO> wifiOutStatisticsByDTO = wifiInfoLogService.getWifiOutStatisticsByDTO(dto);
  259. for (WifiInfoLogDTO wifiInfoLogDTO : wifiOutStatisticsByDTO) {
  260. Date date = new Date(simpleDateFormat2.parse(wifiInfoLogDTO.getUpdateTime()).getTime());
  261. String s = simpleDateFormat.format(date);
  262. if (objectObjectHashMap.containsKey(s)){
  263. Integer integer = objectObjectHashMap.get(s);
  264. list.set(integer,wifiInfoLogDTO);
  265. }
  266. }
  267. for (WifiInfoLogDTO wifiInfoLogDTO : list) {
  268. if (wifiInfoLogDTO != null){
  269. Date date = new Date(simpleDateFormat2.parse(wifiInfoLogDTO.getUpdateTime()).getTime());
  270. String s = simpleDateFormat.format(date);
  271. Integer integer = null;
  272. if (objectObjectHashMap.containsKey(s)){
  273. integer = objectObjectHashMap.get(s);
  274. list.set(integer,wifiInfoLogDTO);
  275. }
  276. if (dto.getDataType() != null){
  277. switch (dto.getDataType()){
  278. case 5:
  279. if (wifiInfoLogDTO.getCurrentC() != null && !wifiInfoLogDTO.getCurrentC().equals("0") && integer != null) {
  280. curList.set(integer, Float.valueOf(wifiInfoLogDTO.getCurrentC()));
  281. }
  282. if (wifiInfoLogDTO.getVoltageC() != null && !wifiInfoLogDTO.getVoltageC().equals("0") && integer != null) {
  283. volList.set(integer, Float.valueOf(wifiInfoLogDTO.getVoltageC()));
  284. }
  285. if (wifiInfoLogDTO.getPowerC() != null && !wifiInfoLogDTO.getPowerC().equals("0")&& integer != null) {
  286. powerList.set(integer, Float.valueOf(wifiInfoLogDTO.getPowerC()));
  287. }
  288. if (wifiInfoLogDTO.getTotalComC() != null && !wifiInfoLogDTO.getTotalComC().equals("0") && integer != null) {
  289. comList.set(integer, Float.valueOf(wifiInfoLogDTO.getTotalComC()));
  290. }
  291. break;
  292. case 4:
  293. if (wifiInfoLogDTO.getCurrentB() != null && !wifiInfoLogDTO.getCurrentB().equals("0") && integer != null) {
  294. curList.set(integer, Float.valueOf(wifiInfoLogDTO.getCurrentB()));
  295. }
  296. if (wifiInfoLogDTO.getVoltageB() != null && !wifiInfoLogDTO.getVoltageB().equals("0") && integer != null) {
  297. volList.set(integer, Float.valueOf(wifiInfoLogDTO.getVoltageB()));
  298. }
  299. if (wifiInfoLogDTO.getPowerB() != null && !wifiInfoLogDTO.getPowerB().equals("0") && integer != null) {
  300. powerList.set(integer, Float.valueOf(wifiInfoLogDTO.getPowerB()));
  301. }
  302. if (wifiInfoLogDTO.getTotalComB() != null &&! wifiInfoLogDTO.getTotalComB().equals("0") && integer != null) {
  303. comList.set(integer, Float.valueOf(wifiInfoLogDTO.getTotalComB()));
  304. }
  305. break;
  306. case 3 :
  307. if (wifiInfoLogDTO.getLna3Cur() != null && !wifiInfoLogDTO.getLna3Cur().equals("0") && integer != null){
  308. curList.set(integer,Float.valueOf(wifiInfoLogDTO.getLna3Cur()));
  309. }
  310. if (wifiInfoLogDTO.getLna3Vol() != null && !wifiInfoLogDTO.getLna3Vol().equals("0") && integer != null){
  311. volList.set(integer,Float.valueOf(wifiInfoLogDTO.getLna3Vol()));
  312. }
  313. break;
  314. case 2 :
  315. if (wifiInfoLogDTO.getLna2Cur() != null && !wifiInfoLogDTO.getLna2Cur().equals("0") && integer != null){
  316. curList.set(integer,Float.valueOf(wifiInfoLogDTO.getLna2Cur()));
  317. }
  318. if (wifiInfoLogDTO.getLna2Vol() != null && !wifiInfoLogDTO.getLna2Vol().equals("0") && integer != null){
  319. volList.set(integer,Float.valueOf(wifiInfoLogDTO.getLna2Vol()));
  320. }
  321. break;
  322. case 1 :
  323. if (wifiInfoLogDTO.getLna1Cur() != null && !wifiInfoLogDTO.getLna1Cur().equals("0") && integer != null){
  324. curList.set(integer,Float.valueOf(wifiInfoLogDTO.getLna1Cur()));
  325. }
  326. if (wifiInfoLogDTO.getLna1Vol() != null && !wifiInfoLogDTO.getLna1Vol().equals("0") && integer != null){
  327. volList.set(integer,Float.valueOf(wifiInfoLogDTO.getLna1Vol()));
  328. }
  329. break;
  330. case 0 :
  331. if (wifiInfoLogDTO.getCurrent() != null && !wifiInfoLogDTO.getCurrent().equals("0") && integer != null){
  332. curList.set(integer,Float.valueOf(wifiInfoLogDTO.getCurrent()));
  333. }
  334. if (wifiInfoLogDTO.getVoltage() != null && !wifiInfoLogDTO.getVoltage().equals("0") && integer != null){
  335. volList.set(integer,Float.valueOf(wifiInfoLogDTO.getVoltage()));
  336. }
  337. if (wifiInfoLogDTO.getPower() != null && !wifiInfoLogDTO.getPower().equals("0") && integer != null){
  338. powerList.set(integer,Float.valueOf(wifiInfoLogDTO.getPower()));
  339. }
  340. if (wifiInfoLogDTO.getTotalComA() != null && !wifiInfoLogDTO.getTotalComA().equals("0") && integer != null){
  341. comList.set(integer,Float.valueOf(wifiInfoLogDTO.getTotalComA()));
  342. }
  343. break;
  344. }
  345. }
  346. date = new Date(simpleDateFormat2.parse(wifiInfoLogDTO.getUpdateTime()).getTime() + timezone * 3600 * 1000);
  347. wifiInfoLogDTO.setUpdateTime(simpleDateFormat.format(date));
  348. }
  349. }
  350. WifiInfoLogVO wifiInfoLogVO = new WifiInfoLogVO();
  351. wifiInfoLogVO.setCurArr(curList);
  352. wifiInfoLogVO.setVolArr(volList);
  353. wifiInfoLogVO.setPowerArr(powerList);
  354. wifiInfoLogVO.setDateArr(dateList);
  355. wifiInfoLogVO.setComArr(comList);
  356. return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,wifiInfoLogVO);
  357. }
  358. /**
  359. * 获取气象站数据列表
  360. * @param request
  361. * @return
  362. */
  363. @RequestMapping(value = "/weatherList", method = RequestMethod.POST)
  364. public BaseResult<EnvmonitorDTO> weatherList(HttpServletRequest request){
  365. Integer page = request.getParameter("page") == null ? 1 : Integer.parseInt(request.getParameter("page"));
  366. Integer count = request.getParameter("count") == null ? 16 : Integer.parseInt(request.getParameter("count"));
  367. Integer online = request.getParameter("online") == null ? 0 : Integer.parseInt(request.getParameter("online"));
  368. EnvmonitorDTO dto = new EnvmonitorDTO();
  369. dto.setPage(count * (page - 1));
  370. dto.setCount(count);
  371. dto.setOnline(online);
  372. dto.setSectionList(toolUtils.getSectionList(request));
  373. EnvmonitorVO vo = envmonitorService.getWeatherList(dto);
  374. return BaseResult.success(vo);
  375. }
  376. /**
  377. * 获取气象站概览数据
  378. * @param request
  379. * @return
  380. */
  381. @RequestMapping(value = "/weatherInfo", method = RequestMethod.POST,produces = "application/json;charset=utf-8")
  382. public BaseResult<EnvmonitorDTO> weatherInfo(HttpServletRequest request){
  383. EnvmonitorDTO dto = new EnvmonitorDTO();
  384. dto.setSectionList(toolUtils.getSectionList(request));
  385. EnvmonitorVO vo = envmonitorService.getDeviceCountBySectionList(dto);
  386. return BaseResult.success(vo);
  387. }
  388. /**
  389. * 获取广告列表
  390. * @param request
  391. * @return
  392. */
  393. @RequestMapping(value = "/screenList", method = RequestMethod.POST)
  394. public BaseResult<ScreenDTO> screenList(HttpServletRequest request){
  395. Integer page = request.getParameter("page") == null ? 1 : Integer.parseInt(request.getParameter("page"));
  396. Integer count = request.getParameter("count") == null ? 16 : Integer.parseInt(request.getParameter("count"));
  397. Integer online = request.getParameter("online") == null ? 0 : Integer.parseInt(request.getParameter("online"));
  398. ScreenDTO dto = new ScreenDTO();
  399. dto.setPage(count * (page - 1));
  400. dto.setCount(count);
  401. dto.setOnline(online);
  402. dto.setSectionList(toolUtils.getSectionList(request));
  403. ScreenVO vo = screenService.getScreenList(dto);
  404. return BaseResult.success(vo);
  405. }
  406. /**
  407. * 操作日志列表
  408. * @param request
  409. * @return
  410. */
  411. @RequestMapping(value = "/logList", method = RequestMethod.POST)
  412. public BaseResult<OperationLogDTO> logList(HttpServletRequest request){
  413. String keyword = request.getParameter("keyword") == null ? "" : request.getParameter("keyword");
  414. String username = request.getParameter("username") == null ? "" : request.getParameter("username");
  415. int page = request.getParameter("page") == null ? 1 : Integer.parseInt(request.getParameter("page"));
  416. int count = request.getParameter("count") == null ? 16 : Integer.parseInt(request.getParameter("count"));
  417. int operaType = request.getParameter("operaType") == null ? 0 : Integer.parseInt(request.getParameter("operaType"));
  418. int devType = request.getParameter("devType") == null ? 0 : Integer.parseInt(request.getParameter("devType"));
  419. OperationLogVO vo = new OperationLogVO();
  420. vo.setKeyword(keyword);
  421. vo.setOffset(count * (page - 1));
  422. vo.setLimit(count);
  423. vo.setOperaType(operaType);
  424. vo.setDevType(devType);
  425. vo.setUsername(username);
  426. OperationLogVO logVO = operationLogService.getLogListByVO(vo);
  427. return BaseResult.success(logVO);
  428. }
  429. /**
  430. * 删除日志信息
  431. * @param request
  432. * @return
  433. */
  434. @RequestMapping(value = "/delLog", method = RequestMethod.POST)
  435. public BaseResult delLog(HttpServletRequest request){
  436. Integer version = request.getParameter("version") == null ? 0 : Integer.parseInt(request.getParameter("version"));
  437. String logId = request.getParameter("logId");
  438. if (logId == null || logId.length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
  439. String[] split = logId.split(",");
  440. for (String id :split) {
  441. int l = Integer.parseInt(id);
  442. operationLogService.deleteLogListById(l);
  443. }
  444. return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
  445. }
  446. /**
  447. * 获取灯控日志信息
  448. * @param request
  449. * @return
  450. */
  451. @RequestMapping(value = "/lampDataHistory", method = RequestMethod.POST)
  452. public BaseResult lampDataHistory(HttpServletRequest request) throws ParseException {
  453. Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
  454. // List sectionList = toolUtils.getSectionList(request);lampId
  455. Integer lampId = (Integer) toolUtils.getRequestContent(request,"lampId",1);
  456. if (lampId == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
  457. LampInfoDTO detailsById = lampService.getDetailsById(lampId, version);
  458. if (detailsById == null) return toolUtils.response(InterfaceResultEnum.PARAM_FAIL,version);
  459. Integer dateType = (Integer) toolUtils.getRequestContent(request,"dateType",1);
  460. long l = System.currentTimeMillis()-detailsById.getTimezone()*3600*1000;
  461. Long startTime = 0L;
  462. Long endTime = 0L;
  463. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  464. if (dateType == 0){ // 1 天
  465. startTime = l - 24*3600*1000;
  466. endTime = l;
  467. }else if (dateType == 1){ // 3 天
  468. startTime = l - 24*3600*1000*3;
  469. endTime = l;
  470. }else if (dateType == 2){ // 7 天
  471. startTime = l - 24*3600*1000*7;
  472. endTime = l;
  473. }else if (dateType == 3){ // 14 天
  474. startTime = l - 24*3600*1000*14;
  475. endTime = l;
  476. }else if (dateType == 4){ // 日期选择 最多30天
  477. String date = (String) toolUtils.getRequestContent(request,"date",2);
  478. if (date.length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_DATE_ERROR,version);
  479. List<String> split = Arrays.asList(date.split("/"));
  480. System.out.println(split.toString());
  481. System.out.println(split.get(0));
  482. System.out.println(split.get(1));
  483. startTime = simpleDateFormat.parse(split.get(0) + " 00:00:00").getTime();
  484. endTime = simpleDateFormat.parse(split.get(1) + " 23:59:59").getTime();
  485. if (endTime < startTime) toolUtils.response(InterfaceResultEnum.LACK_DATE_FORMAT_ERROR,version);
  486. if (endTime - startTime > 29*24*3600*1000) toolUtils.response(InterfaceResultEnum.LACK_DATE_RANGE_ERROR,version);
  487. startTime -= detailsById.getTimezone()*3600*1000;
  488. endTime -= detailsById.getTimezone()*3600*1000;
  489. }
  490. HashMap<String, Integer> objectObjectHashMap = new HashMap<>();
  491. Long timeT = startTime;
  492. int i = 0;
  493. ArrayList<Object> dateList = new ArrayList<>();
  494. ArrayList<Object> volList = new ArrayList<>();
  495. ArrayList<Object> curList = new ArrayList<>();
  496. ArrayList<Object> powerList = new ArrayList<>();
  497. ArrayList<Object> lightList = new ArrayList<>();
  498. ArrayList<LampInfoLogDTO> list = new ArrayList<>();
  499. simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:00:00");
  500. while (timeT < endTime){
  501. objectObjectHashMap.put(simpleDateFormat.format(new Date(timeT)).toString(),i);
  502. dateList.add(simpleDateFormat.format(new Date(timeT+detailsById.getTimezone()*3600*1000)).toString());
  503. volList.add(0);
  504. powerList.add(0);
  505. lightList.add(0);
  506. curList.add(0);
  507. list.add(null);
  508. timeT += 3600*1000;
  509. i ++;
  510. }
  511. SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  512. String startDate = simpleDateFormat.format(new Date(startTime));
  513. String endDate = simpleDateFormat.format(new Date(endTime));
  514. LampLogVO lampLogVO = new LampLogVO();
  515. lampLogVO.setLampId(lampId);
  516. lampLogVO.setStartDate(startDate);
  517. lampLogVO.setEndDate(endDate);
  518. List<LampInfoLogDTO> listByVO = lampInfoLogService.getListByVO(lampLogVO);
  519. for (LampInfoLogDTO lampInfoLogDTO :listByVO) {
  520. Date date = new Date(simpleDateFormat2.parse(lampInfoLogDTO.getUpdateTime()).getTime());
  521. String s = simpleDateFormat.format(date).toString();
  522. System.out.println(s);
  523. if (objectObjectHashMap.containsKey(s)){
  524. Integer integer = objectObjectHashMap.get(s);
  525. list.set(integer,lampInfoLogDTO);
  526. }
  527. }
  528. LampLogVO lampLogVO1 = new LampLogVO();
  529. Float maxCur = Float.valueOf(lampLogVO1.getMaxCur() == null ? "0" : lampLogVO1.getMaxCur());
  530. Float maxPower = Float.valueOf(lampLogVO1.getMaxPower() == null ? "0":lampLogVO1.getMaxPower());
  531. Integer maxLight = Integer.valueOf(lampLogVO1.getMaxLight() == null ? "0":lampLogVO1.getMaxLight());
  532. Float maxVol = Float.valueOf(lampLogVO1.getMaxVol()==null?"0":lampLogVO1.getMaxVol());
  533. ArrayList<Object> logList = new ArrayList<>();
  534. for (LampInfoLogDTO lampInfoLogDTO:list) {
  535. if (lampInfoLogDTO != null){
  536. Date date = new Date(simpleDateFormat2.parse(lampInfoLogDTO.getUpdateTime()).getTime());
  537. String s = simpleDateFormat.format(date).toString();
  538. System.out.println(s);
  539. Integer integer = null;
  540. if (objectObjectHashMap.containsKey(s)){
  541. integer = objectObjectHashMap.get(s);
  542. list.set(integer,lampInfoLogDTO);
  543. }
  544. if (lampInfoLogDTO.getCurrent() != null && !lampInfoLogDTO.getCurrent().equals("0") && integer != null){
  545. curList.set(integer,Float.valueOf(lampInfoLogDTO.getCurrent()));
  546. if (maxCur < Float.valueOf(lampInfoLogDTO.getCurrent()))maxCur = Float.valueOf(lampInfoLogDTO.getCurrent());
  547. }
  548. if (lampInfoLogDTO.getVoltage() != null && !lampInfoLogDTO.getVoltage().equals("0") && integer != null){
  549. volList.set(integer,Float.valueOf(lampInfoLogDTO.getVoltage()));
  550. if (maxVol < Float.valueOf(lampInfoLogDTO.getVoltage()))maxVol = Float.valueOf(lampInfoLogDTO.getVoltage());
  551. }
  552. if (lampInfoLogDTO.getDimValue() != null && !lampInfoLogDTO.getDimValue().equals("0") && integer != null){
  553. lightList.set(integer,Integer.valueOf(lampInfoLogDTO.getDimValue()));
  554. if (maxLight < Integer.valueOf(lampInfoLogDTO.getDimValue()))maxLight = Integer.valueOf(lampInfoLogDTO.getDimValue());
  555. }
  556. if (lampInfoLogDTO.getPower() != null && !lampInfoLogDTO.getPower().equals("0") && integer != null){
  557. powerList.set(integer,Float.valueOf(lampInfoLogDTO.getPower()));
  558. if (maxPower < Float.valueOf(lampInfoLogDTO.getPower()))maxPower = Float.valueOf(lampInfoLogDTO.getPower());
  559. }
  560. if (maxLight.intValue() < Integer.valueOf(lampInfoLogDTO.getDimValue()).intValue())maxLight = Integer.valueOf(lampInfoLogDTO.getDimValue());
  561. date = new Date(simpleDateFormat2.parse(lampInfoLogDTO.getUpdateTime()).getTime()+detailsById.getTimezone()*3600*1000);
  562. lampInfoLogDTO.setUpdateTime(simpleDateFormat.format(date).toString());
  563. logList.add(lampInfoLogDTO);
  564. }
  565. }
  566. lampLogVO1.setCurList(curList);
  567. lampLogVO1.setVolList(volList);
  568. lampLogVO1.setPowerList(powerList);
  569. lampLogVO1.setLightList(lightList);
  570. lampLogVO1.setDateList(dateList);
  571. lampLogVO1.setList(logList);
  572. lampLogVO1.setStep(3600);
  573. lampLogVO1.setMaxCur(maxCur.toString());
  574. lampLogVO1.setMaxLight(maxLight.toString());
  575. lampLogVO1.setMaxPower(maxPower.toString());
  576. lampLogVO1.setMaxVol(maxVol.toString());
  577. return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,lampLogVO1);
  578. }
  579. /**
  580. * 灯杆列表
  581. * @param request
  582. * @return
  583. */
  584. @RequestMapping(value = "/lampPoleList", method = RequestMethod.POST)
  585. public BaseResult lampPoleList(HttpServletRequest request) {
  586. Integer version = request.getParameter("version") == null ? 0 : Integer.parseInt(request.getParameter("version"));
  587. Integer isInspec = request.getParameter("isInspec") == null || request.getParameter("isInspec").length() == 0 ? null : Integer.parseInt(request.getParameter("isInspec"));
  588. String keyword = request.getParameter("keyword") == null ? "" : request.getParameter("keyword");
  589. List sectionList = toolUtils.getSectionList(request);
  590. Integer page = request.getParameter("page") == null ? 1 : Integer.parseInt(request.getParameter("page"));
  591. Integer count = request.getParameter("count") == null ? 16 : Integer.parseInt(request.getParameter("count"));
  592. Integer limit = count;
  593. Integer offset = (page-1)*count;
  594. LampPoleVO lampPoleVO = new LampPoleVO();
  595. lampPoleVO.setVersion(version);
  596. lampPoleVO.setSectionList(sectionList);
  597. lampPoleVO.setLimit(limit);
  598. lampPoleVO.setOffset(offset);
  599. if (isInspec != null) lampPoleVO.setIsInspec(isInspec);
  600. if (keyword != null && keyword.length() != 0) lampPoleVO.setKeyword(keyword);
  601. List<LampPoleDTO> lampPoleDTOS = lampPoleService.lampPoleList(lampPoleVO);
  602. ListResponseVO listResponseVO = new ListResponseVO();
  603. listResponseVO.setList(lampPoleDTOS);
  604. listResponseVO.setTotal(lampPoleService.lampPoleCount(lampPoleVO));
  605. return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,listResponseVO);
  606. }
  607. /**
  608. * 灯杆详情
  609. * @param request
  610. * @return
  611. */
  612. @RequestMapping(value = "/lampPoleInfo", method = RequestMethod.POST)
  613. public BaseResult lampPoleInfo(HttpServletRequest request) throws ParseException {
  614. Integer version = request.getParameter("version") == null ? 0 : Integer.parseInt(request.getParameter("version"));
  615. List sectionList = toolUtils.getSectionList(request);
  616. LampPoleVO lampPoleVO = new LampPoleVO();
  617. lampPoleVO.setSectionList(sectionList);
  618. List<LampPoleDTO> listByVO = lampPoleService.getListByVO(lampPoleVO);
  619. ArrayList<Integer> lampPoleIds = new ArrayList<>();
  620. lampPoleIds.add(0);
  621. for (LampPoleDTO l :listByVO) {
  622. lampPoleIds.add(l.getId());
  623. }
  624. Integer countByLampPoleIdList = lampPoleAlarmLogService.getCountByLampPoleIdList(lampPoleIds);
  625. LampPoleInfoVO lampPoleInfoVO = new LampPoleInfoVO();
  626. lampPoleInfoVO.setDeviceCount(listByVO.size());
  627. lampPoleInfoVO.setRunCount(listByVO.size()-countByLampPoleIdList);
  628. lampPoleInfoVO.setFaultCount(countByLampPoleIdList);
  629. int newCount = 0;
  630. for (LampPoleDTO l :listByVO) {
  631. if (l.getCreateTime() != null){
  632. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  633. Date date = sdf.parse(l.getCreateTime());
  634. long time = date.getTime();
  635. if (System.currentTimeMillis() - time <= 3600*24*30*1000){
  636. newCount ++;
  637. }
  638. }
  639. }
  640. lampPoleInfoVO.setNewCount(newCount);
  641. lampPoleInfoVO.setDisableCount(0);
  642. return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,lampPoleInfoVO);
  643. }
  644. /**
  645. * 云盒气象站RS485设备信息列表
  646. * @param request
  647. * @return
  648. */
  649. @RequestMapping(value = "/GWRS485DevList",method = RequestMethod.POST)
  650. public BaseResult GWRS485DevList(HttpServletRequest request) {
  651. Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
  652. ArrayList<GWRSDevDTO> gWRSDevDTOS = new ArrayList<>();
  653. GWRSDevDTO gWRSDevDTO = new GWRSDevDTO();
  654. gWRSDevDTO.setId(1);
  655. gWRSDevDTO.setName("百叶箱 X 6");
  656. gWRSDevDTOS.add(gWRSDevDTO);
  657. gWRSDevDTO = new GWRSDevDTO();
  658. gWRSDevDTO.setId(2);
  659. gWRSDevDTO.setName("风向");
  660. gWRSDevDTOS.add(gWRSDevDTO);
  661. gWRSDevDTO = new GWRSDevDTO();
  662. gWRSDevDTO.setId(3);
  663. gWRSDevDTO.setName("风速");
  664. gWRSDevDTOS.add(gWRSDevDTO);
  665. gWRSDevDTO = new GWRSDevDTO();
  666. gWRSDevDTO.setId(4);
  667. gWRSDevDTO.setName("雨量");
  668. gWRSDevDTOS.add(gWRSDevDTO);
  669. gWRSDevDTO = new GWRSDevDTO();
  670. gWRSDevDTO.setId(5);
  671. gWRSDevDTO.setName("太阳辐射");
  672. gWRSDevDTOS.add(gWRSDevDTO);
  673. gWRSDevDTO = new GWRSDevDTO();
  674. gWRSDevDTO.setId(6);
  675. gWRSDevDTO.setName("百叶箱 X 10");
  676. gWRSDevDTOS.add(gWRSDevDTO);
  677. gWRSDevDTO = new GWRSDevDTO();
  678. gWRSDevDTO.setId(7);
  679. gWRSDevDTO.setName("超声波风速风向");
  680. gWRSDevDTOS.add(gWRSDevDTO);
  681. ListResponseVO listResponseVO = new ListResponseVO();
  682. listResponseVO.setList(gWRSDevDTOS);
  683. return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,listResponseVO);
  684. }
  685. }