From 6d986e13135e685ecb3fbf7c9b1f18ac7133cb92 Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Wed, 15 May 2024 14:16:35 +0800 Subject: [PATCH 1/2] =?UTF-8?q?#=E5=8F=91=E7=94=B5=E9=87=8F=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E6=9C=80=E5=90=8E=E5=80=BC=E5=87=8F=E6=9C=80=E5=88=9D?= =?UTF-8?q?=E5=80=BC=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../operational/main/constant/MainConstants.java | 3 + .../scheduled/RealTargetScheduledTask.java | 13 +++ .../service/operation/home/RealTargetService.java | 2 +- .../operation/home/impl/RealTargetServiceImpl.java | 118 ++++++++++++--------- 4 files changed, 85 insertions(+), 51 deletions(-) diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/constant/MainConstants.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/constant/MainConstants.java index a080158..f37ce48 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/constant/MainConstants.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/constant/MainConstants.java @@ -50,7 +50,10 @@ public interface MainConstants { String LOAD_HYDROPOWER_UNIT_TARGET = "loadHydropowerUnitTarget"; // 近年发电量 + String LOAD_POWER_DATA_NEW = "loadPowerDataNew"; + String ELECTRICITY_GENERATION_RECENT_YEAR = "electricityGenerationRecentYear"; + // 風電儲能近年发电量 String WIND_POWER_GENERATION_RECENT_YEAR = "windPowerGenerationRecentYear"; diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/RealTargetScheduledTask.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/RealTargetScheduledTask.java index 9591c87..f71d9d3 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/RealTargetScheduledTask.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/RealTargetScheduledTask.java @@ -157,6 +157,19 @@ public class RealTargetScheduledTask { return new ReturnT<>("SUCCESS"); } + /** + * 获取站点近3年发电量数据 + */ + @XxlJob(LOAD_POWER_DATA_NEW) + //@Scheduled(cron = "0/40 * * * * ? ") + public ReturnT loadPowerDataNew(String param) { + if (Func.isBlank(param)) { + param = DateUtil.format(new Date(), "yyyy-MM"); + } + service.loadPowerDataNew(param, Arrays.asList(HomePageConstant.HYDROPOWER,HomePageConstant.PHOTOVOLTAIC),2,3); + return new ReturnT<>("SUCCESS"); + } + @XxlJob(WIND_POWER_GENERATION_RECENT_YEAR) //@Scheduled(cron = "0/40 * * * * ? ") diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/RealTargetService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/RealTargetService.java index bf8d692..7ea1a7d 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/RealTargetService.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/RealTargetService.java @@ -28,7 +28,7 @@ public interface RealTargetService { void loadPowerData(String param, List types, Integer serveType, int year); - void loadPowerDataNew(List types, Integer serveType, int year); + void loadPowerDataNew(String param, List types, Integer serveType, int year); void loadPowerDataByWindEnergy(String param, List types, Integer serveType, int year,String key); } diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/RealTargetServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/RealTargetServiceImpl.java index 8a5f14d..dfca1da 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/RealTargetServiceImpl.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/RealTargetServiceImpl.java @@ -114,6 +114,9 @@ public class RealTargetServiceImpl implements RealTargetService { private final static String recent_year_power_data = "hzims:operation:key:power:data"; + + private final static String recent_year_power_data_test = "hzims:operation:key:power:data:test"; + private final static String load_hydropower_unit_real_key = "hzims:operation:loadhydropowerunit:real:key"; private final static String load_hydropower_unit_target_key = "hzims:operation:loadhydropowerunit:target:key"; private final static String loadwaterpump_target_key = "hzims:operation:loadwaterpump:target:key"; @@ -1275,72 +1278,87 @@ public class RealTargetServiceImpl implements RealTargetService { } @Override - - public void loadPowerDataNew(List types, Integer serveType, int year) { + public void loadPowerDataNew(String param, List types, Integer serveType, int year) { // 站点查询 - List stationList = stationService.list(new LambdaQueryWrapper() {{ - eq(StationEntity::getDataOrigin,"0"); - if (ObjectUtil.isNotEmpty(serveType)) { - eq(StationEntity::getServeType, serveType); - } + List stations = stationService.list(new LambdaQueryWrapper() {{ if (CollectionUtil.isNotEmpty(types)) { in(StationEntity::getType, types); } }}); // 设备信息 - List devices = JSONObject.parseObject(redisTemplate.opsForValue().get(device_cache_cofig_final).toString(), - new TypeReference>() {}); - // 结束时间 + List devices = JSONObject.parseObject(redisTemplate.opsForValue().get(device_cache_cofig_final).toString(), new TypeReference>() { + }); + // 开始时间 Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH) + 12); calendar.add(Calendar.DATE, -calendar.get(Calendar.DATE) + 1); String end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE) + " 00:00:00"; - LocalDateTime endTime = LocalDateTime.parse(end); - // 开始时间 + // 结束日期 calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) - year); calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH)); String start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE) + " 00:00:00"; - LocalDateTime startTime = LocalDateTime.parse(end); - // 存储数据map:<站点id, <月份, 发电量>> - Map> powerMap = new HashMap<>(); - stationList.forEach(station -> { - List datas = new ArrayList<>(); - // 站点设备集合 - List stationDevices = devices.stream().filter(device -> device.getCreateDept().equals(station.getRefDept())).collect(Collectors.toList()); - log.info("load_power_data station :" + station.getCode() + "==== device :" + stationDevices); - if (CollectionUtil.isNotEmpty(devices)) { - stationDevices.forEach(device -> { - ReductionDataDTO reductionDataDTO = new ReductionDataDTO(); - reductionDataDTO.setDeviceCode(device.getEmCode()); - reductionDataDTO.setSaveTimeType(5); - reductionDataDTO.setTimeInterval(1); - reductionDataDTO.setBeginTime(startTime); - reductionDataDTO.setEndTime(endTime); - reductionDataDTO.setNeedPage(false); - Result reductionDataVOResult = deviceDataClient.pageDeviceCodeAndSignages(reductionDataDTO); - if (!reductionDataVOResult.isSuccess() || CollectionUtil.isEmpty(reductionDataVOResult.getData().getDataList())) { + // 存储数据map :<站点id,<月份,发电量>> + Map> powerMap = new CopyOnWriteMap<>(); + // 将站点切割 + int limit = countStep(stations.size()); + List> limits = Stream.iterate(0, n -> n + 1).limit(limit).parallel().map(a -> stations.stream().skip((long) a * 3).limit(3).parallel().collect(Collectors.toList())).collect(Collectors.toList()); + CountDownLatch countDownLatch = new CountDownLatch(limits.size()); + for(List item : limits){ + pool.submit(()->{ + item.forEach(station->{ + // 站点设备集合 + List stationDevices = devices.stream().filter(device -> device.getCreateDept().equals(station.getRefDept())).collect(Collectors.toList()); + Map generateMap = this.lastReduceFirst(station,stationDevices,start,end); + if(MapUtils.isEmpty(generateMap)){ return; } - List> dataList = reductionDataVOResult.getData().getDataList(); - datas.addAll(dataList.stream().map(data -> { - PowerMonthVo generate = new PowerMonthVo(); - Date time = DateUtil.parse(data.get("ts"), "yyyy-MM-dd HH:mm:ss.s"); - generate.setStrMonth(DateUtil.format(time,DateUtil.PATTERN_DATE)); -// generate.setPower(Float.parseFloat(Optional.ofNullable(data.get(HomePageConstant.HYDROPOWER_GENERATE_POWER)) -// .orElse("0")) * device.getRideCount()); - return generate; - }).collect(Collectors.toList())); + powerMap.put(station.getId(),generateMap); }); - } - // 补充填报数据 - datas.addAll(this.generateFill(station,start,end)); - if (CollectionUtil.isEmpty(datas)) { - return; - } - Map map = datas.stream().collect(Collectors.toMap(PowerMonthVo::getStrMonth, PowerMonthVo::getPower, Float::sum)); - powerMap.put(station.getId(), map); - }); - redisTemplate.opsForValue().set(recent_year_power_data, powerMap); + countDownLatch.countDown(); + log.error("pool_item_execute_complete: {}" ,item.stream().map(StationEntity::getName).collect(Collectors.toList())); + }); + + } + //所有模板数据获取完成后释放锁 + try { + countDownLatch.await(); + } catch (InterruptedException e) { + e.printStackTrace(); + Thread.currentThread().interrupt(); + } + redisTemplate.opsForValue().set(recent_year_power_data_test, JSONObject.toJSONString(powerMap)); + } + + private Map lastReduceFirst(StationEntity station, List devices, String start, String end) { + List datas = new ArrayList<>(); + // 设备采集发电量 + if(CollectionUtil.isNotEmpty(devices)){ + devices.forEach(device->{ + List> records = dataService.lastFirstBySignage(start,end,7,5,device.getEmCode(),HomePageConstant.HYDROPOWER_GENERATE_POWER); + if(CollectionUtil.isEmpty(records)){ + return; + } + datas.addAll(records.stream().map(record -> { + PowerMonthVo generate = new PowerMonthVo(); + Date time = DateUtil.parse(record.get("ts"), "yyyy-MM-dd HH:mm:ss.s"); + generate.setStrMonth(DateUtil.format(time,DateUtil.PATTERN_DATE)); + String val = record.get(HomePageConstant.HYDROPOWER_GENERATE_POWER); + if(StringUtil.isEmpty(val)){ + generate.setPower(0f); + }else{ + generate.setPower(Float.parseFloat(String.valueOf(Double.parseDouble(val) * device.getRideCount()))); + } + return generate; + }).collect(Collectors.toList())); + }); + } + // 补充填报数据 + datas.addAll(this.generateFill(station,start,end)); + if(CollectionUtil.isEmpty(datas)){ + return null; + } + return datas.stream().collect(Collectors.toMap(PowerMonthVo::getStrMonth, PowerMonthVo::getPower, Float::sum)); + } /** From 1b8a2cd45d6f27f9e2616a59cd4d66277ac03854 Mon Sep 17 00:00:00 2001 From: liwen Date: Thu, 16 May 2024 10:55:42 +0800 Subject: [PATCH 2/2] =?UTF-8?q?update:=20=E5=AF=BC=E5=87=BA=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E4=BB=A3=E7=A0=81=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/hnac/hzims/safeproduct/utils/BaseUtil.java | 89 ++++++---------------- 1 file changed, 22 insertions(+), 67 deletions(-) diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/utils/BaseUtil.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/utils/BaseUtil.java index 0789275..3c84c29 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/utils/BaseUtil.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/utils/BaseUtil.java @@ -6,9 +6,8 @@ import com.hnac.hzims.safeproduct.constants.SafeProductConstant; import lombok.extern.slf4j.Slf4j; import org.apache.commons.io.IOUtils; import org.apache.poi.xwpf.usermodel.*; -import com.alibaba.fastjson.JSONObject; -import com.alibaba.fastjson.JSONArray; -//import org.json.JSONObject; +import org.json.JSONArray; +import org.json.JSONObject; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHyperlink; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText; @@ -116,77 +115,20 @@ public class BaseUtil { * @param params 数据参数 * @return 文件 */ -// public static XWPFDocument fillDocument(String templatePath, Map params, String findName) { -// XWPFDocument xwpfDocument = null; -// try { -// xwpfDocument = WordExportUtil.exportWord07(templatePath, params); -// if (StringUtils.isNotEmpty(findName)) { -// String findText = params.get(findName).toString(); -// if (StringUtils.isNotEmpty(findText)) { -// JSONArray jsonArray = new JSONArray(findText); -// for (XWPFTable table : xwpfDocument.getTables()) { -// for (int row = 0; row < table.getNumberOfRows(); row++) { -// for (int col = 0; col < table.getRow(row).getTableCells().size(); col++) { -// XWPFTableCell cell = table.getRow(row).getCell(col); -// for (XWPFParagraph p : cell.getParagraphs()) { -// for (int index = 0; index < p.getRuns().size(); index++) { -// XWPFRun run = p.getRuns().get(index); -// String text = run.getText(0); -// if (findText.equals(text)) { -// run.setText("", 0); // 清除原有文本 -// XWPFParagraph paragraph = run.getParagraph(); -// for (int i = 0; i < jsonArray.length(); i++) { -// JSONObject jsonObject = jsonArray.getJSONObject(i); -// String name = jsonObject.getString("name"); -// String url = jsonObject.getString("url"); -// // url编码格式化 -// String encodeName = URLEncoder.encode(name, "UTF-8").replaceAll("\\+", "%20"); -// String prefixString = url.substring(0, url.lastIndexOf("/") + 1); -// String encodeUrl = prefixString + encodeName; -// String id = paragraph.getDocument().getPackagePart().addExternalRelationship(encodeUrl, -// XWPFRelation.HYPERLINK.getRelation()).getId(); -// CTHyperlink cLink = paragraph.getCTP().addNewHyperlink(); -// cLink.setId(id); -// CTText ctText = CTText.Factory.newInstance(); -// ctText.setStringValue(name); -// CTR ctr = CTR.Factory.newInstance(); -// ctr.setTArray(new CTText[]{ctText}); -// cLink.setRArray(new CTR[]{ctr}); -// if (i < jsonArray.length() - 1) { -// paragraph.createRun().addBreak(); -// } -// } -// } -// } -// } -// } -// } -// } -// } -// } -// if (templatePath.equals("template/卫生自查表.docx")) { -// formatHygieneRecordTable(xwpfDocument); -// } -// } catch (Exception e) { -// log.error("数据写入异常: {}",e.getCause().toString()+ e.getStackTrace()); -// e.printStackTrace(); -// } -// return xwpfDocument; -// } - - public static XWPFDocument fillDocument(String templatePath, Map params, String findName) throws IOException { + public static XWPFDocument fillDocument(String templatePath, Map params, String findName) { XWPFDocument xwpfDocument = null; try { xwpfDocument = WordExportUtil.exportWord07(templatePath, params); if (findName != null && !findName.isEmpty()) { String findText = params.get(findName).toString(); if (findText != null && !findText.isEmpty()) { - JSONArray jsonArray = JSONArray.parseArray(findText); + JSONArray jsonArray = new JSONArray(findText); for (XWPFTable table : xwpfDocument.getTables()) { for (XWPFTableRow row : table.getRows()) { for (XWPFTableCell cell : row.getTableCells()) { for (XWPFParagraph p : cell.getParagraphs()) { - for (XWPFRun run : p.getRuns()) { + for (int index = 0; index < p.getRuns().size(); index++) { + XWPFRun run = p.getRuns().get(index); String text = run.getText(0); if (findText.equals(text)) { run.setText("", 0); // 清除原有文本 @@ -200,6 +142,9 @@ public class BaseUtil { } } } + if (templatePath.equals("template/卫生自查表.docx")) { + formatHygieneRecordTable(xwpfDocument); + } } catch (Exception e) { e.printStackTrace(); } @@ -208,7 +153,7 @@ public class BaseUtil { private static void insertJsonArrayIntoParagraph(JSONArray jsonArray, XWPFParagraph paragraph) throws IOException { - for (int i = 0; i < jsonArray.size(); i++) { + for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObject = jsonArray.getJSONObject(i); String name = jsonObject.getString("name"); String url = jsonObject.getString("url"); @@ -216,8 +161,18 @@ public class BaseUtil { String encodeName = URLEncoder.encode(name, "UTF-8").replaceAll("\\+", "%20"); String prefixString = url.substring(0, url.lastIndexOf("/") + 1); String encodeUrl = prefixString + encodeName; - XWPFRun newRun = paragraph.createRun(); - newRun.setText(encodeUrl); + String id = paragraph.getDocument().getPackagePart().addExternalRelationship(encodeUrl, + XWPFRelation.HYPERLINK.getRelation()).getId(); + CTHyperlink cLink = paragraph.getCTP().addNewHyperlink(); + cLink.setId(id); + CTText ctText = CTText.Factory.newInstance(); + ctText.setStringValue(name); + CTR ctr = CTR.Factory.newInstance(); + ctr.setTArray(new CTText[]{ctText}); + cLink.setRArray(new CTR[]{ctr}); + if (i < jsonArray.length() - 1) { + paragraph.createRun().addBreak(); + } } } /**