From 06d3d15a5a08637041cc601101c063b11b07a346 Mon Sep 17 00:00:00 2001
From: net <net@netdeMBP.lan>
Date: 星期五, 14 二月 2025 17:25:21 +0800
Subject: [PATCH]  合并理去杀杀人

---
 zhitan-admin/src/main/java/com/zhitan/web/controller/comprehensivestatistics/MonthlyComprehensiveController.java |  205 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 205 insertions(+), 0 deletions(-)

diff --git a/zhitan-admin/src/main/java/com/zhitan/web/controller/comprehensivestatistics/MonthlyComprehensiveController.java b/zhitan-admin/src/main/java/com/zhitan/web/controller/comprehensivestatistics/MonthlyComprehensiveController.java
new file mode 100644
index 0000000..0a98ba3
--- /dev/null
+++ b/zhitan-admin/src/main/java/com/zhitan/web/controller/comprehensivestatistics/MonthlyComprehensiveController.java
@@ -0,0 +1,205 @@
+package com.zhitan.web.controller.comprehensivestatistics;
+
+import com.zhitan.common.core.controller.BaseController;
+import com.zhitan.common.core.domain.AjaxResult;
+import com.zhitan.common.utils.poi.ExcelUtil;
+import com.zhitan.comprehensivestatistics.domain.MonthlyComprehensive;
+import com.zhitan.comprehensivestatistics.service.ImonthlyComprehensive;
+import com.zhitan.model.domain.ModelNode;
+import com.zhitan.model.service.IModelNodeService;
+import com.zhitan.realtimedata.domain.DataItem;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.ObjectUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.lang.reflect.Field;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+/**
+ * electricityPriceController
+ *
+ * @author sys
+ * @date 2020-02-18
+ */
+@Slf4j
+@RestController
+@RequestMapping("/comprehensive/monthlyComprehensive")
+@Api(value = "缁煎悎鎸囨爣鍒嗘瀽锛堟湀锛塩ontroller",tags = {"缁煎悎鎸囨爣鍒嗘瀽"})
+public class MonthlyComprehensiveController extends BaseController {
+
+    @Autowired
+    private IModelNodeService modelNodeService;
+    @Autowired
+    private ImonthlyComprehensive monthlyComprehensive;
+
+    /*鍏ㄥ巶鑳借�楃粺璁�*/
+    @ApiOperation(value = "鑾峰彇缁煎悎鎸囨爣鍒嗘瀽锛堟湀锛夊垪琛�")
+    @GetMapping("/list")
+    public AjaxResult list(DataItem dataItem) {
+        try {
+
+            Map tableColumn =new HashMap<>();//琛ㄦ暟鎹�
+            List<MonthlyComprehensive> dataList=new ArrayList<>();
+            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.parseInt(getLastDayOfMonth(aa).substring(getLastDayOfMonth(aa).length() - 2))) {
+                if (i > 9) {
+                    bb = aa + "-" + i + " 00:00:00";
+                } else {
+                    bb = aa + "-0" + i + " 00:00:00";
+                }
+                MonthlyComprehensive report = new MonthlyComprehensive();
+                report.setDataTime(sf.parse(bb));
+                report.setValue("value" + i);
+                dataList.add(report);
+                tableColumn.put("value" + i, String.valueOf(i) + "鏃�");
+                i++;
+            }
+
+            MonthlyComprehensive reportList = new MonthlyComprehensive();
+            List<Map> table = new ArrayList<>();
+            table.add(tableColumn);
+            reportList.setTablehead(table);
+
+            ModelNode modelNode = modelNodeService.getModelNodeByModelCodeByIndexCode(dataItem.getIndexCode());
+            if (ObjectUtils.isEmpty(modelNode)) {
+                return AjaxResult.success(reportList);
+            }
+            List<MonthlyComprehensive> list = monthlyComprehensive.getMonthlyComprehensiveList(modelNode.getNodeId(),
+                    dataList, dataItem.getBeginTime(), dataItem.getEndTime(), dataItem.getTimeType(), dataItem.getEnergyType());
+            int count = Integer.parseInt(getLastDayOfMonth(aa).substring(getLastDayOfMonth(aa).length() - 2));
+            list.forEach(monthlyReport -> monthlyReport.setCount(count));
+            reportList.setTabledata(list);
+
+            return AjaxResult.success(reportList);
+        } catch (Exception ex) {
+            logger.error("鑾峰彇鍑洪敊锛�", ex);
+            return AjaxResult.error("鑾峰彇鍑洪敊!");
+        }
+    }
+/**/
+    /**
+     * 鍏ㄥ巶缁煎悎鑳借�楃粺璁″浘
+     */
+    @GetMapping("/listChart")
+    @ApiOperation(value = "鑾峰彇缁煎悎鎸囨爣鍒嗘瀽鍥捐〃锛堟湀锛夋暟鎹�")
+    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";
+        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));
+        List<MonthlyComprehensive> list = monthlyComprehensive.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]); //鏈�
+        Calendar cal = Calendar.getInstance();
+        // 璁剧疆骞翠唤
+        cal.set(Calendar.YEAR, year);
+        // 璁剧疆鏈堜唤
+        // cal.set(Calendar.MONTH, month - 1);
+        cal.set(Calendar.MONTH, month); //璁剧疆褰撳墠鏈堢殑涓婁竴涓湀
+        // 鑾峰彇鏌愭湀鏈�澶уぉ鏁�
+        //int lastDay = cal.getActualMaximum(Calendar.DATE);
+        int lastDay = cal.getMinimum(Calendar.DATE); //鑾峰彇鏈堜唤涓殑鏈�灏忓�硷紝鍗崇涓�澶�
+        // 璁剧疆鏃ュ巻涓湀浠界殑鏈�澶уぉ鏁�
+        //cal.set(Calendar.DAY_OF_MONTH, lastDay);
+        cal.set(Calendar.DAY_OF_MONTH, lastDay - 1); //涓婃湀鐨勭涓�澶╁噺鍘�1灏辨槸褰撴湀鐨勬渶鍚庝竴澶�
+        // 鏍煎紡鍖栨棩鏈�
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        return sdf.format(cal.getTime());
+    }
+    /*缁煎悎鏈堟姤琛ㄥ鍑�*/
+//    @Log(title = "缁煎悎鏈堟姤琛ㄥ鍑�", businessType = BusinessType.EXPORT)
+    @GetMapping("/export")
+    @ApiOperation(value = "缁煎悎鏈堟姤琛ㄥ鍑�")
+    public AjaxResult export(DataItem dataItem) {
+        try {
+
+            Map tableColumn =new HashMap<>();//琛ㄦ暟鎹�
+            List<MonthlyComprehensive> dataList=new ArrayList<>();
+            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.parseInt(getLastDayOfMonth(aa).substring(getLastDayOfMonth(aa).length() - 2))) {
+                if (i > 9) {
+                    bb = aa + "-" + i + " 00:00:00";
+                } else {
+                    bb = aa + "-0" + i + " 00:00:00";
+                }
+                MonthlyComprehensive report = new MonthlyComprehensive();
+                report.setDataTime(sf.parse(bb));
+                report.setValue("value" + i);
+                dataList.add(report);
+                tableColumn.put("value" + i, i + "鏃�");
+                i++;
+            }
+
+            MonthlyComprehensive reportList = new MonthlyComprehensive();
+            List<Map> table = new ArrayList<>();
+            table.add(tableColumn);
+            reportList.setTablehead(table);
+
+            ModelNode modelNode = modelNodeService.getModelNodeByModelCodeByIndexCode(dataItem.getIndexCode());
+            if (ObjectUtils.isEmpty(modelNode)) {
+                return AjaxResult.success(reportList);
+            }
+            List<MonthlyComprehensive> list = monthlyComprehensive.getMonthlyComprehensiveList(modelNode.getNodeId(), dataList,
+                    dataItem.getBeginTime(), dataItem.getEndTime(), dataItem.getTimeType(), dataItem.getEnergyType());
+            int count = Integer.parseInt(getLastDayOfMonth(aa).substring(getLastDayOfMonth(aa).length() - 2));
+            list.forEach(monthlyReport -> monthlyReport.setCount(count));
+            if (CollectionUtils.isNotEmpty(list)) {
+                list.forEach(this::valueRep);
+            }
+            ExcelUtil<MonthlyComprehensive> util = new ExcelUtil<>(MonthlyComprehensive.class);
+            return util.exportExcel(list, "缁煎悎鎸囨爣鍒嗘瀽鏈�");
+        } catch (Exception ex) {
+            logger.error("鑾峰彇鍑洪敊锛�", ex);
+            return AjaxResult.error("鑾峰彇鍑洪敊!");
+        }
+    }
+    public void valueRep(Object dr){
+        Field[] fields = dr.getClass().getDeclaredFields();
+        for(Field field:fields){
+            field.setAccessible(true);
+            Object obj = field.getType();
+            if(field.getType().getName().equals("java.lang.Double")){
+                String name = field.getName();
+                try {
+                    if(ObjectUtils.isEmpty(field.get(dr)))
+                    {
+                        field.set(dr,0.00);
+                    }
+                } catch (IllegalAccessException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+    }
+}

--
Gitblit v1.9.3