Commit c7c176c6 by 18356073052

添加素材类目

1 parent c88e91df
......@@ -31,8 +31,7 @@
</dependency>
<!-- Mysql驱动包 -->
<!-- Mysql驱动包 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
......@@ -62,8 +61,12 @@
<groupId>com.linkwechat</groupId>
<artifactId>linkwe-wecom</artifactId>
</dependency>
<!--腾讯云-->
<dependency>
<groupId>com.qcloud</groupId>
<artifactId>cos_api</artifactId>
<version>5.6.24</version>
</dependency>
</dependencies>
......@@ -84,15 +87,15 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.1.0</version>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<warName>${project.artifactId}</warName>
</configuration>
</plugin>
</configuration>
</plugin>
</plugins>
<finalName>${project.artifactId}</finalName>
</build>
......
package com.linkwechat.web.controller.wecom;
import com.linkwechat.common.annotation.Log;
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.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 企业微信素材分类Controller
*
* @author KEWEN
* @date 2020-10-08
*/
@RestController
@RequestMapping("/wecom/category")
public class WeCategoryController extends BaseController {
@Autowired
private IWeCategoryService weCategoryService;
/**
* 类目树
*/
@PreAuthorize("@ss.hasPermi('wechat:category:list')")
@GetMapping("/list")
@ApiOperation("类目树")
public List<? extends Tree<?>> list(@RequestParam("mediaType") String mediaType) {
return weCategoryService.findWeCategoryByMediaType(mediaType);
}
/**
* 通过id查询类目详细信息
*/
@PreAuthorize("@ss.hasPermi('wechat:category:query')")
@GetMapping(value = "/{id}")
@ApiOperation("通过id查询类目详细信息")
public AjaxResult getInfo(@PathVariable("id") Long id) {
return AjaxResult.success(weCategoryService.findWeCategoryById(id));
}
/**
* 添加类目
*/
@PreAuthorize("@ss.hasPermi('wechat:category:add')")
@Log(title = "添加类目", businessType = BusinessType.INSERT)
@PostMapping
@ApiOperation("添加类目")
public AjaxResult add(@RequestBody WeCategory category) {
return toAjax(weCategoryService.insertWeCategory(category));
}
/**
* 更新目录
*/
@PreAuthorize("@ss.hasPermi('wechat:category:edit')")
@Log(title = "更新目录", businessType = BusinessType.UPDATE)
@PutMapping
@ApiOperation("更新目录")
public AjaxResult edit(@RequestBody WeCategory category) {
return toAjax(weCategoryService.updateWeCategory(category));
}
/**
* 删除类目
*/
@PreAuthorize("@ss.hasPermi('wechat:category:remove')")
@Log(title = "删除类目", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
@ApiOperation("删除类目")
public AjaxResult remove(@PathVariable Long[] ids) {
return toAjax(weCategoryService.deleteWeCategoryByIds(ids));
}
}
......@@ -16,7 +16,7 @@ public class WeConstans {
/**
* 获取外部联系人相关 token
*/
public static final String WE_CONTACT_ACCESS_TOKEN="we_contact_access_token";
public static final String WE_CONTACT_ACCESS_TOKEN = "we_contact_access_token";
/**
......@@ -34,19 +34,19 @@ public class WeConstans {
/**
* 企业微信通讯录用户启用
*/
public static final Integer WE_USER_START= 1;
public static final Integer WE_USER_START = 1;
/**
* 企业微信通讯录用户停用
*/
public static final Integer WE_USER_STOP= 0;
public static final Integer WE_USER_STOP = 0;
/**
* 同步功能提示语
*/
public static final String SYNCH_TIP="后台开始同步数据,请稍后关注进度";
public static final String SYNCH_TIP = "后台开始同步数据,请稍后关注进度";
/**
......@@ -58,4 +58,11 @@ public class WeConstans {
* 离职已分配分配
*/
public static final Integer LEAVE_ALLOCATE_STATE = 6;
/**
* 企业微信素材目录根id
*/
public static final Integer WE_ROOT_CATEGORY_ID = 0;
}
package com.linkwechat.common.core.domain;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
@Data
public class Tree<T> {
@ApiModelProperty(name = "id", value = "id")
private Long id;
/**
* 名称
*/
@ApiModelProperty(name = "label", value = "名称")
private String label;
/**
* 父的叶子信息
*/
@ApiModelProperty(name = "children", value = "父的叶子信息")
private List<Tree<T>> children;
/**
* 父id
*/
@ApiModelProperty(name = "parentId", value = "父id")
private Long parentId;
@ApiModelProperty(name = "hasParent", value = "是否有父节点")
private boolean hasParent = false;
@ApiModelProperty(name = "false", value = "是否有叶子节点")
private boolean hasChildren = false;
public void initChildren() {
this.children = new ArrayList<>();
}
}
package com.linkwechat.common.enums;
import lombok.Getter;
import java.util.Optional;
import java.util.stream.Stream;
/**
* 媒体类型:媒体文件类型,分别有图片(image)、语音(voice)、视频(video),普通文件(file)
*/
@Getter
public enum MediaType {
IMAGE("0", "image"),
VOICE("1", "voice"),
VIDEO("2", "video"),
FILE("3", "file");
/**
* 媒体类型
*/
String mediaType;
/**
* 0 图片(image)、1 语音(voice)、2 视频(video),3 普通文件(file) 4 文本
*/
String type;
MediaType(String type, String mediaType) {
this.type = type;
this.mediaType = mediaType;
}
public static Optional<MediaType> of(String type){
return Stream.of(values()).filter(s->s.type.equals(type)).findFirst();
}
}
package com.linkwechat.common.utils;
import com.linkwechat.common.core.domain.Tree;
import java.util.ArrayList;
import java.util.List;
/**
* 树工具类
*/
public class TreeUtil {
private final static Long TOP_NODE_ID = 0l;
/**
* 御用构建树
*
* @param nodes nodes
* @return <T> List<? extends Tree>
*/
public static <T> List<? extends Tree<?>> build(List<? extends Tree<T>> nodes) {
if (nodes == null) {
return null;
}
List<Tree<T>> topNodes = new ArrayList<>();
nodes.forEach(node -> {
Long pid = node.getParentId();
if (pid == null || TOP_NODE_ID.equals(pid)) {
topNodes.add(node);
return;
}
for (Tree<T> n : nodes) {
Long id = n.getId();
if (id != null && id.equals(pid)) {
if (n.getChildren() == null) {
n.initChildren();
}
n.getChildren().add(node);
node.setHasParent(true);
n.setHasChildren(true);
n.setHasParent(true);
return;
}
}
if (topNodes.isEmpty()) {
topNodes.add(node);
}
});
return topNodes;
}
}
\ No newline at end of file
package com.linkwechat.wecom.domain;
import com.linkwechat.common.core.domain.BaseEntity;
import com.linkwechat.common.utils.SnowFlakeUtil;
import lombok.Data;
@Data
public class WeCategory extends BaseEntity {
private Long id = SnowFlakeUtil.nextId();
/**
* 0 图片(image)、1 语音(voice)、2 视频(video),3 普通文件(file) 4 文本
*/
private String mediaType;
/**
* 分类名称
*/
private String name;
/**
* 父分类的id
*/
private Long parentId;
}
package com.linkwechat.wecom.domain.vo;
import com.linkwechat.common.core.domain.Tree;
import com.linkwechat.wecom.domain.WeCategory;
import lombok.Data;
@Data
public class WeCategoryVo extends Tree<WeCategory> {
}
package com.linkwechat.wecom.mapper;
import com.linkwechat.wecom.domain.WeCategory;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface WeCategoryMapper {
/**
* 保存素材分类
*
* @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);
}
package com.linkwechat.wecom.service;
import com.linkwechat.common.core.domain.Tree;
import com.linkwechat.wecom.domain.WeCategory;
import com.linkwechat.wecom.domain.vo.WeCategoryVo;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface IWeCategoryService {
/**
* 保存素材分类
*
* @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(Long id);
/**
* 批量删除
*
* @param ids id列表
* @return {@link int}
*/
int deleteWeCategoryByIds(Long[] ids);
/**
* 通过类型查询对应类目的分类信息列表
*
* @param mediaType 类型
* @return {@link WeCategory}s
*/
List<? extends Tree<?>> findWeCategoryByMediaType(@Param("mediaType") String mediaType);
/**
* 通过id查询分类信息
*
* @param id 主键id
* @return {@link WeCategory}
*/
WeCategory findWeCategoryById(@Param("id") Long id);
}
package com.linkwechat.wecom.service.impl;
import com.linkwechat.common.core.domain.Tree;
import com.linkwechat.common.exception.wecom.WeComException;
import com.linkwechat.common.utils.TreeUtil;
import com.linkwechat.wecom.domain.WeCategory;
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;
import java.util.List;
@Slf4j
@Service
public class WeCategoryServiceImpl implements IWeCategoryService {
@Autowired
private WeCategoryMapper weCategoryMapper;
@Override
public int insertWeCategory(WeCategory category) {
//判断是否存在相同的名称
WeCategory weCategory = weCategoryMapper.findWeCategoryByMediaTypeAndName(category.getMediaType(), category.getName());
if (null != weCategory) {
throw new WeComException("名称已存在!");
}
return weCategoryMapper.insertWeCategory(category);
}
@Override
public int updateWeCategory(WeCategory category) {
//判断是否存在相同的名称
WeCategory weCategory = weCategoryMapper.findWeCategoryByMediaTypeAndName(category.getMediaType(), category.getName());
if (null != weCategory) {
throw new WeComException("名称已存在!");
}
return weCategoryMapper.updateWeCategory(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<WeCategoryVo> weCategoryVos = new ArrayList<>();
weCategories.forEach(c -> {
WeCategoryVo weCategoryVo = new WeCategoryVo();
weCategoryVo.setId(c.getId());
weCategoryVo.setLabel(c.getName());
weCategoryVo.setParentId(c.getParentId());
weCategoryVos.add(weCategoryVo);
});
return TreeUtil.build(weCategoryVos);
}
@Override
public WeCategory findWeCategoryById(Long id) {
return weCategoryMapper.findWeCategoryById(id);
}
}
<?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.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="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>
<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
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!