|
@@ -1,18 +1,24 @@
|
|
|
package com.cyksj.web.controller.manage;
|
|
package com.cyksj.web.controller.manage;
|
|
|
|
|
|
|
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
|
|
|
|
+import cn.hutool.core.date.DateField;
|
|
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.http.Method;
|
|
import cn.hutool.http.Method;
|
|
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
|
+import com.cyksj.common.util.J11HttpC;
|
|
|
|
|
+import com.cyksj.common.util.Jsons;
|
|
|
import com.cyksj.dto.Result;
|
|
import com.cyksj.dto.Result;
|
|
|
import com.cyksj.enums.GatewayResponse;
|
|
import com.cyksj.enums.GatewayResponse;
|
|
|
-import com.cyksj.mapper.GroupsRelationMapper;
|
|
|
|
|
-import com.cyksj.mapper.UserMapper;
|
|
|
|
|
|
|
+import com.cyksj.mapper.*;
|
|
|
import com.cyksj.mapper.manage.distribute.UserDistributeSharedMapper;
|
|
import com.cyksj.mapper.manage.distribute.UserDistributeSharedMapper;
|
|
|
import com.cyksj.mapper.market.task.UserBindDetailMapper;
|
|
import com.cyksj.mapper.market.task.UserBindDetailMapper;
|
|
|
import com.cyksj.model.entity.*;
|
|
import com.cyksj.model.entity.*;
|
|
|
import com.cyksj.model.manage.views.UserView;
|
|
import com.cyksj.model.manage.views.UserView;
|
|
|
import com.cyksj.model.views.RenewalView;
|
|
import com.cyksj.model.views.RenewalView;
|
|
|
|
|
+import com.cyksj.service.corp.WxCorpOps;
|
|
|
import com.cyksj.service.relation.GroupRelationClearService;
|
|
import com.cyksj.service.relation.GroupRelationClearService;
|
|
|
import com.cyksj.service.relation.GroupRelationFrontService;
|
|
import com.cyksj.service.relation.GroupRelationFrontService;
|
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
@@ -26,8 +32,12 @@ import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
|
+import java.net.http.HttpRequest;
|
|
|
|
|
+import java.net.http.HttpResponse;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
import java.util.Optional;
|
|
import java.util.Optional;
|
|
|
|
|
+import java.util.Set;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -117,6 +127,10 @@ public class CmsUserController{
|
|
|
List<UserBindDetail> userBindDetails = bindDetailMapper.selectList(Wrappers.lambdaQuery(UserBindDetail.class)
|
|
List<UserBindDetail> userBindDetails = bindDetailMapper.selectList(Wrappers.lambdaQuery(UserBindDetail.class)
|
|
|
.ne(UserBindDetail::getPhone, StrUtil.EMPTY));
|
|
.ne(UserBindDetail::getPhone, StrUtil.EMPTY));
|
|
|
List<String> collect = userBindDetails.stream().map(UserBindDetail::getPhone).collect(Collectors.toList());
|
|
List<String> collect = userBindDetails.stream().map(UserBindDetail::getPhone).collect(Collectors.toList());
|
|
|
|
|
+ DateTime now = new DateTime();
|
|
|
|
|
+ DateTime zero = DateUtil.beginOfDay(now);
|
|
|
|
|
+ DateTime time = DateUtil.offset(zero, DateField.DAY_OF_MONTH, 5);
|
|
|
|
|
+ List<GroupsRelation> groupsRelations = groupsRelationMapper.selectUserPhoneByTime(time);
|
|
|
List<List<String>> partition = Lists.partition(collect, 200);
|
|
List<List<String>> partition = Lists.partition(collect, 200);
|
|
|
System.out.println(partition.size());
|
|
System.out.println(partition.size());
|
|
|
for (List<String> list : partition) {
|
|
for (List<String> list : partition) {
|
|
@@ -132,4 +146,77 @@ public class CmsUserController{
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 批量发送过期模板消息
|
|
|
|
|
+ */
|
|
|
|
|
+ private final GoodsDonSkuMapper skuMapper;
|
|
|
|
|
+ private final GoodsDonMapper donMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @GetMapping("/send/expiryMsg")
|
|
|
|
|
+ public void sendExpiryMsg() {
|
|
|
|
|
+ String apiKey = "key-246cd85eb5603c3d4924531e5d5c4edc";
|
|
|
|
|
+ String url = "http://sms-api.luosimao.com/v1/send_batch.json";
|
|
|
|
|
+ DateTime now = new DateTime();
|
|
|
|
|
+ DateTime zero = DateUtil.beginOfDay(now);
|
|
|
|
|
+ DateTime time = DateUtil.offset(zero, DateField.DAY_OF_MONTH, 5);
|
|
|
|
|
+ List<GroupsRelation> groupsRelations = groupsRelationMapper.selectUserPhoneByTime(time);
|
|
|
|
|
+ Map<Long, List<GroupsRelation>> collect = groupsRelations.stream().collect(Collectors.groupingBy(GroupsRelation::getSkuId));
|
|
|
|
|
+ collect.forEach((skuId,relations)->{
|
|
|
|
|
+ GoodsDonSku donSku = skuMapper.selectById(skuId);
|
|
|
|
|
+ GoodsDon goodsDon = donMapper.selectById(donSku.getGoodsId());
|
|
|
|
|
+ String content = String.format("【银河录像局】您的%s平台账号,5天内即将到期,请及时续费以免影响使用,银河录像局官网https://nf.video,公众号:银河录像局助手, 回复“TD”退订", goodsDon.getTitle());
|
|
|
|
|
+ cn.hutool.http.HttpRequest request = new cn.hutool.http.HttpRequest(url);
|
|
|
|
|
+ request.setMethod(Method.POST);
|
|
|
|
|
+ request.basicAuth("api", apiKey);
|
|
|
|
|
+ request.form("mobile_list", relations.stream().map(GroupsRelation::getPhone).collect(Collectors.joining(",")));
|
|
|
|
|
+ request.form("message", content);
|
|
|
|
|
+ cn.hutool.http.HttpResponse execute = request.execute();
|
|
|
|
|
+ System.out.println(execute.body());
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 企业微信群发发送用户账号过期
|
|
|
|
|
+ */
|
|
|
|
|
+ private final WxCorpOps wxCorpOps;
|
|
|
|
|
+
|
|
|
|
|
+ @GetMapping("/corp/send/msg")
|
|
|
|
|
+ public Result<String> corpSendMsg() throws Exception {
|
|
|
|
|
+ DateTime now = new DateTime();
|
|
|
|
|
+ DateTime zero = DateUtil.beginOfDay(now);
|
|
|
|
|
+ DateTime time = DateUtil.offset(zero, DateField.DAY_OF_MONTH, 5);
|
|
|
|
|
+ List<GroupsRelation> groupsRelations = groupsRelationMapper.selectUnionIdByTime(time);
|
|
|
|
|
+ String url = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/add_msg_template?access_token=" + wxCorpOps.getAccessToken("ww9c0ccaad2e9d3822");
|
|
|
|
|
+ Map<Long, List<GroupsRelation>> collect = groupsRelations.stream().collect(Collectors.groupingBy(GroupsRelation::getSkuId));
|
|
|
|
|
+ collect.forEach((skuId, relations) -> {
|
|
|
|
|
+ GoodsDonSku donSku = skuMapper.selectById(skuId);
|
|
|
|
|
+ GoodsDon goodsDon = donMapper.selectById(donSku.getGoodsId());
|
|
|
|
|
+ Set<String> exterUserIds = relations.stream().map(GroupsRelation::getExternalUserid).collect(Collectors.toSet());
|
|
|
|
|
+ String content = String.format("您的%s账号5天内即将到期,请尽快续费,以免影响使用,续费地址:https://nf.video/yinhe/web/ticket", goodsDon.getTitle());
|
|
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
|
|
+ jsonObject.putOpt("chat_type", "single");
|
|
|
|
|
+ jsonObject.putOpt("external_userid", "[\"wmvj2DPQAAzWQY3xIQOQMykTASbvb_pQ\"]");
|
|
|
|
|
+// jsonObject.putOpt("sender", "xx");
|
|
|
|
|
+ JSONObject text = new JSONObject();
|
|
|
|
|
+ text.putOpt("content", content);
|
|
|
|
|
+ jsonObject.putOpt("text", text.toString());
|
|
|
|
|
+ HttpResponse<String> send = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ send = J11HttpC.custom()
|
|
|
|
|
+ .ofPost()
|
|
|
|
|
+ .url(url)
|
|
|
|
|
+ .body(HttpRequest.BodyPublishers.ofString(jsonObject.toString()))
|
|
|
|
|
+ .send(HttpResponse.BodyHandlers.ofString());
|
|
|
|
|
+ JSONObject response = Jsons.parseObject(send.body(), JSONObject.class);
|
|
|
|
|
+ if (response.getInt("errcode") == 0 && response.getStr("errmsg").equals("ok")) {
|
|
|
|
|
+ System.out.println("发送成功");
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|