Commit fd546ea3 by 姚宇航

群活码模块开发

1 parent 5dae7f82
Showing 19 changed files with 1130 additions and 387 deletions
......@@ -52,6 +52,8 @@ public class SysLoginController
@Autowired
private WeAccessTokenClient weAccessTokenClient;
// @Autowired
// private IWeGroupCodeService weGroupCodeService;
/**
......@@ -157,5 +159,32 @@ public class SysLoginController
}
// /**
// * 从群活码获取第一个可用的实际码
// */
// @GetMapping("/getChatQRCode")
// public AjaxResult getActual(Long weGroupCodeId) {
// WeGroupCode weGroupCode = weGroupCodeService.selectWeGroupCodeById(weGroupCodeId);
// List<WeGroupCodeActual> weGroupCodeActualList = weGroupCodeService.selectActualListByGroupCodeId(weGroupCodeId);
// WeGroupCodeActual weGroupCodeActual = null;
// for (WeGroupCodeActual item : weGroupCodeActualList) {
// // 获取第一个可用的实际码
// if (item.getStatus().intValue() == WeConstans.WE_GROUP_CODE_ENABLE) {
// weGroupCodeActual = item;
// break;
// }
// }
// if (StringUtils.isNotNull(weGroupCodeActual)) {
// AjaxResult ajax = AjaxResult.success();
// ajax.put("tipMsg", weGroupCode.getTipMsg());
// ajax.put("activityName", weGroupCode.getActivityName());
// ajax.put("groupName", weGroupCodeActual.getChatGroupName());
// ajax.put("actualQRCode", weGroupCodeActual.getActualGroupQrCode());
// return ajax;
// } else {
// return AjaxResult.error(HttpStatus.NOT_FOUND, "数据不存在");
// }
// }
}
package com.linkwechat.web.controller.wecom;
import com.linkwechat.common.annotation.Log;
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.enums.BusinessType;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.wecom.domain.WeGroupCodeActual;
import com.linkwechat.wecom.service.IWeGroupCodeActualService;
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;
/**
* 实际群码Controller
*
*
* @author ruoyi
* @date 2020-10-07
*/
@RestController
@RequestMapping("/wecom/actual")
public class WeGroupCodeActualController extends BaseController
{
public class WeGroupCodeActualController extends BaseController {
@Autowired
private IWeGroupCodeActualService weGroupCodeActualService;
// /**
// * 查询实际群码列表
// */
// @PreAuthorize("@ss.hasPermi('wecom:actual:list')")
// @GetMapping("/list")
// public TableDataInfo list(WeGroupCodeActual weGroupCodeActual)
// {
// startPage();
// List<WeGroupCodeActual> list = weGroupCodeActualService.selectWeGroupCodeActualList(weGroupCodeActual);
// return getDataTable(list);
// }
/**
* 查询实际群码列表
*/
@PreAuthorize("@ss.hasPermi('wecom:actual:list')")
@GetMapping("/list")
public TableDataInfo list(WeGroupCodeActual weGroupCodeActual) {
startPage();
List<WeGroupCodeActual> list = weGroupCodeActualService.selectWeGroupCodeActualList(weGroupCodeActual);
return getDataTable(list);
}
//
// /**
// * 导出实际群码列表
......@@ -47,27 +51,32 @@ public class WeGroupCodeActualController extends BaseController
// ExcelUtil<WeGroupCodeActual> util = new ExcelUtil<WeGroupCodeActual>(WeGroupCodeActual.class);
// return util.exportExcel(list, "actual");
// }
//
// /**
// * 获取实际群码详细信息
// */
// @PreAuthorize("@ss.hasPermi('wecom:actual:query')")
// @GetMapping(value = "/{id}")
// public AjaxResult getInfo(@PathVariable("id") Long id)
// {
// return AjaxResult.success(weGroupCodeActualService.selectWeGroupCodeActualById(id));
// }
/**
* 新增实际群码
* 获取实际群码详细信息
*/
@PreAuthorize("@ss.hasPermi('wecom:actual:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id) {
WeGroupCodeActual weGroupCodeActual = weGroupCodeActualService.selectWeGroupCodeActualById(id);
if (StringUtils.isNull(weGroupCodeActual)) {
return AjaxResult.error(HttpStatus.NOT_FOUND, "数据不存在");
}
return AjaxResult.success(weGroupCodeActual);
}
/**
* 新增实际群码查询
*/
@PreAuthorize("@ss.hasPermi('wecom:actual:add')")
@Log(title = "实际群码", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody WeGroupCodeActual weGroupCodeActual)
{
weGroupCodeActualService.save(weGroupCodeActual);
return AjaxResult.success();
public AjaxResult add(@Validated @RequestBody WeGroupCodeActual weGroupCodeActual) {
// 唯一性检查
if (!weGroupCodeActualService.checkChatIdUnique(weGroupCodeActual)) {
return AjaxResult.error("新增实际群码失败, 该群聊二维码已存在");
}
return toAjax(weGroupCodeActualService.insertWeGroupCodeActual(weGroupCodeActual));
}
/**
......@@ -76,20 +85,26 @@ public class WeGroupCodeActualController extends BaseController
@PreAuthorize("@ss.hasPermi('wecom:actual:edit')")
@Log(title = "实际群码", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody WeGroupCodeActual weGroupCodeActual)
{
weGroupCodeActualService.updateById(weGroupCodeActual);
return AjaxResult.success();
public AjaxResult edit(@RequestBody WeGroupCodeActual weGroupCodeActual) {
WeGroupCodeActual original = weGroupCodeActualService.selectWeGroupCodeActualById(weGroupCodeActual.getId());
if (StringUtils.isNull(original)) {
return AjaxResult.error(HttpStatus.NOT_FOUND, "数据不存在");
}
// 实际码对应客户群变化时,检查其唯一性
if (!original.getChatId().equals(weGroupCodeActual.getChatId()) &&
!weGroupCodeActualService.checkChatIdUnique(weGroupCodeActual)) {
return AjaxResult.error("修改实际群码失败, 该群聊二维码已存在");
}
return toAjax(weGroupCodeActualService.updateWeGroupCodeActual(weGroupCodeActual));
}
// /**
// * 删除实际群码
// */
// @PreAuthorize("@ss.hasPermi('wecom:actual:remove')")
// @Log(title = "实际群码", businessType = BusinessType.DELETE)
// @DeleteMapping("/{ids}")
// public AjaxResult remove(@PathVariable Long[] ids)
// {
// return toAjax(weGroupCodeActualService.deleteWeGroupCodeActualByIds(ids));
// }
/**
* 删除实际群码
*/
@PreAuthorize("@ss.hasPermi('wecom:actual:remove')")
@Log(title = "实际群码", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids) {
return toAjax(weGroupCodeActualService.deleteWeGroupCodeActualByIds(ids));
}
}
package com.linkwechat.web.controller.wecom;
import cn.hutool.core.collection.CollectionUtil;
import com.linkwechat.common.annotation.Log;
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.enums.BusinessType;
import com.linkwechat.common.utils.SecurityUtils;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.common.utils.file.FileUtils;
import com.linkwechat.wecom.domain.WeGroupCode;
import com.linkwechat.wecom.domain.WeGroupCodeActual;
import com.linkwechat.wecom.service.IWeGroupCodeService;
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 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 ruoyi
* @date 2020-10-07
*/
@RestController
@RequestMapping("/wecom/groupCode")
public class WeGroupCodeController extends BaseController
{
public class WeGroupCodeController extends BaseController {
@Autowired
private IWeGroupCodeService weGroupCodeService;
// /**
// * 查询客户群活码列表
// */
// @PreAuthorize("@ss.hasPermi('wecom:code:list')")
// @GetMapping("/list")
// public TableDataInfo list(WeGroupCode weGroupCode)
// {
// startPage();
// List<WeGroupCode> list = weGroupCodeService.selectWeGroupCodeList(weGroupCode);
// return getDataTable(list);
// }
//
/**
* 查询客户群活码列表
*/
@PreAuthorize("@ss.hasPermi('wecom:groupCode:list')")
@GetMapping("/list")
public TableDataInfo list(WeGroupCode weGroupCode) {
startPage();
List<WeGroupCode> list = weGroupCodeService.selectWeGroupCodeList(weGroupCode);
return getDataTable(list);
}
/**
* 批量下载群活码
*/
@PreAuthorize("@ss.hasPermi('wecom:groupCode: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<WeGroupCode> weGroupCodeList = weGroupCodeService.selectWeGroupCodeListByIds(idList);
ZipOutputStream zos = new ZipOutputStream(response.getOutputStream());
if (CollectionUtil.isNotEmpty(weGroupCodeList)) {
for (WeGroupCode weGroupCode : weGroupCodeList) {
String codeUrl = weGroupCode.getCodeUrl();
if (StringUtils.isEmpty(codeUrl)) {
continue;
}
URL url = new URL(codeUrl);
String fileName = weGroupCode.getActivityName() + ".png";
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();
}
}
@PreAuthorize("@ss.hasPermi('wecom:groupCode:download')")
@Log(title = "群活码下载", businessType = BusinessType.OTHER)
@GetMapping("/download")
public void download(String id, HttpServletRequest request, HttpServletResponse response) {
WeGroupCode weGroupCode = weGroupCodeService.selectWeGroupCodeById(Long.valueOf(id));
try {
FileUtils.downloadFile(weGroupCode.getCodeUrl(), response.getOutputStream());
} catch (IOException e) {
e.printStackTrace();
}
}
// /**
// * 导出客户群活码列表
// */
......@@ -49,39 +117,68 @@ public class WeGroupCodeController extends BaseController
// return util.exportExcel(list, "code");
// }
// /**
// * 获取客户群活码详细信息
// */
// @PreAuthorize("@ss.hasPermi('wecom:code:query')")
// @GetMapping(value = "/{id}")
// public AjaxResult getInfo(@PathVariable("id") Long id)
// {
// return AjaxResult.success(weGroupCodeService.selectWeGroupCodeById(id));
// }
/**
* 获取客户群活码详细信息
*/
@PreAuthorize("@ss.hasPermi('wecom:groupCode:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id) {
WeGroupCode weGroupCode = weGroupCodeService.selectWeGroupCodeById(id);
if (StringUtils.isNull(weGroupCode)) {
return AjaxResult.error(HttpStatus.NOT_FOUND, "数据不存在");
}
List<WeGroupCodeActual> weGroupCodeActualList = weGroupCodeService.selectActualListByGroupCodeId(weGroupCode.getId());
weGroupCode.setActualList(weGroupCodeActualList);
return AjaxResult.success(weGroupCode);
}
/**
* 新增客户群活码
*/
@PreAuthorize("@ss.hasPermi('wecom:code:add')")
@PreAuthorize("@ss.hasPermi('wecom:groupCode:add')")
@Log(title = "客户群活码", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody WeGroupCode weGroupCode)
{
public AjaxResult add(@Validated @RequestBody WeGroupCode weGroupCode) {
// 唯一性检查
if (!weGroupCodeService.checkActivityNameUnique(weGroupCode)) {
return AjaxResult.error("添加群活码失败,活码名称 " + weGroupCode.getActivityName() + " 已存在");
}
AjaxResult ajax = AjaxResult.success();
weGroupCode.setCreateBy(SecurityUtils.getUsername());
weGroupCodeService.insertWeGroupCode(weGroupCode);
return AjaxResult.success();
ajax.put("id", weGroupCode.getId());
return ajax;
}
/**
* 修改客户群活码
*/
@PreAuthorize("@ss.hasPermi('wecom:code:edit')")
@PreAuthorize("@ss.hasPermi('wecom:groupCode:edit')")
@Log(title = "客户群活码", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody WeGroupCode weGroupCode)
{
weGroupCodeService.updateWeGroupCode(weGroupCode);
@PutMapping(value = "/{id}")
public AjaxResult edit(@PathVariable("id") Long id, @RequestBody WeGroupCode weGroupCode) {
WeGroupCode originalCode = weGroupCodeService.selectWeGroupCodeById(id);
if (StringUtils.isNull(originalCode)) {
return AjaxResult.error(HttpStatus.NOT_FOUND, "数据不存在");
}
// 唯一性检查
if (!originalCode.getActivityName().equals(weGroupCode.getActivityName()) &&
!weGroupCodeService.checkActivityNameUnique(weGroupCode)) {
return AjaxResult.error("修改群活码失败,活码名称 " + weGroupCode.getActivityName() + " 已存在");
}
weGroupCode.setId(id);
weGroupCode.setUpdateBy(SecurityUtils.getUsername());
return toAjax(weGroupCodeService.updateWeGroupCode(weGroupCode));
}
return AjaxResult.success();
/**
* 删除客户群活码
*/
@PreAuthorize("@ss.hasPermi('wecom:groupCode:remove')")
@Log(title = "客户群活码", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult batchRemove(@PathVariable Long[] ids) {
return toAjax(weGroupCodeService.deleteWeGroupCodeByIds(ids));
}
// /**
......@@ -94,4 +191,6 @@ public class WeGroupCodeController extends BaseController
// {
// return toAjax(weGroupCodeService.deleteWeGroupCodeByIds(ids));
// }
}
......@@ -105,6 +105,16 @@ public class WeConstans {
*/
public static final Integer WE_ROOT_CATEGORY_ID = 0;
/**
* 实际群活码正在使用中
*/
public static final Integer WE_GROUP_CODE_ENABLE = 0;
/**
* 群活码已禁用/达到扫码次数上限
*/
public static final Integer WE_GROUP_CODE_DISABLE = 2;
/**
* 单人活码
......@@ -240,6 +250,9 @@ public class WeConstans {
put("batch_job_result", "weEventBatchJobResultImpl");
//外部联系人事件
put("change_external_contact", "weEventChangeExternalContactImpl");
//客户群聊事件
put("change_external_chat", "weEventChangeExternalChatImpl");
}
};
......
package com.linkwechat.common.utils;
import java.awt.*;
import java.awt.geom.RoundRectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URL;
import java.util.HashMap;
import java.util.Hashtable;
import javax.imageio.ImageIO;
import javax.servlet.ServletOutputStream;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import com.linkwechat.common.constant.Constants;
public class QREncode {
private static final int BLACK = 0xFF000000;
private static final int WHITE = 0xFFFFFFFF;
private QREncode() {}
public static BufferedImage toBufferedImage(BitMatrix matrix) {
int width = matrix.getWidth();
int height = matrix.getHeight();
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
image.setRGB(x, y, matrix.get(x, y) ? BLACK : WHITE);
}
}
return image;
}
public static void writeToFile(BitMatrix matrix, String format, File file)
throws IOException {
BufferedImage image = toBufferedImage(matrix);
if (!ImageIO.write(image, format, file)) {
throw new IOException("Could not write an image of format " + format + " to " + file);
}
}
public static void writeToStream(BitMatrix matrix, String format, OutputStream stream)
throws IOException {
BufferedImage image = toBufferedImage(matrix);
if (!ImageIO.write(image, format, stream)) {
throw new IOException("Could not write an image of format " + format);
}
}
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void main(String[] args) throws Exception {
String text = "http://open.weixin.qq.com/qr/code/?username=LinkWeChat2021";
int width = 300;
int height = 300;
String format = "png";
Hashtable hints = new Hashtable();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
BitMatrix bitMatrix = new MultiFormatWriter().encode(text,
BarcodeFormat.QR_CODE, width, height, hints);
File outputFile = new File("d:"+File.separator+"qr.png");
QREncode.writeToFile(bitMatrix, format, outputFile);
}
private static final int BLACK = 0xFF000000;
private static final int WHITE = 0xFFFFFFFF;
/**
* 默认宽度
*/
private static final Integer WIDTH = 140;
/**
* 默认高度
*/
private static final Integer HEIGHT = 140;
/**
* LOGO 默认宽度
*/
private static final Integer LOGO_WIDTH = 22;
/**
* LOGO 默认高度
*/
private static final Integer LOGO_HEIGHT = 22;
/**
* 图片格式
*/
private static final String IMAGE_FORMAT = "png";
private QREncode() {
}
public static BufferedImage toBufferedImage(BitMatrix matrix) {
int width = matrix.getWidth();
int height = matrix.getHeight();
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
image.setRGB(x, y, matrix.get(x, y) ? BLACK : WHITE);
}
}
return image;
}
public static void writeToFile(BitMatrix matrix, String format, File file)
throws IOException {
BufferedImage image = toBufferedImage(matrix);
if (!ImageIO.write(image, format, file)) {
throw new IOException("Could not write an image of format " + format + " to " + file);
}
}
public static void writeToStream(BitMatrix matrix, String format, OutputStream stream)
throws IOException {
BufferedImage image = toBufferedImage(matrix);
if (!ImageIO.write(image, format, stream)) {
throw new IOException("Could not write an image of format " + format);
}
}
/**
* 生成二维码
*
* @param content 内容
* @param logoUrl logo 在线地址
* @return
*/
private static BufferedImage crateQRCode(String content, String logoUrl) {
if (StringUtils.isNotBlank(content)) {
ServletOutputStream stream = null;
HashMap<EncodeHintType, Comparable> hints = new HashMap<>(4);
// 指定字符编码为utf-8
hints.put(EncodeHintType.CHARACTER_SET, Constants.UTF8);
// 指定二维码的纠错等级为中级
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M);
// 设置图片的边距
hints.put(EncodeHintType.MARGIN, 2);
try {
QRCodeWriter writer = new QRCodeWriter();
BitMatrix bitMatrix = writer.encode(content, BarcodeFormat.QR_CODE, WIDTH, HEIGHT, hints);
BufferedImage bufferedImage = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
for (int x = 0; x < WIDTH; x++) {
for (int y = 0; y < HEIGHT; y++) {
bufferedImage.setRGB(x, y, bitMatrix.get(x, y) ? 0xFF000000 : 0xFFFFFFFF);
}
}
if (StringUtils.isNotBlank(logoUrl)) {
insertLogo(bufferedImage, logoUrl);
}
return bufferedImage;
} catch (Exception e) {
e.printStackTrace();
} finally {
if (stream != null) {
try {
stream.flush();
stream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
return null;
}
/**
* 二维码插入logo
*
* @param source 二维码
* @param logoUrl logo 在线地址
* @throws Exception
*/
private static void insertLogo(BufferedImage source, String logoUrl) throws Exception {
// logo 源可为 File/InputStream/URL
Image src = ImageIO.read(new URL(logoUrl));
// 插入LOGO
Graphics2D graph = source.createGraphics();
int x = (WIDTH - LOGO_WIDTH) / 2;
int y = (HEIGHT - LOGO_HEIGHT) / 2;
graph.drawImage(src, x, y, LOGO_WIDTH, LOGO_HEIGHT, null);
Shape shape = new RoundRectangle2D.Float(x, y, LOGO_WIDTH, LOGO_HEIGHT, 6, 6);
graph.setStroke(new BasicStroke(3f));
graph.draw(shape);
graph.dispose();
}
/**
* 生成二维码并保存
*
* @param content 内容
* @throws IOException
*/
public static void saveQRCode(String content, String filePath) throws IOException {
BufferedImage image = crateQRCode(content, null);
if (StringUtils.isNotNull(image)) {
File file = createFile(filePath);
ImageIO.write(image, IMAGE_FORMAT, file);
}
}
/**
* 生成带logo的二维码并保存
*
* @param content 二维码内容
* @param logoUrl logo地址
* @throws IOException
*/
public static void saveQRCode(String content, String logoUrl, String filePath) throws IOException {
BufferedImage image = crateQRCode(content, logoUrl);
if (StringUtils.isNotNull(image)) {
File file = createFile(filePath);
ImageIO.write(image, IMAGE_FORMAT, file);
}
}
/**
* 生成带二维码并生成流文件进行传输
*
* @param content 内容
* @param output 输出流
* @throws Exception
*/
public void getQRCode(String content, OutputStream output) throws Exception {
BufferedImage image = crateQRCode(content, null);
if (StringUtils.isNotNull(image)) {
ImageIO.write(image, IMAGE_FORMAT, output);
}
}
/**
* 生成带logo的二维码并生成流文件进行传输
*
* @param content 内容
* @param logoUrl logo资源
* @param output 输出流
* @throws Exception
*/
public void getQRCode(String content, String logoUrl, OutputStream output) throws Exception {
BufferedImage image = crateQRCode(content, logoUrl);
if (StringUtils.isNotNull(image)) {
ImageIO.write(image, IMAGE_FORMAT, output);
}
}
/**
* 根据指定路径创建空文件
* @param path 路径
* @return 空文件
*/
private static File createFile(String path) {
File file = new File(path);
try {
if (!file.exists()) {
file.getParentFile().mkdir();
file.createNewFile();
}
} catch (Exception e) {
e.printStackTrace();
}
return file;
}
@SuppressWarnings({"unchecked", "rawtypes"})
public static void main(String[] args) throws Exception {
String text = "http://open.weixin.qq.com/qr/code/?username=LinkWeChat2021";
int width = 300;
int height = 300;
String format = "png";
Hashtable<EncodeHintType, String> hints = new Hashtable<>();
hints.put(EncodeHintType.CHARACTER_SET, Constants.UTF8);
BitMatrix bitMatrix = new MultiFormatWriter().encode(text, BarcodeFormat.QR_CODE, width, height, hints);
File outputFile = new File("d:" + File.separator + "qr.png");
QREncode.writeToFile(bitMatrix, format, outputFile);
}
}
......@@ -158,7 +158,7 @@ public class FileUploadUtils {
return desc;
}
private static final String getPathFileName(String uploadDir, String fileName) throws IOException {
public static final String getPathFileName(String uploadDir, String fileName) throws IOException {
int dirLastIndex = RuoYiConfig.getProfile().length() + 1;
String currentDir = StringUtils.substring(uploadDir, dirLastIndex);
String pathFileName;
......
......@@ -6,51 +6,103 @@ import com.baomidou.mybatisplus.annotation.TableName;
import com.linkwechat.common.core.domain.BaseEntity;
import com.linkwechat.common.utils.SnowFlakeUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotNull;
import java.util.List;
/**
* 客户群活码对象 we_group_code
*
*
* @author ruoyi
* @date 2020-10-07
*/
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("we_group_code")
public class WeGroupCode
{
public class WeGroupCode extends BaseEntity {
private static final long serialVersionUID = 1L;
/** $column.columnComment */
/**
* $column.columnComment
*/
@TableId
private Long id= SnowFlakeUtil.nextId();
private Long id = SnowFlakeUtil.nextId();
/** 活动头像 */
/**
* 活码URL
*/
private String codeUrl;
/**
* 活码头像
*/
private String activityHeadUrl;
/** 活动名称 */
/**
* 活码名称
*/
@NotNull(message = "活码名称不能为空")
private String activityName;
/** 场景 */
/**
* 活码描述
*/
@NotNull(message = "活码描述不能为空")
private String activityDesc;
/**
* 场景
*/
private String activityScene;
/** 引导语 */
/**
* 加群引导语
*/
private String guide;
/** 进群是否提示:1:是;0:否; */
/**
* 进群是否提示:1:是;0:否;
*/
private Long joinGroupIsTip;
/** 进群提示语 */
/**
* 进群提示语
*/
private String tipMsg;
/** 客服二维码 */
/**
* 客服二维码
*/
private String customerServerQrCode;
/** 0:正常;2:删除; */
/**
* 0:正常;2:删除;
*/
private Long delFlag;
/**
* 可用实际码数量
*/
@TableField(exist = false)
private Long availableCodes;
/**
* 实际码扫码次数之和
*/
@TableField(exist = false)
private Long totalScanTimes;
/**
* 即将过期实际码数量
*/
@TableField(exist = false)
private Long aboutToExpireCodes;
/**
* 实际码
*/
@TableField(exist = false)
private List<WeGroupCodeActual> actualList;
......
......@@ -5,10 +5,11 @@ import java.util.Date;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.linkwechat.common.core.domain.BaseEntity;
import com.linkwechat.common.utils.SnowFlakeUtil;
import lombok.Data;
import javax.validation.constraints.NotNull;
/**
* 实际群码对象 we_group_code_actual
......@@ -27,21 +28,32 @@ public class WeGroupCodeActual
private Long id=SnowFlakeUtil.nextId();
/** 实际群码 */
@NotNull(message = "实际群活码称不能为空")
private String actualGroupQrCode;
/** 群名称 */
@NotNull(message = "群名称不能为空")
private String groupName;
/** 有效期 */
@NotNull(message = "有效期不能为空")
@JsonFormat(pattern = "yyyy-MM-dd")
private Date effectTime;
/** 扫码次数限制 */
@NotNull(message = "次数限制不能为空")
private Long scanCodeTimesLimit;
/** 群活码id */
@NotNull(message = "群活码id不能为空")
private Long groupCodeId;
/** 客户群id */
private String chatId;
/** 客户群名称 */
private String chatGroupName;
/** 扫码次数 */
private Long scanCodeTimes;
......@@ -50,6 +62,4 @@ public class WeGroupCodeActual
/** 0:使用中 */
private Long status;
}
package com.linkwechat.wecom.factory.impl;
import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.wecom.domain.WeGroupCodeActual;
import com.linkwechat.wecom.domain.vo.WxCpXmlMessageVO;
import com.linkwechat.wecom.factory.WeCallBackEventFactory;
import com.linkwechat.wecom.service.IWeGroupCodeActualService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* 客户群变更回调事件处理
*/
@Service
@Slf4j
public class WeEventChangeExternalChatImpl implements WeCallBackEventFactory {
@Autowired
private IWeGroupCodeActualService weGroupCodeActualService;
@Override
public void eventHandle(WxCpXmlMessageVO message) {
String changeType = message.getChangeType();
// 客户群状态变更(群名变更,群成员增加或移除,群主变更,群公告变更)
if (changeType.equals("update")) {
WeGroupCodeActual weGroupCodeActual = weGroupCodeActualService.selectActualCodeByChatId(message.getChatId());
if (StringUtils.isNotNull(weGroupCodeActual))
{
// 扫码次数+1
weGroupCodeActual.setScanCodeTimes(weGroupCodeActual.getScanCodeTimes() + 1);
if (weGroupCodeActual.getScanCodeTimes().equals(weGroupCodeActual.getScanCodeTimesLimit()))
{
weGroupCodeActual.setStatus(WeConstans.WE_GROUP_CODE_DISABLE.longValue());
log.info("客户群 " + weGroupCodeActual.getGroupName() + " 二维码扫描次数已达上限");
}
weGroupCodeActualService.updateWeGroupCodeActual(weGroupCodeActual);
}
}
}
}
......@@ -7,23 +7,29 @@ import com.linkwechat.wecom.domain.WeGroupCodeActual;
/**
* 实际群码Mapper接口
*
*
* @author ruoyi
* @date 2020-10-07
*/
public interface WeGroupCodeActualMapper extends BaseMapper<WeGroupCodeActual>
{
public interface WeGroupCodeActualMapper extends BaseMapper<WeGroupCodeActual> {
/**
* 查询实际群码
*
*
* @param id 实际群码ID
* @return 实际群码
*/
public WeGroupCodeActual selectWeGroupCodeActualById(Long id);
/**
* 根据群聊id获取群实际码
* @param chatId 群聊id
* @return 结果
*/
public WeGroupCodeActual selectWeGroupCodeActualByChatId(String chatId);
/**
* 查询实际群码列表
*
*
* @param weGroupCodeActual 实际群码
* @return 实际群码集合
*/
......@@ -31,7 +37,7 @@ public interface WeGroupCodeActualMapper extends BaseMapper<WeGroupCodeActual>
/**
* 新增实际群码
*
*
* @param weGroupCodeActual 实际群码
* @return 结果
*/
......@@ -39,7 +45,7 @@ public interface WeGroupCodeActualMapper extends BaseMapper<WeGroupCodeActual>
/**
* 修改实际群码
*
*
* @param weGroupCodeActual 实际群码
* @return 结果
*/
......@@ -47,7 +53,7 @@ public interface WeGroupCodeActualMapper extends BaseMapper<WeGroupCodeActual>
/**
* 删除实际群码
*
*
* @param id 实际群码ID
* @return 结果
*/
......@@ -55,9 +61,31 @@ public interface WeGroupCodeActualMapper extends BaseMapper<WeGroupCodeActual>
/**
* 批量删除实际群码
*
*
* @param ids 需要删除的数据ID
* @return 结果
*/
public int deleteWeGroupCodeActualByIds(Long[] ids);
/**
* 通过群活码id查询实际码列表
*
* @param groupCodeId 群活码id
* @return 结果
*/
public List<WeGroupCodeActual> selectActualListByGroupCodeId(Long groupCodeId);
/**
* 通过群活码id删除实际码
* @param groupCodeIds 群活码id列表
* @return 结果
*/
public int deleteActualListByGroupCodeIds(Long[] groupCodeIds);
/**
* 检测chatId是否唯一
* @param chatId 群聊id
* @return 结果
*/
public int checkChatIdUnique(String chatId);
}
......@@ -30,6 +30,13 @@ public interface WeGroupCodeMapper extends BaseMapper<WeGroupCode>
public List<WeGroupCode> selectWeGroupCodeList(WeGroupCode weGroupCode);
/**
* 根据群活码id查询群活码列表
* @param ids id列表
* @return 结果
*/
public List<WeGroupCode> selectWeGroupCodeListByIds(List<String> ids);
/**
* 新增客户群活码
*
* @param weGroupCode 客户群活码
......@@ -60,4 +67,11 @@ public interface WeGroupCodeMapper extends BaseMapper<WeGroupCode>
* @return 结果
*/
public int deleteWeGroupCodeByIds(Long[] ids);
/**
* 检测活码名称是否唯一
* @param activityName 活码名称
* @return 结果
*/
public int checkActivityNameUnique(String activityName);
}
......@@ -2,6 +2,9 @@ package com.linkwechat.wecom.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.linkwechat.wecom.domain.WeGroupCodeActual;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
/**
* 实际群码Service接口
......@@ -11,46 +14,53 @@ import com.linkwechat.wecom.domain.WeGroupCodeActual;
*/
public interface IWeGroupCodeActualService extends IService<WeGroupCodeActual>
{
// /**
// * 查询实际群码
// *
// * @param id 实际群码ID
// * @return 实际群码
// */
// public WeGroupCodeActual selectWeGroupCodeActualById(Long id);
//
// /**
// * 查询实际群码列表
// *
// * @param weGroupCodeActual 实际群码
// * @return 实际群码集合
// */
// public List<WeGroupCodeActual> selectWeGroupCodeActualList(WeGroupCodeActual weGroupCodeActual);
/**
* 查询实际群码
*
* @param id 实际群码ID
* @return 实际群码
*/
public WeGroupCodeActual selectWeGroupCodeActualById(Long id);
// /**
// * 新增实际群码
// *
// * @param weGroupCodeActual 实际群码
// * @return 结果
// */
// public int insertWeGroupCodeActual(WeGroupCodeActual weGroupCodeActual);
//
// /**
// * 修改实际群码
// *
// * @param weGroupCodeActual 实际群码
// * @return 结果
// */
// public int updateWeGroupCodeActual(WeGroupCodeActual weGroupCodeActual);
/**
* 根据群聊id获取对应群二维码
* @param chatId 群聊id
* @return 结果
*/
public WeGroupCodeActual selectActualCodeByChatId(String chatId);
/**
* 查询实际群码列表
*
* @param weGroupCodeActual 实际群码
* @return 实际群码集合
*/
public List<WeGroupCodeActual> selectWeGroupCodeActualList(WeGroupCodeActual weGroupCodeActual);
/**
* 新增实际群码
*
* @param weGroupCodeActual 实际群码
* @return 结果
*/
public int insertWeGroupCodeActual(WeGroupCodeActual weGroupCodeActual);
/**
* 修改实际群码
*
* @param weGroupCodeActual 实际群码
* @return 结果
*/
public int updateWeGroupCodeActual(WeGroupCodeActual weGroupCodeActual);
/**
* 批量删除实际群码
*
* @param ids 需要删除的实际群码ID
* @return 结果
*/
public int deleteWeGroupCodeActualByIds(Long[] ids);
// /**
// * 批量删除实际群码
// *
// * @param ids 需要删除的实际群码ID
// * @return 结果
// */
// public int deleteWeGroupCodeActualByIds(Long[] ids);
//
// /**
// * 删除实际群码信息
// *
......@@ -58,4 +68,11 @@ public interface IWeGroupCodeActualService extends IService<WeGroupCodeActual>
// * @return 结果
// */
// public int deleteWeGroupCodeActualById(Long id);
/**
* 检测实际码chatId是否唯一
* @param weGroupCodeActual 实际码
* @return 结果
*/
public boolean checkChatIdUnique(WeGroupCodeActual weGroupCodeActual);
}
......@@ -4,34 +4,50 @@ import java.util.List;
import com.baomidou.mybatisplus.extension.service.IService;
import com.linkwechat.wecom.domain.WeGroupCode;
import com.linkwechat.wecom.domain.WeGroupCodeActual;
import org.springframework.web.multipart.MultipartFile;
/**
* 客户群活码Service接口
*
*
* @author ruoyi
* @date 2020-10-07
*/
public interface IWeGroupCodeService extends IService<WeGroupCode>
{
// /**
// * 查询客户群活码
// *
// * @param id 客户群活码ID
// * @return 客户群活码
// */
// public WeGroupCode selectWeGroupCodeById(Long id);
//
// /**
// * 查询客户群活码列表
// *
// * @param weGroupCode 客户群活码
// * @return 客户群活码集合
// */
// public List<WeGroupCode> selectWeGroupCodeList(WeGroupCode weGroupCode);
public interface IWeGroupCodeService extends IService<WeGroupCode> {
/**
* 查询客户群活码
*
* @param id 客户群活码ID
* @return 客户群活码
*/
public WeGroupCode selectWeGroupCodeById(Long id);
/**
* 根据群活码id查询实际码列表
* @param groupCodeId 群活码id
* @return 结果
*/
public List<WeGroupCodeActual> selectActualListByGroupCodeId(Long groupCodeId);
/**
* 查询客户群活码列表
*
* @param weGroupCode 客户群活码
* @return 客户群活码集合
*/
public List<WeGroupCode> selectWeGroupCodeList(WeGroupCode weGroupCode);
/**
* 根据群活码id查询群活码列表
*
* @param ids id列表
* @return 结果
*/
public List<WeGroupCode> selectWeGroupCodeListByIds(List<String> ids);
/**
* 新增客户群活码
*
*
* @param weGroupCode 客户群活码
* @return 结果
*/
......@@ -39,25 +55,32 @@ public interface IWeGroupCodeService extends IService<WeGroupCode>
/**
* 修改客户群活码
*
*
* @param weGroupCode 客户群活码
* @return 结果
*/
public void updateWeGroupCode(WeGroupCode weGroupCode);
// /**
// * 批量删除客户群活码
// *
// * @param ids 需要删除的客户群活码ID
// * @return 结果
// */
// public int deleteWeGroupCodeByIds(Long[] ids);
//
// /**
// * 删除客户群活码信息
// *
// * @param id 客户群活码ID
// * @return 结果
// */
// public int deleteWeGroupCodeById(Long id);
public int updateWeGroupCode(WeGroupCode weGroupCode);
/**
* 批量删除客户群活码
*
* @param ids 需要删除的客户群活码ID
* @return 结果
*/
public int deleteWeGroupCodeByIds(Long[] ids);
/**
* 删除客户群活码信息
*
* @param id 客户群活码ID
* @return 结果
*/
public int deleteWeGroupCodeById(Long id);
/**
* 检测活码名称是否唯一
* @param weGroupCode 活码对象
* @return 结果
*/
public boolean checkActivityNameUnique(WeGroupCode weGroupCode);
}
......@@ -3,11 +3,17 @@ package com.linkwechat.wecom.service.impl;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linkwechat.common.config.RuoYiConfig;
import com.linkwechat.common.config.ServerConfig;
import com.linkwechat.common.exception.wecom.WeComException;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.common.utils.file.FileUploadUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.linkwechat.wecom.mapper.WeGroupCodeActualMapper;
import com.linkwechat.wecom.domain.WeGroupCodeActual;
import com.linkwechat.wecom.service.IWeGroupCodeActualService;
import org.springframework.web.multipart.MultipartFile;
/**
* 实际群码Service业务层处理
......@@ -18,70 +24,83 @@ import com.linkwechat.wecom.service.IWeGroupCodeActualService;
@Service
public class WeGroupCodeActualServiceImpl extends ServiceImpl<WeGroupCodeActualMapper,WeGroupCodeActual> implements IWeGroupCodeActualService
{
// @Autowired
// private WeGroupCodeActualMapper weGroupCodeActualMapper;
@Autowired
private ServerConfig serverConfig;
// /**
// * 查询实际群码
// *
// * @param id 实际群码ID
// * @return 实际群码
// */
// @Override
// public WeGroupCodeActual selectWeGroupCodeActualById(Long id)
// {
// return weGroupCodeActualMapper.selectWeGroupCodeActualById(id);
// }
//
// /**
// * 查询实际群码列表
// *
// * @param weGroupCodeActual 实际群码
// * @return 实际群码
// */
// @Override
// public List<WeGroupCodeActual> selectWeGroupCodeActualList(WeGroupCodeActual weGroupCodeActual)
// {
// return weGroupCodeActualMapper.selectWeGroupCodeActualList(weGroupCodeActual);
// }
@Autowired
private WeGroupCodeActualMapper weGroupCodeActualMapper;
// /**
// * 新增实际群码
// *
// * @param weGroupCodeActual 实际群码
// * @return 结果
// */
// @Override
// public int insertWeGroupCodeActual(WeGroupCodeActual weGroupCodeActual)
// {
// this.sa
// return this.baseMapper.insertWeGroupCodeActual(weGroupCodeActual);
// }
//
// /**
// * 修改实际群码
// *
// * @param weGroupCodeActual 实际群码
// * @return 结果
// */
// @Override
// public int updateWeGroupCodeActual(WeGroupCodeActual weGroupCodeActual)
// {
// return this.baseMapper.updateWeGroupCodeActual(weGroupCodeActual);
// }
/**
* 查询实际群码
*
* @param id 实际群码ID
* @return 实际群码
*/
@Override
public WeGroupCodeActual selectWeGroupCodeActualById(Long id)
{
return weGroupCodeActualMapper.selectWeGroupCodeActualById(id);
}
/**
* 根据群聊id获取对应群二维码
*
* @param chatId 群聊id
* @return 结果
*/
@Override
public WeGroupCodeActual selectActualCodeByChatId(String chatId) {
return weGroupCodeActualMapper.selectWeGroupCodeActualByChatId(chatId);
}
/**
* 查询实际群码列表
*
* @param weGroupCodeActual 实际群码
* @return 实际群码
*/
@Override
public List<WeGroupCodeActual> selectWeGroupCodeActualList(WeGroupCodeActual weGroupCodeActual)
{
return weGroupCodeActualMapper.selectWeGroupCodeActualList(weGroupCodeActual);
}
/**
* 新增实际群码
*
* @param weGroupCodeActual 实际群码
* @return 结果
*/
@Override
public int insertWeGroupCodeActual(WeGroupCodeActual weGroupCodeActual)
{
return weGroupCodeActualMapper.insertWeGroupCodeActual(weGroupCodeActual);
}
/**
* 修改实际群码
*
* @param weGroupCodeActual 实际群码
* @return 结果
*/
@Override
public int updateWeGroupCodeActual(WeGroupCodeActual weGroupCodeActual)
{
return this.baseMapper.updateWeGroupCodeActual(weGroupCodeActual);
}
/**
* 批量删除实际群码
*
* @param ids 需要删除的实际群码ID
* @return 结果
*/
@Override
public int deleteWeGroupCodeActualByIds(Long[] ids)
{
return weGroupCodeActualMapper.deleteWeGroupCodeActualByIds(ids);
}
// /**
// * 批量删除实际群码
// *
// * @param ids 需要删除的实际群码ID
// * @return 结果
// */
// @Override
// public int deleteWeGroupCodeActualByIds(Long[] ids)
// {
// return weGroupCodeActualMapper.deleteWeGroupCodeActualByIds(ids);
// }
//
// /**
// * 删除实际群码信息
// *
......@@ -93,4 +112,22 @@ public class WeGroupCodeActualServiceImpl extends ServiceImpl<WeGroupCodeActualM
// {
// return weGroupCodeActualMapper.deleteWeGroupCodeActualById(id);
// }
/**
* 检测实际码chatId是否唯一
*
* @param weGroupCodeActual 实际码
* @return 结果
*/
@Override
public boolean checkChatIdUnique(WeGroupCodeActual weGroupCodeActual) {
// 不指定群聊时,不用检测唯一性
String chatId = weGroupCodeActual.getChatId();
if (StringUtils.isNull(chatId) | StringUtils.isEmpty(chatId))
{
return true;
}
int rows = weGroupCodeActualMapper.checkChatIdUnique(chatId);
return rows == 0;
}
}
......@@ -4,7 +4,16 @@ import java.util.List;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linkwechat.common.config.RuoYiConfig;
import com.linkwechat.common.config.ServerConfig;
import com.linkwechat.common.exception.wecom.WeComException;
import com.linkwechat.common.utils.DateUtils;
import com.linkwechat.common.utils.QREncode;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.common.utils.file.FileUploadUtils;
import com.linkwechat.common.utils.uuid.IdUtils;
import com.linkwechat.wecom.domain.WeGroupCodeActual;
import com.linkwechat.wecom.mapper.WeGroupCodeActualMapper;
import com.linkwechat.wecom.service.IWeGroupCodeActualService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -24,50 +33,108 @@ public class WeGroupCodeServiceImpl extends ServiceImpl<WeGroupCodeMapper,WeGrou
@Autowired
private IWeGroupCodeActualService iWeGroupCodeActualService;
// @Autowired
// private WeGroupCodeMapper weGroupCodeMapper;
//
// /**
// * 查询客户群活码
// *
// * @param id 客户群活码ID
// * @return 客户群活码
// */
// @Override
// public WeGroupCode selectWeGroupCodeById(Long id)
// {
// return weGroupCodeMapper.selectWeGroupCodeById(id);
// }
//
// /**
// * 查询客户群活码列表
// *
// * @param weGroupCode 客户群活码
// * @return 客户群活码
// */
// @Override
// public List<WeGroupCode> selectWeGroupCodeList(WeGroupCode weGroupCode)
// {
// return weGroupCodeMapper.selectWeGroupCodeList(weGroupCode);
// }
@Autowired
private WeGroupCodeMapper weGroupCodeMapper;
@Autowired
private WeGroupCodeActualMapper weGroupCodeActualMapper;
@Autowired
private ServerConfig serverConfig;
private static final String IMAGE_FORMAT = "png";
/**
* 查询客户群活码
*
* @param id 客户群活码ID
* @return 客户群活码
*/
@Override
public WeGroupCode selectWeGroupCodeById(Long id)
{
// 获取群活码
return weGroupCodeMapper.selectWeGroupCodeById(id);
}
/**
* 根据群活码id查询实际码列表
*
* @param groupCodeId 群活码id
* @return 结果
*/
@Override
public List<WeGroupCodeActual> selectActualListByGroupCodeId(Long groupCodeId) {
return weGroupCodeActualMapper.selectActualListByGroupCodeId(groupCodeId);
}
/**
* 查询客户群活码列表
*
* @param weGroupCode 客户群活码
* @return 客户群活码
*/
@Override
public List<WeGroupCode> selectWeGroupCodeList(WeGroupCode weGroupCode)
{
List<WeGroupCode> weGroupCodeList = weGroupCodeMapper.selectWeGroupCodeList(weGroupCode);
for (WeGroupCode item: weGroupCodeList) {
List<WeGroupCodeActual> actualList = weGroupCodeActualMapper.selectActualListByGroupCodeId(item.getId());
item.setActualList(actualList);
}
return weGroupCodeList;
}
/**
* 根据群活码id查询群活码列表
*
* @param ids id列表
* @return 结果
*/
@Override
public List<WeGroupCode> selectWeGroupCodeListByIds(List<String> ids) {
return weGroupCodeMapper.selectWeGroupCodeListByIds(ids);
}
/**
* 新增客户群活码
*
* @param weGroupCode 客户群活码
* @return 结果
*/
@Override
public void insertWeGroupCode(WeGroupCode weGroupCode)
{
try {
if(this.save(weGroupCode)){
List<WeGroupCodeActual> actualList = weGroupCode.getActualList();
if(CollectionUtil.isNotEmpty(actualList)){
iWeGroupCodeActualService.saveBatch(actualList);
String uploadDir = RuoYiConfig.getUploadPath();
String fileName = DateUtils.datePath() + "/" + IdUtils.fastUUID() + "." + IMAGE_FORMAT;
String filePathName = FileUploadUtils.getPathFileName(uploadDir, fileName);
// 生成并保存二维码图片
String logoUrl = weGroupCode.getActivityHeadUrl();
if (StringUtils.isEmpty(logoUrl)) {
QREncode.saveQRCode(weGroupCode.getActivityName(), uploadDir + "/" + fileName);
} else {
QREncode.saveQRCode(weGroupCode.getActivityName(), logoUrl, uploadDir + "/" + fileName);
}
String codeUrl = serverConfig.getUrl() + filePathName;
weGroupCode.setCodeUrl(codeUrl);
if(this.save(weGroupCode)){
List<WeGroupCodeActual> actualList = weGroupCode.getActualList();
if(CollectionUtil.isNotEmpty(actualList)){
iWeGroupCodeActualService.saveBatch(actualList);
}
}
} catch (Exception e) {
throw new WeComException(e.getMessage());
}
}
/**
......@@ -77,37 +144,53 @@ public class WeGroupCodeServiceImpl extends ServiceImpl<WeGroupCodeMapper,WeGrou
* @return 结果
*/
@Override
public void updateWeGroupCode(WeGroupCode weGroupCode)
public int updateWeGroupCode(WeGroupCode weGroupCode)
{
if(this.updateById(weGroupCode)){
List<WeGroupCodeActual> actualList = weGroupCode.getActualList();
if(CollectionUtil.isNotEmpty(actualList)){
iWeGroupCodeActualService.updateBatchById(actualList);
}
}
int rows = weGroupCodeMapper.updateWeGroupCode(weGroupCode);
// 同时更新对应的实际码
if (rows > 0) {
List<WeGroupCodeActual> actualList = weGroupCode.getActualList();
if(CollectionUtil.isNotEmpty(actualList)){
iWeGroupCodeActualService.updateBatchById(actualList);
}
}
return rows;
}
/**
* 批量删除客户群活码
*
* @param ids 需要删除的客户群活码ID
* @return 结果
*/
@Override
public int deleteWeGroupCodeByIds(Long[] ids)
{
weGroupCodeActualMapper.deleteActualListByGroupCodeIds(ids);
return weGroupCodeMapper.deleteWeGroupCodeByIds(ids);
}
/**
* 删除客户群活码信息
*
* @param id 客户群活码ID
* @return 结果
*/
@Override
public int deleteWeGroupCodeById(Long id)
{
return weGroupCodeMapper.deleteWeGroupCodeById(id);
}
/**
* 检测活码名称是否唯一
*
* @param weGroupCode 活码对象
* @return 结果
*/
@Override
public boolean checkActivityNameUnique(WeGroupCode weGroupCode) {
int rows = weGroupCodeMapper.checkActivityNameUnique(weGroupCode.getActivityName());
return rows == 0;
}
//
// /**
// * 批量删除客户群活码
// *
// * @param ids 需要删除的客户群活码ID
// * @return 结果
// */
// @Override
// public int deleteWeGroupCodeByIds(Long[] ids)
// {
// return weGroupCodeMapper.deleteWeGroupCodeByIds(ids);
// }
//
// /**
// * 删除客户群活码信息
// *
// * @param id 客户群活码ID
// * @return 结果
// */
// @Override
// public int deleteWeGroupCodeById(Long id)
// {
// return weGroupCodeMapper.deleteWeGroupCodeById(id);
// }
}
......@@ -102,7 +102,7 @@
<select id="selectWeEmpleCodeByIds" parameterType="java.util.ArrayList" resultMap="WeEmpleCodeResult">
<include refid="selectWeEmpleCodeLsit"/>
<if test="ids != null and ids.size > 0">
wecode.id in
and wecode.id in
<foreach collection="ids" item="id" open="(" close=")" separator=",">
#{id}
</foreach>
......
......@@ -11,13 +11,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="effectTime" column="effect_time" />
<result property="scanCodeTimesLimit" column="scan_code_times_limit" />
<result property="groupCodeId" column="group_code_id" />
<result property="chatId" column="chat_id" />
<result property="chatGroupName" column="chat_group_name" />
<result property="scanCodeTimes" column="scan_code_times" />
<result property="delFlag" column="del_flag" />
<result property="status" column="status" />
</resultMap>
<sql id="selectWeGroupCodeActualVo">
select id, actual_group_qr_code, group_name, effect_time, scan_code_times_limit, group_code_id, scan_code_times, del_flag, status from we_group_code_actual
select id, actual_group_qr_code, group_name, effect_time, scan_code_times_limit, group_code_id, chat_id, chat_group_name, scan_code_times, del_flag, status from we_group_code_actual
</sql>
<select id="selectWeGroupCodeActualList" parameterType="WeGroupCodeActual" resultMap="WeGroupCodeActualResult">
......@@ -30,13 +32,34 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="groupCodeId != null "> and group_code_id = #{groupCodeId}</if>
<if test="scanCodeTimes != null "> and scan_code_times = #{scanCodeTimes}</if>
<if test="status != null "> and status = #{status}</if>
<if test="chatId != null"> and chat_id = #{chatId}</if>
<if test="chatGroupName != null and chatGroupName !=''"> and chat_group_name = #{chatGroupName}</if>
</where>
</select>
<select id="selectActualListByGroupCodeId" parameterType="WeGroupCodeActual" resultMap="WeGroupCodeActualResult">
<include refid="selectWeGroupCodeActualVo"/>
<where>
group_code_id = #{groupCodeId}
</where>
</select>
<select id="selectWeGroupCodeActualByChatId" parameterType="String" resultMap="WeGroupCodeActualResult">
<include refid="selectWeGroupCodeActualVo"/>
<where>
chat_id = #{chatId}
</where>
</select>
<select id="selectWeGroupCodeActualById" parameterType="Long" resultMap="WeGroupCodeActualResult">
<include refid="selectWeGroupCodeActualVo"/>
where id = #{id}
</select>
<select id="checkChatIdUnique" parameterType="String" resultType="int">
select count(1) from we_group_code_actual where chat_id = #{chatId} limit 1
</select>
<insert id="insertWeGroupCodeActual" parameterType="WeGroupCodeActual">
insert into we_group_code_actual
......@@ -47,6 +70,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="effectTime != null">effect_time,</if>
<if test="scanCodeTimesLimit != null">scan_code_times_limit,</if>
<if test="groupCodeId != null">group_code_id,</if>
<if test="chatId != null">chat_id,</if>
<if test="chatGroupName != null">chat_group_name,</if>
<if test="scanCodeTimes != null">scan_code_times,</if>
<if test="delFlag != null">del_flag,</if>
<if test="status != null">status,</if>
......@@ -58,6 +83,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="effectTime != null">#{effectTime},</if>
<if test="scanCodeTimesLimit != null">#{scanCodeTimesLimit},</if>
<if test="groupCodeId != null">#{groupCodeId},</if>
<if test="chatId != null">#{chatId},</if>
<if test="chatGroupName != null">#{chatGroupName},</if>
<if test="scanCodeTimes != null">#{scanCodeTimes},</if>
<if test="delFlag != null">#{delFlag},</if>
<if test="status != null">#{status},</if>
......@@ -72,6 +99,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="effectTime != null">effect_time = #{effectTime},</if>
<if test="scanCodeTimesLimit != null">scan_code_times_limit = #{scanCodeTimesLimit},</if>
<if test="groupCodeId != null">group_code_id = #{groupCodeId},</if>
<if test="chatId != null">chat_id = #{chatId},</if>
<if test="chatGroupName != null">chat_group_name = #{chatGroupName},</if>
<if test="scanCodeTimes != null">scan_code_times = #{scanCodeTimes},</if>
<if test="delFlag != null">del_flag = #{delFlag},</if>
<if test="status != null">status = #{status},</if>
......@@ -89,5 +118,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{id}
</foreach>
</delete>
<delete id="deleteActualListByGroupCodeIds" parameterType="String">
delete from we_group_code_actual where group_code_id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.linkwechat.wecom.mapper.WeGroupCodeMapper">
<resultMap type="WeGroupCode" id="WeGroupCodeResult">
<result property="id" column="id" />
<result property="activityHeadUrl" column="activity_head_url" />
<result property="activityName" column="activity_name" />
<result property="activityScene" column="activity_scene" />
<result property="guide" column="guide" />
<result property="joinGroupIsTip" column="join_group_is_tip" />
<result property="tipMsg" column="tip_msg" />
<result property="customerServerQrCode" column="customer_server_qr_code" />
<result property="delFlag" column="del_flag" />
<result property="id" column="id"/>
<result property="codeUrl" column="code_url"/>
<result property="activityHeadUrl" column="activity_head_url"/>
<result property="activityName" column="activity_name"/>
<result property="activityDesc" column="activity_desc"/>
<result property="activityScene" column="activity_scene"/>
<result property="guide" column="guide"/>
<result property="joinGroupIsTip" column="join_group_is_tip"/>
<result property="tipMsg" column="tip_msg"/>
<result property="customerServerQrCode" column="customer_server_qr_code"/>
<result property="delFlag" column="del_flag"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/>
<result property="updateTime" column="create_time"/>
<result property="remark" column="remark"/>
<result property="availableCodes" column="available_codes"/>
<result property="totalScanTimes" column="total_scan_times"/>
<result property="aboutToExpireCodes" column="about_to_expire_codes"/>
</resultMap>
<sql id="selectWeGroupCodeVo">
select id, activity_head_url, activity_name, activity_scene, guide, join_group_is_tip, tip_msg, customer_server_qr_code, del_flag from we_group_code
SELECT
w.id,
w.code_url,
w.activity_head_url,
w.activity_name,
w.activity_desc,
w.activity_scene,
w.guide,
w.join_group_is_tip,
w.tip_msg,
w.customer_server_qr_code,
w.del_flag,
w.create_by,
w.create_time,
w.update_by,
w.update_time,
w.remark,
IFNULL((SELECT count(1) FROM we_group_code_actual WHERE (SELECT IFNULL(scan_code_times, 0)) &lt; scan_code_times_limit AND group_code_id = w.id ), 0) AS available_codes,
IFNULL((SELECT SUM( scan_code_times ) AS scan_times FROM we_group_code_actual GROUP BY group_code_id HAVING group_code_id = w.id), 0) AS total_scan_times,
IFNULL((SELECT count(1) FROM we_group_code_actual WHERE group_code_id = w.id AND TIMESTAMPDIFF(DAY, sysdate(), effect_time ) &lt; 3), 0) AS about_to_expire_codes
FROM
we_group_code w
</sql>
<select id="selectWeGroupCodeList" parameterType="WeGroupCode" resultMap="WeGroupCodeResult">
<include refid="selectWeGroupCodeVo"/>
<where>
<if test="activityHeadUrl != null and activityHeadUrl != ''"> and activity_head_url = #{activityHeadUrl}</if>
<if test="activityName != null and activityName != ''"> and activity_name like concat('%', #{activityName}, '%')</if>
<if test="activityScene != null and activityScene != ''"> and activity_scene = #{activityScene}</if>
<if test="guide != null and guide != ''"> and guide = #{guide}</if>
<if test="joinGroupIsTip != null "> and join_group_is_tip = #{joinGroupIsTip}</if>
<if test="tipMsg != null and tipMsg != ''"> and tip_msg = #{tipMsg}</if>
<if test="customerServerQrCode != null and customerServerQrCode != ''"> and customer_server_qr_code = #{customerServerQrCode}</if>
<where>
<if test="activityName != null and activityName != ''">and w.activity_name like concat('%', #{activityName},
'%')
</if>
<if test="activityDesc != null and activityDesc != ''">and w.activity_desc like concat('%', #{activityDesc},
'%')
</if>
<if test="activityScene != null and activityScene != ''">and w.activity_scene = #{activityScene}</if>
<if test="guide != null and guide != ''">and w.guide = #{guide}</if>
<if test="joinGroupIsTip != null ">and w.join_group_is_tip = #{joinGroupIsTip}</if>
<if test="tipMsg != null and tipMsg != ''">and w.tip_msg = #{tipMsg}</if>
<if test="createBy != null and createBy != ''">and w.create_by = #{createBy}</if>
<if test="customerServerQrCode != null and customerServerQrCode != ''">and w.customer_server_qr_code =
#{customerServerQrCode}
</if>
<if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
and date_format(w.create_time,'%y%m%d') &gt;= date_format(#{beginTime},'%y%m%d')
</if>
<if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
and date_format(w.create_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')
</if>
</where>
</select>
<select id="selectWeGroupCodeListByIds" resultMap="WeGroupCodeResult">
<include refid="selectWeGroupCodeVo"/>
where w.id in
<foreach item="id" collection="list" open="(" separator="," close=")">
#{id}
</foreach>
</select>
<select id="selectWeGroupCodeById" parameterType="Long" resultMap="WeGroupCodeResult">
<include refid="selectWeGroupCodeVo"/>
where id = #{id}
where w.id = #{id}
</select>
<select id="checkActivityNameUnique" parameterType="String" resultType="int">
select count(1) from we_group_code where activity_name = #{activityName} limit 1
</select>
<insert id="insertWeGroupCode" parameterType="WeGroupCode">
insert into we_group_code
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
<if test="codeUrl != null">code_url,</if>
<if test="activityHeadUrl != null">activity_head_url,</if>
<if test="activityName != null">activity_name,</if>
<if test="activityDesc != null">activity_desc,</if>
<if test="activityScene != null">activity_scene,</if>
<if test="guide != null">guide,</if>
<if test="joinGroupIsTip != null">join_group_is_tip,</if>
<if test="tipMsg != null">tip_msg,</if>
<if test="customerServerQrCode != null">customer_server_qr_code,</if>
<if test="delFlag != null">del_flag,</if>
</trim>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if>
<if test="codeUrl != null">#{codeUrl},</if>
<if test="activityHeadUrl != null">#{activityHeadUrl},</if>
<if test="activityName != null">#{activityName},</if>
<if test="activityDesc != null">#{activityDesc},</if>
<if test="activityScene != null">#{activityScene},</if>
<if test="guide != null">#{guide},</if>
<if test="joinGroupIsTip != null">#{joinGroupIsTip},</if>
<if test="tipMsg != null">#{tipMsg},</if>
<if test="customerServerQrCode != null">#{customerServerQrCode},</if>
<if test="delFlag != null">#{delFlag},</if>
</trim>
</trim>
</insert>
<update id="updateWeGroupCode" parameterType="WeGroupCode">
update we_group_code
<trim prefix="SET" suffixOverrides=",">
<if test="activityHeadUrl != null">activity_head_url = #{activityHeadUrl},</if>
<if test="activityName != null">activity_name = #{activityName},</if>
<if test="activityHeadUrl != null">activity_head_url = #{activityHeadUrl},</if>
<if test="activityDesc != null">activity_desc = #{activityDesc},</if>
<if test="activityScene != null">activity_scene = #{activityScene},</if>
<if test="guide != null">guide = #{guide},</if>
<if test="joinGroupIsTip != null">join_group_is_tip = #{joinGroupIsTip},</if>
......@@ -84,10 +146,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</delete>
<delete id="deleteWeGroupCodeByIds" parameterType="String">
delete from we_group_code where id in
delete from we_group_code where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>
\ No newline at end of file
......@@ -6010,19 +6010,25 @@ CREATE TABLE `we_group` (
-- ----------------------------
-- Table structure for we_group_code
-- ----------------------------
DROP TABLE IF EXISTS `we_group_code`;
CREATE TABLE `we_group_code` (
`id` bigint(20) NOT NULL,
`activity_head_url` varchar(60) DEFAULT NULL COMMENT '活动头像',
`activity_name` varchar(60) DEFAULT NULL COMMENT '活动名称',
`code_url` varchar(255) NOT NULL COMMENT '二维码链接',
`activity_head_url` varchar(255) DEFAULT NULL COMMENT '活码头像链接',
`activity_name` varchar(60) DEFAULT NULL COMMENT '活码名称',
`activity_desc` varchar(60) DEFAULT NULL COMMENT '活码描述',
`activity_scene` varchar(60) DEFAULT NULL COMMENT '场景',
`guide` varchar(60) DEFAULT NULL COMMENT '引导语',
`join_group_is_tip` tinyint(4) DEFAULT NULL COMMENT '进群是否提示:1:是;0:否;',
`tip_msg` varchar(100) DEFAULT NULL COMMENT '进群提示语',
`customer_server_qr_code` varchar(100) DEFAULT NULL COMMENT '客服二维码',
`del_flag` tinyint(4) DEFAULT NULL COMMENT '0:正常;2:删除;',
`create_by` varchar(64) DEFAULT '' COMMENT '创建者',
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
`update_by` varchar(64) DEFAULT '' COMMENT '更新者',
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='客户群活码';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='客户群活码'
-- ----------------------------
-- Records of we_group_code
......@@ -6039,7 +6045,9 @@ CREATE TABLE `we_group_code_actual` (
`effect_time` datetime DEFAULT NULL COMMENT '有效期',
`scan_code_times_limit` int(11) DEFAULT NULL COMMENT '扫码次数限制',
`group_code_id` bigint(20) DEFAULT NULL COMMENT '群活码id',
`scan_code_times` int(11) DEFAULT NULL COMMENT '扫码次数',
`chat_id` bigint(20) DEFAULT NULL COMMENT '群聊id',
`chat_group_name` bigint(20) DEFAULT NULL COMMENT '群聊名称',
`scan_code_times` int(11) DEFAULT 0 COMMENT '扫码次数',
`del_flag` tinyint(4) DEFAULT NULL COMMENT '0:正常使用;2:删除;',
`status` tinyint(4) DEFAULT '0' COMMENT '0:使用中',
PRIMARY KEY (`id`)
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!