Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
spring-simple-operation
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guokunkun
spring-simple-operation
Commits
b9e304fd
Commit
b9e304fd
authored
Mar 19, 2026
by
kk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
21154-视觉刷数据
parent
14eeb45a
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
410 additions
and
9 deletions
+410
-9
CodeGenerator.java
...ain/java/cn/kk/spring_simple_operation/CodeGenerator.java
+7
-7
BrandRecordTool.java
...cn/kk/spring_simple_operation/entity/BrandRecordTool.java
+4
-0
SqlGenerator.java
...ava/cn/kk/spring_simple_operation/utils/SqlGenerator.java
+244
-0
MyTest.java
src/test/java/cn/kk/spring_simple_operation/MyTest.java
+155
-2
No files found.
src/main/java/cn/kk/spring_simple_operation/CodeGenerator.java
View file @
b9e304fd
...
...
@@ -18,13 +18,13 @@ import java.util.Collections;
*/
public
class
CodeGenerator
{
//
private static final String DB_URL = "jdbc:mysql://120.77.232.73:3306/java_visual?useUnicode=true&characterEncoding=utf8&useSSL=true";
//
private static final String DB_USERNAME = "yswg_it_java";
//private static final String DB_PASSWORD = "Yswg@inv-java241011427
";
private
static
final
String
DB_URL
=
"jdbc:mysql://120.77.232.73:3306/java_visual?useUnicode=true&characterEncoding=utf8&useSSL=true"
;
private
static
final
String
DB_USERNAME
=
"yswg_it_java"
;
private
static
final
String
DB_PASSWORD
=
"Yswg@inv-java256239134
"
;
private
static
final
String
DB_URL
=
"jdbc:mysql://mydb.com:3306/visual_0102?useUnicode=true&characterEncoding=utf8&useSSL=true"
;
private
static
final
String
DB_USERNAME
=
"root"
;
private
static
final
String
DB_PASSWORD
=
"root"
;
//
private static final String DB_URL = "jdbc:mysql://mydb.com:3306/visual_0102?useUnicode=true&characterEncoding=utf8&useSSL=true";
//
private static final String DB_USERNAME = "root";
//
private static final String DB_PASSWORD = "root";
public
static
final
String
DIR
=
System
.
getProperty
(
"user.dir"
);
...
...
@@ -54,7 +54,7 @@ public class CodeGenerator {
.
strategyConfig
(
builder
->
{
builder
// 设置需要生成的表名
.
addInclude
(
"
brand_record_tool
"
)
.
addInclude
(
"
visual_plan_executor_task_record
"
)
//entity策略配置
.
entityBuilder
()
...
...
src/main/java/cn/kk/spring_simple_operation/entity/BrandRecordTool.java
View file @
b9e304fd
package
cn
.
kk
.
spring_simple_operation
.
entity
;
import
cn.kk.spring_simple_operation.utils.Excel
;
import
com.baomidou.mybatisplus.annotation.TableField
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.baomidou.mybatisplus.annotation.TableLogic
;
...
...
@@ -32,6 +33,7 @@ public class BrandRecordTool implements Serializable {
@TableId
(
"id"
)
private
Long
id
;
@Excel
(
name
=
"账号"
)
@ApiModelProperty
(
"账号"
)
@TableField
(
"`account`"
)
private
String
account
;
...
...
@@ -48,6 +50,7 @@ public class BrandRecordTool implements Serializable {
@TableField
(
"is_need_design"
)
private
Integer
isNeedDesign
;
@Excel
(
name
=
"备案品牌"
)
@ApiModelProperty
(
"备案品牌"
)
@TableField
(
"record_brand"
)
private
String
recordBrand
;
...
...
@@ -277,6 +280,7 @@ public class BrandRecordTool implements Serializable {
@TableField
(
"empower_account_us"
)
private
String
empowerAccountUs
;
@Excel
(
name
=
"授权账号"
)
@ApiModelProperty
(
"UK被授权账号"
)
@TableField
(
"empower_account_uk"
)
private
String
empowerAccountUk
;
...
...
src/main/java/cn/kk/spring_simple_operation/utils/SqlGenerator.java
0 → 100644
View file @
b9e304fd
package
cn
.
kk
.
spring_simple_operation
.
utils
;
import
com.baomidou.mybatisplus.annotation.TableField
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
com.baomidou.mybatisplus.core.toolkit.IdWorker
;
import
java.lang.reflect.Field
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Objects
;
/**
* SQL生成器工具类
* 通过反射读取实体类注解,自动生成INSERT语句
*/
public
class
SqlGenerator
{
/**
* 生成INSERT SQL语句
*
* @param entity 实体对象
* @return 完整的INSERT SQL语句
*/
public
static
String
generateInsertSql
(
Object
entity
)
{
Class
<?>
clazz
=
entity
.
getClass
();
// 获取表名
String
tableName
=
getTableName
(
clazz
);
// 获取所有字段信息
List
<
FieldInfo
>
fieldInfos
=
getFieldInfos
(
clazz
);
// 字段名
List
<
String
>
columnNames
=
new
ArrayList
<>();
List
<
Object
>
values
=
new
ArrayList
<>();
for
(
FieldInfo
fieldInfo
:
fieldInfos
)
{
Object
fieldValue
=
getFieldValue
(
entity
,
fieldInfo
.
getField
());
if
(
Objects
.
nonNull
(
fieldValue
))
{
columnNames
.
add
(
fieldInfo
.
getColumnName
());
values
.
add
(
fieldValue
);
}
else
if
(
"id"
.
equals
(
fieldInfo
.
getColumnName
()))
{
columnNames
.
add
(
fieldInfo
.
getColumnName
());
values
.
add
(
IdWorker
.
getId
());
}
}
return
generateSqlWithValues
(
tableName
,
columnNames
,
values
);
}
/**
* 生成UPDATE SQL语句
*
* @param entity 实体对象
* @return 完整的UPDATE SQL语句
*/
public
static
String
generateUpdateSql
(
Object
entity
)
{
Class
<?>
clazz
=
entity
.
getClass
();
// 获取表名
String
tableName
=
getTableName
(
clazz
);
// 获取所有字段信息
List
<
FieldInfo
>
fieldInfos
=
getFieldInfos
(
clazz
);
// 存储id值
Object
idValue
=
null
;
// SET子句的字段和值
List
<
String
>
setClauses
=
new
ArrayList
<>();
for
(
FieldInfo
fieldInfo
:
fieldInfos
)
{
Object
fieldValue
=
getFieldValue
(
entity
,
fieldInfo
.
getField
());
// 判断是否为id字段
if
(
"id"
.
equals
(
fieldInfo
.
getColumnName
()))
{
idValue
=
fieldValue
;
continue
;
}
// 跳过null值字段
if
(
Objects
.
isNull
(
fieldValue
))
{
continue
;
}
setClauses
.
add
(
fieldInfo
.
getColumnName
()
+
" = "
+
formatValue
(
fieldValue
));
}
// 校验id是否存在
if
(
Objects
.
isNull
(
idValue
))
{
throw
new
RuntimeException
(
"UPDATE语句必须指定id值"
);
}
// 构建UPDATE SQL
StringBuilder
sql
=
new
StringBuilder
();
sql
.
append
(
"UPDATE "
).
append
(
tableName
).
append
(
" SET "
);
sql
.
append
(
String
.
join
(
", "
,
setClauses
));
sql
.
append
(
" WHERE id = "
).
append
(
formatValue
(
idValue
));
sql
.
append
(
";\n"
);
return
sql
.
toString
();
}
/**
* 生成带实际值的SQL(用于展示)
*/
private
static
String
generateSqlWithValues
(
String
tableName
,
List
<
String
>
columnNames
,
List
<
Object
>
values
)
{
StringBuilder
sql
=
new
StringBuilder
();
sql
.
append
(
"INSERT INTO "
).
append
(
tableName
).
append
(
"("
);
sql
.
append
(
String
.
join
(
", "
,
columnNames
));
sql
.
append
(
") VALUES ("
);
List
<
String
>
formattedValues
=
new
ArrayList
<>();
for
(
Object
value
:
values
)
{
formattedValues
.
add
(
formatValue
(
value
));
}
sql
.
append
(
String
.
join
(
", "
,
formattedValues
));
sql
.
append
(
");\n"
);
return
sql
.
toString
();
}
/**
* 格式化值为SQL字符串
*/
private
static
String
formatValue
(
Object
value
)
{
if
(
value
==
null
)
{
return
"NULL"
;
}
if
(
value
instanceof
String
)
{
return
"'"
+
value
+
"'"
;
}
return
value
.
toString
();
}
/**
* 获取表名
*/
private
static
String
getTableName
(
Class
<?>
clazz
)
{
TableName
tableName
=
clazz
.
getAnnotation
(
TableName
.
class
);
if
(
tableName
!=
null
)
{
return
tableName
.
value
();
}
// 默认使用类名转下划线
return
camelToUnderline
(
clazz
.
getSimpleName
());
}
/**
* 获取所有字段信息
*/
private
static
List
<
FieldInfo
>
getFieldInfos
(
Class
<?>
clazz
)
{
List
<
FieldInfo
>
fieldInfos
=
new
ArrayList
<>();
Field
[]
fields
=
clazz
.
getDeclaredFields
();
for
(
Field
field
:
fields
)
{
// 跳过静态字段
if
(
java
.
lang
.
reflect
.
Modifier
.
isStatic
(
field
.
getModifiers
()))
{
continue
;
}
String
columnName
=
null
;
// 优先读取 @TableField 注解
TableField
tableField
=
field
.
getAnnotation
(
TableField
.
class
);
if
(
tableField
!=
null
)
{
columnName
=
tableField
.
value
();
}
// 如果没有 @TableField,尝试 @TableId
if
(
columnName
==
null
||
columnName
.
isEmpty
())
{
TableId
tableId
=
field
.
getAnnotation
(
TableId
.
class
);
if
(
tableId
!=
null
)
{
columnName
=
tableId
.
value
();
}
}
//// 如果没有注解,使用字段名转下划线
//if (columnName == null || columnName.isEmpty()) {
// columnName = camelToUnderline(field.getName());
//}
if
(
Objects
.
isNull
(
columnName
))
{
continue
;
}
field
.
setAccessible
(
true
);
fieldInfos
.
add
(
new
FieldInfo
(
field
,
columnName
));
}
return
fieldInfos
;
}
/**
* 获取字段值
*/
private
static
Object
getFieldValue
(
Object
entity
,
Field
field
)
{
try
{
return
field
.
get
(
entity
);
}
catch
(
IllegalAccessException
e
)
{
throw
new
RuntimeException
(
"获取字段值失败: "
+
field
.
getName
(),
e
);
}
}
/**
* 驼峰命名转下划线命名
*/
private
static
String
camelToUnderline
(
String
camel
)
{
StringBuilder
result
=
new
StringBuilder
();
for
(
char
c
:
camel
.
toCharArray
())
{
if
(
Character
.
isUpperCase
(
c
))
{
if
(
result
.
length
()
>
0
)
{
result
.
append
(
"_"
);
}
result
.
append
(
Character
.
toLowerCase
(
c
));
}
else
{
result
.
append
(
c
);
}
}
return
result
.
toString
();
}
/**
* 字段信息内部类
*/
private
static
class
FieldInfo
{
private
final
Field
field
;
private
final
String
columnName
;
public
FieldInfo
(
Field
field
,
String
columnName
)
{
this
.
field
=
field
;
this
.
columnName
=
columnName
;
}
public
Field
getField
()
{
return
field
;
}
public
String
getColumnName
()
{
return
columnName
;
}
}
}
src/test/java/cn/kk/spring_simple_operation/MyTest.java
View file @
b9e304fd
package
cn
.
kk
.
spring_simple_operation
;
import
cn.kk.spring_simple_operation.entity.VisualDesigner
;
import
cn.kk.spring_simple_operation.entity.VisualPlanExecutorTaskRecord
;
import
cn.kk.spring_simple_operation.entity.*
;
import
cn.kk.spring_simple_operation.mapper.*
;
import
cn.kk.spring_simple_operation.model.dto.SkuPeopleNameDto
;
import
cn.kk.spring_simple_operation.model.vo.BrandRecordStatisticsVo
;
...
...
@@ -10,6 +9,7 @@ import cn.kk.spring_simple_operation.model.vo.VideoProductExportVo;
import
cn.kk.spring_simple_operation.utils.CommonUtils
;
import
cn.kk.spring_simple_operation.utils.DateUtils
;
import
cn.kk.spring_simple_operation.utils.ExcelUtil
;
import
cn.kk.spring_simple_operation.utils.SqlGenerator
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
com.google.common.collect.Lists
;
import
org.apache.commons.collections4.CollectionUtils
;
...
...
@@ -51,6 +51,53 @@ public class MyTest {
@Resource
private
VisualDesignerMapper
visualDesignerMapper
;
@Resource
private
VisualVideoPlanMapper
visualVideoPlanMapper
;
@Resource
private
BrandRecordToolMapper
brandRecordToolMapper
;
@Test
public
void
selectNoExecutorData
()
{
List
<
Long
>
planIds
=
visualVideoPlanMapper
.
selectList
(
Wrappers
.<
VisualVideoPlan
>
lambdaQuery
()
.
eq
(
VisualVideoPlan:
:
getExecutorNumber
,
""
)
.
eq
(
VisualVideoPlan:
:
getStatus
,
0
)
.
eq
(
VisualVideoPlan:
:
getCreateId
,
0
)
.
in
(
VisualVideoPlan:
:
getVdtId
,
2
)
.
between
(
VisualVideoPlan:
:
getCreateTime
,
1772467200
,
1772553600
)
.
select
(
VisualVideoPlan:
:
getId
)
).
stream
().
map
(
VisualVideoPlan:
:
getId
).
collect
(
Collectors
.
toList
());
if
(
CollectionUtils
.
isEmpty
(
planIds
))
return
;
List
<
VideoProduct
>
videoProducts
=
videoProductMapper
.
selectList
(
Wrappers
.<
VideoProduct
>
lambdaQuery
()
.
in
(
VideoProduct:
:
getVideoPlanId
,
planIds
)
.
eq
(
VideoProduct:
:
getOptimizeType
,
0
)
.
eq
(
VideoProduct:
:
getCreateId
,
0
)
.
select
(
VideoProduct:
:
getId
,
VideoProduct:
:
getVideoPlanId
)
);
List
<
Long
>
videoProductIds
=
videoProducts
.
stream
().
map
(
VideoProduct:
:
getId
).
collect
(
Collectors
.
toList
());
planIds
=
videoProducts
.
stream
().
map
(
VideoProduct:
:
getVideoPlanId
).
collect
(
Collectors
.
toList
());
try
(
BufferedWriter
writer
=
new
BufferedWriter
(
new
FileWriter
(
"删除视频策划数据.sql"
)))
{
for
(
Long
id
:
planIds
)
{
writer
.
write
(
String
.
format
(
"update visual_video_plan set is_delete = 1, remark = '20260303业务让删除无执行人的策划' where id = %d;\n"
,
id
));
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
try
(
BufferedWriter
writer
=
new
BufferedWriter
(
new
FileWriter
(
"删除视频产品数据.sql"
)))
{
for
(
Long
id
:
videoProductIds
)
{
writer
.
write
(
String
.
format
(
"update video_product set is_delete = 1, video_remark = '20260303业务让删除无执行人的策划' where id = %d;\n"
,
id
));
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
@Test
void
exportVideoProductList
()
{
...
...
@@ -243,4 +290,110 @@ public class MyTest {
});
}
@Test
public
void
syncBrandRecordToolLogoData
()
throws
Exception
{
ExcelUtil
<
BrandRecordTool
>
util
=
new
ExcelUtil
<>(
BrandRecordTool
.
class
);
List
<
BrandRecordTool
>
list
=
util
.
importExcel
(
Files
.
newInputStream
(
new
File
(
"品牌工具logo.xlsx"
).
toPath
()));
Set
<
String
>
setFront
=
new
HashSet
<>();
Set
<
String
>
setBack
=
new
HashSet
<>();
list
.
forEach
(
t
->
{
if
(
setFront
.
contains
(
t
.
getAccount
()
+
"-"
+
t
.
getRecordBrand
()))
{
log
.
error
(
"品牌工具logo重复1:{}-{}"
,
t
.
getAccount
(),
t
.
getRecordBrand
());
}
else
{
setFront
.
add
(
t
.
getAccount
()
+
"-"
+
t
.
getRecordBrand
());
}
if
(
setBack
.
contains
(
t
.
getEmpowerAccountUk
()
+
"-"
+
t
.
getRecordBrand
()))
{
log
.
error
(
"品牌工具logo重复2:{}-{}"
,
t
.
getEmpowerAccountUk
(),
t
.
getRecordBrand
());
}
else
{
setBack
.
add
(
t
.
getEmpowerAccountUk
()
+
"-"
+
t
.
getRecordBrand
());
}
});
Integer
currentTimeSecond
=
DateUtils
.
getCurrentTimeSecond
();
List
<
BrandRecordTool
>
updateList
=
new
ArrayList
<>();
List
<
VisualDesignLog
>
logList
=
new
ArrayList
<>();
for
(
BrandRecordTool
brandRecordTool
:
list
)
{
List
<
BrandRecordTool
>
brandRecordTools
=
brandRecordToolMapper
.
selectList
(
Wrappers
.<
BrandRecordTool
>
lambdaQuery
()
.
eq
(
BrandRecordTool:
:
getAccount
,
brandRecordTool
.
getAccount
())
.
eq
(
BrandRecordTool:
:
getRecordBrand
,
brandRecordTool
.
getRecordBrand
()));
if
(
brandRecordTools
.
size
()
==
1
)
{
List
<
BrandRecordTool
>
tools
=
brandRecordToolMapper
.
selectList
(
Wrappers
.<
BrandRecordTool
>
lambdaQuery
()
.
eq
(
BrandRecordTool:
:
getAccount
,
brandRecordTool
.
getEmpowerAccountUk
())
.
eq
(
BrandRecordTool:
:
getRecordBrand
,
brandRecordTool
.
getRecordBrand
()));
if
(
tools
.
size
()
==
1
)
{
BrandRecordTool
update
=
new
BrandRecordTool
();
update
.
setId
(
brandRecordTools
.
get
(
0
).
getId
());
updateList
.
add
(
update
);
BrandRecordTool
tool
=
tools
.
get
(
0
);
update
.
setAccountLogoUrl
(
tool
.
getAccountLogoUrl
())
.
setLogoZipUrl
(
tool
.
getLogoZipUrl
())
.
setCommunicationId
(
tool
.
getCommunicationId
())
.
setFirstAuditId
(
tool
.
getFirstAuditId
())
.
setFirstAuditStatus
(
tool
.
getFirstAuditStatus
())
.
setFirstAuditTime
(
tool
.
getFirstAuditTime
())
.
setFirstAuditRemark
(
tool
.
getFirstAuditRemark
())
.
setFirstAuditName
(
tool
.
getFirstAuditName
())
.
setFirstAuditUrl
(
tool
.
getFirstAuditUrl
())
.
setSecondAuditId
(
tool
.
getSecondAuditId
())
.
setSecondAuditStatus
(
tool
.
getSecondAuditStatus
())
.
setSecondAuditTime
(
tool
.
getSecondAuditTime
())
.
setSecondAuditRemark
(
tool
.
getSecondAuditRemark
())
.
setSecondAuditName
(
tool
.
getSecondAuditName
())
.
setCopyrightApplicant
(
tool
.
getCopyrightApplicant
())
.
setCopyrightApplicantId
(
tool
.
getCopyrightApplicantId
())
.
setCopyrightApplicantStatus
(
tool
.
getCopyrightApplicantStatus
())
.
setCopyrightApplicantTime
(
tool
.
getCopyrightApplicantTime
())
.
setCopyrightApplicantFinishTime
(
tool
.
getCopyrightApplicantFinishTime
())
.
setCopyrightNumber
(
tool
.
getCopyrightNumber
())
.
setCopyrightName
(
tool
.
getCopyrightName
())
.
setCopyrightCertificate
(
tool
.
getCopyrightCertificate
())
.
setApplyCompany
(
tool
.
getApplyCompany
())
;
VisualDesignLog
log
=
new
VisualDesignLog
();
log
.
setOperationKey
(
"brand_record_tool"
)
.
setCreateId
(
0
)
.
setCreateTime
(
currentTimeSecond
)
.
setCreateName
(
"系统"
)
.
setOperationContent
(
String
.
format
(
"同步%s-%s的logo、审核、版权等信息"
,
tool
.
getAccount
(),
tool
.
getRecordBrand
()))
.
setRelationId
(
update
.
getId
())
.
setFileUrl
(
""
)
.
setOperationType
(
"job"
)
;
logList
.
add
(
log
);
}
else
{
log
.
error
(
"数据库品牌工具logo重复2:{}-{}"
,
brandRecordTool
.
getAccount
(),
brandRecordTool
.
getRecordBrand
());
}
}
else
{
log
.
error
(
"数据库品牌工具logo重复1:{}-{}-{}"
,
brandRecordTool
.
getAccount
(),
brandRecordTool
.
getRecordBrand
(),
brandRecordTools
.
size
());
}
}
Map
<
Long
,
VisualDesignLog
>
logMap
=
logList
.
stream
().
collect
(
Collectors
.
toMap
(
VisualDesignLog:
:
getRelationId
,
Function
.
identity
()));
try
(
BufferedWriter
writer
=
new
BufferedWriter
(
new
FileWriter
(
"brand_record_tool_logo_data.sql"
)))
{
for
(
BrandRecordTool
brandRecordTool
:
updateList
)
{
String
updateSql
=
SqlGenerator
.
generateUpdateSql
(
brandRecordTool
);
VisualDesignLog
visualDesignLog
=
logMap
.
get
(
brandRecordTool
.
getId
());
String
insertSql
=
SqlGenerator
.
generateInsertSql
(
visualDesignLog
);
writer
.
write
(
updateSql
+
"\n"
+
insertSql
+
"\n"
);
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment