From 9e428b3f4a90df003848d28aca5f358c7b6ef969 Mon Sep 17 00:00:00 2001
From: whyclxw <810412026@qq.com>
Date: 星期三, 25 六月 2025 14:43:58 +0800
Subject: [PATCH] 蓄电池对比分析中弹窗根据设置的权重表格评分

---
 src/main/java/com/whyc/service/BattInfService.java           |    5 +
 src/main/java/com/whyc/service/BatttestdataInfService.java   |   79 +++++++++++++++++++
 src/main/java/com/whyc/controller/StatisticController.java   |   14 ---
 src/main/java/com/whyc/dto/ResSocreHehavior.java             |   22 +++++
 src/main/java/com/whyc/dto/SocreHehaviorDto.java             |   20 +++++
 src/main/java/com/whyc/controller/BattCompareController.java |   31 +++++++
 src/main/java/com/whyc/pojo/db_station/BattInf.java          |    3 
 src/main/java/com/whyc/mapper/BattInfMapper.java             |    3 
 src/main/resources/mapper/BattInfMapper.xml                  |   33 +++++++
 9 files changed, 194 insertions(+), 16 deletions(-)

diff --git a/src/main/java/com/whyc/controller/BattCompareController.java b/src/main/java/com/whyc/controller/BattCompareController.java
index 5ded782..ff8e2b0 100644
--- a/src/main/java/com/whyc/controller/BattCompareController.java
+++ b/src/main/java/com/whyc/controller/BattCompareController.java
@@ -1,8 +1,11 @@
 package com.whyc.controller;
 
 import com.whyc.dto.Response;
+import com.whyc.dto.SocreHehaviorDto;
 import com.whyc.dto.Statistic.BattCompareStic;
+import com.whyc.pojo.db_param.AppParam;
 import com.whyc.pojo.db_user.User;
+import com.whyc.service.AppParamService;
 import com.whyc.service.BattresdataInfService;
 import com.whyc.service.BatttestdataInfService;
 import com.whyc.util.ActionUtil;
@@ -12,6 +15,7 @@
 import org.springframework.web.bind.annotation.*;
 
 import java.text.ParseException;
+import java.util.List;
 import java.util.Map;
 
 @RestController
@@ -25,6 +29,8 @@
     @Autowired
     private BattresdataInfService battRinfService;
 
+    @Autowired
+    private AppParamService appParamService;
 
     @ApiOperation(value = "钃勭數姹犵粍瀵规瘮鍒嗘瀽鐣岄潰锛堝悓涓�鏃堕棿鍚屼竴鍝佺墝/鍚屼竴鏃堕棿涓嶅悓涓�鍝佺墝/涓嶅悓涓�鏃堕棿鍚屼竴鍝佺墝锛�(1.2.15/16/17)")
     @PostMapping("getBattCompare15Statistic")
@@ -56,4 +62,29 @@
     public Response getMonResChangeByBattgroupId(@RequestParam Integer battgroupId,@RequestParam Integer monNum){
         return battRinfService.getMonResChangeByBattgroupId(battgroupId,monNum);
     }
+
+    @ApiOperation(value = "寮圭獥鏍规嵁璁剧疆鐨勬潈閲嶈〃鏍艰瘎鍒�")
+    @PostMapping("getScoreByHehavior")
+    public Response getScoreByHehavior(@RequestBody SocreHehaviorDto dto) throws ParseException {
+        User uinf= ActionUtil.getUser();
+        dto.setUid(uinf.getId());
+        if(dto.getInuserYear()!=null){
+            int year=ActionUtil.getNowYear();
+            dto.setInuseStartTime(ActionUtil.sdfwithday.parse(ActionUtil.getDayTime(year+1-dto.getInuserYear(),0,1,5)));
+            dto.setInuseEndTime(ActionUtil.sdfwithday.parse(ActionUtil.getDayTime(year,11,31,5)));
+        }
+        return battTinfService.getScoreByHehavior(dto);
+    }
+
+    @ApiOperation(value = "璁剧疆鏉冮噸(1.2.16)")
+    @PostMapping("setHehavior")
+    public Response setHehavior(@RequestBody List<AppParam> List){
+        return appParamService.setHehavior(List);
+    }
+
+    @ApiOperation(value = "璇诲彇鏉冮噸(1.2.16)")
+    @GetMapping("getHehavior")
+    public Response getHehavior(){
+        return appParamService.getHehavior();
+    }
 }
