Pārlūkot izejas kodu

适配湖北 实际、可用计算准确率对比

jyyw 8 mēneši atpakaļ
vecāks
revīzija
7d0ad02f48

+ 2 - 2
pom.xml

@@ -10,8 +10,8 @@
     </parent>
     <groupId>com.syjy</groupId>
     <artifactId>calculation-spring-boot-starter</artifactId>
-    <version>0.0.38</version>
-    <!--    <version>0.0.38-SNAPSHOT</version>-->
+    <version>0.0.39</version>
+    <!--    <version>0.0.39-SNAPSHOT</version>-->
     <name>calculation</name>
     <description>Demo project for Spring Boot</description>
     <properties>

+ 5 - 0
src/main/java/com/syjy/calculate/entity/CalculationInfo.java

@@ -2,6 +2,8 @@ package com.syjy.calculate.entity;
 
 import lombok.Data;
 import lombok.EqualsAndHashCode;
+import lombok.RequiredArgsConstructor;
+
 import java.io.Serializable;
 import java.math.BigDecimal;
 import java.util.Date;
@@ -94,6 +96,9 @@ public class CalculationInfo implements Serializable  {
      */
     private BigDecimal forecastCapacity;
 
+    /*提前多久预测*/
+    private Integer forecastHowLongAgo;
+
     public CalculationInfo(){
 
     }

+ 72 - 70
src/main/java/com/syjy/calculate/repository/CalculationFormulaRepository.java

@@ -3,6 +3,7 @@ package com.syjy.calculate.repository;
 import com.syjy.calculate.entity.CalculationFormula;
 import com.syjy.calculate.entity.CalculationInfo;
 import org.springframework.stereotype.Repository;
+
 import java.util.List;
 
 /**
@@ -15,76 +16,77 @@ import java.util.List;
 @Repository
 public interface CalculationFormulaRepository {
 
-    /**
-     * 创建公式表
-     */
-    void initTable();
-
-
-    /**
-     * 查询总数
-     */
-    int selectCount(String province, String type);
-
-    /**
-     * 查询公式列表
-     */
-    List<CalculationFormula> select(int limit, int offset, String province, String type);
-
-
-    /**
-     * 根据id获取一条
-     */
-    CalculationFormula getOne(int id);
-
-
-    /**
-     * 更新公式
-     */
-    int update(CalculationFormula calculationFormula);
-
-    /**
-     * 新增公式
-     */
-    int add(CalculationFormula calculationFormula);
-
-    /**
-     * 删除公式
-     */
-    int delete(int id);
-    /**
-     * 查询公式数据
-     *
-     * @param type 类型
-     * @return 返回记录
-     */
-    CalculationFormula findByTypeAndProvince(String type, String formulaType,String province,String electricType,String stationCode);
-
-
-    /**
-     * 查询考核公式数据
-     *
-     * @param type 类型
-     * @return 返回记录
-     */
-    CalculationFormula findAssessmentByTypeAndProvince(String type, String formulaType,String province,String electricType,String stationCode);
-
-
-    /**
-     * 查询导入的计算准确率数据
-     *
-     * @return 返回记录
-     */
-    List<CalculationInfo> getCalculationInfo();
-
-    /**
-     * 查询接口用户数据
-     *
-     * @return 返回记录
-     */
-    List<CalculationFormula> getUser();
-
-
+  /**
+   * 创建公式表
+   */
+  void initTable();
+
+
+  /**
+   * 查询总数
+   */
+  int selectCount(String province, String type);
+
+  /**
+   * 查询公式列表
+   */
+  List<CalculationFormula> select(int limit, int offset, String province, String type);
+
+
+  /**
+   * 根据id获取一条
+   */
+  CalculationFormula getOne(int id);
+
+
+  /**
+   * 更新公式
+   */
+  int update(CalculationFormula calculationFormula);
+
+  /**
+   * 新增公式
+   */
+  int add(CalculationFormula calculationFormula);
+
+  /**
+   * 删除公式
+   */
+  int delete(int id);
+
+  /**
+   * 查询公式数据
+   *
+   * @param type 类型
+   * @return 返回记录
+   */
+  CalculationFormula findByTypeAndProvince(String type, String formulaType, String province, String electricType, String stationCode);
+
+  List<CalculationFormula> findFormulaByProvince(String province, String electricType);
+
+
+  /**
+   * 查询考核公式数据
+   *
+   * @param type 类型
+   * @return 返回记录
+   */
+  CalculationFormula findAssessmentByTypeAndProvince(String type, String formulaType, String province, String electricType, String stationCode);
+
+
+  /**
+   * 查询导入的计算准确率数据
+   *
+   * @return 返回记录
+   */
+  List<CalculationInfo> getCalculationInfo();
+
+  /**
+   * 查询接口用户数据
+   *
+   * @return 返回记录
+   */
+  List<CalculationFormula> getUser();
 
 
 }

+ 440 - 426
src/main/java/com/syjy/calculate/repository/repositoryImpl/CalculationFormulaRepositoryImpl.java

@@ -2,7 +2,6 @@ package com.syjy.calculate.repository.repositoryImpl;
 
 import cn.hutool.core.io.IoUtil;
 import cn.hutool.core.util.ObjectUtil;
-import cn.hutool.core.util.StrUtil;
 import cn.hutool.db.sql.SqlUtil;
 import cn.hutool.poi.excel.ExcelReader;
 import cn.hutool.poi.excel.ExcelUtil;
@@ -43,471 +42,486 @@ import java.util.List;
 @Service
 @Slf4j
 public class CalculationFormulaRepositoryImpl implements CalculationFormulaRepository {
-    @Autowired
-    StarterProperties properties;
-    @Resource
-    public JdbcTemplate jdbcTemplate;
+  @Autowired
+  StarterProperties properties;
+  @Resource
+  public JdbcTemplate jdbcTemplate;
 
-    /**
-     * 创建公式表
-     */
-    @Override
-    public void initTable() {
-        log.info("初始化准确率计算公式表");
-        // 获取数据库类型
-        String dbType = properties.getDbType();
-        // 如果是金仓数据库,直接初始化表
-        if (CalculateResult.DB_KINGBASE.equals(dbType)) {
-            this.createTable();
-            return;
-        }
+  /**
+   * 创建公式表
+   */
+  @Override
+  public void initTable() {
+    log.info("初始化准确率计算公式表");
+    // 获取数据库类型
+    String dbType = properties.getDbType();
+    // 如果是金仓数据库,直接初始化表
+    if (CalculateResult.DB_KINGBASE.equals(dbType)) {
+      this.createTable();
+      return;
+    }
 
-        // 从配置文件中获取版本
-        String version = properties.getVersion();
-        // 判断表是否存在
-        String checkSql = "select count(1) from t_calculation_formula";
-        int count = 0;
-        try {
-            // 获取表中数据
-            count = jdbcTemplate.queryForObject(checkSql, Integer.class);
-        } catch (DataAccessException e) {
-            // 如果表不存在,则创建表
-            log.error(e.toString());
-            this.createTable();
-        }
+    // 从配置文件中获取版本
+    String version = properties.getVersion();
+    // 判断表是否存在
+    String checkSql = "select count(1) from t_calculation_formula";
+    int count = 0;
+    try {
+      // 获取表中数据
+      count = jdbcTemplate.queryForObject(checkSql, Integer.class);
+    } catch (DataAccessException e) {
+      // 如果表不存在,则创建表
+      log.error(e.toString());
+      this.createTable();
+    }
 
-        // 再次查询表中数据
-        try {
-            count = jdbcTemplate.queryForObject(checkSql, Integer.class);
-        } catch (DataAccessException e) {
-            e.printStackTrace();
-        }
-        // 如果表存在
-        if (count > 0) {
-            // 从表中获取旧版本
-            String oldVersion = getVersion();
-            // 如果版本没变化,不进行初始化表操作
-            if (oldVersion.equals(version) || oldVersion.equals("null")) {
-                log.info("版本没变化,不进行初始化表");
-                return;
-            }
-            // 如果版本不同,则初始化表
-            this.createTable();
-        }
+    // 再次查询表中数据
+    try {
+      count = jdbcTemplate.queryForObject(checkSql, Integer.class);
+    } catch (DataAccessException e) {
+      e.printStackTrace();
+    }
+    // 如果表存在
+    if (count > 0) {
+      // 从表中获取旧版本
+      String oldVersion = getVersion();
+      // 如果版本没变化,不进行初始化表操作
+      if (oldVersion.equals(version) || oldVersion.equals("null")) {
+        log.info("版本没变化,不进行初始化表");
+        return;
+      }
+      // 如果版本不同,则初始化表
+      this.createTable();
     }
+  }
 
-    @Override
-    public int selectCount(String province, String type) {
+  @Override
+  public int selectCount(String province, String type) {
 
-        String sql = "SELECT count(1) from t_calculation_formula where state = '1' ";
+    String sql = "SELECT count(1) from t_calculation_formula where state = '1' ";
 
-        List<Object> param = new LinkedList<>();
-        // 判断省调是否为空
-        if (province != null && !"".equals(province.trim())) {
-            sql = sql + "and province LIKE ? ";
-            province = "%" + province + "%";
-            param.add(province);
-            if (type != null && !"".equals(type.trim())) {
-                type = "%" + type + "%";
-                param.add(type);
-                sql = sql + "and type LIKE ? ";
-            }
-        } else {
-            // 判断公式类型是否为空
-            if (type != null && !"".equals(type.trim())) {
-                type = "%" + type + "%";
-                param.add(type);
-                sql = sql + "and type LIKE ? ";
-            }
-        }
-        int count = 0;
-        try {
-            if (param != null && param.size() > 0) {
-                count = jdbcTemplate.queryForObject(sql, Integer.class, param.toArray());
-            } else {
-                count = jdbcTemplate.queryForObject(sql, Integer.class);
-            }
+    List<Object> param = new LinkedList<>();
+    // 判断省调是否为空
+    if (province != null && !"".equals(province.trim())) {
+      sql = sql + "and province LIKE ? ";
+      province = "%" + province + "%";
+      param.add(province);
+      if (type != null && !"".equals(type.trim())) {
+        type = "%" + type + "%";
+        param.add(type);
+        sql = sql + "and type LIKE ? ";
+      }
+    } else {
+      // 判断公式类型是否为空
+      if (type != null && !"".equals(type.trim())) {
+        type = "%" + type + "%";
+        param.add(type);
+        sql = sql + "and type LIKE ? ";
+      }
+    }
+    int count = 0;
+    try {
+      if (param != null && param.size() > 0) {
+        count = jdbcTemplate.queryForObject(sql, Integer.class, param.toArray());
+      } else {
+        count = jdbcTemplate.queryForObject(sql, Integer.class);
+      }
 
-        } catch (DataAccessException e) {
-            e.printStackTrace();
-        }
-        return count;
+    } catch (DataAccessException e) {
+      e.printStackTrace();
     }
+    return count;
+  }
 
-    /**
-     * 查询所有公式
-     *
-     * @param limit    每页显示数量
-     * @param offset   起始索引
-     * @param province 省调
-     * @param type     公式类型
-     * @return
-     */
-    @Override
-    public List<CalculationFormula> select(int limit, int offset, String province, String type) {
+  /**
+   * 查询所有公式
+   *
+   * @param limit    每页显示数量
+   * @param offset   起始索引
+   * @param province 省调
+   * @param type     公式类型
+   * @return
+   */
+  @Override
+  public List<CalculationFormula> select(int limit, int offset, String province, String type) {
 
-        String sql = "SELECT * from t_calculation_formula where state = '1' ";
-        List<Object> param = new LinkedList<>();
-        // 判断省调是否为空
-        if (province != null && !"".equals(province.trim())) {
-            sql = sql + "and province LIKE ? ";
-            province = "%" + province + "%";
-            param.add(province);
-            if (type != null && !"".equals(type.trim())) {
-                sql = sql + "and LIKE = ? ";
-                type = "%" + type + "%";
-                param.add(type);
-            }
-        } else {
-            // 判断公式类型是否为空
-            if (type != null && !"".equals(type.trim())) {
-                sql = sql + "and type LIKE ? ";
-                type = "%" + type + "%";
-                param.add(type);
-            }
-        }
-        // 拼接分页范围
-        sql = sql + " limit " + offset + "," + limit;
-        List<CalculationFormula> calculationFormulaList = new ArrayList<>();
+    String sql = "SELECT * from t_calculation_formula where state = '1' ";
+    List<Object> param = new LinkedList<>();
+    // 判断省调是否为空
+    if (province != null && !"".equals(province.trim())) {
+      sql = sql + "and province LIKE ? ";
+      province = "%" + province + "%";
+      param.add(province);
+      if (type != null && !"".equals(type.trim())) {
+        sql = sql + "and LIKE = ? ";
+        type = "%" + type + "%";
+        param.add(type);
+      }
+    } else {
+      // 判断公式类型是否为空
+      if (type != null && !"".equals(type.trim())) {
+        sql = sql + "and type LIKE ? ";
+        type = "%" + type + "%";
+        param.add(type);
+      }
+    }
+    // 拼接分页范围
+    sql = sql + " limit " + offset + "," + limit;
+    List<CalculationFormula> calculationFormulaList = new ArrayList<>();
 
-        try {
-            if (param != null && param.size() > 0) {
-                calculationFormulaList = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(CalculationFormula.class), param.toArray());
-            } else {
-                calculationFormulaList = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(CalculationFormula.class));
-            }
-        } catch (DataAccessException e) {
-            e.printStackTrace();
-        }
-        return calculationFormulaList;
+    try {
+      if (param != null && param.size() > 0) {
+        calculationFormulaList = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(CalculationFormula.class), param.toArray());
+      } else {
+        calculationFormulaList = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(CalculationFormula.class));
+      }
+    } catch (DataAccessException e) {
+      e.printStackTrace();
     }
+    return calculationFormulaList;
+  }
 
-    @Override
-    public CalculationFormula getOne(int id) {
-        String sql = "select * from t_calculation_formula where id = ? and state = '1' ";
-        CalculationFormula calculationFormula;
-        try {
-            calculationFormula = jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(CalculationFormula.class), id);
-        } catch (EmptyResultDataAccessException e) {
-            return null;
-        }
-        return calculationFormula;
+  @Override
+  public CalculationFormula getOne(int id) {
+    String sql = "select * from t_calculation_formula where id = ? and state = '1' ";
+    CalculationFormula calculationFormula;
+    try {
+      calculationFormula = jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(CalculationFormula.class), id);
+    } catch (EmptyResultDataAccessException e) {
+      return null;
     }
+    return calculationFormula;
+  }
 
-    /**
-     * 更新公式
-     *
-     * @param calculationFormula
-     * @return
-     */
-    @Override
-    public int update(CalculationFormula calculationFormula) {
-        Integer id = calculationFormula.getId();
-        String type = calculationFormula.getType();
-        String formula = calculationFormula.getFormula();
-        String ruleFormula = calculationFormula.getRuleFormula();
-        String province = calculationFormula.getProvince();
-        String electricType = calculationFormula.getElectricType();
-        String isRate = calculationFormula.getIsRate();
-        int count = 0;
-        try {
-            count = jdbcTemplate.update("update t_calculation_formula set TYPE=?,FORMULA=?,PROVINCE=?,ELECTRIC_TYPE=?,RULE_FORMULA = ?,IS_RATE=? where id=?", type, formula, province, electricType, ruleFormula, isRate, id);
-        } catch (DataAccessException e) {
-            e.printStackTrace();
-        }
-        if (count > 0) {
-            // 清除缓存公式
-            AviatorEvaluator.clearExpressionCache();
-        }
-        return count;
+  /**
+   * 更新公式
+   *
+   * @param calculationFormula
+   * @return
+   */
+  @Override
+  public int update(CalculationFormula calculationFormula) {
+    Integer id = calculationFormula.getId();
+    String type = calculationFormula.getType();
+    String formula = calculationFormula.getFormula();
+    String ruleFormula = calculationFormula.getRuleFormula();
+    String province = calculationFormula.getProvince();
+    String electricType = calculationFormula.getElectricType();
+    String isRate = calculationFormula.getIsRate();
+    int count = 0;
+    try {
+      count = jdbcTemplate.update("update t_calculation_formula set TYPE=?,FORMULA=?,PROVINCE=?,ELECTRIC_TYPE=?,RULE_FORMULA = ?,IS_RATE=? where id=?", type, formula, province, electricType, ruleFormula, isRate, id);
+    } catch (DataAccessException e) {
+      e.printStackTrace();
+    }
+    if (count > 0) {
+      // 清除缓存公式
+      AviatorEvaluator.clearExpressionCache();
     }
+    return count;
+  }
 
-    /**
-     * 新增公式
-     *
-     * @param calculationFormula
-     * @return
-     */
-    @Override
-    public int add(CalculationFormula calculationFormula) {
-        String electricType = calculationFormula.getElectricType();
-        String isRate = calculationFormula.getIsRate();
-        String type = calculationFormula.getType();
-        String formula = calculationFormula.getFormula();
-        String ruleFormula = calculationFormula.getRuleFormula();
-        String province = calculationFormula.getProvince();
-        int count = 0;
-        try {
-            count = jdbcTemplate.update(
-                "INSERT INTO t_calculation_formula(TYPE,FORMULA,PROVINCE,ELECTRIC_TYPE,RULE_FORMULA,IS_RATE,STATE) VALUES (?, ?, ?, ?, ?, ?,'1')", type, formula, province, electricType, ruleFormula, isRate);
-        } catch (DataAccessException e) {
-            e.printStackTrace();
-        }
-        return count;
+  /**
+   * 新增公式
+   *
+   * @param calculationFormula
+   * @return
+   */
+  @Override
+  public int add(CalculationFormula calculationFormula) {
+    String electricType = calculationFormula.getElectricType();
+    String isRate = calculationFormula.getIsRate();
+    String type = calculationFormula.getType();
+    String formula = calculationFormula.getFormula();
+    String ruleFormula = calculationFormula.getRuleFormula();
+    String province = calculationFormula.getProvince();
+    int count = 0;
+    try {
+      count = jdbcTemplate.update(
+        "INSERT INTO t_calculation_formula(TYPE,FORMULA,PROVINCE,ELECTRIC_TYPE,RULE_FORMULA,IS_RATE,STATE) VALUES (?, ?, ?, ?, ?, ?,'1')", type, formula, province, electricType, ruleFormula, isRate);
+    } catch (DataAccessException e) {
+      e.printStackTrace();
     }
+    return count;
+  }
 
-    /**
-     * 删除公式
-     *
-     * @param id
-     * @return
-     */
-    @Override
-    public int delete(int id) {
-        int count = 0;
-        try {
-            count = jdbcTemplate.update("update t_calculation_formula set state = 0 where id =?", id);
-        } catch (DataAccessException e) {
-            e.printStackTrace();
-        }
-        return count;
+  /**
+   * 删除公式
+   *
+   * @param id
+   * @return
+   */
+  @Override
+  public int delete(int id) {
+    int count = 0;
+    try {
+      count = jdbcTemplate.update("update t_calculation_formula set state = 0 where id =?", id);
+    } catch (DataAccessException e) {
+      e.printStackTrace();
     }
+    return count;
+  }
 
-    /**
-     * 查询公式数据
-     *
-     * @param type         类型
-     * @param province     省调
-     * @param formulaType  公式类型
-     * @param electricType 场站类型
-     * @return
-     */
-    @Override
-    public CalculationFormula findByTypeAndProvince(String type, String formulaType, String province, String electricType, String stationCode) {
-        String sql = "";
-        electricType = "%" + electricType + "%";
-        if (stationCode != null && !"".equals(stationCode)) {
-            stationCode = "%" + stationCode + "%";
-        }
-        // 查询sql
-        if (CalculateResult.FORMULA.equals(type)) {
-            sql = "SELECT * from t_calculation_formula where state = '1' and ELECTRIC_TYPE like ? and PROVINCE = ? and TYPE = ? and STATION_CODE like ? limit 1 ";
-        } else if (CalculateResult.RULES.equals(type)) {
-            sql = "SELECT * from t_calculation_formula where state = '1' and TYPE = 'RULES' and ELECTRIC_TYPE like ? and PROVINCE = ? and RULE_FORMULA = ? and STATION_CODE like ? limit 1";
-        } else {
-            log.error(CalculateResult.MSG_FORMULA_TYPE_ERROR);
-        }
+  /**
+   * 查询公式数据
+   *
+   * @param type         类型
+   * @param province     省调
+   * @param formulaType  公式类型
+   * @param electricType 场站类型
+   * @return
+   */
+  @Override
+  public CalculationFormula findByTypeAndProvince(String type, String formulaType, String province, String electricType, String stationCode) {
+    String sql = "";
+    electricType = "%" + electricType + "%";
+    if (stationCode != null && !"".equals(stationCode)) {
+      stationCode = "%" + stationCode + "%";
+    }
+    // 查询sql
+    if (CalculateResult.FORMULA.equals(type)) {
+      sql = "SELECT * from t_calculation_formula where state = '1' and ELECTRIC_TYPE like ? and PROVINCE = ? and TYPE = ? and STATION_CODE like ? limit 1 ";
+    } else if (CalculateResult.RULES.equals(type)) {
+      sql = "SELECT * from t_calculation_formula where state = '1' and TYPE = 'RULES' and ELECTRIC_TYPE like ? and PROVINCE = ? and RULE_FORMULA = ? and STATION_CODE like ? limit 1";
+    } else {
+      log.error(CalculateResult.MSG_FORMULA_TYPE_ERROR);
+    }
 
-        CalculationFormula calculationFormula = new CalculationFormula();
-        // 根据类型和省调查询公式
-        try {
-            calculationFormula = jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(CalculationFormula.class), electricType, province, formulaType, stationCode);
-            return calculationFormula;
-        } catch (EmptyResultDataAccessException e) {
-            // 如果根据场站编码没查到,则在根据省调和场站类型是All的查
-            if (CalculateResult.FORMULA.equals(type)) {
-                sql = "SELECT * from t_calculation_formula where state = '1' and ELECTRIC_TYPE like ? and PROVINCE = ? and TYPE = ?  and STATION_CODE = 'ALL' limit 1";
-            } else if (CalculateResult.RULES.equals(type)) {
-                sql = "SELECT * from t_calculation_formula where state = '1' and TYPE = 'RULES' and ELECTRIC_TYPE like ? and PROVINCE = ? and RULE_FORMULA = ? and STATION_CODE = 'ALL' limit 1";
-            }
-            // 根据类型和省调查询公式
-            try {
-                calculationFormula = jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(CalculationFormula.class), electricType, province, formulaType);
-                return calculationFormula;
-            } catch (EmptyResultDataAccessException ere) {
-                // 如果根据场站编码没查到,则在根据省调和场站类型是All的查
-                return null;
-            }
-        }
+    CalculationFormula calculationFormula = new CalculationFormula();
+    // 根据类型和省调查询公式
+    try {
+      calculationFormula = jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(CalculationFormula.class), electricType, province, formulaType, stationCode);
+      return calculationFormula;
+    } catch (EmptyResultDataAccessException e) {
+      // 如果根据场站编码没查到,则在根据省调和场站类型是All的查
+      if (CalculateResult.FORMULA.equals(type)) {
+        sql = "SELECT * from t_calculation_formula where state = '1' and ELECTRIC_TYPE like ? and PROVINCE = ? and TYPE = ?  and STATION_CODE = 'ALL' limit 1";
+      } else if (CalculateResult.RULES.equals(type)) {
+        sql = "SELECT * from t_calculation_formula where state = '1' and TYPE = 'RULES' and ELECTRIC_TYPE like ? and PROVINCE = ? and RULE_FORMULA = ? and STATION_CODE = 'ALL' limit 1";
+      }
+      // 根据类型和省调查询公式
+      try {
+        calculationFormula = jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(CalculationFormula.class), electricType, province, formulaType);
+        return calculationFormula;
+      } catch (EmptyResultDataAccessException ere) {
+        // 如果根据场站编码没查到,则在根据省调和场站类型是All的查
+        return null;
+      }
     }
+  }
 
-    /**
-     * 查询考核公式数据
-     *
-     * @param type         类型
-     * @param province     省调
-     * @param formulaType  公式类型
-     * @param electricType 场站类型
-     * @return
-     */
-    @Override
-    public CalculationFormula findAssessmentByTypeAndProvince(String type, String formulaType, String province, String electricType, String stationCode) {
+  @Override
+  public List<CalculationFormula> findFormulaByProvince(String province, String electricType) {
+    List<CalculationFormula> result = new ArrayList<>();
+    electricType = "%" + electricType + "%";
+    // 查询sql
+    String sql = " SELECT * from t_calculation_formula where state = '1' and ELECTRIC_TYPE like ? and PROVINCE = ? and RULE_FORMULA is null and INSTR(`TYPE` ,'ASSESSMENT_') <> 1 ";
+    try {
+      result = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(CalculationFormula.class), electricType, province);
+    } catch (Exception ex) {
+      ex.printStackTrace();
+      log.error(CalculateResult.MSG_NO_FORMULA);
+    }
+    return result;
+  }
 
-        electricType = "%" + electricType + "%";
-        if (stationCode != null && !"".equals(stationCode)) {
-            stationCode = "%" + stationCode + "%";
-        }
-        String sql = "";
+  /**
+   * 查询考核公式数据
+   *
+   * @param type         类型
+   * @param province     省调
+   * @param formulaType  公式类型
+   * @param electricType 场站类型
+   * @return
+   */
+  @Override
+  public CalculationFormula findAssessmentByTypeAndProvince(String type, String formulaType, String province, String electricType, String stationCode) {
 
-        // 查询sql
-        if (CalculateResult.FORMULA.equals(type)) {
-            sql = "SELECT * from t_calculation_formula where state = '1' and ELECTRIC_TYPE like ? and PROVINCE = ? and TYPE = ?  and STATION_CODE like ? limit 1";
-        } else if (CalculateResult.RULES.equals(type)) {
-            sql = "SELECT * from t_calculation_formula where state = '1' and TYPE = 'RULES' and ELECTRIC_TYPE like ? and PROVINCE = ? and RULE_FORMULA = ? and STATION_CODE like ? limit 1";
-        } else {
-            log.error(CalculateResult.MSG_FORMULA_TYPE_ERROR);
-            return null;
-        }
-        // 根据类型和省调查询公式
-        try {
-            CalculationFormula calculationFormula = jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(CalculationFormula.class), electricType, province, formulaType, stationCode);
-            return calculationFormula;
-        } catch (EmptyResultDataAccessException e) {
-            // 如果根据场站编码没查到,则在根据省调和场站类型是All的查
-            // 查询sql
-            if (CalculateResult.FORMULA.equals(type)) {
-                sql = "SELECT * from t_calculation_formula where state = '1' and ELECTRIC_TYPE like ? and PROVINCE = ? and TYPE = ?  and STATION_CODE = 'ALL' limit 1";
-            } else if (CalculateResult.RULES.equals(type)) {
-                sql = "SELECT * from t_calculation_formula where state = '1' and TYPE = 'RULES' and ELECTRIC_TYPE like ? and PROVINCE = ? and RULE_FORMULA = ? and STATION_CODE = 'ALL' limit 1";
-            }
-            // 根据类型和省调查询公式
-            try {
-                CalculationFormula calculationFormula = jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(CalculationFormula.class), electricType, province, formulaType);
-                return calculationFormula;
-            } catch (EmptyResultDataAccessException ere) {
-                // 如果根据场站编码没查到,则在根据省调和场站类型是All的查
-                return null;
-            }
-        }
+    electricType = "%" + electricType + "%";
+    if (stationCode != null && !"".equals(stationCode)) {
+      stationCode = "%" + stationCode + "%";
     }
