DataController.java 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. package com.welampiot.controller;
  2. import com.welampiot.common.BaseResult;
  3. import com.welampiot.common.InterfaceResultEnum;
  4. import com.welampiot.dto.*;
  5. import com.welampiot.service.*;
  6. import com.welampiot.utils.ExcelUtil;
  7. import com.welampiot.utils.ToolUtils;
  8. import com.welampiot.utils.WeatherUtil;
  9. import com.welampiot.utils.WebUtils;
  10. import com.welampiot.vo.*;
  11. import org.apache.commons.lang3.StringUtils;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.web.bind.annotation.CrossOrigin;
  14. import org.springframework.web.bind.annotation.RequestMapping;
  15. import org.springframework.web.bind.annotation.RequestMethod;
  16. import org.springframework.web.bind.annotation.RestController;
  17. import javax.servlet.http.HttpServletRequest;
  18. import java.text.DecimalFormat;
  19. import java.text.ParseException;
  20. import java.text.SimpleDateFormat;
  21. import java.time.YearMonth;
  22. import java.util.*;
  23. @RestController
  24. @CrossOrigin
  25. @RequestMapping("/data")
  26. public class DataController {
  27. @Autowired
  28. private LampService lampService;
  29. @Autowired
  30. private ToolUtils toolUtils;
  31. @Autowired
  32. private SectionService sectionService;
  33. @Autowired
  34. private LampPoleService lampPoleService;
  35. @Autowired
  36. private AllAlarmInfoLogService alarmInfoLogService;
  37. @Autowired
  38. private VideoMonitorService videoMonitorService;
  39. @Autowired
  40. private UserService userService;
  41. @Autowired
  42. private OperationLogService operationLogService;
  43. @Autowired
  44. private ProReviewerService proReviewerService;
  45. @Autowired
  46. private RepairPersonnelService repairPersonnelService;
  47. @Autowired
  48. private LampInfoCacheByDayService lampInfoCacheByDayService;
  49. @Autowired
  50. private SectionCacheByDayService sectionCacheByDayService;
  51. @Autowired
  52. private GlobalLocationService globalLocationService;
  53. @RequestMapping(value = "/info",method = RequestMethod.POST)
  54. public BaseResult<InfoResponseVO> info(HttpServletRequest request){
  55. Integer version = request.getParameter("version") == null ? 0 : Integer.parseInt(request.getParameter("version"));
  56. Integer type = request.getParameter("type") == null ? 0 : Integer.parseInt(request.getParameter("type"));
  57. Integer operaType = request.getParameter("operaType") == null ? 0 : Integer.parseInt(request.getParameter("operaType"));
  58. List sectionList = toolUtils.getSectionList(request);
  59. InfoResponseVO data = new InfoResponseVO();
  60. data.setCompany(toolUtils.getUser().getCompany());
  61. data.setCompanyAddress(toolUtils.getUser().getAddress());
  62. //设备数量,路灯数量,灯杆数量
  63. LampCountVO lampCountVO = new LampCountVO();
  64. if (!sectionList.isEmpty()) lampCountVO.setSectionList(sectionList);
  65. data.setLampCount(lampService.getCountByVO(lampCountVO)); // 灯控总数
  66. data.setDevCount(data.getLampCount()); // 灯控总数
  67. lampCountVO.setOnlineStatus(1);
  68. lampCountVO.setLampStatus(1);
  69. data.setLightCount(lampService.getCountByVO(lampCountVO)); // 亮灯数
  70. List<SectionDTO> listByIdList = sectionService.getListByIdList(sectionList);
  71. List sectionNameList = new ArrayList();
  72. for (SectionDTO s :listByIdList) {
  73. sectionNameList.add(s.getName());
  74. }
  75. if (sectionNameList.isEmpty()){
  76. data.setArea("");
  77. }else {
  78. data.setArea(StringUtils.join(sectionNameList, ','));
  79. }
  80. data.setAreaCount(listByIdList.size());
  81. // 灯杆数
  82. LampPoleCountVO lampPoleCountVO = new LampPoleCountVO();
  83. lampPoleCountVO.setSectionList(sectionList);
  84. data.setLampPoleCount(lampPoleService.getCountByVO(lampPoleCountVO));
  85. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
  86. lampCountVO.setStartDate(simpleDateFormat.format(new Date()).toString());
  87. // Float dayConsumptionByVO = lampService.getDayConsumptionByVO(lampCountVO);
  88. // data.setDayConsumption((float) (Math.round(dayConsumptionByVO*100)/100f));
  89. simpleDateFormat = new SimpleDateFormat("yyyy-MM-01 00:00:00");
  90. // 当月
  91. LampVO lampVO = new LampVO();
  92. lampVO.setSectionList(sectionList);
  93. // 灯控故障数,在线数
  94. data.setAlarmCount(lampService.getAlarmCountByVO(lampVO));
  95. data.setOnlineCount(lampService.getOnlineCountByVO(lampVO));
  96. LampInfoLogNewDTO comBySectionList = lampService.getComBySectionList(lampVO);
  97. data.setDaySavePower((float) (Math.round(Float.valueOf(comBySectionList.getDayEleSave())*100)/100f));
  98. data.setDayConsumption((float) (Math.round(Float.valueOf(comBySectionList.getDayGeneraEnergy())*100)/100f));
  99. Float monthConsumption = Float.valueOf(comBySectionList.getDayGeneraEnergy())+Float.valueOf(comBySectionList.getMonthGeneraEnergyCache());
  100. data.setMonthConsumption((float) (Math.round((monthConsumption)*100)/100f));
  101. // 当年
  102. simpleDateFormat = new SimpleDateFormat("yyyy-01-01 00:00:00");
  103. Float yearConsumption = Float.valueOf(comBySectionList.getDayGeneraEnergy())+Float.valueOf(comBySectionList.getYearGeneraEnergyCache());
  104. data.setYearConsumption((float) (Math.round((yearConsumption)*100)/100f));
  105. // 累计
  106. double v = (double) (Math.round(Float.valueOf(comBySectionList.getDayGeneraEnergy())*100)/100f);
  107. double v2 = (double) (Math.round(Float.valueOf(comBySectionList.getTotalGeneraEnergyCache())*100)/100f);
  108. data.setTotalConsumption(WebUtils.round(v+v2,2));
  109. data.setTotalElectricharge(WebUtils.round(data.getTotalConsumption() * 0.75,2));
  110. data.setTotalCarbonEmission(WebUtils.round(data.getTotalConsumption() * 0.785/1000,3));
  111. Double totalEleSaveCache = Double.valueOf(comBySectionList.getDayEleSave())+Double.valueOf(comBySectionList.getTotalEleSaveCache());
  112. data.setTotalSavePower(WebUtils.round(totalEleSaveCache,2));
  113. data.setTotalSaveElectricharge(WebUtils.round(data.getTotalSavePower() * 0.75,2));
  114. data.setTotalSaveCarbonEmission(WebUtils.round(data.getTotalSavePower() * 0.785/1000,3));
  115. Date endDate = new Date(System.currentTimeMillis() - 24*3600*1000);
  116. Calendar calendar = Calendar.getInstance();
  117. calendar.setTime(endDate);
  118. calendar.add(Calendar.MONDAY, -1);
  119. simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
  120. SectionCacheByDayDTO sectionCacheByDayDTO = new SectionCacheByDayDTO();
  121. sectionCacheByDayDTO.setStartDate(simpleDateFormat.format(calendar.getTime()));
  122. sectionCacheByDayDTO.setEndDate(simpleDateFormat.format(endDate).toString());
  123. List<SectionCacheByDayDTO> consumptionListByDTO = sectionCacheByDayService.getConsumptionListByDTO(sectionCacheByDayDTO);
  124. simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  125. List date = new ArrayList<>();
  126. List value = new ArrayList<>();
  127. List savePower = new ArrayList<>();
  128. List lightDev = new ArrayList<>();
  129. for (SectionCacheByDayDTO t :consumptionListByDTO) {
  130. // String updateTime = simpleDateFormat.format(t.getUpdateTime()).toString();
  131. String updateTime = t.getUpdateTime();
  132. Float consumption = t.getConsumption();
  133. Float powerSave = t.getPowerSave();
  134. date.add(updateTime);
  135. value.add((float) (Math.round((consumption)*100)/100f));
  136. savePower.add((float) (Math.round((powerSave)*100)/100f));
  137. lightDev.add(t.getLightCount());
  138. }
  139. data.setDate(date);
  140. data.setValue(value);
  141. data.setLightDev(lightDev);
  142. data.setSavePower(savePower);
  143. return BaseResult.success(data);
  144. }
  145. @RequestMapping(value = "/syslog",method = RequestMethod.POST)
  146. public BaseResult<List> syslog(HttpServletRequest request){
  147. Integer version = request.getParameter("version") == null ? 0 : Integer.parseInt(request.getParameter("version"));
  148. Integer type = request.getParameter("type") == null ? 0 : Integer.parseInt(request.getParameter("type"));
  149. Integer operaType = request.getParameter("operaType") == null ? 0 : Integer.parseInt(request.getParameter("operaType"));
  150. List sectionList = toolUtils.getSectionList(request);
  151. Integer userId = toolUtils.getUser().getId();
  152. Integer role = toolUtils.getUser().getRole();;
  153. ListResponseVO data = new ListResponseVO();
  154. if (type == 4){ // 故障
  155. AllAlarmInfoLogVO allAlarmInfoLogVO = new AllAlarmInfoLogVO();
  156. allAlarmInfoLogVO.setSectionList(sectionList);
  157. allAlarmInfoLogVO.setOffset(0);
  158. allAlarmInfoLogVO.setLimit(50);
  159. List<AllAlarmInfoLogDTO> listByVO = alarmInfoLogService.getListByVO(allAlarmInfoLogVO);
  160. data.setList(listByVO);
  161. }else if (type == 3){ // 监控
  162. VideoMonitorVO videoMonitorVO = new VideoMonitorVO();
  163. videoMonitorVO.setSectionList(sectionList);
  164. videoMonitorVO.setLimit(50);
  165. videoMonitorVO.setOffset(0);
  166. List<VideoMonitorDTO> listByVO = videoMonitorService.getListByVO(videoMonitorVO);
  167. data.setList(listByVO);
  168. }else{ // 日志
  169. OperationLogVO operationLogVO = new OperationLogVO();
  170. List userList = new ArrayList<>();
  171. if (role != 1){
  172. if (role == 2){
  173. userList.add(userId);
  174. List<UserDTO> listByParentId = userService.getListByParentId(userId);
  175. for (UserDTO u :listByParentId) {
  176. userList.add(u.getId());
  177. }
  178. }else {
  179. userList.add(userId);
  180. }
  181. operationLogVO.setUserIdList(userList);
  182. }
  183. if (operaType != 0) operationLogVO.setOperaType(operaType);
  184. operationLogVO.setVersion(version);
  185. if (type == 1){ // 路灯
  186. operationLogVO.setDevType(1);
  187. }else { // 灯杆
  188. operationLogVO.setDevType(2);
  189. }
  190. operationLogVO.setOffset(0);
  191. operationLogVO.setLimit(50);
  192. List<OperationLogDTO> listByVO = operationLogService.getListByVO(operationLogVO);
  193. data.setList(listByVO);
  194. }
  195. return BaseResult.success(data);
  196. }
  197. /**
  198. * 系统消息统计
  199. * @param request 用户名
  200. * @return 已读未读消息数
  201. */
  202. @RequestMapping(value = "/getSysInfoCount", method = RequestMethod.POST)
  203. public BaseResult<?> getSysInfoCount(HttpServletRequest request) {
  204. Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
  205. String username = (String) toolUtils.getRequestContent(request,"username",2);
  206. if (username.length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
  207. Integer userid = repairPersonnelService.getUserIdByUsername(username);
  208. Integer sysInfoUnReadCount = proReviewerService.getSysInfoUnReadCount(userid);
  209. Integer sysInfoReadCount = proReviewerService.getSysInfoReadCount(userid);
  210. Integer sysInfoCount = proReviewerService.getSysInfoCount(userid);
  211. OperationDataVO operationDataVO = new OperationDataVO();
  212. operationDataVO.setData1(sysInfoUnReadCount);
  213. operationDataVO.setData2(sysInfoReadCount);
  214. operationDataVO.setData(sysInfoCount);
  215. return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,operationDataVO);
  216. }
  217. /**
  218. * 日志信息
  219. * @param request 设备类型,操作类型
  220. * @return 日志信息
  221. */
  222. @RequestMapping(value = "/sysLog", method = RequestMethod.POST)
  223. public BaseResult<?> sysLog(HttpServletRequest request) {
  224. Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
  225. Integer type = (Integer) toolUtils.getRequestContent(request,"type",1);
  226. Integer operaType = (Integer) toolUtils.getRequestContent(request,"operaType",1);
  227. if (type == 0 || operaType == 0)
  228. return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
  229. if (type == 4) { // 视频监控
  230. VideoMonitorVO vo = videoMonitorService.getVideoListBySectionList(toolUtils.getSectionList(request));
  231. return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,vo);
  232. } else if (type == 3) { // 待处理故障
  233. AllAlarmInfoLogVO allAlarmInfoLogVO = new AllAlarmInfoLogVO();
  234. allAlarmInfoLogVO.setSectionList(toolUtils.getSectionList(request));
  235. allAlarmInfoLogVO.setVersion(version);
  236. List<AllAlarmInfoLogDTO> alarmList = alarmInfoLogService.getAlarmOperationList(allAlarmInfoLogVO);
  237. AllAlarmInfoLogVO vo = new AllAlarmInfoLogVO();
  238. vo.setList(alarmList);
  239. return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,vo);
  240. } else { // 路灯、灯杆
  241. OperationLogVO operationLogVO = new OperationLogVO();
  242. operationLogVO.setDevType(type);
  243. operationLogVO.setOperaType(operaType);
  244. List<OperationLogDTO> operationLogList = operationLogService.getOperationLogList(operationLogVO);
  245. OperationLogVO vo = new OperationLogVO();
  246. vo.setList(operationLogList);
  247. return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,vo);
  248. }
  249. }
  250. /**
  251. * 能源监控数据
  252. * @param request 日期类型
  253. * @return 能源监控数据
  254. */
  255. @RequestMapping(value = "/energyMoniData", method = RequestMethod.POST)
  256. public BaseResult<?> energyMoniData(HttpServletRequest request) throws ParseException {
  257. Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
  258. Integer areaId = (Integer) toolUtils.getRequestContent(request,"areaId",1);
  259. Integer sectionId = (Integer) toolUtils.getRequestContent(request,"sectionId",1);
  260. Integer dateType = (Integer) toolUtils.getRequestContent(request,"dateType",1);
  261. long l = System.currentTimeMillis();
  262. Date date1 = new Date(l);
  263. Calendar calendar = Calendar.getInstance();
  264. calendar.setTime(date1);
  265. int year = calendar.get(Calendar.YEAR); // 获取年份
  266. int month = calendar.get(Calendar.MONTH) + 1; // 获取月份
  267. long startTime;
  268. long endTime;
  269. String startDate;
  270. DecimalFormat decimalFormat = new DecimalFormat("0.00");
  271. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  272. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM");
  273. String endDate = simpleDateFormat.format(l);
  274. if (dateType == 0) { // 当月
  275. if (month < 10) {
  276. startDate = year + "-0" + month + "-01";
  277. } else {
  278. startDate = year + "-" + month + "-01";
  279. }
  280. startTime = simpleDateFormat.parse(startDate).getTime();
  281. endTime = simpleDateFormat.parse(endDate).getTime();
  282. } else if (dateType == 1) { // 当年
  283. month = 1;
  284. startDate = year + "-0" + month + "-01";
  285. endDate = simpleDateFormat.format(l);
  286. startTime = simpleDateFormat.parse(startDate).getTime();
  287. endTime = simpleDateFormat.parse(endDate).getTime();
  288. } else if (dateType == 2) { // 具体月份
  289. String date = (String) toolUtils.getRequestContent(request, "date", 2);
  290. if (date.length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_DATE_ERROR, version);
  291. List<String> list = Arrays.asList(date.split("-"));
  292. int yearNum = Integer.parseInt(list.get(0));
  293. int monthNum = Integer.parseInt(list.get(1));
  294. int daysInMonth = YearMonth.of(yearNum, monthNum).lengthOfMonth();
  295. if (yearNum == year && monthNum == month) {
  296. if (month < 10) {
  297. startDate = year + "-" + "0" + month + "-01";
  298. } else {
  299. startDate = year + "-" + month + "-01";
  300. }
  301. startTime = simpleDateFormat.parse(startDate).getTime();
  302. endTime = simpleDateFormat.parse(endDate).getTime();
  303. } else if ((yearNum == year && monthNum > month) || (yearNum > year)) {
  304. return toolUtils.response(InterfaceResultEnum.DATE_CHOOSE_ERROR,version);
  305. } else {
  306. startTime = simpleDateFormat.parse(date + "-01").getTime();
  307. endTime = simpleDateFormat.parse(date + "-" + daysInMonth).getTime();
  308. startDate = simpleDateFormat.format(startTime);
  309. endDate = simpleDateFormat.format(endTime);
  310. }
  311. } else { // 全部
  312. startDate = "2020-01-01";
  313. startTime = simpleDateFormat.parse(startDate).getTime();
  314. endTime = simpleDateFormat.parse(endDate).getTime();
  315. month = 1;
  316. year = 2020;
  317. }
  318. HashMap<String, Integer> objectObjectHashMap = new HashMap<>();
  319. long timeT = startTime;
  320. int i = 0;
  321. List<Object> dateList = new ArrayList<>();
  322. List<Object> valueList1 = new ArrayList<>();
  323. List<Object> valueList2 = new ArrayList<>();
  324. List<Object> valueList3 = new ArrayList<>();
  325. List<Object> valueList4 = new ArrayList<>();
  326. List<LampInfoCacheByDayDTO> conSumList;
  327. LampInfoCacheByDayDTO dayDTO = new LampInfoCacheByDayDTO();
  328. dayDTO.setAreaId(areaId);
  329. dayDTO.setSectionId(sectionId);
  330. dayDTO.setStartDate(startDate);
  331. dayDTO.setEndDate(endDate);
  332. dayDTO.setSectionList(toolUtils.getSectionList(request));
  333. if (dateType == 0 || dateType == 2) { // 当月和具体日期
  334. conSumList = lampInfoCacheByDayService.getSectionOfMonthConSum(dayDTO);
  335. } else { // 当年和全部
  336. conSumList = lampInfoCacheByDayService.getSectionOfYearConSum(dayDTO);
  337. }
  338. for (LampInfoCacheByDayDTO dto1 : conSumList) {
  339. if (dto1.getConSum() != null) {
  340. float v = Float.parseFloat(dto1.getConSum());
  341. String format = decimalFormat.format(v);
  342. dto1.setConSum(format);
  343. float v1 = v * 0.75f;
  344. String format1 = decimalFormat.format(v1);
  345. dto1.setEleFree(format1);
  346. } else {
  347. dto1.setConSum("0");
  348. dto1.setEleFree("0");
  349. }
  350. if (dto1.getPowerSave() != null) {
  351. float v = Float.parseFloat(dto1.getPowerSave());
  352. String format = decimalFormat.format(v);
  353. dto1.setPowerSave(format);
  354. float v1 = v * 0.75f;
  355. String format1 = decimalFormat.format(v1);
  356. dto1.setSaveEleFree(format1);
  357. } else {
  358. dto1.setPowerSave("0");
  359. dto1.setSaveEleFree("0");
  360. }
  361. }
  362. // 折线统计数据
  363. if (dateType == 0 || dateType == 2) { // 当月和具体日期
  364. while (timeT <= endTime) {
  365. objectObjectHashMap.put(simpleDateFormat.format(new Date(timeT)),i);
  366. dateList.add(simpleDateFormat.format(new Date(timeT)));
  367. valueList1.add(0);
  368. valueList2.add(0);
  369. valueList3.add(0);
  370. valueList4.add(0);
  371. timeT += 3600 * 1000 * 24;
  372. i ++;
  373. }
  374. for (LampInfoCacheByDayDTO dto : conSumList) {
  375. Date date = new Date(simpleDateFormat.parse(dto.getUpdateTime()).getTime());
  376. String s = simpleDateFormat.format(date);
  377. Integer integer = null;
  378. if (objectObjectHashMap.containsKey(s)) {
  379. integer = objectObjectHashMap.get(s);
  380. }
  381. // 用电量和电费
  382. if (dto.getConSum() != null && !dto.getConSum().equals("0") && integer != null) {
  383. float conSum = Float.parseFloat(dto.getConSum());
  384. float eleFree = conSum * 0.75f;
  385. String formatConSum = decimalFormat.format(conSum);
  386. String formatEleFree = decimalFormat.format(eleFree);
  387. valueList1.set(integer, Float.parseFloat(formatConSum)); // 当月和具体月份的用电量折线数据
  388. valueList2.set(integer,Float.parseFloat(formatEleFree)); // 当月和具体月份的电费折线数据
  389. }
  390. // 省电量和省电费
  391. if (dto.getPowerSave() != null && !dto.getPowerSave().equals("0") && integer != null) {
  392. float powerSave = Float.parseFloat(dto.getPowerSave());
  393. float eleFree = powerSave * 0.75f;
  394. String formatConSum = decimalFormat.format(powerSave);
  395. String formatEleFree = decimalFormat.format(eleFree);
  396. valueList3.set(integer, Float.parseFloat(formatConSum)); // 当月和具体月份的用电量折线数据
  397. valueList4.set(integer,Float.parseFloat(formatEleFree)); // 当月和具体月份的电费折线数据
  398. }
  399. }
  400. } else { // 当年和全部
  401. String dateStr;
  402. while (timeT <= endTime) {
  403. objectObjectHashMap.put(dateFormat.format(new Date(timeT)),i);
  404. dateList.add(dateFormat.format(new Date(timeT)));
  405. valueList1.add(0);
  406. valueList2.add(0);
  407. valueList3.add(0);
  408. valueList4.add(0);
  409. month ++;
  410. if (month == 13) {
  411. month = 1;
  412. year ++;
  413. }
  414. if (month < 10) {
  415. dateStr = year + "-0" + month;
  416. } else {
  417. dateStr = year + "-" + month;
  418. }
  419. timeT = dateFormat.parse(dateStr).getTime();
  420. i ++;
  421. }
  422. for (LampInfoCacheByDayDTO dto : conSumList) {
  423. Date date = new Date(dateFormat.parse(dto.getUpdateTime()).getTime());
  424. String s = dateFormat.format(date);
  425. dto.setUpdateTime(s);
  426. Integer integer = null;
  427. if (objectObjectHashMap.containsKey(s)) {
  428. integer = objectObjectHashMap.get(s);
  429. }
  430. // 用电量和电费
  431. if (dto.getConSum() != null && !dto.getConSum().equals("0") && integer != null) {
  432. float conSum = Float.parseFloat(dto.getConSum());
  433. float eleFree = conSum * 0.75f;
  434. String formatConSum = decimalFormat.format(conSum);
  435. String formatEleFree = decimalFormat.format(eleFree);
  436. valueList1.set(integer, Float.parseFloat(formatConSum)); // 当年和全部的用电量折线数据
  437. valueList2.set(integer,Float.parseFloat(formatEleFree)); // 当年和全部的电费折线数据
  438. }
  439. // 省电量和省电费
  440. if (dto.getPowerSave() != null && !dto.getPowerSave().equals("0") && integer != null) {
  441. float powerSave = Float.parseFloat(dto.getPowerSave());
  442. float eleFree = powerSave * 0.75f;
  443. String formatConSum = decimalFormat.format(powerSave);
  444. String formatEleFree = decimalFormat.format(eleFree);
  445. valueList3.set(integer, Float.parseFloat(formatConSum)); // 当年和全部的用电量折线数据
  446. valueList4.set(integer,Float.parseFloat(formatEleFree)); // 当年和全部的电费折线数据
  447. }
  448. }
  449. }
  450. LampInfoCacheByDayDTO dto = lampInfoCacheByDayService.getAreaOrSectionOfConSum(dayDTO);
  451. String conSum,powerSave,eleFree,save;
  452. if (dto == null) {
  453. conSum = "0";
  454. powerSave = "0";
  455. eleFree = "0";
  456. save = "0";
  457. } else {
  458. conSum = dto.getConSum();
  459. powerSave = dto.getPowerSave();
  460. conSum = decimalFormat.format(Float.parseFloat(conSum));
  461. powerSave = decimalFormat.format(Float.parseFloat(powerSave));
  462. eleFree = String.valueOf(Float.parseFloat(conSum) * 0.75f);
  463. save = String.valueOf(Float.parseFloat(powerSave) * 0.75f);
  464. }
  465. List<LampInfoCacheByDayDTO> dataList = lampInfoCacheByDayService.getConSumListBySection(dayDTO);
  466. for (LampInfoCacheByDayDTO dto1 : dataList) {
  467. if (dto1.getConSum() != null) {
  468. float v = Float.parseFloat(dto1.getConSum());
  469. String format = decimalFormat.format(v);
  470. dto1.setConSum(format);
  471. float v1 = v * 0.75f;
  472. String format1 = decimalFormat.format(v1);
  473. dto1.setEleFree(format1);
  474. } else {
  475. dto1.setConSum("0");
  476. dto1.setEleFree("0");
  477. }
  478. if (dto1.getPowerSave() != null) {
  479. float v = Float.parseFloat(dto1.getPowerSave());
  480. String format = decimalFormat.format(v);
  481. dto1.setPowerSave(format);
  482. float v1 = v * 0.75f;
  483. String format1 = decimalFormat.format(v1);
  484. dto1.setSaveEleFree(format1);
  485. } else {
  486. dto1.setPowerSave("0");
  487. dto1.setSaveEleFree("0");
  488. }
  489. }
  490. LampInfoCacheByDayVO lampInfoCacheByDayVO = new LampInfoCacheByDayVO();
  491. lampInfoCacheByDayVO.setSaveEleFree(save);
  492. lampInfoCacheByDayVO.setTotalEleFree(eleFree);
  493. lampInfoCacheByDayVO.setTotalConSum(conSum);
  494. lampInfoCacheByDayVO.setTotalPowerSave(powerSave);
  495. lampInfoCacheByDayVO.setConSumList(valueList1);
  496. lampInfoCacheByDayVO.setEleFreeList(valueList2);
  497. lampInfoCacheByDayVO.setPowerSaveList(valueList3);
  498. lampInfoCacheByDayVO.setSaveEleFreeList(valueList4);
  499. lampInfoCacheByDayVO.setUpdateTimeList(dateList);
  500. lampInfoCacheByDayVO.setDataList(dataList);
  501. lampInfoCacheByDayVO.setList(conSumList);
  502. return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,lampInfoCacheByDayVO);
  503. }
  504. /**
  505. * 导出列表数据
  506. * @param request 日期类型
  507. * @return 导出列表数据
  508. */
  509. @RequestMapping(value = "/inputEnergyMoniData", method = RequestMethod.POST)
  510. public BaseResult<?> inputEnergyMoniData(HttpServletRequest request) throws ParseException {
  511. Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
  512. Integer areaId = (Integer) toolUtils.getRequestContent(request,"areaId",1);
  513. Integer sectionId = (Integer) toolUtils.getRequestContent(request,"sectionId",1);
  514. Integer dateType = (Integer) toolUtils.getRequestContent(request,"dateType",1);
  515. long l = System.currentTimeMillis();
  516. Date date1 = new Date(l);
  517. Calendar calendar = Calendar.getInstance();
  518. calendar.setTime(date1);
  519. int year = calendar.get(Calendar.YEAR); // 获取年份
  520. int month = calendar.get(Calendar.MONTH) + 1; // 获取月份
  521. long startTime;
  522. long endTime;
  523. String startDate;
  524. DecimalFormat decimalFormat = new DecimalFormat("0.00");
  525. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  526. String endDate = simpleDateFormat.format(l);
  527. if (dateType == 0) { // 当月
  528. if (month < 10) {
  529. startDate = year + "-0" + month + "-01";
  530. } else {
  531. startDate = year + "-" + month + "-01";
  532. }
  533. } else if (dateType == 1) { // 当年
  534. month = 1;
  535. startDate = year + "-0" + month + "-01";
  536. endDate = simpleDateFormat.format(l);
  537. } else if (dateType == 2) { // 具体月份
  538. String date = (String) toolUtils.getRequestContent(request, "date", 2);
  539. if (date.length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_DATE_ERROR, version);
  540. List<String> list = Arrays.asList(date.split("-"));
  541. int yearNum = Integer.parseInt(list.get(0));
  542. int monthNum = Integer.parseInt(list.get(1));
  543. int daysInMonth = YearMonth.of(yearNum, monthNum).lengthOfMonth();
  544. if (yearNum == year && monthNum == month) {
  545. if (month < 10) {
  546. startDate = year + "-" + "0" + month + "-01";
  547. } else {
  548. startDate = year + "-" + month + "-01";
  549. }
  550. } else if ((yearNum == year && monthNum > month) || (yearNum > year)) {
  551. return toolUtils.response(InterfaceResultEnum.DATE_CHOOSE_ERROR,version);
  552. } else {
  553. startTime = simpleDateFormat.parse(date + "-01").getTime();
  554. endTime = simpleDateFormat.parse(date + "-" + daysInMonth).getTime();
  555. startDate = simpleDateFormat.format(startTime);
  556. endDate = simpleDateFormat.format(endTime);
  557. }
  558. } else { // 全部
  559. startDate = "2020-01-01";
  560. }
  561. List<LampInfoCacheByDayDTO> conSumList;
  562. LampInfoCacheByDayDTO dayDTO = new LampInfoCacheByDayDTO();
  563. dayDTO.setAreaId(areaId);
  564. dayDTO.setSectionId(sectionId);
  565. dayDTO.setStartDate(startDate);
  566. dayDTO.setEndDate(endDate);
  567. dayDTO.setSectionList(toolUtils.getSectionList(request));
  568. if (dateType == 0 || dateType == 2) { // 当月和具体日期
  569. conSumList = lampInfoCacheByDayService.getSectionOfMonthConSum(dayDTO);
  570. } else { // 当年和全部
  571. conSumList = lampInfoCacheByDayService.getSectionOfYearConSum(dayDTO);
  572. }
  573. for (LampInfoCacheByDayDTO dto1 : conSumList) {
  574. if (dto1.getConSum() != null) {
  575. float v = Float.parseFloat(dto1.getConSum());
  576. String format = decimalFormat.format(v);
  577. dto1.setConSum(format);
  578. float v1 = v * 0.75f;
  579. String format1 = decimalFormat.format(v1);
  580. dto1.setEleFree(format1);
  581. } else {
  582. dto1.setConSum("0");
  583. dto1.setEleFree("0");
  584. }
  585. if (dto1.getPowerSave() != null) {
  586. float v = Float.parseFloat(dto1.getPowerSave());
  587. String format = decimalFormat.format(v);
  588. dto1.setPowerSave(format);
  589. float v1 = v * 0.75f;
  590. String format1 = decimalFormat.format(v1);
  591. dto1.setSaveEleFree(format1);
  592. } else {
  593. dto1.setPowerSave("0");
  594. dto1.setSaveEleFree("0");
  595. }
  596. if (dateType == 1 || dateType == 3) {
  597. String dateTime = dto1.getDateTime();
  598. dto1.setUpdateTime(dateTime);
  599. }
  600. }
  601. String title;
  602. if (version == 0) {
  603. title = "用电量,省电量,电费,节省电费,更新时间";
  604. } else if (version == 1) {
  605. title = "Electricity Consumption,Electricity Saving,Electricity Cost,Electricity Saving,Update Time";
  606. } else {
  607. title = "Потребление электроэнергии,экономия электроэнергии,экономия электричества,время обновления";
  608. }
  609. List<String> titleList = Arrays.asList(title.split(","));
  610. List<List<String>> contentList = new ArrayList<>();
  611. for (LampInfoCacheByDayDTO dto : conSumList) {
  612. List<String> newString = new ArrayList<>();
  613. newString.add(0,dto.getConSum());
  614. newString.add(1,dto.getPowerSave());
  615. newString.add(2,dto.getEleFree());
  616. newString.add(3,dto.getSaveEleFree());
  617. newString.add(4,dto.getUpdateTime());
  618. contentList.add(conSumList.indexOf(dto),newString);
  619. }
  620. String path = ExcelUtil.outExcel(titleList, contentList);
  621. LampInfoCacheByDayVO lampInfoCacheByDayVO = new LampInfoCacheByDayVO();
  622. lampInfoCacheByDayVO.setPath(path);
  623. return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,lampInfoCacheByDayVO);
  624. }
  625. /**
  626. * 获取天气信息
  627. */
  628. @RequestMapping(value = "/getWeatherInfo", method = RequestMethod.POST)
  629. public BaseResult<?> getWeatherInfo(LocationVO locationVO) {
  630. Integer version = locationVO.getVersion();
  631. double longitude = 0, latitude = 0;
  632. if (locationVO.getSectionId() != null && locationVO.getSectionId() != 0) {
  633. GlobalLocationDTO globalLocationDTO = globalLocationService.getLocationBySectionId(locationVO.getSectionId());
  634. if (globalLocationDTO != null) {
  635. longitude = globalLocationDTO.getLongitude();
  636. latitude = globalLocationDTO.getLatitude();
  637. }
  638. } else if (locationVO.getAreaId() != null) {
  639. GlobalLocationDTO dto = globalLocationService.getGlobalLocationDTOById(locationVO.getAreaId(), version);
  640. if (dto != null) {
  641. longitude = dto.getLongitude();
  642. latitude = dto.getLatitude();
  643. }
  644. } else if (locationVO.getCityId() != null) {
  645. GlobalLocationDTO dto = globalLocationService.getGlobalLocationDTOById(locationVO.getCityId(), version);
  646. if (dto != null) {
  647. longitude = dto.getLongitude();
  648. latitude = dto.getLatitude();
  649. }
  650. } else if (locationVO.getProvinceId() != null) {
  651. GlobalLocationDTO dto = globalLocationService.getGlobalLocationDTOById(locationVO.getProvinceId(), version);
  652. if (dto != null) {
  653. longitude = dto.getLongitude();
  654. latitude = dto.getLatitude();
  655. }
  656. } else {
  657. // IpdataModel ipDataModel = ToolUtils.getIpDataModel(ToolUtils.getPublicIp());
  658. // latitude = ipDataModel.latitude();
  659. // longitude = ipDataModel.longitude();
  660. }
  661. WeatherDTO weatherInfo = WeatherUtil.getTodayWeatherInfo(String.valueOf(longitude), String.valueOf(latitude));
  662. return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS, version, weatherInfo);
  663. }
  664. }