|
@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.management.platform.entity.User;
|
|
import com.management.platform.entity.User;
|
|
import com.management.platform.entity.UserQrCode;
|
|
import com.management.platform.entity.UserQrCode;
|
|
import com.management.platform.entity.WechatAccount;
|
|
import com.management.platform.entity.WechatAccount;
|
|
|
|
+import com.management.platform.service.CompanyService;
|
|
import com.management.platform.service.UserQrCodeService;
|
|
import com.management.platform.service.UserQrCodeService;
|
|
import com.management.platform.service.UserService;
|
|
import com.management.platform.service.UserService;
|
|
import com.management.platform.service.WechatAccountService;
|
|
import com.management.platform.service.WechatAccountService;
|
|
@@ -64,6 +65,9 @@ public class WechatAccountController {
|
|
@Resource
|
|
@Resource
|
|
private UserQrCodeService userQrCodeService;
|
|
private UserQrCodeService userQrCodeService;
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ private CompanyService companyService;
|
|
|
|
+
|
|
@Value(value ="${upload.path}")
|
|
@Value(value ="${upload.path}")
|
|
private String uploadPath;
|
|
private String uploadPath;
|
|
|
|
|
|
@@ -150,7 +154,7 @@ public class WechatAccountController {
|
|
userQrCode.setTicket(ticket);
|
|
userQrCode.setTicket(ticket);
|
|
userQrCode.setUrl(url);
|
|
userQrCode.setUrl(url);
|
|
userQrCode.setCompanyId(user.getCompanyId());
|
|
userQrCode.setCompanyId(user.getCompanyId());
|
|
-
|
|
|
|
|
|
+ //保存图片
|
|
CompletableFuture<String> future = saveWeChatQrCodeImgHttpClient(prefixUrl + ticket, ticket, uploadPath);
|
|
CompletableFuture<String> future = saveWeChatQrCodeImgHttpClient(prefixUrl + ticket, ticket, uploadPath);
|
|
String imgName = future.get(10, TimeUnit.SECONDS);// 添加超时
|
|
String imgName = future.get(10, TimeUnit.SECONDS);// 添加超时
|
|
if (imgName.isEmpty()){
|
|
if (imgName.isEmpty()){
|
|
@@ -174,6 +178,70 @@ 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;
|
|
|
|
+ }
|
|
|
|
+ //获取公众号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");
|
|
|
|
+
|
|
|
|
+ List<User> userList = userService.list(new QueryWrapper<User>().notIn("id", userAlreadyIds));//未生成二维码的员工
|
|
|
|
+ if (!userList.isEmpty()){
|
|
|
|
+ for (User u : userList) {
|
|
|
|
+ String userId = u.getId();
|
|
|
|
+ try {
|
|
|
|
+ //获取二维码相关信息相关
|
|
|
|
+ String result =createForeverStrTicket(accessToken, userId);
|
|
|
|
+ if (result==null|| StringUtils.isEmpty(result)){
|
|
|
|
+ msg.setError("获取二维码信息失败");
|
|
|
|
+ return msg;
|
|
|
|
+ }else {
|
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
|
+ if (null != jsonObject) {
|
|
|
|
+ String ticket = jsonObject.getString("ticket");
|
|
|
|
+ System.out.println("创建永久带参二维码成功,ticket=" + ticket);
|
|
|
|
+ String url = jsonObject.getString("url");
|
|
|
|
+ System.out.println("创建永久带参二维码成功,url=" + url);
|
|
|
|
+
|
|
|
|
+ UserQrCode userQrCode = new UserQrCode();
|
|
|
|
+ userQrCode.setUserId(userId);
|
|
|
|
+ userQrCode.setTicket(ticket);
|
|
|
|
+ userQrCode.setUrl(url);
|
|
|
|
+ userQrCode.setCompanyId(user.getCompanyId());
|
|
|
|
+ //保存图片
|
|
|
|
+ CompletableFuture<String> future = saveWeChatQrCodeImgHttpClient(prefixUrl + ticket, ticket, uploadPath);
|
|
|
|
+ String imgName = future.get(10, TimeUnit.SECONDS);// 添加超时
|
|
|
|
+ if (imgName.isEmpty()){
|
|
|
|
+ msg.setError("二维码图片保存失败");
|
|
|
|
+ return msg;
|
|
|
|
+ }else {
|
|
|
|
+ userQrCode.setImg(imgName);
|
|
|
|
+ }
|
|
|
|
+ userQrCodeService.save(userQrCode);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ msg.setData(e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
@Async("taskExecutor")
|
|
@Async("taskExecutor")
|
|
public CompletableFuture<String> saveWeChatQrCodeImg(String qrCodeUrl, String ticket, String uploadPath) {
|
|
public CompletableFuture<String> saveWeChatQrCodeImg(String qrCodeUrl, String ticket, String uploadPath) {
|