Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
projectArtifacture
Project
Project
Details
Activity
Releases
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
yangzhaojun
projectArtifacture
Commits
5a3c63ac
Commit
5a3c63ac
authored
Jan 12, 2018
by
李丛阳
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
freemarker
parent
05bc248d
Changes
23
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
23 changed files
with
1309 additions
and
18 deletions
+1309
-18
pom.xml
pom.xml
+39
-3
CodeController.java
...main/java/org/rcisoft/code/controller/CodeController.java
+108
-0
CodeSchema.java
src/main/java/org/rcisoft/code/model/CodeSchema.java
+152
-0
CodeTable.java
src/main/java/org/rcisoft/code/model/CodeTable.java
+29
-0
CodeService.java
src/main/java/org/rcisoft/code/service/CodeService.java
+28
-0
CodeServiceImpl.java
...n/java/org/rcisoft/code/service/impl/CodeServiceImpl.java
+271
-0
FamilyDbUtils.java
...main/java/org/rcisoft/common/component/FamilyDbUtils.java
+78
-0
Global.java
src/main/java/org/rcisoft/common/component/Global.java
+11
-1
DbColumnModel.java
src/main/java/org/rcisoft/common/model/DbColumnModel.java
+217
-0
DbModel.java
src/main/java/org/rcisoft/common/model/DbModel.java
+28
-0
DbTableModel.java
src/main/java/org/rcisoft/common/model/DbTableModel.java
+68
-0
IdEntity.java
src/main/java/org/rcisoft/core/entity/IdEntity.java
+1
-5
BaseService.java
src/main/java/org/rcisoft/core/service/BaseService.java
+14
-0
DateUtil.java
src/main/java/org/rcisoft/core/util/DateUtil.java
+22
-0
JwtUtil.java
src/main/java/org/rcisoft/core/util/JwtUtil.java
+1
-0
application-dev.yml
src/main/resources/application-dev.yml
+13
-8
application-prod.yml
src/main/resources/application-prod.yml
+1
-1
connect.js
src/main/resources/static/connect.js
+49
-0
jquery-1.7.2.min.js
src/main/resources/static/jquery-1.7.2.min.js
+4
-0
controller.ftl
src/main/resources/templates/codeftl/controller.ftl
+93
-0
entity.ftl
src/main/resources/templates/codeftl/entity.ftl
+40
-0
mapper.ftl
src/main/resources/templates/codeftl/mapper.ftl
+16
-0
connect.ftl
src/main/resources/templates/connect.ftl
+26
-0
No files found.
pom.xml
View file @
5a3c63ac
...
...
@@ -61,10 +61,10 @@
</dependency>
<!--spring boot freemarker starter-->
<
!--<
dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-freemarker
</artifactId>
</dependency>
-->
</dependency>
<!--spring boot configuration starter-->
<dependency>
...
...
@@ -122,6 +122,25 @@
<artifactId>
spring-boot-devtools
</artifactId>
<optional>
true
</optional>
</dependency>
<!-- 该依赖必加,里面有sping对schedule的支持
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
-->
<dependency>
<groupId>
org.quartz-scheduler
</groupId>
<artifactId>
quartz
</artifactId>
<version>
2.2.1
</version>
<exclusions>
<exclusion>
<artifactId>
slf4j-api
</artifactId>
<groupId>
org.slf4j
</groupId>
</exclusion>
</exclusions>
</dependency>
<!--spring boot mybatis starter end-->
<!--spring boot starter !!!!!!!!!!!!!!!! end -->
...
...
@@ -283,13 +302,22 @@
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.ant/ant -->
<dependency>
<groupId>
org.apache.ant
</groupId>
<artifactId>
ant
</artifactId>
<version>
1.9.0
</version>
<!-- 1.10 需要jdk1.8-->
</dependency>
</dependencies>
<build>
<finalName>
education
</finalName>
<finalName>
projectArtifacture
</finalName>
<resources>
<resource>
<directory>
src/main/resources
</directory>
...
...
@@ -308,8 +336,16 @@
<artifactId>
spring-boot-maven-plugin
</artifactId>
<version>
${spring.boot.version}
</version>
<configuration>
<mainClass>
org.rcisoft.EducationApplication
</mainClass>
<fork>
true
</fork>
<!-- 如果没有该配置,devtools不会生效 -->
</configuration>
<executions>
<execution>
<goals>
<goal>
repackage
</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
...
...
src/main/java/org/rcisoft/code/controller/CodeController.java
0 → 100644
View file @
5a3c63ac
package
org
.
rcisoft
.
code
.
controller
;
import
io.swagger.annotations.ApiOperation
;
import
org.rcisoft.code.model.CodeSchema
;
import
org.rcisoft.code.model.CodeTable
;
import
org.rcisoft.code.service.CodeService
;
import
org.rcisoft.common.controller.PaginationController
;
import
org.rcisoft.core.constant.MessageConstant
;
import
org.rcisoft.core.model.PersistModel
;
import
org.rcisoft.core.result.Result
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.servlet.ModelAndView
;
import
javax.servlet.ServletOutputStream
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.List
;
/**
* Created by lcy on 17/6/28.
*/
@RestController
@RequestMapping
(
"/code"
)
public
class
CodeController
extends
PaginationController
<
CodeTable
>
{
@Autowired
private
CodeService
codeServiceImpl
;
/**
* 连接数据库 schema
* @param codeSchema
* @return
*/
@ApiOperation
(
value
=
"构建 treeView"
,
notes
=
"构建 treeView"
)
@RequestMapping
(
"connectDb"
)
public
Result
connectDb
(
CodeSchema
codeSchema
){
List
<
CodeTable
>
result
=
codeServiceImpl
.
getCodeTablesBySchema
(
codeSchema
);
if
(
null
==
result
||
0
==
result
.
size
())
return
Result
.
builder
(
new
PersistModel
(
0
),
MessageConstant
.
MESSAGE_ALERT_SUCCESS
,
"数据库连接信息错误,或数据库不存在数据表!"
,
result
);
else
return
Result
.
builder
(
new
PersistModel
(
1
),
MessageConstant
.
MESSAGE_ALERT_SUCCESS
,
"数据库连接信息错误,或数据库不存在数据表!"
,
result
);
}
/**
* 导出code package
* @return
*/
@ApiOperation
(
value
=
"构建 treeView"
,
notes
=
"构建 treeView"
)
@RequestMapping
(
value
=
"constructCode"
)
//@ResponseBody // springMVC 下载 报页面找不到
public
void
constructCode
(
CodeSchema
codeSchema
)
throws
IOException
{
ServletOutputStream
out
=
null
;
InputStream
fin
=
null
;
File
file
=
null
;
//codeSchema.setUserId(UserUtil.getUserInfoProp(getToken(),UserUtil.USER_ID));
String
path
=
codeServiceImpl
.
generateCode
(
codeSchema
);
try
{
if
(
null
==
path
)
return
;
file
=
new
File
(
path
);
//不存在
if
(
null
==
file
||
!
file
.
exists
())
return
;
// response
response
.
setCharacterEncoding
(
"utf-8"
);
response
.
setContentType
(
"application/force-download"
);
response
.
addHeader
(
"Content-Disposition"
,
"attachment;filename=cyCode.zip"
);
out
=
response
.
getOutputStream
();
fin
=
new
FileInputStream
(
file
);
byte
[]
buffer
=
new
byte
[
1024
];
//缓冲区
int
bytesToRead
=
-
1
;
// 通过循环将读入的Word文件的内容输出到浏览器中
while
((
bytesToRead
=
fin
.
read
(
buffer
))
!=
-
1
)
{
out
.
write
(
buffer
,
0
,
bytesToRead
);
}
}
catch
(
Exception
ex
){
ex
.
printStackTrace
();
}
finally
{
if
(
fin
!=
null
)
fin
.
close
();
if
(
out
!=
null
)
out
.
close
();
//if(file != null) file.delete(); // 删除临时文件
}
}
/**
* 跳转 freemarker 连接
* @return
*/
@GetMapping
(
"connect"
)
public
ModelAndView
connectPage
(){
ModelAndView
mv
=
new
ModelAndView
(
"connect"
);
return
mv
;
}
}
src/main/java/org/rcisoft/code/model/CodeSchema.java
0 → 100644
View file @
5a3c63ac
package
org
.
rcisoft
.
code
.
model
;
import
org.rcisoft.common.model.DbModel
;
import
java.io.Serializable
;
/**
* Created by lcy on 17/7/1.
*
* code schema
*/
public
class
CodeSchema
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1154645476624841358L
;
private
String
ip
;
private
String
db
;
private
String
url
;
private
String
dbName
;
private
String
username
;
private
String
password
;
private
String
author
;
public
String
getAuthor
()
{
return
author
;
}
public
void
setAuthor
(
String
author
)
{
this
.
author
=
author
;
}
public
String
getIp
()
{
return
ip
;
}
public
void
setIp
(
String
ip
)
{
this
.
ip
=
ip
;
}
public
String
getDb
()
{
return
db
;
}
public
void
setDb
(
String
db
)
{
this
.
db
=
db
;
}
public
String
getPort
()
{
return
port
;
}
public
void
setPort
(
String
port
)
{
this
.
port
=
port
;
}
private
String
port
;
private
String
dbProduct
;
private
String
driverClass
;
private
String
basePackage
;
public
String
getBasePackage
()
{
return
basePackage
;
}
public
void
setBasePackage
(
String
basePackage
)
{
this
.
basePackage
=
basePackage
;
}
public
CodeSchema
()
{
}
public
String
getUrl
()
{
if
(
DbModel
.
MYSQL
.
getType
().
equals
(
getDb
()))
return
"jdbc:mysql://"
+
getIp
()
+
":"
+
getPort
()
+
"/"
+
getDbName
();
return
url
;
}
public
void
setUrl
(
String
url
)
{
this
.
url
=
url
;
}
public
String
getDbName
()
{
return
dbName
;
}
public
void
setDbName
(
String
dbName
)
{
this
.
dbName
=
dbName
;
}
public
String
getUsername
()
{
return
username
;
}
public
void
setUsername
(
String
username
)
{
this
.
username
=
username
;
}
public
String
getPassword
()
{
return
password
;
}
public
void
setPassword
(
String
password
)
{
this
.
password
=
password
;
}
public
String
getDbProduct
()
{
return
dbProduct
;
}
public
void
setDbProduct
(
String
dbProduct
)
{
this
.
dbProduct
=
dbProduct
;
}
public
String
getDriverClass
()
{
if
(
DbModel
.
MYSQL
.
getType
().
equals
(
getDb
()))
return
"com.mysql.jdbc.Driver"
;
return
driverClass
;
}
public
void
setDriverClass
(
String
driverClass
)
{
this
.
driverClass
=
driverClass
;
}
private
String
tables
;
public
String
getTables
()
{
return
tables
;
}
public
void
setTables
(
String
tables
)
{
this
.
tables
=
tables
;
}
private
String
userId
;
public
String
getUserId
()
{
return
userId
;
}
public
void
setUserId
(
String
userId
)
{
this
.
userId
=
userId
;
}
}
src/main/java/org/rcisoft/code/model/CodeTable.java
0 → 100644
View file @
5a3c63ac
package
org
.
rcisoft
.
code
.
model
;
import
java.io.Serializable
;
/**
* Created by lcy on 17/7/1.
*
* code table
*/
public
class
CodeTable
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1154645476624841358L
;
public
CodeTable
()
{
}
private
String
tableName
;
public
String
getTableName
()
{
return
tableName
;
}
public
void
setTableName
(
String
tableName
)
{
this
.
tableName
=
tableName
;
}
}
src/main/java/org/rcisoft/code/service/CodeService.java
0 → 100644
View file @
5a3c63ac
package
org
.
rcisoft
.
code
.
service
;
import
org.rcisoft.code.model.CodeSchema
;
import
org.rcisoft.code.model.CodeTable
;
import
java.util.List
;
/**
* Created by lcy on 17/6/28.
*/
public
interface
CodeService
{
/**
* 获取 codesTable 通过 schema
* @param schema
* @return
*/
public
List
<
CodeTable
>
getCodeTablesBySchema
(
CodeSchema
schema
);
/**
* 构建代码库
* @param codeSchema
* @return
*/
String
generateCode
(
CodeSchema
codeSchema
);
}
src/main/java/org/rcisoft/code/service/impl/CodeServiceImpl.java
0 → 100644
View file @
5a3c63ac
This diff is collapsed.
Click to expand it.
src/main/java/org/rcisoft/common/component/FamilyDbUtils.java
0 → 100644
View file @
5a3c63ac
package
org
.
rcisoft
.
common
.
component
;
import
com.alibaba.druid.pool.DruidDataSource
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.ibatis.mapping.Environment
;
import
org.apache.ibatis.session.Configuration
;
import
org.apache.ibatis.session.SqlSession
;
import
org.apache.ibatis.session.SqlSessionFactory
;
import
org.apache.ibatis.session.SqlSessionFactoryBuilder
;
import
org.apache.ibatis.transaction.TransactionFactory
;
import
org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory
;
import
org.rcisoft.code.model.CodeSchema
;
import
org.springframework.stereotype.Component
;
import
java.io.Serializable
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
/**
* Created by lcy on 17/6/30.
*/
@Component
@Slf4j
public
class
FamilyDbUtils
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1985679477781607104L
;
/**
* 获取 连接
*
* 通过druidSource 获取连接 连接信息错误时,无法catch住,暂未解决,连接不会停止,不断尝试连接
* 暂不使用
*
* @return
*
* select table_name from information_schema.tables where table_schema='csdb' and table_type='base table';
*
* show tables;
*/
public
SqlSession
getConnectSession
(
CodeSchema
schema
){
// data source
DruidDataSource
ds
=
new
DruidDataSource
();
ds
.
setUrl
(
"jdbc:mysql://"
+
schema
.
getUrl
()
+
":3306/"
+
schema
.
getDbName
());
ds
.
setPassword
(
schema
.
getPassword
());
ds
.
setUsername
(
schema
.
getUsername
());
ds
.
setName
(
schema
.
getDbName
());
ds
.
setDriverClassName
(
"com.mysql.jdbc.Driver"
);
if
(
ds
.
isTestOnReturn
())
{
ds
.
close
();
}
// configure
Configuration
configuration
=
new
Configuration
();
TransactionFactory
transactionFactory
=
new
JdbcTransactionFactory
();
Environment
environment
=
new
Environment
(
schema
.
getUsername
(),
transactionFactory
,
ds
);
configuration
.
setEnvironment
(
environment
);
SqlSessionFactory
sqlSessionFactory
=
new
SqlSessionFactoryBuilder
().
build
(
configuration
);
return
sqlSessionFactory
.
openSession
();
}
/**
* 通过jdbc 获取 connection
* @param schema
* @return
*/
public
Connection
getConnection
(
CodeSchema
schema
)
{
Connection
con
=
null
;
try
{
Class
.
forName
(
schema
.
getDriverClass
());
//创建驱动器
con
=
DriverManager
.
getConnection
(
schema
.
getUrl
(),
schema
.
getUsername
(),
schema
.
getPassword
());
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
());
}
return
con
;
}
}
src/main/java/org/rcisoft/common/component/Global.java
View file @
5a3c63ac
...
...
@@ -5,6 +5,7 @@ import lombok.Data;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
java.io.Serializable
;
import
java.util.Map
;
/**
...
...
@@ -16,9 +17,10 @@ import java.util.Map;
*/
@Component
@Data
public
class
Global
{
public
class
Global
implements
Serializable
{
private
static
final
long
serialVersionUID
=
-
7950787304594954554L
;
/**
* 保存全局属性值
*/
...
...
@@ -75,4 +77,12 @@ public class Global {
private
String
studentCode
;
@Value
(
"${global.path.base_upload_location}"
)
private
String
baseUploadLocation
;
@Value
(
"${global.path.code_generate_location}"
)
private
String
codeGenerateLocation
;
}
src/main/java/org/rcisoft/common/model/DbColumnModel.java
0 → 100644
View file @
5a3c63ac
package
org
.
rcisoft
.
common
.
model
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
java.io.Serializable
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
/**
* Created by lcy on 17/7/5.
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public
class
DbColumnModel
implements
Serializable
{
private
static
final
long
serialVersionUID
=
-
7808860348918160912L
;
private
String
colName
;
//列名
private
String
typeName
;
//类型名称
private
int
precision
,
isNull
,
dataType
,
scale
;
//精度,是否为空,类型,小数的位数
private
boolean
isKey
=
false
;
//是否为主键
private
String
remarks
,
defaultValue
;
//备注 默认值
/**
* get method 用 is 的话 freemarker 找不到
* @return
*/
public
boolean
getIsKey
()
{
return
isKey
;
}
public
void
setKey
(
boolean
key
)
{
isKey
=
key
;
}
/**
* 复制属性
* @param rs
* @throws SQLException
*/
public
void
copyColumnFromSqlResult
(
ResultSet
rs
)
throws
SQLException
{
try
{
String
colName
=
rs
.
getString
(
"COLUMN_NAME"
);
//列名
String
typeName
=
rs
.
getString
(
"TYPE_NAME"
);
//类型名称
int
precision
=
rs
.
getInt
(
"COLUMN_SIZE"
);
//精度
int
isNull
=
rs
.
getInt
(
"NULLABLE"
);
//是否为空
int
dataType
=
rs
.
getInt
(
"DATA_TYPE"
);
//类型
int
scale
=
rs
.
getInt
(
"DECIMAL_DIGITS"
);
// 小数的位数
String
remarks
=
rs
.
getString
(
"REMARKS"
);
//注释
String
defaultValue
=
rs
.
getString
(
"COLUMN_DEF"
);
//默认值
this
.
setColName
(
colName
);
this
.
setTypeName
(
typeName
);
this
.
setPrecision
(
precision
);
this
.
setIsNull
(
isNull
);
this
.
setDataType
(
dataType
);
this
.
setScale
(
scale
);
this
.
setRemarks
(
remarks
);
this
.
setDefaultValue
(
defaultValue
);
}
catch
(
SQLException
e
){
throw
e
;
}
}
private
String
columnNameLowerCamel
;
//列名转化为小写驼峰式
private
String
columnNameUpperCamel
;
//列名转化为大写驼峰式
private
String
javaType
;
//数据库属性名转化为java属性名
public
String
getJavaType
()
{
String
typeNamel
=
typeName
.
toLowerCase
();
switch
(
typeNamel
)
{
case
"int"
:
javaType
=
"Integer"
;
break
;
case
"varchar"
:
javaType
=
"String"
;
break
;
case
"char"
:
javaType
=
"Char"
;
break
;
case
"blob"
:
javaType
=
"Byte[]"
;
break
;
case
"text"
:
javaType
=
"String"
;
break
;
case
"integer"
:
javaType
=
"Long"
;
break
;
case
"tinyint"
:
javaType
=
"Integer"
;
break
;
case
"smallint"
:
javaType
=
"Integer"
;
break
;
case
"mediumint"
:
javaType
=
"Integer"
;
break
;
case
"bit"
:
javaType
=
"Boolean"
;
break
;
case
"bigint"
:
javaType
=
"BigInteger"
;
break
;
case
"float"
:
javaType
=
"Float"
;
break
;
case
"double"
:
javaType
=
"Double"
;
break
;
case
"decimal"
:
javaType
=
"BigDecimal"
;
break
;
case
"id"
:
javaType
=
"Long"
;
break
;
case
"date"
:
javaType
=
"Date"
;
break
;
case
"year"
:
javaType
=
"Date"
;
break
;
case
"time"
:
javaType
=
"Time"
;
break
;
case
"datetime"
:
javaType
=
"Date"
;
break
;
case
"timestamp"
:
javaType
=
"Date"
;
break
;
}
return
javaType
;
}
public
String
getColumnNameLowerCamel
()
{
columnNameLowerCamel
=
this
.
columnNameConvertLowerCamel
(
colName
);
return
columnNameLowerCamel
;
}
public
String
getColumnNameUpperCamel
()
{
columnNameUpperCamel
=
this
.
columnNameConvertUpperCamel
(
colName
);
return
columnNameUpperCamel
;
}
/**
* 将数据库属性名改为驼峰式,首字母大写
*
* @param columnName 列名
* @return
*/
private
static
String
columnNameConvertLowerCamel
(
String
columnName
)
{
StringBuilder
result
=
new
StringBuilder
();
if
(
columnName
!=
null
&&
columnName
.
length
()
>
0
)
{
columnName
=
columnName
.
toLowerCase
();
//兼容使用大写的表名
boolean
flag
=
false
;
for
(
int
i
=
0
;
i
<
columnName
.
length
();
i
++)
{
char
ch
=
columnName
.
charAt
(
i
);
if
(
"_"
.
charAt
(
0
)
==
ch
)
{
flag
=
true
;
}
else
{
if
(
flag
)
{
result
.
append
(
Character
.
toUpperCase
(
ch
));
flag
=
false
;
}
else
{
result
.
append
(
ch
);
}
}
}
}
return
result
.
toString
();
}
/**
* 将数据库属性名改为驼峰式,首字母大写
*
* @param columnName 列名
* @return
*/
private
static
String
columnNameConvertUpperCamel
(
String
columnName
)
{
String
camel
=
columnNameConvertLowerCamel
(
columnName
);
return
camel
.
substring
(
0
,
1
).
toUpperCase
()
+
camel
.
substring
(
1
);
}
private
String
typeNameUpper
;
//类型名称
/**
* jdbc Type
* @return
*/
public
String
getTypeNameUpper
()
{
typeNameUpper
=
typeName
.
toUpperCase
();
if
(
typeNameUpper
.
equals
(
"INT"
))
typeNameUpper
=
"INTEGER"
;
if
(
typeNameUpper
.
equals
(
"DATETIME"
))
typeNameUpper
=
"TIMESTAMP"
;
return
typeNameUpper
;
}
}
src/main/java/org/rcisoft/common/model/DbModel.java
0 → 100644
View file @
5a3c63ac
package
org
.
rcisoft
.
common
.
model
;
/**
* Created by lcy on 17/7/4.
*
* 数据库模型
*/
public
enum
DbModel
{
MYSQL
(
"1"
),
SQLSERVER
(
"2"
),
ORACLE
(
"3"
);
private
String
type
;
public
String
getType
()
{
return
type
;
}
public
void
setType
(
String
type
)
{
this
.
type
=
type
;
}
DbModel
(
String
type
)
{
this
.
type
=
type
;
}
DbModel
()
{
}
}
src/main/java/org/rcisoft/common/model/DbTableModel.java
0 → 100644
View file @
5a3c63ac
package
org
.
rcisoft
.
common
.
model
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
java.io.Serializable
;
import
java.util.List
;
/**
* Created by lcy on 17/7/5.
* 表模型
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public
class
DbTableModel
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1803273420552584045L
;
private
List
<
DbColumnModel
>
columnModels
;
public
List
<
DbColumnModel
>
getColumnModels
()
{
return
columnModels
;
}
public
void
setColumnModels
(
List
<
DbColumnModel
>
columnModels
)
{
this
.
columnModels
=
columnModels
;
}
private
String
tableName
;
//表名 全小写
private
String
tableRemark
;
//表名 备注
private
String
entityName
;
public
String
getEntityName
()
{
StringBuffer
simpleEntity
=
new
StringBuffer
();
boolean
upPower
=
true
;
for
(
int
i
=
0
;
i
<
tableName
.
length
()
;
i
++){
char
tab
=
tableName
.
charAt
(
i
);
String
tabStr
=
tab
+
""
;
//非数字 字符
if
(!
tabStr
.
matches
(
"[0-9a-zA-Z]*"
)){
upPower
=
true
;
continue
;
}
if
(
upPower
)
simpleEntity
.
append
(
Character
.
toUpperCase
(
tab
));
else
simpleEntity
.
append
(
tab
);
upPower
=
false
;
}
return
simpleEntity
.
toString
();
}
public
String
getMappingPath
()
{
return
tableNameConvertMappingPath
(
tableName
);
}
private
static
String
tableNameConvertMappingPath
(
String
tableName
)
{
tableName
=
tableName
.
toLowerCase
();
//兼容使用大写的表名
return
"/"
+
(
tableName
.
contains
(
"_"
)
?
tableName
.
replaceAll
(
"_"
,
"/"
)
:
tableName
);
}
}
src/main/java/org/rcisoft/core/entity/IdEntity.java
View file @
5a3c63ac
...
...
@@ -29,11 +29,7 @@ public abstract class IdEntity<T> extends DataEntity<T> implements Serializable
protected
String
businessId
;
// 编号
public
void
setBusinessId
(
String
businessId
)
{
this
.
businessId
=
businessId
;
}
protected
String
token
;
/**
* 通用设置ID
...
...
src/main/java/org/rcisoft/core/service/BaseService.java
0 → 100644
View file @
5a3c63ac
package
org
.
rcisoft
.
core
.
service
;
import
java.io.Serializable
;
/**
* Created by lcy on 18/1/10.
*
* base service
*/
public
abstract
class
BaseService
implements
Serializable
{
private
static
final
long
serialVersionUID
=
-
6073290503145789958L
;
}
src/main/java/org/rcisoft/core/util/DateUtil.java
0 → 100644
View file @
5a3c63ac
package
org
.
rcisoft
.
core
.
util
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
/**
* Created by lcy on 17/2/17.
*/
public
class
DateUtil
{
/**
* 获取格式化日期
* @param format
* @param date
* @return
*/
public
static
String
getSimepleDate
(
String
format
,
Date
date
){
if
(
date
==
null
)
date
=
new
Date
();
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
format
);
return
dateFormat
.
format
(
date
);
}
}
src/main/java/org/rcisoft/core/util/JwtUtil.java
View file @
5a3c63ac
...
...
@@ -52,6 +52,7 @@ public class JwtUtil {
Map
<
String
,
Object
>
map
=
new
HashedMap
();
map
.
put
(
userDetails
.
getUsername
(),
userDetails
);
map
.
put
(
UserUtil
.
USER_ID
,
jwtUser
.
getBusinessId
());
map
.
put
(
UserUtil
.
USER_USERNAME
,
jwtUser
.
getUsername
());
String
token
=
jwtBean
.
generateToken
(
userDetails
.
getUsername
(),
map
);
return
token
;
}
...
...
src/main/resources/application-dev.yml
View file @
5a3c63ac
server
:
port
:
8082
context-path
:
/
edu
#ContextPath must start with '/' and not end with '/'
context-path
:
/
project
#ContextPath must start with '/' and not end with '/'
tomcat
:
max-threads
:
300
#uri-encoding: UTF-8
#
logging:
#
level:
#
root: INFO
#
org.springframework.web: DEBUG
logging
:
level
:
root
:
INFO
org.springframework.web
:
DEBUG
druid
:
url
:
jdbc:mysql://127.0.0.1:3306/
projectartifacture?useUnicode=true&characterEncoding=UTF-8
&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true
url
:
jdbc:mysql://127.0.0.1:3306/
edu_db?useUnicode=true&characterEncoding=UTF-8&useSSL=false
&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true
username
:
root
password
:
root
password
:
cy
initial-size
:
1
min-idle
:
1
max-active
:
20
...
...
@@ -52,7 +52,10 @@ spring:
throw-exception-if-no-handler-found
:
true
resources
:
add-mappings
:
false
freemarker
:
charset
:
UTF-8
suffix
:
.ftl
template-loader-path
:
classpath:/templates/
springfox
:
documentation
:
...
...
@@ -79,6 +82,8 @@ global:
min_password
:
6
max_password
:
16
path
:
base_upload_location
:
/working/resource/eduServer/
code_generate_location
:
/code
video_location
:
/video
temp_location
:
/temp
file_location
:
/file
...
...
src/main/resources/application-prod.yml
View file @
5a3c63ac
...
...
@@ -10,7 +10,7 @@ server:
# org.springframework.web: DEBUG
druid
:
url
:
jdbc:mysql://127.0.0.1:3306/projectartifacture?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true
url
:
jdbc:mysql://127.0.0.1:3306/projectartifacture?useUnicode=true&characterEncoding=UTF-8&
useSSL=false&
zeroDateTimeBehavior=convertToNull&allowMultiQueries=true
username
:
root
password
:
cy
initial-size
:
1
...
...
src/main/resources/static/connect.js
0 → 100644
View file @
5a3c63ac
/**
* Created by gaowenfeng on 2017/7/13.
*/
function
connect
()
{
$
.
ajax
({
type
:
'post'
,
url
:
'../code/connectDb'
,
data
:
{
ip
:
$
(
'#ip'
).
val
(),
db
:
$
(
'#db'
).
val
(),
port
:
$
(
'#port'
).
val
(),
dbName
:
$
(
'#dbName'
).
val
(),
username
:
$
(
'#username'
).
val
(),
password
:
$
(
'#password'
).
val
()
},
success
:
function
(
result
)
{
if
(
result
.
code
==
200
){
alert
(
"连接成功"
);
var
str
=
'<br>'
;
var
list
=
result
.
data
;
for
(
var
i
=
0
;
i
<
list
.
length
;
i
++
)
str
+=
(
list
[
i
].
tableName
+
':<input type="checkbox" name="table" value="'
+
list
[
i
].
tableName
+
'"> '
);
$
(
'#tableDiv'
).
append
(
str
);
}
},
error
:
function
(
error
)
{
alert
(
JSON
.
stringify
(
error
));
}
})
}
function
generate
()
{
var
str
=
""
;
var
j
=
0
for
(
var
i
=
0
;
i
<
document
.
getElementsByName
(
'table'
).
length
;
i
++
)
{
if
(
document
.
getElementsByName
(
'table'
)[
i
].
checked
)
{
if
(
j
==
0
)
str
+=
document
.
getElementsByName
(
'table'
)[
i
].
value
;
else
str
+=
","
+
document
.
getElementsByName
(
'table'
)[
i
].
value
;
j
++
;
}
}
if
(
str
==
""
)
{
alert
(
"您没有选择任何数据"
);
}
else
{
window
.
location
.
href
=
'../code/constructCode?ip='
+
$
(
'#ip'
).
val
()
+
'&db='
+
$
(
'#db'
).
val
()
+
'&port='
+
$
(
'#port'
).
val
()
+
'&dbName='
+
$
(
'#dbName'
).
val
()
+
'&username='
+
$
(
'#username'
).
val
()
+
'&password='
+
$
(
'#password'
).
val
()
+
'&tables='
+
str
+
'&basePackage='
+
$
(
'#basepackage'
).
val
()
+
'&author='
+
$
(
'#author'
).
val
();
}
}
\ No newline at end of file
src/main/resources/static/jquery-1.7.2.min.js
0 → 100644
View file @
5a3c63ac
This diff is collapsed.
Click to expand it.
src/main/resources/templates/codeftl/controller.ftl
0 → 100755
View file @
5a3c63ac
package
org
.
rcisoft
.
business
.${
table
.
entityName
?
lower_case
}.
controller
;
/*
固定导入
*/
import
io
.
swagger
.
annotations
.
ApiImplicitParam
;
import
io
.
swagger
.
annotations
.
ApiImplicitParams
;
import
io
.
swagger
.
annotations
.
ApiOperation
;
import
org
.
springframework
.
validation
.
BindingResult
;
import
org
.
springframework
.
beans
.
factory
.
annotation
.
Autowired
;
import
org
.
springframework
.
web
.
bind
.
annotation
.*;
import
org
.
rcisoft
.
core
.
result
.
Result
;
import
org
.
rcisoft
.
core
.
result
.
ResultServiceEnums
;
import
org
.
rcisoft
.
core
.
model
.
PersistModel
;
import
org
.
rcisoft
.
core
.
constant
.
MessageConstant
;
import
org
.
rcisoft
.
business
.${
table
.
entityName
?
lower_case
}.
entity
.${
table
.
entityName
};
import
org
.
rcisoft
.
business
.${
table
.
entityName
?
lower_case
}.
service
.${
table
.
entityName
}
Service
;
import
java
.
util
.
List
;
/**
*
Created
by
${
author
}
on
${.
now
}.
*/
@
RestController
@
RequestMapping
(
"${table.mappingPath!}"
)
public
class
${
table
.
entityName
}
Controller
extends
PaginationController
<${
table
.
entityName
}>
{
@
Autowired
private
${
table
.
entityName
}
Service
${
table
.
entityName
?
uncap_first
}
ServiceImpl
;
@
ApiOperation
(
value
=
"添加${table.tableRemark!}"
,
notes
=
"添加${table.tableRemark!}"
)
//@
ApiImplicitParams
({@
ApiImplicitParam
(
name
=
"businessId"
,
value
=
"businessId"
,
required
=
false
,
dataType
=
"varchar"
)})
@
PostMapping
public
Result
add
(@
Valid
${
table
.
entityName
}
${
table
.
entityName
?
uncap_first
},
BindingResult
bindingResult
)
{
if
(
bindingResult
.
hasErrors
())
{
throw
new
ServiceException
(
ResultServiceEnums
.
PARAMETER_ERROR
.
getCode
(),
}
${
table
.
entityName
?
uncap_first
}.
setToken
(
getToken
());
PersistModel
data
=
${
table
.
entityName
?
uncap_first
}
ServiceImpl
.
save
(${
table
.
entityName
?
uncap_first
});
return
Result
.
builder
(
data
,
MessageConstant
.
MESSAGE_ALERT_SUCCESS
,
MessageConstant
.
MESSAGE_ALERT_ERROR
,
${
table
.
entityName
?
uncap_first
});
}
@
ApiOperation
(
value
=
"逻辑删除${table.tableRemark!}"
,
notes
=
"逻辑删除${table.tableRemark!}"
)
@
ApiImplicitParams
({@
ApiImplicitParam
(
name
=
"id"
,
value
=
"id"
,
required
=
false
,
dataType
=
"varchar"
)})
@
DeleteMapping
(
"/{id:
\\
d+}"
)
public
Result
delete
(@
PathVariable
String
id
)
{
${
table
.
entityName
}
${
table
.
entityName
?
uncap_first
}
=
new
${
table
.
entityName
?
uncap_first
}();
${
table
.
entityName
?
uncap_first
}.
setBusinessId
(
id
);
${
table
.
entityName
?
uncap_first
}.
setToken
(
getToken
());
PersistModel
data
=
${
table
.
entityName
?
uncap_first
}
ServiceImpl
.
remove
(${
table
.
entityName
?
uncap_first
});
return
Result
.
builder
(
data
,
MessageConstant
.
MESSAGE_ALERT_SUCCESS
,
MessageConstant
.
MESSAGE_ALERT_ERROR
,
id
);
}
@
ApiOperation
(
value
=
"修改${table.tableRemark!}"
,
notes
=
"修改${table.tableRemark!}"
)
@
ApiImplicitParams
({@
ApiImplicitParam
(
name
=
"businessId"
,
value
=
"businessId"
,
required
=
false
,
dataType
=
"varchar"
)})
@
PutMapping
(
"/{id:
\\
d+}"
)
public
Result
update
(${
table
.
entityName
}
${
table
.
entityName
?
uncap_first
})
{
if
(
bindingResult
.
hasErrors
())
{
throw
new
ServiceException
(
ResultServiceEnums
.
PARAMETER_ERROR
.
getCode
(),
}
${
table
.
entityName
?
uncap_first
}.
setToken
(
getToken
());
PersistModel
data
=
${
table
.
entityName
?
uncap_first
}
ServiceImpl
.
merge
(${
table
.
entityName
?
uncap_first
});
return
Result
.
builder
(
data
,
MessageConstant
.
MESSAGE_ALERT_SUCCESS
,
MessageConstant
.
MESSAGE_ALERT_ERROR
,
${
table
.
entityName
?
uncap_first
});
}
@
ApiOperation
(
value
=
"查看单 ${table.tableRemark!}"
,
notes
=
"查看单 ${table.tableRemark!}"
)
@
GetMapping
(
"/{id:
\\
d+}"
)
public
Result
detail
(@
PathVariable
String
id
)
{
return
Result
.
builder
(
new
PersistModel
(
1
),
MessageConstant
.
MESSAGE_ALERT_SUCCESS
,
MessageConstant
.
MESSAGE_ALERT_ERROR
,
${
table
.
entityName
?
uncap_first
}
ServiceImpl
.
findById
(
id
));
}
@
ApiOperation
(
value
=
"查看 ${table.tableRemark!} 集合"
,
notes
=
"查看单 ${table.tableRemark!} 集合"
)
@
GetMapping
(
value
=
"/query${table.entityName}ByPagination"
)
public
GridModel
listByPagination
(${
table
.
entityName
}
${
table
.
entityName
?
uncap_first
})
{
${
table
.
entityName
?
uncap_first
}.
setCreateBy
(
UserUtil
.
getUserInfoProp
(
getToken
(),
UserUtil
.
USER_ID
));
${
table
.
entityName
?
uncap_first
}
ServiceImpl
.
findAllByPagination
(
getPaginationUtility
(),
${
table
.
entityName
?
uncap_first
});
return
getGridModelResponse
();
}
}
src/main/resources/templates/codeftl/entity.ftl
0 → 100644
View file @
5a3c63ac
package
org
.
rcisoft
.
business
.${
table
.
entityName
?
lower_case
}.
entity
;
import
lombok
.*;
import
org
.
rcisoft
.
core
.
entity
.
IdEntity
;
import
javax
.
persistence
.*;
import
java
.
math
.
BigDecimal
;
import
java
.
math
.
BigInteger
;
import
java
.
io
.
Serializable
;
import
java
.
util
.
Date
;
import
java
.
util
.
List
;
/**
*
Created
with
${
author
}
on
${.
now
}.
*/
@
Entity
@
Data
@
NoArgsConstructor
@
AllArgsConstructor
@
Table
(
name
=
"${table.tableName}"
)
public
class
${
table
.
entityName
}
extends
IdEntity
<${
table
.
entityName
}>
{
<#
list
table
.
columnModels
as
item
>
<#
if
item
.
columnNameLowerCamel
!='businessId'&&
item
.
columnNameLowerCamel
!='remarks'&&
item
.
columnNameLowerCamel
!='createBy'&&
item
.
columnNameLowerCamel
!='createDate'&&
item
.
columnNameLowerCamel
!='updateBy'&&
item
.
columnNameLowerCamel
!='updateDate'&&
item
.
columnNameLowerCamel
!='delFlag'&&
item
.
columnNameLowerCamel
!='flag'>
private
${
item
.
javaType
}
${
item
.
columnNameLowerCamel
};
</#
if
>
</#
list
>
}
src/main/resources/templates/codeftl/mapper.ftl
0 → 100644
View file @
5a3c63ac
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"org.rcisoft.business.${table.entityName?lower_case}.dao.${table.entityName}Repository"
>
<resultMap
id=
"BaseResultMap"
type=
"org.rcisoft.business.${table.entityName?lower_case}.entity.${table.entityName}"
>
<
#list table.columnModels as item>
<
#if item.isKey>
<id
column=
"${item.colName}"
jdbcType=
"${item.typeNameUpper}"
property=
"${item.columnNameLowerCamel}"
/>
<
/#if>
<
#if !item.isKey>
<result
column=
"${item.colName}"
jdbcType=
"${item.typeNameUpper}"
property=
"${item.columnNameLowerCamel}"
/>
<
/#if>
<
/#list>
</resultMap>
<!--<cache type="${r'${corePackag!}'}.util.RedisCache"/>-->
</mapper>
\ No newline at end of file
src/main/resources/templates/connect.ftl
0 → 100644
View file @
5a3c63ac
<html>
<head>
<title>
代码生成
</title>
</head>
<body>
ip:
<input
type=
"text"
id=
"ip"
/><br></br>
db:
<select
id=
"db"
>
<option
value=
"1"
>
mysql
</option>
<option
value=
"2"
>
oracle
</option>
<option
value=
"3"
>
sqlserver
</option>
</select><br></br>
port:
<input
type=
"text"
id=
"port"
/><br></br>
dbName:
<input
type=
"text"
id=
"dbName"
/><br></br>
username:
<input
type=
"text"
id=
"username"
/><br></br>
password:
<input
type=
"text"
id=
"password"
/><br></br>
<button
onclick=
"connect()"
>
连接
</button>
<hr/>
<div
id=
"tableDiv"
>
basepackage:
<input
type=
"text"
id=
"basepackage"
/><br></br>
author:
<input
type=
"text"
id=
"author"
/><br></br>
</div>
<button
onclick=
"generate()"
>
生成
</button>
<script
src=
"../static/jquery-1.7.2.min.js"
></script>
<script
src=
"../static/connect.js"
></script>
</body>
</html>
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