+    String sql = "";
 
-    /**
-     * 获取测试数据
-     */
-    @Override
-    public List<CalculationInfo> getCalculationInfo() {
-        String sql = "SELECT * FROM `t_calculation_info`";
-        List<CalculationInfo> list = new ArrayList<>();
-        try {
-            list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(CalculationInfo.class));
-            return list;
-        } catch (EmptyResultDataAccessException ere) {
-            return null;
-        }
+    // 查询sql
+    if (CalculateResult.FORMULA.equals(type)) {
+      sql = "SELECT * from t_calculation_formula where state = '1' and ELECTRIC_TYPE like ? and PROVINCE = ? and TYPE = ?  and STATION_CODE like ? limit 1";
+    } else if (CalculateResult.RULES.equals(type)) {
+      sql = "SELECT * from t_calculation_formula where state = '1' and TYPE = 'RULES' and ELECTRIC_TYPE like ? and PROVINCE = ? and RULE_FORMULA = ? and STATION_CODE like ? limit 1";
+    } else {
+      log.error(CalculateResult.MSG_FORMULA_TYPE_ERROR);
+      return null;
+    }
+    // 根据类型和省调查询公式
+    try {
+      CalculationFormula calculationFormula = jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(CalculationFormula.class), electricType, province, formulaType, stationCode);
+      return calculationFormula;
+    } catch (EmptyResultDataAccessException e) {
+      // 如果根据场站编码没查到,则在根据省调和场站类型是All的查
+      // 查询sql
+      if (CalculateResult.FORMULA.equals(type)) {
+        sql = "SELECT * from t_calculation_formula where state = '1' and ELECTRIC_TYPE like ? and PROVINCE = ? and TYPE = ?  and STATION_CODE = 'ALL' limit 1";
+      } else if (CalculateResult.RULES.equals(type)) {
+        sql = "SELECT * from t_calculation_formula where state = '1' and TYPE = 'RULES' and ELECTRIC_TYPE like ? and PROVINCE = ? and RULE_FORMULA = ? and STATION_CODE = 'ALL' limit 1";
+      }
+      // 根据类型和省调查询公式
+      try {
+        CalculationFormula calculationFormula = jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(CalculationFormula.class), electricType, province, formulaType);
+        return calculationFormula;
+      } catch (EmptyResultDataAccessException ere) {
+        // 如果根据场站编码没查到,则在根据省调和场站类型是All的查
+        return null;
+      }
     }
