From 0e4aa8d08a3bf8e8683d05081baefdbf96ce080f Mon Sep 17 00:00:00 2001 From: cjl <276999030@qq.com> Date: Wed, 08 Nov 2023 11:45:08 +0800 Subject: [PATCH] fix:小程序添加流程状态变更 --- screen-api/src/main/java/com/moral/api/service/impl/ExcelServiceImpl.java | 170 +++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 155 insertions(+), 15 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 79b6f06..6d6bce9 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 @@ -1,6 +1,7 @@ package com.moral.api.service.impl; +import lombok.extern.slf4j.Slf4j; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; @@ -11,7 +12,6 @@ import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import org.springframework.util.ObjectUtils; import org.springframework.web.multipart.MultipartFile; import java.io.IOException; @@ -25,12 +25,13 @@ 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.HistoryDaily; import com.moral.api.entity.TbExcel; import com.moral.api.mapper.ExcelMapper; +import com.moral.api.mapper.HistoryDailyMapper; import com.moral.api.pojo.bo.ExcelBO; import com.moral.api.pojo.vo.excel.ExcelVo; @@ -41,10 +42,14 @@ @Service +@Slf4j public class ExcelServiceImpl implements ExcelService { @Autowired private ExcelMapper excelMapper; + + @Autowired + private HistoryDailyMapper historyDailyMapper; /** * ��������������� @@ -55,11 +60,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); @@ -91,11 +97,11 @@ 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<>(); @@ -124,7 +130,7 @@ excelMapper.updateById(excel); excelBO.setId(excel.getId()); excelBO.setTime(excel.getTime()); - excelBO.setDate(excel.getDate()); + excelBO.setDate(date2); } return excelBO; } @@ -181,11 +187,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")){ @@ -368,8 +382,10 @@ if (Double.parseDouble(CO)<4){ count++; } - if (Double.parseDouble(O8)<160){ - count++; + if (!O8.equals("--")) { + if (Double.parseDouble(O8) < 160) { + count++; + } } @@ -441,6 +457,126 @@ } return excelBOS; + } + + /** + * ��������������� + * @param files + * @return + */ + @Override + public void rexcelImport(List<MultipartFile> files) throws IOException { + MultipartFile file = files.get(0); + XSSFWorkbook workbook = new XSSFWorkbook(file.getInputStream()); +// HashMap<String, Object> rsMap = new HashMap<>(); + ArrayList<Map<String, Object>> list = new ArrayList<>(); + XSSFSheet sheetAt = workbook.getSheetAt(0); + //������������������ + int lastRowNum = sheetAt.getLastRowNum(); + for (int i = 1; i <= lastRowNum; i++) { + XSSFRow row = sheetAt.getRow(i); + if (row == null) { + continue; + } + short lastCellNum = row.getLastCellNum(); +// if (lastCellNum < 10) { +// continue; +// } + Object[] objects = new Object[lastCellNum]; + for (int j = 0; j < lastCellNum; j++) { + Cell cell = row.getCell(j); + Object value = ExcelUtils.getValue(cell); + objects[j] = value; + } + HashMap<String, Object> map = new HashMap<>(); + map.put("mac", objects[0]); + map.put("time", objects[1]); + // pm2.5 + if (!objects[2].toString().equals("-")){ + map.put("a34004", objects[2]); + } + + // pm10 + if (!objects[3].toString().equals("-")){ + map.put("a34002", objects[3]); + } + // ������������ + if (!objects[4].toString().equals("-")){ + map.put("a21026", objects[4]); + } + // ������������ + if (!objects[5].toString().equals("-")){ + map.put("a21004", objects[5]); + } + // co + if (!objects[6].toString().equals("-")){ + map.put("a21005", objects[6]); + } + // o3 + if (!objects[7].toString().equals("-")){ + map.put("a05024", objects[7]); + } + + // ������ + if (!objects[8].toString().equals("-")){ + map.put("a01001", objects[8]); + } + // ������ + if (!objects[9].toString().equals("-")){ + map.put("a01002", objects[9]); + } + // ������ + if (!objects[10].toString().equals("-")){ + map.put("a01007", objects[10]); + } + // ������ + if (!objects[11].toString().equals("-")){ + map.put("a01008", objects[11]); + } + + // ������ + if (!objects[12].toString().equals("-")){ + map.put("a01006", objects[12]); + } + // ������������ + if (!objects[13].toString().equals("-")){ + map.put("a00e12", objects[13]); + } + // tvoc + if (!objects[14].toString().equals("-")){ + map.put("a99054", objects[14]); + } + +// map.put("���������0.3", objects[15]); +// map.put("���������2.5", objects[16]); +// map.put("���������", objects[17]); +// map.put("������", objects[18]); +// map.put("���", objects[19]); +// map.put("������", objects[20]); +// map.put("���������", objects[21]); +// map.put("���������������", objects[22]); + list.add(map); + } +// ArrayList<HistoryDaily> rsList = new ArrayList<>(); + for (Map<String, Object> map : list) { + HistoryDaily historyDaily = new HistoryDaily(); + String time = map.remove("time").toString(); + Date date=null; + if (time.length()>20){ + date = DateUtils.dateStringToDate(time); + }else { + date = DateUtils.getDate(time, DateUtils.yyyy_MM_dd_HH_mm_ss_EN); + } + + String mac = map.remove("mac").toString(); + String value = JSONObject.toJSONString(map); + historyDaily.setMac(mac); + historyDaily.setTime(date); + historyDaily.setValue(value); +// log.info(historyDaily.getValue()); + historyDailyMapper.insert(historyDaily); +// rsList.add(historyDaily); + } } @@ -591,7 +727,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]); -- Gitblit v1.8.0