From ee138e53a109cfc28aa8565575a944086711094c Mon Sep 17 00:00:00 2001 From: chen_xi <276999030@qq.com> Date: Thu, 29 Jun 2023 17:33:55 +0800 Subject: [PATCH] 去除无效内容 --- screen-api/src/main/java/com/moral/api/service/impl/ExcelServiceImpl.java | 237 +++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 204 insertions(+), 33 deletions(-) diff --git a/screen-api/src/main/java/com/moral/api/service/impl/ExcelServiceImpl.java b/screen-api/src/main/java/com/moral/api/service/impl/ExcelServiceImpl.java index 99491f1..0ffda38 100644 --- a/screen-api/src/main/java/com/moral/api/service/impl/ExcelServiceImpl.java +++ b/screen-api/src/main/java/com/moral/api/service/impl/ExcelServiceImpl.java @@ -36,8 +36,7 @@ import com.moral.api.pojo.vo.excel.ExcelVo; import com.moral.api.service.ExcelService; import com.moral.api.utils.ExcelUtils; -import com.moral.pojo.AQI; -import com.moral.util.AQIUtils; + import com.moral.util.DateUtils; @@ -48,7 +47,7 @@ private ExcelMapper excelMapper; /** - * ������ + * ��������������� * @param files * @param params * @return @@ -56,11 +55,12 @@ */ @Override public ExcelBO importTemplate(List<MultipartFile> files, Map<String, Object> params) throws IOException { + Date date2 = new Date(); String time = (String) params.get("time"); String code = (String) params.get("code"); - String time1 = (String) params.get("date"); +// String time1 = (String) params.get("date"); Date date = DateUtils.getDate(time, "yyyy-MM-dd"); - Date date1 = DateUtils.getDate(time1, "yyyy-MM-dd"); +// Date date1 = DateUtils.getDate(time1, "yyyy-MM-dd"); ExcelBO excelBO = new ExcelBO(); QueryWrapper<TbExcel> wrapper = new QueryWrapper<>(); wrapper.eq("time",date).eq("code",code); @@ -83,18 +83,20 @@ MultipartFile file5 = files.get(4); Map<String, Object> map5 = getMap5(file5); map.put("c5",map5); - MultipartFile file6 = files.get(5); - Map<String, Object> map6 = getMap6(file6); - map.put("c6",map6); + if (files.size()>5){ + MultipartFile file6 = files.get(5); + Map<String, Object> map6 = getMap6(file6); + map.put("c6",map6); + } String s = JSON.toJSONString(map); excel1.setValue(s); excel1.setTime(date); excel1.setCode(code); - excel1.setDate(date1); + excel1.setDate(date2); excelMapper.insert(excel1); excelBO.setId(excel1.getId()); excelBO.setTime(excel1.getTime()); - excelBO.setDate(excel1.getDate()); + excelBO.setDate(date2); }else { HashMap<String, Object> map = new HashMap<>(); @@ -113,28 +115,28 @@ MultipartFile file5 = files.get(4); Map<String, Object> map5 = getMap5(file5); map.put("c5",map5); - MultipartFile file6 = files.get(5); - Map<String, Object> map6 = getMap6(file6); - map.put("c6",map6); + if (files.size()>5){ + MultipartFile file6 = files.get(5); + Map<String, Object> map6 = getMap6(file6); + map.put("c6",map6); + } String s = JSON.toJSONString(map); excel.setValue(s); excelMapper.updateById(excel); excelBO.setId(excel.getId()); excelBO.setTime(excel.getTime()); - excelBO.setDate(excel.getDate()); + excelBO.setDate(date2); } return excelBO; } /** - * ������ + * ��������������� * @param id * @return */ @Override public ExcelVo export(Integer id) { - - HashMap<String, Object> map1 = new HashMap<>(); ArrayList<Map<String,Object>> list1 = new ArrayList<>(); ArrayList<Map<String,Object>> list2 = new ArrayList<>(); @@ -180,11 +182,19 @@ Map map5 = JSON.parseObject(s, Map.class); Set set1s = map5.keySet(); for (Object set1 : set1s) { - Object o1 = map5.get(set1); - String s1 = JSON.toJSONString(o1); - Map map6 = JSON.parseObject(s1, Map.class); - map6.put("place",set1); - list3.add(map6); + if (set1.equals("���������")){ + Object o1 = map5.get(set1); + String s1 = JSON.toJSONString(o1); + Map map6 = JSON.parseObject(s1, Map.class); + map6.put("place","���������"); + list3.add(map6); + }else { + Object o1 = map5.get(set1); + String s1 = JSON.toJSONString(o1); + Map map6 = JSON.parseObject(s1, Map.class); + map6.put("place",set1.toString().substring(3)); + list3.add(map6); + } } } if (set.equals("c4")){ @@ -384,7 +394,7 @@ // "������8���������������������90���������������������"+O3y+"������/������������������"+code5+"%���" + // "���������������������������������"+AQIy+"%���������"+code6+"%���"; - excelVo.setQuality(s3+s4); + excelVo.setQuality(s4+s3); excelVo.setSu(s1); excelVo.setCount(count); excelVo.setPM10(PM10); @@ -590,7 +600,11 @@ objects[j] = value; } HashMap<String, Object> map = new HashMap<>(); - map.put("place", objects[0]); + if (objects[0].toString().equals("���������")){ + map.put("place", "���������"); + }else { + map.put("place",objects[0].toString().substring(3)); + } map.put("������", objects[1]); map.put("SO2", objects[2]); map.put("SO2���������", objects[3]); @@ -760,25 +774,37 @@ for (String s : strings1) { HashMap<String, Object> map = new HashMap<>(); List<Double> doubles = ListHashMap.get(s); + + ArrayList<Double> list = new ArrayList<>(); + double co = getCo(doubles.get(0)); + double so2 = getSo2(doubles.get(1)); + double no2 = getNo2(doubles.get(2)); + double pm10 = getPm10(doubles.get(3)); + double pm2_5 = getPm2_5(doubles.get(4)); + double o3 = getO3(doubles.get(5)); + list.add(co); + list.add(so2); + list.add(no2); + list.add(pm10); + list.add(pm2_5); + list.add(o3); + + Double aqi = Collections.max(list); + map.put("a21005",doubles.get(0)); map.put("a21026",doubles.get(1)); map.put("a21004",doubles.get(2)); map.put("a34002",doubles.get(3)); map.put("a34004",doubles.get(4)); map.put("a05024",doubles.get(5)); - AQI aqi = AQIUtils.dailyAQI(map); - Integer aqiValue = aqi.getAQIValue(); - map.put("AQI",aqiValue); - List<String> primaryPollutantNames = aqi.getPrimaryPollutantNames(); - String primaryPollutant = "__"; - if (!ObjectUtils.isEmpty(primaryPollutantNames)) { - primaryPollutant = primaryPollutantNames.stream().map(String::valueOf).collect(Collectors.joining(",")); - } - map.put("SU", primaryPollutant); + map.put("AQI",aqi); + map.put("SU", getSU(aqi,list)); resultMap.put(s,map); } return resultMap; } + + /** * ��������������� @@ -947,4 +973,149 @@ } return round; } + /** + * ��������������������� + * @param aqi + * @param list + * @return + */ + private String getSU(Double aqi,ArrayList list){ + String SU=null; + if (aqi<=50){ + SU="-"; + } else if (aqi==list.get(1)){ + SU="SO2"; + }else if (aqi==list.get(0)){ + SU="CO"; + }else if (aqi==list.get(2)){ + SU="NO2"; + }else if (aqi==list.get(3)){ + SU="PM10"; + }else if (aqi==list.get(4)){ + SU="PM2.5"; + }else if (aqi==list.get(5)){ + SU="O3"; + } + return SU; + } + + private static double getSo2(double so2){ + double v = 0.0; + if (so2<50){ + v = 50 * so2 / 50; + }else if (so2<150 && so2 >= 50){ + v = 50 * (so2 - 50) / 100 + 50; + }else if (so2<475 && so2 >= 150){ + v = 50 * (so2 - 150) / 325 + 100; + }else if (so2<800 && so2 >= 475){ + v = 50 * (so2 - 475) / 325 + 150; + }else { + v = 100 * (so2 - 800) / 800 + 200; + } + return Math.round(v); + } + + private static double getNo2(double no2){ + double v = 0.0; + if (no2<40){ + v = 50 * no2 / 40; + }else if (no2<80 && no2 >= 40){ + v = 50 * (no2 - 40) / 40 + 50; + }else if (no2<180 && no2 >= 80){ + v = 50 * (no2 - 80) / 100 + 100; + }else if (no2<280 && no2 >= 180){ + v = 50 * (no2 - 180) / 100 + 150; + }else if (no2<565 && no2 >= 280){ + v = 100 * (no2 - 280) / 285 + 200; + }else if (no2<750 && no2 >= 565){ + v = 100 * (no2 - 565) / 185 + 300; + } + else { + v = 100 * (no2 - 750) / 190 + 400; + } + return Math.round(v); + } + + + private static double getCo(double co){ + double v = 0.0; + if (co<2){ + v = 50 * co / 2; + }else if (co<4 && co >= 2){ + v = 50 * (co - 2) / 2 + 50; + }else if (co<14 && co >= 4){ + v = 50 * (co - 4) / 10 + 100; + }else if (co<24 && co >= 14){ + v = 50 * (co - 14) / 10 + 150; + }else if (co<36 && co >= 24){ + v = 100 * (co - 24) / 12 + 200; + }else if (co<48 && co >= 36){ + v = 100 * (co - 36) / 12 + 300; + } + else { + v = 100 * (co - 48) / 12 + 400; + } + return Math.round(v); + } + + private static double getPm10(double pm10){ + double v = 0.0; + if (pm10<50){ + v = 50 * pm10 / 50; + }else if (pm10<150 && pm10 >= 50){ + v = 50 * (pm10 - 50) / 100 + 50; + }else if (pm10<250 && pm10 >= 150){ + v = 50 * (pm10 - 150) / 100 + 100; + }else if (pm10<350 && pm10 >= 250){ + v = 50 * (pm10 - 250) / 100 + 150; + }else if (pm10<420 && pm10 >= 350){ + v = 100 * (pm10 - 350) / 70 + 200; + }else if (pm10<500 && pm10 >= 420){ + v = 100 * (pm10 - 420) / 80 + 300; + } + else { + v = 100 * (pm10 - 500) / 100 + 400; + } + return Math.round(v); + } + + private static double getPm2_5(double pm2_5){ + double v = 0.0; + if (pm2_5<35){ + v = 50 * pm2_5 / 35; + }else if (pm2_5<75 && pm2_5 >= 35){ + v = 50 * (pm2_5 - 35) / 40 + 50; + }else if (pm2_5<115 && pm2_5 >= 75){ + v = 50 * (pm2_5 - 75) / 40 + 100; + }else if (pm2_5<150 && pm2_5 >= 115){ + v = 50 * (pm2_5 - 115) / 35 + 150; + }else if (pm2_5<250 && pm2_5 >= 150){ + v = 100 * (pm2_5 - 150) / 100 + 200; + }else if (pm2_5<350 && pm2_5 >= 250){ + v = 100 * (pm2_5 - 250) / 100 + 300; + } + else { + v = 100 * (pm2_5 - 350) / 150 + 400; + } + return Math.round(v); + } + + + private static double getO3(double o3){ + double v = 0.0; + if (o3<100){ + v = 50 * o3 / 100; + }else if (o3<160 && o3 >= 100){ + v = 50 * (o3 - 100) / 60 + 50; + }else if (o3<215 && o3 >= 160){ + v = 50 * (o3 - 160) / 55 + 100; + }else if (o3<265 && o3 >= 215){ + v = 50 * (o3 - 215) / 50 + 150; + }else if (o3<800 && o3 >= 265){ + v = 100 * (o3 - 265) / 535 + 200; + }else if (o3<1000 && o3 >= 800){ + v = 100 * (o3 - 800) / 200 + 300; + } + return Math.round(v); + } } \ No newline at end of file -- Gitblit v1.8.0