WeMaterialController.java
5.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
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.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
*
* @author KEWEN
* @date 2020-10-08
*/
@RestController
@RequestMapping("/wecom/material")
public class WeMaterialController extends BaseController {
@Autowired
private IWeMaterialService materialService;
@Resource
private IWePosterService wePosterService;
/**
* 查询素材列表
*/
@PreAuthorize("@ss.hasPermi('wecom:material:list')")
@GetMapping("/list")
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;
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);
}
/**
* 查询素材详细信息
*/
@PreAuthorize("@ss.hasPermi('wechat:material:query')")
@GetMapping(value = "/{id}")
@ApiOperation("查询素材详细信息")
public AjaxResult getInfo(@PathVariable("id") Long id) {
return AjaxResult.success(materialService.findWeMaterialById(id));
}
/**
* 添加素材信息
*/
@PreAuthorize("@ss.hasPermi('wechat:material:add')")
@Log(title = "添加素材信息", businessType = BusinessType.INSERT)
@PostMapping
@ApiOperation("添加素材信息")
public AjaxResult add(@RequestBody WeMaterial material) {
return toAjax(materialService.insertWeMaterial(material));
}
/**
* 更新素材信息
*/
@PreAuthorize("@ss.hasPermi('wechat:material:edit')")
@Log(title = "更新素材信息", businessType = BusinessType.UPDATE)
@PutMapping
@ApiOperation("更新素材信息")
public AjaxResult edit(@RequestBody WeMaterial material) {
return toAjax(materialService.updateWeMaterial(material));
}
/**
* 删除素材信息
*/
@PreAuthorize("@ss.hasPermi('wechat:material:remove')")
@Log(title = "删除素材信息", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
@ApiOperation("删除素材信息")
public AjaxResult remove(@PathVariable Long[] ids) {
return toAjax(materialService.deleteWeMaterialByIds(ids));
}
/**
* 上传素材信息
*/
@PreAuthorize("@ss.hasPermi('wechat:material:upload')")
@Log(title = "上传素材信息", businessType = BusinessType.OTHER)
@PostMapping("/upload")
@ApiOperation("上传素材信息")
public AjaxResult upload(@RequestParam(value = "file") MultipartFile file, @RequestParam(value = "mediaType") String mediaType) {
WeMaterialFileVO weMaterialFileVO = materialService.uploadWeMaterialFile(file, mediaType);
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();
}
@PreAuthorize("@ss.hasPermi('wechat:material:temporaryMaterialMediaId')")
@Log(title = "获取素材media_id", businessType = BusinessType.OTHER)
@PostMapping("/temporaryMaterialMediaId")
@ApiOperation("获取素材media_id")
public AjaxResult temporaryMaterialMediaId(@RequestParam(value = "url") String url, @RequestParam(value = "type") String type,@RequestParam(value = "name") String name){
WeMediaDto weMediaDto = materialService.uploadTemporaryMaterial(url, type,name);
return AjaxResult.success(weMediaDto);
}
}