WeCommunityGroupSopController.java
5.88 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
145
package com.linkwechat.web.controller.wecom;
import com.linkwechat.common.constant.HttpStatus;
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.utils.SecurityUtils;
import com.linkwechat.wecom.domain.WeGroupSop;
import com.linkwechat.wecom.domain.dto.WeGroupSopDto;
import com.linkwechat.wecom.domain.vo.WeGroupSopVo;
import com.linkwechat.wecom.service.IWeGroupSopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 社区运营 - 群sop controller
*/
@Api(description = "新客自动拉群 Controller")
@RestController
@RequestMapping(value = "/wecom/communityGroupSop")
public class WeCommunityGroupSopController extends BaseController {
@Autowired
private IWeGroupSopService groupSopService;
/**
* 通过过滤条件获取群sop列表
*
* @param ruleName 规则名称
* @param createBy 创建者
* @param beginTime 创建区间 - 开始时间
* @param endTime 创建区间 - 结束时间
* @return 群sop规则列表
*/
@ApiOperation(value = "通过过滤条件获取群sop列表", httpMethod = "GET")
// @PreAuthorize("@ss.hasPermi('wecom:communityGroupSop:list')")
@GetMapping(path = "/list")
public TableDataInfo<List<WeGroupSopVo>> getSopList(
@RequestParam(value = "ruleName", required = false) String ruleName,
@RequestParam(value = "createBy", required = false) String createBy,
@RequestParam(value = "beginTime", required = false) String beginTime,
@RequestParam(value = "endTime", required = false) String endTime
)
{
startPage();
List<WeGroupSopVo> groupSopVoList = groupSopService.getGroupSopList(ruleName, createBy, beginTime, endTime);
return getDataTable(groupSopVoList);
}
/**
* 新增SOP规则
*
* @param groupSopDto 更新数据
* @return 结果
*/
@ApiOperation(value = "新增SOP规则", httpMethod = "POST")
// @PreAuthorize("@ss.hasPermi('wecom:communityGroupSop:add')")
@PostMapping(path = "/")
public AjaxResult addGroupSop(@Validated @RequestBody WeGroupSopDto groupSopDto) {
if (!groupSopService.isRuleNameUnique(groupSopDto.getRuleName())) {
return AjaxResult.error(HttpStatus.BAD_REQUEST, "规则名称已存在");
}
WeGroupSop weGroupSop = new WeGroupSop();
BeanUtils.copyProperties(groupSopDto, weGroupSop);
weGroupSop.setCreateBy(SecurityUtils.getUsername());
// 群聊id列表
List<String> groupIdList = groupSopDto.getChatIdList();
// 素材URL
List<Long> materialIdList = groupSopDto.getMaterialIdList();
// 上传的图片的URl列表
List<String> picList = groupSopDto.getPicList();
return toAjax(groupSopService.addGroupSop(weGroupSop, groupIdList, materialIdList, picList));
}
/**
* 通过规则id获取sop规则
*
* @param ruleId 规则id
* @return 结果
*/
@ApiOperation(value = "通过规则id获取sop规则详情", httpMethod = "GET")
// @PreAuthorize("@ss.hasPermi('wecom:communityGroupSop:query')")
@GetMapping(path = "/{ruleId}")
public AjaxResult getGroupSop(@PathVariable("ruleId") Long ruleId) {
WeGroupSopVo groupSopVo = groupSopService.getGroupSopById(ruleId);
if (null == groupSopVo) {
return AjaxResult.error(HttpStatus.NOT_FOUND, "该群SOP规则不存在");
}
return AjaxResult.success(groupSopVo);
}
/**
* 更改SOP规则
*
* @param ruleId SOP规则 id
* @param groupSopDto 更新数据
* @return 结果
*/
@ApiOperation(value = "更改SOP规则", httpMethod = "PUT")
// @PreAuthorize("@ss.hasPermi('wecom:communityGroupSop:edit')")
@PutMapping(path = "/{ruleId}")
public AjaxResult updateGroupSop(@PathVariable Long ruleId, @Validated @RequestBody WeGroupSopDto groupSopDto) {
// 校验是否存在
if (null == groupSopService.getGroupSopById(ruleId)) {
return AjaxResult.error(HttpStatus.NOT_FOUND, "该群SOP规则不存在");
}
// 校验规则名是否可用
WeGroupSopVo original = groupSopService.getGroupSopById(ruleId);
if (!groupSopDto.getRuleName().equals(original.getRuleName()) && !groupSopService.isRuleNameUnique(groupSopDto.getRuleName())) {
return AjaxResult.error(HttpStatus.BAD_REQUEST, "规则名称已存在");
}
WeGroupSop weGroupSop = new WeGroupSop();
BeanUtils.copyProperties(groupSopDto, weGroupSop);
weGroupSop.setRuleId(ruleId);
weGroupSop.setUpdateBy(SecurityUtils.getUsername());
// 群聊id列表
List<String> groupIdList = groupSopDto.getChatIdList();
// 素材id列表
List<Long> materialIdList = groupSopDto.getMaterialIdList();
// 上传的图片的URl列表
List<String> picList = groupSopDto.getPicList();
return toAjax(groupSopService.updateGroupSop(weGroupSop, groupIdList, materialIdList, picList));
}
/**
* 根据id列表批量删除群sop规则
*
* @param ids 群sop规则列表
* @return 结果
*/
@ApiOperation(value = "根据id列表批量删除群sop规则", httpMethod = "DELETE")
// @PreAuthorize("@ss.hasPermi('wecom:communityGroupSop:remove')")
@DeleteMapping(path = "/{ids}")
public AjaxResult batchDeleteSopRule(@PathVariable("ids") Long[] ids) {
return toAjax(groupSopService.batchRemoveGroupSopByIds(ids));
}
}