Răsfoiți Sursa

Merge branch 'master' of http://git.xt.wenhq.top:8083/hs/zhny_bg

hsshuxian 11 luni în urmă
părinte
comite
2b83f1bc5a
20 a modificat fișierele cu 797 adăugiri și 285 ștergeri
  1. 22 1
      ems-cloud/ems-modules/ems-server/src/main/java/com/ruoyi/ems/controller/ChargingBillController.java
  2. 37 28
      ems-cloud/ems-modules/ems-server/src/main/java/com/ruoyi/ems/controller/ElecUseHController.java
  3. 25 0
      ems-cloud/ems-modules/ems-server/src/main/java/com/ruoyi/ems/controller/PvSupplyHController.java
  4. 45 26
      ems-cloud/ems-modules/ems-server/src/main/java/com/ruoyi/ems/domain/ChargingBill.java
  5. 28 5
      ems-cloud/ems-modules/ems-server/src/main/java/com/ruoyi/ems/domain/vo/QueryChargingBill.java
  6. 4 4
      ems-cloud/ems-modules/ems-server/src/main/java/com/ruoyi/ems/domain/vo/QueryMeterReading.java
  7. 14 9
      ems-cloud/ems-modules/ems-server/src/main/java/com/ruoyi/ems/mapper/ElecUseHMapper.java
  8. 9 0
      ems-cloud/ems-modules/ems-server/src/main/java/com/ruoyi/ems/mapper/PvSupplyHMapper.java
  9. 9 0
      ems-cloud/ems-modules/ems-server/src/main/java/com/ruoyi/ems/service/IAreaBuildingZoningService.java
  10. 7 0
      ems-cloud/ems-modules/ems-server/src/main/java/com/ruoyi/ems/service/IChargingBillService.java
  11. 15 9
      ems-cloud/ems-modules/ems-server/src/main/java/com/ruoyi/ems/service/IElecUseHService.java
  12. 8 0
      ems-cloud/ems-modules/ems-server/src/main/java/com/ruoyi/ems/service/IPvSupplyHService.java
  13. 6 0
      ems-cloud/ems-modules/ems-server/src/main/java/com/ruoyi/ems/service/impl/AreaBuildingZoningServiceImpl.java
  14. 281 63
      ems-cloud/ems-modules/ems-server/src/main/java/com/ruoyi/ems/service/impl/ChargingBillServiceImpl.java
  15. 54 23
      ems-cloud/ems-modules/ems-server/src/main/java/com/ruoyi/ems/service/impl/ElecUseHServiceImpl.java
  16. 23 1
      ems-cloud/ems-modules/ems-server/src/main/java/com/ruoyi/ems/service/impl/PvSupplyHServiceImpl.java
  17. 103 43
      ems-cloud/ems-modules/ems-server/src/main/resources/mapper/ems/ElecPvSupplyHMapper.xml
  18. 57 33
      ems-cloud/ems-modules/ems-server/src/main/resources/mapper/ems/ElecUseHMapper.xml
  19. 0 1
      ems-cloud/ems-modules/ems-server/src/main/resources/mapper/ems/MeterReadingMapper.xml
  20. 50 39
      ems-cloud/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/DateTimeUtil.java

+ 22 - 1
ems-cloud/ems-modules/ems-server/src/main/java/com/ruoyi/ems/controller/ChargingBillController.java

@@ -53,7 +53,7 @@ public class ChargingBillController extends BaseController {
      * 商户计费
      *
      * @param queryParam 查询参数
-     * @return
+     * @return 计费
      */
     @GetMapping(value = "/co")
     public AjaxResult getCoBill(QueryChargingBill queryParam) {
@@ -69,4 +69,25 @@ public class ChargingBillController extends BaseController {
             return error("系统异常");
         }
     }
+
+    /**
+     * 商户计费
+     *
+     * @param queryParam 查询参数
+     * @return 计费
+     */
+    @GetMapping(value = "/getByTag")
+    public AjaxResult getByTag(QueryChargingBill queryParam) {
+        try {
+            List<ChargingBill> list = chargingBillService.selectTagChargingBill(queryParam);
+            return success(list);
+        }
+        catch (BusinessException e) {
+            return error(e.getMessage());
+        }
+        catch (Exception e) {
+            logger.error("系统异常", e);
+            return error("系统异常");
+        }
+    }
 }

+ 37 - 28
ems-cloud/ems-modules/ems-server/src/main/java/com/ruoyi/ems/controller/ElecUseHController.java

@@ -1,15 +1,9 @@
 package com.ruoyi.ems.controller;
 
-import com.ruoyi.common.core.utils.poi.ExcelUtil;
-import com.ruoyi.common.core.web.controller.BaseController;
-import com.ruoyi.common.core.web.domain.AjaxResult;
-import com.ruoyi.common.core.web.page.TableDataInfo;
-import com.ruoyi.common.log.annotation.Log;
-import com.ruoyi.common.log.enums.BusinessType;
-import com.ruoyi.common.security.annotation.RequiresPermissions;
-import com.ruoyi.ems.domain.ElecUseH;
-import com.ruoyi.ems.service.IElecUseHService;
-import io.swagger.annotations.Api;
+import java.util.List;
+
+import javax.servlet.http.HttpServletResponse;
+
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.DeleteMapping;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -18,22 +12,31 @@ import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.PutMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
-import javax.servlet.http.HttpServletResponse;
-import java.util.List;
+import com.ruoyi.common.core.utils.poi.ExcelUtil;
+import com.ruoyi.common.core.web.controller.BaseController;
+import com.ruoyi.common.core.web.domain.AjaxResult;
+import com.ruoyi.common.core.web.page.TableDataInfo;
+import com.ruoyi.common.log.annotation.Log;
+import com.ruoyi.common.log.enums.BusinessType;
+import com.ruoyi.common.security.annotation.RequiresPermissions;
+import com.ruoyi.ems.domain.ElecUseH;
+import com.ruoyi.ems.service.IElecUseHService;
+
+import io.swagger.annotations.Api;
 
 /**
  * 用能计量-小时Controller
- * 
+ *
  * @author ruoyi
  * @date 2024-08-15
  */
 @RestController
 @RequestMapping("/elec/use/hour")
 @Api(value = "ElecUseHController", description = "用电计量数据接口")
