WeCommunityNewGroupController.java
7.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
package com.linkwechat.web.controller.wecom;
import cn.hutool.core.collection.CollectionUtil;
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.exception.wecom.WeComException;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.common.utils.file.FileUtils;
import com.linkwechat.wecom.domain.WeCommunityNewGroup;
import com.linkwechat.wecom.domain.WeEmpleCode;
import com.linkwechat.wecom.domain.dto.WeCommunityNewGroupDto;
import com.linkwechat.wecom.domain.vo.WeCommunityNewGroupVo;
import com.linkwechat.wecom.service.IWeCommunityNewGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
/**
* 社群运营 新客自动拉群 Controller
*
* @author kewen
* @date 2021-02-19
*/
@Api(description = "新客自动拉群 Controller")
@Controller
@RequestMapping(value = "/wecom/communityNewGroup")
public class WeCommunityNewGroupController extends BaseController {
@Autowired
private IWeCommunityNewGroupService weCommunityNewGroupService;
/**
* 查询新客自动拉群列表
*/
@ApiOperation(value = "查询新客自动拉群列表", httpMethod = "GET")
@PreAuthorize("@ss.hasPermi('wecom:communityNewGroup:list')")
@GetMapping("/list")
public TableDataInfo list(@RequestParam(value = "empleCodeName", required = false) String empleCodeName
, @RequestParam(value = "createBy", required = false) String createBy
, @RequestParam(value = "beginTime", required = false) String beginTime
, @RequestParam(value = "endTime", required = false) String endTime) {
startPage();
List<WeCommunityNewGroupVo> communityNewGroupVos = weCommunityNewGroupService.selectWeCommunityNewGroupList(empleCodeName, createBy, beginTime, endTime);
return getDataTable(communityNewGroupVos);
}
/**
* 获取新客自动拉群详细信息
*/
@ApiOperation(value = "获取新客自动拉群详细信息", httpMethod = "GET")
@PreAuthorize("@ss.hasPermi('wecom:communityNewGroup:query')")
@GetMapping(value = "/{id}")
public AjaxResult<WeCommunityNewGroupVo> getInfo(@PathVariable("newGroupId") @ApiParam("主键ID") Long newGroupId) {
return AjaxResult.success(weCommunityNewGroupService.selectWeCommunityNewGroupById(newGroupId));
}
/**
* 修改新客自动拉群
*/
@ApiOperation(value = "修改新客自动拉群", httpMethod = "PUT")
@PreAuthorize("@ss.hasPermi('wecom:communityNewGroup:edit')")
@Log(title = "新客自动拉群", businessType = BusinessType.UPDATE)
@PutMapping("/update")
public AjaxResult edit(@RequestBody @Validated WeCommunityNewGroupDto communityNewGroupDto) {
weCommunityNewGroupService.updateWeCommunityNewGroup(communityNewGroupDto);
return AjaxResult.success();
}
/**
* 删除新客自动拉群
*/
@ApiOperation(value = "删除新客自动拉群", httpMethod = "DELETE")
@PreAuthorize("@ss.hasPermi('wecom:communityNewGroup:remove')")
@Log(title = "新客自动拉群", businessType = BusinessType.DELETE)
@DeleteMapping("/delete/{ids}")
public AjaxResult remove(@PathVariable String ids) {
List<String> idList = Arrays.stream(StringUtils.split(ids, ",")).collect(Collectors.toList());
return toAjax(weCommunityNewGroupService.batchRemoveWeCommunityNewGroupIds(idList));
}
/**
* 新增新客自动拉群
*/
@ApiOperation(value = "新增新客自动拉群", httpMethod = "POST")
@PreAuthorize("@ss.hasPermi('wecom:communityNewGroup:add')")
@Log(title = "新客自动拉群", businessType = BusinessType.INSERT)
@PostMapping("/add")
public AjaxResult add(@RequestBody @Validated WeCommunityNewGroupDto communityNewGroupDto) {
try {
weCommunityNewGroupService.add(communityNewGroupDto);
return AjaxResult.success();
} catch (Exception e) {
e.printStackTrace();
if (e instanceof WeComException) {
return AjaxResult.error(e.getMessage());
} else {
return AjaxResult.error("请求接口异常!");
}
}
}
/**
* 员工活码批量下载
*
* @param ids 新客自动拉群ids
* @param request 请求
* @param response 输出
* @throws Exception
*/
@ApiOperation(value = "员工活码批量下载", httpMethod = "GET")
@PreAuthorize("@ss.hasPermi('wecom:code:downloadBatch')")
@Log(title = "员工活码批量下载", businessType = BusinessType.OTHER)
@GetMapping("/downloadBatch")
public void downloadBatch(String ids, HttpServletRequest request, HttpServletResponse response) {
List<String> idList = Arrays.stream(Optional.ofNullable(ids).orElse("").split(","))
.filter(StringUtils::isNotEmpty).collect(Collectors.toList());
try {
List<WeCommunityNewGroupVo> weCommunityNewGroupVos = weCommunityNewGroupService.selectWeCommunityNewGroupByIds(idList);
//zip输出流
ZipOutputStream zos = new ZipOutputStream(response.getOutputStream());
if (CollectionUtil.isNotEmpty(weCommunityNewGroupVos)) {
for (WeCommunityNewGroupVo communityNewGroupVo : weCommunityNewGroupVos) {
String qrCode = communityNewGroupVo.getQrCode();
if (StringUtils.isEmpty(qrCode)) {
continue;
}
URL url = new URL(qrCode);
//每个二维码名称
String fileName = communityNewGroupVo.getEmpleCodeName() + communityNewGroupVo.getActivityScene() + ".jpg";
zos.putNextEntry(new ZipEntry(fileName));
InputStream fis = url.openConnection().getInputStream();
byte[] buffer = new byte[1024];
int r = 0;
while ((r = fis.read(buffer)) != -1) {
zos.write(buffer, 0, r);
}
fis.close();
}
}
//关闭zip输出流
zos.flush();
zos.close();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
@ApiOperation(value = "员工活码下载", httpMethod = "GET")
@PreAuthorize("@ss.hasPermi('wecom:code:download')")
@Log(title = "员工活码下载", businessType = BusinessType.OTHER)
@GetMapping("/download")
public void download(String id, HttpServletRequest request, HttpServletResponse response) {
WeCommunityNewGroupVo communityNewGroupVo = weCommunityNewGroupService.selectWeCommunityNewGroupById(Long.valueOf(id));
if (StringUtils.isEmpty(communityNewGroupVo.getQrCode())) {
return;
} else {
try {
FileUtils.downloadFile(communityNewGroupVo.getQrCode(), response.getOutputStream());
} catch (IOException e) {
e.printStackTrace();
}
}
}
}