|
@@ -1,189 +1,188 @@
|
|
|
-package com.book.push.task;
|
|
|
-
|
|
|
-import com.book.dao.cps.entity.CustomMediaPush;
|
|
|
-import com.book.dao.cps.entity.CustomUrl;
|
|
|
-import com.book.dao.cps.pojo.AdminConfig;
|
|
|
-import com.book.dao.cps.pojo.Custom;
|
|
|
-import com.book.dao.cps.pojo.Ophost;
|
|
|
-import com.book.dao.cps.pojo.User;
|
|
|
-import com.book.dao.utils.DateUtils;
|
|
|
-import com.book.push.service.dao.*;
|
|
|
-import com.book.push.service.push.PushService;
|
|
|
-import com.book.push.service.push.vo.CustomMessage;
|
|
|
-import com.book.push.service.wx.WxThirdPartService;
|
|
|
-import com.book.push.utils.JsonUtils;
|
|
|
-import com.sun.corba.se.spi.ior.IdentifiableFactory;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
-import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
|
|
|
-import me.chanjar.weixin.mp.builder.kefu.NewsBuilder;
|
|
|
-import me.chanjar.weixin.mp.builder.kefu.TextBuilder;
|
|
|
-import me.chanjar.weixin.open.api.WxOpenMpService;
|
|
|
-import me.chanjar.weixin.open.api.WxOpenService;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.scheduling.annotation.Scheduled;
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
-
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.concurrent.TimeUnit;
|
|
|
-
|
|
|
-/**
|
|
|
- * created in 2021/8/17
|
|
|
- * Project: book-store
|
|
|
- * 客服消息
|
|
|
- *
|
|
|
- * @author win7
|
|
|
- */
|
|
|
-
|
|
|
-@Component
|
|
|
-@Slf4j
|
|
|
-public class KefuTask {
|
|
|
- @Autowired
|
|
|
- private CustomService customService;
|
|
|
- @Autowired
|
|
|
- private AdminConfigService adminConfigService;
|
|
|
- @Autowired
|
|
|
- private WxThirdPartService wxThirdPartService;
|
|
|
- @Autowired
|
|
|
- private UserService userService;
|
|
|
- @Autowired
|
|
|
- private PushService pushService;
|
|
|
- @Autowired
|
|
|
- private CustomUrlService customUrlService;
|
|
|
- @Autowired
|
|
|
- private CustomMediaPushService customMediaPushService;
|
|
|
- @Autowired
|
|
|
- private OpHostService opHostService;
|
|
|
-
|
|
|
- @Scheduled(fixedRate = 1000 * 60 * 10)
|
|
|
- public void run() {
|
|
|
- Integer now = DateUtils.getNow();
|
|
|
- Integer to = now + (1000 * 60 * 10);
|
|
|
- List<Custom> customs = customService.selectListBetweenSendTime(now, to);
|
|
|
- for (Custom custom : customs) {
|
|
|
-
|
|
|
- System.out.println("kefu-task...");
|
|
|
- Integer sendtime = custom.getSendtime();
|
|
|
- Integer delay = sendtime - DateUtils.getNow();
|
|
|
-
|
|
|
- Integer customId = custom.getId();
|
|
|
- Integer customMediaPushId = custom.getCustomMediaPushId();
|
|
|
- CustomMediaPush customMediaPush = customMediaPushService.selectById(customMediaPushId);
|
|
|
- CustomUrl customUrl = customUrlService.selectByCustomId(customId);
|
|
|
-
|
|
|
-
|
|
|
- Integer adminId = custom.getAdminId();
|
|
|
- AdminConfig adminConfig = adminConfigService.selectByAdminId(adminId);
|
|
|
- String appid = adminConfig.getAppid();
|
|
|
- Integer platformId = adminConfig.getPlatformId();
|
|
|
- Ophost ophost = opHostService.selectById(adminConfig.getOphostId());
|
|
|
-
|
|
|
- String userJsonStr = custom.getUserJson().toString();
|
|
|
- userJsonStr = userJsonStr.substring(1, userJsonStr.length() - 1).replace("\\", "");
|
|
|
- Custom.UserJson userJson = JsonUtils.getObject(userJsonStr, Custom.UserJson.class);
|
|
|
- List<User> userList = getListByjson(userJson, adminId);
|
|
|
-
|
|
|
- List<WxMpKefuMessage> messageList = new ArrayList<>();
|
|
|
-
|
|
|
- log.info("检测到客服消息:消息id:{},符合条件的人数:{}",custom.getId(),userList.size());
|
|
|
- for (User user : userList) {
|
|
|
-
|
|
|
- if ("0".equals(custom.getMessageType())) {
|
|
|
- String messageJson = custom.getMessageJson().toString().replace("\\", "");
|
|
|
- messageJson = messageJson.replace("\\", "").substring(1, messageJson.length() - 1);
|
|
|
-
|
|
|
- Custom.MessageJson[] messageJsons = JsonUtils.getArray(messageJson, Custom.MessageJson.class);
|
|
|
- NewsBuilder newsBuilder = new NewsBuilder().toUser(user.getOpenid());
|
|
|
- for (Custom.MessageJson message : messageJsons) {
|
|
|
- WxMpKefuMessage.WxArticle wxArticle = new WxMpKefuMessage.WxArticle();
|
|
|
- wxArticle.setTitle(message.getTitle());
|
|
|
- wxArticle.setPicUrl(message.getImage());
|
|
|
- wxArticle.setDescription(message.getDescription());
|
|
|
- String url = message.getUrl()==null?"":message.getUrl().replace("{$ophost}",ophost.getHost());
|
|
|
- wxArticle.setUrl(url);
|
|
|
- newsBuilder.addArticle(wxArticle);
|
|
|
-
|
|
|
- }
|
|
|
- WxMpKefuMessage kefuMessage = newsBuilder.build();
|
|
|
- messageList.add(kefuMessage);
|
|
|
- } else {
|
|
|
- if (StringUtils.isNotEmpty(custom.getMessageText())){
|
|
|
- String text = custom.getMessageText();
|
|
|
-
|
|
|
- text = text.replace("{$ophost}",ophost.getHost());
|
|
|
- WxMpKefuMessage build = new TextBuilder().toUser(user.getOpenid()).content(text).build();
|
|
|
- messageList.add(build);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- custom.setSendNum(messageList.size());
|
|
|
- WxOpenService wxOpenService = wxThirdPartService.getWxOpenServiceByPlatFormId(platformId);
|
|
|
- WxOpenMpService wxMpService = wxOpenService.getWxOpenComponentService().getWxMpServiceByAppid(adminConfig.getAppid());
|
|
|
- CustomMessage customMessage = new CustomMessage();
|
|
|
- customMessage.setCustom(custom);
|
|
|
- customMessage.setMessageList(messageList);
|
|
|
- customMessage.setCustomService(customService);
|
|
|
-
|
|
|
- pushService.addCustomMessagePushTask(wxMpService, customMessage, delay, TimeUnit.SECONDS);
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private List<User> getListByjson(Custom.UserJson userJson, Integer channelId) {
|
|
|
- // "{\"sex\":-1,\"tag\":-1,\"consume\":-1,\"kandian\":-1,\"subscribe_time\":-1,\"all\":\"0\"}"
|
|
|
-// "{\"sex\":2,\"mobile_system\":2,\"tag\":8,\"consume\":4,\"kandian\":2,\"subscribe_time\":7,\"all\":\"0\"}"
|
|
|
-
|
|
|
- Map map = new HashMap<>();
|
|
|
- map.put("channel_id", channelId);
|
|
|
- if (!"1".equals(userJson.getAll())) {
|
|
|
- if (userJson.getKandian() == 1) {
|
|
|
- map.put("kandian_max", "500");
|
|
|
- } else if (userJson.getKandian() == 2) {
|
|
|
- map.put("kandian_max", "2000");
|
|
|
- } else if (userJson.getKandian() == 3) {
|
|
|
- map.put("kandian_min", "2000");
|
|
|
- }
|
|
|
-
|
|
|
- if (userJson.getSex() != -1) {
|
|
|
- map.put("sex", userJson.getSex());
|
|
|
- }
|
|
|
- if (userJson.getConsume() == 1) {
|
|
|
- map.put("is_pay", "0");
|
|
|
- } else if (userJson.getConsume() == 4) {
|
|
|
- map.put("is_pay", "1");
|
|
|
- }
|
|
|
- if (userJson.getTag() != -1) {
|
|
|
- map.put("tag", userJson.getTag());
|
|
|
- }
|
|
|
- if (userJson.getSubscribe_time() != -1) {
|
|
|
- int subscribeTime = -1;
|
|
|
- if (userJson.getSubscribe_time() == 6) {
|
|
|
- subscribeTime = DateUtils.getNow() - 12 * 60 * 60;
|
|
|
- } else if (userJson.getSubscribe_time() == 7) {
|
|
|
- subscribeTime = DateUtils.getNow() - 24 * 60 * 60;
|
|
|
- } else if (userJson.getSubscribe_time() == 8) {
|
|
|
- subscribeTime = DateUtils.getNow() - 48 * 60 * 60;
|
|
|
- } else if (userJson.getSubscribe_time() == 9) {
|
|
|
- subscribeTime = DateUtils.getNow() - 7 * 24 * 60 * 60;
|
|
|
- } else if (userJson.getSubscribe_time() == 10) {
|
|
|
- subscribeTime = DateUtils.getNow() - 15 * 24 * 60 * 60;
|
|
|
- }
|
|
|
- map.put("subscribe_time", subscribeTime);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- List<User> users = userService.selectListByPushMap(map);
|
|
|
- return users;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-}
|
|
|
+package com.book.push.task;
|
|
|
+
|
|
|
+import com.book.dao.cps.entity.CustomMediaPush;
|
|
|
+import com.book.dao.cps.entity.CustomUrl;
|
|
|
+import com.book.dao.cps.pojo.AdminConfig;
|
|
|
+import com.book.dao.cps.pojo.Custom;
|
|
|
+import com.book.dao.cps.pojo.Ophost;
|
|
|
+import com.book.dao.cps.pojo.User;
|
|
|
+import com.book.dao.utils.DateUtils;
|
|
|
+import com.book.push.service.dao.*;
|
|
|
+import com.book.push.service.push.PushService;
|
|
|
+import com.book.push.service.push.vo.CustomMessage;
|
|
|
+import com.book.push.service.wx.WxThirdPartService;
|
|
|
+import com.book.push.utils.JsonUtils;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
|
|
|
+import me.chanjar.weixin.mp.builder.kefu.NewsBuilder;
|
|
|
+import me.chanjar.weixin.mp.builder.kefu.TextBuilder;
|
|
|
+import me.chanjar.weixin.open.api.WxOpenMpService;
|
|
|
+import me.chanjar.weixin.open.api.WxOpenService;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+
|
|
|
+/**
|
|
|
+ * created in 2021/8/17
|
|
|
+ * Project: book-store
|
|
|
+ * 客服消息
|
|
|
+ *
|
|
|
+ * @author win7
|
|
|
+ */
|
|
|
+
|
|
|
+@Component
|
|
|
+@Slf4j
|
|
|
+public class KefuTask {
|
|
|
+ @Autowired
|
|
|
+ private CustomService customService;
|
|
|
+ @Autowired
|
|
|
+ private AdminConfigService adminConfigService;
|
|
|
+ @Autowired
|
|
|
+ private WxThirdPartService wxThirdPartService;
|
|
|
+ @Autowired
|
|
|
+ private UserService userService;
|
|
|
+ @Autowired
|
|
|
+ private PushService pushService;
|
|
|
+ @Autowired
|
|
|
+ private CustomUrlService customUrlService;
|
|
|
+ @Autowired
|
|
|
+ private CustomMediaPushService customMediaPushService;
|
|
|
+ @Autowired
|
|
|
+ private OpHostService opHostService;
|
|
|
+
|
|
|
+ @Scheduled(fixedRate = 1000 * 60 * 10)
|
|
|
+ public void run() {
|
|
|
+ Integer now = DateUtils.getNow();
|
|
|
+ Integer to = now + (1000 * 60 * 10);
|
|
|
+ List<Custom> customs = customService.selectListBetweenSendTime(now, to);
|
|
|
+ for (Custom custom : customs) {
|
|
|
+
|
|
|
+ System.out.println("kefu-task...");
|
|
|
+ Integer sendtime = custom.getSendtime();
|
|
|
+ Integer delay = sendtime - DateUtils.getNow();
|
|
|
+
|
|
|
+ Integer customId = custom.getId();
|
|
|
+ Integer customMediaPushId = custom.getCustomMediaPushId();
|
|
|
+ CustomMediaPush customMediaPush = customMediaPushService.selectById(customMediaPushId);
|
|
|
+ CustomUrl customUrl = customUrlService.selectByCustomId(customId);
|
|
|
+
|
|
|
+
|
|
|
+ Integer adminId = custom.getAdminId();
|
|
|
+ AdminConfig adminConfig = adminConfigService.selectByAdminId(adminId);
|
|
|
+ String appid = adminConfig.getAppid();
|
|
|
+ Integer platformId = adminConfig.getPlatformId();
|
|
|
+ Ophost ophost = opHostService.selectById(adminConfig.getOphostId());
|
|
|
+
|
|
|
+ String userJsonStr = custom.getUserJson().toString();
|
|
|
+ userJsonStr = userJsonStr.substring(1, userJsonStr.length() - 1).replace("\\", "");
|
|
|
+ Custom.UserJson userJson = JsonUtils.getObject(userJsonStr, Custom.UserJson.class);
|
|
|
+ List<User> userList = getListByjson(userJson, adminId);
|
|
|
+
|
|
|
+ List<WxMpKefuMessage> messageList = new ArrayList<>();
|
|
|
+
|
|
|
+ log.info("检测到客服消息:消息id:{},符合条件的人数:{}",custom.getId(),userList.size());
|
|
|
+ for (User user : userList) {
|
|
|
+
|
|
|
+ if ("0".equals(custom.getMessageType())) {
|
|
|
+ String messageJson = custom.getMessageJson().toString().replace("\\", "");
|
|
|
+ messageJson = messageJson.replace("\\", "").substring(1, messageJson.length() - 1);
|
|
|
+
|
|
|
+ Custom.MessageJson[] messageJsons = JsonUtils.getArray(messageJson, Custom.MessageJson.class);
|
|
|
+ NewsBuilder newsBuilder = new NewsBuilder().toUser(user.getOpenid());
|
|
|
+ for (Custom.MessageJson message : messageJsons) {
|
|
|
+ WxMpKefuMessage.WxArticle wxArticle = new WxMpKefuMessage.WxArticle();
|
|
|
+ wxArticle.setTitle(message.getTitle());
|
|
|
+ wxArticle.setPicUrl(message.getImage());
|
|
|
+ wxArticle.setDescription(message.getDescription());
|
|
|
+ String url = message.getUrl()==null?"":message.getUrl().replace("{$ophost}",ophost.getHost());
|
|
|
+ wxArticle.setUrl(url);
|
|
|
+ newsBuilder.addArticle(wxArticle);
|
|
|
+
|
|
|
+ }
|
|
|
+ WxMpKefuMessage kefuMessage = newsBuilder.build();
|
|
|
+ messageList.add(kefuMessage);
|
|
|
+ } else {
|
|
|
+ if (StringUtils.isNotEmpty(custom.getMessageText())){
|
|
|
+ String text = custom.getMessageText();
|
|
|
+
|
|
|
+ text = text.replace("{$ophost}",ophost.getHost());
|
|
|
+ WxMpKefuMessage build = new TextBuilder().toUser(user.getOpenid()).content(text).build();
|
|
|
+ messageList.add(build);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ custom.setSendNum(messageList.size());
|
|
|
+ WxOpenService wxOpenService = wxThirdPartService.getWxOpenServiceByPlatFormId(platformId);
|
|
|
+ WxOpenMpService wxMpService = wxOpenService.getWxOpenComponentService().getWxMpServiceByAppid(adminConfig.getAppid());
|
|
|
+ CustomMessage customMessage = new CustomMessage();
|
|
|
+ customMessage.setCustom(custom);
|
|
|
+ customMessage.setMessageList(messageList);
|
|
|
+ customMessage.setCustomService(customService);
|
|
|
+
|
|
|
+ pushService.addCustomMessagePushTask(wxMpService, customMessage, delay, TimeUnit.SECONDS);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<User> getListByjson(Custom.UserJson userJson, Integer channelId) {
|
|
|
+ // "{\"sex\":-1,\"tag\":-1,\"consume\":-1,\"kandian\":-1,\"subscribe_time\":-1,\"all\":\"0\"}"
|
|
|
+// "{\"sex\":2,\"mobile_system\":2,\"tag\":8,\"consume\":4,\"kandian\":2,\"subscribe_time\":7,\"all\":\"0\"}"
|
|
|
+
|
|
|
+ Map map = new HashMap<>();
|
|
|
+ map.put("channel_id", channelId);
|
|
|
+ if (!"1".equals(userJson.getAll())) {
|
|
|
+ if (userJson.getKandian() == 1) {
|
|
|
+ map.put("kandian_max", "500");
|
|
|
+ } else if (userJson.getKandian() == 2) {
|
|
|
+ map.put("kandian_max", "2000");
|
|
|
+ } else if (userJson.getKandian() == 3) {
|
|
|
+ map.put("kandian_min", "2000");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (userJson.getSex() != -1) {
|
|
|
+ map.put("sex", userJson.getSex());
|
|
|
+ }
|
|
|
+ if (userJson.getConsume() == 1) {
|
|
|
+ map.put("is_pay", "0");
|
|
|
+ } else if (userJson.getConsume() == 4) {
|
|
|
+ map.put("is_pay", "1");
|
|
|
+ }
|
|
|
+ if (userJson.getTag() != -1) {
|
|
|
+ map.put("tag", userJson.getTag());
|
|
|
+ }
|
|
|
+ if (userJson.getSubscribe_time() != -1) {
|
|
|
+ int subscribeTime = -1;
|
|
|
+ if (userJson.getSubscribe_time() == 6) {
|
|
|
+ subscribeTime = DateUtils.getNow() - 12 * 60 * 60;
|
|
|
+ } else if (userJson.getSubscribe_time() == 7) {
|
|
|
+ subscribeTime = DateUtils.getNow() - 24 * 60 * 60;
|
|
|
+ } else if (userJson.getSubscribe_time() == 8) {
|
|
|
+ subscribeTime = DateUtils.getNow() - 48 * 60 * 60;
|
|
|
+ } else if (userJson.getSubscribe_time() == 9) {
|
|
|
+ subscribeTime = DateUtils.getNow() - 7 * 24 * 60 * 60;
|
|
|
+ } else if (userJson.getSubscribe_time() == 10) {
|
|
|
+ subscribeTime = DateUtils.getNow() - 15 * 24 * 60 * 60;
|
|
|
+ }
|
|
|
+ map.put("subscribe_time", subscribeTime);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ List<User> users = userService.selectListByPushMap(map);
|
|
|
+ return users;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|