123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740 |
- package com.welampiot.service.impl;
- import com.welampiot.common.BaseResult;
- import com.welampiot.common.InterfaceResultEnum;
- import com.welampiot.dto.*;
- 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.*;
- 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.*;
- @Service
- public class LampServiceImpl implements LampService {
- @Autowired
- private LampDao lampDao;
- @Autowired
- private ToolUtils toolUtils;
- @Autowired
- private LampInfoLogService lampInfoLogService;
- @Autowired
- private NetworkService networkService;
- @Autowired
- private LampInfoCacheByDayService lampInfoCacheByDayService;
- @Override
- public Integer getCountByVO(LampCountVO lampCountVO) {return lampDao.getCountByVO(lampCountVO);}
- @Override
- public Float getDayConsumptionByVO(LampCountVO lampCountVO) {
- Float dayConsumptionByVO = lampDao.getDayConsumptionByVO(lampCountVO);
- dayConsumptionByVO = dayConsumptionByVO == null ? 0 : dayConsumptionByVO;
- return dayConsumptionByVO;
- }
- @Override
- public Float getConsumptionByVO(LampCountVO lampCountVO) {
- Float consumptionByVO = lampDao.getConsumptionByVO(lampCountVO);
- consumptionByVO = consumptionByVO == null ? 0 : consumptionByVO;
- return consumptionByVO;
- }
- @Override
- public List<LampLogVO> getConsumptionListByVO(LampCountVO lampCountVO) {return lampDao.getConsumptionListByVO(lampCountVO);}
- @Override
- public List<LampInfoDTO> getListByVO(LampListResponseVO lampListResponseVO) {
- List<LampInfoDTO> listByVO = lampDao.getListByVO(lampListResponseVO);
- List<LampInfoDTO> list = new ArrayList<>();
- for (LampInfoDTO lamp :listByVO) {
- if (lamp.getCurrent() != null) {
- if (Math.abs(Float.parseFloat(lamp.getCurrent())) >= 0.01){
- lamp.setCurrent(String.valueOf((Math.round((Float.parseFloat(lamp.getCurrent()))*100)/100f)));
- }else {
- lamp.setCurrent("0");
- }
- }else {
- lamp.setCurrent("");
- }
- if (lamp.getVoltage() != null) {
- if (Math.abs(Float.parseFloat(lamp.getCurrent())) >= 0.01){
- lamp.setVoltage(String.valueOf((Math.round((Float.parseFloat(lamp.getVoltage()))*100)/100f)));
- }else {
- lamp.setCurrent("0");
- }
- }else {
- lamp.setVoltage("");
- }
- if (lamp.getPower() != null) {
- if (Math.abs(Float.parseFloat(lamp.getCurrent())) >= 0.01){
- lamp.setPower(String.valueOf((Math.round((Float.parseFloat(lamp.getPower()))*100)/100f)));
- }else {
- lamp.setCurrent("0");
- }
- }else {
- lamp.setPower("");
- }
- if (lamp.getLedLuxValue() == null){
- lamp.setLedLuxValue(0);
- }
- if (Integer.parseInt(lamp.getNetworkStatus()) == 0){
- lamp.setLighteness(0);
- }
- if (lamp.getPolicyName() == null || lamp.getPolicyType() != 1){
- lamp.setPolicyName("暂无");
- }
- lamp.setControlTypeStr(toolUtils.getLampControlNameById(lamp.getControlType()));
- if (lamp.getControlType() == 5){
- if (lamp.getMode() == 0){
- lamp.setNumber(lamp.getNumber()+"-1");
- }else {
- lamp.setNumber(lamp.getNumber()+"-2");
- }
- }
- list.add(lamp);
- }
- return list;
- }
- @Override
- public LampInfoDTO getDetailsById(Integer id,Integer version) {
- LampInfoDTO detailsById = lampDao.getDetailsById(id,version);
- return detailsById;
- }
- @Override
- public Integer findByVO(LampInfoDTO lampInfoDTO) {
- return lampDao.findByVO(lampInfoDTO);
- }
- @Override
- public Integer checkData(LampInfoDTO lampInfoDTO) {
- Integer integer = lampDao.checkData(lampInfoDTO);
- if (integer == null) integer = 0;
- return integer;
- }
- @Override
- public BaseResult add(LampInfoDTO lampInfoDTO) {
- if (lampInfoDTO.getNumber() == null || lampInfoDTO.getNumber().length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_LAMP_NUMBER_ERROR,lampInfoDTO.getVersion());
- if (!lampInfoDTO.getNumber().matches("^[A-Za-z0-9_]+$")) return toolUtils.response(InterfaceResultEnum.LAMP_NUMBER_FORMAT_ERROR,lampInfoDTO.getVersion());
- if (lampInfoDTO.getName() == null || lampInfoDTO.getName().length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_LAMP_NAME_ERROR,lampInfoDTO.getVersion());
- if (lampInfoDTO.getSn() == null || lampInfoDTO.getSn().length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_LAMP_ADDRESS_ERROR,lampInfoDTO.getVersion());
- if (lampInfoDTO.getAreaId() == 0) return toolUtils.response(InterfaceResultEnum.LACK_AREA_ERROR,lampInfoDTO.getVersion());
- if (lampInfoDTO.getSectionId() == 0) return toolUtils.response(InterfaceResultEnum.LACK_SECTION_ERROR,lampInfoDTO.getVersion());
- LampInfoDTO lampInfoDTO1 = new LampInfoDTO();
- lampInfoDTO1.setSn(lampInfoDTO.getSn());
- if (lampDao.findByVO(lampInfoDTO1) > 0) return toolUtils.response(InterfaceResultEnum.LAMP_ADDRESS_UNIQUE_ERROR,lampInfoDTO.getVersion());
- lampInfoDTO1 = new LampInfoDTO();
- lampInfoDTO1.setNumber(lampInfoDTO.getNumber());
- lampInfoDTO1.setSectionId(lampInfoDTO.getSectionId());
- if (lampDao.findByVO(lampInfoDTO1) > 0) return toolUtils.response(InterfaceResultEnum.LAMP_NUMBER_UNIQUE_ERROR,lampInfoDTO.getVersion());
- lampInfoDTO1 = new LampInfoDTO();
- lampInfoDTO1.setName(lampInfoDTO.getName());
- lampInfoDTO1.setSectionId(lampInfoDTO.getSectionId());
- if (lampDao.findByVO(lampInfoDTO) > 0) return toolUtils.response(InterfaceResultEnum.LAMP_NAME_UNIQUE_ERROR,lampInfoDTO.getVersion());
- NetworkDTO networkDTO = new NetworkDTO();
- networkDTO.setNetworkName(lampInfoDTO.getSn());
- networkDTO.setDeviceSn(lampInfoDTO.getSn());
- networkDTO.setAreaId(lampInfoDTO.getAreaId());
- networkDTO.setSectionId(lampInfoDTO.getSectionId());
- networkDTO.setNetType(1);
- networkDTO.setGatewayType("direct");
- if (lampInfoDTO.getProtocolType() == 10) networkDTO.setDeviceType(4);
- networkDTO.setProtocolType(lampInfoDTO.getProtocolType());
- networkService.add(networkDTO);
- lampInfoDTO.setNetworkId(networkDTO.getId());
- Date endDate = new Date(System.currentTimeMillis());
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- String createTime = simpleDateFormat.format(endDate).toString();
- lampInfoDTO.setCreateTime(createTime);
- if (lampInfoDTO.getControlType() == 5 || lampInfoDTO.getControlType() == 6 || lampInfoDTO.getControlType() == 7){
- lampInfoDTO.setMode(1);
- }
- lampDao.add(lampInfoDTO);
- if (lampInfoDTO.getControlType() == 5){ // 4G 双灯
- lampInfoDTO.setMode(0);
- lampDao.add(lampInfoDTO);
- }
- return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,lampInfoDTO.getVersion());
- }
- @Override
- public BaseResult update(LampInfoDTO lampInfoDTO) {
- LampInfoDTO oldLamp = lampDao.getDetailsById(lampInfoDTO.getId(),lampInfoDTO.getVersion());
- lampInfoDTO.setNetworkId(oldLamp.getNetworkId());
- LampInfoDTO lampInfoDTO1 = new LampInfoDTO();
- // lampInfoDTO1.
- lampInfoDTO1.setSn(lampInfoDTO.getSn());
- lampInfoDTO1.setId(lampInfoDTO.getId());
- lampInfoDTO1.setNetworkId(lampInfoDTO.getNetworkId());
- if (this.checkData(lampInfoDTO1) > 0) return toolUtils.response(InterfaceResultEnum.LAMP_ADDRESS_UNIQUE_ERROR,lampInfoDTO.getVersion());
- lampInfoDTO1 = new LampInfoDTO();
- lampInfoDTO1.setNetworkId(lampInfoDTO.getNetworkId());
- lampInfoDTO1.setNumber(lampInfoDTO.getNumber());
- lampInfoDTO1.setSectionId(lampInfoDTO.getSectionId());
- if (this.checkData(lampInfoDTO1) > 0) return toolUtils.response(InterfaceResultEnum.LAMP_NUMBER_UNIQUE_ERROR,lampInfoDTO.getVersion());
- lampInfoDTO1 = new LampInfoDTO();
- lampInfoDTO1.setNetworkId(lampInfoDTO.getNetworkId());
- lampInfoDTO1.setName(lampInfoDTO.getName());
- lampInfoDTO1.setSectionId(lampInfoDTO.getSectionId());
- if (this.checkData(lampInfoDTO) > 0) return toolUtils.response(InterfaceResultEnum.LAMP_NAME_UNIQUE_ERROR,lampInfoDTO.getVersion());
- if (oldLamp.getProtocolType() != lampInfoDTO.getProtocolType()){
- NetworkDTO networkDTO = new NetworkDTO();
- networkDTO.setId(oldLamp.getNetworkId());
- networkDTO.setNetworkName(lampInfoDTO.getSn());
- networkDTO.setDeviceSn(lampInfoDTO.getSn());
- networkDTO.setAreaId(lampInfoDTO.getAreaId());
- networkDTO.setSectionId(lampInfoDTO.getSectionId());
- networkDTO.setDeviceType(0);
- if (lampInfoDTO.getProtocolType() == 10) networkDTO.setDeviceType(4);
- networkDTO.setProtocolType(lampInfoDTO.getProtocolType());
- networkService.update(networkDTO);
- }
- if (lampInfoDTO.getControlType() == 5 || lampInfoDTO.getControlType() == 6 || lampInfoDTO.getControlType() == 7){
- lampInfoDTO.setMode(oldLamp.getMode());
- }
- lampDao.update(lampInfoDTO);
- System.out.println(lampInfoDTO.getMode());
- if (lampInfoDTO.getControlType() == 5){ // 4G 双灯
- lampInfoDTO1 = new LampInfoDTO();
- lampInfoDTO1.setSn(lampInfoDTO.getSn());
- lampInfoDTO1.setId(lampInfoDTO.getId());
- Integer lampId = this.checkData(lampInfoDTO1);
- if (oldLamp.getMode() == null || oldLamp.getMode() == 0){
- lampInfoDTO.setMode(1);
- }else {
- lampInfoDTO.setMode(0);
- }
- System.out.println(lampInfoDTO.getMode());
- if (lampId > 0){
- lampInfoDTO.setId(lampId);
- lampDao.update(lampInfoDTO);
- }else {
- Date endDate = new Date(System.currentTimeMillis());
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- String createTime = simpleDateFormat.format(endDate).toString();
- lampInfoDTO.setCreateTime(createTime);
- lampDao.add(lampInfoDTO);
- }
- }else {
- if (oldLamp.getControlType() == 5){
- lampInfoDTO1 = new LampInfoDTO();
- lampInfoDTO1.setSn(lampInfoDTO.getSn());
- lampInfoDTO1.setId(lampInfoDTO.getId());
- Integer lampId = this.checkData(lampInfoDTO1);
- System.out.println(lampId);
- if (lampId > 0){
- lampDao.deleteById(lampId);
- }
- }
- }
- return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,lampInfoDTO.getVersion());
- }
- @Override
- public Integer deleteById(Integer id) {
- LampInfoDTO detailsById = this.getDetailsById(id, 0);
- lampInfoLogService.deleteByLampId(id);
- Integer integer = lampDao.deleteById(id);
- if (detailsById.getControlType() == 5){ // 4G 双灯
- LampInfoDTO detailsByAddress = this.getDetailsByAddress(detailsById.getSn(), 0);
- lampInfoLogService.deleteByLampId(detailsByAddress.getId());
- lampDao.deleteById(detailsByAddress.getId());
- }
- return integer;
- }
- @Override
- public LampInfoDTO getDetailsByAddress(String address, Integer version) {
- return lampDao.getDetailsByAddress(address,version);
- }
- @Override
- public List<LampInfoDTO> groupSelectLamp(LampListResponseVO lampListResponseVO) {
- List<LampInfoDTO> lampInfoDTOS = lampDao.groupSelectLamp(lampListResponseVO);
- return lampInfoDTOS;
- }
- @Override
- public List<LampInfoDTO> getNavByVO(LampListResponseVO lampListResponseVO) {
- List<LampInfoDTO> navByVO = lampDao.getNavByVO(lampListResponseVO);
- List<LampInfoDTO> list = new ArrayList<>();
- for (LampInfoDTO l :navByVO) {
- if ((l.getProtocolType() == 10 && l.getControlType() == 5) || (l.getProtocolType() == 3 && l.getControlType() == 9) || (l.getProtocolType() == 11 && l.getControlType() == 8) || l.getControlType() == 25 || l.getControlType() == 27){
- if (l.getMode() == 0){
- l.setNumber(l.getNumber()+"-1");
- }else {
- l.setNumber(l.getNumber()+"-2");
- }
- }
- list.add(l);
- }
- return list;
- }
- @Override
- public List<LampInfoDTO> getLampPoleDetailListByLampPoleId(Integer lampPoleId) {
- return lampDao.getLampPoleDetailListByLampPoleId(lampPoleId);
- }
- @Override
- public List<LampInfoDTO> getLampInfoListByDTO(LampInfoDTO dto) {
- return lampDao.getLampInfoListByDTO(dto);
- }
- @Override
- public List<LampInfoDTO> getLampLocationByGroupId(Integer id) {
- return lampDao.getLampLocationByGroupId(id);
- }
- @Override
- public List<LampInfoDTO> getLampLocationByLoopId(Integer id) {
- return lampDao.getLampLocationByLoopId(id);
- }
- @Override
- public Integer getLampInstallTotalByDTO(LampInfoDTO dto) {
- return lampDao.getLampInstallTotalByDTO(dto);
- }
- @Override
- public Integer getLampLightTotalByDTO(LampInfoDTO dto) {
- return lampDao.getLampLightTotalByDTO(dto);
- }
- @Override
- public Integer getLampOnlineTotalByDTO(LampInfoDTO dto) {
- return lampDao.getLampOnlineTotalByDTO(dto);
- }
- @Override
- public Integer getLampFaultTotalByDTO(LampInfoDTO dto) {
- return lampDao.getLampFaultTotalByDTO(dto);
- }
- @Override
- public void changeLampLocationById(LampInfoDTO dto) {
- lampDao.changeLampLocationById(dto);
- }
- @Override
- public Integer getSectionOfLampCountBySectionId(Integer id) {
- return lampDao.getSectionOfLampCountBySectionId(id);
- }
- @Override
- public String getNameOrNumber(Integer type, Integer value, Integer version) {
- return lampDao.getNameOrNumber(type, value, version);
- }
- @Override
- public LampInfoDTO getLampInfoDTOById(Integer id) {
- return lampDao.getLampInfoDTOById(id);
- }
- @Override
- public List<LampInfoDTO> getLampList(LampVO vo) {
- return lampDao.getLampList(vo);
- }
- @Override
- public Integer getLampTotal(LampVO vo) {
- return lampDao.getLampTotal(vo);
- }
- @Override
- public List<LampInfoDTO> getLampDataByLampIds(List<String> lampIds) {
- return lampDao.getLampDataByLampIds(lampIds);
- }
- @Override
- public List<LampInfoDTO> getLampListByLampPoleId(Integer lampPoleId) {
- return lampDao.getLampListByLampPoleId(lampPoleId);
- }
- @Override
- public Integer getLampPoleIdByLampId(Integer id) {
- return lampDao.getLampPoleIdByLampId(id);
- }
- @Override
- public Integer getLampCountByLampPoleId(Integer lampPoleId) {
- return lampDao.getLampCountByLampPoleId(lampPoleId);
- }
- @Override
- public void updateLampInfoForLoopId(LampInfoDTO dto) {
- lampDao.updateLampInfoForLoopId(dto);
- }
- @Override
- public List<LampInfoDTO> getLampInfoListForGroup(LampVO vo) {
- 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 List<LampInfoDTO> getAlarmAreaCountTop(LampInfoDTO dto) {
- return lampDao.getAlarmAreaCountTop(dto);
- }
- @Override
- public List<LampInfoDTO> getLampEleUseSectionTop(LampInfoDTO dto) {
- return lampDao.getLampEleUseSectionTop(dto);
- }
- @Override
- public List<LampInfoDTO> getLampInfoAlarmList(LampInfoDTO dto) {
- return lampDao.getLampInfoAlarmList(dto);
- }
- @Override
- public List<LampInfoDTO> getLampAlarmTotal(LampInfoDTO dto) {
- return lampDao.getLampAlarmTotal(dto);
- }
- @Override
- public int getAlarmCountByVO(LampVO lampVO) {
- return lampDao.getAlarmCountByVO(lampVO);
- }
- @Override
- public int getOnlineCountByVO(LampVO lampVO) {
- return lampDao.getOnlineCountByVO(lampVO);
- }
- @Override
- public List<LampInfoDTO> getLampSectionAlarmCountTop(LampVO vo) {
- return lampDao.getLampSectionAlarmCountTop(vo);
- }
- @Override
- public LampInfoDTO getLampOfLampPoleById(Integer lampPoleId, Integer lampId) {
- LampInfoDTO lampInfoDTO = lampDao.getLampOfLampPoleById(lampPoleId, lampId);
- String workTimeTotal = lampInfoDTO.getWorkTimeTotal();
- int workTime = Integer.parseInt(workTimeTotal);
- int hour = workTime / 60;
- int min = workTime % 60;
- String hourStr,minStr;
- if (hour < 10) {
- hourStr = "0" + hour;
- } else {
- hourStr = hour + "";
- }
- if (min < 10) {
- minStr = "0" + min;
- } else {
- minStr = min + "";
- }
- workTimeTotal = hourStr + ":" + minStr;
- lampInfoDTO.setWorkTimeTotal(workTimeTotal);
- return lampInfoDTO;
- }
- @Override
- public LampInfoLogNewDTO getComBySectionList(LampVO vo) {
- return lampDao.getComBySectionList(vo);
- }
- @Override
- public Integer updateLight(LampInfoDTO lampInfoDTO) {
- return lampDao.updateLight(lampInfoDTO);
- }
- @Override
- public List<LampInfoDTO> getListByIdList(List idList) {
- return lampDao.getListByIdList(idList);
- }
- @Override
- public Integer getLampPoleCountByVO(LampCountVO lampCountVO) {
- return lampDao.getLampPoleCountByVO(lampCountVO);
- }
- @Override
- public List<LampInfoDTO> areaInfoLampList(LampListResponseVO lampListResponseVO) {
- return lampDao.areaInfoLampList(lampListResponseVO);
- }
- }
|