\ No newline at end of file
diff --git a/src/main/java/com/whyc/controller/StatisticController.java b/src/main/java/com/whyc/controller/StatisticController.java
index 4d22234..495d3f2 100644
--- a/src/main/java/com/whyc/controller/StatisticController.java
+++ b/src/main/java/com/whyc/controller/StatisticController.java
@@ -33,8 +33,6 @@
     @Autowired
     private DeviceStateService deviceStateService;
 
-    @Autowired
-    private AppParamService appParamService;
 
     @ApiOperation(value = "鐢垫簮淇℃伅缁熻(1.2.1/1.2.13)")
     @PostMapping("getPowerStatistic")
@@ -158,18 +156,6 @@
         User uinf= ActionUtil.getUser();
         stic.setUid(uinf.getId());
         return deviceStateService.getDeviceStateStatistic(stic);
-    }
-
-    @ApiOperation(value = "璁剧疆鏉冮噸(1.2.16)")
-    @PostMapping("setHehavior")
-    public Response setHehavior(@RequestBody List<AppParam> List){
-        return appParamService.setHehavior(List);
-    }
-
-    @ApiOperation(value = "璇诲彇鏉冮噸(1.2.16)")
-    @GetMapping("getHehavior")
-    public Response getHehavior(){
-        return appParamService.getHehavior();
     }
 
 
diff --git a/src/main/java/com/whyc/dto/ResSocreHehavior.java b/src/main/java/com/whyc/dto/ResSocreHehavior.java
new file mode 100644
index 0000000..0d752ac
--- /dev/null
+++ b/src/main/java/com/whyc/dto/ResSocreHehavior.java
@@ -0,0 +1,22 @@
+package com.whyc.dto;
+
+import lombok.Data;
+
+@Data
+public class ResSocreHehavior {
+    private String product;
+    private Float monvolstd;
+    private Float moncapstd;
+    private String inuseYear;
+    private Integer sumBatt;
+    private Integer goodBatt;
+    private String  goodPercent;
+    private Integer badBatt;
+    private String badPercent;  //鎭跺寲
+    private Integer damagebatt;
+    private String damagePercent;//鎹熷潖
+    private Integer nodisbatt;
+    private String nodisPercent;//鏈斁鐢�
+    private Float score;//鏈�缁堝緱鍒�
+
+}
\ No newline at end of file
diff --git a/src/main/java/com/whyc/dto/SocreHehaviorDto.java b/src/main/java/com/whyc/dto/SocreHehaviorDto.java
new file mode 100644
index 0000000..a70b4cc
--- /dev/null
+++ b/src/main/java/com/whyc/dto/SocreHehaviorDto.java
@@ -0,0 +1,20 @@
+package com.whyc.dto;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+
+import java.util.Date;
+
+@Data
+public class SocreHehaviorDto {
+    private String product;
+    private Float moncapstd;
+    private Float monvolstd;//鏍囩О鐢靛帇
+    @JsonFormat(pattern = "yyyy-MM-dd")
+    private Date inuseStartTime;//寮�濮嬫椂闂�
+    @JsonFormat(pattern = "yyyy-MM-dd")
+    private Date inuseEndTime;//缁撴潫鏃堕棿
+
+    private Integer inuserYear;//鎶曡繍鏃堕棿1~15骞�
+    private Integer uid;
+}
\ No newline at end of file
diff --git a/src/main/java/com/whyc/mapper/BattInfMapper.java b/src/main/java/com/whyc/mapper/BattInfMapper.java
index 806cbe4..6e0e58d 100644
--- a/src/main/java/com/whyc/mapper/BattInfMapper.java
+++ b/src/main/java/com/whyc/mapper/BattInfMapper.java
@@ -3,6 +3,7 @@
 import com.whyc.dto.BattDto;
 import com.whyc.dto.InfoDto;
 import com.whyc.dto.Param.ParamAlmDto;
