提交 eb3f2259 编写于 作者: 1 1539136324@qq.com

群活码二维码生成逻辑优化移动至后端

上级 ae70522d
......@@ -6,21 +6,25 @@ import com.linkwechat.common.constant.HttpStatus;
import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.domain.model.LoginUser;
import com.linkwechat.common.core.page.TableDataInfo;
import com.linkwechat.common.enums.BusinessType;
import com.linkwechat.common.utils.QREncode;
import com.linkwechat.common.utils.SecurityUtils;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.common.utils.file.FileUtils;
import com.linkwechat.framework.web.domain.server.SysFile;
import com.linkwechat.framework.web.service.FileService;
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.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
......@@ -43,7 +47,12 @@ import java.util.zip.ZipOutputStream;
@RequestMapping("/wecom/groupCode")
public class WeGroupCodeController extends BaseController {
@Autowired
private IWeGroupCodeService groupCodeService;
IWeGroupCodeService groupCodeService;
@Autowired
FileService fileService;
/**
* 查询客户群活码列表
......@@ -127,13 +136,20 @@ public class WeGroupCodeController extends BaseController {
// @PreAuthorize("@ss.hasPermi('drainageCode:group:add')")
@Log(title = "客户群活码", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@Validated @RequestBody WeGroupCode weGroupCode) {
public AjaxResult add(@Validated @RequestBody WeGroupCode weGroupCode) throws IOException {
// 唯一性检查
if (!groupCodeService.checkActivityNameUnique(weGroupCode)) {
return AjaxResult.error("添加群活码失败,活码名称 " + weGroupCode.getActivityName() + " 已存在");
}
AjaxResult ajax = AjaxResult.success();
weGroupCode.setCreateBy(SecurityUtils.getUsername());
// weGroupCode.setCodeUrl(
// fileService.upload(QREncode.getQRCodeMultipartFile(
// SecurityUtils.getLoginUser().getUser().getWeCorpAccount().getH5DoMainName()+"/mobile/#/groupCode?id="+weGroupCode.getId()
// ,weGroupCode.getActivityHeadUrl())).getImgUrlPrefix()
// );
groupCodeService.insertWeGroupCode(weGroupCode);
ajax.put("id", weGroupCode.getId());
return ajax;
......
......@@ -264,6 +264,10 @@
<groupId>com.github.jsqlparser</groupId>
<artifactId>jsqlparser</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</dependency>
</dependencies>
......
package com.linkwechat.common.constant;
import io.swagger.models.auth.In;
/**
* 通用常量信息
*
......@@ -166,6 +168,10 @@ public class Constants
public static final String HANDLE_SUCCESS="3";
/**总公司节点类型的CORP*/
public static final Integer CORP_TYPE_ADMIN=1;
......
......@@ -114,9 +114,16 @@ public class WeCorpAccount extends BaseEntity
private String fissionGroupUrl;
@ApiModelProperty("H5域名")
private String h5DoMainName;
@ApiModelProperty("会话私钥")
private String financePrivateKey;
@ApiModelProperty("账号类型(1:超管体系公司账号;2:普通下级公司体系账号)")
private Integer corpType;
}
......@@ -19,6 +19,8 @@ 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;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.web.multipart.MultipartFile;
public class QREncode {
......@@ -169,7 +171,7 @@ public class QREncode {
* @param output 输出流
* @throws Exception
*/
public void getQRCode(String content, String logoUrl, OutputStream output) throws Exception {
public static 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);
......@@ -186,9 +188,22 @@ public class QREncode {
}
}
public static MultipartFile getQRCodeMultipartFile(String content,String logoUrl) throws IOException {
BufferedImage bufferedImage = crateQRCode(content, logoUrl);
//读取图片转换为 BufferedImage
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write( bufferedImage, "jpg", baos );
//转换为MultipartFile
return new MockMultipartFile("groupQrCode","groupQrCode.jpg","text/plain", baos.toByteArray());
}
@SuppressWarnings({"unchecked", "rawtypes"})
public static void main(String[] args) throws Exception {
String text = "http://open.weixin.qq.com/qr/code/?username=LinkWeChat2021";
String text = "http://linkwechat.cn/mobile/#/groupCode?id=f251619cd5d548b9ba67ab74f40f2b74";
int width = 300;
int height = 300;
String format = "png";
......@@ -196,6 +211,9 @@ public class QREncode {
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);
// QREncode.writeToFile(bitMatrix, format, outputFile);
getQRCode(text,"",new FileOutputStream(outputFile));
}
}
......@@ -140,6 +140,12 @@ public class UserDetailsServiceImpl implements UserDetailsService
iWeCorpAccountService.getOne(new LambdaQueryWrapper<WeCorpAccount>().eq(WeCorpAccount::getCorpAccount, username)
.eq(WeCorpAccount::getDelFlag, Constants.NORMAL_CODE))
);
}else{//超管体系下的账号
user.setWeCorpAccount(
iWeCorpAccountService.getOne(new LambdaQueryWrapper<WeCorpAccount>().eq(WeCorpAccount::getCorpType, Constants.CORP_TYPE_ADMIN))
);
}
......
......@@ -63,7 +63,8 @@ public class WeCorpAccountServiceImpl extends ServiceImpl<WeCorpAccountMapper,We
return ruoYiConfig.isStartTenant()? WeCorpAccount.builder().build():this.getOne(new LambdaQueryWrapper<WeCorpAccount>()
.eq(WeCorpAccount::getDelFlag,Constants.NORMAL_CODE)
.eq(WeCorpAccount::getStatus,Constants.NORMAL_CODE));
.eq(WeCorpAccount::getStatus,Constants.NORMAL_CODE)
.eq(WeCorpAccount::getCorpType,Constants.CORP_TYPE_ADMIN));
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册