+  }
 
-    /**
-     * 创建表
-     */
-    private void createTable() {
-        InputStream excelInputStream = null;
-        InputStream sqlInputStream = null;
-        try {
-            log.info("---------------开始创建准确率计算表---------------");
-            // 从配置文件中获取版本
-            String dbType = properties.getDbType();
-            String path;
-            // 获取初始化公式表sql
-            // 如果是金仓数据库
-            if (CalculateResult.DB_KINGBASE.equals(dbType)) {
-                path = "sql/t_calculation_formula_king_base.sql";
-                // 如果是mysql
-            } else {
-                path = "sql/t_calculation_formula.sql";
-            }
+  /**
+   * 获取测试数据
+   */
+  @Override
+  public List<CalculationInfo> getCalculationInfo() {
+    String sql = "SELECT * FROM `t_calculation_info`";
+    List<CalculationInfo> list = new ArrayList<>();
+    try {
+      list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(CalculationInfo.class));
+      return list;
+    } catch (EmptyResultDataAccessException ere) {
+      return null;
+    }
+  }
 
-            // 用ClassLoader获取jar包中的文件,获取文件流
-            ClassLoader defaultClassLoader = ClassUtils.getDefaultClassLoader();
-            assert defaultClassLoader != null;
-            URL resource = defaultClassLoader.getResource(path);
-            assert resource != null;
-            sqlInputStream = resource.openStream();
-            //
-            URL excelUrl = defaultClassLoader.getResource("sql/t_calculation_formula.xlsx");
-            if (null == excelUrl) {
-                return;
-            }
-            excelInputStream = excelUrl.openStream();
-            ExcelReader excelReader = ExcelUtil.getReader(excelInputStream, 0, true);
-            List<CalculationFormula> list = excelReader.readAll(CalculationFormula.class);
-            BatchPreparedStatementSetter pss = new BatchPreparedStatementSetter() {
-                @Override
-                public void setValues(PreparedStatement ps, int i) throws SQLException {
-                    ps.setInt(1, i + 1);
-                    ps.setString(2, list.get(i).getType());
-                    ps.setInt(3, ObjectUtil.defaultIfNull(list.get(i).getOrderNo(), 1));
-                    //String formula = StrUtil.removeAll(list.get(i).getFormula(), '\r', '\n');
-                    ps.setObject(4, list.get(i).getFormula());
-                    ps.setString(5, list.get(i).getProvince());
-                    ps.setString(6, list.get(i).getElectricType());
-                    ps.setString(7, list.get(i).getStationCode());
-                    ps.setString(8, list.get(i).getRuleFormula());
-                    ps.setString(9, list.get(i).getIsRate());
-                    ps.setString(10, list.get(i).getMaxMinLimit());
-                    ps.setString(11, list.get(i).getState());
-                    ps.setString(12, list.get(i).getDataSourceType());
-                    ps.setString(13, list.get(i).getHowManyDays());
-                    ps.setObject(14, list.get(i).getCreateTime());
-                    ps.setString(15, list.get(i).getCreator());
-                    ps.setString(16, list.get(i).getLastModifier());
-                    ps.setObject(17, list.get(i).getLastModifyTime());
-                    log.info("PS ## {} ## {}", i + 1, ps);
-                }
+  /**
+   * 创建表
+   */
+  private void createTable() {
+    InputStream excelInputStream = null;
+    InputStream sqlInputStream = null;
+    try {
+      log.info("---------------开始创建准确率计算表---------------");
+      // 从配置文件中获取版本
+      String dbType = properties.getDbType();
+      String path;
+      // 获取初始化公式表sql
+      // 如果是金仓数据库
+      if (CalculateResult.DB_KINGBASE.equals(dbType)) {
+        path = "sql/t_calculation_formula_king_base.sql";
+        // 如果是mysql
+      } else {
+        path = "sql/t_calculation_formula.sql";
+      }
 
-                @Override
-                public int getBatchSize() {
-                    return list.size();
-                }
-            };
-            switch (dbType) {
-                case CalculateResult.DB_KINGBASE:
-                    jdbcTemplate.execute(SqlUtil.formatSql(IoUtil.read(sqlInputStream, StandardCharsets.UTF_8)));
-                    jdbcTemplate.batchUpdate("INSERT INTO T_CALCULATION_FORMULA VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", pss);
-                    break;
-                case CalculateResult.DB_MYSQL:
-                    String sql = "SET NAMES utf8mb4;\nSET FOREIGN_KEY_CHECKS = 0;\n" + IoUtil.read(sqlInputStream, StandardCharsets.UTF_8);
-                    jdbcTemplate.execute(SQLUtils.formatMySql(sql));
-                    jdbcTemplate.batchUpdate("INSERT INTO T_CALCULATION_FORMULA VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", pss);
-                    jdbcTemplate.execute(SQLUtils.formatMySql("SET FOREIGN_KEY_CHECKS = 1;"));
-                    break;
-                default:
-                    throw new Exception("未知数据库类型");
-            }
-            // 执行sql文件
-            log.info("建表成功");
-            //
-        } catch (Exception ex) {
-            log.error("建表失败:{}", ex.getMessage());
-        } finally {
-            IoUtil.closeIfPosible(excelInputStream);
-            IoUtil.closeIfPosible(sqlInputStream);
+      // 用ClassLoader获取jar包中的文件,获取文件流
+      ClassLoader defaultClassLoader = ClassUtils.getDefaultClassLoader();
+      assert defaultClassLoader != null;
+      URL resource = defaultClassLoader.getResource(path);
+      assert resource != null;
+      sqlInputStream = resource.openStream();
+      //
+      URL excelUrl = defaultClassLoader.getResource("sql/t_calculation_formula.xlsx");
+      if (null == excelUrl) {
+        return;
+      }
+      excelInputStream = excelUrl.openStream();
+      ExcelReader excelReader = ExcelUtil.getReader(excelInputStream, 0, true);
+      List<CalculationFormula> list = excelReader.readAll(CalculationFormula.class);
+      BatchPreparedStatementSetter pss = new BatchPreparedStatementSetter() {
+        @Override
+        public void setValues(PreparedStatement ps, int i) throws SQLException {
+          ps.setInt(1, i + 1);
+          ps.setString(2, list.get(i).getType());
+          ps.setInt(3, ObjectUtil.defaultIfNull(list.get(i).getOrderNo(), 1));
+          //String formula = StrUtil.removeAll(list.get(i).getFormula(), '\r', '\n');
+          ps.setObject(4, list.get(i).getFormula());
+          ps.setString(5, list.get(i).getProvince());
+          ps.setString(6, list.get(i).getElectricType());
+          ps.setString(7, list.get(i).getStationCode());
+          ps.setString(8, list.get(i).getRuleFormula());
+          ps.setString(9, list.get(i).getIsRate());
+          ps.setString(10, list.get(i).getMaxMinLimit());
+          ps.setString(11, list.get(i).getState());
+          ps.setString(12, list.get(i).getDataSourceType());
+          ps.setString(13, list.get(i).getHowManyDays());
+          ps.setObject(14, list.get(i).getCreateTime());
+          ps.setString(15, list.get(i).getCreator());
+          ps.setString(16, list.get(i).getLastModifier());
+          ps.setObject(17, list.get(i).getLastModifyTime());
+          log.info("PS ## {} ## {}", i + 1, ps);
         }
-        log.info("---------------结束创建准确率计算表---------------");
-        // 更新公式
-        updateVersion();
-    }
 
-    /**
-     * 获取版本
-     */
-    private String getVersion() {
-        String version = "";
-        String sql = " SELECT * FROM t_calculation_formula where type = 'VERSION' ";
-        try {
-            CalculationFormula calculationFormula = jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(CalculationFormula.class));
-            version = calculationFormula.getFormula();
-        } catch (DataAccessException e) {
-            e.printStackTrace();
+        @Override
+        public int getBatchSize() {
+          return list.size();
         }
-        return version;
+      };
+      switch (dbType) {
+        case CalculateResult.DB_KINGBASE:
+          jdbcTemplate.execute(SqlUtil.formatSql(IoUtil.read(sqlInputStream, StandardCharsets.UTF_8)));
+          jdbcTemplate.batchUpdate("INSERT INTO T_CALCULATION_FORMULA VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", pss);
+          break;
+        case CalculateResult.DB_MYSQL:
+          String sql = "SET NAMES utf8mb4;\nSET FOREIGN_KEY_CHECKS = 0;\n" + IoUtil.read(sqlInputStream, StandardCharsets.UTF_8);
+          jdbcTemplate.execute(SQLUtils.formatMySql(sql));
+          jdbcTemplate.batchUpdate("INSERT INTO T_CALCULATION_FORMULA VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", pss);
+          jdbcTemplate.execute(SQLUtils.formatMySql("SET FOREIGN_KEY_CHECKS = 1;"));
+          break;
+        default:
+          throw new Exception("未知数据库类型");
+      }
+      // 执行sql文件
+      log.info("建表成功");
+      //
+    } catch (Exception ex) {
+      log.error("建表失败:{}", ex.getMessage());
+    } finally {
+      IoUtil.closeIfPosible(excelInputStream);
+      IoUtil.closeIfPosible(sqlInputStream);
     }
+    log.info("---------------结束创建准确率计算表---------------");
+    // 更新公式
+    updateVersion();
+  }
 
-    /**
-     * 获取用户密码
-     */
-    @Override
-    public List<CalculationFormula> getUser() {
-        String sql = " SELECT * FROM t_calculation_formula where type = 'USER' ";
-        List<CalculationFormula> list = new ArrayList<>();
-        try {
-            list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(CalculationFormula.class));
-            return list;
-        } catch (EmptyResultDataAccessException ere) {
-            return null;
-        }
+  /**
+   * 获取版本
+   */
+  private String getVersion() {
+    String version = "";
+    String sql = " SELECT * FROM t_calculation_formula where type = 'VERSION' ";
+    try {
+      CalculationFormula calculationFormula = jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(CalculationFormula.class));
+      version = calculationFormula.getFormula();
+    } catch (DataAccessException e) {
+      e.printStackTrace();
     }
+    return version;
+  }
 
