|
@@ -3,23 +3,23 @@ package com.welampiot.service.impl;
|
|
|
import com.welampiot.common.BaseResult;
|
|
|
import com.welampiot.common.InterfaceResultEnum;
|
|
|
import com.welampiot.dao.LampDao;
|
|
|
+import com.welampiot.dto.LampInfoCacheByDayDTO;
|
|
|
import com.welampiot.dto.LampInfoDTO;
|
|
|
+import com.welampiot.dto.LampInfoLogDTO;
|
|
|
import com.welampiot.dto.NetworkDTO;
|
|
|
+import com.welampiot.service.LampInfoCacheByDayService;
|
|
|
import com.welampiot.service.LampInfoLogService;
|
|
|
import com.welampiot.service.LampService;
|
|
|
import com.welampiot.service.NetworkService;
|
|
|
import com.welampiot.utils.ToolUtils;
|
|
|
-import com.welampiot.vo.LampCountVO;
|
|
|
-import com.welampiot.vo.LampListResponseVO;
|
|
|
-import com.welampiot.vo.LampLogVO;
|
|
|
-import com.welampiot.vo.LampVO;
|
|
|
+import com.welampiot.vo.*;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.text.DecimalFormat;
|
|
|
+import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
|
|
|
@Service
|
|
|
public class LampServiceImpl implements LampService {
|
|
@@ -31,6 +31,8 @@ public class LampServiceImpl implements LampService {
|
|
|
private LampInfoLogService lampInfoLogService;
|
|
|
@Autowired
|
|
|
private NetworkService networkService;
|
|
|
+ @Autowired
|
|
|
+ private LampInfoCacheByDayService lampInfoCacheByDayService;
|
|
|
@Override
|
|
|
public Integer getCountByVO(LampCountVO lampCountVO) {return lampDao.getCountByVO(lampCountVO);}
|
|
|
|
|
@@ -392,6 +394,266 @@ public class LampServiceImpl implements LampService {
|
|
|
return lampDao.getLampInfoListForGroup(vo);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public LampInfoVO getLampConsumptionData(LampInfoDataVO vo) throws ParseException {
|
|
|
+ String dateType = vo.getDateType();
|
|
|
+ Integer type = vo.getType();
|
|
|
+ Integer value = vo.getValue();
|
|
|
+ String date = vo.getDate();
|
|
|
+ long l = System.currentTimeMillis();
|
|
|
+ Date date1 = new Date(l);
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.setTime(date1);
|
|
|
+ int year = calendar.get(Calendar.YEAR); // 获取年份
|
|
|
+ int month = calendar.get(Calendar.MONTH) + 1; // 获取月份
|
|
|
+
|
|
|
+ long startTime = 0L;
|
|
|
+ long endTime = 0L;
|
|
|
+ String startDate = "";
|
|
|
+ DecimalFormat decimalFormat = new DecimalFormat("0.00");
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM");
|
|
|
+ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
|
|
|
+ SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd 23:59:59");
|
|
|
+ SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ String endDate = simpleDateFormat.format(l);
|
|
|
+ if (dateType != null && !dateType.isEmpty()) {
|
|
|
+ switch (dateType) {
|
|
|
+ case "day":
|
|
|
+ startDate = format.format(l);
|
|
|
+ endDate = format1.format(l);
|
|
|
+ startTime = format2.parse(startDate).getTime();
|
|
|
+ endTime = format2.parse(endDate).getTime();
|
|
|
+ break;
|
|
|
+ case "month":
|
|
|
+ if (month < 10) {
|
|
|
+ startDate = year + "-0" + month + "-01";
|
|
|
+ } else {
|
|
|
+ startDate = year + "-" + month + "-01";
|
|
|
+ }
|
|
|
+ startTime = simpleDateFormat.parse(startDate).getTime();
|
|
|
+ endTime = simpleDateFormat.parse(endDate).getTime();
|
|
|
+ break;
|
|
|
+ case "year":
|
|
|
+ month = 1;
|
|
|
+ startDate = year + "-0" + month + "-01";
|
|
|
+ endDate = simpleDateFormat.format(l);
|
|
|
+ startTime = simpleDateFormat.parse(startDate).getTime();
|
|
|
+ endTime = simpleDateFormat.parse(endDate).getTime();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ } else if (date != null && !date.isEmpty()) {
|
|
|
+ List<String> split = Arrays.asList(date.split("/"));
|
|
|
+ startDate = split.get(0);
|
|
|
+ endDate = split.get(1);
|
|
|
+ startTime = simpleDateFormat.parse(startDate + " 00:00:00").getTime();
|
|
|
+ endTime = simpleDateFormat.parse(endDate + " 23:59:59").getTime();
|
|
|
+ if (endTime < startTime) {
|
|
|
+ LampInfoVO lampInfoVO = new LampInfoVO();
|
|
|
+ lampInfoVO.setName("错误1");
|
|
|
+ return lampInfoVO;
|
|
|
+ }
|
|
|
+ if (endTime - startTime > 29L * 24 * 3600 * 1000) {
|
|
|
+ LampInfoVO lampInfoVO = new LampInfoVO();
|
|
|
+ lampInfoVO.setName("错误2");
|
|
|
+ return lampInfoVO;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ HashMap<String, Integer> objectObjectHashMap = new HashMap<>();
|
|
|
+ long timeT = startTime;
|
|
|
+ int i = 0;
|
|
|
+ List<Object> dateList = new ArrayList<>();
|
|
|
+ List<Object> valueList1 = new ArrayList<>();
|
|
|
+ List<Object> valueList2 = new ArrayList<>();
|
|
|
+ List<Object> valueList3 = new ArrayList<>();
|
|
|
+ List<LampInfoCacheByDayDTO> conSumList = new ArrayList<>();
|
|
|
+ List<LampInfoLogDTO> dayEleList = new ArrayList<>();
|
|
|
+ LampInfoCacheByDayDTO dayDTO = new LampInfoCacheByDayDTO();
|
|
|
+ dayDTO.setType(type);
|
|
|
+ dayDTO.setValue(value);
|
|
|
+ dayDTO.setStartDate(startDate);
|
|
|
+ dayDTO.setEndDate(endDate);
|
|
|
+
|
|
|
+ if (dateType != null && !dateType.isEmpty()) {
|
|
|
+ switch (dateType) {
|
|
|
+ case "day": // 当天
|
|
|
+ dayEleList = lampInfoLogService.getDayEleUsedList(type, value);
|
|
|
+ break;
|
|
|
+ case "month": // 当月
|
|
|
+ conSumList = lampInfoCacheByDayService.getMonthConSum(dayDTO);
|
|
|
+ break;
|
|
|
+ case "year":
|
|
|
+ conSumList = lampInfoCacheByDayService.getYearConSum(dayDTO);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (dateType.equals("month")) { // 当月
|
|
|
+ while (timeT <= endTime) {
|
|
|
+ objectObjectHashMap.put(simpleDateFormat.format(new Date(timeT)),i);
|
|
|
+ dateList.add(simpleDateFormat.format(new Date(timeT)));
|
|
|
+ valueList1.add(0);
|
|
|
+ valueList2.add(0);
|
|
|
+ valueList3.add(0);
|
|
|
+ timeT += 3600 * 1000 * 24;
|
|
|
+ i ++;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (LampInfoCacheByDayDTO dto : conSumList) {
|
|
|
+ Date date2 = new Date(simpleDateFormat.parse(dto.getUpdateTime()).getTime());
|
|
|
+ String s = simpleDateFormat.format(date2);
|
|
|
+ Integer integer = null;
|
|
|
+ if (objectObjectHashMap.containsKey(s)) {
|
|
|
+ integer = objectObjectHashMap.get(s);
|
|
|
+ }
|
|
|
+ // 当月累计用电量
|
|
|
+ if (dto.getConSum() != null && !dto.getConSum().equals("0") && integer != null) {
|
|
|
+ String formatConSum = decimalFormat.format(dto.getConSum());
|
|
|
+ valueList1.set(integer, Float.parseFloat(formatConSum));
|
|
|
+ }
|
|
|
+ // 当月累计亮灯时间
|
|
|
+ if (dto.getLightTime() != null && dto.getLightTime() != 0 && integer != null) {
|
|
|
+ valueList2.set(integer,dto.getLightTime());
|
|
|
+ }
|
|
|
+ // 当月累计省电量
|
|
|
+ if (dto.getPowerSave() != null && !dto.getPowerSave().equals("0") && integer != null) {
|
|
|
+ String formatSave = decimalFormat.format(dto.getPowerSave());
|
|
|
+ valueList3.set(integer,Float.parseFloat(formatSave));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (dateType.equals("day")) { // 当天
|
|
|
+ format = new SimpleDateFormat("yyyy-MM-dd HH:00:00");
|
|
|
+ while (timeT < endTime) {
|
|
|
+ objectObjectHashMap.put(format.format(new Date(timeT)),i);
|
|
|
+ dateList.add(format.format(new Date(timeT)));
|
|
|
+ valueList1.add(0);
|
|
|
+ valueList2.add(0);
|
|
|
+ valueList3.add(0);
|
|
|
+ timeT += 3600 * 1000;
|
|
|
+ i ++;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (LampInfoLogDTO dto : dayEleList) {
|
|
|
+ Date date2 = new Date(format.parse(dto.getUpdateTime()).getTime());
|
|
|
+ String s = format.format(date2);
|
|
|
+ Integer integer = null;
|
|
|
+ if (objectObjectHashMap.containsKey(s)) {
|
|
|
+ integer = objectObjectHashMap.get(s);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 当天累计用电量
|
|
|
+ if (dto.getSumMinEle() != null && !dto.getSumMinEle().equals("0") && integer != null &&
|
|
|
+ dto.getSumMaxEle() != null && !dto.getSumMaxEle().equals("0")) {
|
|
|
+ Float sumEle = Float.parseFloat(dto.getSumMaxEle()) - Float.parseFloat(dto.getSumMinEle());
|
|
|
+ String formatEle = decimalFormat.format(sumEle);
|
|
|
+ valueList1.set(integer, Float.parseFloat(formatEle));
|
|
|
+ }
|
|
|
+ // 当天累计亮灯时间
|
|
|
+ if (dto.getSumMinLightTime() != null && !dto.getSumMinLightTime().equals("0") && integer != null &&
|
|
|
+ dto.getSumMaxLightTime() != null && !dto.getSumMaxLightTime().equals("0")) {
|
|
|
+ Float sumTime = Float.parseFloat(dto.getSumMaxLightTime()) - Float.parseFloat(dto.getSumMinLightTime());
|
|
|
+ String formatTime = decimalFormat.format(sumTime);
|
|
|
+ valueList1.set(integer, Float.parseFloat(formatTime));
|
|
|
+ }
|
|
|
+ // 当天累计省电量
|
|
|
+ if (dto.getSumMinSave() != null && !dto.getSumMinSave().equals("0") && integer != null &&
|
|
|
+ dto.getSumMaxSave() != null && !dto.getSumMaxSave().equals("0")) {
|
|
|
+ Float sumSave = Float.parseFloat(dto.getSumMaxSave()) - Float.parseFloat(dto.getSumMinSave());
|
|
|
+ String formatSave = decimalFormat.format(sumSave);
|
|
|
+ valueList1.set(integer, Float.parseFloat(formatSave));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else { // 当年
|
|
|
+ String dateStr;
|
|
|
+ while (timeT <= endTime) {
|
|
|
+ objectObjectHashMap.put(dateFormat.format(new Date(timeT)),i);
|
|
|
+ dateList.add(dateFormat.format(new Date(timeT)));
|
|
|
+ valueList1.add(0);
|
|
|
+ valueList2.add(0);
|
|
|
+ valueList3.add(0);
|
|
|
+ month ++;
|
|
|
+ if (month == 13) {
|
|
|
+ month = 1;
|
|
|
+ year ++;
|
|
|
+ }
|
|
|
+ if (month < 10) {
|
|
|
+ dateStr = year + "-0" + month;
|
|
|
+ } else {
|
|
|
+ dateStr = year + "-" + month;
|
|
|
+ }
|
|
|
+ timeT = dateFormat.parse(dateStr).getTime();
|
|
|
+ i ++;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (LampInfoCacheByDayDTO dto : conSumList) {
|
|
|
+ Date date2 = new Date(dateFormat.parse(dto.getUpdateTime()).getTime());
|
|
|
+ String s = dateFormat.format(date2);
|
|
|
+ Integer integer = null;
|
|
|
+ if (objectObjectHashMap.containsKey(s)) {
|
|
|
+ integer = objectObjectHashMap.get(s);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 当年累计用电量
|
|
|
+ if (dto.getConSum() != null && !dto.getConSum().equals("0") && integer != null) {
|
|
|
+ String formatConSum = decimalFormat.format(dto.getConSum());
|
|
|
+ valueList1.set(integer, Float.parseFloat(formatConSum));
|
|
|
+ }
|
|
|
+ // 当年累计亮灯时间
|
|
|
+ if (dto.getLightTime() != null && dto.getLightTime() != 0 && integer != null) {
|
|
|
+ valueList2.set(integer,dto.getLightTime());
|
|
|
+ }
|
|
|
+ // 当年累计省电量
|
|
|
+ if (dto.getPowerSave() != null && !dto.getPowerSave().equals("0") && integer != null) {
|
|
|
+ String formatSave = decimalFormat.format(dto.getPowerSave());
|
|
|
+ valueList3.set(integer,Float.parseFloat(formatSave));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (date != null && !date.isEmpty()) {
|
|
|
+ while (timeT <= endTime) {
|
|
|
+ objectObjectHashMap.put(simpleDateFormat.format(new Date(timeT)),i);
|
|
|
+ dateList.add(simpleDateFormat.format(new Date(timeT)));
|
|
|
+ valueList1.add(0);
|
|
|
+ valueList2.add(0);
|
|
|
+ valueList3.add(0);
|
|
|
+ timeT += 3600 * 1000 * 24;
|
|
|
+ i ++;
|
|
|
+ }
|
|
|
+
|
|
|
+ conSumList = lampInfoCacheByDayService.getMonthConSum(dayDTO);
|
|
|
+ for (LampInfoCacheByDayDTO dto : conSumList) {
|
|
|
+ Date date2 = new Date(simpleDateFormat.parse(dto.getUpdateTime()).getTime());
|
|
|
+ String s = simpleDateFormat.format(date2);
|
|
|
+ Integer integer = null;
|
|
|
+ if (objectObjectHashMap.containsKey(s)) {
|
|
|
+ integer = objectObjectHashMap.get(s);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 具体日期累计用电量
|
|
|
+ if (dto.getConSum() != null && !dto.getConSum().equals("0") && integer != null) {
|
|
|
+ String formatConSum = decimalFormat.format(dto.getConSum());
|
|
|
+ valueList1.set(integer, Float.parseFloat(formatConSum));
|
|
|
+ }
|
|
|
+ // 具体日期累计亮灯时间
|
|
|
+ if (dto.getLightTime() != null && dto.getLightTime() != 0 && integer != null) {
|
|
|
+ valueList2.set(integer,dto.getLightTime());
|
|
|
+ }
|
|
|
+ // 具体日期累计省电量
|
|
|
+ if (dto.getPowerSave() != null && !dto.getPowerSave().equals("0") && integer != null) {
|
|
|
+ String formatSave = decimalFormat.format(dto.getPowerSave());
|
|
|
+ valueList3.set(integer,Float.parseFloat(formatSave));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ LampInfoVO lampInfoVO = new LampInfoVO();
|
|
|
+ lampInfoVO.setDate(dateList);
|
|
|
+ lampInfoVO.setConsumption(valueList1);
|
|
|
+ lampInfoVO.setLightTime(valueList2);
|
|
|
+ lampInfoVO.setSavePower(valueList3);
|
|
|
+ return lampInfoVO;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public Integer updateLight(LampInfoDTO lampInfoDTO) {
|
|
|
return lampDao.updateLight(lampInfoDTO);
|