+import com.whyc.dto.SocreHehaviorDto;
 import com.whyc.dto.Statistic.*;
 import com.whyc.pojo.db_station.BattInf;
 import org.apache.ibatis.annotations.Param;
@@ -67,4 +68,6 @@
     List<BattInf> getBattgroupIdListByPowerId(@Param("powerId") Integer powerId);
     //鏌ヨ璁惧涓嬫墍鏈夌殑鐢垫睜缁刬d
     List<BattInf> getBattgroupIdListByDevId(@Param("devId") Integer devId);
+    //璇㈢鍚堟潯浠剁殑鐢垫睜缁勬潈閲嶈〃鏍艰瘎鍒�
+    List<BattInf> getScoreByHehavior(@Param("stic") SocreHehaviorDto dto);
 }
\ No newline at end of file
diff --git a/src/main/java/com/whyc/pojo/db_station/BattInf.java b/src/main/java/com/whyc/pojo/db_station/BattInf.java
index ea09391..722db05 100644
--- a/src/main/java/com/whyc/pojo/db_station/BattInf.java
+++ b/src/main/java/com/whyc/pojo/db_station/BattInf.java
@@ -88,6 +88,9 @@
     private Date inuseTime;
 
     @TableField(exist = false)
+    private Integer inuseYear;
+
+    @TableField(exist = false)
     private String stationName;
 
     @TableField(exist = false)
diff --git a/src/main/java/com/whyc/service/BattInfService.java b/src/main/java/com/whyc/service/BattInfService.java
index 5aff1a0..ddaa507 100644
--- a/src/main/java/com/whyc/service/BattInfService.java
+++ b/src/main/java/com/whyc/service/BattInfService.java
@@ -10,6 +10,7 @@
 import com.whyc.dto.Param.ParamAlmDto;
 import com.whyc.dto.Real.QuarterDto;
 import com.whyc.dto.Response;
+import com.whyc.dto.SocreHehaviorDto;
 import com.whyc.dto.Statistic.*;
 import com.whyc.factory.InfoFactory;
 import com.whyc.mapper.BattInfMapper;
@@ -510,4 +511,8 @@
     public List<BattInf> getBattgroupIdListByDevId(Integer devId) {
         return mapper.getBattgroupIdListByDevId(devId);
     }
+    //璇㈢鍚堟潯浠剁殑鐢垫睜缁勬潈閲嶈〃鏍艰瘎鍒�
+    public List<BattInf> getScoreByHehavior(SocreHehaviorDto dto) {
+        return mapper.getScoreByHehavior(dto);
+    }
 }
\ No newline at end of file
diff --git a/src/main/java/com/whyc/service/BatttestdataInfService.java b/src/main/java/com/whyc/service/BatttestdataInfService.java
index 6811e8c..865d92f 100644
--- a/src/main/java/com/whyc/service/BatttestdataInfService.java
+++ b/src/main/java/com/whyc/service/BatttestdataInfService.java
@@ -7,7 +7,9 @@
 import com.whyc.constant.PwrCapperformanceEnum;
 import com.whyc.constant.StopReasonEnum;
 import com.whyc.dto.Real.TestDataDto;
+import com.whyc.dto.ResSocreHehavior;
 import com.whyc.dto.Response;
+import com.whyc.dto.SocreHehaviorDto;
 import com.whyc.dto.Statistic.*;
 import com.whyc.factory.BattCapFactory;
 import com.whyc.mapper.BatttestdataInfMapper;
@@ -27,6 +29,7 @@
 
 import java.time.LocalDateTime;
 import java.util.*;
