|
@@ -1,6 +1,9 @@
|
|
package com.platform.service.produce.impl;
|
|
package com.platform.service.produce.impl;
|
|
|
|
|
|
import com.github.pagehelper.PageHelper;
|
|
import com.github.pagehelper.PageHelper;
|
|
|
|
+import com.greenpineyu.fel.FelEngine;
|
|
|
|
+import com.greenpineyu.fel.FelEngineImpl;
|
|
|
|
+import com.greenpineyu.fel.context.FelContext;
|
|
import com.platform.common.bean.AbstractPageResultBean;
|
|
import com.platform.common.bean.AbstractPageResultBean;
|
|
import com.platform.common.cache.ConfigCache;
|
|
import com.platform.common.cache.ConfigCache;
|
|
import com.platform.common.exception.BusinessException;
|
|
import com.platform.common.exception.BusinessException;
|
|
@@ -21,7 +24,6 @@ import com.platform.service.base.impl.BaseServiceImpl;
|
|
import com.platform.service.produce.ProduceDataService;
|
|
import com.platform.service.produce.ProduceDataService;
|
|
import com.platform.service.produce.ProduceRecordService;
|
|
import com.platform.service.produce.ProduceRecordService;
|
|
import com.platform.service.produce.ProduceReportService;
|
|
import com.platform.service.produce.ProduceReportService;
|
|
-import com.platform.service.util.FelParameterUtil;
|
|
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.scheduling.annotation.Async;
|
|
import org.springframework.scheduling.annotation.Async;
|
|
@@ -33,6 +35,7 @@ import tk.mybatis.mapper.weekend.WeekendCriteria;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
import java.math.RoundingMode;
|
|
import java.math.RoundingMode;
|
|
|
|
+import java.text.DecimalFormat;
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
@@ -562,10 +565,17 @@ public class ProduceReportServiceImpl extends BaseServiceImpl<ProduceReportMappe
|
|
} else {
|
|
} else {
|
|
param.put("value", 1.0);
|
|
param.put("value", 1.0);
|
|
}
|
|
}
|
|
-
|
|
|
|
log.info("公式:" + col.get(1));
|
|
log.info("公式:" + col.get(1));
|
|
- String result = FelParameterUtil.getResultFromMap(col.get(1), param, 2);
|
|
|
|
-
|
|
|
|
|
|
+ log.info("value:" + param.get("value"));
|
|
|
|
+ String result = null;
|
|
|
|
+ try {
|
|
|
|
+ result = getResultFromMap(col.get(1), param, 2);
|
|
|
|
+ log.info("表达式计算成功,结果:{}", result);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ log.error("表达式计算失败,表达式: {}, 错误: {}", col.get(1), e.getMessage(), e);
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
// 类型1,直接乘以系数
|
|
// 类型1,直接乘以系数
|
|
BigDecimal bak = null;
|
|
BigDecimal bak = null;
|
|
if ("1".equals(col.get(2))) {
|
|
if ("1".equals(col.get(2))) {
|
|
@@ -615,7 +625,7 @@ public class ProduceReportServiceImpl extends BaseServiceImpl<ProduceReportMappe
|
|
|
|
|
|
// GS-907
|
|
// GS-907
|
|
String prefix = "zcp_";
|
|
String prefix = "zcp_";
|
|
- String result = FelParameterUtil.getResultFromMap("((a1+a2)*0.58+a3)/2", param, 2);
|
|
|
|
|
|
+ String result = getResultFromMap("((a1+a2)*0.58+a3)/2", param, 2);
|
|
// 找到对应填报数据
|
|
// 找到对应填报数据
|
|
ProduceData produceData = produceDataService.selectByNo(prefix + "total");
|
|
ProduceData produceData = produceDataService.selectByNo(prefix + "total");
|
|
ProduceReport report = BeanConverterUtil.copyObjectProperties(produceData, ProduceReport.class);
|
|
ProduceReport report = BeanConverterUtil.copyObjectProperties(produceData, ProduceReport.class);
|
|
@@ -639,18 +649,6 @@ public class ProduceReportServiceImpl extends BaseServiceImpl<ProduceReportMappe
|
|
* @param prefix
|
|
* @param prefix
|
|
*/
|
|
*/
|
|
private void generateDlAndHy(LocalDate date, String prefix) {
|
|
private void generateDlAndHy(LocalDate date, String prefix) {
|
|
-/* List<ProduceData> produceDataList = produceDataService.selectByPrefix(prefix);
|
|
|
|
- for (ProduceData produceData : produceDataList) {
|
|
|
|
- ProduceReport report = BeanConverterUtil.copyObjectProperties(produceData, ProduceReport.class);
|
|
|
|
- report.setValue("0");
|
|
|
|
- report.setDate(date);
|
|
|
|
- report.setDataId(produceData.getId());
|
|
|
|
- report.setYear(date.getYear());
|
|
|
|
- report.setMonth(date.getMonthValue());
|
|
|
|
- report.setDay(date.getDayOfMonth());
|
|
|
|
- report.setCreatedTime(LocalDateTime.now());
|
|
|
|
- this.saveModel(report);
|
|
|
|
- }*/
|
|
|
|
|
|
|
|
// 天然气
|
|
// 天然气
|
|
List<ProduceData> list = produceDataService.selectByPrefix(prefix + "天然气");
|
|
List<ProduceData> list = produceDataService.selectByPrefix(prefix + "天然气");
|
|
@@ -1414,4 +1412,59 @@ public class ProduceReportServiceImpl extends BaseServiceImpl<ProduceReportMappe
|
|
produceRecordService.saveModel(record);
|
|
produceRecordService.saveModel(record);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 计算一条表达式的值
|
|
|
|
+ *
|
|
|
|
+ * @param expression
|
|
|
|
+ * @param param
|
|
|
|
+ * @param scale
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public String getResultFromMap(String expression, Map<String, Double> param, int scale) {
|
|
|
|
+
|
|
|
|
+ FelEngine fel = new FelEngineImpl();
|
|
|
|
+ FelContext ctx = fel.getContext();
|
|
|
|
+ log.info("开始时间:" + LocalDateTime.now());
|
|
|
|
+ for (Map.Entry<String, Double> entry : param.entrySet()) {
|
|
|
|
+ log.info("key = " + entry.getKey() + ", value = " + entry.getValue());
|
|
|
|
+ String entryKey = entry.getKey();
|
|
|
|
+ Double entryValue = entry.getValue();
|
|
|
|
+ ctx.set(entryKey, entryValue);
|
|
|
|
+ }
|
|
|
|
+ log.info("expression = " + expression);
|
|
|
|
+ Object obj = fel.eval(expression);
|
|
|
|
+ String resultD = "";
|
|
|
|
+ if (obj instanceof Integer) {
|
|
|
|
+ log.info("Integer: " + obj.toString());
|
|
|
|
+ resultD = obj.toString();
|
|
|
|
+ } else {
|
|
|
|
+ if (Double.isNaN((double) obj)) {
|
|
|
|
+ resultD = "0";
|
|
|
|
+ } else {
|
|
|
|
+ resultD = obj.toString();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ log.info("结束时间:" + LocalDateTime.now());
|
|
|
|
+ return getScaleResult(Double.valueOf(resultD), scale);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 返回指定精度的结果
|
|
|
|
+ *
|
|
|
|
+ * @param result
|
|
|
|
+ * @param scale
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public static String getScaleResult(Double result, int scale) {
|
|
|
|
+ StringBuffer sb = new StringBuffer("#0.");
|
|
|
|
+ for (int i = 0; i < scale; i++) {
|
|
|
|
+ sb.append("0");
|
|
|
|
+ }
|
|
|
|
+ String pattern = sb.toString();
|
|
|
|
+ DecimalFormat decimalFormat = new DecimalFormat(pattern);// 格式化设置
|
|
|
|
+ return decimalFormat.format(result);
|
|
|
|
+ }
|
|
}
|
|
}
|