|
@@ -10,10 +10,15 @@ import com.ims.eval.expression.*;
|
|
|
import com.ims.eval.service.IEvaluationScoreCountService;
|
|
|
import com.ims.eval.util.MathCalculatorUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.poi.hssf.usermodel.*;
|
|
|
+import org.apache.poi.ss.formula.FormulaParseException;
|
|
|
+import org.apache.poi.ss.usermodel.CellType;
|
|
|
+import org.apache.poi.ss.usermodel.FormulaEvaluator;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -55,6 +60,14 @@ public class ScoreCalculationSchedule {
|
|
|
private OrganizationEvaluationRuleMapper organizationEvaluationRuleMapper;
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * Sheet 中的每一行
|
|
|
+ */
|
|
|
+ private static HSSFRow row = null;
|
|
|
+
|
|
|
+ private static FormulaEvaluator formulaEvaluator = null;
|
|
|
+
|
|
|
+
|
|
|
public boolean doTask(String id){
|
|
|
|
|
|
boolean save = true;
|
|
@@ -335,4 +348,36 @@ public class ScoreCalculationSchedule {
|
|
|
|
|
|
}*/
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算值
|
|
|
+ *
|
|
|
+ * @param formula Excel 中的公式,例如:MAX(56-FLOOR(20/6,1),2)
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static double caculateFormula(String formula) {
|
|
|
+ if(formula.startsWith("=")){
|
|
|
+ formula =formula.replace("=","");
|
|
|
+ }
|
|
|
+ HSSFWorkbook workbook = new HSSFWorkbook();
|
|
|
+ HSSFSheet sheet = workbook.createSheet();
|
|
|
+ row = sheet.createRow(0);
|
|
|
+ formulaEvaluator = new HSSFFormulaEvaluator(workbook);
|
|
|
+
|
|
|
+ // 这里必须新建一个对象,否则只有第一个 formula 才有效。查看 formulaEvaluator.evaluate 的源码。
|
|
|
+ HSSFCell cell = row.createCell(0);
|
|
|
+ cell.setCellType(CellType.FORMULA);
|
|
|
+ try {
|
|
|
+ cell.setCellFormula(formula);
|
|
|
+ double value = formulaEvaluator.evaluate(cell).getNumberValue();
|
|
|
+ return new BigDecimal(value).setScale(2, BigDecimal.ROUND_CEILING).doubleValue();
|
|
|
+ } catch (FormulaParseException e) {
|
|
|
+ System.out.print(e.getMessage());
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|