Commit cc3f0f06 by 18356073052

修改素材接口逻辑

1 parent 03125080
...@@ -6,9 +6,11 @@ import com.linkwechat.common.core.domain.AjaxResult; ...@@ -6,9 +6,11 @@ import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.page.TableDataInfo; import com.linkwechat.common.core.page.TableDataInfo;
import com.linkwechat.common.enums.BusinessType; import com.linkwechat.common.enums.BusinessType;
import com.linkwechat.wecom.domain.WeMaterial; import com.linkwechat.wecom.domain.WeMaterial;
import com.linkwechat.wecom.domain.dto.ResetCategoryDto;
import com.linkwechat.wecom.domain.vo.WeMaterialFileVO; import com.linkwechat.wecom.domain.vo.WeMaterialFileVO;
import com.linkwechat.wecom.service.IWeMaterialService; import com.linkwechat.wecom.service.IWeMaterialService;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -35,9 +37,10 @@ public class WeMaterialController extends BaseController { ...@@ -35,9 +37,10 @@ public class WeMaterialController extends BaseController {
*/ */
@PreAuthorize("@ss.hasPermi('wecom:material:list')") @PreAuthorize("@ss.hasPermi('wecom:material:list')")
@GetMapping("/list") @GetMapping("/list")
public TableDataInfo list(@RequestParam(value = "categoryId", required = false) String categoryId, @RequestParam(value = "search", required = false) String search) { public TableDataInfo list(@RequestParam(value = "categoryId", required = false) String categoryId
, @RequestParam(value = "search", required = false) String search,@RequestParam(value = "mediaType") String mediaType) {
startPage(); startPage();
List<WeMaterial> list = materialService.findWeMaterials(categoryId, search); List<WeMaterial> list = materialService.findWeMaterials(categoryId, search,mediaType);
return getDataTable(list); return getDataTable(list);
} }
...@@ -91,9 +94,22 @@ public class WeMaterialController extends BaseController { ...@@ -91,9 +94,22 @@ public class WeMaterialController extends BaseController {
@Log(title = "上传素材信息", businessType = BusinessType.OTHER) @Log(title = "上传素材信息", businessType = BusinessType.OTHER)
@PostMapping("/upload") @PostMapping("/upload")
@ApiOperation("上传素材信息") @ApiOperation("上传素材信息")
public AjaxResult upload(@RequestParam(value = "file") MultipartFile file, @RequestParam(value = "type") String type) { public AjaxResult upload(@RequestParam(value = "file") MultipartFile file, @RequestParam(value = "mediaType") String mediaType) {
WeMaterialFileVO weMaterialFileVO = materialService.uploadWeMaterialFile(file, type); WeMaterialFileVO weMaterialFileVO = materialService.uploadWeMaterialFile(file, mediaType);
return AjaxResult.success(weMaterialFileVO); return AjaxResult.success(weMaterialFileVO);
} }
/**
* 更换分组
*/
@PreAuthorize("@ss.hasPermi('wechat:material:resetCategory')")
@Log(title = "更换分组", businessType = BusinessType.OTHER)
@PutMapping("/resetCategory")
@ApiOperation("更换分组")
public AjaxResult resetCategory(@RequestBody ResetCategoryDto resetCategoryDto) {
materialService.resetCategory(resetCategoryDto.getCategoryId(), resetCategoryDto.getMaterials());
return AjaxResult.success();
}
} }
...@@ -59,8 +59,19 @@ public interface WeMaterialMapper { ...@@ -59,8 +59,19 @@ public interface WeMaterialMapper {
* *
* @param categoryId 类目id * @param categoryId 类目id
* @param search 搜索值 * @param search 搜索值
* @param mediaType 0 图片(image)、1 语音(voice)、2 视频(video),3 普通文件(file) 4 文本
* @return {@link WeMaterial}s * @return {@link WeMaterial}s
*/ */
List<WeMaterial> findWeMaterials(@Param("categoryId") String categoryId, @Param("search") String search); List<WeMaterial> findWeMaterials(@Param("categoryId") String categoryId, @Param("search") String search, @Param("mediaType") String mediaType);
/**
* 更换分组
*
* @param categoryId 类目id
* @param material 素材id
* @return int
*/
int resetCategory(@Param("categoryId") String categoryId, @Param("material") String material);
} }
...@@ -2,6 +2,8 @@ package com.linkwechat.wecom.service; ...@@ -2,6 +2,8 @@ package com.linkwechat.wecom.service;
import com.linkwechat.wecom.domain.WeMaterial; import com.linkwechat.wecom.domain.WeMaterial;
import com.linkwechat.wecom.domain.vo.WeMaterialFileVO; import com.linkwechat.wecom.domain.vo.WeMaterialFileVO;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.util.List; import java.util.List;
...@@ -70,6 +72,15 @@ public interface IWeMaterialService { ...@@ -70,6 +72,15 @@ public interface IWeMaterialService {
* @param search 搜索值 * @param search 搜索值
* @return {@link WeMaterial}s * @return {@link WeMaterial}s
*/ */
List<WeMaterial> findWeMaterials(String categoryId, String search); List<WeMaterial> findWeMaterials(String categoryId, String search,String mediaType);
/**
* 更换分组
*
* @param categoryId 类目id
* @param materials 素材id
* @return int
*/
void resetCategory(String categoryId, String materials);
} }
...@@ -63,7 +63,7 @@ public class WeCategoryServiceImpl implements IWeCategoryService { ...@@ -63,7 +63,7 @@ public class WeCategoryServiceImpl implements IWeCategoryService {
weCategories.forEach(c -> { weCategories.forEach(c -> {
WeCategoryVo weCategoryVo = new WeCategoryVo(); WeCategoryVo weCategoryVo = new WeCategoryVo();
weCategoryVo.setId(c.getId()); weCategoryVo.setId(c.getId());
weCategoryVo.setLabel(c.getName()); weCategoryVo.setName(c.getName());
weCategoryVo.setParentId(c.getParentId()); weCategoryVo.setParentId(c.getParentId());
weCategoryVos.add(weCategoryVo); weCategoryVos.add(weCategoryVo);
}); });
......
package com.linkwechat.wecom.service.impl; package com.linkwechat.wecom.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import com.linkwechat.common.config.RuoYiConfig; import com.linkwechat.common.config.RuoYiConfig;
import com.linkwechat.common.config.ServerConfig; import com.linkwechat.common.config.ServerConfig;
import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.enums.MediaType; import com.linkwechat.common.enums.MediaType;
import com.linkwechat.common.exception.wecom.WeComException; import com.linkwechat.common.exception.wecom.WeComException;
import com.linkwechat.common.utils.SnowFlakeUtil; import com.linkwechat.common.utils.SnowFlakeUtil;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.common.utils.file.FileUploadUtils; import com.linkwechat.common.utils.file.FileUploadUtils;
import com.linkwechat.wecom.domain.WeMaterial; import com.linkwechat.wecom.domain.WeMaterial;
import com.linkwechat.wecom.domain.vo.WeMaterialFileVO; import com.linkwechat.wecom.domain.vo.WeMaterialFileVO;
...@@ -16,6 +19,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -16,6 +19,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
...@@ -44,18 +48,25 @@ public class WeMaterialServiceImpl implements IWeMaterialService { ...@@ -44,18 +48,25 @@ public class WeMaterialServiceImpl implements IWeMaterialService {
//上传文件到文件服务器 //上传文件到文件服务器
// 上传文件路径 // 上传文件路径
String filePath = RuoYiConfig.getUploadPath(); String filePath = RuoYiConfig.getUploadPath();
String fileName = "";
if (MediaType.FILE.getType().equals(type)) {
fileName = FileUploadUtils.uploadFile(file);
} else {
// 上传并返回新文件名称 // 上传并返回新文件名称
String fileName = FileUploadUtils.upload(filePath, file); fileName = FileUploadUtils.upload(filePath, file);
}
String url = serverConfig.getUrl() + fileName; String url = serverConfig.getUrl() + fileName;
//上传临时素材 //上传临时素材
Optional<MediaType> mediaType = MediaType.of(type); Optional<MediaType> mediaType = MediaType.of(type);
if (!mediaType.isPresent()) { if (!mediaType.isPresent()) {
throw new WeComException("媒体类型出错!"); throw new WeComException("媒体类型出错!");
} }
//构造返回结果 //构造返回结果
return WeMaterialFileVO.builder().materialUrl(url).materialName(file.getOriginalFilename()).build(); return WeMaterialFileVO.builder().materialUrl(url).materialName(file.getOriginalFilename()).build();
} catch (Exception e) { } catch (Exception e) {
throw new WeComException("临时素材上传失败!"); throw new WeComException(e.getMessage());
} }
} }
...@@ -89,8 +100,20 @@ public class WeMaterialServiceImpl implements IWeMaterialService { ...@@ -89,8 +100,20 @@ public class WeMaterialServiceImpl implements IWeMaterialService {
} }
@Override @Override
public List<WeMaterial> findWeMaterials(String categoryId, String search) { public List<WeMaterial> findWeMaterials(String categoryId, String search, String mediaType) {
return weMaterialMapper.findWeMaterials(categoryId, search); return weMaterialMapper.findWeMaterials(categoryId, search, mediaType);
} }
@Override
public void resetCategory(String categoryId, String materials) {
List<String> materialList = Arrays.asList(StringUtils.splitByWholeSeparatorPreserveAllTokens(materials, WeConstans.COMMA));
if (CollectionUtil.isNotEmpty(materialList)) {
materialList.forEach(s -> {
weMaterialMapper.resetCategory(categoryId, s);
});
}
}
} }
...@@ -129,6 +129,20 @@ ...@@ -129,6 +129,20 @@
<if test="updateTime!=null"> <if test="updateTime!=null">
update_time=#{updateTime} update_time=#{updateTime}
</if> </if>
<where>
<if test="id!=null">
id=#{id}
</if>
</where>
</update>
<update id="resetCategory">
UPDATE we_material
<set>
category_id=#{categoryId}
</set>
<where>
id=#{material}
</where>
</update> </update>
<delete id="deleteWeMaterialById"> <delete id="deleteWeMaterialById">
...@@ -161,15 +175,18 @@ ...@@ -161,15 +175,18 @@
<select id="findWeMaterials" resultMap="materialMap"> <select id="findWeMaterials" resultMap="materialMap">
SELECT SELECT
<include refid="material"/> wm.id,wm.category_id,wm.material_url,wm.content,wm.material_name,wm.digest,wm.cover_url,wm.create_by,wm.create_time,wm.update_by,wm.update_time
FROM we_material FROM we_material wm LEFT JOIN we_category wc ON wm.category_id=wc.id
<where> <where>
del_flag=0 wm.del_flag=0
<if test="categoryId!=null and categoryId!=''"> <if test="categoryId!=null and categoryId!=''">
AND category_id=#{categoryId} AND wm.category_id=#{categoryId}
</if> </if>
<if test="search!=null and search!=''"> <if test="search!=null and search!=''">
AND (material_name LIKE CONCAT('%',#{search},'%') OR content LIKE CONCAT('%',#{search},'%')) AND (wm.material_name LIKE CONCAT('%',#{search},'%') OR wm.content LIKE CONCAT('%',#{search},'%'))
</if>
<if test="mediaType!=null">
AND wc.media_type=#{mediaType}
</if> </if>
</where> </where>
</select> </select>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!