+import java.util.stream.Collectors;
 
 @Service
 public class BatttestdataInfService {
@@ -1090,4 +1093,80 @@
         }
         return new Response().setII(1,list.size()>0,curvelist,"鐐瑰嚮鍙充晶鎶樼嚎鍥剧敾鍑虹數姹犵粍鎵�鏈夊畬鏁村懆鏈熺殑娴厖鐢靛帇鍙樺寲鍥�(1.2.15/16/17)");
     }
+    //寮圭獥鏍规嵁璁剧疆鐨勬潈閲嶈〃鏍艰瘎鍒�
+    public Response getScoreByHehavior(SocreHehaviorDto dto) {
+        //鑾峰彇鏍稿浼樺姡锛屾崯鍧忓弬鏁�
+        List<AppParam> paramList=appParamService.getHrParam();
+        Float badValue=0f;
+        Float damageValue=0f;
+        if(paramList!=null){
+            for (AppParam param:paramList) {
+                if(param.getParamNamePsx().equals("batt_mon_deteriorate_val")){
+                    badValue=param.getParamValue();
+                }
+                if(param.getParamNamePsx().equals("batt_mon_damage_val")){
+                    damageValue=param.getParamValue();
+                }
+            }
+        }
+        List<ResSocreHehavior> reslist=new ArrayList<>();
+        //璇㈢鍚堟潯浠剁殑鐢垫睜缁勬潈閲嶈〃鏍艰瘎鍒�
+        List<BattInf> binfList=battInfService.getScoreByHehavior(dto);
+        if(binfList==null||binfList.size()==0){
+            return new Response().set(1,false,"褰撳墠鐢ㄦ埛鏈鐞嗘弧瓒虫潯浠剁殑鐢垫睜缁�");
+        }else{
+            Map<String, List<BattInf>> map=binfList.stream().collect(Collectors.groupingBy(item -> item.getMonvolstd().toString() + '-' + item.getMoncapstd()));
+            for (String volcap : map.keySet()) {
+                List<BattInf> list=map.get(volcap);
+                ResSocreHehavior res=new ResSocreHehavior();
+                res.setProduct(dto.getProduct());
+                res.setInuseYear(dto.getInuserYear()+"骞村唴");
+                Integer goodBatt=0;
+                Integer badBatt=0;
+                Integer damageBatt=0;
+                Integer nodisBatt=0;
+                Integer sumBatt=list.size();
+                res.setSumBatt(sumBatt);
+                String[] parts = volcap.split("-"); // 浣跨敤split鏂规硶鍒嗗壊瀛楃涓�
+                res.setMonvolstd(Float.valueOf(parts[0]));
+                res.setMoncapstd(Float.valueOf(parts[1]));
+                for (BattInf binf:list) {
+                    //2.鑾峰彇鐢垫睜缁勫湪缁欏畾鏃堕棿娈电殑鏀剧數璁板綍(鎸囧畾鏃堕棿娈电殑鏍囧噯鏍稿鏀剧數)
+                    BatttestdataInf tinf =getLastStandardTestDataByTime(binf.getBattgroupId(),null,null);
+                    if(tinf==null){
+                        nodisBatt++;
+                    }else{
+                        Float moncapStd=binf.getMoncapstd();
+                        int hourRate = BattCapFactory.GetHourRate(tinf.getTestCap(), tinf.getTestCurr());
+                        Float grouprealCap = (float) BattCapFactory.GetMonomerCap(binf.getMoncapstd(), hourRate, tinf.getTestCap(), tinf.getMaxMonvol(), tinf.getMinMonvol(), tinf.getGroupVol(), BattCapFactory.CapType_Real);
+                        if(grouprealCap>=moncapStd*badValue){
+                            goodBatt++;
+                        }
+                        if(grouprealCap<=moncapStd*damageValue){
+                            damageBatt++;
+                        }
+                        if((grouprealCap>moncapStd*damageValue)&&(grouprealCap<moncapStd*badValue)){
+                            badBatt++;
+                        }
+                    }
+                }
+                //淇濈暀5浣嶅皬鏁�
+                String goodPercent = String.format("%.5f",(goodBatt/sumBatt*100.0));
+                res.setGoodBatt(goodBatt);
+                res.setGoodPercent(goodPercent);
+                String badPercent = String.format("%.5f",(badBatt/sumBatt*100.0));
+                res.setBadBatt(badBatt);
+                res.setBadPercent(badPercent);
+                String damagePercent = String.format("%.5f",(damageBatt/sumBatt*100.0));
+                res.setDamagebatt(damageBatt);
+                res.setDamagePercent(damagePercent);
+                String nodisPercent = String.format("%.5f",(nodisBatt/sumBatt*100.0));
+                res.setNodisbatt(nodisBatt);
+                res.setNodisPercent(nodisPercent);
+                res.setScore(0f);
+                reslist.add(res);
+            }
+        }
+        return new Response().setII(1,reslist.size()>0,reslist,"寮圭獥鏍规嵁璁剧疆鐨勬潈閲嶈〃鏍艰瘎鍒�");
+    }
 }
