|
@@ -1,16 +1,22 @@
|
|
package com.syjy.calculate.repository.repositoryImpl;
|
|
package com.syjy.calculate.repository.repositoryImpl;
|
|
|
|
|
|
|
|
+import com.syjy.calculate.config.StarterProperties;
|
|
import com.syjy.calculate.entity.CalculationFormula;
|
|
import com.syjy.calculate.entity.CalculationFormula;
|
|
import com.syjy.calculate.repository.CalculationFormulaRepository;
|
|
import com.syjy.calculate.repository.CalculationFormulaRepository;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.dao.DataAccessException;
|
|
import org.springframework.dao.DataAccessException;
|
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
|
+import org.springframework.jdbc.core.ResultSetExtractor;
|
|
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;
|
|
|
|
+import java.sql.ResultSet;
|
|
|
|
+import java.sql.SQLException;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
@@ -18,6 +24,8 @@ import java.util.List;
|
|
@Slf4j
|
|
@Slf4j
|
|
public class CalculationFormulaRepositoryImpl implements CalculationFormulaRepository {
|
|
public class CalculationFormulaRepositoryImpl implements CalculationFormulaRepository {
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ StarterProperties properties;
|
|
@Resource
|
|
@Resource
|
|
public JdbcTemplate jdbcTemplate;
|
|
public JdbcTemplate jdbcTemplate;
|
|
|
|
|
|
@@ -26,6 +34,22 @@ public class CalculationFormulaRepositoryImpl implements CalculationFormulaRepos
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
public void createTable() {
|
|
public void createTable() {
|
|
|
|
+ String config = properties.getDropTableFlag();
|
|
|
|
+ // 如果不删除表,通过页面更改
|
|
|
|
+ if ("false".equals(config)) {
|
|
|
|
+ // 判断表是否存在
|
|
|
|
+ String checkSql = "SHOW TABLES LIKE 't_calculation_formula'";
|
|
|
|
+ Boolean created = jdbcTemplate.query(checkSql, null, null, new ResultSetExtractor<Boolean>() {
|
|
|
|
+ @Override
|
|
|
|
+ public Boolean extractData(ResultSet rs) throws SQLException, DataAccessException {
|
|
|
|
+ return rs.next();
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ // 如果表存在,不对表做任何操作
|
|
|
|
+ if (created) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
try {
|
|
try {
|
|
// 获取初始化公式表sql
|
|
// 获取初始化公式表sql
|
|
String path = "sql/t_calculation_formula.sql";
|
|
String path = "sql/t_calculation_formula.sql";
|
|
@@ -46,6 +70,7 @@ public class CalculationFormulaRepositoryImpl implements CalculationFormulaRepos
|
|
inputStream.close();
|
|
inputStream.close();
|
|
// 执行sql文件
|
|
// 执行sql文件
|
|
jdbcTemplate.execute(builder.toString());
|
|
jdbcTemplate.execute(builder.toString());
|
|
|
|
+
|
|
} catch (DataAccessException e) {
|
|
} catch (DataAccessException e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
log.info("删除/创建表错误:" + e.toString());
|
|
log.info("删除/创建表错误:" + e.toString());
|
|
@@ -58,20 +83,21 @@ public class CalculationFormulaRepositoryImpl implements CalculationFormulaRepos
|
|
|
|
|
|
/**
|
|
/**
|
|
* 查询公式数据
|
|
* 查询公式数据
|
|
- * @param type 类型
|
|
|
|
|
|
+ *
|
|
|
|
+ * @param type 类型
|
|
* @param provinceEnum
|
|
* @param provinceEnum
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public List<CalculationFormula> findByTypeAndProvince(String type,String provinceEnum) {
|
|
|
|
|
|
+ public List<CalculationFormula> findByTypeAndProvince(String type, String provinceEnum) {
|
|
// 模糊查询参数
|
|
// 模糊查询参数
|
|
- provinceEnum = "%"+provinceEnum+";%";
|
|
|
|
|
|
+ provinceEnum = "%" + provinceEnum + ";%";
|
|
// 查询sql
|
|
// 查询sql
|
|
String sql = "SELECT * from t_calculation_formula where TYPE = ? and PROVINCE_ENUM like ? ";
|
|
String sql = "SELECT * from t_calculation_formula where TYPE = ? and PROVINCE_ENUM like ? ";
|
|
// 根据类型和省调查询公式
|
|
// 根据类型和省调查询公式
|
|
List<CalculationFormula> calculationFormulaList = new ArrayList<>();
|
|
List<CalculationFormula> calculationFormulaList = new ArrayList<>();
|
|
try {
|
|
try {
|
|
- calculationFormulaList = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(CalculationFormula.class), type ,provinceEnum);
|
|
|
|
|
|
+ calculationFormulaList = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(CalculationFormula.class), type, provinceEnum);
|
|
} catch (DataAccessException e) {
|
|
} catch (DataAccessException e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|