Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
江名洋
/
linkwe-scrm
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 5c6ee661
authored
Dec 17, 2020
by
ws
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
海报创建
1 parent
0b497b06
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
24 changed files
with
977 additions
and
2 deletions
linkwe-admin/src/main/java/com/linkwechat/web/controller/wecom/WePosterController.java
linkwe-admin/src/main/java/com/linkwechat/web/controller/wecom/WePosterFontController.java
linkwe-common/pom.xml
linkwe-common/src/main/java/com/linkwechat/common/core/domain/BaseEntity.java
linkwe-common/src/main/java/com/linkwechat/common/enums/WePosterSubassemblyType.java
linkwe-common/src/main/java/com/linkwechat/common/utils/img/ImageUtils.java
linkwe-common/src/main/java/com/linkwechat/common/utils/img/NetFileUtils.java
linkwe-framework/pom.xml
linkwe-wecom/src/main/java/com/linkwechat/wecom/domain/WePoster.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/domain/WePosterFont.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/domain/WePosterSubassembly.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/mapper/WePosterFontMapper.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/mapper/WePosterMapper.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/mapper/WePosterSubassemblyMapper.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/IWePosterFontService.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/IWePosterService.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/IWePosterSubassemblyService.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WePosterFontServiceImpl.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WePosterServiceImpl.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WePosterSubassemblyServiceImpl.java
linkwe-wecom/src/main/resources/mapper/wecom/WeposterFontMapper.xml
linkwe-wecom/src/main/resources/mapper/wecom/WeposterMapper.xml
linkwe-wecom/src/main/resources/mapper/wecom/WeposterSubassemblyMapper.xml
pom.xml
linkwe-admin/src/main/java/com/linkwechat/web/controller/wecom/WePosterController.java
0 → 100644
View file @
5c6ee66
package
com
.
linkwechat
.
web
.
controller
.
wecom
;
import
com.linkwechat.common.core.controller.BaseController
;
import
com.linkwechat.common.core.domain.AjaxResult
;
import
com.linkwechat.common.utils.SnowFlakeUtil
;
import
com.linkwechat.wecom.domain.WePoster
;
import
com.linkwechat.wecom.domain.WePosterFont
;
import
com.linkwechat.wecom.domain.WePosterSubassembly
;
import
com.linkwechat.wecom.service.IWePosterFontService
;
import
com.linkwechat.wecom.service.IWePosterService
;
import
com.linkwechat.wecom.service.IWePosterSubassemblyService
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.web.bind.annotation.*
;
import
javax.annotation.Resource
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
@RestController
@RequestMapping
(
value
=
"wecom/poster/"
)
public
class
WePosterController
extends
BaseController
{
@Resource
private
IWePosterService
wePosterService
;
@Resource
private
IWePosterSubassemblyService
wePosterSubassemblyService
;
@Resource
private
IWePosterFontService
wePosterFontService
;
@PostMapping
(
value
=
"insert"
)
@Transactional
(
rollbackFor
=
RuntimeException
.
class
)
public
AjaxResult
insert
(
@RequestBody
WePoster
poster
){
wePosterService
.
generateSimpleImg
(
poster
);
poster
.
setId
(
SnowFlakeUtil
.
nextId
());
poster
.
setDelFlag
(
1
);
wePosterService
.
saveOrUpdate
(
poster
);
poster
.
getPosterSubassemblyList
().
forEach
(
wePosterSubassembly
->
{
wePosterSubassembly
.
setDelFlag
(
1
);
wePosterSubassembly
.
setId
(
SnowFlakeUtil
.
nextId
());
wePosterSubassembly
.
setPosterId
(
poster
.
getId
());
});
wePosterSubassemblyService
.
saveBatch
(
poster
.
getPosterSubassemblyList
());
return
AjaxResult
.
success
(
"创建成功"
);
}
@PutMapping
(
value
=
"update"
)
public
AjaxResult
update
(
@RequestBody
WePoster
poster
){
if
(
poster
.
getId
()
==
null
){
return
AjaxResult
.
error
(
"id为空"
);
}
wePosterService
.
generateSimpleImg
(
poster
);
wePosterService
.
saveOrUpdate
(
poster
);
List
<
WePosterSubassembly
>
posterSubassemblyList
=
wePosterSubassemblyService
.
lambdaQuery
().
eq
(
WePosterSubassembly:
:
getPosterId
,
poster
.
getId
()).
eq
(
WePosterSubassembly:
:
getDelFlag
,
1
).
list
();
Map
<
Long
,
WePosterSubassembly
>
posterSubassemblyMap
=
posterSubassemblyList
.
stream
().
collect
(
Collectors
.
toMap
(
WePosterSubassembly:
:
getId
,
p
->
p
));
List
<
WePosterSubassembly
>
insertList
=
new
ArrayList
<>();
List
<
WePosterSubassembly
>
updateList
=
new
ArrayList
<>();
poster
.
getPosterSubassemblyList
().
forEach
(
wePosterSubassembly
->
{
if
(
wePosterSubassembly
.
getId
()
==
null
){
wePosterSubassembly
.
setId
(
SnowFlakeUtil
.
nextId
());
wePosterSubassembly
.
setPosterId
(
poster
.
getId
());
wePosterSubassembly
.
setDelFlag
(
1
);
insertList
.
add
(
wePosterSubassembly
);
}
else
{
posterSubassemblyMap
.
remove
(
wePosterSubassembly
.
getId
());
updateList
.
add
(
wePosterSubassembly
);
}
});
if
(!
CollectionUtils
.
isEmpty
(
insertList
))
{
wePosterSubassemblyService
.
saveBatch
(
insertList
);
}
if
(!
CollectionUtils
.
isEmpty
(
updateList
))
{
wePosterSubassemblyService
.
updateBatchById
(
updateList
);
}
List
<
WePosterSubassembly
>
deleteList
=
new
ArrayList
<>(
posterSubassemblyMap
.
values
());
if
(!
CollectionUtils
.
isEmpty
(
deleteList
)){
deleteList
.
forEach
(
wePosterSubassembly
->
wePosterSubassembly
.
setDelFlag
(
0
));
wePosterSubassemblyService
.
updateBatchById
(
deleteList
);
}
return
AjaxResult
.
success
(
"修改成功"
);
}
@GetMapping
(
value
=
"list"
)
public
AjaxResult
list
(){
List
<
WePoster
>
fontList
=
wePosterService
.
lambdaQuery
()
.
eq
(
WePoster:
:
getDelFlag
,
1
)
.
orderByDesc
(
WePoster:
:
getCreateTime
)
.
list
();
return
AjaxResult
.
success
(
fontList
);
}
@GetMapping
(
value
=
"entity/{id}"
)
public
AjaxResult
entity
(
@PathVariable
Long
id
){
return
AjaxResult
.
success
(
wePosterService
.
selectOne
(
id
));
}
@GetMapping
(
value
=
"page"
)
public
AjaxResult
page
(){
startPage
();
List
<
WePoster
>
fontList
=
wePosterService
.
lambdaQuery
()
.
eq
(
WePoster:
:
getDelFlag
,
1
)
.
orderByDesc
(
WePoster:
:
getCreateTime
)
.
list
();
return
AjaxResult
.
success
(
getDataTable
(
fontList
));
}
@DeleteMapping
(
value
=
"delete/{id}"
)
public
AjaxResult
deletePosterFont
(
@PathVariable
Long
id
){
wePosterService
.
lambdaUpdate
().
set
(
WePoster:
:
getDelFlag
,
0
).
eq
(
WePoster:
:
getId
,
id
);
wePosterSubassemblyService
.
lambdaUpdate
().
set
(
WePosterSubassembly:
:
getDelFlag
,
0
).
eq
(
WePosterSubassembly:
:
getPosterId
,
id
).
eq
(
WePosterSubassembly:
:
getFontId
,
1
);
return
AjaxResult
.
success
(
"删除成功"
);
}
}
linkwe-admin/src/main/java/com/linkwechat/web/controller/wecom/WePosterFontController.java
0 → 100644
View file @
5c6ee66
package
com
.
linkwechat
.
web
.
controller
.
wecom
;
import
com.linkwechat.common.core.controller.BaseController
;
import
com.linkwechat.common.core.domain.AjaxResult
;
import
com.linkwechat.common.utils.SnowFlakeUtil
;
import
com.linkwechat.web.controller.common.CommonController
;
import
com.linkwechat.wecom.domain.WePosterFont
;
import
com.linkwechat.wecom.service.IWePosterFontService
;
import
org.springframework.web.bind.annotation.*
;
import
javax.annotation.Resource
;
import
java.util.List
;
@RestController
@RequestMapping
(
value
=
"wecom/posterFont/"
)
public
class
WePosterFontController
extends
BaseController
{
@Resource
private
IWePosterFontService
wePosterFontService
;
@PostMapping
(
value
=
"posterFont"
)
public
AjaxResult
insertPosterFont
(
@RequestBody
WePosterFont
posterFont
){
posterFont
.
setId
(
SnowFlakeUtil
.
nextId
());
posterFont
.
setDelFlag
(
1
);
wePosterFontService
.
save
(
posterFont
);
return
AjaxResult
.
success
(
"创建成功"
);
}
@PutMapping
(
value
=
"posterFont"
)
public
AjaxResult
updatePosterFont
(
@RequestBody
WePosterFont
posterFont
){
if
(
posterFont
.
getId
()
==
null
){
return
AjaxResult
.
error
(
"id为空"
);
}
wePosterFontService
.
saveOrUpdate
(
posterFont
);
return
AjaxResult
.
success
(
"修改成功"
);
}
@GetMapping
(
value
=
"posterFontList"
)
public
AjaxResult
selectPosterFontList
(){
List
<
WePosterFont
>
fontList
=
wePosterFontService
.
lambdaQuery
()
.
eq
(
WePosterFont:
:
getDelFlag
,
1
)
.
orderByDesc
(
WePosterFont:
:
getOrder
)
.
orderByDesc
(
WePosterFont:
:
getCreateTime
)
.
list
();
return
AjaxResult
.
success
(
fontList
);
}
@GetMapping
(
value
=
"posterFontPage"
)
public
AjaxResult
selectPosterFontPage
(){
startPage
();
List
<
WePosterFont
>
fontList
=
wePosterFontService
.
lambdaQuery
()
.
eq
(
WePosterFont:
:
getDelFlag
,
1
)
.
orderByDesc
(
WePosterFont:
:
getOrder
)
.
orderByDesc
(
WePosterFont:
:
getCreateTime
)
.
list
();
return
AjaxResult
.
success
(
getDataTable
(
fontList
));
}
@DeleteMapping
(
value
=
"posterFont/{id}"
)
public
AjaxResult
deletePosterFont
(
@PathVariable
Long
id
){
wePosterFontService
.
lambdaUpdate
().
set
(
WePosterFont:
:
getDelFlag
,
0
).
eq
(
WePosterFont:
:
getId
,
id
);
return
AjaxResult
.
success
(
"删除成功"
);
}
}
linkwe-common/pom.xml
View file @
5c6ee66
...
@@ -101,6 +101,16 @@
...
@@ -101,6 +101,16 @@
<artifactId>
jjwt
</artifactId>
<artifactId>
jjwt
</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>
io.vertx
</groupId>
<artifactId>
vertx-core
</artifactId>
</dependency>
<dependency>
<groupId>
io.vertx
</groupId>
<artifactId>
vertx-web-client
</artifactId>
</dependency>
<!-- redis 缓存操作 -->
<!-- redis 缓存操作 -->
<dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
...
@@ -137,6 +147,8 @@
...
@@ -137,6 +147,8 @@
</dependency>
</dependency>
<!--防止进入swagger页面报类型转换错误,排除2.9.2中的引用,手动增加1.5.21版本-->
<!--防止进入swagger页面报类型转换错误,排除2.9.2中的引用,手动增加1.5.21版本-->
<dependency>
<dependency>
<groupId>
io.swagger
</groupId>
<groupId>
io.swagger
</groupId>
...
...
linkwe-common/src/main/java/com/linkwechat/common/core/domain/BaseEntity.java
View file @
5c6ee66
...
@@ -22,6 +22,7 @@ public class BaseEntity implements Serializable
...
@@ -22,6 +22,7 @@ public class BaseEntity implements Serializable
private
static
final
long
serialVersionUID
=
1L
;
private
static
final
long
serialVersionUID
=
1L
;
/** 搜索值 */
/** 搜索值 */
@TableField
(
exist
=
false
)
private
String
searchValue
;
private
String
searchValue
;
/** 创建者 */
/** 创建者 */
...
@@ -39,17 +40,21 @@ public class BaseEntity implements Serializable
...
@@ -39,17 +40,21 @@ public class BaseEntity implements Serializable
private
Date
updateTime
=
new
Date
();
private
Date
updateTime
=
new
Date
();
/** 备注 */
/** 备注 */
@TableField
(
exist
=
false
)
private
String
remark
;
private
String
remark
;
/** 开始时间 */
/** 开始时间 */
@JsonIgnore
@JsonIgnore
@TableField
(
exist
=
false
)
private
String
beginTime
;
private
String
beginTime
;
/** 结束时间 */
/** 结束时间 */
@JsonIgnore
@JsonIgnore
@TableField
(
exist
=
false
)
private
String
endTime
;
private
String
endTime
;
/** 请求参数 */
/** 请求参数 */
@TableField
(
exist
=
false
)
private
Map
<
String
,
Object
>
params
;
private
Map
<
String
,
Object
>
params
;
public
String
getSearchValue
()
public
String
getSearchValue
()
...
...
linkwe-common/src/main/java/com/linkwechat/common/enums/WePosterSubassemblyType.java
0 → 100644
View file @
5c6ee66
package
com
.
linkwechat
.
common
.
enums
;
/**
* 海报组件类型
* @author ws
*/
public
enum
WePosterSubassemblyType
{
/**
* 自定义文本
*/
plainText
(
0
,
"自定义文本"
),
/**
* 图片
*/
picture
(
1
,
"图片"
),
/**
* 二维码
*/
QRCode
(
2
,
"二维码"
);
private
Integer
code
;
private
String
label
;
private
WePosterSubassemblyType
(
Integer
code
,
String
label
){
this
.
code
=
code
;
this
.
label
=
label
;
}
public
Integer
getCode
()
{
return
code
;
}
public
void
setCode
(
Integer
code
)
{
this
.
code
=
code
;
}
public
String
getLabel
()
{
return
label
;
}
public
void
setLabel
(
String
label
)
{
this
.
label
=
label
;
}
}
linkwe-common/src/main/java/com/linkwechat/common/utils/img/ImageUtils.java
0 → 100644
View file @
5c6ee66
This diff is collapsed.
Click to expand it.
linkwe-common/src/main/java/com/linkwechat/common/utils/img/NetFileUtils.java
0 → 100644
View file @
5c6ee66
package
com
.
linkwechat
.
common
.
utils
.
img
;
import
io.netty.buffer.ByteBuf
;
import
io.netty.buffer.Unpooled
;
import
io.vertx.core.Vertx
;
import
io.vertx.core.buffer.Buffer
;
import
io.vertx.ext.web.client.WebClient
;
import
java.awt.*
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.util.concurrent.Callable
;
import
java.util.concurrent.CountDownLatch
;
import
java.util.concurrent.TimeUnit
;
/**
* @author ws
*/
public
class
NetFileUtils
{
private
static
final
Vertx
vertx
=
Vertx
.
vertx
();
private
static
final
WebClient
webClient
=
WebClient
.
create
(
vertx
);
public
static
void
main
(
String
[]
args
)
{
FileCallable
fileCallable
=
getNetFile
(
"https://pc-index-skin.cdn.bcebos.com/hiphoto/51631423522.jpg?x-bce-process=image/crop,x_0,y_13,w_1999,h_1250"
);
getByteArrayOutputStream
(
fileCallable
,
true
);
}
public
static
FileCallable
getNetFile
(
String
urlPath
){
FileCallable
fileCallable
=
new
FileCallable
();
webClient
.
getAbs
(
urlPath
).
send
().
onSuccess
(
response
->
{
if
(
response
.
statusCode
()
==
200
||
response
.
statusCode
()
==
302
){
Buffer
buffer
=
response
.
body
();
buffer
.
getByteBuf
();
byte
[]
bytes
=
buffer
.
getBytes
();
fileCallable
.
setFile
(
bytes
);
}
else
{
fileCallable
.
error
();
}
}).
onFailure
(
throwable
->
{
fileCallable
.
error
();
throwable
.
printStackTrace
();
});
return
fileCallable
;
}
public
static
ByteArrayOutputStream
getByteArrayOutputStream
(
FileCallable
fileCallable
,
boolean
clearBuf
){
try
{
ByteBuf
byteBuf
=
fileCallable
.
call
();
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
int
byteLength
=
1024
;
byte
[]
bytes
=
new
byte
[
byteLength
];
int
length
=
0
;
while
((
length
=
byteBuf
.
readableBytes
())
>
0
){
byteBuf
.
readBytes
(
bytes
,
0
,
Math
.
min
(
length
,
byteLength
));
byteArrayOutputStream
.
write
(
bytes
,
0
,
Math
.
min
(
length
,
byteLength
));
}
if
(!
clearBuf
){
byteBuf
.
resetReaderIndex
();
}
else
{
byteBuf
.
clear
();
}
return
byteArrayOutputStream
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
public
static
class
FileCallable
implements
Callable
<
ByteBuf
>{
private
final
CountDownLatch
countDownLatch
=
new
CountDownLatch
(
1
);
private
volatile
ByteBuf
byteBuf
;
/**
* Computes a result, or throws an exception if unable to do so.
*
* @return computed result
* @throws Exception if unable to compute a result
*/
@Override
public
ByteBuf
call
()
throws
Exception
{
boolean
k
=
countDownLatch
.
await
(
10
,
TimeUnit
.
MINUTES
);
if
(
k
&&
byteBuf
!=
null
){
return
byteBuf
;
}
else
{
throw
new
RuntimeException
(
"获取失败"
);
}
}
public
void
setFile
(
byte
[]
bytes
){
ByteBuf
byteBuf
=
Unpooled
.
directBuffer
();
byteBuf
.
writeBytes
(
bytes
);
this
.
byteBuf
=
byteBuf
;
countDownLatch
.
countDown
();
}
public
void
error
(){
countDownLatch
.
countDown
();
}
}
}
linkwe-framework/pom.xml
View file @
5c6ee66
...
@@ -75,6 +75,15 @@
...
@@ -75,6 +75,15 @@
<artifactId>
linkwe-wecom
</artifactId>
<artifactId>
linkwe-wecom
</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>
io.vertx
</groupId>
<artifactId>
vertx-core
</artifactId>
</dependency>
<dependency>
<groupId>
io.vertx
</groupId>
<artifactId>
vertx-web-client
</artifactId>
</dependency>
</dependencies>
</dependencies>
...
...
linkwe-wecom/src/main/java/com/linkwechat/wecom/domain/WePoster.java
0 → 100644
View file @
5c6ee66
package
com
.
linkwechat
.
wecom
.
domain
;
import
com.alibaba.fastjson.JSON
;
import
com.baomidou.mybatisplus.annotation.TableField
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
com.linkwechat.common.core.domain.BaseEntity
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* 海报
* @author ws
*/
@EqualsAndHashCode
(
callSuper
=
true
)
@Data
@TableName
(
value
=
"we_poster"
)
public
class
WePoster
extends
BaseEntity
{
@TableId
private
Long
id
;
/**
* 海报标题
*/
@TableField
private
String
title
;
/**
* 背景图片
*/
@TableField
private
String
backgroundImgPath
;
/**
* 示例图片
*/
@TableField
private
String
sampleImgPath
;
/**
* 海报类型 1 通用海报
*/
@TableField
private
Long
type
;
@TableField
private
Integer
delFlag
;
@TableField
private
Integer
width
;
@TableField
private
Integer
height
;
/**
* 海报组件数组
*/
@TableField
(
exist
=
false
)
private
List
<
WePosterSubassembly
>
posterSubassemblyList
;
public
static
void
main
(
String
[]
args
)
{
WePoster
wePoster
=
new
WePoster
();
wePoster
.
setDelFlag
(
1
);
wePoster
.
setTitle
(
"你好世界"
);
wePoster
.
setHeight
(
1000
);
wePoster
.
setWidth
(
1000
);
wePoster
.
setType
(
1L
);
wePoster
.
setBackgroundImgPath
(
"1"
);
wePoster
.
setPosterSubassemblyList
(
new
ArrayList
<>());
for
(
int
i
=
0
;
i
<
1
;
i
++){
WePosterSubassembly
subassembly
=
new
WePosterSubassembly
();
subassembly
.
setFontColor
(
"#544875"
);
subassembly
.
setFontId
(
1L
);
subassembly
.
setHeight
(
100
);
subassembly
.
setWidth
(
100
);
subassembly
.
setDelFlag
(
1
);
subassembly
.
setLeft
(
1
);
subassembly
.
setTop
(
1
);
subassembly
.
setFontTextAlign
(
1
);
wePoster
.
getPosterSubassemblyList
().
add
(
subassembly
);
}
System
.
out
.
println
(
JSON
.
toJSONString
(
wePoster
));
}
}
linkwe-wecom/src/main/java/com/linkwechat/wecom/domain/WePosterFont.java
0 → 100644
View file @
5c6ee66
package
com
.
linkwechat
.
wecom
.
domain
;
import
com.baomidou.mybatisplus.annotation.TableField
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
com.linkwechat.common.core.domain.BaseEntity
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
/**
* 海报字体实体
* @author ws
*/
@EqualsAndHashCode
(
callSuper
=
true
)
@Data
@TableName
(
value
=
"we_poster_font"
)
public
class
WePosterFont
extends
BaseEntity
{
/**
* id
*/
@TableId
private
Long
id
;
/**
* 字体名称
*/
@TableField
(
value
=
"font_name"
)
private
String
fontName
;
/**
* 字体网络地址
*/
@TableField
(
value
=
"font_url"
)
private
String
fontUrl
;
/**
* 字体排序
*/
@TableField
(
value
=
"`order`"
)
private
Integer
order
;
/**
* 状态
*/
@TableField
(
value
=
"del_flag"
)
private
Integer
delFlag
;
}
linkwe-wecom/src/main/java/com/linkwechat/wecom/domain/WePosterSubassembly.java
0 → 100644
View file @
5c6ee66
package
com
.
linkwechat
.
wecom
.
domain
;
import
com.baomidou.mybatisplus.annotation.TableField
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
com.linkwechat.common.core.domain.BaseEntity
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
/**
* 海报组成部件
* @author ws
*/
@EqualsAndHashCode
(
callSuper
=
true
)
@Data
@TableName
(
value
=
"we_poster_subassembly"
)
public
class
WePosterSubassembly
extends
BaseEntity
{
@TableId
private
Long
id
;
@TableField
private
Long
posterId
;
/**
* x坐标
*/
@TableField
(
value
=
"`left`"
)
private
Integer
left
;
/**
* y坐标
*/
@TableField
private
Integer
top
;
/**
* 宽度
*/
@TableField
private
Integer
width
;
/**
* 高度
*/
@TableField
private
Integer
height
;
/**
* 类型 1 固定文本 2 固定图片 3 二维码图片
*/
@TableField
private
Integer
type
;
@TableField
private
Long
fontId
;
/**
* 字体大小(像素大小)
*/
@TableField
private
Integer
fontSize
;
/**
* 字体颜色(十六进制)
*/
@TableField
private
String
fontColor
;
/**
* 字体对齐方式 0 左对齐 1居中 2右对齐
*/
@TableField
private
Integer
fontTextAlign
;
/**
* 图片网络地址
*/
@TableField
private
String
imgPath
;
@TableField
private
Integer
delFlag
;
/**
* 文字内容
*/
@TableField
private
String
content
;
/**
* 字体实体
*/
@TableField
(
exist
=
false
)
private
WePosterFont
font
;
}
linkwe-wecom/src/main/java/com/linkwechat/wecom/mapper/WePosterFontMapper.java
0 → 100644
View file @
5c6ee66
package
com
.
linkwechat
.
wecom
.
mapper
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.linkwechat.wecom.domain.WePosterFont
;
/**
* 海报字体
* @author ws
*/
public
interface
WePosterFontMapper
extends
BaseMapper
<
WePosterFont
>
{
}
linkwe-wecom/src/main/java/com/linkwechat/wecom/mapper/WePosterMapper.java
0 → 100644
View file @
5c6ee66
package
com
.
linkwechat
.
wecom
.
mapper
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.linkwechat.wecom.domain.WePoster
;
import
com.linkwechat.wecom.domain.WePosterFont
;
/**
* 海报
* @author ws
*/
public
interface
WePosterMapper
extends
BaseMapper
<
WePoster
>
{
}
linkwe-wecom/src/main/java/com/linkwechat/wecom/mapper/WePosterSubassemblyMapper.java
0 → 100644
View file @
5c6ee66
package
com
.
linkwechat
.
wecom
.
mapper
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.linkwechat.wecom.domain.WePosterFont
;
import
com.linkwechat.wecom.domain.WePosterSubassembly
;
/**
* 海报组件
* @author ws
*/
public
interface
WePosterSubassemblyMapper
extends
BaseMapper
<
WePosterSubassembly
>{
}
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/IWePosterFontService.java
0 → 100644
View file @
5c6ee66
package
com
.
linkwechat
.
wecom
.
service
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.linkwechat.wecom.domain.WePosterFont
;
import
java.awt.*
;
/**
* 海报
* @author ws
*/
public
interface
IWePosterFontService
extends
IService
<
WePosterFont
>
{
/**
* 获取字体
* @param id
* @param size
* @return
*/
public
Font
getFont
(
Long
id
,
Integer
size
);
}
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/IWePosterService.java
0 → 100644
View file @
5c6ee66
package
com
.
linkwechat
.
wecom
.
service
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.linkwechat.wecom.domain.WePoster
;
/**
* 海报
* @author ws
*/
public
interface
IWePosterService
extends
IService
<
WePoster
>
{
/**
* 查询一条
* @param id
* @return
*/
public
WePoster
selectOne
(
Long
id
);
/**
* 生成海报图片地址
* @param poster
* @return
*/
public
String
generateSimpleImg
(
WePoster
poster
);
}
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/IWePosterSubassemblyService.java
0 → 100644
View file @
5c6ee66
package
com
.
linkwechat
.
wecom
.
service
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.linkwechat.wecom.domain.WePosterSubassembly
;
import
java.util.List
;
/**
* 海报
* @author ws
*/
public
interface
IWePosterSubassemblyService
extends
IService
<
WePosterSubassembly
>
{
}
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WePosterFontServiceImpl.java
0 → 100644
View file @
5c6ee66
package
com
.
linkwechat
.
wecom
.
service
.
impl
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.linkwechat.common.utils.img.NetFileUtils
;
import
com.linkwechat.wecom.domain.WePosterFont
;
import
com.linkwechat.wecom.mapper.WePosterFontMapper
;
import
com.linkwechat.wecom.service.IWePosterFontService
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.awt.*
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
/**
* 海报字体
* @author ws
*/
@Service
public
class
WePosterFontServiceImpl
extends
ServiceImpl
<
WePosterFontMapper
,
WePosterFont
>
implements
IWePosterFontService
{
@Resource
private
WePosterFontMapper
wePosterFontMapper
;
/**
* 字体数据缓存
*/
private
final
Map
<
Long
,
Font
>
FONT_MAP
=
new
ConcurrentHashMap
<>();
/**
* 获取字体
*
* @param id
* @param size
* @return
*/
@Override
public
Font
getFont
(
Long
id
,
Integer
size
)
{
WePosterFont
posterFont
=
this
.
getById
(
id
);
if
(
posterFont
==
null
){
throw
new
RuntimeException
(
"字体id为:"
+
id
+
"的字体不存在"
);
}
Font
font
;
if
((
font
=
FONT_MAP
.
get
(
posterFont
.
getId
()))
!=
null
){
return
font
.
deriveFont
((
float
)
size
);
}
ByteArrayInputStream
byteArrayInputStream
=
new
ByteArrayInputStream
(
NetFileUtils
.
getByteArrayOutputStream
(
NetFileUtils
.
getNetFile
(
posterFont
.
getFontUrl
()),
false
).
toByteArray
());
try
{
font
=
Font
.
createFont
(
Font
.
TRUETYPE_FONT
,
byteArrayInputStream
);
FONT_MAP
.
put
(
posterFont
.
getId
(),
font
);
font
=
font
.
deriveFont
((
float
)
size
);
return
font
;
}
catch
(
FontFormatException
e
)
{
e
.
printStackTrace
();
throw
new
RuntimeException
(
"字体格式错误"
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
}
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WePosterServiceImpl.java
0 → 100644
View file @
5c6ee66
package
com
.
linkwechat
.
wecom
.
service
.
impl
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.linkwechat.common.utils.file.FileUploadUtils
;
import
com.linkwechat.common.utils.file.FileUtils
;
import
com.linkwechat.common.utils.img.ImageUtils
;
import
com.linkwechat.common.utils.img.NetFileUtils
;
import
com.linkwechat.wecom.domain.WePoster
;
import
com.linkwechat.wecom.domain.WePosterFont
;
import
com.linkwechat.wecom.domain.WePosterSubassembly
;
import
com.linkwechat.wecom.mapper.WePosterMapper
;
import
com.linkwechat.wecom.service.IWePosterFontService
;
import
com.linkwechat.wecom.service.IWePosterService
;
import
com.linkwechat.wecom.service.IWePosterSubassemblyService
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
javax.annotation.Resource
;
import
javax.imageio.ImageIO
;
import
java.awt.*
;
import
java.awt.image.BufferedImage
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.net.NetworkInterface
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
/**
* 海报字体
*
* @author ws
*/
@Service
public
class
WePosterServiceImpl
extends
ServiceImpl
<
WePosterMapper
,
WePoster
>
implements
IWePosterService
{
@Resource
private
WePosterMapper
wePosterMapper
;
@Resource
private
IWePosterSubassemblyService
posterSubassemblyService
;
@Resource
private
IWePosterFontService
posterFontService
;
/**
* 查询一条
*
* @param id
* @return
*/
@Override
public
WePoster
selectOne
(
Long
id
)
{
WePoster
poster
=
this
.
lambdaQuery
()
.
eq
(
WePoster:
:
getId
,
id
)
.
eq
(
WePoster:
:
getDelFlag
,
1
)
.
getEntity
();
if
(
poster
==
null
)
{
return
null
;
}
poster
.
setPosterSubassemblyList
(
posterSubassemblyService
.
lambdaQuery
().
eq
(
WePosterSubassembly:
:
getPosterId
,
poster
.
getId
()).
list
());
if
(!
CollectionUtils
.
isEmpty
(
poster
.
getPosterSubassemblyList
()))
{
List
<
Long
>
fontIdList
=
poster
.
getPosterSubassemblyList
().
stream
().
filter
(
wePosterSubassembly
->
wePosterSubassembly
.
getFontId
()
!=
null
).
map
(
WePosterSubassembly:
:
getFontId
).
distinct
().
collect
(
Collectors
.
toList
());
if
(!
CollectionUtils
.
isEmpty
(
fontIdList
))
{
List
<
WePosterFont
>
fontList
=
posterFontService
.
lambdaQuery
().
in
(
WePosterFont:
:
getId
,
fontIdList
).
list
();
if
(!
CollectionUtils
.
isEmpty
(
fontList
))
{
Map
<
Long
,
WePosterFont
>
fontMap
=
fontList
.
stream
().
collect
(
Collectors
.
toMap
(
WePosterFont:
:
getId
,
f
->
f
));
poster
.
getPosterSubassemblyList
().
stream
().
filter
(
wePosterSubassembly
->
wePosterSubassembly
.
getFontId
()
!=
null
).
forEach
(
wePosterSubassembly
->
{
WePosterFont
font
=
fontMap
.
get
(
wePosterSubassembly
.
getFontId
());
if
(
font
!=
null
)
{
wePosterSubassembly
.
setFont
(
font
);
}
});
}
}
}
return
poster
;
}
/**
* 生成海报图片地址
*
* @param poster
* @return
*/
@Override
public
String
generateSimpleImg
(
WePoster
poster
)
{
Map
<
Long
,
Font
>
fontMap
=
poster
.
getPosterSubassemblyList
().
stream
().
filter
(
wePosterSubassembly
->
wePosterSubassembly
.
getFontId
()
!=
null
)
.
collect
(
Collectors
.
toMap
(
WePosterSubassembly:
:
getFontId
,
wePosterSubassembly
->
posterFontService
.
getFont
(
wePosterSubassembly
.
getFontId
(),
wePosterSubassembly
.
getFontSize
())));
Map
<
String
,
NetFileUtils
.
FileCallable
>
fileCallableMap
=
poster
.
getPosterSubassemblyList
().
stream
().
filter
(
wePosterSubassembly
->
StringUtils
.
isNotBlank
(
wePosterSubassembly
.
getImgPath
())).
distinct
().
collect
(
Collectors
.
toMap
(
WePosterSubassembly:
:
getImgPath
,
wePosterSubassembly
->
{
return
NetFileUtils
.
getNetFile
(
wePosterSubassembly
.
getImgPath
());
}));
if
(
CollectionUtils
.
isEmpty
(
fileCallableMap
))
{
fileCallableMap
=
new
HashMap
<>();
}
fileCallableMap
.
put
(
poster
.
getBackgroundImgPath
(),
NetFileUtils
.
getNetFile
(
poster
.
getBackgroundImgPath
()));
Map
<
String
,
BufferedImage
>
bufferedImageMap
=
fileCallableMap
.
entrySet
().
stream
().
collect
(
Collectors
.
toMap
(
stringFileCallableEntry
->
stringFileCallableEntry
.
getKey
(),
stringFileCallableEntry
->
{
try
{
return
ImageIO
.
read
(
new
ByteArrayInputStream
(
NetFileUtils
.
getByteArrayOutputStream
(
stringFileCallableEntry
.
getValue
(),
false
).
toByteArray
()));
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
throw
new
RuntimeException
(
"图片读取错误"
);
}
}));
BufferedImage
backgroundImg
=
bufferedImageMap
.
get
(
poster
.
getBackgroundImgPath
());
poster
.
getPosterSubassemblyList
().
forEach
(
wePosterSubassembly
->
{
if
(
wePosterSubassembly
.
getFontId
()
!=
null
)
{
Font
font
=
fontMap
.
get
(
wePosterSubassembly
.
getFontId
());
FontMetrics
fontMetrics
=
ImageUtils
.
getFontMetrics
(
font
);
Color
color
;
if
(
StringUtils
.
isNotBlank
(
wePosterSubassembly
.
getFontColor
()))
{
color
=
ImageUtils
.
getColor
(
wePosterSubassembly
.
getFontColor
());
}
else
{
color
=
Color
.
BLACK
;
}
List
<
ImageUtils
.
LineText
>
lineTextList
=
ImageUtils
.
splitContext
(
wePosterSubassembly
.
getContent
(),
fontMetrics
,
wePosterSubassembly
.
getLeft
(),
wePosterSubassembly
.
getTop
(),
wePosterSubassembly
.
getWidth
(),
wePosterSubassembly
.
getHeight
(),
wePosterSubassembly
.
getFontTextAlign
());
lineTextList
.
forEach
(
lineText
->
{
ImageUtils
.
writeFontBufferedImage
(
backgroundImg
,
lineText
.
getText
(),
lineText
.
getPointX
(),
lineText
.
getPointY
(),
font
,
color
);
});
}
else
{
BufferedImage
bufferedImage
=
bufferedImageMap
.
get
(
wePosterSubassembly
.
getImgPath
());
bufferedImage
=
ImageUtils
.
fixedDimensionBufferedImage
(
bufferedImage
,
BufferedImage
.
TYPE_INT_RGB
,
wePosterSubassembly
.
getWidth
(),
wePosterSubassembly
.
getHeight
());
ImageUtils
.
mergeBufferedImage
(
backgroundImg
,
bufferedImage
,
wePosterSubassembly
.
getLeft
(),
wePosterSubassembly
.
getTop
());
}
});
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
try
{
ImageIO
.
write
(
backgroundImg
,
"jpg"
,
byteArrayOutputStream
);
ImageUtils
.
byteToFile
(
byteArrayOutputStream
.
toByteArray
(),
"测试"
+
System
.
currentTimeMillis
(),
"jpg"
,
"D:/网页/"
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
throw
new
RuntimeException
(
"图片生成错误"
);
}
return
null
;
}
}
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WePosterSubassemblyServiceImpl.java
0 → 100644
View file @
5c6ee66
package
com
.
linkwechat
.
wecom
.
service
.
impl
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.linkwechat.wecom.domain.WePosterSubassembly
;
import
com.linkwechat.wecom.mapper.WePosterSubassemblyMapper
;
import
com.linkwechat.wecom.service.IWePosterSubassemblyService
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.util.List
;
/**
* 海报字体
* @author ws
*/
@Service
public
class
WePosterSubassemblyServiceImpl
extends
ServiceImpl
<
WePosterSubassemblyMapper
,
WePosterSubassembly
>
implements
IWePosterSubassemblyService
{
@Resource
private
WePosterSubassemblyMapper
wePosterSubassemblyMapper
;
}
linkwe-wecom/src/main/resources/mapper/wecom/WeposterFontMapper.xml
0 → 100644
View file @
5c6ee66
<?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=
"com.linkwechat.wecom.mapper.WePosterFontMapper"
>
</mapper>
\ No newline at end of file
\ No newline at end of file
linkwe-wecom/src/main/resources/mapper/wecom/WeposterMapper.xml
0 → 100644
View file @
5c6ee66
<?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=
"com.linkwechat.wecom.mapper.WePosterMapper"
>
</mapper>
\ No newline at end of file
\ No newline at end of file
linkwe-wecom/src/main/resources/mapper/wecom/WeposterSubassemblyMapper.xml
0 → 100644
View file @
5c6ee66
<?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=
"com.linkwechat.wecom.mapper.WePosterSubassemblyMapper"
>
</mapper>
\ No newline at end of file
\ No newline at end of file
pom.xml
View file @
5c6ee66
...
@@ -37,12 +37,22 @@
...
@@ -37,12 +37,22 @@
<hutool.version>
5.4.1
</hutool.version>
<hutool.version>
5.4.1
</hutool.version>
<zxing.version>
3.3.3
</zxing.version>
<zxing.version>
3.3.3
</zxing.version>
<mybatis-plus.version>
3.4.0
</mybatis-plus.version>
<mybatis-plus.version>
3.4.0
</mybatis-plus.version>
<vertx.version>
4.0.0
</vertx.version>
<netty-version>
4.1.49.Final
</netty-version>
</properties>
</properties>
<!-- 依赖声明 -->
<!-- 依赖声明 -->
<dependencyManagement>
<dependencyManagement>
<dependencies>
<dependencies>
<dependency>
<groupId>
io.netty
</groupId>
<artifactId>
netty-bom
</artifactId>
<version>
${netty-version}
</version>
<type>
pom
</type>
<scope>
import
</scope>
</dependency>
<!-- SpringBoot的依赖配置-->
<!-- SpringBoot的依赖配置-->
<dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
...
@@ -235,8 +245,17 @@
...
@@ -235,8 +245,17 @@
<version>
${mybatis-plus.version}
</version>
<version>
${mybatis-plus.version}
</version>
</dependency>
</dependency>
<dependency>
<groupId>
io.vertx
</groupId>
<artifactId>
vertx-core
</artifactId>
<version>
${vertx.version}
</version>
</dependency>
<dependency>
<groupId>
io.vertx
</groupId>
<artifactId>
vertx-web-client
</artifactId>
<version>
${vertx.version}
</version>
</dependency>
</dependencies>
</dependencies>
</dependencyManagement>
</dependencyManagement>
...
@@ -292,7 +311,7 @@
...
@@ -292,7 +311,7 @@
<enabled>
true
</enabled>
<enabled>
true
</enabled>
</releases>
</releases>
<snapshots>
<snapshots>
<enabled>
fals
e
</enabled>
<enabled>
tru
e
</enabled>
</snapshots>
</snapshots>
</pluginRepository>
</pluginRepository>
</pluginRepositories>
</pluginRepositories>
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment