New file |
| | |
| | | package com.moral.api.service.impl; |
| | | |
| | | import org.apache.poi.ss.usermodel.Cell; |
| | | import org.apache.poi.xssf.usermodel.XSSFRow; |
| | | import org.apache.poi.xssf.usermodel.XSSFSheet; |
| | | import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.moral.api.entity.TbExcel; |
| | | import com.moral.api.mapper.ExcelMapper; |
| | | import com.moral.api.pojo.bo.ExcelBO; |
| | | import com.moral.api.pojo.vo.excel.SyExcelVo; |
| | | import com.moral.api.service.HnExcelService; |
| | | import com.moral.api.utils.ExcelUtils; |
| | | import com.moral.pojo.AQI; |
| | | import com.moral.util.AQIUtils; |
| | | import com.moral.util.AmendUtils; |
| | | import com.moral.util.DateUtils; |
| | | |
| | | |
| | | @Service |
| | | public class HnExcelServiceImpl implements HnExcelService { |
| | | |
| | | @Autowired |
| | | private ExcelMapper excelMapper; |
| | | |
| | | /** |
| | | * 浑南区导入 |
| | | * @param files |
| | | * @param params |
| | | * @return |
| | | * @throws IOException |
| | | * @throws ParseException |
| | | */ |
| | | @Override |
| | | public ExcelBO getExcelImport(List<MultipartFile> files, Map<String, Object> params) throws IOException, ParseException { |
| | | String time = (String) params.get("time"); |
| | | String code = (String) params.get("code"); |
| | | String time1 = (String) params.get("date"); |
| | | Date date = DateUtils.getDate(time, "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); |
| | | TbExcel excel = excelMapper.selectOne(wrapper); |
| | | if (excel==null){ |
| | | TbExcel excel1 = new TbExcel(); |
| | | HashMap<String, Map<String, List<Integer>>> map = new HashMap<>(); |
| | | MultipartFile file1 = files.get(0); |
| | | Map<String, List<Integer>> map1 = getMap1(file1, 0,time); |
| | | map.put("浑南东路",map1); |
| | | Map<String, List<Integer>> map2 = getMap1(file1, 1,time); |
| | | map.put("新秀街",map2); |
| | | Map<String, List<Integer>> map3 = getTo(file1,time); |
| | | map.put("浑南区",map3); |
| | | String s = JSON.toJSONString(map); |
| | | excel1.setValue(s); |
| | | excel1.setTime(date); |
| | | excel1.setCode(code); |
| | | excel1.setDate(date1); |
| | | excelMapper.insert(excel1); |
| | | excelBO.setId(excel1.getId()); |
| | | excelBO.setTime(excel1.getTime()); |
| | | excelBO.setDate(excel1.getDate()); |
| | | }else { |
| | | HashMap<String, Map<String, List<Integer>>> map = new HashMap<>(); |
| | | MultipartFile file1 = files.get(0); |
| | | Map<String, List<Integer>> map1 = getMap1(file1, 0,time); |
| | | map.put("浑南东路",map1); |
| | | Map<String, List<Integer>> map2 = getMap1(file1, 1,time); |
| | | map.put("新秀街",map2); |
| | | Map<String, List<Integer>> map3 = getTo(file1,time); |
| | | map.put("浑南区",map3); |
| | | String s = JSON.toJSONString(map); |
| | | excel.setValue(s); |
| | | excelMapper.updateById(excel); |
| | | excelBO.setId(excel.getId()); |
| | | excelBO.setTime(excel.getTime()); |
| | | excelBO.setDate(excel.getDate()); |
| | | |
| | | } |
| | | return excelBO; |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 浑南区下载 |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @Override |
| | | public SyExcelVo SyExport(Integer id) { |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | HashMap<String, ArrayList<String>> rsMap = new HashMap<>(); |
| | | SyExcelVo syExcelVo = new SyExcelVo(); |
| | | TbExcel excel = excelMapper.selectById(id); |
| | | String value = excel.getValue(); |
| | | Date time = excel.getTime(); |
| | | String format = sdf.format(time); |
| | | String substring = format.substring(5, 7); |
| | | int data= Integer.parseInt(substring); |
| | | |
| | | Map<String, Map<String, List<Integer>>> map = JSON.parseObject(value, Map.class); |
| | | Set<String> strings = map.keySet(); |
| | | for (String string : strings) { |
| | | if (string.equals("浑南东路")){ |
| | | Map<String, List<Integer>> stringListMap = map.get(string); |
| | | Set<String> strings1 = stringListMap.keySet(); |
| | | for (String s : strings1) { |
| | | if (s.equals("count")){ |
| | | ArrayList<String> list1 = getList(stringListMap, s); |
| | | rsMap.put("hnd1",list1); |
| | | } |
| | | if (s.equals("PM2_5")){ |
| | | ArrayList<String> list1 = getArrayList(stringListMap, s); |
| | | rsMap.put("hnd2",list1); |
| | | |
| | | } |
| | | } |
| | | } |
| | | if (string.equals("新秀街")){ |
| | | Map<String, List<Integer>> stringListMap = map.get(string); |
| | | Set<String> strings1 = stringListMap.keySet(); |
| | | for (String s : strings1) { |
| | | if (s.equals("count")){ |
| | | ArrayList<String> list1 = getList(stringListMap, s); |
| | | rsMap.put("xxj1",list1); |
| | | } |
| | | if (s.equals("PM2_5")){ |
| | | ArrayList<String> list1 = getArrayList(stringListMap, s); |
| | | rsMap.put("xxj2",list1); |
| | | } |
| | | } |
| | | } |
| | | if (string.equals("浑南区")){ |
| | | Map<String, List<Integer>> stringListMap = map.get(string); |
| | | Set<String> strings1 = stringListMap.keySet(); |
| | | for (String s : strings1) { |
| | | if (s.equals("count")){ |
| | | ArrayList<String> list1 = new ArrayList<>(); |
| | | List<Integer> list = stringListMap.get(s); |
| | | Integer sum =0; |
| | | if (data>=1 && data<=3){ |
| | | sum = list.get(0) + list.get(1) + list.get(2); |
| | | }else if (data>=4 &&data<=6){ |
| | | sum = list.get(3) + list.get(4) + list.get(5); |
| | | }else if (data>=7 &&data<=9){ |
| | | sum = list.get(6) + list.get(7) + list.get(8); |
| | | }else { |
| | | sum = list.get(9) + list.get(10) + list.get(11); |
| | | } |
| | | syExcelVo.setCode5(sum.toString()); |
| | | for (int i = 0; i < list.size()-1; i++) { |
| | | if (list.get(i)==0){ |
| | | list1.add(""); |
| | | continue; |
| | | } |
| | | list1.add(list.get(i).toString()); |
| | | } |
| | | Integer integer = list.get(12); |
| | | syExcelVo.setCode1(integer.toString()); |
| | | Integer integer1 = list.get(13); |
| | | int i = integer - integer1; |
| | | String code =""; |
| | | if (i<=0){ |
| | | code = "减少"+i+"天"; |
| | | }else { |
| | | code = "增加"+i+"天"; |
| | | } |
| | | list1.add(code); |
| | | syExcelVo.setCode2(code); |
| | | list1.add(0,"优良天数"); |
| | | rsMap.put("hnq1",list1); |
| | | } |
| | | if (s.equals("PM2_5")){ |
| | | ArrayList<String> list1 = new ArrayList<>(); |
| | | List<Integer> list = stringListMap.get(s); |
| | | Integer sum =0; |
| | | if (data>=1 && data<=3){ |
| | | sum = list.get(0) + list.get(1) + list.get(2); |
| | | }else if (data>=4 &&data<=6){ |
| | | sum = list.get(3) + list.get(4) + list.get(5); |
| | | }else if (data>=7 &&data<=9){ |
| | | sum = list.get(6) + list.get(7) + list.get(8); |
| | | }else { |
| | | sum = list.get(9) + list.get(10) + list.get(11); |
| | | } |
| | | |
| | | Integer round = Math.round(sum / 3); |
| | | syExcelVo.setCode6(round.toString()); |
| | | for (int i = 0; i < list.size()-1; i++) { |
| | | if (list.get(i)==0){ |
| | | list1.add(""); |
| | | continue; |
| | | } |
| | | list1.add(list.get(i).toString()); |
| | | } |
| | | Integer integer = list.get(12); |
| | | syExcelVo.setCode3(integer.toString()); |
| | | Integer integer1 = list.get(13); |
| | | double i = integer - integer1; |
| | | |
| | | double i1 = AmendUtils.sciCal((i / integer1)*100,1); |
| | | String code = ""; |
| | | if (i1<=0){ |
| | | code = "下降"+i1+"%"; |
| | | }else { |
| | | code = "上升"+i1+"%"; |
| | | } |
| | | |
| | | list1.add(code); |
| | | syExcelVo.setCode4(code); |
| | | list1.add(0,"PM2.5浓度微克/立方"); |
| | | rsMap.put("hnq2",list1); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | ArrayList<String> list1 = new ArrayList<>(); |
| | | ArrayList<String> list2 = new ArrayList<>(); |
| | | for (int i = 0; i < 15; i++) { |
| | | if (i==0){ |
| | | list1.add("优良天数"); |
| | | continue; |
| | | } |
| | | list1.add(""); |
| | | } |
| | | list2.addAll(list1); |
| | | list2.remove(0); |
| | | list2.add(0,"PM2.5浓度微克/立方"); |
| | | rsMap.put("sy1",list1); |
| | | rsMap.put("sy2",list2); |
| | | syExcelVo.setList(rsMap); |
| | | return syExcelVo; |
| | | } |
| | | |
| | | |
| | | //计算pm2.5同比 |
| | | private ArrayList<String> getArrayList(Map<String, List<Integer>> stringListMap, String s) { |
| | | ArrayList<String> list1 = new ArrayList<>(); |
| | | List<Integer> list = stringListMap.get(s); |
| | | for (int i = 0; i < list.size()-1; i++) { |
| | | if (list.get(i)==0){ |
| | | list1.add(""); |
| | | continue; |
| | | } |
| | | list1.add(list.get(i).toString()); |
| | | } |
| | | Integer integer = list.get(12); |
| | | Integer integer1 = list.get(13); |
| | | double i1 = 0.0; |
| | | if (integer1!=0){ |
| | | double i = integer - integer1; |
| | | i1 = AmendUtils.sciCal((i / integer1)*100,1); |
| | | } |
| | | String code = ""; |
| | | if (i1<=0){ |
| | | code = "下降"+i1+"%"; |
| | | }else { |
| | | code = "上升"+i1+"%"; |
| | | } |
| | | list1.add(code); |
| | | list1.add(0,"PM2.5浓度微克/立方"); |
| | | return list1; |
| | | } |
| | | |
| | | //计算优良天数 |
| | | private ArrayList<String> getList(Map<String, List<Integer>> stringListMap, String s) { |
| | | ArrayList<String> list1 = new ArrayList<>(); |
| | | List<Integer> list = stringListMap.get(s); |
| | | for (int i = 0; i < list.size()-1; i++) { |
| | | if (list.get(i)==0){ |
| | | list1.add(""); |
| | | continue; |
| | | } |
| | | list1.add(list.get(i).toString()); |
| | | } |
| | | Integer integer = list.get(12); |
| | | Integer integer1 = list.get(13); |
| | | int i = integer - integer1; |
| | | String code = ""; |
| | | if (i<=0){ |
| | | code = "减少"+i+"天"; |
| | | }else { |
| | | code = "增加"+i+"天"; |
| | | } |
| | | list1.add(code); |
| | | list1.add(0,"优良天数"); |
| | | return list1; |
| | | } |
| | | //解析文件 |
| | | private Map<String, List<Integer>> getMap1(MultipartFile file, int code,String time) throws IOException, ParseException { |
| | | XSSFWorkbook workbook = new XSSFWorkbook(file.getInputStream()); |
| | | HashMap<String, Object> rsMap1 = new HashMap<>(); |
| | | HashMap<String, Object> rsMap2 = new HashMap<>(); |
| | | HashMap<String, Object> rsMap3 = new HashMap<>(); |
| | | XSSFSheet sheetAt = workbook.getSheetAt(code); |
| | | //一共有多少行 |
| | | int lastRowNum = sheetAt.getLastRowNum(); |
| | | for (int i = 2; i <= lastRowNum; i++) { |
| | | XSSFRow row = sheetAt.getRow(i); |
| | | if (row == null) { |
| | | continue; |
| | | } |
| | | short lastCellNum = row.getLastCellNum(); |
| | | if (lastCellNum < 8) { |
| | | continue; |
| | | } |
| | | Object[] objects = new Object[lastCellNum]; |
| | | for (int j = 0; j < lastCellNum; j++) { |
| | | Cell cell = row.getCell(j); |
| | | if (cell != null) { |
| | | Object value = ExcelUtils.getValue(cell); |
| | | objects[j] = value; |
| | | } |
| | | |
| | | } |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | HashMap<String, Object> map1 = new HashMap<>(); |
| | | HashMap<String, Object> map2 = new HashMap<>(); |
| | | if (objects.length == 9) { |
| | | map.put("time", objects[0]); |
| | | map.put("PM10", objects[1]); |
| | | map.put("a34004", objects[2]); |
| | | map.put("SO2", objects[3]); |
| | | map.put("NO2", objects[4]); |
| | | map.put("CO", objects[5]); |
| | | map.put("O3_8H", objects[6]); |
| | | map.put("AQI", objects[7]); |
| | | rsMap1.put(objects[0].toString(), map); |
| | | } |
| | | if (objects.length == 18) { |
| | | map.put("time", objects[0]); |
| | | map.put("PM10", objects[1]); |
| | | map.put("a34004", objects[2]); |
| | | map.put("SO2", objects[3]); |
| | | map.put("NO2", objects[4]); |
| | | map.put("CO", objects[5]); |
| | | map.put("O3_8H", objects[6]); |
| | | map.put("AQI", objects[7]); |
| | | rsMap1.put(objects[0].toString(), map); |
| | | |
| | | if (!objects[11].toString().contains("H") |
| | | && !objects[12].toString().contains("H") |
| | | && !objects[13].toString().contains("H") |
| | | && !objects[14].toString().contains("H") |
| | | && !objects[15].toString().contains("H") |
| | | && !objects[16].toString().contains("H")) |
| | | { |
| | | map1.put("time", objects[10]); |
| | | map1.put("PM10", objects[11]); |
| | | map1.put("a34004", objects[12]); |
| | | map1.put("SO2", objects[13]); |
| | | map1.put("NO2", objects[14]); |
| | | map1.put("CO", objects[15]); |
| | | map1.put("O3_8H", objects[16]); |
| | | map1.put("AQI", objects[17]); |
| | | rsMap2.put(objects[10].toString(), map1); |
| | | } |
| | | |
| | | } |
| | | |
| | | if (objects.length == 27) { |
| | | map.put("time", objects[0]); |
| | | map.put("PM10", objects[1]); |
| | | map.put("a34004", objects[2]); |
| | | map.put("SO2", objects[3]); |
| | | map.put("NO2", objects[4]); |
| | | map.put("CO", objects[5]); |
| | | map.put("O3_8H", objects[6]); |
| | | map.put("AQI", objects[7]); |
| | | rsMap1.put(objects[0].toString(), map); |
| | | if ( !objects[11].toString().contains("H") |
| | | && !objects[12].toString().contains("H") |
| | | && !objects[13].toString().contains("H") |
| | | && !objects[14].toString().contains("H") |
| | | && !objects[15].toString().contains("H") |
| | | && !objects[16].toString().contains("H") |
| | | ) { |
| | | |
| | | map1.put("time", objects[10]); |
| | | map1.put("PM10", objects[11]); |
| | | map1.put("a34004", objects[12]); |
| | | map1.put("SO2", objects[13]); |
| | | map1.put("NO2", objects[14]); |
| | | map1.put("CO", objects[15]); |
| | | map1.put("O3_8H", objects[16]); |
| | | map1.put("AQI", objects[17]); |
| | | rsMap2.put(objects[10].toString(), map1); |
| | | } |
| | | if ( !objects[20].toString().contains("H") |
| | | && !objects[21].toString().contains("H") |
| | | && !objects[22].toString().contains("H") |
| | | && !objects[23].toString().contains("H") |
| | | && !objects[24].toString().contains("H") |
| | | && !objects[25].toString().contains("H") |
| | | ) { |
| | | map2.put("time", objects[19]); |
| | | map2.put("PM10", objects[20]); |
| | | map2.put("a34004", objects[21]); |
| | | map2.put("SO2", objects[22]); |
| | | map2.put("NO2", objects[23]); |
| | | map2.put("CO", objects[24]); |
| | | map2.put("O3_8H", objects[25]); |
| | | map2.put("AQI", objects[26]); |
| | | rsMap3.put(objects[19].toString(), map2); |
| | | } |
| | | } |
| | | |
| | | } |
| | | //计算本年度pm2.5和优良天数 |
| | | Map<String, List<Integer>> map = getMap(rsMap3); |
| | | //计算去年PM2.5和优良天数 |
| | | Map<String, Integer> map2 = getResult(rsMap2, time); |
| | | List<Integer> list = map.get("count"); |
| | | list.add(map2.get("count")); |
| | | List<Integer> list1 = map.get("PM2_5"); |
| | | list1.add(map2.get("PM2_5")); |
| | | return map; |
| | | } |
| | | |
| | | /** |
| | | * 计算PM2.5 和优良天数 |
| | | * |
| | | * @param rsMap3 |
| | | */ |
| | | private Map<String, List<Integer>> getMap(HashMap<String, Object> rsMap3) { |
| | | HashMap<String, List<Integer>> listMap = new HashMap<>(); |
| | | Set<String> strings = rsMap3.keySet(); |
| | | ArrayList<Double> list1 = new ArrayList<>(); |
| | | ArrayList<Double> list2 = new ArrayList<>(); |
| | | ArrayList<Double> list3 = new ArrayList<>(); |
| | | ArrayList<Double> list4 = new ArrayList<>(); |
| | | ArrayList<Double> list5 = new ArrayList<>(); |
| | | ArrayList<Double> list6 = new ArrayList<>(); |
| | | ArrayList<Double> list7 = new ArrayList<>(); |
| | | ArrayList<Double> list8 = new ArrayList<>(); |
| | | ArrayList<Double> list9 = new ArrayList<>(); |
| | | ArrayList<Double> list10 = new ArrayList<>(); |
| | | ArrayList<Double> list11 = new ArrayList<>(); |
| | | ArrayList<Double> list12 = new ArrayList<>(); |
| | | ArrayList<Double> resList = new ArrayList<>(); |
| | | ArrayList<Integer> list = new ArrayList<>(); |
| | | ArrayList<Integer> listPM = new ArrayList<>(); |
| | | int count1 = 0; |
| | | int count2 = 0; |
| | | int count3 = 0; |
| | | int count4 = 0; |
| | | int count5 = 0; |
| | | int count6 = 0; |
| | | int count7 = 0; |
| | | int count8 = 0; |
| | | int count9 = 0; |
| | | int count10 = 0; |
| | | int count11 = 0; |
| | | int count12 = 0; |
| | | for (String string : strings) { |
| | | String substring = string.substring(5, 7); |
| | | |
| | | if (substring.equals("01")) { |
| | | Object o = rsMap3.get(string); |
| | | String s = JSON.toJSONString(o); |
| | | Map map = JSON.parseObject(s, Map.class); |
| | | String aqi = map.get("AQI").toString(); |
| | | String pm2_5 = map.get("a34004").toString(); |
| | | list1.add(Double.parseDouble(pm2_5)); |
| | | resList.add(Double.parseDouble(pm2_5)); |
| | | if (Double.parseDouble(aqi) < 100) { |
| | | count1++; |
| | | } |
| | | } |
| | | if (substring.equals("02")) { |
| | | Object o = rsMap3.get(string); |
| | | String s = JSON.toJSONString(o); |
| | | Map map = JSON.parseObject(s, Map.class); |
| | | String aqi = map.get("AQI").toString(); |
| | | String pm2_5 = map.get("a34004").toString(); |
| | | list2.add(Double.parseDouble(pm2_5)); |
| | | resList.add(Double.parseDouble(pm2_5)); |
| | | if (Double.parseDouble(aqi) < 100) { |
| | | count2++; |
| | | } |
| | | } |
| | | if (substring.equals("03")) { |
| | | Object o = rsMap3.get(string); |
| | | String s = JSON.toJSONString(o); |
| | | Map map = JSON.parseObject(s, Map.class); |
| | | String aqi = map.get("AQI").toString(); |
| | | String pm2_5 = map.get("a34004").toString(); |
| | | list3.add(Double.parseDouble(pm2_5)); |
| | | resList.add(Double.parseDouble(pm2_5)); |
| | | if (Double.parseDouble(aqi) < 100) { |
| | | count3++; |
| | | } |
| | | } |
| | | if (substring.equals("04")) { |
| | | Object o = rsMap3.get(string); |
| | | String s = JSON.toJSONString(o); |
| | | Map map = JSON.parseObject(s, Map.class); |
| | | |
| | | String aqi = map.get("AQI").toString(); |
| | | |
| | | String pm2_5 = map.get("a34004").toString(); |
| | | list4.add(Double.parseDouble(pm2_5)); |
| | | resList.add(Double.parseDouble(pm2_5)); |
| | | if (Double.parseDouble(aqi) < 100) { |
| | | count4++; |
| | | } |
| | | } |
| | | if (substring.equals("05")) { |
| | | Object o = rsMap3.get(string); |
| | | String s = JSON.toJSONString(o); |
| | | Map map = JSON.parseObject(s, Map.class); |
| | | String aqi = map.get("AQI").toString(); |
| | | String pm2_5 = map.get("a34004").toString(); |
| | | list5.add(Double.parseDouble(pm2_5)); |
| | | resList.add(Double.parseDouble(pm2_5)); |
| | | if (Double.parseDouble(aqi) < 100) { |
| | | count5++; |
| | | } |
| | | } |
| | | if (substring.equals("06")) { |
| | | Object o = rsMap3.get(string); |
| | | String s = JSON.toJSONString(o); |
| | | Map map = JSON.parseObject(s, Map.class); |
| | | String aqi = map.get("AQI").toString(); |
| | | String pm2_5 = map.get("a34004").toString(); |
| | | list6.add(Double.parseDouble(pm2_5)); |
| | | resList.add(Double.parseDouble(pm2_5)); |
| | | if (Double.parseDouble(aqi) < 100) { |
| | | count6++; |
| | | } |
| | | } |
| | | if (substring.equals("07")) { |
| | | Object o = rsMap3.get(string); |
| | | String s = JSON.toJSONString(o); |
| | | Map map = JSON.parseObject(s, Map.class); |
| | | String aqi = map.get("AQI").toString(); |
| | | String pm2_5 = map.get("a34004").toString(); |
| | | list7.add(Double.parseDouble(pm2_5)); |
| | | resList.add(Double.parseDouble(pm2_5)); |
| | | if (Double.parseDouble(aqi) < 100) { |
| | | count7++; |
| | | } |
| | | } |
| | | if (substring.equals("08")) { |
| | | Object o = rsMap3.get(string); |
| | | String s = JSON.toJSONString(o); |
| | | Map map = JSON.parseObject(s, Map.class); |
| | | String aqi = map.get("AQI").toString(); |
| | | String pm2_5 = map.get("a34004").toString(); |
| | | list8.add(Double.parseDouble(pm2_5)); |
| | | resList.add(Double.parseDouble(pm2_5)); |
| | | if (Double.parseDouble(aqi) < 100) { |
| | | count8++; |
| | | } |
| | | } |
| | | if (substring.equals("09")) { |
| | | Object o = rsMap3.get(string); |
| | | String s = JSON.toJSONString(o); |
| | | Map map = JSON.parseObject(s, Map.class); |
| | | String aqi = map.get("AQI").toString(); |
| | | String pm2_5 = map.get("a34004").toString(); |
| | | list9.add(Double.parseDouble(pm2_5)); |
| | | resList.add(Double.parseDouble(pm2_5)); |
| | | if (Double.parseDouble(aqi) < 100) { |
| | | count9++; |
| | | } |
| | | } |
| | | if (substring.equals("10")) { |
| | | Object o = rsMap3.get(string); |
| | | String s = JSON.toJSONString(o); |
| | | Map map = JSON.parseObject(s, Map.class); |
| | | String aqi = map.get("AQI").toString(); |
| | | String pm2_5 = map.get("a34004").toString(); |
| | | list10.add(Double.parseDouble(pm2_5)); |
| | | resList.add(Double.parseDouble(pm2_5)); |
| | | if (Double.parseDouble(aqi) < 100) { |
| | | count10++; |
| | | } |
| | | } |
| | | if (substring.equals("11")) { |
| | | Object o = rsMap3.get(string); |
| | | String s = JSON.toJSONString(o); |
| | | Map map = JSON.parseObject(s, Map.class); |
| | | String aqi = map.get("AQI").toString(); |
| | | String pm2_5 = map.get("a34004").toString(); |
| | | list11.add(Double.parseDouble(pm2_5)); |
| | | resList.add(Double.parseDouble(pm2_5)); |
| | | if (Double.parseDouble(aqi) < 100) { |
| | | count11++; |
| | | } |
| | | } |
| | | if (substring.equals("12")) { |
| | | Object o = rsMap3.get(string); |
| | | String s = JSON.toJSONString(o); |
| | | Map map = JSON.parseObject(s, Map.class); |
| | | String aqi = map.get("AQI").toString(); |
| | | String pm2_5 = map.get("a34004").toString(); |
| | | list12.add(Double.parseDouble(pm2_5)); |
| | | resList.add(Double.parseDouble(pm2_5)); |
| | | if (Double.parseDouble(aqi) < 100) { |
| | | count12++; |
| | | } |
| | | } |
| | | |
| | | } |
| | | list.add(count1); |
| | | list.add(count2); |
| | | list.add(count3); |
| | | list.add(count4); |
| | | list.add(count5); |
| | | list.add(count6); |
| | | list.add(count7); |
| | | list.add(count8); |
| | | list.add(count9); |
| | | list.add(count10); |
| | | list.add(count11); |
| | | list.add(count12); |
| | | |
| | | Integer sum = list.stream().reduce(Integer::sum).orElse(0); |
| | | list.add(sum); |
| | | listMap.put("count", list); |
| | | |
| | | Integer collect1 = 0; |
| | | if (list1.size() > 0) { |
| | | collect1 = Math.toIntExact(Math.round(list1.stream().collect(Collectors.averagingDouble(Double::doubleValue)))); |
| | | } |
| | | Integer collect2 = 0; |
| | | if (list2.size() > 0) { |
| | | collect2 = Math.toIntExact(Math.round(list2.stream().collect(Collectors.averagingDouble(Double::doubleValue)))); |
| | | } |
| | | Integer collect3 = 0; |
| | | if (list3.size() > 0) { |
| | | collect3 = Math.toIntExact(Math.round(list3.stream().collect(Collectors.averagingDouble(Double::doubleValue)))); |
| | | } |
| | | Integer collect4 = 0; |
| | | if (list4.size() > 0) { |
| | | collect4 = Math.toIntExact(Math.round(list4.stream().collect(Collectors.averagingDouble(Double::doubleValue)))); |
| | | } |
| | | Integer collect5 = 0; |
| | | if (list5.size() > 0) { |
| | | collect5 = Math.toIntExact(Math.round(list5.stream().collect(Collectors.averagingDouble(Double::doubleValue)))); |
| | | } |
| | | Integer collect6 = 0; |
| | | if (list6.size() > 0) { |
| | | collect6 = Math.toIntExact(Math.round(list6.stream().collect(Collectors.averagingDouble(Double::doubleValue)))); |
| | | } |
| | | Integer collect7 = 0; |
| | | if (list7.size() > 0) { |
| | | collect7 = Math.toIntExact(Math.round(list7.stream().collect(Collectors.averagingDouble(Double::doubleValue)))); |
| | | } |
| | | Integer collect8 = 0; |
| | | if (list8.size() > 0) { |
| | | collect8 = Math.toIntExact(Math.round(list8.stream().collect(Collectors.averagingDouble(Double::doubleValue)))); |
| | | } |
| | | Integer collect9 = 0; |
| | | if (list9.size() > 0) { |
| | | collect9 = Math.toIntExact(Math.round(list9.stream().collect(Collectors.averagingDouble(Double::doubleValue)))); |
| | | } |
| | | Integer collect10 = 0; |
| | | if (list10.size() > 0) { |
| | | collect10 = Math.toIntExact(Math.round(list10.stream().collect(Collectors.averagingDouble(Double::doubleValue)))); |
| | | } |
| | | Integer collect11 = 0; |
| | | if (list11.size() > 0) { |
| | | collect11 = Math.toIntExact(Math.round(list11.stream().collect(Collectors.averagingDouble(Double::doubleValue)))); |
| | | } |
| | | Integer collect12 = 0; |
| | | if (list12.size() > 0) { |
| | | collect12 = Math.toIntExact(Math.round(list12.stream().collect(Collectors.averagingDouble(Double::doubleValue)))); |
| | | } |
| | | //今年的pm2.5累计 |
| | | int resPM25 = Math.toIntExact(Math.round(resList.stream().collect(Collectors.averagingDouble(Double::doubleValue)))); |
| | | listPM.add(collect1); |
| | | listPM.add(collect2); |
| | | listPM.add(collect3); |
| | | listPM.add(collect4); |
| | | listPM.add(collect5); |
| | | listPM.add(collect6); |
| | | listPM.add(collect7); |
| | | listPM.add(collect8); |
| | | listPM.add(collect9); |
| | | listPM.add(collect10); |
| | | listPM.add(collect11); |
| | | listPM.add(collect12); |
| | | listPM.add(resPM25); |
| | | listMap.put("PM2_5", listPM); |
| | | return listMap; |
| | | } |
| | | |
| | | /** |
| | | * 计算去年PM2.5和优良天数 |
| | | * |
| | | * @param rsMap2 |
| | | */ |
| | | private Map<String, Integer> getResult(HashMap<String, Object> rsMap2, String time) throws ParseException { |
| | | HashMap<String, Integer> rsMap = new HashMap<>(); |
| | | ArrayList<Double> list = new ArrayList<>(); |
| | | SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd"); |
| | | Calendar instance = Calendar.getInstance(); |
| | | instance.setTime(sdf1.parse(time)); |
| | | instance.add(Calendar.YEAR, -1); |
| | | Date date = instance.getTime(); |
| | | //时间戳 |
| | | long time1 = date.getTime(); |
| | | int count = 0; |
| | | Set<String> strings = rsMap2.keySet(); |
| | | for (String string : strings) { |
| | | Date parse = sdf1.parse(string); |
| | | long time2 = parse.getTime(); |
| | | if (time2 <= time1) { |
| | | Object o = rsMap2.get(string); |
| | | String s = JSON.toJSONString(o); |
| | | Map map = JSON.parseObject(s, Map.class); |
| | | String aqi = map.get("AQI").toString(); |
| | | String pm2_5 = map.get("a34004").toString(); |
| | | list.add(Double.parseDouble(pm2_5)); |
| | | if (Double.parseDouble(aqi) < 100) { |
| | | count++; |
| | | } |
| | | } |
| | | } |
| | | //去年的pm2.5累积 |
| | | int PM2_5 = Math.toIntExact(Math.round(list.stream().collect(Collectors.averagingDouble(Double::doubleValue)))); |
| | | rsMap.put("count", count); |
| | | rsMap.put("PM2_5", PM2_5); |
| | | |
| | | return rsMap; |
| | | } |
| | | |
| | | /** |
| | | * 计算 浑南区的数据 |
| | | * @param file |
| | | * @throws IOException |
| | | */ |
| | | private Map<String, List<Integer>> getTo(MultipartFile file,String time) throws IOException, ParseException { |
| | | XSSFWorkbook workbook = new XSSFWorkbook(file.getInputStream()); |
| | | HashMap<String, Object> rsMap1 = new HashMap<>(); |
| | | HashMap<String, Object> rsMap2 = new HashMap<>(); |
| | | HashMap<String, Object> rsMap3 = new HashMap<>(); |
| | | HashMap<String, Object> rsMap4 = new HashMap<>(); |
| | | //去年的浑南区 |
| | | HashMap<String, Object> hnMap1 = new HashMap<>(); |
| | | //今年的浑南区 |
| | | HashMap<String, Object> hnMap2 = new HashMap<>(); |
| | | |
| | | XSSFSheet sheetAt = workbook.getSheetAt(0); |
| | | |
| | | //一共有多少行 |
| | | //浑南东路 |
| | | int lastRowNum = sheetAt.getLastRowNum(); |
| | | for (int i = 2; i <= lastRowNum; i++) { |
| | | XSSFRow row = sheetAt.getRow(i); |
| | | if (row == null) { |
| | | continue; |
| | | } |
| | | short lastCellNum = row.getLastCellNum(); |
| | | if (lastCellNum < 8) { |
| | | continue; |
| | | } |
| | | Object[] objects = new Object[lastCellNum]; |
| | | for (int j = 0; j < lastCellNum; j++) { |
| | | Cell cell = row.getCell(j); |
| | | if (cell != null) { |
| | | Object value = ExcelUtils.getValue(cell); |
| | | objects[j] = value; |
| | | } |
| | | |
| | | } |
| | | HashMap<String, Object> map1 = new HashMap<>(); |
| | | HashMap<String, Object> map2 = new HashMap<>(); |
| | | if (objects.length == 18) { |
| | | if ( !objects[11].toString().contains("H") |
| | | && !objects[12].toString().contains("H") |
| | | && !objects[13].toString().contains("H") |
| | | && !objects[14].toString().contains("H") |
| | | && !objects[15].toString().contains("H") |
| | | && !objects[16].toString().contains("H") |
| | | ) { |
| | | // map1.put("time", objects[10]); |
| | | //PM10 |
| | | map1.put("a34002", objects[11]); |
| | | //PM2_5 |
| | | map1.put("a34004", objects[12]); |
| | | //SO2 |
| | | map1.put("a21026", objects[13]); |
| | | //NO2 |
| | | map1.put("a21004", objects[14]); |
| | | //CO |
| | | map1.put("a21005", objects[15]); |
| | | //O3_8H |
| | | map1.put("a05024", objects[16]); |
| | | |
| | | rsMap1.put(objects[10].toString(), map1); |
| | | } |
| | | |
| | | } |
| | | |
| | | if (objects.length == 27) { |
| | | if ( !objects[11].toString().contains("H") |
| | | && !objects[12].toString().contains("H") |
| | | && !objects[13].toString().contains("H") |
| | | && !objects[14].toString().contains("H") |
| | | && !objects[15].toString().contains("H") |
| | | && !objects[16].toString().contains("H") |
| | | |
| | | ) { |
| | | map1.put("a34002", objects[11]); |
| | | map1.put("a34004", objects[12]); |
| | | map1.put("a21026", objects[13]); |
| | | map1.put("a21004", objects[14]); |
| | | map1.put("a21005", objects[15]); |
| | | map1.put("a05024", objects[16]); |
| | | |
| | | rsMap1.put(objects[10].toString(), map1); |
| | | } |
| | | if ( |
| | | !objects[20].toString().contains("H") |
| | | && !objects[21].toString().contains("H") |
| | | && !objects[22].toString().contains("H") |
| | | && !objects[23].toString().contains("H") |
| | | && !objects[24].toString().contains("H") |
| | | && !objects[25].toString().contains("H")) |
| | | { |
| | | map2.put("a34002", objects[20]); |
| | | map2.put("a34004", objects[21]); |
| | | map2.put("a21026", objects[22]); |
| | | map2.put("a21004", objects[23]); |
| | | map2.put("a21005", objects[24]); |
| | | map2.put("a05024", objects[25]); |
| | | |
| | | rsMap2.put(objects[19].toString(), map2); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | //新秀街 |
| | | XSSFSheet sheetAt1 = workbook.getSheetAt(1); |
| | | |
| | | int lastRowNum1 = sheetAt1.getLastRowNum(); |
| | | for (int i = 2; i < lastRowNum1; i++) { |
| | | XSSFRow row = sheetAt1.getRow(i); |
| | | if (row == null) { |
| | | continue; |
| | | } |
| | | short lastCellNum = row.getLastCellNum(); |
| | | if (lastCellNum < 8) { |
| | | continue; |
| | | } |
| | | Object[] objects = new Object[lastCellNum]; |
| | | for (int j = 0; j < lastCellNum; j++) { |
| | | Cell cell = row.getCell(j); |
| | | if (cell != null) { |
| | | Object value = ExcelUtils.getValue(cell); |
| | | objects[j] = value; |
| | | } |
| | | |
| | | } |
| | | HashMap<String, Object> map1 = new HashMap<>(); |
| | | HashMap<String, Object> map2 = new HashMap<>(); |
| | | if (objects.length == 18) { |
| | | if ( !objects[11].toString().contains("H") |
| | | && !objects[12].toString().contains("H") |
| | | && !objects[13].toString().contains("H") |
| | | && !objects[14].toString().contains("H") |
| | | && !objects[15].toString().contains("H") |
| | | && !objects[16].toString().contains("H") |
| | | ) { |
| | | // map1.put("time", objects[10]); |
| | | map1.put("a34002", objects[11]); |
| | | map1.put("a34004", objects[12]); |
| | | map1.put("a21026", objects[13]); |
| | | map1.put("a21004", objects[14]); |
| | | map1.put("a21005", objects[15]); |
| | | map1.put("a05024", objects[16]); |
| | | |
| | | rsMap3.put(objects[10].toString(), map1); |
| | | } |
| | | |
| | | } |
| | | |
| | | if (objects.length == 27) { |
| | | if ( !objects[11].toString().contains("H") |
| | | && !objects[12].toString().contains("H") |
| | | && !objects[13].toString().contains("H") |
| | | && !objects[14].toString().contains("H") |
| | | && !objects[15].toString().contains("H") |
| | | && !objects[16].toString().contains("H")) |
| | | { |
| | | map1.put("a34002", objects[11]); |
| | | map1.put("a34004", objects[12]); |
| | | map1.put("a21026", objects[13]); |
| | | map1.put("a21004", objects[14]); |
| | | map1.put("a21005", objects[15]); |
| | | map1.put("a05024", objects[16]); |
| | | |
| | | rsMap3.put(objects[10].toString(), map1); |
| | | } |
| | | if ( !objects[20].toString().contains("H") |
| | | && !objects[21].toString().contains("H") |
| | | && !objects[22].toString().contains("H") |
| | | && !objects[23].toString().contains("H") |
| | | && !objects[24].toString().contains("H") |
| | | && !objects[25].toString().contains("H") |
| | | ) { |
| | | // map2.put("time", objects[19]); |
| | | map2.put("a34002", objects[20]); |
| | | map2.put("a34004", objects[21]); |
| | | map2.put("a21026", objects[22]); |
| | | map2.put("a21004", objects[23]); |
| | | map2.put("a21005", objects[24]); |
| | | map2.put("a05024", objects[25]); |
| | | rsMap4.put(objects[19].toString(), map2); |
| | | } |
| | | } |
| | | |
| | | } |
| | | Set<String> strings = rsMap1.keySet(); |
| | | for (String string : strings) { |
| | | Object o = rsMap1.get(string); |
| | | String s = JSON.toJSONString(o); |
| | | Map map = JSON.parseObject(s, Map.class); |
| | | if (!rsMap3.containsKey(string)){ |
| | | hnMap1.put(string,map); |
| | | continue; |
| | | } |
| | | Object o1 = rsMap3.get(string); |
| | | String s1 = JSON.toJSONString(o1); |
| | | Map map1 = JSON.parseObject(s1, Map.class); |
| | | Set sets = map1.keySet(); |
| | | HashMap<Object, Object> hs = new HashMap<>(); |
| | | for (Object set : sets) { |
| | | if (set.toString().equals("a21005")){ |
| | | String s3 = map1.get(set).toString(); |
| | | String s2 = map.get(set).toString(); |
| | | hs.put(set,new BigDecimal((Double.parseDouble(s3)+Double.parseDouble(s2))/2).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue()); |
| | | continue; |
| | | } |
| | | String s3 = map1.get(set).toString(); |
| | | String s2 = map.get(set).toString(); |
| | | hs.put(set,Math.round((Double.parseDouble(s3)+Double.parseDouble(s2))/2)); |
| | | } |
| | | hnMap1.put(string,hs); |
| | | } |
| | | |
| | | Set<String> strings2 = rsMap3.keySet(); |
| | | for (String s : strings2) { |
| | | Object o = rsMap3.get(s); |
| | | String s1 = JSON.toJSONString(o); |
| | | Map map = JSON.parseObject(s1, Map.class); |
| | | if (!hnMap1.containsKey(s)){ |
| | | hnMap1.put(s,map); |
| | | } |
| | | } |
| | | |
| | | Set<String> strings1 = rsMap2.keySet(); |
| | | for (String s : strings1) { |
| | | Object o = rsMap2.get(s); |
| | | String s1 = JSON.toJSONString(o); |
| | | Map map = JSON.parseObject(s1, Map.class); |
| | | if (!rsMap4.containsKey(s)){ |
| | | hnMap2.put(s,map); |
| | | continue; |
| | | } |
| | | Object o1 = rsMap4.get(s); |
| | | String s2 = JSON.toJSONString(o1); |
| | | Map map1 = JSON.parseObject(s2, Map.class); |
| | | Set sets = map1.keySet(); |
| | | HashMap<Object, Object> hs = new HashMap<>(); |
| | | for (Object set : sets) { |
| | | if (set.toString().equals("a21005")){ |
| | | String s3 = map1.get(set).toString(); |
| | | String s4 = map.get(set).toString(); |
| | | hs.put(set,new BigDecimal((Double.parseDouble(s3)+Double.parseDouble(s4))/2).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue()); |
| | | continue; |
| | | } |
| | | String s3 = map1.get(set).toString(); |
| | | String s4 = map.get(set).toString(); |
| | | hs.put(set,Math.round((Double.parseDouble(s3)+Double.parseDouble(s4))/2)); |
| | | |
| | | } |
| | | hnMap2.put(s,hs); |
| | | } |
| | | |
| | | Set<String> strings3 = rsMap4.keySet(); |
| | | for (String s : strings3) { |
| | | Object o = rsMap4.get(s); |
| | | String s1 = JSON.toJSONString(o); |
| | | Map map = JSON.parseObject(s1, Map.class); |
| | | if (!rsMap2.containsKey(s1)){ |
| | | hnMap2.put(s,map); |
| | | } |
| | | } |
| | | //计算今年的aqi |
| | | getHnMap(hnMap2); |
| | | //计算去年的aqi |
| | | getHnMap(hnMap1); |
| | | // |
| | | Map<String, List<Integer>> map = getMap(hnMap2); |
| | | |
| | | |
| | | Map<String, Integer> map2 = getResult(hnMap1, time); |
| | | |
| | | List<Integer> list = map.get("count"); |
| | | list.add(map2.get("count")); |
| | | List<Integer> list1 = map.get("PM2_5"); |
| | | list1.add(map2.get("PM2_5")); |
| | | |
| | | return map; |
| | | |
| | | } |
| | | //计算aqi |
| | | private void getHnMap(HashMap<String, Object> hnMap2) { |
| | | Set<String> strings4 = hnMap2.keySet(); |
| | | for (String s : strings4) { |
| | | Object o = hnMap2.get(s); |
| | | String s1 = JSON.toJSONString(o); |
| | | Map rs = JSON.parseObject(s1, Map.class); |
| | | AQI aqi = AQIUtils.dailyAQI(rs); |
| | | JSONObject jsonObject = JSON.parseObject(s1); |
| | | jsonObject.put("AQI",aqi.getAQIValue()); |
| | | String s2 = JSON.toJSONString(jsonObject); |
| | | Map map = JSON.parseObject(s2, Map.class); |
| | | hnMap2.put(s,map); |
| | | } |
| | | } |
| | | |
| | | } |