下载成员二维码相关

master
LegnaYet 6 years ago
parent b409997599
commit e81995720d

@ -1,7 +1,5 @@
package com.kiisoo.ic.employee.service;
import java.io.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kiisoo.ic.department.entity.PrivilageCpUserDepartmentDO;
import com.kiisoo.ic.department.mapper.PrivilageCpUserDepartmentDOMapper;
@ -16,19 +14,24 @@ import com.kiisoo.ic.wx.service.QWMailListManageService;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.bean.WxCpUser;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.imageio.ImageIO;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
@ -157,6 +160,9 @@ public class EmployeeService {
PrivilageCpUserDO privilageCpUserDO = new PrivilageCpUserDO();
BeanUtils.copyProperties(wxCpUser, privilageCpUserDO);
privilageCpUserDO.setCpUserId(wxCpUser.getUserId());
String alias = privilageCpUserDO.getAlias();
alias = filterEmoji(alias);
privilageCpUserDO.setAlias(alias);
if (CollectionUtils.isEmpty(cuUserIdUser)) {
//添加用户
@ -183,6 +189,19 @@ public class EmployeeService {
}
}
public static String filterEmoji(String source) {
if (source != null) {
Pattern emoji = Pattern.compile("[\ud83c\udc00-\ud83c\udfff]|[\ud83d\udc00-\ud83d\udfff]|[\u2600-\u27ff]", Pattern.UNICODE_CASE | Pattern.CASE_INSENSITIVE);
Matcher emojiMatcher = emoji.matcher(source);
if (emojiMatcher.find()) {
source = emojiMatcher.replaceAll("*");
return source;
}
return source;
}
return source;
}
/**
*
*
@ -256,6 +275,7 @@ public class EmployeeService {
/**
*
*
* @param response
* @throws WxErrorException
* @throws IOException
@ -263,41 +283,101 @@ public class EmployeeService {
public void downLoadQrCode(HttpServletResponse response) throws WxErrorException, IOException {
List<WxCpUser> wxCpUsers = qwMailListManageService.syncUser();
Map<String, String> stores = new HashMap<>();
InputStreamReader br = new InputStreamReader(new FileInputStream(new File("G:\\kiisoo-ic\\src\\main\\resources\\store.txt")), "utf-8");
BufferedReader reader = new BufferedReader(br);
String str = null;
//-----------------------------打印重复店铺---------------------start----------------------
while ((str = reader.readLine()) != null) {
String[] split = str.split(",");
if (StringUtils.isNotBlank(split[1].trim()) && StringUtils.isNotBlank(split[0].trim())){
if (stores.get(split[1].trim()) != null){
System.out.println(split[1].trim()+ "-"+ split[0].trim());
System.out.println(split[1].trim()+ "-" + stores.get(split[1].trim()));
}else{
stores.put(split[1].trim(), split[0].trim());
}
}
}
//-----------------------------打印重复店铺--------------------end-----------------------
byte[] buffer = new byte[1024];
// 生成的ZIP文件名为Demo.zip
String strZipName = "bsd_qr_code.zip";
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(strZipName));
List<String> fileNames = new ArrayList<>();
int count = wxCpUsers.size();
//----------------------------打印绑定的店铺---------------------start-------------------
for (int i = 0; i < count; i++) {
System.out.println("总进度:" + count + " | 当前进度:" + i);
WxCpUser wxCpUser = wxCpUsers.get(i);
String url = wxCpUser.getQrCode();
String code = wxCpUser.getName();
String code = wxCpUser.getAlias().trim();
if (StringUtils.isBlank(code)) {
continue;
}
String storeCode = stores.get(code);
InputStream inStream = getInputStream(url);
out.putNextEntry(new ZipEntry(code + ".png"));
if (StringUtils.isBlank(storeCode)) {
continue;
}
stores.remove(code);
//下载图片
BufferedInputStream in = new BufferedInputStream(getInputStream(url));
//字节流转图片对象
Image bi = ImageIO.read(in);
//构建图片流
BufferedImage tag = new BufferedImage(300, 300, BufferedImage.TYPE_INT_RGB);
//绘制改变尺寸后的图
tag.getGraphics().drawImage(bi, 0, 0, 300, 300, null);
//输出流
BufferedOutputStream Imgout = new BufferedOutputStream(new FileOutputStream(storeCode + ".png"));
ImageIO.write(tag, "PNG", Imgout);
FileInputStream newImgIn = new FileInputStream(new File(storeCode + ".png"));
String fileName = storeCode + ".png";
if (fileNames.contains(fileName)){
fileName = storeCode + "-" + code + ".png";
}
fileNames.add(fileName);
out.putNextEntry(new ZipEntry(fileName));
int len;
// 读入需要下载的文件的内容打包到zip文件
while ((len = inStream.read(buffer)) > 0) {
while ((len = newImgIn.read(buffer)) > 0) {
out.write(buffer, 0, len);
}
out.closeEntry();
inStream.close();
in.close();
Imgout.close();
newImgIn.close();
}
//----------------------------打印绑定的店铺---------------------end-------------------
out.flush();
out.close();
System.out.println("生成压缩包成功");
//----------------------------打印未绑定的店铺---------------------start-------------------
Set<Map.Entry<String, String>> entries = stores.entrySet();
for (Map.Entry<String, String> entry: entries){
System.out.println(entry.getValue() + "-" + entry.getKey());
}
//----------------------------打印未绑定的店铺---------------------end-------------------
//输入到response
ServletOutputStream outputStream = response.getOutputStream();
byte[] bufferNew = new byte[1024];
FileInputStream inStream = new FileInputStream(new File(strZipName));
int lenNew;
// 读入需要下载的文件的内容打包到zip文件
while ((lenNew = inStream.read(bufferNew)) > 0) {
outputStream.write(bufferNew, 0, lenNew);
}
@ -306,6 +386,7 @@ public class EmployeeService {
/**
* url
*
* @param fileUrl url
* @return
*/

@ -9,12 +9,9 @@ import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.api.WxCpUserService;
import me.chanjar.weixin.cp.bean.WxCpDepart;
import me.chanjar.weixin.cp.bean.WxCpUser;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import static com.kiisoo.ic.department.constant.Constants.MAIN_DEPARTMENT_ID;
@ -28,7 +25,7 @@ import static com.kiisoo.ic.department.constant.Constants.MAIN_DEPARTMENT_ID;
@Service
public class QWMailListManageService {
private final Integer applicationid = 1000042;
private final Integer applicationid = 1;
private WxCpService wxCpService;

Loading…
Cancel
Save