|
@@ -8,7 +8,7 @@ import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.jdbc.core.ResultSetExtractor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-
|
|
|
+import org.springframework.util.ResourceUtils;
|
|
|
import javax.annotation.Resource;
|
|
|
import java.io.*;
|
|
|
import java.sql.ResultSet;
|
|
@@ -44,8 +44,9 @@ public class CalculationFormulaRepositoryImpl implements CalculationFormulaRepos
|
|
|
String createSql = "create table t_calculation_formula ( ID int(0) not null auto_increment primary key, TYPE varchar(50) , `ORDER` int(0), FORMULA varchar(255) not null , PROVINCE_ENUM varchar(10), STATE varchar(10), CREATE_TIME datetime(0), CREATOR varchar(50), LAST_MODIFIER varchar(50), LAST_MODIFY_TIME datetime(0));";
|
|
|
|
|
|
jdbcTemplate.execute(createSql);
|
|
|
-
|
|
|
- File sqlFile = new File("../../../../../../resources/sql/test.sql");
|
|
|
+ // 获取sql文件
|
|
|
+ File sqlFile = ResourceUtils.getFile("classpath:sql/test.sql");
|
|
|
+ // 读取文件
|
|
|
FileReader fileReader = new FileReader(sqlFile);
|
|
|
BufferedReader reader = new BufferedReader(fileReader);
|
|
|
String s;
|
|
@@ -54,24 +55,6 @@ public class CalculationFormulaRepositoryImpl implements CalculationFormulaRepos
|
|
|
builder.append(s);
|
|
|
}
|
|
|
jdbcTemplate.execute(builder.toString());
|
|
|
- // 拼接插入语句,配置文件要增加&allowMultiQueries=true ,允许一次提交多条sql语句
|
|
|
- /* String insertSql =
|
|
|
- "INSERT INTO `t_calculation_formula` VALUES (1, 'DQ', 1, 'sum:math.abs(VariateA-VariateB)', 'E62', NULL, NULL, NULL, NULL, NULL);" +
|
|
|
- "INSERT INTO `t_calculation_formula` VALUES (2, 'DQ', 2, 'sum:math.pow((VariateA-VariateB),2)*math.abs(VariateA-VariateB)/result1', 'E62', NULL, NULL, NULL, NULL, NULL);" +
|
|
|
- "INSERT INTO `t_calculation_formula` VALUES (3, 'DQ', 3, '(1-(math.sqrt(result2)/VariateC))*100', 'E62', NULL, NULL, NULL, NULL, NULL);" +
|
|
|
- "INSERT INTO `t_calculation_formula` VALUES (4, 'VariateA', NULL, 'sj', 'E62', NULL, NULL, NULL, NULL, NULL);" +
|
|
|
- "INSERT INTO `t_calculation_formula` VALUES (5, 'VariateB', NULL, 'yc', 'E62', NULL, NULL, NULL, NULL, NULL);" +
|
|
|
- "INSERT INTO `t_calculation_formula` VALUES (6, 'VariateC', NULL, 'rl', 'E62', NULL, NULL, NULL, NULL, NULL);" +
|
|
|
- "INSERT INTO `t_calculation_formula` VALUES (7, 'VariateD', NULL, 'count', 'E62', NULL, NULL, NULL, NULL, NULL);" +
|
|
|
- "INSERT INTO `t_calculation_formula` VALUES (8, 'Point', 1, 'math.abs((VariateA-VariateB)/VariateC)*100', 'E62', NULL, NULL, NULL, NULL, NULL);" +
|
|
|
- "INSERT INTO `t_calculation_formula` VALUES (9, 'MAE', 1, 'sum:math.abs((VariateA-VariateB)', 'E62', NULL, NULL, NULL, NULL, NULL);" +
|
|
|
- "INSERT INTO `t_calculation_formula` VALUES (10, 'MAE', 2, '1-(result1/(VariateC*VariateD))', 'E62', NULL, NULL, NULL, NULL, NULL);" +
|
|
|
- "INSERT INTO `t_calculation_formula` VALUES (11, 'RMSE', 1, 'sum:math.pow((VariateA-VariateB)/VariateC,2)', 'E62', NULL, NULL, NULL, NULL, NULL);" +
|
|
|
- "INSERT INTO `t_calculation_formula` VALUES (12, 'RMSE', 2, '(1-math.sqrt((result1/VariateD)))*100', 'E62', NULL, NULL, NULL, NULL, NULL);" +
|
|
|
- "INSERT INTO `t_calculation_formula` VALUES (13, 'RMSES', 1, 'sum:math.pow((VariateA-VariateB),2)', 'E62', NULL, NULL, NULL, NULL, NULL);" +
|
|
|
- "INSERT INTO `t_calculation_formula` VALUES (14, 'RMSES', 2, '(1-(result1/VariateC*math.sqrt(VariateD)))*100', 'E62', NULL, NULL, NULL, NULL, NULL);";
|
|
|
-
|
|
|
- jdbcTemplate.execute(insertSql);*/
|
|
|
} catch (DataAccessException e) {
|
|
|
e.printStackTrace();
|
|
|
log.info("删除/创建表错误:" + e.toString());
|
|
@@ -83,27 +66,13 @@ public class CalculationFormulaRepositoryImpl implements CalculationFormulaRepos
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void updateTable() {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void save(CalculationFormula calculationFormula) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void update(CalculationFormula calculationFormula) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<CalculationFormula> findByTypeAndProvince(String type) {
|
|
|
- String sql = "SELECT * from t_calculation_formula where TYPE = ? ";
|
|
|
+ public List<CalculationFormula> findByTypeAndProvince(String type,String provinceEnum) {
|
|
|
+ provinceEnum = "%"+provinceEnum+";%";
|
|
|
+ String sql = "SELECT * from t_calculation_formula where TYPE = ? and PROVINCE_ENUM like ? ";
|
|
|
|
|
|
List<CalculationFormula> calculationFormulaList = null;
|
|
|
try {
|
|
|
- calculationFormulaList = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(CalculationFormula.class), type);
|
|
|
+ calculationFormulaList = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(CalculationFormula.class), type ,provinceEnum);
|
|
|
} catch (DataAccessException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
@@ -111,15 +80,4 @@ public class CalculationFormulaRepositoryImpl implements CalculationFormulaRepos
|
|
|
return calculationFormulaList;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public List<CalculationFormula> findVariate(String provinceEnum) {
|
|
|
- String sql = "SELECT * from t_calculation_formula where TYPE in ('VariateA','VariateB','VariateC') and PROVINCE_ENUM = ?";
|
|
|
- List<CalculationFormula> calculationFormulaList = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(CalculationFormula.class), provinceEnum);
|
|
|
- return calculationFormulaList;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<CalculationFormula> findAll() {
|
|
|
- return null;
|
|
|
- }
|
|
|
}
|