|
@@ -12,6 +12,7 @@ import com.management.platform.service.CompanyService;
|
|
|
import com.management.platform.service.UserQrCodeService;
|
|
|
import com.management.platform.service.UserService;
|
|
|
import com.management.platform.service.WechatAccountService;
|
|
|
+import com.management.platform.service.impl.QRCodeService;
|
|
|
import com.management.platform.service.impl.WechatApiService;
|
|
|
import com.management.platform.util.FileZipUtil;
|
|
|
import com.management.platform.util.HttpRespMsg;
|
|
@@ -37,10 +38,7 @@ import java.io.File;
|
|
|
import java.io.FileOutputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.net.InetAddress;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -79,6 +77,9 @@ public class WechatAccountController {
|
|
|
@Value(value ="${upload.path}")
|
|
|
private String uploadPath;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private QRCodeService qrCodeService;
|
|
|
+
|
|
|
private final static String prefixUrl="https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=";
|
|
|
|
|
|
|
|
@@ -230,8 +231,8 @@ public class WechatAccountController {
|
|
|
}
|
|
|
|
|
|
//一键生成所有员工的二维码
|
|
|
- @RequestMapping(value = "oneClickGeneration")
|
|
|
- public HttpRespMsg oneClickGeneration(HttpServletRequest request) {
|
|
|
+ @RequestMapping(value = "oneClickGenerationOld")
|
|
|
+ public HttpRespMsg oneClickGenerationOld(HttpServletRequest request) {
|
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
|
String token = request.getHeader("Token");
|
|
|
User user = userService.getById(token);
|
|
@@ -294,6 +295,83 @@ public class WechatAccountController {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ //一键生成所有员工的二维码
|
|
|
+ @RequestMapping(value = "oneClickGeneration")
|
|
|
+ public HttpRespMsg oneClickGeneration(HttpServletRequest request) {
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ String token = request.getHeader("Token");
|
|
|
+ User user = userService.getById(token);
|
|
|
+
|
|
|
+ // 检查公众号配置
|
|
|
+ WechatAccount wechatAccount = wechatAccountService.getOne(
|
|
|
+ new QueryWrapper<WechatAccount>().eq("company_id", user.getCompanyId()));
|
|
|
+ if (wechatAccount == null) {
|
|
|
+ msg.setError("该公司没有配置公众号相关的参数");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取微信access_token
|
|
|
+ String accessToken = wechatAccountService.getAccessToken(user.getCompanyId(), wechatAccount.getAppId());
|
|
|
+
|
|
|
+ // 查询已生成二维码的员工
|
|
|
+ List<UserQrCode> qrCodeList = userQrCodeService.list(
|
|
|
+ new QueryWrapper<UserQrCode>().eq("company_id", user.getCompanyId()));
|
|
|
+ List<String> userAlreadyIds = qrCodeList.stream()
|
|
|
+ .map(UserQrCode::getUserId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ userAlreadyIds.add("-1"); // 避免空列表导致SQL异常
|
|
|
+
|
|
|
+ // 查询未生成二维码的员工
|
|
|
+ List<User> userList = userService.list(
|
|
|
+ new QueryWrapper<User>()
|
|
|
+ .notIn("id", userAlreadyIds)
|
|
|
+ .eq("company_id", user.getCompanyId()));
|
|
|
+
|
|
|
+ if (!userList.isEmpty()) {
|
|
|
+ List<CompletableFuture<String>> futures = new ArrayList<>();
|
|
|
+ List<String> failedUsers = new ArrayList<>();
|
|
|
+
|
|
|
+ for (User u : userList) {
|
|
|
+ try {
|
|
|
+ // 异步生成二维码并保存
|
|
|
+ CompletableFuture<String> future = qrCodeService.generateAndSaveQRCode(
|
|
|
+ accessToken, u.getId(), u.getName());
|
|
|
+
|
|
|
+ future.thenAccept(filePath -> {
|
|
|
+ // 成功生成后,保存记录到数据库
|
|
|
+ UserQrCode qrCode = new UserQrCode();
|
|
|
+ qrCode.setCompanyId(user.getCompanyId());
|
|
|
+ qrCode.setUserId(u.getId());
|
|
|
+ qrCode.setImg(filePath); // 存储文件路径
|
|
|
+ userQrCodeService.save(qrCode);
|
|
|
+ }).exceptionally(e -> {
|
|
|
+ // 记录失败用户
|
|
|
+ failedUsers.add(u.getName());
|
|
|
+ return null;
|
|
|
+ });
|
|
|
+
|
|
|
+ futures.add(future);
|
|
|
+ } catch (Exception e) {
|
|
|
+ failedUsers.add(u.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 等待所有任务完成(可选)
|
|
|
+ CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
|
|
|
+
|
|
|
+ if (!failedUsers.isEmpty()) {
|
|
|
+ msg.setError("部分员工二维码生成失败: " + String.join(", ", failedUsers));
|
|
|
+ } else {
|
|
|
+ msg.setData("所有员工二维码生成成功!");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ msg.setData("没有需要生成二维码的员工。");
|
|
|
+ }
|
|
|
+
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
@Async("taskExecutor")
|