|
@@ -0,0 +1,185 @@
|
|
|
+package com.welampiot.controller;
|
|
|
+
|
|
|
+import com.welampiot.common.BaseResult;
|
|
|
+import com.welampiot.dto.*;
|
|
|
+import com.welampiot.service.*;
|
|
|
+import com.welampiot.utils.ToolUtils;
|
|
|
+import com.welampiot.vo.*;
|
|
|
+import org.apache.catalina.User;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+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.SimpleDateFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Calendar;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@CrossOrigin
|
|
|
+@RequestMapping("/data")
|
|
|
+public class DataController {
|
|
|
+ @Autowired
|
|
|
+ private LampService lampService;
|
|
|
+ @Autowired
|
|
|
+ private ToolUtils toolUtils;
|
|
|
+ @Autowired
|
|
|
+ private SectionService sectionService;
|
|
|
+ @Autowired
|
|
|
+ private LampPoleService lampPoleService;
|
|
|
+ @Autowired
|
|
|
+ private AllAlarmInfoLogService alarmInfoLogService;
|
|
|
+ @Autowired
|
|
|
+ private VideoMonitorService videoMonitorService;
|
|
|
+ @Autowired
|
|
|
+ private UserService userService;
|
|
|
+ @Autowired
|
|
|
+ private OperationLogService operationLogService;
|
|
|
+ @RequestMapping(value = "/info",method = RequestMethod.POST)
|
|
|
+ public BaseResult<InfoResponseVO> info(HttpServletRequest request){
|
|
|
+ Integer version = request.getParameter("version") == null ? 0 : Integer.parseInt(request.getParameter("version"));
|
|
|
+ Integer type = request.getParameter("type") == null ? 0 : Integer.parseInt(request.getParameter("type"));
|
|
|
+ Integer operaType = request.getParameter("operaType") == null ? 0 : Integer.parseInt(request.getParameter("operaType"));
|
|
|
+ List sectionList = toolUtils.getSectionList(request);
|
|
|
+ InfoResponseVO data = new InfoResponseVO();
|
|
|
+ data.setCompany(toolUtils.getUser().getCompany());
|
|
|
+ data.setCompanyAddress(toolUtils.getUser().getAddress());
|
|
|
+ Integer userId = toolUtils.getUser().getId();
|
|
|
+ Integer role = toolUtils.getUser().getRole();
|
|
|
+ //设备数量,路灯数量,灯杆数量
|
|
|
+ LampCountVO lampCountVO = new LampCountVO();
|
|
|
+ if (!sectionList.isEmpty()) lampCountVO.setSectionList(sectionList);
|
|
|
+ data.setLampCount(lampService.getCountByVO(lampCountVO)); // 灯控总数
|
|
|
+ lampCountVO.setOnlineStatus(1);
|
|
|
+ lampCountVO.setLampStatus(1);
|
|
|
+ data.setLightCount(lampService.getCountByVO(lampCountVO)); // 亮灯数
|
|
|
+ List<SectionDTO> listByIdList = sectionService.getListByIdList(sectionList);
|
|
|
+ List sectionNameList = new ArrayList();
|
|
|
+ for (SectionDTO s :listByIdList) {
|
|
|
+ sectionNameList.add(s.getName());
|
|
|
+ }
|
|
|
+ if (sectionNameList.isEmpty()){
|
|
|
+ data.setArea("");
|
|
|
+ }else {
|
|
|
+ data.setArea(StringUtils.join(sectionNameList, ','));
|
|
|
+ }
|
|
|
+ data.setAreaCount(listByIdList.size());
|
|
|
+
|
|
|
+ // 灯杆数
|
|
|
+ LampPoleCountVO lampPoleCountVO = new LampPoleCountVO();
|
|
|
+ lampPoleCountVO.setSectionList(sectionList);
|
|
|
+ data.setLampPoleCount(lampPoleService.getCountByVO(lampPoleCountVO));
|
|
|
+
|
|
|
+ Float dayConsumptionByVO = lampService.getDayConsumptionByVO(lampCountVO);
|
|
|
+ data.setDayConsumption((float) (Math.round(dayConsumptionByVO*100)/100f));
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-01 00:00:00");
|
|
|
+ // 当月
|
|
|
+ lampCountVO.setStartDate(simpleDateFormat.format(new Date()).toString());
|
|
|
+ Float monthConsumption = lampService.getConsumptionByVO(lampCountVO);
|
|
|
+ monthConsumption = monthConsumption == null ? 0 : monthConsumption;
|
|
|
+ data.setMonthConsumption((float) (Math.round((dayConsumptionByVO+monthConsumption)*100)/100f));
|
|
|
+ // 当年
|
|
|
+ simpleDateFormat = new SimpleDateFormat("yyyy-01-01 00:00:00");
|
|
|
+ lampCountVO.setStartDate(simpleDateFormat.format(new Date()).toString());
|
|
|
+ Float yearConsumption = lampService.getConsumptionByVO(lampCountVO);
|
|
|
+ yearConsumption = yearConsumption == null ? 0 : yearConsumption;
|
|
|
+ data.setYearConsumption((float) (Math.round((dayConsumptionByVO+yearConsumption)*100)/100f));
|
|
|
+ // 累计
|
|
|
+ lampCountVO.setStartDate(null);
|
|
|
+ Float totalConsumption = lampService.getConsumptionByVO(lampCountVO);
|
|
|
+ totalConsumption = totalConsumption == null ? 0 : totalConsumption;
|
|
|
+ data.setTotalConsumption((float) (Math.round((dayConsumptionByVO+totalConsumption)*100)/100f));
|
|
|
+// Date startDate = new Date(System.currentTimeMillis() - 20*24*3600*1000);
|
|
|
+ Date endDate = new Date(System.currentTimeMillis() - 24*3600*1000);
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.setTime(endDate);
|
|
|
+ calendar.add(Calendar.MONDAY, -1);
|
|
|
+
|
|
|
+ simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
|
|
|
+// Date startDate = simpleDateFormat.format(calendar.getTime());
|
|
|
+// for (int i = 0; i < 30; i++) {
|
|
|
+// long t = startDate.getTime() + i * 24 * 3600 * 1000;
|
|
|
+// }
|
|
|
+ lampCountVO.setStartDate(simpleDateFormat.format(calendar.getTime()));
|
|
|
+ lampCountVO.setEndDate(simpleDateFormat.format(endDate).toString());
|
|
|
+ System.out.println(lampCountVO.getStartDate());
|
|
|
+ System.out.println(lampCountVO.getEndDate());
|
|
|
+ List<LampLogVO> consumptionListByVO = lampService.getConsumptionListByVO(lampCountVO);
|
|
|
+ simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ List date = new ArrayList<>();
|
|
|
+ List value = new ArrayList<>();
|
|
|
+ List savePower = new ArrayList<>();
|
|
|
+ for (LampLogVO t :consumptionListByVO) {
|
|
|
+ String updateTime = simpleDateFormat.format(t.getUpdateTime()).toString();
|
|
|
+ Float consumption = t.getConsumption();
|
|
|
+ Float powerSave = t.getPowerSave();
|
|
|
+ date.add(updateTime);
|
|
|
+ value.add((float) (Math.round((consumption)*100)/100f));
|
|
|
+ savePower.add((float) (Math.round((powerSave)*100)/100f));
|
|
|
+ }
|
|
|
+ data.setDate(date);
|
|
|
+ data.setValue(value);
|
|
|
+ data.setSavePower(savePower);
|
|
|
+ return BaseResult.success(data);
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value = "/syslog",method = RequestMethod.POST)
|
|
|
+ public BaseResult<List> syslog(HttpServletRequest request){
|
|
|
+
|
|
|
+ Integer version = request.getParameter("version") == null ? 0 : Integer.parseInt(request.getParameter("version"));
|
|
|
+ Integer type = request.getParameter("type") == null ? 0 : Integer.parseInt(request.getParameter("type"));
|
|
|
+ Integer operaType = request.getParameter("operaType") == null ? 0 : Integer.parseInt(request.getParameter("operaType"));
|
|
|
+ List sectionList = toolUtils.getSectionList(request);
|
|
|
+// if (type == 0) return weResponse.response("0007",version);
|
|
|
+ Integer userId = toolUtils.getUser().getId();
|
|
|
+ Integer role = toolUtils.getUser().getRole();;
|
|
|
+ ListResponseVO data = new ListResponseVO();
|
|
|
+ if (type == 4){ // 故障
|
|
|
+ AllAlarmInfoLogVO allAlarmInfoLogVO = new AllAlarmInfoLogVO();
|
|
|
+ allAlarmInfoLogVO.setSectionList(sectionList);
|
|
|
+ allAlarmInfoLogVO.setOffset(0);
|
|
|
+ allAlarmInfoLogVO.setLimit(50);
|
|
|
+ List<AllAlarmInfoLogDTO> listByVO = alarmInfoLogService.getListByVO(allAlarmInfoLogVO);
|
|
|
+ data.setList(listByVO);
|
|
|
+ }else if (type == 3){ // 监控
|
|
|
+ VideoMonitorVO videoMonitorVO = new VideoMonitorVO();
|
|
|
+ videoMonitorVO.setSectionList(sectionList);
|
|
|
+ videoMonitorVO.setLimit(50);
|
|
|
+ videoMonitorVO.setOffset(0);
|
|
|
+ List<VideoMonitorDTO> listByVO = videoMonitorService.getListByVO(videoMonitorVO);
|
|
|
+ data.setList(listByVO);
|
|
|
+ }else{ // 日志
|
|
|
+ OperationLogVO operationLogVO = new OperationLogVO();
|
|
|
+ List userList = new ArrayList<>();
|
|
|
+ if (role != 1){
|
|
|
+ if (role == 2){
|
|
|
+ userList.add(userId);
|
|
|
+ List<UserDTO> listByParentId = userService.getListByParentId(userId);
|
|
|
+ for (UserDTO u :listByParentId) {
|
|
|
+ userList.add(u.getId());
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ userList.add(userId);
|
|
|
+ }
|
|
|
+ operationLogVO.setUserIdList(userList);
|
|
|
+ }
|
|
|
+ if (operaType != 0) operationLogVO.setOperaType(operaType);
|
|
|
+ operationLogVO.setVersion(version);
|
|
|
+ if (type == 1){ // 路灯
|
|
|
+ operationLogVO.setDevType(1);
|
|
|
+ }else { // 灯杆
|
|
|
+ operationLogVO.setDevType(2);
|
|
|
+ }
|
|
|
+ operationLogVO.setOffset(0);
|
|
|
+ operationLogVO.setLimit(50);
|
|
|
+ List<OperationLogDTO> listByVO = operationLogService.getListByVO(operationLogVO);
|
|
|
+ data.setList(listByVO);
|
|
|
+ }
|
|
|
+ return BaseResult.success(data);
|
|
|
+ }
|
|
|
+}
|