提交 0b4607cc authored 作者: 1239068511@qq.com's avatar 1239068511@qq.com

[数据模型] 修改了ID会被删除的BUG

上级 e0766992
...@@ -7,10 +7,10 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; ...@@ -7,10 +7,10 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
* @author HASEE * @author HASEE
*/ */
@SpringBootApplication @SpringBootApplication
public class AnnualPerformanceIndicatorsApplication { public class DataWareHouseApplication {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(AnnualPerformanceIndicatorsApplication.class, args); SpringApplication.run(DataWareHouseApplication.class, args);
} }
} }
package com.tykj.base.config; package com.tykj.base.config;
import com.tykj.model.create_util.BaseCreateUtil; import com.tykj.model.create_util.BaseTableUtil;
import com.tykj.model.create_util.MysqlCreateTableUtil; import com.tykj.model.create_util.MysqlTableUtil;
import com.tykj.model.create_util.OscarCreateUtil; import com.tykj.model.create_util.OscarTableUtil;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -18,13 +18,13 @@ public class BeanFactory { ...@@ -18,13 +18,13 @@ public class BeanFactory {
private String env; private String env;
@Bean("baseCreateUtil") @Bean("baseCreateUtil")
BaseCreateUtil baseCreateUtil() { BaseTableUtil baseCreateUtil() {
if ("com.mysql.cj.jdbc.Driver".equals(env) || "com.mysql.jdbc.Driver".equals(env)) { if ("com.mysql.cj.jdbc.Driver".equals(env) || "com.mysql.jdbc.Driver".equals(env)) {
return new MysqlCreateTableUtil(); return new MysqlTableUtil();
} }
if ("com.oscar.Driver".equals(env)) { if ("com.oscar.Driver".equals(env)) {
return new OscarCreateUtil(); return new OscarTableUtil();
} }
return new MysqlCreateTableUtil(); return new MysqlTableUtil();
} }
} }
...@@ -12,7 +12,7 @@ import java.util.List; ...@@ -12,7 +12,7 @@ import java.util.List;
* @version V1.0 * @version V1.0
* @data 2021/7/15 10:40 * @data 2021/7/15 10:40
**/ **/
public abstract class BaseCreateUtil { public abstract class BaseTableUtil {
public String createTable(TableVO tableVO) { public String createTable(TableVO tableVO) {
// 1sql-type="text" string 转为text文本,2长度超过会自动转换 // 1sql-type="text" string 转为text文本,2长度超过会自动转换
...@@ -52,4 +52,5 @@ public abstract class BaseCreateUtil { ...@@ -52,4 +52,5 @@ public abstract class BaseCreateUtil {
abstract String addDefaultTime(TableVO tableVO); abstract String addDefaultTime(TableVO tableVO);
} }
package com.tykj.model.create_util; package com.tykj.model.create_util;
import com.tykj.base.result.ApiException;
import com.tykj.model.entity.vo.ColumnVO;
import com.tykj.model.entity.vo.TableVO; import com.tykj.model.entity.vo.TableVO;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
/** /**
* @author huangjiafu * @author huangjiafu
* @version V1.0 * @version V1.0
* @data 2021/7/15 10:43 * @data 2021/7/15 10:43
**/ **/
public class MysqlCreateTableUtil extends BaseCreateUtil { public class MysqlTableUtil extends BaseTableUtil {
@Override @Override
String addGenerator(TableVO tableVO) { String addGenerator(TableVO tableVO) {
......
...@@ -7,7 +7,7 @@ import com.tykj.model.entity.vo.TableVO; ...@@ -7,7 +7,7 @@ import com.tykj.model.entity.vo.TableVO;
* @version V1.0 * @version V1.0
* @data 2021/7/15 10:58 * @data 2021/7/15 10:58
**/ **/
public class OscarCreateUtil extends BaseCreateUtil { public class OscarTableUtil extends BaseTableUtil {
@Override @Override
public String createTable(TableVO tableVO) { public String createTable(TableVO tableVO) {
return super.createTable(tableVO); return super.createTable(tableVO);
......
...@@ -5,8 +5,7 @@ import com.github.wenhao.jpa.PredicateBuilder; ...@@ -5,8 +5,7 @@ import com.github.wenhao.jpa.PredicateBuilder;
import com.github.wenhao.jpa.Specifications; import com.github.wenhao.jpa.Specifications;
import com.tykj.base.consumer.FourComsumer; import com.tykj.base.consumer.FourComsumer;
import com.tykj.base.result.ApiException; import com.tykj.base.result.ApiException;
import com.tykj.base.result.ResultUtil; import com.tykj.model.create_util.BaseTableUtil;
import com.tykj.model.create_util.BaseCreateUtil;
import com.tykj.model.dao.ColumnInfoDao; import com.tykj.model.dao.ColumnInfoDao;
import com.tykj.model.dao.QuoteDao; import com.tykj.model.dao.QuoteDao;
import com.tykj.model.dao.RuleDao; import com.tykj.model.dao.RuleDao;
...@@ -34,7 +33,6 @@ import org.hibernate.type.*; ...@@ -34,7 +33,6 @@ import org.hibernate.type.*;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.http.ResponseEntity;
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.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -43,7 +41,6 @@ import java.text.SimpleDateFormat; ...@@ -43,7 +41,6 @@ import java.text.SimpleDateFormat;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZoneId; import java.time.ZoneId;
import java.util.*; import java.util.*;
import java.util.concurrent.ExecutionException;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -68,7 +65,7 @@ import static java.util.Objects.nonNull; ...@@ -68,7 +65,7 @@ import static java.util.Objects.nonNull;
public class ModelImpl implements ModelService { public class ModelImpl implements ModelService {
@Autowired @Autowired
BaseCreateUtil baseCreateUtil; BaseTableUtil baseCreateUtil;
@Autowired @Autowired
private TableInfoDao tableInfoDao; private TableInfoDao tableInfoDao;
...@@ -409,10 +406,10 @@ public class ModelImpl implements ModelService { ...@@ -409,10 +406,10 @@ public class ModelImpl implements ModelService {
tableInfo.setDescription(tableVO.getDescription()); tableInfo.setDescription(tableVO.getDescription());
tableInfo.setModelTitle(tableVO.getModelTitle()); tableInfo.setModelTitle(tableVO.getModelTitle());
List<ColumnInfo> originalColumnInfos = columnInfoDao.findAllByDbId(dbId); List<ColumnInfo> originalColumnInfos = columnInfoDao.findAllByDbId(dbId);
//新的字段信息 //新的字段信息
List<ColumnInfo> currentColumnInfos = tableVO.getDataList().stream() List<ColumnInfo> currentColumnInfos = tableVO.getDataList().stream()
.filter(columnVO -> !columnVO.getFieldName().toUpperCase(Locale.ROOT).equals("ID"))
.map(columnVO -> columnInfo(tableInfo.getId(), tableInfo.getModelName(), columnVO)) .map(columnVO -> columnInfo(tableInfo.getId(), tableInfo.getModelName(), columnVO))
.collect(Collectors.toList()); .collect(Collectors.toList());
...@@ -425,15 +422,8 @@ public class ModelImpl implements ModelService { ...@@ -425,15 +422,8 @@ public class ModelImpl implements ModelService {
} catch (Exception exception) { } catch (Exception exception) {
//todo //todo
exception.printStackTrace(); exception.printStackTrace();
throw new ApiException("出错"); throw new ApiException("SQL执行出错");
// if (exception instanceof OSQLException) {
// String error = exception.getMessage();
// error.substring(error.lastIndexOf(":"));
// return ResultUtil.failed("已有数据类型不能转换"+error);
// }
// if (exception instanceof SQLSyntaxErrorException) {
// return ResultUtil.failed("sql语法错误"+ exception.getMessage());
// }
} }
} }
...@@ -518,7 +508,7 @@ public class ModelImpl implements ModelService { ...@@ -518,7 +508,7 @@ public class ModelImpl implements ModelService {
} }
//遍历获取删除列的情况 //遍历获取删除列的情况
for (ColumnInfo originColumnInfo : origin) { for (ColumnInfo originColumnInfo : origin) {
if (!"id".equals(originColumnInfo.getFieldName())) { if (!"ID".equals(originColumnInfo.getFieldName().toUpperCase(Locale.ROOT))) {
boolean noneMatch = current.stream() boolean noneMatch = current.stream()
.noneMatch(columnInfo1 -> Objects.equals(originColumnInfo.getId(), columnInfo1.getId())); .noneMatch(columnInfo1 -> Objects.equals(originColumnInfo.getId(), columnInfo1.getId()));
if (noneMatch) { if (noneMatch) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论