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 966e6588
authored
Dec 31, 2020
by
星梦苍天
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
海报修改
1 parent
51383025
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
216 additions
and
56 deletions
linkwe-admin/src/main/java/com/linkwechat/web/controller/wecom/WeMaterialController.java
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/src/main/java/com/linkwechat/common/enums/MediaType.java
linkwe-common/src/main/java/com/linkwechat/common/utils/img/ImageUtils.java
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/service/IWePosterFontService.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/IWePosterService.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/resources/font/default.ttf
linkwe-admin/src/main/java/com/linkwechat/web/controller/wecom/WeMaterialController.java
View file @
966e658
...
...
@@ -5,19 +5,24 @@ import com.linkwechat.common.core.controller.BaseController;
import
com.linkwechat.common.core.domain.AjaxResult
;
import
com.linkwechat.common.core.page.TableDataInfo
;
import
com.linkwechat.common.enums.BusinessType
;
import
com.linkwechat.common.enums.MediaType
;
import
com.linkwechat.wecom.domain.WeMaterial
;
import
com.linkwechat.wecom.domain.dto.ResetCategoryDto
;
import
com.linkwechat.wecom.domain.dto.WeMediaDto
;
import
com.linkwechat.wecom.domain.vo.WeMaterialFileVO
;
import
com.linkwechat.wecom.service.IWeMaterialService
;
import
com.linkwechat.wecom.service.IWePosterService
;
import
io.swagger.annotations.ApiOperation
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.ibatis.annotations.Param
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.annotation.Resource
;
import
java.util.List
;
import
java.util.stream.Collectors
;
/**
* 企业微信素材Controller
...
...
@@ -33,6 +38,9 @@ public class WeMaterialController extends BaseController {
@Autowired
private
IWeMaterialService
materialService
;
@Resource
private
IWePosterService
wePosterService
;
/**
* 查询素材列表
*/
...
...
@@ -41,7 +49,19 @@ public class WeMaterialController extends BaseController {
public
TableDataInfo
list
(
@RequestParam
(
value
=
"categoryId"
,
required
=
false
)
String
categoryId
,
@RequestParam
(
value
=
"search"
,
required
=
false
)
String
search
,
@RequestParam
(
value
=
"mediaType"
)
String
mediaType
)
{
startPage
();
List
<
WeMaterial
>
list
=
materialService
.
findWeMaterials
(
categoryId
,
search
,
mediaType
);
List
<
WeMaterial
>
list
;
if
(
StringUtils
.
isNotBlank
(
mediaType
)
&&
mediaType
.
equals
(
MediaType
.
POSTER
.
getType
())){
list
=
wePosterService
.
list
(
Long
.
valueOf
(
categoryId
),
search
).
stream
().
map
(
wePoster
->
{
WeMaterial
weMaterial
=
new
WeMaterial
();
weMaterial
.
setMaterialName
(
wePoster
.
getTitle
());
weMaterial
.
setMaterialUrl
(
wePoster
.
getSampleImgPath
());
weMaterial
.
setId
(
wePoster
.
getId
());
return
weMaterial
;
}).
collect
(
Collectors
.
toList
());
}
else
{
list
=
materialService
.
findWeMaterials
(
categoryId
,
search
,
mediaType
);
}
return
getDataTable
(
list
);
}
...
...
linkwe-admin/src/main/java/com/linkwechat/web/controller/wecom/WePosterController.java
View file @
966e658
...
...
@@ -2,7 +2,10 @@ package com.linkwechat.web.controller.wecom;
import
com.linkwechat.common.core.controller.BaseController
;
import
com.linkwechat.common.core.domain.AjaxResult
;
import
com.linkwechat.common.enums.MediaType
;
import
com.linkwechat.common.utils.SnowFlakeUtil
;
import
com.linkwechat.common.utils.StringUtils
;
import
com.linkwechat.wecom.domain.WeMaterial
;
import
com.linkwechat.wecom.domain.WePoster
;
import
com.linkwechat.wecom.domain.WePosterFont
;
import
com.linkwechat.wecom.domain.WePosterSubassembly
;
...
...
@@ -17,11 +20,15 @@ import org.springframework.web.bind.annotation.*;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.annotation.Resource
;
import
java.awt.*
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
/**
* @author ws
*/
@RestController
@RequestMapping
(
value
=
"wecom/poster/"
)
@Api
(
description
=
"海报"
)
...
...
@@ -43,10 +50,14 @@ public class WePosterController extends BaseController {
public
AjaxResult
insert
(
@RequestBody
WePoster
poster
){
wePosterService
.
generateSimpleImg
(
poster
);
poster
.
setId
(
SnowFlakeUtil
.
nextId
());
poster
.
setDelFlag
(
1
);
poster
.
setDelFlag
(
0
);
poster
.
setMediaType
(
MediaType
.
POSTER
.
getType
());
/*if(poster.getCategoryId() == null){
return AjaxResult.error("请选择海报分类");
}*/
wePosterService
.
saveOrUpdate
(
poster
);
poster
.
getPosterSubassemblyList
().
forEach
(
wePosterSubassembly
->
{
wePosterSubassembly
.
setDelFlag
(
1
);
wePosterSubassembly
.
setDelFlag
(
0
);
wePosterSubassembly
.
setId
(
SnowFlakeUtil
.
nextId
());
wePosterSubassembly
.
setPosterId
(
poster
.
getId
());
});
...
...
@@ -62,6 +73,7 @@ public class WePosterController extends BaseController {
if
(
poster
.
getId
()
==
null
){
return
AjaxResult
.
error
(
"id为空"
);
}
poster
.
setMediaType
(
null
);
wePosterService
.
generateSimpleImg
(
poster
);
wePosterService
.
saveOrUpdate
(
poster
);
List
<
WePosterSubassembly
>
posterSubassemblyList
=
wePosterSubassemblyService
.
lambdaQuery
().
eq
(
WePosterSubassembly:
:
getPosterId
,
poster
.
getId
()).
eq
(
WePosterSubassembly:
:
getDelFlag
,
1
).
list
();
...
...
@@ -72,7 +84,7 @@ public class WePosterController extends BaseController {
if
(
wePosterSubassembly
.
getId
()
==
null
){
wePosterSubassembly
.
setId
(
SnowFlakeUtil
.
nextId
());
wePosterSubassembly
.
setPosterId
(
poster
.
getId
());
wePosterSubassembly
.
setDelFlag
(
1
);
wePosterSubassembly
.
setDelFlag
(
0
);
insertList
.
add
(
wePosterSubassembly
);
}
else
{
posterSubassemblyMap
.
remove
(
wePosterSubassembly
.
getId
());
...
...
@@ -87,21 +99,23 @@ public class WePosterController extends BaseController {
}
List
<
WePosterSubassembly
>
deleteList
=
new
ArrayList
<>(
posterSubassemblyMap
.
values
());
if
(!
CollectionUtils
.
isEmpty
(
deleteList
)){
deleteList
.
forEach
(
wePosterSubassembly
->
wePosterSubassembly
.
setDelFlag
(
0
));
deleteList
.
forEach
(
wePosterSubassembly
->
wePosterSubassembly
.
setDelFlag
(
1
));
wePosterSubassemblyService
.
updateBatchById
(
deleteList
);
}
return
AjaxResult
.
success
(
"修改成功"
);
}
@GetMapping
(
value
=
"list"
)
/*
@GetMapping(value = "list")
@ApiOperation("列表查询海报")
public
AjaxResult
list
(){
public AjaxResult list(
Long categoryId,String name
){
List<WePoster> fontList = wePosterService.lambdaQuery()
.
eq
(
WePoster:
:
getDelFlag
,
1
)
.eq(WePoster::getDelFlag,0)
.eq(categoryId != null,WePoster::getCategoryId,categoryId)
.like(StringUtils.isNotBlank(name),WePoster::getTitle,name)
.orderByDesc(WePoster::getCreateTime)
.list();
return AjaxResult.success(fontList);
}
}
*/
@GetMapping
(
value
=
"entity/{id}"
)
@ApiOperation
(
"查询海报详情"
)
...
...
@@ -111,10 +125,12 @@ public class WePosterController extends BaseController {
@GetMapping
(
value
=
"page"
)
@ApiOperation
(
"分页查询海报"
)
public
AjaxResult
page
(){
public
AjaxResult
page
(
Long
categoryId
,
String
name
){
startPage
();
List
<
WePoster
>
fontList
=
wePosterService
.
lambdaQuery
()
.
eq
(
WePoster:
:
getDelFlag
,
1
)
.
eq
(
WePoster:
:
getDelFlag
,
0
)
.
eq
(
categoryId
!=
null
,
WePoster:
:
getCategoryId
,
categoryId
)
.
like
(
StringUtils
.
isNotBlank
(
name
),
WePoster:
:
getTitle
,
name
)
.
orderByDesc
(
WePoster:
:
getCreateTime
)
.
list
();
return
AjaxResult
.
success
(
getDataTable
(
fontList
));
...
...
@@ -124,11 +140,12 @@ public class WePosterController extends BaseController {
@ApiOperation
(
value
=
"删除海报"
)
@Transactional
(
rollbackFor
=
RuntimeException
.
class
)
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
);
wePosterService
.
lambdaUpdate
().
set
(
WePoster:
:
getDelFlag
,
1
).
eq
(
WePoster:
:
getId
,
id
);
wePosterSubassemblyService
.
lambdaUpdate
().
set
(
WePosterSubassembly:
:
getDelFlag
,
1
).
eq
(
WePosterSubassembly:
:
getPosterId
,
id
);
return
AjaxResult
.
success
(
"删除成功"
);
}
}
linkwe-admin/src/main/java/com/linkwechat/web/controller/wecom/WePosterFontController.java
View file @
966e658
...
...
@@ -2,6 +2,7 @@ package com.linkwechat.web.controller.wecom;
import
com.linkwechat.common.core.controller.BaseController
;
import
com.linkwechat.common.core.domain.AjaxResult
;
import
com.linkwechat.common.enums.MediaType
;
import
com.linkwechat.common.utils.SnowFlakeUtil
;
import
com.linkwechat.web.controller.common.CommonController
;
import
com.linkwechat.wecom.domain.WePosterFont
;
...
...
@@ -14,6 +15,9 @@ import org.springframework.web.bind.annotation.*;
import
javax.annotation.Resource
;
import
java.util.List
;
/**
* @author ws
*/
@RestController
@RequestMapping
(
value
=
"wecom/posterFont/"
)
@Api
(
description
=
"海报字体"
)
...
...
@@ -28,7 +32,8 @@ public class WePosterFontController extends BaseController {
@Transactional
(
rollbackFor
=
RuntimeException
.
class
)
public
AjaxResult
insertPosterFont
(
@RequestBody
WePosterFont
posterFont
){
posterFont
.
setId
(
SnowFlakeUtil
.
nextId
());
posterFont
.
setDelFlag
(
1
);
posterFont
.
setDelFlag
(
0
);
posterFont
.
setMediaType
(
MediaType
.
POSTER_FONT
.
getType
());
wePosterFontService
.
save
(
posterFont
);
return
AjaxResult
.
success
(
"创建成功"
);
}
...
...
@@ -41,6 +46,7 @@ public class WePosterFontController extends BaseController {
if
(
posterFont
.
getId
()
==
null
){
return
AjaxResult
.
error
(
"id为空"
);
}
posterFont
.
setMediaType
(
null
);
wePosterFontService
.
saveOrUpdate
(
posterFont
);
return
AjaxResult
.
success
(
"修改成功"
);
}
...
...
@@ -49,7 +55,7 @@ public class WePosterFontController extends BaseController {
@ApiOperation
(
"列表查询海报字体"
)
public
AjaxResult
selectPosterFontList
(){
List
<
WePosterFont
>
fontList
=
wePosterFontService
.
lambdaQuery
()
.
eq
(
WePosterFont:
:
getDelFlag
,
1
)
.
eq
(
WePosterFont:
:
getDelFlag
,
0
)
.
orderByDesc
(
WePosterFont:
:
getOrder
)
.
orderByDesc
(
WePosterFont:
:
getCreateTime
)
.
list
();
...
...
@@ -61,7 +67,7 @@ public class WePosterFontController extends BaseController {
public
AjaxResult
selectPosterFontPage
(){
startPage
();
List
<
WePosterFont
>
fontList
=
wePosterFontService
.
lambdaQuery
()
.
eq
(
WePosterFont:
:
getDelFlag
,
1
)
.
eq
(
WePosterFont:
:
getDelFlag
,
0
)
.
orderByDesc
(
WePosterFont:
:
getOrder
)
.
orderByDesc
(
WePosterFont:
:
getCreateTime
)
.
list
();
...
...
@@ -72,7 +78,7 @@ public class WePosterFontController extends BaseController {
@ApiOperation
(
"删除海报字体"
)
@Transactional
(
rollbackFor
=
RuntimeException
.
class
)
public
AjaxResult
deletePosterFont
(
@PathVariable
Long
id
){
wePosterFontService
.
lambdaUpdate
().
set
(
WePosterFont:
:
getDelFlag
,
0
).
eq
(
WePosterFont:
:
getId
,
id
);
wePosterFontService
.
lambdaUpdate
().
set
(
WePosterFont:
:
getDelFlag
,
1
).
eq
(
WePosterFont:
:
getId
,
id
);
return
AjaxResult
.
success
(
"删除成功"
);
}
...
...
linkwe-common/src/main/java/com/linkwechat/common/enums/MediaType.java
View file @
966e658
...
...
@@ -14,7 +14,15 @@ public enum MediaType {
IMAGE
(
"0"
,
"image"
),
VOICE
(
"1"
,
"voice"
),
VIDEO
(
"2"
,
"video"
),
FILE
(
"3"
,
"file"
);
FILE
(
"3"
,
"file"
),
/**
* 海报
*/
POSTER
(
"5"
,
"poster"
),
/**
* 海报字体
*/
POSTER_FONT
(
"6"
,
"poster_font"
);
/**
* 媒体类型
...
...
@@ -22,7 +30,7 @@ public enum MediaType {
String
mediaType
;
/**
* 0 图片(image)、1 语音(voice)、2 视频(video),3 普通文件(file) 4 文本
* 0 图片(image)、1 语音(voice)、2 视频(video),3 普通文件(file) 4 文本
5 海报 6 海报字体
*/
String
type
;
...
...
linkwe-common/src/main/java/com/linkwechat/common/utils/img/ImageUtils.java
View file @
966e658
This diff is collapsed.
Click to expand it.
linkwe-wecom/src/main/java/com/linkwechat/wecom/domain/WePoster.java
View file @
966e658
...
...
@@ -57,7 +57,7 @@ public class WePoster extends BaseEntity {
private
Long
type
;
@TableField
@ApiModelProperty
(
value
=
"海报状态
1 启用 0
关闭"
)
@ApiModelProperty
(
value
=
"海报状态
0 启用 1
关闭"
)
private
Integer
delFlag
;
@TableField
...
...
@@ -68,6 +68,14 @@ public class WePoster extends BaseEntity {
@ApiModelProperty
(
value
=
"海报背景高度"
)
private
Integer
height
;
@TableField
@ApiModelProperty
(
"资源类型"
)
private
String
mediaType
;
@TableField
@ApiModelProperty
(
"分类id"
)
private
Long
categoryId
;
/**
* 海报组件数组
*/
...
...
linkwe-wecom/src/main/java/com/linkwechat/wecom/domain/WePosterFont.java
View file @
966e658
...
...
@@ -50,6 +50,14 @@ public class WePosterFont extends BaseEntity {
* 状态
*/
@TableField
(
value
=
"del_flag"
)
@ApiModelProperty
(
value
=
"
1 启用 0
关闭"
)
@ApiModelProperty
(
value
=
"
0 启用 1
关闭"
)
private
Integer
delFlag
;
@TableField
@ApiModelProperty
(
"资源类型"
)
private
String
mediaType
;
@TableField
@ApiModelProperty
(
"分类id"
)
private
Long
categoryId
;
}
linkwe-wecom/src/main/java/com/linkwechat/wecom/domain/WePosterSubassembly.java
View file @
966e658
...
...
@@ -84,8 +84,15 @@ public class WePosterSubassembly extends BaseEntity {
* 字体对齐方式 0 左对齐 1居中 2右对齐
*/
@TableField
@ApiModelProperty
(
value
=
"字体对齐方式 0 左对齐 1居中 2右对齐"
)
private
Integer
fontTextAlign
;
@ApiModelProperty
(
value
=
"字体对齐方式 1 左对齐 2 居中 3右对齐"
)
private
Integer
fontTextAlign
=
2
;
/**
* 字体垂直对齐方式 0 上对齐 1居中 2下对齐
*/
@TableField
@ApiModelProperty
(
value
=
"字体垂直对齐方式 1 上对齐 2 居中 3 下对齐"
)
private
Integer
verticalType
=
2
;
/**
* 图片网络地址
...
...
@@ -95,7 +102,7 @@ public class WePosterSubassembly extends BaseEntity {
private
String
imgPath
;
@TableField
@ApiModelProperty
(
value
=
"
1 启用 0
删除"
)
@ApiModelProperty
(
value
=
"
0 启用 1
删除"
)
private
Integer
delFlag
;
/**
...
...
@@ -105,6 +112,29 @@ public class WePosterSubassembly extends BaseEntity {
@ApiModelProperty
(
value
=
"文本内容"
)
private
String
content
;
@TableField
@ApiModelProperty
(
"字间距"
)
private
Integer
wordSpace
=
0
;
@TableField
@ApiModelProperty
(
"行间距"
)
private
Integer
lineSpace
=
0
;
@TableField
@ApiModelProperty
(
"透明度[0,255]"
)
private
Integer
alpha
;
@TableField
@ApiModelProperty
(
"旋转角度(顺时针)"
)
private
Integer
rotate
;
@TableField
@ApiModelProperty
(
"字体类型 0 通常 1 粗体 2 斜体"
)
private
Integer
fontStyle
=
0
;
@TableField
(
value
=
"`order`"
)
@ApiModelProperty
(
"顺序排序"
)
private
Integer
order
;
/**
* 字体实体
*/
...
...
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/IWePosterFontService.java
View file @
966e658
...
...
@@ -13,10 +13,11 @@ public interface IWePosterFontService extends IService<WePosterFont> {
/**
* 获取字体
* @param id
* @param size
* @param id 字体id
* @param size 字体大小
* @param fontStyle 字体类型 0 通常 1 粗体 2 斜体
* @return
*/
public
Font
getFont
(
Long
id
,
Integer
size
);
public
Font
getFont
(
Long
id
,
Integer
size
,
Integer
fontStyle
);
}
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/IWePosterService.java
View file @
966e658
package
com
.
linkwechat
.
wecom
.
service
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.linkwechat.common.core.domain.AjaxResult
;
import
com.linkwechat.wecom.domain.WePoster
;
import
java.util.List
;
/**
* 海报
* @author ws
...
...
@@ -16,6 +19,14 @@ public interface IWePosterService extends IService<WePoster> {
*/
public
WePoster
selectOne
(
Long
id
);
/**
* 列表查询海报
* @param categoryId
* @param name
* @return
*/
public
List
<
WePoster
>
list
(
Long
categoryId
,
String
name
);
/**
* 生成海报图片地址
...
...
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WePosterFontServiceImpl.java
View file @
966e658
package
com
.
linkwechat
.
wecom
.
service
.
impl
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.linkwechat.common.utils.html.EscapeUtil
;
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
lombok.extern.java.Log
;
import
lombok.extern.log4j.Log4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.stereotype.Service
;
...
...
@@ -22,8 +25,24 @@ import java.util.concurrent.ConcurrentHashMap;
* @author ws
*/
@Service
@Log
public
class
WePosterFontServiceImpl
extends
ServiceImpl
<
WePosterFontMapper
,
WePosterFont
>
implements
IWePosterFontService
{
private
static
Font
DEFAULT_FONT
;
static
{
try
{
DEFAULT_FONT
=
Font
.
createFont
(
Font
.
TRUETYPE_FONT
,
WePosterFontServiceImpl
.
class
.
getResourceAsStream
(
"/font/default.ttf"
));
log
.
info
(
"字体文件读取成功"
);
}
catch
(
FontFormatException
e
)
{
e
.
printStackTrace
();
log
.
info
(
"字体加载失败"
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
log
.
info
(
"字体文件读取失败"
);
}
}
@Resource
private
WePosterFontMapper
wePosterFontMapper
;
...
...
@@ -34,15 +53,16 @@ public class WePosterFontServiceImpl extends ServiceImpl<WePosterFontMapper,WePo
private
final
Map
<
Long
,
Font
>
FONT_MAP
=
new
ConcurrentHashMap
<>();
/**
* 获取字体
*
* @param id
* @param size
* @return
*/
@Override
public
Font
getFont
(
Long
id
,
Integer
size
)
{
public
Font
getFont
(
Long
id
,
Integer
size
,
Integer
fontStyle
)
{
if
(
id
==
null
||
id
.
equals
(
0L
)){
if
(
fontStyle
>
0
){
return
DEFAULT_FONT
.
deriveFont
(
fontStyle
.
equals
(
1
)?
Font
.
BOLD
:
Font
.
ITALIC
,(
float
)
size
);
}
else
{
return
DEFAULT_FONT
.
deriveFont
((
float
)
size
);
}
}
WePosterFont
posterFont
=
this
.
getById
(
id
);
if
(
posterFont
==
null
){
throw
new
RuntimeException
(
"字体id为:"
+
id
+
"的字体不存在"
);
...
...
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WePosterServiceImpl.java
View file @
966e658
package
com
.
linkwechat
.
wecom
.
service
.
impl
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.linkwechat.common.config.RuoYiConfig
;
import
com.linkwechat.common.config.ServerConfig
;
import
com.linkwechat.common.utils.file.FileUploadUtils
;
import
com.linkwechat.common.utils.file.FileUtils
;
import
com.linkwechat.common.utils.img.ImageUtils
;
...
...
@@ -28,10 +30,8 @@ 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.*
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
/**
...
...
@@ -51,6 +51,9 @@ public class WePosterServiceImpl extends ServiceImpl<WePosterMapper, WePoster> i
@Resource
private
IWePosterFontService
posterFontService
;
@Resource
private
ServerConfig
serverConfig
;
/**
* 查询一条
...
...
@@ -62,7 +65,7 @@ public class WePosterServiceImpl extends ServiceImpl<WePosterMapper, WePoster> i
public
WePoster
selectOne
(
Long
id
)
{
WePoster
poster
=
this
.
lambdaQuery
()
.
eq
(
WePoster:
:
getId
,
id
)
.
eq
(
WePoster:
:
getDelFlag
,
1
)
.
eq
(
WePoster:
:
getDelFlag
,
0
)
.
list
().
get
(
0
);
if
(
poster
==
null
)
{
return
null
;
...
...
@@ -89,6 +92,18 @@ public class WePosterServiceImpl extends ServiceImpl<WePosterMapper, WePoster> i
return
poster
;
}
@Override
public
List
<
WePoster
>
list
(
Long
categoryId
,
String
name
)
{
List
<
WePoster
>
fontList
=
this
.
lambdaQuery
()
.
eq
(
WePoster:
:
getDelFlag
,
0
)
.
eq
(
categoryId
!=
null
,
WePoster:
:
getCategoryId
,
categoryId
)
.
like
(
com
.
linkwechat
.
common
.
utils
.
StringUtils
.
isNotBlank
(
name
),
WePoster:
:
getTitle
,
name
)
.
orderByDesc
(
WePoster:
:
getCreateTime
)
.
list
();
return
fontList
;
}
/**
* 生成海报图片地址
*
...
...
@@ -97,18 +112,21 @@ public class WePosterServiceImpl extends ServiceImpl<WePosterMapper, WePoster> i
*/
@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
());
}));
Map
<
Long
,
Font
>
fontMap
=
poster
.
getPosterSubassemblyList
().
stream
().
filter
(
wePosterSubassembly
->
wePosterSubassembly
.
getType
().
equals
(
1
))
.
peek
(
wePosterSubassembly
->
{
if
(
wePosterSubassembly
.
getFontId
()
==
null
){
wePosterSubassembly
.
setFontId
(
0L
);
}
})
.
collect
(
Collectors
.
toMap
(
WePosterSubassembly:
:
getFontId
,
wePosterSubassembly
->
posterFontService
.
getFont
(
wePosterSubassembly
.
getFontId
(),
wePosterSubassembly
.
getFontSize
(),
wePosterSubassembly
.
getFontStyle
())));
Map
<
String
,
NetFileUtils
.
FileCallable
>
fileCallableMap
=
poster
.
getPosterSubassemblyList
().
stream
().
filter
(
wePosterSubassembly
->
StringUtils
.
isNotBlank
(
wePosterSubassembly
.
getImgPath
())).
distinct
().
collect
(
Collectors
.
toMap
(
WePosterSubassembly:
:
getImgPath
,
wePosterSubassembly
->
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
->
{
Map
<
String
,
BufferedImage
>
bufferedImageMap
=
fileCallableMap
.
entrySet
().
stream
().
collect
(
Collectors
.
toMap
(
Map
.
Entry
::
getKey
,
stringFileCallableEntry
->
{
try
{
return
Image
IO
.
read
(
new
ByteArrayInputStream
(
NetFileUtils
.
getByteArrayOutputStream
(
stringFileCallableEntry
.
getValue
(),
false
).
toByteArray
())
);
return
Image
Utils
.
copyBufferedImage
(
ImageIO
.
read
(
new
ByteArrayInputStream
(
Objects
.
requireNonNull
(
NetFileUtils
.
getByteArrayOutputStream
(
stringFileCallableEntry
.
getValue
(),
false
)).
toByteArray
())),
BufferedImage
.
TYPE_INT_ARGB
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
throw
new
RuntimeException
(
"图片读取错误"
);
...
...
@@ -118,35 +136,48 @@ public class WePosterServiceImpl extends ServiceImpl<WePosterMapper, WePoster> i
poster
.
setWidth
(
backgroundImg
.
getWidth
());
poster
.
setHeight
(
backgroundImg
.
getHeight
());
poster
.
getPosterSubassemblyList
().
forEach
(
wePosterSubassembly
->
{
if
(
wePosterSubassembly
.
get
FontId
()
!=
null
)
{
if
(
wePosterSubassembly
.
get
Type
().
equals
(
1
)
)
{
Font
font
=
fontMap
.
get
(
wePosterSubassembly
.
getFontId
());
FontMetrics
fontMetrics
=
ImageUtils
.
getFontMetrics
(
font
);
Color
color
;
if
(
StringUtils
.
isNotBlank
(
wePosterSubassembly
.
getFontColor
()))
{
color
=
ImageUtils
.
getColor
(
wePosterSubassembly
.
getFontColor
());
color
=
ImageUtils
.
getColor
(
wePosterSubassembly
.
getFontColor
()
,
wePosterSubassembly
.
getAlpha
()
);
}
else
{
color
=
Color
.
BLACK
;
}
List
<
ImageUtils
.
LineText
>
lineTextList
=
ImageUtils
.
splitContext
(
wePosterSubassembly
.
getContent
(),
fontMetrics
,
wePosterSubassembly
.
getLeft
(),
wePosterSubassembly
.
getTop
(),
wePosterSubassembly
.
getWidth
(),
wePosterSubassembly
.
getHeight
(),
wePosterSubassembly
.
getFontTextAlign
());
List
<
ImageUtils
.
LineText
>
lineTextList
=
ImageUtils
.
splitContext
(
wePosterSubassembly
.
getContent
(),
fontMetrics
,
wePosterSubassembly
.
getLeft
(),
wePosterSubassembly
.
getTop
(),
wePosterSubassembly
.
getWidth
(),
wePosterSubassembly
.
getHeight
(),
wePosterSubassembly
.
getWordSpace
(),
wePosterSubassembly
.
getLineSpace
(),
wePosterSubassembly
.
getFontTextAlign
(),
wePosterSubassembly
.
getVerticalType
());
lineTextList
.
forEach
(
lineText
->
{
ImageUtils
.
writeFontBufferedImage
(
backgroundImg
,
lineText
.
getText
(),
lineText
.
getPointX
(),
lineText
.
getPointY
(),
font
,
color
);
}
);
lineText
.
getCharTextList
().
forEach
(
charText
->
{
ImageUtils
.
writeFontBufferedImage
(
backgroundImg
,
charText
.
getValue
().
toString
(),
charText
.
getPointX
(),
charText
.
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
());
if
(
wePosterSubassembly
.
getAlpha
()
!=
null
&&
wePosterSubassembly
.
getAlpha
()
>=
0
){
bufferedImage
=
ImageUtils
.
setBufferedImageAlpha
(
bufferedImage
,
wePosterSubassembly
.
getAlpha
(),
BufferedImage
.
TYPE_INT_ARGB
);
}
bufferedImage
=
ImageUtils
.
fixedDimensionBufferedImage
(
bufferedImage
,
BufferedImage
.
TYPE_INT_ARGB
,
wePosterSubassembly
.
getWidth
(),
wePosterSubassembly
.
getHeight
());
if
(
wePosterSubassembly
.
getRotate
()
==
null
){
ImageUtils
.
mergeBufferedImage
(
backgroundImg
,
bufferedImage
,
wePosterSubassembly
.
getLeft
(),
wePosterSubassembly
.
getTop
());
}
else
{
int
x
=
wePosterSubassembly
.
getLeft
()
+
bufferedImage
.
getWidth
()/
2
;
int
y
=
wePosterSubassembly
.
getTop
()
+
bufferedImage
.
getHeight
()/
2
;
bufferedImage
=
ImageUtils
.
rotateImage
(
bufferedImage
,
wePosterSubassembly
.
getRotate
());
x
=
x
-
bufferedImage
.
getWidth
()
/
2
;
y
=
y
-
bufferedImage
.
getHeight
()
/
2
;
ImageUtils
.
mergeBufferedImage
(
backgroundImg
,
bufferedImage
,
x
,
y
);
}
}
});
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
try
{
ImageIO
.
write
(
backgroundImg
,
"
jp
g"
,
byteArrayOutputStream
);
ImageIO
.
write
(
backgroundImg
,
"
pn
g"
,
byteArrayOutputStream
);
NetFileUtils
.
StreamMultipartFile
streamMultipartFile
=
new
NetFileUtils
.
StreamMultipartFile
(
System
.
currentTimeMillis
()+
".jpg"
,
byteArrayOutputStream
.
toByteArray
());
byteArrayOutputStream
.
close
();
String
path
=
FileUploadUtils
.
uploadFile
(
streamMultipartFile
);
poster
.
setSampleImgPath
(
path
);
poster
.
setSampleImgPath
(
serverConfig
.
getUrl
()
+
path
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
throw
new
RuntimeException
(
"图片生成错误"
);
...
...
linkwe-wecom/src/main/resources/font/default.ttf
0 → 100644
View file @
966e658
No preview for this file type
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