Browse Source

Merge remote-tracking branch 'origin/prod-20240506' into prod-20240506

zhongwei
yang_shj 6 months ago
parent
commit
c544eec9d0
  1. 1
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/MainSystemMonitoringServiceImpl.java
  2. 15
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/OperStationMonthReportServiceImpl.java
  3. 2
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/util/ObjectUtils.java
  4. 119
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/utils/BaseUtil.java

1
hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/MainSystemMonitoringServiceImpl.java

@ -1360,6 +1360,7 @@ public class MainSystemMonitoringServiceImpl implements IMainSystemMonitoringSer
String currentMon = TimeUtils.getMon(year, mon);
Integer count=0;
Map<Long, Map<String, Float>> powerMapThree = (Map<Long, Map<String, Float>>) redisTemplate.opsForValue().get(RECENT_YEAR_POWER_DATA);
log.info("Redis近三年发电量数据查询:"+powerMapThree);
for (Map.Entry<Long, Map<String, Float>> deviceMap : powerMapThree.entrySet()) {
for (StationEntity stationEntity : stationEntityList) {
if (stationEntity.getId().equals(deviceMap.getKey())) {

15
hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/OperStationMonthReportServiceImpl.java

@ -344,16 +344,19 @@ public class OperStationMonthReportServiceImpl implements IOperStationMonthRepor
Integer currentYear = calendar.get(Calendar.YEAR);
if (year>currentYear-3) {
mainSystemMonitoringService.getElectricSituationByRedis(yearAndMonth, reportVOS, stationEntityList);
log.info("电站发电情况"+reportVOS.toString());
}else {
stationEntityList.forEach(stationEntity -> {
List<StationRunReportVO> stationReportVOList = mainSystemMonitoringService.getElectricSituationV2(yearAndMonth, stationEntity.getCode());
reportVOS.addAll(stationReportVOList);
});
log.info("电站发电情况"+reportVOS.toString());
}
getSumStationRunReport(reportVOS);
stationReportAllVo.setStationReportVOList(reportVOS);
log.info("电站发电量总览"+reportVOS.toString());
}catch (Exception e){
log.error("", e);
log.error("getStationMonthReportV2电站发电量报错", e);
System.out.println(e);
}finally {
countDownLatch.countDown();
@ -523,11 +526,12 @@ public class OperStationMonthReportServiceImpl implements IOperStationMonthRepor
stationRunReportVO.setStationName("合计");
if (CollectionUtil.isNotEmpty(reportVOS)){
double sumPowerMonPlan = reportVOS.stream().mapToDouble(StationRunReportVO::getPowerMonPlan).sum();
stationRunReportVO.setPowerMonPlan(sumPowerMonPlan);
stationRunReportVO.setPowerMonPlan(new BigDecimal(sumPowerMonPlan).setScale(2,BigDecimal.ROUND_UP).doubleValue());
double sumFinishPowerMon = reportVOS.stream().map(StationRunReportVO::getFinishPowerMon).mapToDouble(s -> Double.valueOf(s)).sum();
stationRunReportVO.setFinishPowerMon(String.valueOf(sumFinishPowerMon));
stationRunReportVO.setFinishPowerMon(new BigDecimal(sumFinishPowerMon).setScale(2,BigDecimal.ROUND_UP).toString());
if (!ObjectUtils.isEmpty(sumPowerMonPlan)) {
BigDecimal powerMonRate = new BigDecimal(sumFinishPowerMon).divide(new BigDecimal(sumPowerMonPlan)).setScale(2, BigDecimal.ROUND_UP);
BigDecimal powerMonRate = new BigDecimal(sumFinishPowerMon).divide(new BigDecimal(sumPowerMonPlan),4,BigDecimal.ROUND_UP)
.multiply(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_UP);
stationRunReportVO.setPowerMonRate(String.valueOf(powerMonRate));
}else {
stationRunReportVO.setPowerMonRate("0.0");
@ -537,7 +541,8 @@ public class OperStationMonthReportServiceImpl implements IOperStationMonthRepor
double sumFinishPowerYear = reportVOS.stream().map(StationRunReportVO::getFinishPowerYear).mapToDouble(s -> Double.valueOf(s)).sum();
stationRunReportVO.setFinishPowerYear(String.valueOf(sumFinishPowerYear));
if (!ObjectUtils.isEmpty(sumPowerYearPlan)){
BigDecimal powerYearRate = new BigDecimal(sumFinishPowerYear).divide(new BigDecimal(sumPowerYearPlan)).setScale(2, BigDecimal.ROUND_UP);
BigDecimal powerYearRate = new BigDecimal(sumFinishPowerYear).divide(new BigDecimal(sumPowerYearPlan),4,BigDecimal.ROUND_UP)
.multiply(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_UP);
stationRunReportVO.setPowerYearRate(String.valueOf(powerYearRate));
}else {
stationRunReportVO.setPowerYearRate("0.0");

2
hzims-service/operational/src/main/java/com/hnac/hzims/operational/util/ObjectUtils.java

@ -85,7 +85,7 @@ public class ObjectUtils {
public static BigDecimal objDivide(String s){
BigDecimal bigDecimal = new BigDecimal(s);
BigDecimal res = bigDecimal.divide(new BigDecimal(10000)).setScale(2, BigDecimal.ROUND_UP);
BigDecimal res = bigDecimal.divide(new BigDecimal(10000),2,BigDecimal.ROUND_UP).setScale(2, BigDecimal.ROUND_UP);
return res;
}
}

119
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/utils/BaseUtil.java

@ -6,8 +6,9 @@ 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 org.json.JSONArray;
import org.json.JSONObject;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.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;
@ -115,46 +116,82 @@ public class BaseUtil {
* @param params 数据参数
* @return 文件
*/
public static XWPFDocument fillDocument(String templatePath, Map<String, Object> params, String findName) {
// public static XWPFDocument fillDocument(String templatePath, Map<String, Object> 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<String, Object> params, String findName) throws IOException {
XWPFDocument xwpfDocument = null;
try {
xwpfDocument = WordExportUtil.exportWord07(templatePath, params);
if (StringUtils.isNotEmpty(findName)) {
if (findName != null && !findName.isEmpty()) {
String findText = params.get(findName).toString();
if (StringUtils.isNotEmpty(findText)) {
JSONArray jsonArray = new JSONArray(findText);
if (findText != null && !findText.isEmpty()) {
JSONArray jsonArray = JSONArray.parseArray(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 (XWPFTableRow row : table.getRows()) {
for (XWPFTableCell cell : row.getTableCells()) {
for (XWPFParagraph p : cell.getParagraphs()) {
for (int index = 0; index < p.getRuns().size(); index++) {
XWPFRun run = p.getRuns().get(index);
for (XWPFRun run : p.getRuns()) {
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();
}
}
insertJsonArrayIntoParagraph(jsonArray, paragraph);
}
}
}
@ -163,16 +200,26 @@ public class BaseUtil {
}
}
}
if (templatePath.equals("template/卫生自查表.docx")) {
formatHygieneRecordTable(xwpfDocument);
}
} catch (Exception e) {
log.error("数据写入异常: {}",e.getCause().toString()+ e.getStackTrace());
e.printStackTrace();
}
return xwpfDocument;
}
private static void insertJsonArrayIntoParagraph(JSONArray jsonArray, XWPFParagraph paragraph) throws IOException {
for (int i = 0; i < jsonArray.size(); 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;
XWPFRun newRun = paragraph.createRun();
newRun.setText(encodeUrl);
}
}
/**
* 卫生自查表格式处理
* @param xwpfDocument word文件类

Loading…
Cancel
Save