|
@@ -13,6 +13,7 @@ import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.util.ClassUtils;
|
|
import org.springframework.util.ClassUtils;
|
|
|
|
+
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import java.io.*;
|
|
import java.io.*;
|
|
import java.net.URL;
|
|
import java.net.URL;
|
|
@@ -44,7 +45,7 @@ public class CalculationFormulaRepositoryImpl implements CalculationFormulaRepos
|
|
// 获取数据库类型
|
|
// 获取数据库类型
|
|
String dbType = properties.getDbType();
|
|
String dbType = properties.getDbType();
|
|
// 如果是金仓数据库,直接初始化表
|
|
// 如果是金仓数据库,直接初始化表
|
|
- if(CalculateResult.DB_KINGBASE.equals(dbType)){
|
|
|
|
|
|
+ if (CalculateResult.DB_KINGBASE.equals(dbType)) {
|
|
this.createTable();
|
|
this.createTable();
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -70,7 +71,7 @@ public class CalculationFormulaRepositoryImpl implements CalculationFormulaRepos
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
// 如果表存在
|
|
// 如果表存在
|
|
- if (count>0) {
|
|
|
|
|
|
+ if (count > 0) {
|
|
// 从表中获取旧版本
|
|
// 从表中获取旧版本
|
|
String oldVersion = getVersion();
|
|
String oldVersion = getVersion();
|
|
// 如果版本没变化,不进行初始化表操作
|
|
// 如果版本没变化,不进行初始化表操作
|
|
@@ -260,10 +261,10 @@ public class CalculationFormulaRepositoryImpl implements CalculationFormulaRepos
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public CalculationFormula findByTypeAndProvince(String type, String formulaType, String province, String electricType,String stationCode) {
|
|
|
|
|
|
+ public CalculationFormula findByTypeAndProvince(String type, String formulaType, String province, String electricType, String stationCode) {
|
|
String sql = "";
|
|
String sql = "";
|
|
electricType = "%" + electricType + "%";
|
|
electricType = "%" + electricType + "%";
|
|
- if(stationCode!=null && !"".equals(stationCode)){
|
|
|
|
|
|
+ if (stationCode != null && !"".equals(stationCode)) {
|
|
stationCode = "%" + stationCode + "%";
|
|
stationCode = "%" + stationCode + "%";
|
|
}
|
|
}
|
|
// 查询sql
|
|
// 查询sql
|
|
@@ -271,14 +272,14 @@ public class CalculationFormulaRepositoryImpl implements CalculationFormulaRepos
|
|
sql = "SELECT * from t_calculation_formula where state = '1' and ELECTRIC_TYPE like ? and PROVINCE = ? and TYPE = ? and STATION_CODE like ? limit 1 ";
|
|
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)) {
|
|
} 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";
|
|
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{
|
|
|
|
|
|
+ } else {
|
|
log.error(CalculateResult.MSG_FORMULA_TYPE_ERROR);
|
|
log.error(CalculateResult.MSG_FORMULA_TYPE_ERROR);
|
|
}
|
|
}
|
|
|
|
|
|
CalculationFormula calculationFormula = new CalculationFormula();
|
|
CalculationFormula calculationFormula = new CalculationFormula();
|
|
// 根据类型和省调查询公式
|
|
// 根据类型和省调查询公式
|
|
try {
|
|
try {
|
|
- calculationFormula = jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(CalculationFormula.class), electricType, province, formulaType,stationCode);
|
|
|
|
|
|
+ calculationFormula = jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(CalculationFormula.class), electricType, province, formulaType, stationCode);
|
|
return calculationFormula;
|
|
return calculationFormula;
|
|
} catch (EmptyResultDataAccessException e) {
|
|
} catch (EmptyResultDataAccessException e) {
|
|
// 如果根据场站编码没查到,则在根据省调和场站类型是All的查
|
|
// 如果根据场站编码没查到,则在根据省调和场站类型是All的查
|
|
@@ -308,10 +309,10 @@ public class CalculationFormulaRepositoryImpl implements CalculationFormulaRepos
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public CalculationFormula findAssessmentByTypeAndProvince(String type, String formulaType, String province, String electricType,String stationCode) {
|
|
|
|
|
|
+ public CalculationFormula findAssessmentByTypeAndProvince(String type, String formulaType, String province, String electricType, String stationCode) {
|
|
|
|
|
|
electricType = "%" + electricType + "%";
|
|
electricType = "%" + electricType + "%";
|
|
- if(stationCode!=null && !"".equals(stationCode)){
|
|
|
|
|
|
+ if (stationCode != null && !"".equals(stationCode)) {
|
|
stationCode = "%" + stationCode + "%";
|
|
stationCode = "%" + stationCode + "%";
|
|
}
|
|
}
|
|
String sql = "";
|
|
String sql = "";
|
|
@@ -321,13 +322,13 @@ public class CalculationFormulaRepositoryImpl implements CalculationFormulaRepos
|
|
sql = "SELECT * from t_calculation_formula where state = '1' and ELECTRIC_TYPE like ? and PROVINCE = ? and TYPE = ? and STATION_CODE like ? limit 1";
|
|
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)) {
|
|
} 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";
|
|
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{
|
|
|
|
|
|
+ } else {
|
|
log.error(CalculateResult.MSG_FORMULA_TYPE_ERROR);
|
|
log.error(CalculateResult.MSG_FORMULA_TYPE_ERROR);
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
// 根据类型和省调查询公式
|
|
// 根据类型和省调查询公式
|
|
try {
|
|
try {
|
|
- CalculationFormula calculationFormula = jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(CalculationFormula.class), electricType, province, formulaType,stationCode);
|
|
|
|
|
|
+ CalculationFormula calculationFormula = jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(CalculationFormula.class), electricType, province, formulaType, stationCode);
|
|
return calculationFormula;
|
|
return calculationFormula;
|
|
} catch (EmptyResultDataAccessException e) {
|
|
} catch (EmptyResultDataAccessException e) {
|
|
// 如果根据场站编码没查到,则在根据省调和场站类型是All的查
|
|
// 如果根据场站编码没查到,则在根据省调和场站类型是All的查
|
|
@@ -359,10 +360,10 @@ public class CalculationFormulaRepositoryImpl implements CalculationFormulaRepos
|
|
String path;
|
|
String path;
|
|
// 获取初始化公式表sql
|
|
// 获取初始化公式表sql
|
|
// 如果是金仓数据库
|
|
// 如果是金仓数据库
|
|
- if(CalculateResult.DB_KINGBASE.equals(dbType)){
|
|
|
|
|
|
+ if (CalculateResult.DB_KINGBASE.equals(dbType)) {
|
|
path = "sql/t_calculation_formula_king_base.sql";
|
|
path = "sql/t_calculation_formula_king_base.sql";
|
|
- // 如果是mysql
|
|
|
|
- }else {
|
|
|
|
|
|
+ // 如果是mysql
|
|
|
|
+ } else {
|
|
path = "sql/t_calculation_formula.sql";
|
|
path = "sql/t_calculation_formula.sql";
|
|
}
|
|
}
|
|
|
|
|
|
@@ -372,13 +373,15 @@ public class CalculationFormulaRepositoryImpl implements CalculationFormulaRepos
|
|
URL resource = defaultClassLoader.getResource(path);
|
|
URL resource = defaultClassLoader.getResource(path);
|
|
assert resource != null;
|
|
assert resource != null;
|
|
InputStream inputStream = resource.openStream();
|
|
InputStream inputStream = resource.openStream();
|
|
- // 循环将流放到StringBuilder中
|
|
|
|
|
|
+
|
|
|
|
+ // 读取流
|
|
|
|
+ InputStreamReader reader = new InputStreamReader(inputStream, "utf-8");
|
|
StringBuilder builder = new StringBuilder();
|
|
StringBuilder builder = new StringBuilder();
|
|
int len;
|
|
int len;
|
|
- byte[] buf = new byte[1024];
|
|
|
|
- while ((len = inputStream.read(buf)) != -1) {
|
|
|
|
- builder.append(new String(buf, 0, len));
|
|
|
|
|
|
+ while ((len = reader.read()) != -1) {
|
|
|
|
+ builder.append((char) len);
|
|
}
|
|
}
|
|
|
|
+
|
|
// 关闭流
|
|
// 关闭流
|
|
inputStream.close();
|
|
inputStream.close();
|
|
// 执行sql文件
|
|
// 执行sql文件
|