提交 dbbbf9cc authored 作者: ww1xhqc's avatar ww1xhqc

[数据模型] 修改model的bug。

上级 ebc68b1e
...@@ -111,36 +111,30 @@ ...@@ -111,36 +111,30 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId> <artifactId>spring-boot-starter-cache</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>
<resources> <!-- <resources>-->
<resource> <!-- <resource>-->
<directory>src/main/java</directory> <!-- <directory>src/main/java</directory>-->
<includes> <!-- <includes>-->
<include>**/*</include> <!-- <include>**/*</include>-->
</includes> <!-- </includes>-->
<excludes> <!-- <excludes>-->
<exclude>**/.svn/*</exclude> <!-- <exclude>**/.svn/*</exclude>-->
</excludes> <!-- </excludes>-->
<filtering>false</filtering> <!-- <filtering>false</filtering>-->
</resource> <!-- </resource>-->
<resource> <!-- <resource>-->
<directory>${project.basedir}/src/main/resources</directory> <!-- <directory>${project.basedir}/src/main/resources</directory>-->
<targetPath>META-INF/resources/</targetPath> <!-- <targetPath>META-INF/resources/</targetPath>-->
</resource> <!-- </resource>-->
</resources> <!-- </resources>-->
<plugins> <plugins>
<!-- <plugin>--> <plugin>
<!-- <groupId>org.springframework.boot</groupId>--> <groupId>org.springframework.boot</groupId>
<!-- <artifactId>spring-boot-maven-plugin</artifactId>--> <artifactId>spring-boot-maven-plugin</artifactId>
<!-- </plugin>--> </plugin>
<plugin> <plugin>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
......
...@@ -4,6 +4,8 @@ package com.tykj.workflowcore.model_layer.dao; ...@@ -4,6 +4,8 @@ package com.tykj.workflowcore.model_layer.dao;
import com.tykj.workflowcore.model_layer.entity.ColumnInfo; import com.tykj.workflowcore.model_layer.entity.ColumnInfo;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.transaction.annotation.Transactional;
import java.util.List; import java.util.List;
...@@ -21,4 +23,12 @@ public interface ColumnInfoDao extends JpaRepository<ColumnInfo, Integer>, JpaSp ...@@ -21,4 +23,12 @@ public interface ColumnInfoDao extends JpaRepository<ColumnInfo, Integer>, JpaSp
* @return * @return
*/ */
List<ColumnInfo> findAllByDbId(int id); List<ColumnInfo> findAllByDbId(int id);
/**
* 根据dbID删除
* @param id
*/
@Transactional(rollbackFor = Exception.class)
@Modifying
void deleteAllByDbId(Integer id);
} }
...@@ -4,6 +4,10 @@ package com.tykj.workflowcore.model_layer.dao; ...@@ -4,6 +4,10 @@ package com.tykj.workflowcore.model_layer.dao;
import com.tykj.workflowcore.model_layer.entity.TableInfo; import com.tykj.workflowcore.model_layer.entity.TableInfo;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/** /**
* @ClassName TableInfoDao * @ClassName TableInfoDao
...@@ -19,4 +23,14 @@ public interface TableInfoDao extends JpaRepository<TableInfo, Integer>, JpaSpec ...@@ -19,4 +23,14 @@ public interface TableInfoDao extends JpaRepository<TableInfo, Integer>, JpaSpec
* @return * @return
*/ */
TableInfo findByModelName(String name); TableInfo findByModelName(String name);
/**
* 删除modelType是0的数据
* @param type
* @return
*/
@Transactional(rollbackFor = Exception.class)
@Modifying
List<TableInfo> deleteAllByModelType(Integer type);
} }
...@@ -25,8 +25,6 @@ import java.io.Serializable; ...@@ -25,8 +25,6 @@ import java.io.Serializable;
@Data @Data
@NoArgsConstructor @NoArgsConstructor
@Entity @Entity
@SQLDelete(sql = "update column_info set deleted = 1 where id = ?")
@Where(clause = "deleted = 0")
public class ColumnInfo extends BaseEntity { public class ColumnInfo extends BaseEntity {
/** /**
......
...@@ -48,7 +48,7 @@ public class AggregationImpl implements AggregationService { ...@@ -48,7 +48,7 @@ public class AggregationImpl implements AggregationService {
SessionUtil sessionUtil; SessionUtil sessionUtil;
@Override @Override
@Transactional @Transactional(rollbackOn = Exception.class)
public void addAggregation(AggregationVO aggregationVO) { public void addAggregation(AggregationVO aggregationVO) {
Document mainTableDocument; Document mainTableDocument;
//获取主表XML //获取主表XML
......
...@@ -11,7 +11,7 @@ import com.tykj.workflowcore.model_layer.entity.vo.*; ...@@ -11,7 +11,7 @@ import com.tykj.workflowcore.model_layer.entity.vo.*;
import com.tykj.workflowcore.model_layer.entity.*; import com.tykj.workflowcore.model_layer.entity.*;
import com.tykj.workflowcore.model_layer.myEnum.ModelType; import com.tykj.workflowcore.model_layer.myEnum.ModelType;
import com.tykj.workflowcore.model_layer.service.ModelService; import com.tykj.workflowcore.model_layer.service.ModelService;
import com.tykj.workflowcore.model_layer.utils.CreateTableUtil;
import com.tykj.workflowcore.model_layer.utils.SessionUtil; import com.tykj.workflowcore.model_layer.utils.SessionUtil;
import com.tykj.workflowcore.model_layer.utils.SqlUtil; import com.tykj.workflowcore.model_layer.utils.SqlUtil;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
...@@ -268,6 +268,8 @@ public class ModelImpl implements ModelService { ...@@ -268,6 +268,8 @@ public class ModelImpl implements ModelService {
*/ */
@Override @Override
public void swaggerScan(List<Class<?>> classList) { public void swaggerScan(List<Class<?>> classList) {
/* 扫描前先删除原数据*/
delTableAndColumnInfo();
for (Class<?> aClass : classList) { for (Class<?> aClass : classList) {
//不扫描自己 //不扫描自己
TableInfo tableInfo = new TableInfo(); TableInfo tableInfo = new TableInfo();
...@@ -279,12 +281,11 @@ public class ModelImpl implements ModelService { ...@@ -279,12 +281,11 @@ public class ModelImpl implements ModelService {
if (aClass.isAnnotationPresent(Table.class)) { if (aClass.isAnnotationPresent(Table.class)) {
Table table = aClass.getAnnotation(Table.class); Table table = aClass.getAnnotation(Table.class);
if (!"".equals(table.name()) && table.name() != null) { if (!"".equals(table.name()) && table.name() != null) {
realName=table.name(); realName = table.name();
} }
} } else {
else {
String className = getClassName(aClass.toString()); String className = getClassName(aClass.toString());
realName=className; realName = className;
} }
tableVO.setModelName(realName); tableVO.setModelName(realName);
//获得类中文描述 //获得类中文描述
...@@ -308,7 +309,7 @@ public class ModelImpl implements ModelService { ...@@ -308,7 +309,7 @@ public class ModelImpl implements ModelService {
List<ColumnVO> list = new ArrayList<>(); List<ColumnVO> list = new ArrayList<>();
for (Field declaredField : declaredFields) { for (Field declaredField : declaredFields) {
ColumnVO columnVO = new ColumnVO(); ColumnVO columnVO = new ColumnVO();
if (declaredField.isAnnotationPresent(Transient.class)){ if (declaredField.isAnnotationPresent(Transient.class)) {
continue; continue;
} }
//获得类型 //获得类型
...@@ -604,4 +605,15 @@ public class ModelImpl implements ModelService { ...@@ -604,4 +605,15 @@ public class ModelImpl implements ModelService {
tableAndColumnInfoVO.setColumnInfos(allColumnInfos); tableAndColumnInfoVO.setColumnInfos(allColumnInfos);
return tableAndColumnInfoVO; return tableAndColumnInfoVO;
} }
public void delTableAndColumnInfo() {
/* 先删除上次扫描的基础类型*/
List<TableInfo> tableInfos = tableInfoDao.deleteAllByModelType(ModelType.BASICS);
for (TableInfo tableInfo : tableInfos) {
/*删除columnInfo*/
columnInfoDao.deleteAllByDbId(tableInfo.getId());
}
}
} }
...@@ -2,7 +2,7 @@ spring: ...@@ -2,7 +2,7 @@ spring:
datasource: datasource:
username: root username: root
password: Huang123+ password: Huang123+
url: jdbc:mysql://47.106.142.73:3306/www3?useSSL=false&serverTimezone=GMT%2b8&characterEncoding=utf-8&nullCatalogMeansCurrent=true url: jdbc:mysql://47.106.142.73:3306/www_hxh?useSSL=false&serverTimezone=GMT%2b8&characterEncoding=utf-8&nullCatalogMeansCurrent=true
driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.cj.jdbc.Driver
jpa: jpa:
show-sql: true show-sql: true
......
...@@ -3,8 +3,10 @@ package com.tykj.workflowcore; ...@@ -3,8 +3,10 @@ package com.tykj.workflowcore;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.tykj.workflowcore.model_layer.controller.ModelController; import com.tykj.workflowcore.model_layer.controller.ModelController;
import com.tykj.workflowcore.model_layer.dao.ColumnInfoDao;
import com.tykj.workflowcore.model_layer.dao.TableInfoDao; import com.tykj.workflowcore.model_layer.dao.TableInfoDao;
import com.tykj.workflowcore.model_layer.dao.TableInfoExDao; import com.tykj.workflowcore.model_layer.dao.TableInfoExDao;
import com.tykj.workflowcore.model_layer.entity.ColumnInfo;
import com.tykj.workflowcore.model_layer.entity.TableInfo; import com.tykj.workflowcore.model_layer.entity.TableInfo;
import com.tykj.workflowcore.model_layer.entity.vo.TableAndColumnInfoVO; import com.tykj.workflowcore.model_layer.entity.vo.TableAndColumnInfoVO;
import com.tykj.workflowcore.model_layer.myEnum.ModelType; import com.tykj.workflowcore.model_layer.myEnum.ModelType;
...@@ -88,6 +90,9 @@ class WorkflowCoreApplicationTests { ...@@ -88,6 +90,9 @@ class WorkflowCoreApplicationTests {
@Autowired @Autowired
TableInfoExDao tableInfoExDao; TableInfoExDao tableInfoExDao;
@Autowired
ColumnInfoDao columnInfoDao;
@Before("") @Before("")
public void setUp() { public void setUp() {
mockMvc = MockMvcBuilders.standaloneSetup(modelController).build(); mockMvc = MockMvcBuilders.standaloneSetup(modelController).build();
...@@ -489,4 +494,14 @@ class WorkflowCoreApplicationTests { ...@@ -489,4 +494,14 @@ class WorkflowCoreApplicationTests {
// System.out.println(jsonExample); // System.out.println(jsonExample);
StringUtils.hasLength(xml); StringUtils.hasLength(xml);
} }
@Test
public void testDelete(){
List<TableInfo> tableInfos = tableInfoDao.deleteAllByModelType(0);
for (TableInfo tableInfo : tableInfos) {
System.out.println(tableInfo.getId());
columnInfoDao.deleteAllByDbId(tableInfo.getId());
}
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论