Browse Source

1.查询公式sql修改,场站类型(E1/E2)模糊查询

zhangchenglong 2 years ago
parent
commit
7113d0e37a

+ 12 - 11
src/main/java/com/syjy/calculate/repository/repositoryImpl/CalculationFormulaRepositoryImpl.java

@@ -14,6 +14,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.jdbc.core.ResultSetExtractor;
 import org.springframework.stereotype.Service;
 import org.springframework.util.ClassUtils;
+
 import javax.annotation.Resource;
 import java.io.*;
 import java.net.URL;
@@ -58,13 +59,13 @@ public class CalculationFormulaRepositoryImpl implements CalculationFormulaRepos
             // 从表中获取旧版本
             String oldVersion = getVersion();
             // 如果版本没变化,不进行初始化表操作
-            if(oldVersion.equals(version) || oldVersion.equals("null")){
+            if (oldVersion.equals(version) || oldVersion.equals("null")) {
                 return;
             }
             // 如果版本不同,则初始化表
             this.createTable();
-        // 如果表不存在,初始化表
-        }else{
+            // 如果表不存在,初始化表
+        } else {
             this.createTable();
         }
     }
@@ -155,20 +156,20 @@ public class CalculationFormulaRepositoryImpl implements CalculationFormulaRepos
      * 查询公式数据
      *
      * @param type         类型
-     * @param province 省调
+     * @param province     省调
      * @param formulaType  公式类型
      * @param electricType 场站类型
      * @return
      */
     @Override
     public CalculationFormula findByTypeAndProvince(String type, String formulaType, String province, String electricType) {
-
         String sql = "";
+        electricType = "%" + electricType + "%";
         // 查询sql
         if (CalculateResult.FORMULA.equals(type)) {
-            sql = "SELECT * from t_calculation_formula where ELECTRIC_TYPE = ? and PROVINCE = ? and TYPE = ? limit 1 ";
+            sql = "SELECT * from t_calculation_formula where ELECTRIC_TYPE like ? and PROVINCE = ? and TYPE = ? limit 1 ";
         } else if (CalculateResult.RULES.equals(type)) {
-            sql = "SELECT * from t_calculation_formula where TYPE = 'RULES' and ELECTRIC_TYPE = ? and PROVINCE = ? and RULE_FORMULA = ? limit 1";
+            sql = "SELECT * from t_calculation_formula where TYPE = 'RULES' and ELECTRIC_TYPE like ? and PROVINCE = ? and RULE_FORMULA = ? limit 1";
         }
         // 根据类型和省调查询公式
         try {
@@ -182,7 +183,7 @@ public class CalculationFormulaRepositoryImpl implements CalculationFormulaRepos
     /**
      * 创建表
      */
-    private void createTable(){
+    private void createTable() {
         try {
             // 获取初始化公式表sql
             String path = "sql/t_calculation_formula.sql";
@@ -214,7 +215,7 @@ public class CalculationFormulaRepositoryImpl implements CalculationFormulaRepos
     /**
      * 获取版本
      */
-    private String getVersion(){
+    private String getVersion() {
         String version = "";
         String sql = " SELECT * FROM t_calculation_formula where type = 'VERSION' ";
         try {
@@ -229,9 +230,9 @@ public class CalculationFormulaRepositoryImpl implements CalculationFormulaRepos
     /**
      * 更新版本
      */
-    private void updateVersion(){
+    private void updateVersion() {
         String version = properties.getVersion();
-        String sql = " UPDATE t_calculation_formula set FORMULA = '" + version +"' where type = 'VERSION' ";
+        String sql = " UPDATE t_calculation_formula set FORMULA = '" + version + "' where type = 'VERSION' ";
         try {
             jdbcTemplate.update(sql);
         } catch (DataAccessException e) {