-public class ElecUseHController extends BaseController
-{
+public class ElecUseHController extends BaseController {
     @Autowired
     private IElecUseHService elecUseHService;
 
@@ -42,8 +45,7 @@ public class ElecUseHController extends BaseController
      */
     @RequiresPermissions("ems:h:list")
     @GetMapping("/list")
-    public TableDataInfo list(ElecUseH admEmsFacsUseH)
-    {
+    public TableDataInfo list(ElecUseH admEmsFacsUseH) {
         startPage();
         List<ElecUseH> list = elecUseHService.selectElecUseHList(admEmsFacsUseH);
         return getDataTable(list);
@@ -55,8 +57,7 @@ public class ElecUseHController extends BaseController
     @RequiresPermissions("ems:h:export")
     @Log(title = "用能计量-小时", businessType = BusinessType.EXPORT)
     @PostMapping("/export")
-    public void export(HttpServletResponse response, ElecUseH admEmsFacsUseH)
-    {
+    public void export(HttpServletResponse response, ElecUseH admEmsFacsUseH) {
         List<ElecUseH> list = elecUseHService.selectElecUseHList(admEmsFacsUseH);
         ExcelUtil<ElecUseH> util = new ExcelUtil<ElecUseH>(ElecUseH.class);
         util.exportExcel(response, list, "用能计量-小时数据");
@@ -67,8 +68,7 @@ public class ElecUseHController extends BaseController
      */
     @RequiresPermissions("ems:h:query")
     @GetMapping(value = "/{id}")
-    public AjaxResult getInfo(@PathVariable("id") Long id)
-    {
+    public AjaxResult getInfo(@PathVariable("id") Long id) {
         return success(elecUseHService.selectElecUseHById(id));
     }
 
@@ -78,8 +78,7 @@ public class ElecUseHController extends BaseController
     @RequiresPermissions("ems:h:add")
     @Log(title = "用能计量-小时", businessType = BusinessType.INSERT)
     @PostMapping
-    public AjaxResult add(@RequestBody ElecUseH admEmsFacsUseH)
-    {
+    public AjaxResult add(@RequestBody ElecUseH admEmsFacsUseH) {
         return toAjax(elecUseHService.insertElecUseH(admEmsFacsUseH));
     }
 
@@ -89,8 +88,7 @@ public class ElecUseHController extends BaseController
     @RequiresPermissions("ems:h:edit")
     @Log(title = "用能计量-小时", businessType = BusinessType.UPDATE)
     @PutMapping
-    public AjaxResult edit(@RequestBody ElecUseH admEmsFacsUseH)
-    {
+    public AjaxResult edit(@RequestBody ElecUseH admEmsFacsUseH) {
         return toAjax(elecUseHService.updateElecUseH(admEmsFacsUseH));
     }
 
@@ -99,9 +97,20 @@ public class ElecUseHController extends BaseController
      */
     @RequiresPermissions("ems:h:remove")
     @Log(title = "用能计量-小时", businessType = BusinessType.DELETE)
-	@DeleteMapping("/{ids}")
-    public AjaxResult remove(@PathVariable Long[] ids)
-    {
+    @DeleteMapping("/{ids}")
+    public AjaxResult remove(@PathVariable Long[] ids) {
         return toAjax(elecUseHService.deleteElecUseHByIds(ids));
     }
+
+    /**
+     * 网-用电量月度统计
+     *
+     * @param area the area
+     * @return the area month use supply
+     * @author chen.cheng
+     */
+    @GetMapping("/area/month/use/supply")
+    public AjaxResult getAreaMonthUseSupply(@RequestParam("area") String area) {
+        return success(elecUseHService.selectElecAndPower(area));
+    }
 }

+ 25 - 0
ems-cloud/ems-modules/ems-server/src/main/java/com/ruoyi/ems/controller/PvSupplyHController.java

@@ -1,6 +1,7 @@
 package com.ruoyi.ems.controller;
 
 import java.util.List;
+import java.util.Map;
 
 import javax.servlet.http.HttpServletResponse;
 
@@ -33,6 +34,7 @@ import com.ruoyi.ems.service.IPvSupplyHService;
 public class PvSupplyHController extends BaseController {
     @Autowired
     private IPvSupplyHService admEmsPvSupplyHService;
+
     /**
      * 查询光伏并网计量光伏并网计量-小时列表
      */
@@ -65,6 +67,29 @@ public class PvSupplyHController extends BaseController {
         return success(list);
     }
 
+    @RequiresPermissions("ems:prod:list")
+    @GetMapping("/list/prod/this/day/total")
+    public AjaxResult listProdThisDayTotalIndex(PvSupplyH admEmsPvSupplyH) {
+        List<Map<String, Object>> list = admEmsPvSupplyHService
+            .selectAreaSupplyHByThisDay(admEmsPvSupplyH.getAreaCode());
+        return success(list);
+    }
+
+    @RequiresPermissions("ems:prod:list")
+    @GetMapping("/list/prod/this/month/total")
+    public AjaxResult listProdThisMonthTotalIndex(PvSupplyH admEmsPvSupplyH) {
+        List<Map<String, Object>> list = admEmsPvSupplyHService
+            .selectAreaSupplyHByRefMonth(admEmsPvSupplyH.getAreaCode());
+        return success(list);
+    }
+
+    @RequiresPermissions("ems:prod:list")
+    @GetMapping("/list/prod/this/year/total")
+    public AjaxResult listProdThisYearTotalIndex(PvSupplyH admEmsPvSupplyH) {
+        List<Map<String, Object>> list = admEmsPvSupplyHService.selectAreaSupplyHByYear(admEmsPvSupplyH.getAreaCode());
+        return success(list);
+    }
+
     /**
      * 导出光伏并网计量光伏并网计量-小时列表
      */

+ 45 - 26
ems-cloud/ems-modules/ems-server/src/main/java/com/ruoyi/ems/domain/ChargingBill.java

@@ -11,7 +11,7 @@
 package com.ruoyi.ems.domain;
 
 /**
- * 采购项目
+ * 账单
  * <功能详细描述>
  *
  * @author lvwenbin
@@ -20,16 +20,17 @@ package com.ruoyi.ems.domain;
  * @since [产品/模块版本]
  */
 public class ChargingBill {
-    private Long objType;
-
-    private Long objSubType;
-
     /**
-     * 账单项目名称
+     * 账单主体代码
      */
     private String objCode;
 
     /**
+     * 账单主体名称
+     */
+    private String objName;
+
+    /**
      * 计量时间
      */
     private String meteredTime;
@@ -45,6 +46,11 @@ public class ChargingBill {
     private Double meteredPrice;
 
     /**
+     * 公摊值
+     */
+    private Long sharedValue;
+
+    /**
      * 公摊金额
      */
     private Double sharedPrice;
@@ -55,26 +61,15 @@ public class ChargingBill {
     private Integer sharedComputeType;
 
     /**
+     * 总计用量
+     */
+    private Long totalValue;
+
+    /**
      * 合计金额
      */
     private Double totalPrice;
 
-    public Long getObjType() {
-        return objType;
-    }
-
-    public void setObjType(Long objType) {
-        this.objType = objType;
-    }
-
-    public Long getObjSubType() {
-        return objSubType;
-    }
-
-    public void setObjSubType(Long objSubType) {
-        this.objSubType = objSubType;
-    }
-
     public String getObjCode() {
         return objCode;
     }
@@ -83,6 +78,14 @@ public class ChargingBill {
         this.objCode = objCode;
     }
 
+    public String getObjName() {
+        return objName;
+    }
+
+    public void setObjName(String objName) {
+        this.objName = objName;
+    }
+
     public String getMeteredTime() {
         return meteredTime;
     }
@@ -107,6 +110,14 @@ public class ChargingBill {
         this.meteredPrice = meteredPrice;
     }
 
+    public Long getSharedValue() {
+        return sharedValue;
+    }
+
+    public void setSharedValue(Long sharedValue) {
+        this.sharedValue = sharedValue;
+    }
+
     public Double getSharedPrice() {
         return sharedPrice;
     }
@@ -123,6 +134,14 @@ public class ChargingBill {
         this.sharedComputeType = sharedComputeType;
     }
 
+    public Long getTotalValue() {
+        return totalValue;
+    }
+
+    public void setTotalValue(Long totalValue) {
+        this.totalValue = totalValue;
+    }
+
     public Double getTotalPrice() {
         return totalPrice;
     }
@@ -133,9 +152,9 @@ public class ChargingBill {
 
     @Override
     public String toString() {
-        return "ChargingBill{" + "objType=" + objType + ", objSubType=" + objSubType + ", objCode='" + objCode + '\''
-            + ", meteredTime='" + meteredTime + '\'' + ", meteredValue=" + meteredValue + ", meteredPrice="
-            + meteredPrice + ", sharedPrice=" + sharedPrice + ", sharedComputeType=" + sharedComputeType
-            + ", totalPrice=" + totalPrice + '}';
+        return "ChargingBill{" + "objCode='" + objCode + '\'' + ", objName='" + objName + '\'' + ", meteredTime='"
+            + meteredTime + '\'' + ", meteredValue=" + meteredValue + ", meteredPrice=" + meteredPrice
+            + ", sharedValue=" + sharedValue + ", sharedPrice=" + sharedPrice + ", sharedComputeType="
+            + sharedComputeType + ", totalValue='" + totalValue + '\'' + ", totalPrice=" + totalPrice + '}';
     }
 }

+ 28 - 5
ems-cloud/ems-modules/ems-server/src/main/java/com/ruoyi/ems/domain/vo/QueryChargingBill.java

@@ -10,6 +10,9 @@
  */
 package com.ruoyi.ems.domain.vo;
 
+import com.ruoyi.common.core.utils.StringUtils;
+import com.ruoyi.ems.domain.common.AreaTier;
+
 /**
  * 查询账单请求
  * <功能详细描述>
@@ -23,7 +26,7 @@ public class QueryChargingBill {
     /**
      * 区域编码
      */
-    private String areaCode;
+    private String areaPath;
 
     /**
      * 区域层级
@@ -45,12 +48,12 @@ public class QueryChargingBill {
      */
     private String endTime;
 
-    public String getAreaCode() {
-        return areaCode;
+    public String getAreaPath() {
+        return areaPath;
     }
 
-    public void setAreaCode(String areaCode) {
-        this.areaCode = areaCode;
+    public void setAreaPath(String areaPath) {
+        this.areaPath = areaPath;
     }
 
     public String getTier() {
@@ -84,4 +87,24 @@ public class QueryChargingBill {
     public void setEndTime(String endTime) {
         this.endTime = endTime;
     }
+
+    public String getAreaCode() {
+        return StringUtils.split(areaPath, "/")[0];
+    }
+
+    public String getObjArea() {
+        String[] pathArray = StringUtils.split(areaPath, "/");
+
+        if (AreaTier.Area.name().equals(this.tier)) {
+            return pathArray[0];
+        }
+        else if (AreaTier.Building.name().equals(this.tier)) {
+            return pathArray[1];
+        }
+        else if (AreaTier.Zoning.name().equals(this.tier)) {
+            return pathArray[2];
+        }
+
+        return null;
+    }
 }

+ 4 - 4
ems-cloud/ems-modules/ems-server/src/main/java/com/ruoyi/ems/domain/vo/QueryMeterReading.java

@@ -30,7 +30,7 @@ public class QueryMeterReading {
     private Integer objTag;
 
     /** 计量介质 */
-    private Long meterCls;
+    private Integer meterCls;
 
     /** 年份 */
     private String year;
@@ -49,7 +49,7 @@ public class QueryMeterReading {
     public QueryMeterReading() {
     }
 
-    public QueryMeterReading(String areaCode, Integer objTag, Long meterCls, String startMonth, String endMonth) {
+    public QueryMeterReading(String areaCode, Integer objTag, Integer meterCls, String startMonth, String endMonth) {
         this.areaCode = areaCode;
         this.objTag = objTag;
         this.meterCls = meterCls;
@@ -81,11 +81,11 @@ public class QueryMeterReading {
         this.objTag = objTag;
     }
 
-    public Long getMeterCls() {
+    public Integer getMeterCls() {
         return meterCls;
     }
 
-    public void setMeterCls(Long meterCls) {
+    public void setMeterCls(Integer meterCls) {
         this.meterCls = meterCls;
     }
 

+ 14 - 9
ems-cloud/ems-modules/ems-server/src/main/java/com/ruoyi/ems/mapper/ElecUseHMapper.java

@@ -1,12 +1,15 @@
 package com.ruoyi.ems.mapper;
 
-import com.ruoyi.ems.domain.ElecUseH;
-
 import java.util.List;
+import java.util.Map;
+
+import org.apache.ibatis.annotations.Param;
+
+import com.ruoyi.ems.domain.ElecUseH;
 
 /**
  * 用能计量-小时Mapper接口
- * 
+ *
  * @author ruoyi
  * @date 2024-08-15
  */
@@ -14,7 +17,7 @@ public interface ElecUseHMapper
 {
     /**
      * 查询用能计量-小时
-     * 
+     *
      * @param id 用能计量-小时主键
      * @return 用能计量-小时
      */
@@ -22,7 +25,7 @@ public interface ElecUseHMapper
 
     /**
      * 查询用能计量-小时列表
-     * 
+     *
      * @param elecUseH 用能计量-小时
      * @return 用能计量-小时集合
      */
@@ -30,7 +33,7 @@ public interface ElecUseHMapper
 
     /**
      * 新增用能计量-小时
-     * 
+     *
      * @param elecUseH 用能计量-小时
      * @return 结果
      */
@@ -38,7 +41,7 @@ public interface ElecUseHMapper
 
     /**
      * 修改用能计量-小时
-     * 
+     *
      * @param elecUseH 用能计量-小时
      * @return 结果
      */
@@ -46,7 +49,7 @@ public interface ElecUseHMapper
 
     /**
      * 删除用能计量-小时
-     * 
+     *
      * @param id 用能计量-小时主键
      * @return 结果
      */
@@ -54,9 +57,11 @@ public interface ElecUseHMapper
 
     /**
      * 批量删除用能计量-小时
-     * 
+     *
      * @param ids 需要删除的数据主键集合
      * @return 结果
      */
      int deleteElecUseHByIds(Long[] ids);
+
+    List<Map<String, Object>> selectElecUseHByMonth(@Param("areaCode") String areaCode, @Param("date") String date);
 }

+ 9 - 0
ems-cloud/ems-modules/ems-server/src/main/java/com/ruoyi/ems/mapper/PvSupplyHMapper.java

@@ -1,7 +1,10 @@
 package com.ruoyi.ems.mapper;
 
 import java.util.List;
+import java.util.Map;
+
 import com.ruoyi.ems.domain.PvSupplyH;
+import org.apache.ibatis.annotations.Param;
 
 /**
  * 光伏并网计量光伏并网计量-小时Mapper接口
@@ -30,6 +33,12 @@ public interface PvSupplyHMapper
      List<PvSupplyH> selectAreaSupplyH(PvSupplyH pvSupplyH);
 
 
+    List<Map<String,Object>> selectAreaSupplyByDate(@Param("areaCode")String areaCode, @Param("date")String date);
+
+    List<Map<String,Object>> selectAreaSupplyByThisYear(@Param("areaCode")String areaCode, @Param("date")String date);
+
+    List<Map<String,Object>> selectAreaSupplyByMonth(@Param("areaCode")String areaCode, @Param("date")String date);
+
     /**
      * 新增光伏并网计量光伏并网计量-小时
      *

+ 9 - 0
ems-cloud/ems-modules/ems-server/src/main/java/com/ruoyi/ems/service/IAreaBuildingZoningService.java

@@ -1,6 +1,7 @@
 package com.ruoyi.ems.service;
 
 import java.util.List;
+import java.util.Set;
 
 import com.ruoyi.ems.domain.AreaBuildingZoning;
 
@@ -28,6 +29,14 @@ public interface IAreaBuildingZoningService {
     AreaBuildingZoning selectAreaBuildingZoningByCode(String code);
 
     /**
+     * 查询建筑区域划分
+     *
+     * @param codes 建筑区域划分code list
+     * @return 建筑区域划分
+     */
+    List<AreaBuildingZoning> selectByCodes(Set<String> codes);
+
+    /**
      * 查询建筑区域划分列表
      *
      * @param areaBuildingZoning 建筑区域划分

+ 7 - 0
ems-cloud/ems-modules/ems-server/src/main/java/com/ruoyi/ems/service/IChargingBillService.java

@@ -31,4 +31,11 @@ public interface IChargingBillService {
      * @return 返回列表
      */
     List<ChargingBill> selectCoChargingBill(QueryChargingBill queryParam);
+
+    /**
+     * 查询计费账单列表by标签
+     * @param queryParam 查询参数
+     * @return 返回列表
+     */
+    List<ChargingBill> selectTagChargingBill(QueryChargingBill queryParam);
 }

+ 15 - 9
ems-cloud/ems-modules/ems-server/src/main/java/com/ruoyi/ems/service/IElecUseHService.java

@@ -1,12 +1,13 @@
 package com.ruoyi.ems.service;
 
-import com.ruoyi.ems.domain.ElecUseH;
-
 import java.util.List;
+import java.util.Map;
+
+import com.ruoyi.ems.domain.ElecUseH;
 
 /**
  * 用能计量-小时Service接口
- * 
+ *
  * @author ruoyi
  * @date 2024-08-15
  */
@@ -14,7 +15,7 @@ public interface IElecUseHService
 {
     /**
      * 查询用能计量-小时
-     * 
+     *
      * @param id 用能计量-小时主键
      * @return 用能计量-小时
      */
@@ -22,7 +23,7 @@ public interface IElecUseHService
 
     /**
      * 查询用能计量-小时列表
-     * 
+     *
      * @param elecUseH 用能计量-小时
      * @return 用能计量-小时集合
      */
@@ -30,7 +31,7 @@ public interface IElecUseHService
 
     /**
      * 新增用能计量-小时
-     * 
+     *
      * @param elecUseH 用能计量-小时
      * @return 结果
      */
@@ -38,7 +39,7 @@ public interface IElecUseHService
 
     /**
      * 修改用能计量-小时
-     * 
+     *
      * @param elecUseH 用能计量-小时
      * @return 结果
      */
@@ -46,7 +47,7 @@ public interface IElecUseHService
 
     /**
      * 批量删除用能计量-小时
-     * 
+     *
      * @param ids 需要删除的用能计量-小时主键集合
      * @return 结果
      */
@@ -54,9 +55,14 @@ public interface IElecUseHService
 
     /**
      * 删除用能计量-小时信息
-     * 
+     *
      * @param id 用能计量-小时主键
      * @return 结果
      */
      int deleteElecUseHById(Long id);
+
+    /**
+     * 查询用能和发电量
+     */
+    List<Map> selectElecAndPower(String areaCode);
 }

+ 8 - 0
ems-cloud/ems-modules/ems-server/src/main/java/com/ruoyi/ems/service/IPvSupplyHService.java

@@ -1,6 +1,8 @@
 package com.ruoyi.ems.service;
 
 import java.util.List;
+import java.util.Map;
+
 import com.ruoyi.ems.domain.PvSupplyH;
 
 /**
@@ -29,6 +31,12 @@ public interface IPvSupplyHService
 
 
      List<PvSupplyH> selectAreaSupplyH(PvSupplyH admEmsPvSupplyH);
+
+    List<Map<String, Object>> selectAreaSupplyHByThisDay(String areaCode);
+
+    List<Map<String, Object>> selectAreaSupplyHByRefMonth(String areaCode);
+
+    List<Map<String, Object>> selectAreaSupplyHByYear(String areaCode);
     /**
      * 新增光伏并网计量-小时
      *

+ 6 - 0
ems-cloud/ems-modules/ems-server/src/main/java/com/ruoyi/ems/service/impl/AreaBuildingZoningServiceImpl.java

@@ -16,6 +16,7 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.function.Function;
 import java.util.stream.Collectors;
 
@@ -60,6 +61,11 @@ public class AreaBuildingZoningServiceImpl implements IAreaBuildingZoningService
         return areaBuildingZoningMapper.selectAreaBuildingZoningByCode(code);
     }
 
+    @Override
+    public List<AreaBuildingZoning> selectByCodes(Set<String> codes) {
+        return areaBuildingZoningMapper.selectByCodes(codes);
+    }
+
     /**
      * 查询建筑区域划分列表
      *

+ 281 - 63
ems-cloud/ems-modules/ems-server/src/main/java/com/ruoyi/ems/service/impl/ChargingBillServiceImpl.java

@@ -10,28 +10,38 @@
  */
 package com.ruoyi.ems.service.impl;
 
+import com.ruoyi.common.core.utils.StringUtils;
+import com.ruoyi.ems.domain.Area;
+import com.ruoyi.ems.domain.AreaBuilding;
 import com.ruoyi.ems.domain.AreaBuildingZoning;
 import com.ruoyi.ems.domain.ChargingBill;
 import com.ruoyi.ems.domain.CoChargingConfig;
 import com.ruoyi.ems.domain.CoChargingConfigRel;
 import com.ruoyi.ems.domain.MeterDevice;
 import com.ruoyi.ems.domain.MeterReading;
+import com.ruoyi.ems.domain.common.AreaTier;
 import com.ruoyi.ems.domain.common.MeterObjSubType;
 import com.ruoyi.ems.domain.common.MeterObjTag;
 import com.ruoyi.ems.domain.common.MeterObjType;
 import com.ruoyi.ems.domain.vo.QueryChargingBill;
 import com.ruoyi.ems.domain.vo.QueryMeterReading;
-import com.ruoyi.ems.mapper.AreaBuildingZoningMapper;
 import com.ruoyi.ems.mapper.MeterDeviceMapper;
 import com.ruoyi.ems.mapper.MeterReadingMapper;
+import com.ruoyi.ems.service.IAreaBuildingService;
+import com.ruoyi.ems.service.IAreaBuildingZoningService;
+import com.ruoyi.ems.service.IAreaService;
 import com.ruoyi.ems.service.IChargingBillService;
 import com.ruoyi.ems.service.ICoChargingConfigService;
+import com.ruoyi.ems.util.DateUtils;
+import org.apache.commons.collections4.MapUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
@@ -58,7 +68,13 @@ public class ChargingBillServiceImpl implements IChargingBillService {
     private MeterDeviceMapper meterDeviceMapper;
 
     @Autowired
-    private AreaBuildingZoningMapper areaBuildingZoningMapper;
+    private IAreaService areaService;
+
+    @Autowired
+    private IAreaBuildingService buildingService;
+
+    @Autowired
+    private IAreaBuildingZoningService zoningService;
 
     @Autowired
     private ICoChargingConfigService coChargingConfigService;
@@ -71,13 +87,108 @@ public class ChargingBillServiceImpl implements IChargingBillService {
      */
     @Override
     public List<ChargingBill> selectCoChargingBill(QueryChargingBill queryParam) {
+        // 查询园区内部计费配置
+        CoChargingConfig chargingCfg = coChargingConfigService.selectByArea(queryParam.getAreaCode());
+
+        // 计算个户账单
+        Map<String, ChargingBill> coBillMap = clacCoBill(queryParam, chargingCfg);
+
+        // 计算公摊账单
+        Map<String, ChargingBill> sharedMap = clacSharedBill(queryParam, chargingCfg);
+
+        return mergeBill(queryParam, coBillMap, sharedMap);
+    }
+
+    @Override
+    public List<ChargingBill> selectTagChargingBill(QueryChargingBill queryParam) {
+        // 查询园区内部计费配置
+        CoChargingConfig chargingCfg = coChargingConfigService.selectByArea(queryParam.getAreaCode());
+
+        Map<String, Long> individualMap = getQuantityByTag(queryParam, MeterObjTag.INDIVIDUAL);
+        Map<String, Long> sharedMap = getQuantityByTag(queryParam, MeterObjTag.SHARED);
+
+        List<ChargingBill> retList = new ArrayList<>();
+        Date start = DateUtils.stringToDate(queryParam.getStartTime(), "yyyyMM");
+        Date end = DateUtils.stringToDate(queryParam.getEndTime(), "yyyyMM");
+        String objName = getObjName(queryParam);
+
+        do {
+            String time = DateUtils.dateToString(start, "yyyyMM");
+
+            ChargingBill bill = new ChargingBill();
+            bill.setObjCode(queryParam.getObjArea());
+            bill.setMeteredTime(time);
+            bill.setObjName(objName);
+
+            long individual = (null != individualMap.get(time)) ? individualMap.get(time) : 0L;
+            bill.setMeteredValue((double) individual);
+            bill.setMeteredPrice(calcPrice(queryParam.getMeterCls(), individual, chargingCfg));
+
+            long shared = (null != sharedMap.get(time)) ? sharedMap.get(time) : 0L;
+            bill.setSharedValue(shared);
+            bill.setSharedPrice(calcPrice(queryParam.getMeterCls(), shared, chargingCfg));
+
+            bill.setTotalValue(individual + shared);
+            bill.setTotalPrice(clacTotalPrice(bill));
+
+            retList.add(bill);
+
+            start = DateUtils.adjustMonth(start, 1);
+        }
+        while (start.before(end) || start.equals(end));
+
+        return retList;
+    }
+
+    private List<ChargingBill> mergeBill(QueryChargingBill queryParam, Map<String, ChargingBill> coBillMap,
+        Map<String, ChargingBill> sharedMap) {
         List<ChargingBill> retList = new ArrayList<>();
+        Date start = DateUtils.stringToDate(queryParam.getStartTime(), "yyyyMM");
+        Date end = DateUtils.stringToDate(queryParam.getEndTime(), "yyyyMM");
+        String objName = getObjName(queryParam);
+
+        do {
+            String time = DateUtils.dateToString(start, "yyyyMM");
+
+            ChargingBill bill = new ChargingBill();
+            bill.setObjCode(queryParam.getObjArea());
+            bill.setMeteredTime(time);
+            bill.setObjName(objName);
+
+            ChargingBill coBill = coBillMap.get(time);
+
+            if (null != coBill) {
+                bill.setMeteredValue(coBill.getMeteredValue());
+                bill.setMeteredPrice(coBill.getMeteredPrice());
+            }
+
+            ChargingBill sharedBill = sharedMap.get(time);
+
+            if (null != sharedBill) {
+                bill.setSharedPrice(sharedBill.getSharedPrice());
+                bill.setSharedComputeType(sharedBill.getSharedComputeType());
+            }
+
+            bill.setTotalPrice(clacTotalPrice(bill));
+
+            retList.add(bill);
+
+            start = DateUtils.adjustMonth(start, 1);
+        }
+        while (start.before(end) || start.equals(end));
+
+        return retList;
+    }
+
+    private Map<String, ChargingBill> clacCoBill(QueryChargingBill queryParam, CoChargingConfig chargingCfg) {
+        Map<String, ChargingBill> retMap = null;
 
         // 查询计量设备
         int objType = MeterObjType.METER_ABZ.getType();
         int objSubType = MeterObjSubType.getByTier(queryParam.getTier()).getType();
-        MeterDevice meterDevice = meterDeviceMapper.selectMeterDeviceByObj(objType, objSubType,
-            queryParam.getAreaCode(), queryParam.getMeterCls());
+
+        MeterDevice meterDevice = meterDeviceMapper.selectMeterDeviceByObj(objType, objSubType, queryParam.getObjArea(),
+            queryParam.getMeterCls());
 
         if (null != meterDevice) {
             QueryMeterReading recParam = new QueryMeterReading();
@@ -87,98 +198,142 @@ public class ChargingBillServiceImpl implements IChargingBillService {
             recParam.setEndMonth(queryParam.getEndTime());
 
             List<MeterReading> recList = meterReadingMapper.selectList(recParam);
-            retList = convertToChargingBill(meterDevice, queryParam, recList);
+            List<ChargingBill> billList = convertToChargingBill(queryParam, chargingCfg, recList);
+            retMap = billList.stream().collect(Collectors.toMap(ChargingBill::getMeteredTime, Function.identity()));
         }
 
-        return retList;
+        return MapUtils.isNotEmpty(retMap) ? retMap : new HashMap<>();
     }
 
-    private List<ChargingBill> convertToChargingBill(MeterDevice meterDevice, QueryChargingBill queryParam,
-        List<MeterReading> recList) {
-        List<ChargingBill> retList = new ArrayList<>();
+    private Map<String, ChargingBill> clacSharedBill(QueryChargingBill queryParam, CoChargingConfig chargingCfg) {
+        Map<String, ChargingBill> retMap = null;
 
-        // 查询园区内部计费配置
-        CoChargingConfig chargingCfg = coChargingConfigService.selectByArea(meterDevice.getAreaCode());
+        if (queryParam.getMeterCls() == 45) {
+            retMap = clacElecSharedPrice(queryParam, chargingCfg);
+        }
+        else if (queryParam.getMeterCls() == 70) {
+            retMap = clacWaterSharedPrice(queryParam, chargingCfg);
+        }
 
-        // 参与公摊的分区ID
-        Set<String> coSet = getCoSet(chargingCfg);
+        return MapUtils.isNotEmpty(retMap) ? retMap : new HashMap<>();
+    }
+
+    private List<ChargingBill> convertToChargingBill(QueryChargingBill queryParam, CoChargingConfig chargingCfg,
+        List<MeterReading> recList) {
+        List<ChargingBill> retList = new ArrayList<>();
 
         for (MeterReading rec : recList) {
             ChargingBill bill = new ChargingBill();
-            bill.setObjType(meterDevice.getObjType());
-            bill.setObjSubType(meterDevice.getObjSubType());
-            bill.setObjCode(meterDevice.getObjCode());
             bill.setMeteredValue(rec.getIncrease().doubleValue());
             bill.setMeteredTime(rec.getMeterMonth());
 
-            // 计算商户个体费用、公摊费用
+            // 计算商户个体费用
             if (null != chargingCfg) {
-                if (meterDevice.getMeterCls() == 45) {
+                if (queryParam.getMeterCls() == 45) {
                     bill.setMeteredPrice(calcPrice(rec.getIncrease(), chargingCfg.getElecUnitPrice()));
-                    bill.setSharedComputeType(chargingCfg.getElecGtComputeType());
-                    clacElecSharedPrice(bill, meterDevice, chargingCfg, queryParam, coSet);
                 }
-                else if (meterDevice.getMeterCls() == 70) {
+                else if (queryParam.getMeterCls() == 70) {
                     bill.setMeteredPrice(calcPrice(rec.getIncrease(), chargingCfg.getWaterUnitPrice()));
-                    bill.setSharedComputeType(chargingCfg.getWaterGtComputeType());
-                    clacWaterSharedPrice(bill, meterDevice, chargingCfg, queryParam, coSet);
                 }
             }
 
-            bill.setTotalPrice(clacTotalPrice(bill));
             retList.add(bill);
         }
 
         return retList;
     }
 
-    private Set<String> getCoSet(CoChargingConfig chargingCfg) {
-        Set<String> coSet;
+    private Map<String, ChargingBill> clacElecSharedPrice(QueryChargingBill queryParam, CoChargingConfig chargingCfg) {
+        Map<String, ChargingBill> retMap = new HashMap<>();
+        // 参与公摊的分区ID
+        Set<String> coSet = getCoSet(chargingCfg);
 
-        if (null != chargingCfg) {
-            coSet = chargingCfg.getRelCoList().stream().map(CoChargingConfigRel::getZoningCode)
-                .collect(Collectors.toSet());
-        }
-        else {
-            coSet = new HashSet<>();
+        // 电价公摊计算
+        if (chargingCfg.getElecGtComputeType() > 0 && coSet.contains(queryParam.getObjArea())) {
+            QueryMeterReading param = new QueryMeterReading(queryParam.getAreaCode(), MeterObjTag.SHARED.getTagValue(),
+                queryParam.getMeterCls(), queryParam.getStartTime(), queryParam.getEndTime());
+            List<MeterReading> totalReadings = meterReadingMapper.selectByTag(param);
+            Map<String, List<MeterReading>> groupedRecs = totalReadings.stream()
+                .collect(Collectors.groupingBy(MeterReading::getMeterMonth));
+
+            for (Map.Entry<String, List<MeterReading>> entry : groupedRecs.entrySet()) {
+                String meterTime = entry.getKey();
+                List<MeterReading> sharedReadings = entry.getValue();
+
+                // 公摊价格计算
+                Double price = clacSharedPrice(sharedReadings, coSet, queryParam.getObjArea(),
+                    chargingCfg.getElecGtComputeType(), chargingCfg.getElecUnitPrice());
+
+                ChargingBill bill = new ChargingBill();
+                bill.setSharedPrice(price);
+                bill.setSharedComputeType(chargingCfg.getElecGtComputeType());
+
+                retMap.put(meterTime, bill);
+            }
         }
 
-        return coSet;
+        return retMap;
     }
 
-    private void clacElecSharedPrice(ChargingBill bill, MeterDevice meterDevice, CoChargingConfig chargingCfg,
-        QueryChargingBill queryParam, Set<String> coSet) {
+    private Map<String, ChargingBill> clacWaterSharedPrice(QueryChargingBill queryParam, CoChargingConfig chargingCfg) {
+        Map<String, ChargingBill> retMap = new HashMap<>();
+        // 参与公摊的分区ID
+        Set<String> coSet = getCoSet(chargingCfg);
+
+        // 水价公摊计算
+        if (chargingCfg.getWaterGtComputeType() > 0 && coSet.contains(queryParam.getObjArea())) {
+            QueryMeterReading param = new QueryMeterReading(queryParam.getAreaCode(), MeterObjTag.SHARED.getTagValue(),
+                queryParam.getMeterCls(), queryParam.getStartTime(), queryParam.getEndTime());
+            List<MeterReading> totalReadings = meterReadingMapper.selectByTag(param);
+            Map<String, List<MeterReading>> groupedRecs = totalReadings.stream()
+                .collect(Collectors.groupingBy(MeterReading::getMeterMonth));
+
+            for (Map.Entry<String, List<MeterReading>> entry : groupedRecs.entrySet()) {
+                String meterTime = entry.getKey();
+                List<MeterReading> sharedReadings = entry.getValue();
+
+                // 公摊价格计算
+                Double price = clacSharedPrice(sharedReadings, coSet, queryParam.getObjArea(),
+                    chargingCfg.getWaterGtComputeType(), chargingCfg.getWaterUnitPrice());
+
+                ChargingBill bill = new ChargingBill();
+                bill.setObjCode(queryParam.getObjArea());
+                bill.setSharedPrice(price);
+                bill.setSharedComputeType(chargingCfg.getElecGtComputeType());
+
+                retMap.put(meterTime, bill);
+            }
 
-        // 电价公摊计算
-        if (chargingCfg.getElecGtComputeType() > 0 && coSet.contains(meterDevice.getObjCode())) {
-            QueryMeterReading param = new QueryMeterReading(meterDevice.getAreaCode(), MeterObjTag.SHARED.getTagValue(),
-                meterDevice.getMeterCls(), queryParam.getStartTime(), queryParam.getEndTime());
-            List<MeterReading> sharedReadings = meterReadingMapper.selectByTag(param);
-            Double price = clacSharedPrice(sharedReadings, coSet, meterDevice.getObjCode(),
-                chargingCfg.getElecGtComputeType(), chargingCfg.getElecUnitPrice());
-
-            bill.setSharedPrice(price);
         }
+
+        return retMap;
     }
 
-    private void clacWaterSharedPrice(ChargingBill bill, MeterDevice meterDevice, CoChargingConfig chargingCfg,
-        QueryChargingBill queryParam, Set<String> coSet) {
-        // 水价公摊计算
-        if (chargingCfg.getWaterGtComputeType() > 0 && coSet.contains(meterDevice.getObjCode())) {
-            QueryMeterReading param = new QueryMeterReading(meterDevice.getAreaCode(), MeterObjTag.SHARED.getTagValue(),
-                meterDevice.getMeterCls(), queryParam.getStartTime(), queryParam.getEndTime());
-            List<MeterReading> sharedReadings = meterReadingMapper.selectByTag(param);
-            Double price = clacSharedPrice(sharedReadings, coSet, meterDevice.getObjCode(),
-                chargingCfg.getWaterGtComputeType(), chargingCfg.getWaterUnitPrice());
-
-            bill.setSharedPrice(price);
+    private Map<String, Long> getQuantityByTag(QueryChargingBill queryParam, MeterObjTag tag) {
+        Map<String, Long> retMap = new HashMap<>();
+
+        QueryMeterReading param = new QueryMeterReading(queryParam.getAreaCode(), tag.getTagValue(),
+            queryParam.getMeterCls(), queryParam.getStartTime(), queryParam.getEndTime());
+        List<MeterReading> totalReadings = meterReadingMapper.selectByTag(param);
+        Map<String, List<MeterReading>> groupedRecs = totalReadings.stream()
+            .collect(Collectors.groupingBy(MeterReading::getMeterMonth));
+
+        for (Map.Entry<String, List<MeterReading>> entry : groupedRecs.entrySet()) {
+            String meterTime = entry.getKey();
+            List<MeterReading> sharedReadings = entry.getValue();
+
+            // 公摊用量
+            Long sharedQuantity = sumSharedReadings(sharedReadings);
+            retMap.put(meterTime, sharedQuantity);
         }
+
+        return retMap;
     }
 
     /**
      * 计算公摊价
      *
-     * @return
+     * @return 价格
      */
     private Double clacSharedPrice(List<MeterReading> sharedReadings, Set<String> coSet, String objCode,
         int gtComputeType, Double unitPrice) {
@@ -210,7 +365,7 @@ public class ChargingBillServiceImpl implements IChargingBillService {
     }
 
     private double sharedPriceByArea(Double sharedPriceSum, String objCode, Set<String> coSet) {
-        List<AreaBuildingZoning> zonings = areaBuildingZoningMapper.selectByCodes(coSet);
+        List<AreaBuildingZoning> zonings = zoningService.selectByCodes(coSet);
         Map<String, AreaBuildingZoning> map = zonings.stream()
             .collect(Collectors.toMap(AreaBuildingZoning::getZoningCode, Function.identity()));
         AreaBuildingZoning zoning = map.get(objCode);
@@ -218,7 +373,6 @@ public class ChargingBillServiceImpl implements IChargingBillService {
         Long areas = sumSharedAreas(zonings);
 
         BigDecimal bd1 = new BigDecimal(sharedPriceSum.toString());
-
         BigDecimal bd2 = new BigDecimal(areas.toString());
         BigDecimal bd3 = new BigDecimal(zoning.getBldgLdArea().toString());
 
@@ -247,6 +401,25 @@ public class ChargingBillServiceImpl implements IChargingBillService {
     /**
      * 计算用量总价
      *
+     * @param meterCls  计量类别
+     * @param dosage    用量
+     * @param chargingCfg 价格配置
+     * @return 返回总价
+     */
+    private Double calcPrice(int meterCls, Long dosage, CoChargingConfig chargingCfg) {
+        if (meterCls == 45) {
+            return calcPrice(dosage, chargingCfg.getElecUnitPrice());
+        }
+        else if (meterCls == 70) {
+            return calcPrice(dosage, chargingCfg.getWaterUnitPrice());
+        }
+
+        return null;
+    }
+
+    /**
+     * 计算用量总价
+     *
      * @param dosage    用量
      * @param unitPrice 价格配置
      * @return 返回总价
@@ -259,13 +432,58 @@ public class ChargingBillServiceImpl implements IChargingBillService {
     }
 
     private Double clacTotalPrice(ChargingBill bill) {
-        BigDecimal bd1 = new BigDecimal(bill.getMeteredPrice().toString());
-
-        if (null != bill.getSharedPrice()) {
+        if (null != bill.getMeteredPrice() && null != bill.getSharedPrice()) {
+            BigDecimal bd1 = new BigDecimal(bill.getMeteredPrice().toString());
             BigDecimal bd2 = new BigDecimal(bill.getSharedPrice().toString());
-            bd1 = bd1.add(bd2);
+            return bd1.add(bd2).setScale(3, RoundingMode.HALF_UP).doubleValue();
+        }
+        else if (null == bill.getMeteredPrice() && null != bill.getSharedPrice()) {
+            return bill.getSharedPrice();
+        }
+        else if (null != bill.getMeteredPrice() && null == bill.getSharedPrice()) {
+            return bill.getMeteredPrice();
+        }
+        else {
+            return null;
+        }
+    }
+
+    private Set<String> getCoSet(CoChargingConfig chargingCfg) {
+        Set<String> coSet;
+
+        if (null != chargingCfg) {
+            coSet = chargingCfg.getRelCoList().stream().map(CoChargingConfigRel::getZoningCode)
+                .collect(Collectors.toSet());
+        }
+        else {
+            coSet = new HashSet<>();
+        }
+
+        return coSet;
+    }
+
+    private String getObjName(QueryChargingBill queryParam) {
+        String objName = "未知";
+
+        if (StringUtils.equals(AreaTier.Area.name(), queryParam.getTier())) {
+            Area area = areaService.selectAreaByCode(queryParam.getObjArea());
+            objName = area != null ? area.getShortName() : "未知";
+        }
+        else if (StringUtils.equals(AreaTier.Building.name(), queryParam.getTier())) {
+            AreaBuilding building = buildingService.selectAreaBuildingByCode(queryParam.getObjArea());
+            objName = (building != null) ? (building.getAreaShortName() + "/" + building.getBldgName()) : "未知";
+        }
+        else if (StringUtils.equals(AreaTier.Zoning.name(), queryParam.getTier())) {
+            AreaBuildingZoning zoning = zoningService.selectAreaBuildingZoningByCode(queryParam.getObjArea());
+
+            if (null != zoning) {
+                AreaBuilding building = buildingService.selectAreaBuildingByCode(zoning.getBldgCode());
+                objName = (building != null) ?
+                    (building.getAreaShortName() + "/" + building.getBldgName() + "/" + zoning.getZoningName()) :
+                    "未知";
+            }
         }
 
-        return bd1.setScale(3, RoundingMode.HALF_UP).doubleValue();
+        return objName;
     }
 }

+ 54 - 23
ems-cloud/ems-modules/ems-server/src/main/java/com/ruoyi/ems/service/impl/ElecUseHServiceImpl.java

@@ -1,94 +1,125 @@
 package com.ruoyi.ems.service.impl;
 
+import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import com.ruoyi.common.core.utils.DateTimeUtil;
+import com.ruoyi.common.core.utils.StreamUtils;
 import com.ruoyi.ems.domain.ElecUseH;
 import com.ruoyi.ems.mapper.ElecUseHMapper;
+import com.ruoyi.ems.mapper.PvSupplyHMapper;
 import com.ruoyi.ems.service.IElecUseHService;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
+
+import cn.hutool.core.map.MapUtil;
 
 /**
  * 用能计量-小时Service业务层处理
- * 
+ *
  * @author ruoyi
  * @date 2024-08-15
  */
 @Service
-public class ElecUseHServiceImpl implements IElecUseHService
-{
+public class ElecUseHServiceImpl implements IElecUseHService {
     @Autowired
     private ElecUseHMapper elecUseHMapper;
 
+    @Autowired
+    private PvSupplyHMapper pvSupplyHMapper;
+
     /**
      * 查询用能计量-小时
-     * 
+     *
      * @param id 用能计量-小时主键
      * @return 用能计量-小时
      */
     @Override
-    public ElecUseH selectElecUseHById(Long id)
-    {
+    public ElecUseH selectElecUseHById(Long id) {
         return elecUseHMapper.selectElecUseHById(id);
     }
 
     /**
      * 查询用能计量-小时列表
-     * 
+     *
      * @param ElecUseH 用能计量-小时
      * @return 用能计量-小时
      */
     @Override
-    public List<ElecUseH> selectElecUseHList(ElecUseH ElecUseH)
-    {
+    public List<ElecUseH> selectElecUseHList(ElecUseH ElecUseH) {
         return elecUseHMapper.selectElecUseHList(ElecUseH);
     }
 
     /**
      * 新增用能计量-小时
-     * 
+     *
      * @param ElecUseH 用能计量-小时
      * @return 结果
      */
     @Override
-    public int insertElecUseH(ElecUseH ElecUseH)
-    {
+    public int insertElecUseH(ElecUseH ElecUseH) {
         return elecUseHMapper.insertElecUseH(ElecUseH);
     }
 
     /**
      * 修改用能计量-小时
-     * 
+     *
      * @param ElecUseH 用能计量-小时
      * @return 结果
      */
     @Override
-    public int updateElecUseH(ElecUseH ElecUseH)
-    {
+    public int updateElecUseH(ElecUseH ElecUseH) {
         return elecUseHMapper.updateElecUseH(ElecUseH);
     }
 
     /**
      * 批量删除用能计量-小时
-     * 
+     *
      * @param ids 需要删除的用能计量-小时主键
      * @return 结果
      */
     @Override
-    public int deleteElecUseHByIds(Long[] ids)
-    {
+    public int deleteElecUseHByIds(Long[] ids) {
         return elecUseHMapper.deleteElecUseHByIds(ids);
     }
 
     /**
      * 删除用能计量-小时信息
-     * 
+     *
      * @param id 用能计量-小时主键
      * @return 结果
      */
     @Override
-    public int deleteElecUseHById(Long id)
-    {
+    public int deleteElecUseHById(Long id) {
         return elecUseHMapper.deleteElecUseHById(id);
     }
+
+    @Override
+    public List<Map> selectElecAndPower(String areaCode) {
+        String firstDayOfRecentYear = DateTimeUtil.getFirstDayOfRecentYear();
+        List<Map<String, Object>> monthElecUse = elecUseHMapper.selectElecUseHByMonth(areaCode, firstDayOfRecentYear);
+        List<Map<String, Object>> monthPv = pvSupplyHMapper.selectAreaSupplyByMonth(areaCode, firstDayOfRecentYear);
+        Map<String, Map<String, Object>> dateElecUseIndex = StreamUtils.toIdentityMap(monthElecUse,
+            map -> MapUtil.getStr(map, "dateIndex"));
+        Map<String, Map<String, Object>> datePvIndex = StreamUtils.toIdentityMap(monthPv,
+            map -> MapUtil.getStr(map, "dateIndex"));
+        List<String> dates = DateTimeUtil.monthOfRange(firstDayOfRecentYear,
+            DateTimeUtil.currentDateTime(DateTimeUtil.DateFormatter.yyyy_MM_dd), DateTimeUtil.DateFormatter.yyyy_MM_dd,
+            DateTimeUtil.DateFormatter.yyyy_MM);
+        List<Map> result = new ArrayList<>();
+        Map<Object, Object> dateIndex;
+        for (String date : dates) {
+            dateIndex = MapUtil.builder().put("dateIndex", date).map();
+            if (dateElecUseIndex.containsKey(date)) {
+                dateIndex.putAll(dateElecUseIndex.get(date));
+            }
+            if (datePvIndex.containsKey(date)) {
+                dateIndex.putAll(datePvIndex.get(date));
+            }
+            result.add(dateIndex);
+        }
+        return result;
+    }
 }

+ 23 - 1
ems-cloud/ems-modules/ems-server/src/main/java/com/ruoyi/ems/service/impl/PvSupplyHServiceImpl.java

@@ -1,10 +1,14 @@
 package com.ruoyi.ems.service.impl;
 
 import java.util.List;
+import java.util.Map;
+
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
-import com.ruoyi.ems.mapper.PvSupplyHMapper;
+
+import com.ruoyi.common.core.utils.DateTimeUtil;
 import com.ruoyi.ems.domain.PvSupplyH;
+import com.ruoyi.ems.mapper.PvSupplyHMapper;
 import com.ruoyi.ems.service.IPvSupplyHService;
 
 /**
@@ -45,6 +49,24 @@ public class PvSupplyHServiceImpl implements IPvSupplyHService {
         return pvSupplyHMapper.selectAreaSupplyH(PvSupplyH);
     }
 
+    @Override
+    public List<Map<String, Object>> selectAreaSupplyHByThisDay(String areaCode) {
+        String dateTime = DateTimeUtil.currentDateTime(DateTimeUtil.DateFormatter.yyyy_MM_dd);
+        return pvSupplyHMapper.selectAreaSupplyByDate(areaCode, dateTime);
+    }
+
+    @Override
+    public List<Map<String, Object>> selectAreaSupplyHByRefMonth(String areaCode) {
+        String firstDayOfRecentMonth = DateTimeUtil.getFirstDayOfRecentMonth();
+        return pvSupplyHMapper.selectAreaSupplyByDate(areaCode, firstDayOfRecentMonth);
+    }
+
+    @Override
+    public List<Map<String, Object>> selectAreaSupplyHByYear(String areaCode) {
+        String dateTime = DateTimeUtil.getFirstDayOfThisYear(DateTimeUtil.DateFormatter.yyyy_MM_dd);
+        return pvSupplyHMapper.selectAreaSupplyByThisYear(areaCode, dateTime);
+    }
+
     /**
      * 新增光伏并网计量光伏并网计量-小时
      *

+ 103 - 43
ems-cloud/ems-modules/ems-server/src/main/resources/mapper/ems/ElecPvSupplyHMapper.xml

@@ -1,59 +1,71 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!DOCTYPE mapper
-PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
-"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.ruoyi.ems.mapper.PvSupplyHMapper">
     <resultMap type="com.ruoyi.ems.domain.PvSupplyH" id="PvSupplyHResult">
-        <result property="id"    column="id"    />
-        <result property="areaCode"    column="area_code"    />
-        <result property="areaName"    column="area_name"    />
-        <result property="areaShortName"    column="area_short_name"    />
-        <result property="facsCode"    column="facs_code"    />
-        <result property="facsName"    column="facs_name"    />
-        <result property="date"    column="date"  jdbcType="DATE"  />
-        <result property="time"    column="time"    />
-        <result property="timeIndex"    column="time_index"    />
-        <result property="upUnitPrice"    column="up_unit_price"    />
-        <result property="genElecQuantity"    column="gen_elec_quantity"    />
-        <result property="useElecQuantity"    column="use_elec_quantity"    />
-        <result property="upElecQuantity"    column="up_elec_quantity"    />
-        <result property="upElecEarn"    column="up_elec_earn"    />
+        <result property="id" column="id"/>
+        <result property="areaCode" column="area_code"/>
+        <result property="areaName" column="area_name"/>
+        <result property="areaShortName" column="area_short_name"/>
+        <result property="facsCode" column="facs_code"/>
+        <result property="facsName" column="facs_name"/>
+        <result property="date" column="date" jdbcType="DATE"/>
+        <result property="time" column="time"/>
+        <result property="timeIndex" column="time_index"/>
+        <result property="upUnitPrice" column="up_unit_price"/>
+        <result property="genElecQuantity" column="gen_elec_quantity"/>
+        <result property="useElecQuantity" column="use_elec_quantity"/>
+        <result property="upElecQuantity" column="up_elec_quantity"/>
+        <result property="upElecEarn" column="up_elec_earn"/>
     </resultMap>
 
     <sql id="selectPvSupplyHVo">
-        select
-            pv.id, pv.area_code, a.area_name, a.short_name as area_short_name, pv.facs_code, f.facs_name, pv.`date`, pv.`time`, pv.time_index, pv.up_unit_price, pv.gen_elec_quantity, pv.use_elec_quantity, pv.up_elec_quantity, pv.up_elec_earn
+        select pv.id,
+               pv.area_code,
+               a.area_name,
+               a.short_name as area_short_name,
+               pv.facs_code,
+               f.facs_name,
+               pv.`date`,
+               pv.`time`,
+               pv.time_index,
+               pv.up_unit_price,
+               pv.gen_elec_quantity,
+               pv.use_elec_quantity,
+               pv.up_elec_quantity,
+               pv.up_elec_earn
         from adm_ems_pv_supply_h pv
-            LEFT JOIN adm_service_area a ON pv.`area_code` = a.`area_code`
-            LEFT JOIN adm_ems_facs f ON pv.`facs_code` = f.`facs_code`
+                 LEFT JOIN adm_service_area a ON pv.`area_code` = a.`area_code`
+                 LEFT JOIN adm_ems_facs f ON pv.`facs_code` = f.`facs_code`
     </sql>
 
     <select id="selectPvSupplyHList" parameterType="com.ruoyi.ems.domain.PvSupplyH" resultMap="PvSupplyHResult">
         <include refid="selectPvSupplyHVo"/>
         <where>
-            <if test="areaCode != null  and areaCode != ''"> and pv.area_code = #{areaCode}</if>
-            <if test="facsCode != null  and facsCode != ''"> and pv.facs_code = #{facsCode}</if>
-            <if test="date != null "> and pv.`date` = #{date}</if>
-            <if test="time != null "> and pv.`time` = #{time}</if>
-            <if test="timeIndex != null "> and pv.time_index = #{timeIndex}</if>
-            <if test="upUnitPrice != null "> and pv.up_unit_price = #{upUnitPrice}</if>
-            <if test="genElecQuantity != null "> and pv.gen_elec_quantity = #{genElecQuantity}</if>
-            <if test="useElecQuantity != null "> and pv.use_elec_quantity = #{useElecQuantity}</if>
-            <if test="upElecQuantity != null "> and pv.up_elec_quantity = #{upElecQuantity}</if>
-            <if test="upElecEarn != null "> and pv.up_elec_earn = #{upElecEarn}</if>
+            <if test="areaCode != null  and areaCode != ''">and pv.area_code = #{areaCode}</if>
+            <if test="facsCode != null  and facsCode != ''">and pv.facs_code = #{facsCode}</if>
+            <if test="date != null ">and pv.`date` = #{date}</if>
+            <if test="time != null ">and pv.`time` = #{time}</if>
+            <if test="timeIndex != null ">and pv.time_index = #{timeIndex}</if>
+            <if test="upUnitPrice != null ">and pv.up_unit_price = #{upUnitPrice}</if>
+            <if test="genElecQuantity != null ">and pv.gen_elec_quantity = #{genElecQuantity}</if>
+            <if test="useElecQuantity != null ">and pv.use_elec_quantity = #{useElecQuantity}</if>
+            <if test="upElecQuantity != null ">and pv.up_elec_quantity = #{upElecQuantity}</if>
+            <if test="upElecEarn != null ">and pv.up_elec_earn = #{upElecEarn}</if>
         </where>
     </select>
 
     <select id="selectAreaSupplyH" parameterType="com.ruoyi.ems.domain.PvSupplyH" resultMap="PvSupplyHResult">
-        SELECT area_code, `date`, time_index,
-               SUM( gen_elec_quantity ) as gen_elec_quantity,
-               SUM( use_elec_quantity ) as use_elec_quantity,
-               SUM( up_elec_quantity ) as up_elec_quantity,
-               SUM( up_elec_earn ) as up_elec_earn
-        FROM
-            adm_ems_pv_supply_h
-        WHERE
-            area_code = #{areaCode}
+        SELECT area_code,
+               `date`,
+               time_index,
+               SUM(gen_elec_quantity) as gen_elec_quantity,
+               SUM(use_elec_quantity) as use_elec_quantity,
+               SUM(up_elec_quantity)  as up_elec_quantity,
+               SUM(up_elec_earn)      as up_elec_earn
+        FROM adm_ems_pv_supply_h
+        WHERE area_code = #{areaCode}
           AND DATE = #{date,jdbcType=DATE}
         GROUP BY
             area_code,
@@ -62,12 +74,58 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             time_index ASC
     </select>
 
+    <select id="selectAreaSupplyByDate" resultType="Map">
+        SELECT area_code,
+               DATE_FORMAT(date, '%Y-%m-%d') AS dateIndex,
+               SUM(gen_elec_quantity)        as genElecQuantity,
+               SUM(use_elec_quantity)        as useElecQuantity,
+               SUM(up_elec_quantity)         as upElecQuantity,
+               SUM(up_elec_earn)             as upElecEarn
+        FROM adm_ems_pv_supply_h
+        WHERE area_code = #{areaCode}
+          AND DATE >= #{date}
+        GROUP BY
+            area_code,
+            dateIndex
+    </select>
+
+    <select id="selectAreaSupplyByMonth" resultType="Map">
+        SELECT area_code,
+               DATE_FORMAT(date, '%Y-%m') AS dateIndex,
+               SUM(gen_elec_quantity)        as genElecQuantity,
+               SUM(use_elec_quantity)        as useElecQuantity,
+               SUM(up_elec_quantity)         as upElecQuantity,
+               SUM(up_elec_earn)             as upElecEarn
+        FROM adm_ems_pv_supply_h
+        WHERE area_code = #{areaCode}
+          AND DATE >= #{date}
+        GROUP BY
+            area_code,
+            dateIndex
+    </select>
+
+    <select id="selectAreaSupplyByThisYear" resultType="Map">
+        SELECT area_code,
+               DATE_FORMAT(date, '%Y') AS dateIndex,
+               SUM(gen_elec_quantity)  as genElecQuantity,
+               SUM(use_elec_quantity)  as useElecQuantity,
+               SUM(up_elec_quantity)   as upElecQuantity,
+               SUM(up_elec_earn)       as upElecEarn
+        FROM adm_ems_pv_supply_h
+        WHERE area_code = #{areaCode}
+          AND DATE >= #{date}
+        GROUP BY
+            area_code,
+            dateIndex
+    </select>
+
     <select id="selectPvSupplyHById" parameterType="Long" resultMap="PvSupplyHResult">
         <include refid="selectPvSupplyHVo"/>
         where id = #{id}
     </select>
 
-    <insert id="insertPvSupplyH" parameterType="com.ruoyi.ems.domain.PvSupplyH" useGeneratedKeys="true" keyProperty="id">
+    <insert id="insertPvSupplyH" parameterType="com.ruoyi.ems.domain.PvSupplyH" useGeneratedKeys="true"
+            keyProperty="id">
         insert into adm_ems_pv_supply_h
         <trim prefix="(" suffix=")" suffixOverrides=",">
             <if test="areaCode != null and areaCode != ''">area_code,</if>
@@ -80,7 +138,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="useElecQuantity != null">use_elec_quantity,</if>
             <if test="upElecQuantity != null">up_elec_quantity,</if>
             <if test="upElecEarn != null">up_elec_earn,</if>
-         </trim>
+        </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="areaCode != null and areaCode != ''">#{areaCode},</if>
             <if test="facsCode != null and facsCode != ''">#{facsCode},</if>
@@ -92,7 +150,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="useElecQuantity != null">#{useElecQuantity},</if>
             <if test="upElecQuantity != null">#{upElecQuantity},</if>
             <if test="upElecEarn != null">#{upElecEarn},</if>
-         </trim>
+        </trim>
     </insert>
 
     <update id="updatePvSupplyH" parameterType="com.ruoyi.ems.domain.PvSupplyH">
@@ -113,7 +171,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </update>
 
     <delete id="deletePvSupplyHById" parameterType="Long">
-        delete from adm_ems_pv_supply_h where id = #{id}
+        delete
+        from adm_ems_pv_supply_h
+        where id = #{id}
     </delete>
 
     <delete id="deletePvSupplyHByIds" parameterType="String">

+ 57 - 33
ems-cloud/ems-modules/ems-server/src/main/resources/mapper/ems/ElecUseHMapper.xml

@@ -1,49 +1,59 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!DOCTYPE mapper
-PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
-"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.ruoyi.ems.mapper.ElecUseHMapper">
-    
+
     <resultMap type="com.ruoyi.ems.domain.ElecUseH" id="elecUseHResult">
-        <result property="id"    column="id"    />
-        <result property="areaCode"    column="area_code"    />
-        <result property="areaName"    column="area_name"    />
-        <result property="areaShortName"    column="area_short_name"    />
-        <result property="facsCode"    column="facs_code"    />
-        <result property="facsName"    column="facs_name"    />
-        <result property="date"    column="date"    />
-        <result property="time"    column="time"    />
-        <result property="timeIndex"    column="time_index"    />
-        <result property="elecQuantity"    column="elec_quantity"    />
+        <result property="id" column="id"/>
+        <result property="areaCode" column="area_code"/>
+        <result property="areaName" column="area_name"/>
+        <result property="areaShortName" column="area_short_name"/>
+        <result property="facsCode" column="facs_code"/>
+        <result property="facsName" column="facs_name"/>
+        <result property="date" column="date"/>
+        <result property="time" column="time"/>
+        <result property="timeIndex" column="time_index"/>
+        <result property="elecQuantity" column="elec_quantity"/>
     </resultMap>
 
     <sql id="selectElecUseHVo">
-        select
-            u.id, u.area_code, a.area_name, a.short_name as area_short_name, u.facs_code, f.facs_name, f.facs_type, f.facs_subtype, u.`date`, u.`time`, u.time_index, u.elec_quantity
+        select u.id,
+               u.area_code,
+               a.area_name,
+               a.short_name as area_short_name,
+               u.facs_code,
+               f.facs_name,
+               f.facs_type,
+               f.facs_subtype,
+               u.`date`,
+               u.`time`,
+               u.time_index,
+               u.elec_quantity
         from adm_ems_facs_use_h u
-            LEFT JOIN adm_service_area a ON u.`area_code` = a.`area_code`
-            LEFT JOIN adm_ems_facs f ON u.`facs_code` = f.`facs_code`
+                 LEFT JOIN adm_service_area a ON u.`area_code` = a.`area_code`
+                 LEFT JOIN adm_ems_facs f ON u.`facs_code` = f.`facs_code`
     </sql>
 
     <select id="selectElecUseHList" parameterType="com.ruoyi.ems.domain.ElecUseH" resultMap="elecUseHResult">
         <include refid="selectElecUseHVo"/>
-        <where>  
-            <if test="areaCode != null  and areaCode != ''"> and u.area_code = #{areaCode}</if>
-            <if test="facsCode != null  and facsCode != ''"> and u.facs_code = #{facsCode}</if>
-            <if test="facsType != null  and facsType != ''"> and f.facs_type = #{facsType}</if>
-            <if test="facsSubtype != null  and facsSubtype != ''"> and f.facs_subtype = #{facsSubtype}</if>
-            <if test="date != null "> and u.`date` = #{date}</if>
-            <if test="time != null "> and u.`time` = #{time}</if>
-            <if test="timeIndex != null "> and u.time_index = #{timeIndex}</if>
-            <if test="elecQuantity != null "> and u.elec_quantity = #{elecQuantity}</if>
+        <where>
+            <if test="areaCode != null  and areaCode != ''">and u.area_code = #{areaCode}</if>
+            <if test="facsCode != null  and facsCode != ''">and u.facs_code = #{facsCode}</if>
+            <if test="facsType != null  and facsType != ''">and f.facs_type = #{facsType}</if>
+            <if test="facsSubtype != null  and facsSubtype != ''">and f.facs_subtype = #{facsSubtype}</if>
+            <if test="date != null ">and u.`date` = #{date}</if>
+            <if test="time != null ">and u.`time` = #{time}</if>
+            <if test="timeIndex != null ">and u.time_index = #{timeIndex}</if>
+            <if test="elecQuantity != null ">and u.elec_quantity = #{elecQuantity}</if>
         </where>
     </select>
-    
+
     <select id="selectElecUseHById" parameterType="Long" resultMap="elecUseHResult">
         <include refid="selectElecUseHVo"/>
         where u.`id` = #{id}
     </select>
-        
+
     <insert id="insertElecUseH" parameterType="com.ruoyi.ems.domain.ElecUseH" useGeneratedKeys="true" keyProperty="id">
         insert into adm_ems_facs_use_h
         <trim prefix="(" suffix=")" suffixOverrides=",">
@@ -53,7 +63,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="time != null">time,</if>
             <if test="timeIndex != null">time_index,</if>
             <if test="elecQuantity != null">elec_quantity,</if>
-         </trim>
+        </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="areaCode != null and areaCode != ''">#{areaCode},</if>
             <if test="facsCode != null and facsCode != ''">#{facsCode},</if>
@@ -61,7 +71,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="time != null">#{time},</if>
             <if test="timeIndex != null">#{timeIndex},</if>
             <if test="elecQuantity != null">#{elecQuantity},</if>
-         </trim>
+        </trim>
     </insert>
 
     <update id="updateElecUseH" parameterType="com.ruoyi.ems.domain.ElecUseH">
@@ -78,13 +88,27 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </update>
 
     <delete id="deleteElecUseHById" parameterType="Long">
-        delete from adm_ems_facs_use_h where id = #{id}
+        delete
+        from adm_ems_facs_use_h
+        where id = #{id}
     </delete>
 
     <delete id="deleteElecUseHByIds" parameterType="String">
-        delete from adm_ems_facs_use_h where id in 
+        delete from adm_ems_facs_use_h where id in
         <foreach item="id" collection="array" open="(" separator="," close=")">
             #{id}
         </foreach>
     </delete>
-</mapper>
+
+    <select id="selectElecUseHByMonth" resultType="Map">
+        SELECT area_code,
+               DATE_FORMAT(date, '%Y-%m') AS dateIndex,
+               SUM(elec_quantity)         as elecQuantity
+        FROM adm_ems_facs_use_h
+        WHERE area_code = #{areaCode}
+          AND DATE >= #{date}
+        GROUP BY
+            area_code,
+            dateIndex
+    </select>
+</mapper>

+ 0 - 1
ems-cloud/ems-modules/ems-server/src/main/resources/mapper/ems/MeterReadingMapper.xml

@@ -57,7 +57,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <where>
             <if test="areaCode != null  and areaCode != ''"> and r.area_code = #{areaCode}</if>
             <if test="objTag != null"> and d.obj_tag = #{objTag}</if>
-            <if test="objTag != null"> and d.obj_tag = #{objTag}</if>
             <if test="startMonth != null  and startMonth != ''"> and meter_month &gt;= #{startMonth}</if>
             <if test="endMonth != null  and endMonth != ''"> and meter_month &lt;= #{endMonth}</if>
         </where>

+ 50 - 39
ems-cloud/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/DateTimeUtil.java

@@ -49,7 +49,7 @@ public class DateTimeUtil {
     /**
      * Parse date date.
      *
-     * @param dateString  the date string
+     * @param dateString the date string
      * @param formatRegex the format regex
      * @return the date
      * @author chen.cheng
@@ -78,7 +78,7 @@ public class DateTimeUtil {
      * Parse date string.
      *
      * @param localDateTime the local date time
-     * @param formatRegex   the format regex
+     * @param formatRegex the format regex
      * @return the string
      * @author chen.cheng
      */
@@ -90,7 +90,7 @@ public class DateTimeUtil {
     /**
      * Parse date string.
      *
-     * @param localDate   the local date
+     * @param localDate the local date
      * @param formatRegex the format regex
      * @return the string
      * @author chen.cheng
@@ -116,7 +116,7 @@ public class DateTimeUtil {
     /**
      * Parse local date local date time.
      *
-     * @param dateString  the date string
+     * @param dateString the date string
      * @param formatRegex the format regex
      * @return the local date time
      * @author chen.cheng
@@ -130,7 +130,7 @@ public class DateTimeUtil {
     /**
      * Parse local date local date.
      *
-     * @param dateString  the date string
+     * @param dateString the date string
      * @param formatRegex the format regex
      * @return the local date
      * @author chen.cheng
@@ -144,7 +144,7 @@ public class DateTimeUtil {
     /**
      * Parse date string string.
      *
-     * @param dateString  the date string
+     * @param dateString the date string
      * @param formatRegex the format regex
      * @return the string
      * @author chen.cheng
@@ -158,9 +158,9 @@ public class DateTimeUtil {
     /**
      * Parse date string string.
      *
-     * @param dateString     the date string
+     * @param dateString the date string
      * @param srcFormatRegex the src format regex
-     * @param formatRegex    the format regex
+     * @param formatRegex the format regex
      * @return the string
      * @author chen.cheng
      */
@@ -173,9 +173,9 @@ public class DateTimeUtil {
     /**
      * Parse short date string string(yyyyMMdd).
      *
-     * @param dateString     the date string
+     * @param dateString the date string
      * @param srcFormatRegex the src format regex
-     * @param formatRegex    the format regex
+     * @param formatRegex the format regex
      * @return the string
      * @author chen.cheng
      */
@@ -189,8 +189,8 @@ public class DateTimeUtil {
      * Days of range list.
      *
      * @param startDate the start date
-     * @param endDate   the end date DateTimeUtil.daysOfRange("2020-05-06",
-     *                  "2020-09-02",DateFormatter.yyyy_MM_dd,DateFormatter.yyyyMMdd)
+     * @param endDate the end date DateTimeUtil.daysOfRange("2020-05-06",
+     *            "2020-09-02",DateFormatter.yyyy_MM_dd,DateFormatter.yyyyMMdd)
      * @return the list
      * @author chen.cheng
      */
@@ -201,7 +201,7 @@ public class DateTimeUtil {
     /**
      * Minus month string.
      *
-     * @param monthNum   the month num
+     * @param monthNum the month num
      * @param formatRegx the format regx
      * @return the string
      * @author chen.cheng
@@ -216,7 +216,7 @@ public class DateTimeUtil {
     /**
      * Minus month string
      *
-     * @param monthNum   month num
+     * @param monthNum month num
      * @param formatRegx format regx
      * @return the string
      * @author chen.cheng
@@ -239,7 +239,7 @@ public class DateTimeUtil {
     /**
      * Minus month string.
      *
-     * @param monthNum   the month num
+     * @param monthNum the month num
      * @param formatRegx the format regx
      * @return the string
      * @author chen.cheng
@@ -254,9 +254,9 @@ public class DateTimeUtil {
     /**
      * Date minus month string
      *
-     * @param date       date
+     * @param date date
      * @param formatRegx format regx
-     * @param monthNum   month num
+     * @param monthNum month num
      * @return the string
      * @author chen.cheng
      */
@@ -267,10 +267,10 @@ public class DateTimeUtil {
     /**
      * Date minus month string
      *
-     * @param date          date
+     * @param date date
      * @param srcFormatRegx src format regx
-     * @param formatRegx    format regx
-     * @param monthNum      month num
+     * @param formatRegx format regx
+     * @param monthNum month num
      * @return the string
      * @author chen.cheng
      */
@@ -284,7 +284,7 @@ public class DateTimeUtil {
     /**
      * Minus day string.
      *
-     * @param dayNum     the day num
+     * @param dayNum the day num
      * @param formatRegx the format regx
      * @return the string
      * @author chen.cheng
@@ -299,9 +299,9 @@ public class DateTimeUtil {
     /**
      * Days of range list.
      *
-     * @param startDate    the start date
-     * @param endDate      the end date
-     * @param paramFormat  the param format
+     * @param startDate the start date
+     * @param endDate the end date
+     * @param paramFormat the param format
      * @param resultFormat the result format
      * @return the list
      * @author chen.cheng
@@ -338,16 +338,11 @@ public class DateTimeUtil {
         return month;
     }
 
-    public static void main(String[] args) {
-        List<String> month = monthOfRange("20230731", "20240831", DateFormatter.yyyyMMdd, DateFormatter.yyyyMM);
-        System.out.println(month);
-    }
-
     /**
      * Days of range list.
      *
-     * @param startDate   the start date
-     * @param endDate     the end date
+     * @param startDate the start date
+     * @param endDate the end date
      * @param paramFormat the param format
      * @return the list
      * @author chen.cheng
@@ -368,7 +363,7 @@ public class DateTimeUtil {
     /**
      * Gets time step of time index.
      *
-     * @param tp  the tp
+     * @param tp the tp
      * @param gap the gap (now + gap minutes)
      * @return the time step of time index
      * @author chen.cheng
@@ -380,13 +375,14 @@ public class DateTimeUtil {
     /**
      * Get time step index of now integer.
      *
-     * @param tp         the tp
+     * @param tp the tp
      * @param toDateTime the to date time
      * @return the integer
      * @author chen.cheng
      */
     public static int getTimeStepIndexOfNow(Integer tp, LocalDateTime toDateTime) {
-        LocalDateTime zero = LocalDateTime.of(toDateTime.getYear(), toDateTime.getMonth(), toDateTime.getDayOfMonth(), 0, 0, 0);
+        LocalDateTime zero = LocalDateTime.of(toDateTime.getYear(), toDateTime.getMonth(), toDateTime.getDayOfMonth(),
+            0, 0, 0);
         Duration duration = Duration.between(zero, toDateTime);
         double minutes = duration.toMinutes();
         return (int) Math.floor(minutes / tp);
@@ -396,7 +392,7 @@ public class DateTimeUtil {
      * Gets time from step index. tp is min the format hh:mm:00
      *
      * @param stepIndex the step index
-     * @param tp        the tp
+     * @param tp the tp
      * @return the time from step index
      * @author chen.cheng
      */
@@ -411,7 +407,7 @@ public class DateTimeUtil {
      * Gets time from step index with out second.
      *
      * @param stepIndex the step index
-     * @param tp        the tp
+     * @param tp the tp
      * @return the time from step index with out second
      * @author chen.cheng
      */
@@ -425,7 +421,7 @@ public class DateTimeUtil {
     /**
      * Gets day of week.
      *
-     * @param date           the date
+     * @param date the date
      * @param paramFormatter the param formatter
      * @return the day of week
      * @author chen.cheng
@@ -480,7 +476,7 @@ public class DateTimeUtil {
     /**
      * Cal week of year integer.
      *
-     * @param date           the date
+     * @param date the date
      * @param paramFormatter the param formatter
      * @return the integer
      * @author chen.cheng
@@ -528,7 +524,9 @@ public class DateTimeUtil {
         firstTime = firstTime.plusDays(-(weekIndex * 7L));
         // 结束时间
         lastTime = lastTime.plusDays(-1);
-        return new String[]{firstTime.format(resultDateFormat), lastTime.format(resultDateFormat)};
+        return new String[] {
+            firstTime.format(resultDateFormat), lastTime.format(resultDateFormat)
+        };
     }
 
     public static String getFirstDayOfRecentYear(String dateFormat) {
@@ -539,6 +537,19 @@ public class DateTimeUtil {
         int recentYear = today.getYear() - 1;
 
         // 使用 TemporalAdjusters 来找到近一年的第一天
+        LocalDate localDate = LocalDate.of(recentYear, today.getMonth(), 1);
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dateFormat);
+        return localDate.format(formatter);
+    }
+
+    public static String getFirstDayOfThisYear(String dateFormat) {
+        // 获取当前日期
+        LocalDate today = LocalDate.now();
+
+        // 计算近一年的年份
+        int recentYear = today.getYear();
+
+        // 使用 TemporalAdjusters 来找到近一年的第一天
         LocalDate localDate = LocalDate.of(recentYear, 1, 1).with(TemporalAdjusters.firstDayOfYear());
         DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dateFormat);
         return localDate.format(formatter);