\ No newline at end of file
diff --git a/src/main/resources/mapper/BattInfMapper.xml b/src/main/resources/mapper/BattInfMapper.xml
index d799e9a..ce2a816 100644
--- a/src/main/resources/mapper/BattInfMapper.xml
+++ b/src/main/resources/mapper/BattInfMapper.xml
@@ -278,7 +278,7 @@
                 and tb_batt_inf.inuse_time>=#{stic.inuseStartTime}
             </if>
             <if test="stic.inuseEndTime!=null">
-                and tb_batt_inf.inuse_time&lt;=#{stic.inuseEndTimee}
+                and tb_batt_inf.inuse_time&lt;=#{stic.inuseEndTime}
             </if>
             <if test="stic.uid>100">
                 and tb_batt_inf.station_id in(
@@ -315,7 +315,7 @@
             and tb_batt_inf.inuse_time>=#{stic.inuseStartTime}
         </if>
         <if test="stic.inuseEndTime!=null">
-            and tb_batt_inf.inuse_time&lt;=#{stic.inuseEndTimee}
+            and tb_batt_inf.inuse_time&lt;=#{stic.inuseEndTime}
         </if>
         <if test="stic.uid>100">
             and tb_batt_inf.station_id in(
@@ -501,4 +501,33 @@
         </where>
         order by battgroup_num asc
     </select>
+    <select id="getScoreByHehavior" resultType="com.whyc.pojo.db_station.BattInf">
+        select distinct tb_batt_inf.*,#{stic.inuserYear} as inuse_year
+        from db_station.tb_batt_inf
+        <where>
+            <if test="stic.product!=null">
+                and tb_batt_inf.product=#{stic.product}
+            </if>
+            <if test="stic.moncapstd!=null">
+                and tb_batt_inf.moncapstd=#{stic.moncapstd}
+            </if>
+            <if test="stic.monvolstd!=null">
+                and tb_batt_inf.monvolstd=#{stic.monvolstd}
+            </if>
+            <if test="stic.inuseStartTime!=null">
+                and tb_batt_inf.inuse_time>=#{stic.inuseStartTime}
+            </if>
+            <if test="stic.inuseEndTime!=null">
+                and tb_batt_inf.inuse_time&lt;=#{stic.inuseEndTime}
+            </if>
+            <if test="stic.uid>100">
+                and tb_batt_inf.station_id in(
+                select distinct station_id from db_user.tb_baojigroup_power,db_user.tb_baojigroup_usr
+                where   tb_baojigroup_power.baoji_group_id=tb_baojigroup_usr.baoji_group_id
+                and tb_baojigroup_usr.uid=#{stic.uid}
+                )
+            </if>
+            order by tb_batt_inf.dev_id asc,battgroup_id asc
+        </where>
+    </select>
 </mapper>
\ No newline at end of file

--
Gitblit v1.9.1