123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702 |
- package com.welampiot.controller;
- import com.welampiot.common.BaseResult;
- import com.welampiot.common.InterfaceResultEnum;
- import com.welampiot.dto.*;
- import com.welampiot.service.*;
- import com.welampiot.utils.ExcelUtil;
- import com.welampiot.utils.ToolUtils;
- import com.welampiot.utils.WeatherUtil;
- import com.welampiot.utils.WebUtils;
- import com.welampiot.vo.*;
- 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.DecimalFormat;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.time.YearMonth;
- import java.util.*;
- @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;
- @Autowired
- private ProReviewerService proReviewerService;
- @Autowired
- private RepairPersonnelService repairPersonnelService;
- @Autowired
- private LampInfoCacheByDayService lampInfoCacheByDayService;
- @Autowired
- private SectionCacheByDayService sectionCacheByDayService;
- @Autowired
- private GlobalLocationService globalLocationService;
- @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());
- //设备数量,路灯数量,灯杆数量
- LampCountVO lampCountVO = new LampCountVO();
- if (!sectionList.isEmpty()) lampCountVO.setSectionList(sectionList);
- data.setLampCount(lampService.getCountByVO(lampCountVO)); // 灯控总数
- data.setDevCount(data.getLampCount()); // 灯控总数
- 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));
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
- lampCountVO.setStartDate(simpleDateFormat.format(new Date()).toString());
- // Float dayConsumptionByVO = lampService.getDayConsumptionByVO(lampCountVO);
- // data.setDayConsumption((float) (Math.round(dayConsumptionByVO*100)/100f));
- simpleDateFormat = new SimpleDateFormat("yyyy-MM-01 00:00:00");
- // 当月
- LampVO lampVO = new LampVO();
- lampVO.setSectionList(sectionList);
- // 灯控故障数,在线数
- data.setAlarmCount(lampService.getAlarmCountByVO(lampVO));
- data.setOnlineCount(lampService.getOnlineCountByVO(lampVO));
- LampInfoLogNewDTO comBySectionList = lampService.getComBySectionList(lampVO);
- data.setDaySavePower((float) (Math.round(Float.valueOf(comBySectionList.getDayEleSave())*100)/100f));
- data.setDayConsumption((float) (Math.round(Float.valueOf(comBySectionList.getDayGeneraEnergy())*100)/100f));
- Float monthConsumption = Float.valueOf(comBySectionList.getDayGeneraEnergy())+Float.valueOf(comBySectionList.getMonthGeneraEnergyCache());
- data.setMonthConsumption((float) (Math.round((monthConsumption)*100)/100f));
- // 当年
- simpleDateFormat = new SimpleDateFormat("yyyy-01-01 00:00:00");
- Float yearConsumption = Float.valueOf(comBySectionList.getDayGeneraEnergy())+Float.valueOf(comBySectionList.getYearGeneraEnergyCache());
- data.setYearConsumption((float) (Math.round((yearConsumption)*100)/100f));
- // 累计
- double v = (double) (Math.round(Float.valueOf(comBySectionList.getDayGeneraEnergy())*100)/100f);
- double v2 = (double) (Math.round(Float.valueOf(comBySectionList.getTotalGeneraEnergyCache())*100)/100f);
- data.setTotalConsumption(WebUtils.round(v+v2,2));
- data.setTotalElectricharge(WebUtils.round(data.getTotalConsumption() * 0.75,2));
- data.setTotalCarbonEmission(WebUtils.round(data.getTotalConsumption() * 0.785/1000,3));
- Double totalEleSaveCache = Double.valueOf(comBySectionList.getDayEleSave())+Double.valueOf(comBySectionList.getTotalEleSaveCache());
- data.setTotalSavePower(WebUtils.round(totalEleSaveCache,2));
- data.setTotalSaveElectricharge(WebUtils.round(data.getTotalSavePower() * 0.75,2));
- data.setTotalSaveCarbonEmission(WebUtils.round(data.getTotalSavePower() * 0.785/1000,3));
- 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");
- SectionCacheByDayDTO sectionCacheByDayDTO = new SectionCacheByDayDTO();
- sectionCacheByDayDTO.setStartDate(simpleDateFormat.format(calendar.getTime()));
- sectionCacheByDayDTO.setEndDate(simpleDateFormat.format(endDate).toString());
- List<SectionCacheByDayDTO> consumptionListByDTO = sectionCacheByDayService.getConsumptionListByDTO(sectionCacheByDayDTO);
- simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
- List date = new ArrayList<>();
- List value = new ArrayList<>();
- List savePower = new ArrayList<>();
- List lightDev = new ArrayList<>();
- for (SectionCacheByDayDTO t :consumptionListByDTO) {
- // String updateTime = simpleDateFormat.format(t.getUpdateTime()).toString();
- String updateTime = t.getUpdateTime();
- 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));
- lightDev.add(t.getLightCount());
- }
- data.setDate(date);
- data.setValue(value);
- data.setLightDev(lightDev);
- 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);
- 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);
- }
- /**
- * 系统消息统计
- * @param request 用户名
- * @return 已读未读消息数
- */
- @RequestMapping(value = "/getSysInfoCount", method = RequestMethod.POST)
- public BaseResult<?> getSysInfoCount(HttpServletRequest request) {
- Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
- String username = (String) toolUtils.getRequestContent(request,"username",2);
- if (username.length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
- Integer userid = repairPersonnelService.getUserIdByUsername(username);
- Integer sysInfoUnReadCount = proReviewerService.getSysInfoUnReadCount(userid);
- Integer sysInfoReadCount = proReviewerService.getSysInfoReadCount(userid);
- Integer sysInfoCount = proReviewerService.getSysInfoCount(userid);
- OperationDataVO operationDataVO = new OperationDataVO();
- operationDataVO.setData1(sysInfoUnReadCount);
- operationDataVO.setData2(sysInfoReadCount);
- operationDataVO.setData(sysInfoCount);
- return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,operationDataVO);
- }
- /**
- * 日志信息
- * @param request 设备类型,操作类型
- * @return 日志信息
- */
- @RequestMapping(value = "/sysLog", method = RequestMethod.POST)
- public BaseResult<?> sysLog(HttpServletRequest request) {
- Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
- Integer type = (Integer) toolUtils.getRequestContent(request,"type",1);
- Integer operaType = (Integer) toolUtils.getRequestContent(request,"operaType",1);
- if (type == 0 || operaType == 0)
- return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
- if (type == 4) { // 视频监控
- VideoMonitorVO vo = videoMonitorService.getVideoListBySectionList(toolUtils.getSectionList(request));
- return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,vo);
- } else if (type == 3) { // 待处理故障
- AllAlarmInfoLogVO allAlarmInfoLogVO = new AllAlarmInfoLogVO();
- allAlarmInfoLogVO.setSectionList(toolUtils.getSectionList(request));
- allAlarmInfoLogVO.setVersion(version);
- List<AllAlarmInfoLogDTO> alarmList = alarmInfoLogService.getAlarmOperationList(allAlarmInfoLogVO);
- AllAlarmInfoLogVO vo = new AllAlarmInfoLogVO();
- vo.setList(alarmList);
- return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,vo);
- } else { // 路灯、灯杆
- OperationLogVO operationLogVO = new OperationLogVO();
- operationLogVO.setDevType(type);
- operationLogVO.setOperaType(operaType);
- List<OperationLogDTO> operationLogList = operationLogService.getOperationLogList(operationLogVO);
- OperationLogVO vo = new OperationLogVO();
- vo.setList(operationLogList);
- return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,vo);
- }
- }
- /**
- * 能源监控数据
- * @param request 日期类型
- * @return 能源监控数据
- */
- @RequestMapping(value = "/energyMoniData", method = RequestMethod.POST)
- public BaseResult<?> energyMoniData(HttpServletRequest request) throws ParseException {
- Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
- Integer areaId = (Integer) toolUtils.getRequestContent(request,"areaId",1);
- Integer sectionId = (Integer) toolUtils.getRequestContent(request,"sectionId",1);
- Integer dateType = (Integer) toolUtils.getRequestContent(request,"dateType",1);
- 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;
- long endTime;
- String startDate;
- DecimalFormat decimalFormat = new DecimalFormat("0.00");
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
- SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM");
- String endDate = simpleDateFormat.format(l);
- if (dateType == 0) { // 当月
- if (month < 10) {
- startDate = year + "-0" + month + "-01";
- } else {
- startDate = year + "-" + month + "-01";
- }
- startTime = simpleDateFormat.parse(startDate).getTime();
- endTime = simpleDateFormat.parse(endDate).getTime();
- } else if (dateType == 1) { // 当年
- month = 1;
- startDate = year + "-0" + month + "-01";
- endDate = simpleDateFormat.format(l);
- startTime = simpleDateFormat.parse(startDate).getTime();
- endTime = simpleDateFormat.parse(endDate).getTime();
- } else if (dateType == 2) { // 具体月份
- String date = (String) toolUtils.getRequestContent(request, "date", 2);
- if (date.length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_DATE_ERROR, version);
- List<String> list = Arrays.asList(date.split("-"));
- int yearNum = Integer.parseInt(list.get(0));
- int monthNum = Integer.parseInt(list.get(1));
- int daysInMonth = YearMonth.of(yearNum, monthNum).lengthOfMonth();
- if (yearNum == year && monthNum == month) {
- if (month < 10) {
- startDate = year + "-" + "0" + month + "-01";
- } else {
- startDate = year + "-" + month + "-01";
- }
- startTime = simpleDateFormat.parse(startDate).getTime();
- endTime = simpleDateFormat.parse(endDate).getTime();
- } else if ((yearNum == year && monthNum > month) || (yearNum > year)) {
- return toolUtils.response(InterfaceResultEnum.DATE_CHOOSE_ERROR,version);
- } else {
- startTime = simpleDateFormat.parse(date + "-01").getTime();
- endTime = simpleDateFormat.parse(date + "-" + daysInMonth).getTime();
- startDate = simpleDateFormat.format(startTime);
- endDate = simpleDateFormat.format(endTime);
- }
- } else { // 全部
- startDate = "2020-01-01";
- startTime = simpleDateFormat.parse(startDate).getTime();
- endTime = simpleDateFormat.parse(endDate).getTime();
- month = 1;
- year = 2020;
- }
- 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<Object> valueList4 = new ArrayList<>();
- List<LampInfoCacheByDayDTO> conSumList;
- LampInfoCacheByDayDTO dayDTO = new LampInfoCacheByDayDTO();
- dayDTO.setAreaId(areaId);
- dayDTO.setSectionId(sectionId);
- dayDTO.setStartDate(startDate);
- dayDTO.setEndDate(endDate);
- dayDTO.setSectionList(toolUtils.getSectionList(request));
- if (dateType == 0 || dateType == 2) { // 当月和具体日期
- conSumList = lampInfoCacheByDayService.getSectionOfMonthConSum(dayDTO);
- } else { // 当年和全部
- conSumList = lampInfoCacheByDayService.getSectionOfYearConSum(dayDTO);
- }
- for (LampInfoCacheByDayDTO dto1 : conSumList) {
- if (dto1.getConSum() != null) {
- float v = Float.parseFloat(dto1.getConSum());
- String format = decimalFormat.format(v);
- dto1.setConSum(format);
- float v1 = v * 0.75f;
- String format1 = decimalFormat.format(v1);
- dto1.setEleFree(format1);
- } else {
- dto1.setConSum("0");
- dto1.setEleFree("0");
- }
- if (dto1.getPowerSave() != null) {
- float v = Float.parseFloat(dto1.getPowerSave());
- String format = decimalFormat.format(v);
- dto1.setPowerSave(format);
- float v1 = v * 0.75f;
- String format1 = decimalFormat.format(v1);
- dto1.setSaveEleFree(format1);
- } else {
- dto1.setPowerSave("0");
- dto1.setSaveEleFree("0");
- }
- }
- // 折线统计数据
- if (dateType == 0 || dateType == 2) { // 当月和具体日期
- 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);
- valueList4.add(0);
- timeT += 3600 * 1000 * 24;
- i ++;
- }
- for (LampInfoCacheByDayDTO dto : conSumList) {
- Date date = new Date(simpleDateFormat.parse(dto.getUpdateTime()).getTime());
- String s = simpleDateFormat.format(date);
- Integer integer = null;
- if (objectObjectHashMap.containsKey(s)) {
- integer = objectObjectHashMap.get(s);
- }
- // 用电量和电费
- if (dto.getConSum() != null && !dto.getConSum().equals("0") && integer != null) {
- float conSum = Float.parseFloat(dto.getConSum());
- float eleFree = conSum * 0.75f;
- String formatConSum = decimalFormat.format(conSum);
- String formatEleFree = decimalFormat.format(eleFree);
- valueList1.set(integer, Float.parseFloat(formatConSum)); // 当月和具体月份的用电量折线数据
- valueList2.set(integer,Float.parseFloat(formatEleFree)); // 当月和具体月份的电费折线数据
- }
- // 省电量和省电费
- if (dto.getPowerSave() != null && !dto.getPowerSave().equals("0") && integer != null) {
- float powerSave = Float.parseFloat(dto.getPowerSave());
- float eleFree = powerSave * 0.75f;
- String formatConSum = decimalFormat.format(powerSave);
- String formatEleFree = decimalFormat.format(eleFree);
- valueList3.set(integer, Float.parseFloat(formatConSum)); // 当月和具体月份的用电量折线数据
- valueList4.set(integer,Float.parseFloat(formatEleFree)); // 当月和具体月份的电费折线数据
- }
- }
- } 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);
- valueList4.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 date = new Date(dateFormat.parse(dto.getUpdateTime()).getTime());
- String s = dateFormat.format(date);
- dto.setUpdateTime(s);
- Integer integer = null;
- if (objectObjectHashMap.containsKey(s)) {
- integer = objectObjectHashMap.get(s);
- }
- // 用电量和电费
- if (dto.getConSum() != null && !dto.getConSum().equals("0") && integer != null) {
- float conSum = Float.parseFloat(dto.getConSum());
- float eleFree = conSum * 0.75f;
- String formatConSum = decimalFormat.format(conSum);
- String formatEleFree = decimalFormat.format(eleFree);
- valueList1.set(integer, Float.parseFloat(formatConSum)); // 当年和全部的用电量折线数据
- valueList2.set(integer,Float.parseFloat(formatEleFree)); // 当年和全部的电费折线数据
- }
- // 省电量和省电费
- if (dto.getPowerSave() != null && !dto.getPowerSave().equals("0") && integer != null) {
- float powerSave = Float.parseFloat(dto.getPowerSave());
- float eleFree = powerSave * 0.75f;
- String formatConSum = decimalFormat.format(powerSave);
- String formatEleFree = decimalFormat.format(eleFree);
- valueList3.set(integer, Float.parseFloat(formatConSum)); // 当年和全部的用电量折线数据
- valueList4.set(integer,Float.parseFloat(formatEleFree)); // 当年和全部的电费折线数据
- }
- }
- }
- LampInfoCacheByDayDTO dto = lampInfoCacheByDayService.getAreaOrSectionOfConSum(dayDTO);
- String conSum,powerSave,eleFree,save;
- if (dto == null) {
- conSum = "0";
- powerSave = "0";
- eleFree = "0";
- save = "0";
- } else {
- conSum = dto.getConSum();
- powerSave = dto.getPowerSave();
- conSum = decimalFormat.format(Float.parseFloat(conSum));
- powerSave = decimalFormat.format(Float.parseFloat(powerSave));
- eleFree = String.valueOf(Float.parseFloat(conSum) * 0.75f);
- save = String.valueOf(Float.parseFloat(powerSave) * 0.75f);
- }
- List<LampInfoCacheByDayDTO> dataList = lampInfoCacheByDayService.getConSumListBySection(dayDTO);
- for (LampInfoCacheByDayDTO dto1 : dataList) {
- if (dto1.getConSum() != null) {
- float v = Float.parseFloat(dto1.getConSum());
- String format = decimalFormat.format(v);
- dto1.setConSum(format);
- float v1 = v * 0.75f;
- String format1 = decimalFormat.format(v1);
- dto1.setEleFree(format1);
- } else {
- dto1.setConSum("0");
- dto1.setEleFree("0");
- }
- if (dto1.getPowerSave() != null) {
- float v = Float.parseFloat(dto1.getPowerSave());
- String format = decimalFormat.format(v);
- dto1.setPowerSave(format);
- float v1 = v * 0.75f;
- String format1 = decimalFormat.format(v1);
- dto1.setSaveEleFree(format1);
- } else {
- dto1.setPowerSave("0");
- dto1.setSaveEleFree("0");
- }
- }
- LampInfoCacheByDayVO lampInfoCacheByDayVO = new LampInfoCacheByDayVO();
- lampInfoCacheByDayVO.setSaveEleFree(save);
- lampInfoCacheByDayVO.setTotalEleFree(eleFree);
- lampInfoCacheByDayVO.setTotalConSum(conSum);
- lampInfoCacheByDayVO.setTotalPowerSave(powerSave);
- lampInfoCacheByDayVO.setConSumList(valueList1);
- lampInfoCacheByDayVO.setEleFreeList(valueList2);
- lampInfoCacheByDayVO.setPowerSaveList(valueList3);
- lampInfoCacheByDayVO.setSaveEleFreeList(valueList4);
- lampInfoCacheByDayVO.setUpdateTimeList(dateList);
- lampInfoCacheByDayVO.setDataList(dataList);
- lampInfoCacheByDayVO.setList(conSumList);
- return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,lampInfoCacheByDayVO);
- }
- /**
- * 导出列表数据
- * @param request 日期类型
- * @return 导出列表数据
- */
- @RequestMapping(value = "/inputEnergyMoniData", method = RequestMethod.POST)
- public BaseResult<?> inputEnergyMoniData(HttpServletRequest request) throws ParseException {
- Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
- Integer areaId = (Integer) toolUtils.getRequestContent(request,"areaId",1);
- Integer sectionId = (Integer) toolUtils.getRequestContent(request,"sectionId",1);
- Integer dateType = (Integer) toolUtils.getRequestContent(request,"dateType",1);
- 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;
- long endTime;
- String startDate;
- DecimalFormat decimalFormat = new DecimalFormat("0.00");
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
- String endDate = simpleDateFormat.format(l);
- if (dateType == 0) { // 当月
- if (month < 10) {
- startDate = year + "-0" + month + "-01";
- } else {
- startDate = year + "-" + month + "-01";
- }
- } else if (dateType == 1) { // 当年
- month = 1;
- startDate = year + "-0" + month + "-01";
- endDate = simpleDateFormat.format(l);
- } else if (dateType == 2) { // 具体月份
- String date = (String) toolUtils.getRequestContent(request, "date", 2);
- if (date.length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_DATE_ERROR, version);
- List<String> list = Arrays.asList(date.split("-"));
- int yearNum = Integer.parseInt(list.get(0));
- int monthNum = Integer.parseInt(list.get(1));
- int daysInMonth = YearMonth.of(yearNum, monthNum).lengthOfMonth();
- if (yearNum == year && monthNum == month) {
- if (month < 10) {
- startDate = year + "-" + "0" + month + "-01";
- } else {
- startDate = year + "-" + month + "-01";
- }
- } else if ((yearNum == year && monthNum > month) || (yearNum > year)) {
- return toolUtils.response(InterfaceResultEnum.DATE_CHOOSE_ERROR,version);
- } else {
- startTime = simpleDateFormat.parse(date + "-01").getTime();
- endTime = simpleDateFormat.parse(date + "-" + daysInMonth).getTime();
- startDate = simpleDateFormat.format(startTime);
- endDate = simpleDateFormat.format(endTime);
- }
- } else { // 全部
- startDate = "2020-01-01";
- }
- List<LampInfoCacheByDayDTO> conSumList;
- LampInfoCacheByDayDTO dayDTO = new LampInfoCacheByDayDTO();
- dayDTO.setAreaId(areaId);
- dayDTO.setSectionId(sectionId);
- dayDTO.setStartDate(startDate);
- dayDTO.setEndDate(endDate);
- dayDTO.setSectionList(toolUtils.getSectionList(request));
- if (dateType == 0 || dateType == 2) { // 当月和具体日期
- conSumList = lampInfoCacheByDayService.getSectionOfMonthConSum(dayDTO);
- } else { // 当年和全部
- conSumList = lampInfoCacheByDayService.getSectionOfYearConSum(dayDTO);
- }
- for (LampInfoCacheByDayDTO dto1 : conSumList) {
- if (dto1.getConSum() != null) {
- float v = Float.parseFloat(dto1.getConSum());
- String format = decimalFormat.format(v);
- dto1.setConSum(format);
- float v1 = v * 0.75f;
- String format1 = decimalFormat.format(v1);
- dto1.setEleFree(format1);
- } else {
- dto1.setConSum("0");
- dto1.setEleFree("0");
- }
- if (dto1.getPowerSave() != null) {
- float v = Float.parseFloat(dto1.getPowerSave());
- String format = decimalFormat.format(v);
- dto1.setPowerSave(format);
- float v1 = v * 0.75f;
- String format1 = decimalFormat.format(v1);
- dto1.setSaveEleFree(format1);
- } else {
- dto1.setPowerSave("0");
- dto1.setSaveEleFree("0");
- }
- if (dateType == 1 || dateType == 3) {
- String dateTime = dto1.getDateTime();
- dto1.setUpdateTime(dateTime);
- }
- }
- String title;
- if (version == 0) {
- title = "用电量,省电量,电费,节省电费,更新时间";
- } else if (version == 1) {
- title = "Electricity Consumption,Electricity Saving,Electricity Cost,Electricity Saving,Update Time";
- } else {
- title = "Потребление электроэнергии,экономия электроэнергии,экономия электричества,время обновления";
- }
- List<String> titleList = Arrays.asList(title.split(","));
- List<List<String>> contentList = new ArrayList<>();
- for (LampInfoCacheByDayDTO dto : conSumList) {
- List<String> newString = new ArrayList<>();
- newString.add(0,dto.getConSum());
- newString.add(1,dto.getPowerSave());
- newString.add(2,dto.getEleFree());
- newString.add(3,dto.getSaveEleFree());
- newString.add(4,dto.getUpdateTime());
- contentList.add(conSumList.indexOf(dto),newString);
- }
- String path = ExcelUtil.outExcel(titleList, contentList);
- LampInfoCacheByDayVO lampInfoCacheByDayVO = new LampInfoCacheByDayVO();
- lampInfoCacheByDayVO.setPath(path);
- return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,lampInfoCacheByDayVO);
- }
- /**
- * 获取天气信息
- */
- @RequestMapping(value = "/getWeatherInfo", method = RequestMethod.POST)
- public BaseResult<?> getWeatherInfo(LocationVO locationVO) {
- Integer version = locationVO.getVersion();
- double longitude = 0, latitude = 0;
- if (locationVO.getSectionId() != null && locationVO.getSectionId() != 0) {
- GlobalLocationDTO globalLocationDTO = globalLocationService.getLocationBySectionId(locationVO.getSectionId());
- if (globalLocationDTO != null) {
- longitude = globalLocationDTO.getLongitude();
- latitude = globalLocationDTO.getLatitude();
- }
- } else if (locationVO.getAreaId() != null) {
- GlobalLocationDTO dto = globalLocationService.getGlobalLocationDTOById(locationVO.getAreaId(), version);
- if (dto != null) {
- longitude = dto.getLongitude();
- latitude = dto.getLatitude();
- }
- } else if (locationVO.getCityId() != null) {
- GlobalLocationDTO dto = globalLocationService.getGlobalLocationDTOById(locationVO.getCityId(), version);
- if (dto != null) {
- longitude = dto.getLongitude();
- latitude = dto.getLatitude();
- }
- } else if (locationVO.getProvinceId() != null) {
- GlobalLocationDTO dto = globalLocationService.getGlobalLocationDTOById(locationVO.getProvinceId(), version);
- if (dto != null) {
- longitude = dto.getLongitude();
- latitude = dto.getLatitude();
- }
- } else {
- // IpdataModel ipDataModel = ToolUtils.getIpDataModel(ToolUtils.getPublicIp());
- // latitude = ipDataModel.latitude();
- // longitude = ipDataModel.longitude();
- }
- WeatherDTO weatherInfo = WeatherUtil.getTodayWeatherInfo(String.valueOf(longitude), String.valueOf(latitude));
- return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS, version, weatherInfo);
- }
- }
|