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 a252a346
authored
May 07, 2021
by
水库浪子
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
优化替换素材分类的持久层为mybatis-plus
1 parent
82c2ac17
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
94 additions
and
234 deletions
linkwe-admin/src/main/java/com/linkwechat/web/controller/wecom/WeCategoryController.java
linkwe-admin/src/main/java/com/linkwechat/web/controller/wecom/WeMaterialController.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/domain/WeCategory.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/mapper/WeCategoryMapper.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/IWeCategoryService.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WeCategoryServiceImpl.java
linkwe-wecom/src/main/resources/mapper/wecom/WeCategoryMapper.xml
linkwe-admin/src/main/java/com/linkwechat/web/controller/wecom/WeCategoryController.java
View file @
a252a34
package
com
.
linkwechat
.
web
.
controller
.
wecom
;
import
com.linkwechat.common.annotation.Log
;
import
com.linkwechat.common.constant.Constants
;
import
com.linkwechat.common.core.controller.BaseController
;
import
com.linkwechat.common.core.domain.AjaxResult
;
import
com.linkwechat.common.core.domain.Tree
;
import
com.linkwechat.common.enums.BusinessType
;
import
com.linkwechat.wecom.domain.WeCategory
;
import
com.linkwechat.wecom.service.IWeCategoryService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
...
...
@@ -22,14 +25,14 @@ import java.util.List;
*/
@RestController
@RequestMapping
(
"/wecom/category"
)
@Api
(
"企业微信素材分类"
)
public
class
WeCategoryController
extends
BaseController
{
@Autowired
private
IWeCategoryService
weCategoryService
;
/**
* 类目树
*/
// @PreAuthorize("@ss.hasPermi('wechat:category:list')")
@GetMapping
(
"/list"
)
@ApiOperation
(
"类目树"
)
...
...
@@ -44,7 +47,7 @@ public class WeCategoryController extends BaseController {
@GetMapping
(
value
=
"/{id}"
)
@ApiOperation
(
"通过id查询类目详细信息"
)
public
AjaxResult
getInfo
(
@PathVariable
(
"id"
)
Long
id
)
{
return
AjaxResult
.
success
(
weCategoryService
.
findWeCategory
ById
(
id
));
return
AjaxResult
.
success
(
weCategoryService
.
get
ById
(
id
));
}
/**
...
...
@@ -55,7 +58,8 @@ public class WeCategoryController extends BaseController {
@PostMapping
@ApiOperation
(
"添加类目"
)
public
AjaxResult
add
(
@RequestBody
WeCategory
category
)
{
return
toAjax
(
weCategoryService
.
insertWeCategory
(
category
));
weCategoryService
.
insertWeCategory
(
category
);
return
AjaxResult
.
success
();
}
/**
...
...
@@ -66,7 +70,8 @@ public class WeCategoryController extends BaseController {
@PutMapping
@ApiOperation
(
"更新目录"
)
public
AjaxResult
edit
(
@RequestBody
WeCategory
category
)
{
return
toAjax
(
weCategoryService
.
updateWeCategory
(
category
));
weCategoryService
.
updateWeCategory
(
category
);
return
AjaxResult
.
success
();
}
...
...
@@ -78,7 +83,17 @@ public class WeCategoryController extends BaseController {
@DeleteMapping
(
"/{ids}"
)
@ApiOperation
(
"删除类目"
)
public
AjaxResult
remove
(
@PathVariable
Long
[]
ids
)
{
return
toAjax
(
weCategoryService
.
deleteWeCategoryByIds
(
ids
));
List
<
WeCategory
>
categorys
=
new
ArrayList
<>();
for
(
Long
id:
ids
)
{
categorys
.
add
(
WeCategory
.
builder
()
.
id
(
id
)
.
delFlag
(
Constants
.
DELETE_CODE
)
.
build
()
);
}
weCategoryService
.
updateBatchById
(
categorys
);
return
AjaxResult
.
success
();
}
}
linkwe-admin/src/main/java/com/linkwechat/web/controller/wecom/WeMaterialController.java
View file @
a252a34
...
...
@@ -16,9 +16,7 @@ import com.linkwechat.wecom.service.IWePosterService;
import
io.swagger.annotations.Api
;
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
;
...
...
@@ -44,11 +42,10 @@ public class WeMaterialController extends BaseController {
@Resource
private
IWePosterService
wePosterService
;
/**
* 查询素材列表
*/
// @PreAuthorize("@ss.hasPermi('wecom:material:list')")
@GetMapping
(
"/list"
)
@ApiOperation
(
"查询素材列表"
)
public
TableDataInfo
list
(
@RequestParam
(
value
=
"categoryId"
,
required
=
false
)
String
categoryId
,
@RequestParam
(
value
=
"search"
,
required
=
false
)
String
search
,
@RequestParam
(
value
=
"mediaType"
)
String
mediaType
)
{
startPage
();
...
...
@@ -69,9 +66,8 @@ public class WeMaterialController extends BaseController {
return
getDataTable
(
list
);
}
/**
* 查询素材详细信息
*/
// @PreAuthorize("@ss.hasPermi('wechat:material:query')")
@GetMapping
(
value
=
"/{id}"
)
@ApiOperation
(
"查询素材详细信息"
)
...
...
@@ -79,9 +75,7 @@ public class WeMaterialController extends BaseController {
return
AjaxResult
.
success
(
materialService
.
findWeMaterialById
(
id
));
}
/**
* 添加素材信息
*/
// @PreAuthorize("@ss.hasPermi('wechat:material:add')")
@Log
(
title
=
"添加素材信息"
,
businessType
=
BusinessType
.
INSERT
)
@PostMapping
...
...
@@ -90,9 +84,7 @@ public class WeMaterialController extends BaseController {
return
toAjax
(
materialService
.
insertWeMaterial
(
material
));
}
/**
* 更新素材信息
*/
// @PreAuthorize("@ss.hasPermi('wechat:material:edit')")
@Log
(
title
=
"更新素材信息"
,
businessType
=
BusinessType
.
UPDATE
)
@PutMapping
...
...
@@ -101,9 +93,7 @@ public class WeMaterialController extends BaseController {
return
toAjax
(
materialService
.
updateWeMaterial
(
material
));
}
/**
* 删除素材信息
*/
// @PreAuthorize("@ss.hasPermi('wechat:material:remove')")
@Log
(
title
=
"删除素材信息"
,
businessType
=
BusinessType
.
DELETE
)
@DeleteMapping
(
"/{ids}"
)
...
...
@@ -112,9 +102,7 @@ public class WeMaterialController extends BaseController {
return
toAjax
(
materialService
.
deleteWeMaterialByIds
(
ids
));
}
/**
* 上传素材信息
*/
// @PreAuthorize("@ss.hasPermi('wechat:material:upload')")
@Log
(
title
=
"上传素材信息"
,
businessType
=
BusinessType
.
OTHER
)
@PostMapping
(
"/upload"
)
...
...
@@ -124,9 +112,7 @@ public class WeMaterialController extends BaseController {
return
AjaxResult
.
success
(
weMaterialFileVO
);
}
/**
* 更换分组
*/
// @PreAuthorize("@ss.hasPermi('wechat:material:resetCategory')")
@Log
(
title
=
"更换分组"
,
businessType
=
BusinessType
.
OTHER
)
@PutMapping
(
"/resetCategory"
)
...
...
@@ -147,6 +133,8 @@ public class WeMaterialController extends BaseController {
return
AjaxResult
.
success
(
weMediaDto
);
}
@Log
(
title
=
"上传素材图片"
,
businessType
=
BusinessType
.
OTHER
)
@PostMapping
(
"/uploadimg"
)
@ApiOperation
(
"上传素材图片"
)
...
...
linkwe-wecom/src/main/java/com/linkwechat/wecom/domain/WeCategory.java
View file @
a252a34
package
com
.
linkwechat
.
wecom
.
domain
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
com.linkwechat.common.core.domain.BaseEntity
;
import
com.linkwechat.common.utils.SnowFlakeUtil
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
@Data
@TableName
(
"we_category"
)
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ApiModel
(
"素材分类"
)
public
class
WeCategory
extends
BaseEntity
{
private
Long
id
=
SnowFlakeUtil
.
nextId
();
/**
* 0 图片(image)、1 语音(voice)、2 视频(video),3 普通文件(file) 4 文本
*/
@TableId
@ApiModelProperty
(
"素材主键"
)
private
Long
id
;
@ApiModelProperty
(
"素材分类:0 图片(image)、1 语音(voice)、2 视频(video),3 普通文件(file) 4 文本"
)
private
String
mediaType
;
/**
* 分类名称
*/
@ApiModelProperty
(
"分类名称"
)
private
String
name
;
/**
* 父分类的id
*/
@ApiModelProperty
(
"素材上级父节点id"
)
private
Long
parentId
;
@ApiModelProperty
(
"素材状态:0 未删除 2 已删除"
)
private
String
delFlag
;
}
linkwe-wecom/src/main/java/com/linkwechat/wecom/mapper/WeCategoryMapper.java
View file @
a252a34
package
com
.
linkwechat
.
wecom
.
mapper
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.linkwechat.wecom.domain.WeCategory
;
import
org.apache.ibatis.annotations.Param
;
import
java.util.List
;
public
interface
WeCategoryMapper
{
public
interface
WeCategoryMapper
extends
BaseMapper
<
WeCategory
>
{
/**
* 保存素材分类
*
* @param category 素材分类 信息
* @return {@link int}
*/
int
insertWeCategory
(
WeCategory
category
);
/**
* 保存素材分类
*
* @param category 素材分类 信息
* @return {@link int}
*/
int
updateWeCategory
(
WeCategory
category
);
/**
* 删除分类信息
*
* @param id 主键id
* @return {@link int}
*/
int
deleteWeCategoryById
(
@Param
(
"id"
)
Long
id
);
/**
* 批量删除
*
* @param ids id列表
* @return {@link int}
*/
int
deleteWeCategoryByIds
(
Long
[]
ids
);
/**
* 通过类型查询对应类目的分类信息列表
*
* @param mediaType 类型
* @return {@link WeCategory}s
*/
List
<
WeCategory
>
findWeCategoryByMediaType
(
@Param
(
"mediaType"
)
String
mediaType
);
/**
* 通过id查询分类信息
*
* @param id 主键id
* @return {@link WeCategory}
*/
WeCategory
findWeCategoryById
(
@Param
(
"id"
)
Long
id
);
/**
* 通过类型和名称查询类目信息
*
* @param mediaType 0 图片(image)、1 语音(voice)、2 视频(video),3 普通文件(file) 4 文本
* @param name 分类名称
* @return {@link WeCategory}
*/
WeCategory
findWeCategoryByMediaTypeAndName
(
@Param
(
"mediaType"
)
String
mediaType
,
@Param
(
"name"
)
String
name
);
}
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/IWeCategoryService.java
View file @
a252a34
package
com
.
linkwechat
.
wecom
.
service
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.linkwechat.common.core.domain.Tree
;
import
com.linkwechat.wecom.domain.WeCategory
;
import
com.linkwechat.wecom.domain.vo.WeCategoryVo
;
...
...
@@ -7,39 +8,23 @@ import org.apache.ibatis.annotations.Param;
import
java.util.List
;
public
interface
IWeCategoryService
{
public
interface
IWeCategoryService
extends
IService
<
WeCategory
>
{
/**
* 保存素材分类
*
* @param category 素材分类 信息
* @return {@link int}
*/
int
insertWeCategory
(
WeCategory
category
);
void
insertWeCategory
(
WeCategory
category
);
/**
* 保存素材分类
*
* @param category 素材分类 信息
* @return {@link int}
*/
int
updateWeCategory
(
WeCategory
category
);
void
updateWeCategory
(
WeCategory
category
);
/**
* 删除分类信息
*
* @param id 主键id
* @return {@link int}
*/
int
deleteWeCategoryById
(
Long
id
);
/**
* 批量删除
*
* @param ids id列表
* @return {@link int}
*/
int
deleteWeCategoryByIds
(
Long
[]
ids
);
/**
* 通过类型查询对应类目的分类信息列表
...
...
@@ -49,12 +34,6 @@ public interface IWeCategoryService {
*/
List
<?
extends
Tree
<?>>
findWeCategoryByMediaType
(
@Param
(
"mediaType"
)
String
mediaType
);
/**
* 通过id查询分类信息
*
* @param id 主键id
* @return {@link WeCategory}
*/
WeCategory
findWeCategoryById
(
@Param
(
"id"
)
Long
id
);
}
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WeCategoryServiceImpl.java
View file @
a252a34
package
com
.
linkwechat
.
wecom
.
service
.
impl
;
import
cn.hutool.core.date.DateUtil
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.linkwechat.common.constant.Constants
;
import
com.linkwechat.common.core.domain.Tree
;
import
com.linkwechat.common.exception.wecom.WeComException
;
import
com.linkwechat.common.utils.SnowFlakeUtil
;
...
...
@@ -10,7 +13,6 @@ import com.linkwechat.wecom.domain.vo.WeCategoryVo;
import
com.linkwechat.wecom.mapper.WeCategoryMapper
;
import
com.linkwechat.wecom.service.IWeCategoryService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.ArrayList
;
...
...
@@ -18,47 +20,49 @@ import java.util.List;
@Slf4j
@Service
public
class
WeCategoryServiceImpl
implements
IWeCategoryService
{
public
class
WeCategoryServiceImpl
extends
ServiceImpl
<
WeCategoryMapper
,
WeCategory
>
implements
IWeCategoryService
{
@Autowired
private
WeCategoryMapper
weCategoryMapper
;
@Override
public
int
insertWeCategory
(
WeCategory
category
)
{
public
void
insertWeCategory
(
WeCategory
category
)
{
//判断是否存在相同的名称
WeCategory
weCategory
=
weCategoryMapper
.
findWeCategoryByMediaTypeAndName
(
category
.
getMediaType
(),
category
.
getName
());
WeCategory
weCategory
=
this
.
getOne
(
new
LambdaQueryWrapper
<
WeCategory
>()
.
eq
(
WeCategory:
:
getMediaType
,
category
.
getMediaType
())
.
eq
(
WeCategory:
:
getName
,
category
.
getName
())
.
eq
(
WeCategory:
:
getDelFlag
,
Constants
.
NORMAL_CODE
));
if
(
null
!=
weCategory
)
{
throw
new
WeComException
(
"名称已存在!"
);
}
category
.
setCreateTime
(
DateUtil
.
date
());
category
.
setId
(
SnowFlakeUtil
.
nextId
());
return
weCategoryMapper
.
insertWeCategory
(
category
);
this
.
save
(
category
);
}
@Override
public
int
updateWeCategory
(
WeCategory
category
)
{
public
void
updateWeCategory
(
WeCategory
category
)
{
//判断是否存在相同的名称
WeCategory
weCategory
=
weCategoryMapper
.
findWeCategoryByMediaTypeAndName
(
category
.
getMediaType
(),
category
.
getName
());
WeCategory
weCategory
=
this
.
getOne
(
new
LambdaQueryWrapper
<
WeCategory
>()
.
eq
(
WeCategory:
:
getMediaType
,
category
.
getMediaType
())
.
eq
(
WeCategory:
:
getName
,
category
.
getName
())
.
eq
(
WeCategory:
:
getDelFlag
,
Constants
.
NORMAL_CODE
));
if
(
null
!=
weCategory
)
{
throw
new
WeComException
(
"名称已存在!"
);
}
category
.
setUpdateTime
(
DateUtil
.
date
());
return
weCategoryMapper
.
updateWeCategory
(
category
);
this
.
updateById
(
category
);
}
@Override
public
int
deleteWeCategoryById
(
Long
id
)
{
return
weCategoryMapper
.
deleteWeCategoryById
(
id
);
}
@Override
public
int
deleteWeCategoryByIds
(
Long
[]
ids
)
{
return
weCategoryMapper
.
deleteWeCategoryByIds
(
ids
);
}
@Override
public
List
<?
extends
Tree
<?>>
findWeCategoryByMediaType
(
String
mediaType
)
{
List
<
WeCategory
>
weCategories
=
weCategoryMapper
.
findWeCategoryByMediaType
(
mediaType
);
List
<
WeCategory
>
weCategories
=
this
.
list
(
new
LambdaQueryWrapper
<
WeCategory
>()
.
eq
(
WeCategory:
:
getMediaType
,
mediaType
)
.
eq
(
WeCategory:
:
getDelFlag
,
Constants
.
NORMAL_CODE
));
List
<
WeCategoryVo
>
weCategoryVos
=
new
ArrayList
<>();
weCategories
.
forEach
(
c
->
{
WeCategoryVo
weCategoryVo
=
new
WeCategoryVo
();
...
...
@@ -70,10 +74,6 @@ public class WeCategoryServiceImpl implements IWeCategoryService {
return
TreeUtil
.
build
(
weCategoryVos
);
}
@Override
public
WeCategory
findWeCategoryById
(
Long
id
)
{
return
weCategoryMapper
.
findWeCategoryById
(
id
);
}
}
linkwe-wecom/src/main/resources/mapper/wecom/WeCategoryMapper.xml
View file @
a252a34
...
...
@@ -3,92 +3,6 @@
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"com.linkwechat.wecom.mapper.WeCategoryMapper"
>
<resultMap
id=
"categoryMap"
type=
"com.linkwechat.wecom.domain.WeCategory"
>
<id
property=
"id"
column=
"id"
/>
<result
property=
"mediaType"
column=
"media_type"
/>
<result
property=
"name"
column=
"name"
/>
<result
property=
"parentId"
column=
"parent_id"
/>
</resultMap>
<insert
id=
"insertWeCategory"
>
INSERT INTO we_category
<trim
prefix=
"("
suffix=
")"
suffixOverrides=
","
>
<if
test=
"id != null"
>
id,
</if>
<if
test=
"mediaType != null"
>
media_type,
</if>
<if
test=
"name != null"
>
name,
</if>
<if
test=
"parentId != null"
>
parent_id,
</if>
<if
test=
"createBy != null"
>
create_by,
</if>
<if
test=
"createTime != null"
>
create_time,
</if>
<if
test=
"updateBy != null"
>
update_by,
</if>
<if
test=
"updateTime != null"
>
update_time,
</if>
</trim>
<trim
prefix=
"values ("
suffix=
")"
suffixOverrides=
","
>
<if
test=
"id != null"
>
#{id},
</if>
<if
test=
"mediaType != null"
>
#{mediaType},
</if>
<if
test=
"name != null"
>
#{name},
</if>
<if
test=
"parentId != null"
>
#{parentId},
</if>
<if
test=
"createBy != null"
>
#{createBy},
</if>
<if
test=
"createTime != null"
>
#{createTime},
</if>
<if
test=
"updateBy != null"
>
#{updateBy},
</if>
<if
test=
"updateTime != null"
>
#{updateTime},
</if>
</trim>
</insert>
<update
id=
"updateWeCategory"
>
UPDATE we_category
<trim
prefix=
"set"
suffixOverrides=
","
>
<if
test=
"mediaType != null"
>
media_type=#{mediaType},
</if>
<if
test=
"name != null"
>
name=#{name},
</if>
<if
test=
"parentId != null"
>
parent_id=#{parentId},
</if>
<if
test=
"createBy != null"
>
create_by=#{createBy},
</if>
<if
test=
"createTime != null"
>
create_time=#{createTime},
</if>
<if
test=
"updateBy != null"
>
update_by=#{updateBy},
</if>
<if
test=
"updateTime != null"
>
update_time=#{updateTime},
</if>
</trim>
<where>
id=#{id}
</where>
</update>
<delete
id=
"deleteWeCategoryById"
>
UPDATE we_category
set del_flag=1
<where>
id=#{id}
</where>
</delete>
<delete
id=
"deleteWeCategoryByIds"
>
UPDATE we_category
set del_flag=1
<where>
id in
<foreach
collection=
"array"
open=
"("
close=
")"
item=
"item"
separator=
","
>
#{item}
</foreach>
</where>
</delete>
<select
id=
"findWeCategoryByMediaType"
resultType=
"com.linkwechat.wecom.domain.WeCategory"
>
SELECT
<include
refid=
"categoryVo"
/>
FROM we_category
<where>
media_type=#{mediaType} and del_flag=0
</where>
</select>
<select
id=
"findWeCategoryById"
resultType=
"com.linkwechat.wecom.domain.WeCategory"
>
SELECT
<include
refid=
"categoryVo"
/>
FROM we_category
<where>
id=#{id} and del_flag=0
</where>
</select>
<select
id=
"findWeCategoryByMediaTypeAndName"
resultType=
"com.linkwechat.wecom.domain.WeCategory"
>
SELECT
<include
refid=
"categoryVo"
/>
FROM we_category
<where>
media_type=#{mediaType} and del_flag=0 and `name`=#{name}
</where>
</select>
<sql
id=
"categoryVo"
>
id,media_type,parent_id,`name`
</sql>
</mapper>
\ No newline at end of file
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