|
@@ -29,38 +29,37 @@ import java.util.stream.Collectors;
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
public class UnbindWarnPushServiceImpl implements IUnbindWarnPushService {
|
|
public class UnbindWarnPushServiceImpl implements IUnbindWarnPushService {
|
|
|
|
|
|
|
|
- private static final String TEMPLATE_VERSION = "1.0.5";
|
|
|
|
|
|
|
+ private static final String TEMPLATE_VERSION = "1.0.7";
|
|
|
private static final String TEMPLATE_ID = "AAqRuaOUCifK9";
|
|
private static final String TEMPLATE_ID = "AAqRuaOUCifK9";
|
|
|
@Autowired
|
|
@Autowired
|
|
|
ReportsAdPushMapper reportsPushMapper;
|
|
ReportsAdPushMapper reportsPushMapper;
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public void send(){
|
|
|
|
|
|
|
+ public void send() {
|
|
|
send(null, true);
|
|
send(null, true);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void send(List<String> advertiserIds, boolean copySend) {
|
|
public void send(List<String> advertiserIds, boolean copySend) {
|
|
|
|
|
+ String today = DateUtils.getNowDate("yyyy-MM-dd");
|
|
|
|
|
+ Long todayLong = Long.parseLong(today.replaceAll("-", ""));
|
|
|
|
|
+ String last90Day = DateUtils.getNowAddDate("yyyy-MM-dd", -60);
|
|
|
|
|
+ Long last90DayLong = Long.parseLong(last90Day.substring(0, 10).replaceAll("-", ""));
|
|
|
|
|
+ List<Map<String, String>> unbindData = reportsPushMapper.unbindData(todayLong, last90DayLong, advertiserIds);
|
|
|
|
|
+ if (unbindData.isEmpty()) {
|
|
|
|
|
+ log.info("unbindData数:0");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
List<JSONObject> users = reportsPushMapper.selectUserList();
|
|
List<JSONObject> users = reportsPushMapper.selectUserList();
|
|
|
users.forEach(u -> {
|
|
users.forEach(u -> {
|
|
|
- if (u.containsKey("remark") && u.getString("remark") != null && u.getString("remark").length() < 2){
|
|
|
|
|
|
|
+ if (u.containsKey("remark") && u.getString("remark") != null && u.getString("remark").length() < 2) {
|
|
|
u.remove("remark");
|
|
u.remove("remark");
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
List<String> mobiles = users.stream().map(user -> user.getString("phonenumber"))
|
|
List<String> mobiles = users.stream().map(user -> user.getString("phonenumber"))
|
|
|
.filter(s -> s != null && s.length() == 11)
|
|
.filter(s -> s != null && s.length() == 11)
|
|
|
.collect(Collectors.toList());
|
|
.collect(Collectors.toList());
|
|
|
-
|
|
|
|
|
- String today = DateUtils.getNowDate("yyyy-MM-dd");
|
|
|
|
|
- Long todayLong = Long.parseLong(today.replaceAll("-", ""));
|
|
|
|
|
- String last30Day = DateUtils.getNowAddDate("yyyy-MM-dd", -30);
|
|
|
|
|
- Long last30DayLong = Long.parseLong(last30Day.substring(0, 10).replaceAll("-", ""));
|
|
|
|
|
- String last90Day = DateUtils.getNowAddDate("yyyy-MM-dd", -60);
|
|
|
|
|
- Long last90DayLong = Long.parseLong(last90Day.substring(0, 10).replaceAll("-", ""));
|
|
|
|
|
-
|
|
|
|
|
int unFindCount = 0;
|
|
int unFindCount = 0;
|
|
|
- List<Map<String, String>> unbindData = reportsPushMapper.unbindData(todayLong, last90DayLong, advertiserIds);
|
|
|
|
|
-
|
|
|
|
|
List<Unbind> unbinds = new ArrayList<>();
|
|
List<Unbind> unbinds = new ArrayList<>();
|
|
|
List<Map<String, String>> unFindList = new ArrayList<>();
|
|
List<Map<String, String>> unFindList = new ArrayList<>();
|
|
|
for (JSONObject user : users) {
|
|
for (JSONObject user : users) {
|
|
@@ -72,7 +71,6 @@ public class UnbindWarnPushServiceImpl implements IUnbindWarnPushService {
|
|
|
}
|
|
}
|
|
|
for (Map<String, String> map : unbindData) {
|
|
for (Map<String, String> map : unbindData) {
|
|
|
String advertiserName = map.get("advertiser_name");
|
|
String advertiserName = map.get("advertiser_name");
|
|
|
-
|
|
|
|
|
boolean sameFlag = false;
|
|
boolean sameFlag = false;
|
|
|
for (Unbind ub : unbinds) {
|
|
for (Unbind ub : unbinds) {
|
|
|
if (same(advertiserName, ub)) {
|
|
if (same(advertiserName, ub)) {
|
|
@@ -83,16 +81,14 @@ public class UnbindWarnPushServiceImpl implements IUnbindWarnPushService {
|
|
|
}
|
|
}
|
|
|
if (!sameFlag) {
|
|
if (!sameFlag) {
|
|
|
unFindCount++;
|
|
unFindCount++;
|
|
|
- if (unFindList.size()<20) {
|
|
|
|
|
|
|
+ if (unFindList.size() < 20) {
|
|
|
unFindList.add(map);
|
|
unFindList.add(map);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
System.out.println(">>>> 未匹配的账户数:" + unFindCount);
|
|
System.out.println(">>>> 未匹配的账户数:" + unFindCount);
|
|
|
-
|
|
|
|
|
String alarm_time = DateUtils.getNowDate("yyyy-MM-dd HH:mm:ss");
|
|
String alarm_time = DateUtils.getNowDate("yyyy-MM-dd HH:mm:ss");
|
|
|
-
|
|
|
|
|
String token = null, token2 = null, token3 = null;
|
|
String token = null, token2 = null, token3 = null;
|
|
|
Map<String, String> mobileMap = null;
|
|
Map<String, String> mobileMap = null;
|
|
|
try {
|
|
try {
|
|
@@ -100,24 +96,24 @@ public class UnbindWarnPushServiceImpl implements IUnbindWarnPushService {
|
|
|
mobileMap = FeishuRobotUtil.getFsUserIds(token, mobiles); //mobile -> userId
|
|
mobileMap = FeishuRobotUtil.getFsUserIds(token, mobiles); //mobile -> userId
|
|
|
token2 = FeishuRobotUtil.getTenantToken(FeishuRobotUtil.getFsAdlb2Auth());
|
|
token2 = FeishuRobotUtil.getTenantToken(FeishuRobotUtil.getFsAdlb2Auth());
|
|
|
token3 = FeishuRobotUtil.getTenantToken(FeishuRobotUtil.getFsAdlb3Auth());
|
|
token3 = FeishuRobotUtil.getTenantToken(FeishuRobotUtil.getFsAdlb3Auth());
|
|
|
- }catch (IOException e){
|
|
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
log.error("获取飞书token失败", e);
|
|
log.error("获取飞书token失败", e);
|
|
|
- if (token == null || mobileMap == null){
|
|
|
|
|
|
|
+ if (token == null || mobileMap == null) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- for (Unbind ub : unbinds){
|
|
|
|
|
|
|
+ for (Unbind ub : unbinds) {
|
|
|
String userId = mobileMap.get(ub.getPhoneNumber());
|
|
String userId = mobileMap.get(ub.getPhoneNumber());
|
|
|
- if (!Check.isNull(userId) && ub.getUnbindNum() > 0){
|
|
|
|
|
|
|
+ if (!Check.isNull(userId) && ub.getUnbindNum() > 0) {
|
|
|
JSONObject template_variable = new JSONObject();
|
|
JSONObject template_variable = new JSONObject();
|
|
|
template_variable.put("unbindNum", ub.getUnbindNum());
|
|
template_variable.put("unbindNum", ub.getUnbindNum());
|
|
|
template_variable.put("alarm_time", alarm_time);
|
|
template_variable.put("alarm_time", alarm_time);
|
|
|
JSONArray object_list_1 = new JSONArray();
|
|
JSONArray object_list_1 = new JSONArray();
|
|
|
- for (Map<String, String> map : ub.getTop10List()){
|
|
|
|
|
|
|
+ for (Map<String, String> map : ub.getTop10List()) {
|
|
|
JSONObject object = new JSONObject();
|
|
JSONObject object = new JSONObject();
|
|
|
object.put("advertiserName", map.get("advertiser_name"));
|
|
object.put("advertiserName", map.get("advertiser_name"));
|
|
|
object.put("advertiserId", String.valueOf(map.get("advertiser_id")));
|
|
object.put("advertiserId", String.valueOf(map.get("advertiser_id")));
|
|
|
- object.put("todayCost", String.valueOf(map.getOrDefault("today_cost", "0")));
|
|
|
|
|
|
|
+ //object.put("todayCost", String.valueOf(map.getOrDefault("today_cost", "0")));
|
|
|
object.put("last30Cost", String.valueOf(map.getOrDefault("last_30_cost", "0")));
|
|
object.put("last30Cost", String.valueOf(map.getOrDefault("last_30_cost", "0")));
|
|
|
object_list_1.add(object);
|
|
object_list_1.add(object);
|
|
|
}
|
|
}
|
|
@@ -125,7 +121,7 @@ public class UnbindWarnPushServiceImpl implements IUnbindWarnPushService {
|
|
|
|
|
|
|
|
JSONObject content = new JSONObject();
|
|
JSONObject content = new JSONObject();
|
|
|
JSONObject contentData = new JSONObject();
|
|
JSONObject contentData = new JSONObject();
|
|
|
- contentData.put("template_id",TEMPLATE_ID);
|
|
|
|
|
|
|
+ contentData.put("template_id", TEMPLATE_ID);
|
|
|
contentData.put("template_version_name", TEMPLATE_VERSION);
|
|
contentData.put("template_version_name", TEMPLATE_VERSION);
|
|
|
contentData.put("template_variable", template_variable);
|
|
contentData.put("template_variable", template_variable);
|
|
|
content.put("type", "template");
|
|
content.put("type", "template");
|
|
@@ -136,7 +132,7 @@ public class UnbindWarnPushServiceImpl implements IUnbindWarnPushService {
|
|
|
// request.put("receive_id", "44fbaed6");
|
|
// request.put("receive_id", "44fbaed6");
|
|
|
request.put("msg_type", "interactive");
|
|
request.put("msg_type", "interactive");
|
|
|
request.put("content", content.toJSONString());
|
|
request.put("content", content.toJSONString());
|
|
|
- System.out.println("发送给: "+ub.getName());
|
|
|
|
|
|
|
+ System.out.println("发送给: " + ub.getName());
|
|
|
sendToFeishu(token, request);
|
|
sendToFeishu(token, request);
|
|
|
|
|
|
|
|
// //todo 临时加的
|
|
// //todo 临时加的
|
|
@@ -152,16 +148,16 @@ public class UnbindWarnPushServiceImpl implements IUnbindWarnPushService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//给指定人员抄送
|
|
//给指定人员抄送
|
|
|
- if (copySend){
|
|
|
|
|
|
|
+ if (copySend) {
|
|
|
JSONObject template_variable = new JSONObject();
|
|
JSONObject template_variable = new JSONObject();
|
|
|
template_variable.put("unbindNum", unbindData.size());
|
|
template_variable.put("unbindNum", unbindData.size());
|
|
|
template_variable.put("alarm_time", alarm_time);
|
|
template_variable.put("alarm_time", alarm_time);
|
|
|
JSONArray object_list_1 = new JSONArray();
|
|
JSONArray object_list_1 = new JSONArray();
|
|
|
- for (Map<String, String> map : unbindData.subList(0, Math.min(10, unbindData.size()))){
|
|
|
|
|
|
|
+ for (Map<String, String> map : unbindData.subList(0, Math.min(10, unbindData.size()))) {
|
|
|
JSONObject object = new JSONObject();
|
|
JSONObject object = new JSONObject();
|
|
|
object.put("advertiserName", map.get("advertiser_name"));
|
|
object.put("advertiserName", map.get("advertiser_name"));
|
|
|
object.put("advertiserId", String.valueOf(map.get("advertiser_id")));
|
|
object.put("advertiserId", String.valueOf(map.get("advertiser_id")));
|
|
|
- object.put("todayCost", String.valueOf(map.getOrDefault("today_cost", "0")));
|
|
|
|
|
|
|
+ //object.put("todayCost", String.valueOf(map.getOrDefault("today_cost", "0")));
|
|
|
object.put("last30Cost", String.valueOf(map.getOrDefault("last_30_cost", "0")));
|
|
object.put("last30Cost", String.valueOf(map.getOrDefault("last_30_cost", "0")));
|
|
|
object_list_1.add(object);
|
|
object_list_1.add(object);
|
|
|
}
|
|
}
|
|
@@ -169,7 +165,7 @@ public class UnbindWarnPushServiceImpl implements IUnbindWarnPushService {
|
|
|
|
|
|
|
|
JSONObject content = new JSONObject();
|
|
JSONObject content = new JSONObject();
|
|
|
JSONObject contentData = new JSONObject();
|
|
JSONObject contentData = new JSONObject();
|
|
|
- contentData.put("template_id",TEMPLATE_ID);
|
|
|
|
|
|
|
+ contentData.put("template_id", TEMPLATE_ID);
|
|
|
contentData.put("template_version_name", TEMPLATE_VERSION);
|
|
contentData.put("template_version_name", TEMPLATE_VERSION);
|
|
|
contentData.put("template_variable", template_variable);
|
|
contentData.put("template_variable", template_variable);
|
|
|
content.put("type", "template");
|
|
content.put("type", "template");
|
|
@@ -177,44 +173,44 @@ public class UnbindWarnPushServiceImpl implements IUnbindWarnPushService {
|
|
|
|
|
|
|
|
List<String> userIds = Arrays.asList(
|
|
List<String> userIds = Arrays.asList(
|
|
|
"44fbaed6" //zhaotx
|
|
"44fbaed6" //zhaotx
|
|
|
- ,"c5f6b59d" //yuyang
|
|
|
|
|
- ,"d834552b" //hemenghao
|
|
|
|
|
- ,"a3235a61" //louzijun
|
|
|
|
|
- ,"ebeeced9" //yumeng
|
|
|
|
|
- ,"58e7a98a" //xsq
|
|
|
|
|
|
|
+ , "c5f6b59d" //yuyang
|
|
|
|
|
+ , "d834552b" //hemenghao
|
|
|
|
|
+ , "a3235a61" //louzijun
|
|
|
|
|
+ , "ebeeced9" //yumeng
|
|
|
|
|
+ , "58e7a98a" //xsq
|
|
|
|
|
+ , "43gb7fbc" //hpk
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- for (String userId : userIds){
|
|
|
|
|
|
|
+ for (String userId : userIds) {
|
|
|
JSONObject request = new JSONObject();
|
|
JSONObject request = new JSONObject();
|
|
|
request.put("receive_id", userId);
|
|
request.put("receive_id", userId);
|
|
|
request.put("msg_type", "interactive");
|
|
request.put("msg_type", "interactive");
|
|
|
request.put("content", content.toJSONString());
|
|
request.put("content", content.toJSONString());
|
|
|
- System.out.println("发送给: "+userId);
|
|
|
|
|
|
|
+ System.out.println("发送给: " + userId);
|
|
|
sendToFeishu(token, request);
|
|
sendToFeishu(token, request);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private void sendToFeishu(String token, JSONObject requestBody){
|
|
|
|
|
|
|
+ private void sendToFeishu(String token, JSONObject requestBody) {
|
|
|
//发送
|
|
//发送
|
|
|
- try (CloseableHttpClient client = HttpClients.createDefault()){
|
|
|
|
|
|
|
+ try (CloseableHttpClient client = HttpClients.createDefault()) {
|
|
|
HttpPost httpPost = new HttpPost("https://open.feishu.cn/open-apis/im/v1/messages?receive_id_type=user_id");
|
|
HttpPost httpPost = new HttpPost("https://open.feishu.cn/open-apis/im/v1/messages?receive_id_type=user_id");
|
|
|
- httpPost.setHeader("Authorization", "Bearer "+token);
|
|
|
|
|
|
|
+ httpPost.setHeader("Authorization", "Bearer " + token);
|
|
|
HttpEntity entity = new StringEntity(requestBody.toJSONString(), "UTF-8");
|
|
HttpEntity entity = new StringEntity(requestBody.toJSONString(), "UTF-8");
|
|
|
httpPost.setEntity(entity);
|
|
httpPost.setEntity(entity);
|
|
|
httpPost.setHeader("Content-Type", "application/json; charset=utf-8");
|
|
httpPost.setHeader("Content-Type", "application/json; charset=utf-8");
|
|
|
CloseableHttpResponse respon = client.execute(httpPost);
|
|
CloseableHttpResponse respon = client.execute(httpPost);
|
|
|
- System.out.println("发送结果: "+ EntityUtils.toString(respon.getEntity(), "UTF-8"));
|
|
|
|
|
|
|
+ System.out.println("发送结果: " + EntityUtils.toString(respon.getEntity(), "UTF-8"));
|
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
|
log.error("发送飞书消息失败", e);
|
|
log.error("发送飞书消息失败", e);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private boolean same(String advertiserName, Unbind ub){
|
|
|
|
|
- if (advertiserName.contains(ub.getName())){
|
|
|
|
|
|
|
+ private boolean same(String advertiserName, Unbind ub) {
|
|
|
|
|
+ if (advertiserName.contains(ub.getName())) {
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
// if (!Check.isNull(ub.getRemark())){
|
|
// if (!Check.isNull(ub.getRemark())){
|