| | |
| | | package com.zhitan.web.controller.keyequipment; |
| | | |
| | | |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.zhitan.common.core.controller.BaseController; |
| | | import com.zhitan.common.core.domain.AjaxResult; |
| | | import com.zhitan.keyequipment.domain.MonthlyKeyEquipment; |
| | |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | *重点设备能耗统计 月 |
| | | * 重点设备能耗统计 月 |
| | | * |
| | | * @author sys |
| | | * @date 2021-01-11 |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/keyEquipment/MonthlyKeyEquipment") |
| | | @Api(value = "重点设备能耗统计(月)",tags = {"设备单耗分析"}) |
| | | @Api(value = "重点设备能耗统计(月)", tags = {"设备单耗分析"}) |
| | | public class MonthlyKeyEquipmentController extends BaseController { |
| | | |
| | | @Autowired |
| | |
| | | |
| | | @GetMapping("/list") |
| | | @ApiOperation(value = "重点设备能耗统计(月)列表") |
| | | public AjaxResult list(DataItem dataItem) { |
| | | try { |
| | | List<MonthlyKeyEquipment> dataList=new ArrayList<>(); |
| | | public AjaxResult list(DataItem dataItem) throws ParseException { |
| | | List<MonthlyKeyEquipment> dataList = new ArrayList<>(); |
| | | |
| | | Map tableColumn =new HashMap<>();//表数据 |
| | | DateFormat df = new SimpleDateFormat("yyyy-MM"); |
| | | SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | String aa= df.format(dataItem.getDataTime()); |
| | | String bb=""; |
| | | int i = 1; |
| | | String beginTime=aa+"-01 00:00:00"; |
| | | dataItem.setBeginTime(sf.parse(beginTime)); |
| | | String endTime=aa+"-"+Integer.valueOf(getLastDayOfMonth(aa).substring(getLastDayOfMonth(aa).length()-2))+" 00:00:00"; |
| | | dataItem.setEndTime(sf.parse(endTime)); |
| | | while (i <= Integer.valueOf(getLastDayOfMonth(aa).substring(getLastDayOfMonth(aa).length()-2))) { |
| | | if(i>9){ |
| | | bb=aa+"-"+i+" 00:00:00"; |
| | | }else{ |
| | | bb=aa+"-0"+i+" 00:00:00"; |
| | | } |
| | | MonthlyKeyEquipment report=new MonthlyKeyEquipment(); |
| | | report.setDataTime(sf.parse(bb)); |
| | | report.setValue("value"+i); |
| | | dataList.add(report); |
| | | tableColumn.put("value"+i,String.valueOf(i)+"日"); |
| | | i++; |
| | | Map tableColumn = new HashMap<>();//表数据 |
| | | DateFormat df = new SimpleDateFormat("yyyy-MM"); |
| | | SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | String aa = df.format(dataItem.getDataTime()); |
| | | String bb = ""; |
| | | int i = 1; |
| | | String beginTime = aa + "-01 00:00:00"; |
| | | dataItem.setBeginTime(sf.parse(beginTime)); |
| | | String endTime = aa + "-" + Integer.valueOf(getLastDayOfMonth(aa).substring(getLastDayOfMonth(aa).length() - 2)) + " 00:00:00"; |
| | | dataItem.setEndTime(sf.parse(endTime)); |
| | | while (i <= Integer.valueOf(getLastDayOfMonth(aa).substring(getLastDayOfMonth(aa).length() - 2))) { |
| | | if (i > 9) { |
| | | bb = aa + "-" + i + " 00:00:00"; |
| | | } else { |
| | | bb = aa + "-0" + i + " 00:00:00"; |
| | | } |
| | | List<Map> table=new ArrayList<>(); |
| | | MonthlyKeyEquipment reportList =new MonthlyKeyEquipment(); |
| | | table.add(tableColumn); |
| | | reportList.setTablehead(table); |
| | | List<ModelNode> nodeId = modelNodeService.getModelNodeByModelCode(dataItem.getIndexCode()); |
| | | if(CollectionUtils.isEmpty(nodeId)){ |
| | | return AjaxResult.success(reportList); |
| | | } |
| | | List<EnergyIndex> energyList = modelNodeService.getSettingIndex(nodeId.get(0).getNodeId()); |
| | | if(CollectionUtils.isEmpty(energyList)){ |
| | | return AjaxResult.success(reportList); |
| | | } |
| | | List<String> indexIds = energyList.stream().map(EnergyIndex::getIndexId).collect(Collectors.toList()); |
| | | |
| | | startPage(); |
| | | List<MonthlyKeyEquipment> list = monthlyKeyEquipmentService.getMonthlyKeyEquipmentList(indexIds, dataList,dataItem.getBeginTime(),dataItem.getEndTime(), dataItem.getTimeType(),dataItem.getEnergyType()); |
| | | int count=Integer.valueOf(getLastDayOfMonth(aa).substring(getLastDayOfMonth(aa).length()-2)); |
| | | list.forEach(monthlyReport -> monthlyReport.setCount(count)); |
| | | reportList.setTabledata(list); |
| | | reportList.setTotal(new PageInfo(list).getTotal()); |
| | | |
| | | return AjaxResult.success(reportList); |
| | | } catch (Exception ex) { |
| | | logger.error("获取出错!", ex); |
| | | return AjaxResult.error("获取出错!"); |
| | | MonthlyKeyEquipment report = new MonthlyKeyEquipment(); |
| | | report.setDataTime(sf.parse(bb)); |
| | | report.setValue("value" + i); |
| | | dataList.add(report); |
| | | tableColumn.put("value" + i, String.valueOf(i) + "日"); |
| | | i++; |
| | | } |
| | | List<Map> table = new ArrayList<>(); |
| | | MonthlyKeyEquipment reportList = new MonthlyKeyEquipment(); |
| | | table.add(tableColumn); |
| | | reportList.setTablehead(table); |
| | | List<ModelNode> nodeId = modelNodeService.getModelNodeByModelCode(dataItem.getIndexCode()); |
| | | if (CollectionUtils.isEmpty(nodeId)) { |
| | | return success(new ArrayList<>()); |
| | | } |
| | | List<EnergyIndex> energyList = modelNodeService.getSettingIndex(nodeId.get(0).getNodeId()); |
| | | if (CollectionUtils.isEmpty(energyList)) { |
| | | return success(new ArrayList<>()); |
| | | } |
| | | List<String> indexIds = energyList.stream().map(EnergyIndex::getIndexId).collect(Collectors.toList()); |
| | | |
| | | List<MonthlyKeyEquipment> list = monthlyKeyEquipmentService.getMonthlyKeyEquipmentList(indexIds, dataList, dataItem.getBeginTime(), dataItem.getEndTime(), dataItem.getTimeType(), dataItem.getEnergyType()); |
| | | |
| | | return success(list); |
| | | } |
| | | |
| | | @GetMapping("/listChart") |
| | |
| | | public AjaxResult listChart(DataItem dataItem) throws ParseException { |
| | | DateFormat df = new SimpleDateFormat("yyyy-MM"); |
| | | SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | String aa= df.format(dataItem.getDataTime()); |
| | | String beginTime=aa+"-01 00:00:00"; |
| | | String aa = df.format(dataItem.getDataTime()); |
| | | String beginTime = aa + "-01 00:00:00"; |
| | | dataItem.setBeginTime(sf.parse(beginTime)); |
| | | String endTime=aa+"-"+Integer.valueOf(getLastDayOfMonth(aa).substring(getLastDayOfMonth(aa).length()-2))+" 00:00:00"; |
| | | String endTime = aa + "-" + Integer.valueOf(getLastDayOfMonth(aa).substring(getLastDayOfMonth(aa).length() - 2)) + " 00:00:00"; |
| | | dataItem.setEndTime(sf.parse(endTime)); |
| | | List<MonthlyKeyEquipment> list = monthlyKeyEquipmentService.getListChart(dataItem.getIndexId(),dataItem.getBeginTime(),dataItem.getEndTime(), dataItem.getTimeType(),dataItem.getEnergyType()); |
| | | List<MonthlyKeyEquipment> list = monthlyKeyEquipmentService.getListChart(dataItem.getIndexId(), dataItem.getBeginTime(), dataItem.getEndTime(), dataItem.getTimeType(), dataItem.getEnergyType()); |
| | | return AjaxResult.success(list); |
| | | } |
| | | |
| | | public static String getLastDayOfMonth(String yearMonth) { |
| | | int year = Integer.parseInt(yearMonth.split("-")[0]); //年 |
| | | int month = Integer.parseInt(yearMonth.split("-")[1]); //月 |