From a6c0ad601911684f1641c41c6abe4afe770bebb8 Mon Sep 17 00:00:00 2001 From: whyclxw <810412026@qq.com> Date: 星期三, 25 六月 2025 16:23:03 +0800 Subject: [PATCH] 蓄电池对比分析中弹窗根据设置的权重表格评分 --- src/main/java/com/whyc/dto/Statistic/BattCompareStic.java | 2 src/main/java/com/whyc/service/BatttestdataInfService.java | 272 ++++++++++++++++++++++++++++++++++++++++++--- src/main/java/com/whyc/dto/SocreHehaviorDto.java | 8 + src/main/java/com/whyc/controller/BattCompareController.java | 21 ++ src/main/java/com/whyc/pojo/db_station/BattInf.java | 3 src/main/resources/mapper/BattInfMapper.xml | 2 6 files changed, 282 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/whyc/controller/BattCompareController.java b/src/main/java/com/whyc/controller/BattCompareController.java index ff8e2b0..85697ce 100644 --- a/src/main/java/com/whyc/controller/BattCompareController.java +++ b/src/main/java/com/whyc/controller/BattCompareController.java @@ -37,9 +37,9 @@ public Response getBattCompare15Statistic(@RequestBody BattCompareStic stic) throws ParseException { User uinf= ActionUtil.getUser(); stic.setUid(uinf.getId()); - if(stic.getInuserYear()!=null){ + if(stic.getInuseYear()!=null){ int year=ActionUtil.getNowYear(); - stic.setInuseStartTime(ActionUtil.sdfwithday.parse(ActionUtil.getDayTime(year+1-stic.getInuserYear(),0,1,5))); + stic.setInuseStartTime(ActionUtil.sdfwithday.parse(ActionUtil.getDayTime(year+1-stic.getInuseYear(),0,1,5))); stic.setInuseEndTime(ActionUtil.sdfwithday.parse(ActionUtil.getDayTime(year,11,31,5))); } return battTinfService.getBattCompare15Statistic(stic); @@ -68,11 +68,24 @@ public Response getScoreByHehavior(@RequestBody SocreHehaviorDto dto) throws ParseException { User uinf= ActionUtil.getUser(); dto.setUid(uinf.getId()); - if(dto.getInuserYear()!=null){ + if(dto.getInuseYear()!=null){ int year=ActionUtil.getNowYear(); - dto.setInuseStartTime(ActionUtil.sdfwithday.parse(ActionUtil.getDayTime(year+1-dto.getInuserYear(),0,1,5))); + dto.setInuseStartTime(ActionUtil.sdfwithday.parse(ActionUtil.getDayTime(year+1-dto.getInuseYear(),0,1,5))); dto.setInuseEndTime(ActionUtil.sdfwithday.parse(ActionUtil.getDayTime(year,11,31,5))); } + if (dto.getProduct()!=null) { + if(dto.getInuseYear()!=null){ + dto.setSelectType(1); + }else{ + dto.setSelectType(2); + } + }else{ + if(dto.getInuseYear()!=null){ + dto.setSelectType(3); + }else{ + dto.setSelectType(4); + } + } return battTinfService.getScoreByHehavior(dto); } diff --git a/src/main/java/com/whyc/dto/SocreHehaviorDto.java b/src/main/java/com/whyc/dto/SocreHehaviorDto.java index a70b4cc..906264a 100644 --- a/src/main/java/com/whyc/dto/SocreHehaviorDto.java +++ b/src/main/java/com/whyc/dto/SocreHehaviorDto.java @@ -15,6 +15,12 @@ @JsonFormat(pattern = "yyyy-MM-dd") private Date inuseEndTime;//缁撴潫鏃堕棿 - private Integer inuserYear;//鎶曡繍鏃堕棿1~15骞� + private Integer inuseYear;//鎶曡繍鏃堕棿1~15骞� private Integer uid; + /*1:閫夊搧鐗岋紝閫夋姇杩愭椂闂� + 2:閫夊搧鐗岋紝涓嶉�夋姇杩愭椂闂� + 3:涓嶉�夊搧鐗岋紝閫夋姇杩愭椂闂� + 4:涓嶉�夊搧鐗岋紝涓嶉�夋姇杩愭椂闂� + */ + private Integer selectType; } \ No newline at end of file diff --git a/src/main/java/com/whyc/dto/Statistic/BattCompareStic.java b/src/main/java/com/whyc/dto/Statistic/BattCompareStic.java index 947ed61..f6ba1e2 100644 --- a/src/main/java/com/whyc/dto/Statistic/BattCompareStic.java +++ b/src/main/java/com/whyc/dto/Statistic/BattCompareStic.java @@ -27,5 +27,5 @@ @JsonFormat(pattern = "yyyy-MM-dd") private Date inuseEndTime;//缁撴潫鏃堕棿 - private Integer inuserYear;//鎶曡繍鏃堕棿1~15骞� + private Integer inuseYear;//鎶曡繍鏃堕棿1~15骞� } \ 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 722db05..ddefd6b 100644 --- a/src/main/java/com/whyc/pojo/db_station/BattInf.java +++ b/src/main/java/com/whyc/pojo/db_station/BattInf.java @@ -91,6 +91,9 @@ private Integer inuseYear; @TableField(exist = false) + private Integer battYear; + + @TableField(exist = false) private String stationName; @TableField(exist = false) diff --git a/src/main/java/com/whyc/service/BatttestdataInfService.java b/src/main/java/com/whyc/service/BatttestdataInfService.java index 865d92f..4d22fff 100644 --- a/src/main/java/com/whyc/service/BatttestdataInfService.java +++ b/src/main/java/com/whyc/service/BatttestdataInfService.java @@ -1095,6 +1095,34 @@ } //寮圭獥鏍规嵁璁剧疆鐨勬潈閲嶈〃鏍艰瘎鍒� public Response getScoreByHehavior(SocreHehaviorDto dto) { + 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=new HashMap<>(); + if(dto.getSelectType()==1){//閫夊搧鐗岋紝閫夋椂闂� + map=binfList.stream().collect(Collectors.groupingBy(item -> item.getProduct() + '-' + item.getInuseYear())); + groupby1(dto,reslist,map); + } + if(dto.getSelectType()==2){//閫夊搧鐗岋紝涓嶉�夋椂闂� + map=binfList.stream().collect(Collectors.groupingBy(item -> item.getProduct())); + groupby2(dto,reslist,map); + } + if(dto.getSelectType()==3){//涓嶉�夊搧鐗岋紝閫夋椂闂� + map=binfList.stream().collect(Collectors.groupingBy(item -> ""+item.getInuseYear())); + groupby3(dto,reslist,map); + } + if(dto.getSelectType()==4){//涓嶉�夊搧鐗屼笉閫夋椂闂� + map=binfList.stream().collect(Collectors.groupingBy(item -> item.getMonvolstd().toString() + '-' + item.getMoncapstd())); + groupby4(dto,reslist,map); + } + } + return new Response().setII(1,reslist.size()>0,reslist,"寮圭獥鏍规嵁璁剧疆鐨勬潈閲嶈〃鏍艰瘎鍒�"); + } + //涓嶉�夊搧鐗屼笉閫夋椂闂� + private void groupby4(SocreHehaviorDto dto,List<ResSocreHehavior> reslist, Map<String, List<BattInf>> map) { //鑾峰彇鏍稿浼樺姡锛屾崯鍧忓弬鏁� List<AppParam> paramList=appParamService.getHrParam(); Float badValue=0f; @@ -1109,36 +1137,33 @@ } } } - 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); + for (String groupType : map.keySet()) { + List<BattInf> list=map.get(groupType); + Map<String,List<BattInf>> groupMap=list.stream().collect(Collectors.groupingBy(item -> item.getProduct()+"-"+item.getBattYear())); + for (String group : groupMap.keySet()) { + List<BattInf> grouplist=groupMap.get(group); 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(); + Integer sumBatt=grouplist.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) { + String[] productYearparts = group.split("-"); // 浣跨敤split鏂规硶鍒嗗壊瀛楃涓� + res.setProduct(productYearparts[0]); + res.setInuseYear(productYearparts[1]+"骞村唴"); + res.setMonvolstd(dto.getMonvolstd()); + res.setMoncapstd(dto.getMoncapstd()); + for (BattInf binf:grouplist) { + Float moncapStd=binf.getMoncapstd(); //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); + Float grouprealCap = (float) BattCapFactory.GetMonomerCap(moncapStd, hourRate, tinf.getTestCap(), tinf.getMaxMonvol(), tinf.getMinMonvol(), tinf.getGroupVol(), BattCapFactory.CapType_Real); if(grouprealCap>=moncapStd*badValue){ goodBatt++; } @@ -1167,6 +1192,215 @@ reslist.add(res); } } - return new Response().setII(1,reslist.size()>0,reslist,"寮圭獥鏍规嵁璁剧疆鐨勬潈閲嶈〃鏍艰瘎鍒�"); + } + + //涓嶉�夊搧鐗岋紝閫夋椂闂� + private void groupby3(SocreHehaviorDto dto,List<ResSocreHehavior> reslist, Map<String, List<BattInf>> map) { + //鑾峰彇鏍稿浼樺姡锛屾崯鍧忓弬鏁� + 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(); + } + } + } + for (String groupType : map.keySet()) { + List<BattInf> list=map.get(groupType); + Map<String,List<BattInf>> productMap=list.stream().collect(Collectors.groupingBy(item -> item.getProduct())); + for (String product : productMap.keySet()) { + List<BattInf> productList=productMap.get(product); + ResSocreHehavior res=new ResSocreHehavior(); + res.setInuseYear(dto.getInuseYear()+"骞村唴"); + res.setProduct(product); + Integer goodBatt=0; + Integer badBatt=0; + Integer damageBatt=0; + Integer nodisBatt=0; + Integer sumBatt=productList.size(); + res.setSumBatt(sumBatt); + res.setMonvolstd(dto.getMonvolstd()); + res.setMoncapstd(dto.getMoncapstd()); + for (BattInf binf:productList) { + Float moncapStd=binf.getMoncapstd(); + //2.鑾峰彇鐢垫睜缁勫湪缁欏畾鏃堕棿娈电殑鏀剧數璁板綍(鎸囧畾鏃堕棿娈电殑鏍囧噯鏍稿鏀剧數) + BatttestdataInf tinf =getLastStandardTestDataByTime(binf.getBattgroupId(),null,null); + if(tinf==null){ + nodisBatt++; + }else{ + + int hourRate = BattCapFactory.GetHourRate(tinf.getTestCap(), tinf.getTestCurr()); + Float grouprealCap = (float) BattCapFactory.GetMonomerCap(moncapStd, 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); + } + } + } + + //閫夊搧鐗岋紝涓嶉�夋椂闂� + private void groupby2(SocreHehaviorDto dto,List<ResSocreHehavior> reslist, Map<String, List<BattInf>> map) { + //鑾峰彇鏍稿浼樺姡锛屾崯鍧忓弬鏁� + 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(); + } + } + } + for (String groupType : map.keySet()) { + List<BattInf> list=map.get(groupType); + Map<String,List<BattInf>> timeMap=list.stream().collect(Collectors.groupingBy(item -> item.getBattYear().toString())); + for (String time : timeMap.keySet()) { + List<BattInf> timeList=timeMap.get(time); + ResSocreHehavior res=new ResSocreHehavior(); + res.setProduct(dto.getProduct()); + res.setInuseYear(time+"骞村唴"); + Integer goodBatt=0; + Integer badBatt=0; + Integer damageBatt=0; + Integer nodisBatt=0; + Integer sumBatt=timeList.size(); + res.setSumBatt(sumBatt); + res.setMonvolstd(dto.getMonvolstd()); + res.setMoncapstd(dto.getMoncapstd()); + for (BattInf binf:timeList) { + Float moncapStd=binf.getMoncapstd(); + //2.鑾峰彇鐢垫睜缁勫湪缁欏畾鏃堕棿娈电殑鏀剧數璁板綍(鎸囧畾鏃堕棿娈电殑鏍囧噯鏍稿鏀剧數) + BatttestdataInf tinf =getLastStandardTestDataByTime(binf.getBattgroupId(),null,null); + if(tinf==null){ + nodisBatt++; + }else{ + int hourRate = BattCapFactory.GetHourRate(tinf.getTestCap(), tinf.getTestCurr()); + Float grouprealCap = (float) BattCapFactory.GetMonomerCap(moncapStd, 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); + } + } + } + + //閫夊搧鐗岋紝閫夋椂闂� + private void groupby1(SocreHehaviorDto dto,List<ResSocreHehavior> reslist, Map<String, List<BattInf>> map) { + //鑾峰彇鏍稿浼樺姡锛屾崯鍧忓弬鏁� + 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(); + } + } + } + for (String groupType : map.keySet()) { + List<BattInf> list=map.get(groupType); + ResSocreHehavior res=new ResSocreHehavior(); + res.setProduct(dto.getProduct()); + res.setInuseYear(dto.getInuseYear()+"骞村唴"); + Integer goodBatt=0; + Integer badBatt=0; + Integer damageBatt=0; + Integer nodisBatt=0; + Integer sumBatt=list.size(); + res.setSumBatt(sumBatt); + res.setMonvolstd(dto.getMonvolstd()); + res.setMoncapstd(dto.getMoncapstd()); + for (BattInf binf:list) { + Float moncapStd=binf.getMoncapstd(); + //2.鑾峰彇鐢垫睜缁勫湪缁欏畾鏃堕棿娈电殑鏀剧數璁板綍(鎸囧畾鏃堕棿娈电殑鏍囧噯鏍稿鏀剧數) + BatttestdataInf tinf =getLastStandardTestDataByTime(binf.getBattgroupId(),null,null); + if(tinf==null){ + nodisBatt++; + }else{ + int hourRate = BattCapFactory.GetHourRate(tinf.getTestCap(), tinf.getTestCurr()); + Float grouprealCap = (float) BattCapFactory.GetMonomerCap(moncapStd, 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); + } } } \ No newline at end of file diff --git a/src/main/resources/mapper/BattInfMapper.xml b/src/main/resources/mapper/BattInfMapper.xml index ce2a816..a0ada3d 100644 --- a/src/main/resources/mapper/BattInfMapper.xml +++ b/src/main/resources/mapper/BattInfMapper.xml @@ -502,7 +502,7 @@ 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 + select distinct tb_batt_inf.*,(TIMESTAMPDIFF(YEAR, tb_batt_inf.inuse_time,CURDATE())+1) as batt_year,#{stic.inuseYear} as inuse_year from db_station.tb_batt_inf <where> <if test="stic.product!=null"> -- Gitblit v1.9.1