Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
D
dataDeclaration
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
黄夏豪
dataDeclaration
Commits
53857fb7
提交
53857fb7
authored
5月 20, 2021
作者:
黄夏豪
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[数据模块] 增加了版本
上级
bfb8afcf
隐藏空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
81 行增加
和
29 行删除
+81
-29
VersionController.java
...va/com/tykj/model_layer/controller/VersionController.java
+13
-3
VersionDao.java
src/main/java/com/tykj/model_layer/dao/VersionDao.java
+4
-0
Version.java
src/main/java/com/tykj/model_layer/entity/Version.java
+0
-2
ModelService.java
src/main/java/com/tykj/model_layer/service/ModelService.java
+1
-3
VersionService.java
...ain/java/com/tykj/model_layer/service/VersionService.java
+6
-0
ModelImpl.java
...ain/java/com/tykj/model_layer/service/impl/ModelImpl.java
+19
-7
VersionServiceImpl.java
...com/tykj/model_layer/service/impl/VersionServiceImpl.java
+36
-12
ClassTypeLength.java
...main/java/com/tykj/model_layer/utils/ClassTypeLength.java
+1
-1
CreateTableUtil.java
...main/java/com/tykj/model_layer/utils/CreateTableUtil.java
+1
-1
没有找到文件。
src/main/java/com/tykj/model_layer/controller/VersionController.java
浏览文件 @
53857fb7
...
...
@@ -6,6 +6,7 @@ import com.tykj.model_layer.entity.Version;
import
com.tykj.model_layer.entity.vo.VersionVO
;
import
com.tykj.model_layer.service.VersionService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -22,20 +23,29 @@ public class VersionController {
@Autowired
private
VersionService
versionService
;
@ApiOperation
(
value
=
"删除版本"
)
@DeleteMapping
(
"/delVersion"
)
public
ResponseEntity
delVersion
(
Integer
id
){
versionService
.
delVersion
(
id
);
return
ResultUtil
.
success
(
"删除成功!"
);
}
@ApiOperation
(
value
=
"新增版本"
)
@PostMapping
(
"/addVersion"
)
public
ResponseEntity
addVersion
(
@RequestBody
VersionVO
versionVO
){
return
ResultUtil
.
success
(
versionService
.
addVersion
(
versionVO
),
"保存成功!"
);
}
@RequestMapping
(
"/goBack"
)
public
ResponseEntity
goBack
(
Integer
integer
){
@ApiOperation
(
value
=
"回滚版本"
)
@PostMapping
(
"/goBack"
)
public
ResponseEntity
goBack
(
Integer
id
){
versionService
.
goback
(
id
);
return
ResultUtil
.
success
(
"还原成功了"
);
}
return
ResultUtil
.
success
(
""
);
@ApiOperation
(
value
=
"根据DBId查询版本"
)
@GetMapping
(
"/getVersionList"
)
public
ResponseEntity
getVersionList
(
Integer
dbId
){
return
ResultUtil
.
success
(
versionService
.
findVersionByDbId
(
dbId
),
"查询成功"
);
}
}
src/main/java/com/tykj/model_layer/dao/VersionDao.java
浏览文件 @
53857fb7
...
...
@@ -4,10 +4,14 @@ import com.tykj.model_layer.entity.Version;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.JpaSpecificationExecutor
;
import
java.util.List
;
/**
* @Description TODO
* @Author WWW
* @Date 2021/5/19 13:21
*/
public
interface
VersionDao
extends
JpaRepository
<
Version
,
Integer
>,
JpaSpecificationExecutor
<
Version
>
{
List
<
Version
>
findAllByDbId
(
Integer
dbId
);
}
src/main/java/com/tykj/model_layer/entity/Version.java
浏览文件 @
53857fb7
...
...
@@ -30,11 +30,9 @@ public class Version extends BaseEntity {
@ApiModelProperty
(
"描述"
)
private
String
versionDesc
;
@Lob
@ApiModelProperty
(
"描述"
)
private
String
ids
;
@Lob
@ApiModelProperty
(
"对应数据表"
)
private
Integer
dbId
;
...
...
src/main/java/com/tykj/model_layer/service/ModelService.java
浏览文件 @
53857fb7
...
...
@@ -66,9 +66,7 @@ public interface ModelService {
* @param mapList
* @return
*/
public
int
putValueByEntityNameList
(
List
<
Map
<
String
,
Object
>>
mapList
);
int
putValueByEntityNameList
(
List
<
Map
<
String
,
Object
>>
mapList
);
/**
* 根据表名查询所有
...
...
src/main/java/com/tykj/model_layer/service/VersionService.java
浏览文件 @
53857fb7
...
...
@@ -3,6 +3,8 @@ package com.tykj.model_layer.service;
import
com.tykj.model_layer.entity.Version
;
import
com.tykj.model_layer.entity.vo.VersionVO
;
import
java.util.List
;
/**
* @Description TODO
* @Author WWW
...
...
@@ -23,4 +25,8 @@ public interface VersionService {
void
delVersion
(
Integer
id
);
void
goback
(
Integer
id
);
List
<
Version
>
findVersionByDbId
(
Integer
dbId
);
}
src/main/java/com/tykj/model_layer/service/impl/ModelImpl.java
浏览文件 @
53857fb7
...
...
@@ -224,13 +224,13 @@ public class ModelImpl implements ModelService {
Object
values
=
map
.
get
(
tableName
);
if
(
values
instanceof
Map
)
{
//插入数据
insertValue
(
tableInfo
.
getModelName
(),
(
Map
)
values
,
session
);
insertValue
(
tableInfo
.
getModelName
(),
(
Map
)
values
,
session
,
true
,
false
);
}
else
{
//循环插入数据
List
valuesList
=
(
List
)
values
;
for
(
int
i
=
0
;
i
<
valuesList
.
size
();
i
++)
{
insertValue
(
tableInfo
.
getModelName
(),
(
Map
)
valuesList
.
get
(
i
),
session
);
insertValue
(
tableInfo
.
getModelName
(),
(
Map
)
valuesList
.
get
(
i
),
session
,
true
,
false
);
}
}
session
.
getTransaction
().
commit
();
...
...
@@ -274,12 +274,12 @@ public class ModelImpl implements ModelService {
Object
values
=
map
.
get
(
tableName
);
if
(
values
instanceof
Map
)
{
//插入数据
insertValue
(
tableInfo
.
getModelName
(),
(
Map
)
values
,
session
);
insertValue
(
tableInfo
.
getModelName
(),
(
Map
)
values
,
session
,
true
,
false
);
}
else
{
//循环插入数据
List
valuesList
=
(
List
)
values
;
for
(
int
i
=
0
;
i
<
valuesList
.
size
();
i
++)
{
insertValue
(
tableInfo
.
getModelName
(),
(
Map
)
valuesList
.
get
(
i
),
session
);
insertValue
(
tableInfo
.
getModelName
(),
(
Map
)
valuesList
.
get
(
i
),
session
,
true
,
false
);
}
}
...
...
@@ -293,6 +293,7 @@ public class ModelImpl implements ModelService {
return
0
;
}
/**
* @param tableName
* @param map
...
...
@@ -301,7 +302,7 @@ public class ModelImpl implements ModelService {
* @Description 新增参数的方法
* @Date 16:17 2021/3/5
**/
public
void
insertValue
(
String
tableName
,
Map
map
,
SessionImpl
session
)
{
public
void
insertValue
(
String
tableName
,
Map
map
,
SessionImpl
session
,
boolean
back
,
boolean
saveOrSaveAndUpdate
)
{
EntityPersister
entityPersister
=
session
.
getEntityPersister
(
tableName
,
map
);
Type
[]
propertyTypes
=
entityPersister
.
getPropertyTypes
();
String
[]
propertyNames
=
entityPersister
.
getEntityPersister
().
getPropertyNames
();
...
...
@@ -335,8 +336,19 @@ public class ModelImpl implements ModelService {
}
HashMap
hashMap
=
new
HashMap
();
hashMap
.
putAll
(
map
);
session
.
saveOrUpdate
(
tableName
,
map
);
session
.
saveOrUpdate
(
tableName
+
"_back"
,
hashMap
);
if
(
saveOrSaveAndUpdate
){
session
.
save
(
tableName
,
map
);
}
else
{
session
.
saveOrUpdate
(
tableName
,
map
);
}
if
(
back
){
if
(
saveOrSaveAndUpdate
){
session
.
save
(
tableName
+
"_back"
,
map
);
}
else
{
session
.
saveOrUpdate
(
tableName
+
"_back"
,
map
);
}
}
}
...
...
src/main/java/com/tykj/model_layer/service/impl/VersionServiceImpl.java
浏览文件 @
53857fb7
...
...
@@ -15,12 +15,12 @@ import com.tykj.model_layer.utils.SessionUtil;
import
org.apache.commons.lang3.StringUtils
;
import
org.checkerframework.checker.units.qual.A
;
import
org.hibernate.Session
;
import
org.hibernate.internal.SessionImpl
;
import
org.hibernate.query.Query
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
import
java.util.Objects
;
import
java.util.Optional
;
import
java.util.*
;
import
java.util.stream.Collectors
;
/**
...
...
@@ -42,20 +42,29 @@ public class VersionServiceImpl implements VersionService {
@Autowired
TableInfoDao
tableInfoDao
;
@Autowired
ModelImpl
model
;
@Override
public
Version
addVersion
(
VersionVO
versionVO
)
{
Version
version
=
new
Version
();
version
.
setVersionId
(
versionVO
.
getVersionId
());
version
.
setDbId
(
versionVO
.
getDbId
());
version
.
setVersionDesc
(
versionVO
.
getVersionDesc
());
List
<
Integer
>
collect
=
columnInfoDao
.
findAllByDbId
(
versionVO
.
getDbId
()).
stream
()
.
map
(
ColumnInfo:
:
getId
)
.
collect
(
Collectors
.
toList
());
TableInfo
tableInfo
=
tableInfoDao
.
getOne
(
version
.
getDbId
());
List
<
Map
<
String
,
Object
>>
maps
=
model
.
complexQuery
(
tableInfo
.
getModelName
(),
null
,
null
);
List
<
Integer
>
collect
=
new
ArrayList
<>();
for
(
Map
<
String
,
Object
>
map
:
maps
)
{
collect
.
add
((
Integer
)
map
.
get
(
"id"
));
}
version
.
setIds
(
JSONArray
.
toJSONString
(
collect
));
return
versionDao
.
save
(
version
);
}
public
List
<
Version
>
findVersionByDbId
(
Integer
dbId
){
return
versionDao
.
findAllByDbId
(
dbId
);
}
@Override
public
void
delVersion
(
Integer
id
)
{
versionDao
.
deleteById
(
id
);
...
...
@@ -77,13 +86,28 @@ public class VersionServiceImpl implements VersionService {
Session
session
=
sessionUtil
.
getSession
();
session
.
getTransaction
().
begin
();
StringBuilder
result
=
new
StringBuilder
(
"delete "
);
result
.
append
(
"entity "
);
result
.
append
(
" from "
).
append
(
tableInfo
.
getModelName
()).
append
(
" entity "
);
result
.
append
(
"where entity.id in "
+
version
.
getIds
());
StringBuilder
delete_Sql
=
new
StringBuilder
(
"delete "
);
delete_Sql
.
append
(
" from "
).
append
(
tableInfo
.
getModelName
());
delete_Sql
.
append
(
" where id in ("
+
version
.
getIds
().
substring
(
1
,
version
.
getIds
().
length
()-
1
)+
")"
);
Query
deleteQuery
=
session
.
createQuery
(
delete_Sql
.
toString
());
deleteQuery
.
executeUpdate
();
StringBuilder
selectSql
=
new
StringBuilder
(
"select "
);
selectSql
.
append
(
"entity "
);
selectSql
.
append
(
" from "
).
append
(
tableInfo
.
getModelName
()+
"_back"
).
append
(
" entity "
);
delete_Sql
.
append
(
" where id in ("
+
version
.
getIds
().
substring
(
1
,
version
.
getIds
().
length
()-
1
)+
")"
);
session
.
createQuery
(
result
.
toString
());
Query
query
=
session
.
createQuery
(
selectSql
.
toString
());
List
<
Map
<
String
,
Object
>>
list
=
query
.
list
();
for
(
Map
<
String
,
Object
>
map
:
list
)
{
map
.
remove
(
"$type$"
);
HashMap
hashMap
=
new
HashMap
();
hashMap
.
putAll
(
map
);
model
.
insertValue
(
tableInfo
.
getModelName
(),
hashMap
,(
SessionImpl
)
session
,
false
,
true
);
}
System
.
out
.
println
(
"1"
);
session
.
getTransaction
().
commit
();
session
.
close
();
...
...
src/main/java/com/tykj/model_layer/utils/ClassTypeLength.java
浏览文件 @
53857fb7
...
...
@@ -17,7 +17,7 @@ public class ClassTypeLength {
int
length
;
if
(
STRING
.
equals
(
genericType
))
{
length
=
2
55
;
length
=
1
55
;
}
else
if
(
Integer
.
equals
(
genericType
))
{
length
=
11
;
}
else
if
(
Double
.
equals
(
genericType
))
{
...
...
src/main/java/com/tykj/model_layer/utils/CreateTableUtil.java
浏览文件 @
53857fb7
...
...
@@ -59,7 +59,7 @@ public class CreateTableUtil {
" <class entity-name=\""
+
tableVO
.
getModelName
()
+
"\" table=\""
+
tableVO
.
getModelName
()
+
"\">\n"
;
xmlMapping
+=
" <id name=\"id\" type=\"java.lang.Integer\" length=\"11\" unsaved-value=\"null\" >\n"
+
" <generator
class=\"identity
\" />"
+
" <generator
class=\"com.tykj.base.entity.XMQGenerator
\" />"
+
" </id>"
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论