WeGroupFissionController.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. package com.linkwechat.web.controller.system;
  2. import com.baomidou.mybatisplus.core.metadata.IPage;
  3. import com.linkwechat.common.annotation.InnerAuth;
  4. import com.linkwechat.common.core.controller.BaseController;
  5. import com.linkwechat.common.core.domain.AjaxResult;
  6. import com.linkwechat.common.core.page.TableDataInfo;
  7. import com.linkwechat.common.utils.QrCodeGenerator;
  8. import com.linkwechat.common.utils.QrcodeUtils;
  9. import com.linkwechat.common.utils.createQrCode.CreateQRCodeByCodeVO;
  10. import com.linkwechat.common.utils.createQrCode.WxMiniProgramGetQRCodeByCommonUtil;
  11. import com.linkwechat.domain.weGroupFission.dto.DistDto;
  12. import com.linkwechat.domain.weGroupFission.dto.WeGroupFissionDetailDto;
  13. import com.linkwechat.domain.weGroupFission.dto.WeGroupFissionDto;
  14. import com.linkwechat.domain.weGroupFission.entity.WeGroupFission;
  15. import com.linkwechat.domain.weGroupFission.vo.CreateWechatGroupFissionUrlVo;
  16. import com.linkwechat.domain.weGroupFission.vo.WeGroupFissionAddVo;
  17. import com.linkwechat.domain.weGroupFission.vo.WeGroupFissionVo;
  18. import com.linkwechat.service.IWeGroupFissionService;
  19. import com.linkwechat.web.service.ISysUserService;
  20. import io.swagger.annotations.Api;
  21. import io.swagger.annotations.ApiOperation;
  22. import lombok.extern.slf4j.Slf4j;
  23. import me.chanjar.weixin.common.error.WxErrorException;
  24. import org.apache.commons.lang3.StringUtils;
  25. import org.springframework.beans.factory.annotation.Autowired;
  26. import org.springframework.beans.factory.annotation.Value;
  27. import org.springframework.http.HttpHeaders;
  28. import org.springframework.http.HttpStatus;
  29. import org.springframework.http.MediaType;
  30. import org.springframework.http.ResponseEntity;
  31. import org.springframework.web.bind.annotation.*;
  32. import javax.annotation.Resource;
  33. import javax.servlet.http.HttpServletRequest;
  34. import javax.servlet.http.HttpServletResponse;
  35. import javax.validation.Valid;
  36. import java.util.ArrayList;
  37. import java.util.List;
  38. /**
  39. * @Description: 群裂变活动表
  40. * @Author: jeecg-boot
  41. * @Date: 2026-01-28
  42. * @Version: V1.0
  43. */
  44. @Slf4j
  45. //@Api(tags="群裂变后台接口相关")
  46. @RestController
  47. @RequestMapping("system/weGroupFission")
  48. @CrossOrigin
  49. public class WeGroupFissionController extends BaseController {
  50. @Autowired
  51. private IWeGroupFissionService weGroupFissionService;
  52. @Autowired
  53. private ISysUserService sysUserService;
  54. @Resource
  55. private WxMiniProgramGetQRCodeByCommonUtil wxMiniProgramGetQRCodeByCommonUtil;
  56. //微信小程序的appid
  57. @Value("${wechat.app_id}")
  58. private String lifeWechatAppId;
  59. //微信小程序的appid
  60. @Value("${wechat.secret}")
  61. private String lifeWechatSecret;
  62. /**
  63. * @version
  64. * @author: hxl
  65. * @Date: 2026/1/28 10:43
  66. * @Description: 后台分页列表
  67. */
  68. //@ApiOperation(value="群裂变活动表-分页列表查询", notes="群裂变活动表-分页列表查询")
  69. @PostMapping(value = "/list")
  70. public TableDataInfo<?> queryPageList(@RequestBody WeGroupFissionVo weGroupFissionVo){
  71. return weGroupFissionService.getPageList(weGroupFissionVo);
  72. }
  73. /**
  74. * @version
  75. * @author: hxl
  76. * @Date: 2026/1/28 11:10
  77. * @Description:
  78. */
  79. //@ApiOperation(value="群裂变活动表-添加或者修改", notes="群裂变活动表-添加或者修改")
  80. @PostMapping(value = "/addOrUpdate")
  81. public AjaxResult addOrUpdate(@RequestBody @Valid WeGroupFissionAddVo weGroupFissionAddVo) {
  82. try{
  83. weGroupFissionService.addOrUpdate(weGroupFissionAddVo);
  84. return AjaxResult.success();
  85. }catch (Exception e){
  86. return AjaxResult.error(e.getMessage());
  87. }
  88. }
  89. /**
  90. * @version
  91. * @author: hxl
  92. * @Date: 2026/1/28 11:11
  93. * @Description: 详情接口
  94. */
  95. //@ApiOperation(value="群裂变活动表-详情接口", notes="群裂变活动表-详情接口")
  96. @GetMapping(value = "/queryById")
  97. public AjaxResult queryById(@RequestParam(name="id",required=true) String id) {
  98. try{
  99. WeGroupFissionDetailDto weGroupFissionDetailDto = weGroupFissionService.queryDetailById(id,"1");
  100. return AjaxResult.success(weGroupFissionDetailDto);
  101. }catch (Exception e){
  102. return AjaxResult.error(e.getMessage());
  103. }
  104. }
  105. /**
  106. * @version
  107. * @author: hxl
  108. * @Date: 2026/1/28 11:11
  109. * @Description: 通过id删除数据
  110. */
  111. //@ApiOperation(value="群裂变活动表-通过id删除", notes="群裂变活动表-通过id删除")
  112. @DeleteMapping(value = "/delete")
  113. public AjaxResult delete(@RequestParam(name="id",required=true) String id) {
  114. try{
  115. weGroupFissionService.deleteByWeGroupFissionId(id);
  116. return AjaxResult.success();
  117. }catch (Exception e){
  118. return AjaxResult.error(e.getMessage());
  119. }
  120. }
  121. /**
  122. * @version
  123. * @author: hxl
  124. * @Date: 2026/1/28 15:42
  125. * @Description: 生成小程序的群裂变页面加密链接
  126. */
  127. //@ApiOperation(value="群裂变活动表-群打卡微信小程序短链", notes="群裂变活动表-群打卡微信小程序短链")
  128. @PostMapping(value = "/getWechatGroupFissionUrl")
  129. public AjaxResult getWechatGroupFissionUrl(@RequestBody CreateWechatGroupFissionUrlVo createWechatGroupFissionUrlVo) {
  130. if(StringUtils.isBlank(createWechatGroupFissionUrlVo.getUrl())){
  131. return AjaxResult.error("生成页面路径不能为空");
  132. }
  133. if(StringUtils.isBlank(createWechatGroupFissionUrlVo.getGroupFissionId())){
  134. return AjaxResult.error("群裂变活动id不能为空");
  135. }
  136. if(StringUtils.isBlank(createWechatGroupFissionUrlVo.getVersion())){
  137. return AjaxResult.error("版本不能为空");
  138. }
  139. try{
  140. String url = weGroupFissionService.getWechatGroupFissionUrl(createWechatGroupFissionUrlVo);
  141. return AjaxResult.success(url);
  142. }catch (Exception e){
  143. return AjaxResult.error(e.getMessage());
  144. }
  145. }
  146. /**
  147. * @version
  148. * @author: hxl
  149. * @Date: 2026/1/28 16:36
  150. * @Description: 企业微信群列表
  151. */
  152. //@ApiOperation(value="群打卡活动app-企业微信群列表", notes="群打卡活动app-企业微信群列表")
  153. @GetMapping(value = "/getWecomGroupList")
  154. public AjaxResult getWecomGroupList() {
  155. try{
  156. List<DistDto> list = weGroupFissionService.getWecomGroupList();
  157. return AjaxResult.success(list);
  158. }catch (Exception e){
  159. return AjaxResult.error(e.getMessage());
  160. }
  161. }
  162. /**
  163. * @version
  164. * @author: hxl
  165. * @Date: 2026/1/28 16:36
  166. * @Description: 企业微信群列表
  167. */
  168. //@ApiOperation(value="群裂变活动表-企业微信员工列表", notes="群裂变活动表-企业微信员工列表")
  169. @GetMapping(value = "/getWecomEmployeeList")
  170. public AjaxResult getWecomEmployeeList() {
  171. try{
  172. List<DistDto> list = weGroupFissionService.getWecomEmployeeList();
  173. return AjaxResult.success(list);
  174. }catch (Exception e){
  175. return AjaxResult.error(e.getMessage());
  176. }
  177. }
  178. /**
  179. * @version
  180. * @author: hxl
  181. * @Date: 2026/1/31 16:19
  182. * @Description: 通过类型查询字典列表 type 1.商户 2.权益券 3.抽奖 4.负责人列表
  183. */
  184. @GetMapping(value = "/getDictListByType")
  185. public AjaxResult getDictListByType(@RequestParam(name="type",required=true) String type) {
  186. try{
  187. List<DistDto> list = new ArrayList<>();
  188. //商户字典
  189. if("1".equals(type)){
  190. //商户
  191. list = weGroupFissionService.getLocalMerchantInfoDictDtos();
  192. }else if("2".equals(type)){
  193. //权益券
  194. list = weGroupFissionService.getRightInfoDictDtos();
  195. }else if("3".equals(type)){
  196. //抽奖活动
  197. list = weGroupFissionService.getActivityDictDtos();
  198. }else if("4".equals(type)){
  199. //负责人
  200. list = weGroupFissionService.getUserDictDtos();
  201. }
  202. return AjaxResult.success(list);
  203. }catch (Exception e){
  204. return AjaxResult.error(e.getMessage());
  205. }
  206. }
  207. /**
  208. * @version
  209. * @author: hxl
  210. * @Date: 2026/2/9 8:34
  211. * @Description: 获取外部群二维码的链接
  212. */
  213. @GetMapping(value = "/getChartQrCodeByChatId")
  214. public AjaxResult getChartQrCodeByChatId(@RequestParam(name="chatId",required=true) String chatId,@RequestParam(name="activityId",required=false,defaultValue = "") String activityId) throws WxErrorException {
  215. try {
  216. String qrCode = weGroupFissionService.getChartQrCodeByChatId(chatId, activityId);
  217. return AjaxResult.success(qrCode);
  218. } catch (Exception e) {
  219. e.printStackTrace();
  220. return AjaxResult.error("二维码获取失败:"+e.getMessage());
  221. }
  222. }
  223. /**
  224. * @version
  225. * @author: hxl
  226. * @Date: 2026/2/9 8:34
  227. * @Description: 获取外部群二维码的链接二进制流
  228. */
  229. @GetMapping(value = "/getChartQrCodeByChatIdStream")
  230. public ResponseEntity<byte[]> getChartQrCodeByChatIdStream(@RequestParam(name="chatId",required=true) String chatId, @RequestParam(name="activityId",required=false,defaultValue = "") String activityId){
  231. try {
  232. String qrCode = weGroupFissionService.getChartQrCodeByChatId(chatId, activityId);
  233. byte[] qrcodeBytes = QrcodeUtils.qrcodeUrlToBytes(qrCode);
  234. return QrcodeUtils.returnQrcodeToFront(qrcodeBytes);
  235. } catch (Exception e) {
  236. e.printStackTrace();
  237. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("二维码获取失败:".getBytes());
  238. }
  239. }
  240. /**
  241. * @version
  242. * @author: hxl
  243. * @Date: 2026/2/25 10:34
  244. * @Description: 获取短链二进制流
  245. */
  246. @PostMapping(value = "/getWechatGroupFissionUrlStream")
  247. public void getWechatGroupFissionUrlStream(@RequestBody CreateWechatGroupFissionUrlVo createWechatGroupFissionUrlVo,HttpServletResponse servletResponse){
  248. if(StringUtils.isBlank(createWechatGroupFissionUrlVo.getUrl())){
  249. throw new RuntimeException("生成页面路径不能为空");
  250. }
  251. if(StringUtils.isBlank(createWechatGroupFissionUrlVo.getGroupFissionId())){
  252. throw new RuntimeException("群裂变活动id不能为空");
  253. }
  254. if(StringUtils.isBlank(createWechatGroupFissionUrlVo.getVersion())){
  255. throw new RuntimeException("版本不能为空");
  256. }
  257. CreateQRCodeByCodeVO createQRCode = new CreateQRCodeByCodeVO();
  258. createQRCode.setKeyName("id");
  259. createQRCode.setKeyValue(createWechatGroupFissionUrlVo.getGroupFissionId());
  260. createQRCode.setSharePath(createWechatGroupFissionUrlVo.getUrl());
  261. createQRCode.setEnv_version(createWechatGroupFissionUrlVo.getVersion());
  262. createQRCode.setWidth(300); // 小程序码宽度
  263. createQRCode.setAuto_color(false); // 不自动配色
  264. createQRCode.setIs_hyaline(false); // 不透明
  265. try{
  266. wxMiniProgramGetQRCodeByCommonUtil.createQRCode(createQRCode,lifeWechatAppId,lifeWechatSecret,servletResponse);
  267. }catch (Exception e){
  268. throw new RuntimeException("生成二维码错误");
  269. }
  270. }
  271. }