-    /**
-     * 更新版本
-     */
-    private void updateVersion() {
-        String version = properties.getVersion();
-        String sql = " UPDATE t_calculation_formula set FORMULA = '" + version + "' where type = 'VERSION' ";
-        try {
-            jdbcTemplate.update(sql);
-        } catch (DataAccessException e) {
-            e.printStackTrace();
-        }
+  /**
+   * 获取用户密码
+   */
+  @Override
+  public List<CalculationFormula> getUser() {
+    String sql = " SELECT * FROM t_calculation_formula where type = 'USER' ";
+    List<CalculationFormula> list = new ArrayList<>();
+    try {
+      list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(CalculationFormula.class));
+      return list;
+    } catch (EmptyResultDataAccessException ere) {
+      return null;
+    }
+  }
+
+  /**
+   * 更新版本
+   */
+  private void updateVersion() {
+    String version = properties.getVersion();
+    String sql = " UPDATE t_calculation_formula set FORMULA = '" + version + "' where type = 'VERSION' ";
+    try {
+      jdbcTemplate.update(sql);
+    } catch (DataAccessException e) {
+      e.printStackTrace();
     }
+  }
 
 }

+ 2 - 2
src/main/resources/application.yml

@@ -8,7 +8,7 @@ spring:
       # 数据源配置
       username: root
       password: '!QAZ2root'
-      url: jdbc:mysql://192.168.1.205:3306/ipfcst-v3?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&characterSetResults=UTF-8&autoReconnect=true&rewriteBatchedStatements=true&serverTimezone=Asia/Shanghai
+      url: jdbc:mysql://192.168.1.226:3306/ipfcst-v3?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&characterSetResults=UTF-8&autoReconnect=true&rewriteBatchedStatements=true&serverTimezone=Asia/Shanghai
       driver-class-name: com.mysql.cj.jdbc.Driver
 
 #server:
@@ -36,7 +36,7 @@ logging:
 calculate:
   service:
     enabled: true
-    version: 0.0.38
+    version: 0.0.39
     dbType: mysql
 
 version: @project.version@

BIN
src/main/resources/sql/t_calculation_formula.xlsx