|
@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSON;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.fs.app.service.IpadSendServer;
|
|
import com.fs.app.service.IpadSendServer;
|
|
import com.fs.common.core.redis.RedisCacheT;
|
|
import com.fs.common.core.redis.RedisCacheT;
|
|
|
|
+import com.fs.common.utils.DateUtils;
|
|
import com.fs.common.utils.PubFun;
|
|
import com.fs.common.utils.PubFun;
|
|
import com.fs.company.service.ICompanyMiniappService;
|
|
import com.fs.company.service.ICompanyMiniappService;
|
|
import com.fs.course.config.CourseConfig;
|
|
import com.fs.course.config.CourseConfig;
|
|
@@ -12,8 +13,12 @@ import com.fs.course.domain.FsCoursePlaySourceConfig;
|
|
import com.fs.course.service.IFsCoursePlaySourceConfigService;
|
|
import com.fs.course.service.IFsCoursePlaySourceConfigService;
|
|
import com.fs.ipad.vo.BaseVo;
|
|
import com.fs.ipad.vo.BaseVo;
|
|
import com.fs.qw.domain.QwIpadServer;
|
|
import com.fs.qw.domain.QwIpadServer;
|
|
|
|
+import com.fs.qw.domain.QwPushCount;
|
|
|
|
+import com.fs.qw.domain.QwRestrictionPushRecord;
|
|
import com.fs.qw.domain.QwUser;
|
|
import com.fs.qw.domain.QwUser;
|
|
import com.fs.qw.mapper.QwIpadServerMapper;
|
|
import com.fs.qw.mapper.QwIpadServerMapper;
|
|
|
|
+import com.fs.qw.mapper.QwPushCountMapper;
|
|
|
|
+import com.fs.qw.mapper.QwRestrictionPushRecordMapper;
|
|
import com.fs.qw.mapper.QwUserMapper;
|
|
import com.fs.qw.mapper.QwUserMapper;
|
|
import com.fs.qw.service.impl.AsyncSopTestService;
|
|
import com.fs.qw.service.impl.AsyncSopTestService;
|
|
import com.fs.qw.vo.QwSopCourseFinishTempSetting;
|
|
import com.fs.qw.vo.QwSopCourseFinishTempSetting;
|
|
@@ -55,6 +60,8 @@ public class SendMsg {
|
|
private final AsyncSopTestService asyncSopTestService;
|
|
private final AsyncSopTestService asyncSopTestService;
|
|
private final ICompanyMiniappService companyMiniappService;
|
|
private final ICompanyMiniappService companyMiniappService;
|
|
private final IFsCoursePlaySourceConfigService fsCoursePlaySourceConfigService;
|
|
private final IFsCoursePlaySourceConfigService fsCoursePlaySourceConfigService;
|
|
|
|
+ private final QwPushCountMapper qwPushCountMapper;
|
|
|
|
+ private final QwRestrictionPushRecordMapper qwRestrictionPushRecordMapper;
|
|
|
|
|
|
@Value("${group-no}")
|
|
@Value("${group-no}")
|
|
private String groupNo;
|
|
private String groupNo;
|
|
@@ -65,7 +72,7 @@ public class SendMsg {
|
|
@Qualifier("customThreadPool")
|
|
@Qualifier("customThreadPool")
|
|
private ThreadPoolTaskExecutor customThreadPool;
|
|
private ThreadPoolTaskExecutor customThreadPool;
|
|
|
|
|
|
- public SendMsg(QwUserMapper qwUserMapper, QwSopLogsMapper qwSopLogsMapper, IpadSendServer sendServer, SysConfigMapper sysConfigMapper, IQwSopLogsService qwSopLogsService, QwIpadServerMapper qwIpadServerMapper, RedisCacheT<Long> redisCache, AsyncSopTestService asyncSopTestService, ICompanyMiniappService companyMiniappService, IFsCoursePlaySourceConfigService fsCoursePlaySourceConfigService) {
|
|
|
|
|
|
+ public SendMsg(QwUserMapper qwUserMapper, QwSopLogsMapper qwSopLogsMapper, IpadSendServer sendServer, SysConfigMapper sysConfigMapper, IQwSopLogsService qwSopLogsService, QwIpadServerMapper qwIpadServerMapper, RedisCacheT<Long> redisCache, AsyncSopTestService asyncSopTestService, ICompanyMiniappService companyMiniappService, IFsCoursePlaySourceConfigService fsCoursePlaySourceConfigService, QwPushCountMapper qwPushCountMapper, QwRestrictionPushRecordMapper qwRestrictionPushRecordMapper) {
|
|
this.qwUserMapper = qwUserMapper;
|
|
this.qwUserMapper = qwUserMapper;
|
|
this.qwSopLogsMapper = qwSopLogsMapper;
|
|
this.qwSopLogsMapper = qwSopLogsMapper;
|
|
this.sendServer = sendServer;
|
|
this.sendServer = sendServer;
|
|
@@ -76,6 +83,8 @@ public class SendMsg {
|
|
this.asyncSopTestService = asyncSopTestService;
|
|
this.asyncSopTestService = asyncSopTestService;
|
|
this.companyMiniappService = companyMiniappService;
|
|
this.companyMiniappService = companyMiniappService;
|
|
this.fsCoursePlaySourceConfigService = fsCoursePlaySourceConfigService;
|
|
this.fsCoursePlaySourceConfigService = fsCoursePlaySourceConfigService;
|
|
|
|
+ this.qwPushCountMapper = qwPushCountMapper;
|
|
|
|
+ this.qwRestrictionPushRecordMapper = qwRestrictionPushRecordMapper;
|
|
}
|
|
}
|
|
private List<QwUser> getQwUserList() {
|
|
private List<QwUser> getQwUserList() {
|
|
if (qwUserList.isEmpty()) {
|
|
if (qwUserList.isEmpty()) {
|
|
@@ -191,27 +200,67 @@ public class SendMsg {
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
redisCache.setCacheObject(key, System.currentTimeMillis(), 24, TimeUnit.HOURS);
|
|
redisCache.setCacheObject(key, System.currentTimeMillis(), 24, TimeUnit.HOURS);
|
|
|
|
+ List<QwPushCount> pushCountList = qwPushCountMapper.selectQwPushCountLists();
|
|
|
|
+ Map<Integer, List<QwPushCount>> pushMap = pushCountList.stream().collect(Collectors.groupingBy(QwPushCount::getType));
|
|
// 循环发送消息里面的每一条消息
|
|
// 循环发送消息里面的每一条消息
|
|
for (QwSopCourseFinishTempSetting.Setting content : setting.getSetting()) {
|
|
for (QwSopCourseFinishTempSetting.Setting content : setting.getSetting()) {
|
|
long start4 = System.currentTimeMillis();
|
|
long start4 = System.currentTimeMillis();
|
|
- // 发送
|
|
|
|
- sendServer.send(content, user, qwSopLogs, miniMap, parentVo);
|
|
|
|
- long end4 = System.currentTimeMillis();
|
|
|
|
- log.info("请求pad发送完成:{}, {}, 时长4:{}", user.getQwUserName(), qwSopLogs.getId(), end4 - start4);
|
|
|
|
- if(content.getSendStatus() == 2 && ("请求失败:消息发送过于频繁,请稍后再试".equals(content.getSendRemarks()) || "请求失败:请求频率异常".equals(content.getSendRemarks()))){
|
|
|
|
- QwUser update = new QwUser();
|
|
|
|
- update.setRemark("请求频率异常,暂停发送,三小时后恢复继续发送");
|
|
|
|
- update.setUpdateTime(new Date());
|
|
|
|
- qwUserMapper.update(update, new QueryWrapper<QwUser>().eq("id", user.getId()));
|
|
|
|
- redisCache.setCacheObject("qw:user:id:" + user.getId(), user.getId(), 3, TimeUnit.HOURS);
|
|
|
|
- return;
|
|
|
|
|
|
+ //判断当前销售推送客户消息限制
|
|
|
|
+ Long qwUserId = qwUser.getId();//销售的Id
|
|
|
|
+ Integer type = Integer.valueOf(content.getContentType());//发送消息的类型
|
|
|
|
+ Long customerId = qwSopLogs.getExternalId();//客户ID
|
|
|
|
+ Long companyId = qwSopLogs.getCompanyId();//公司ID
|
|
|
|
+ Integer pushCount = -99;
|
|
|
|
+ if(pushMap.containsKey(type)){
|
|
|
|
+ List<QwPushCount> qwPushCounts = pushMap.get(type);
|
|
|
|
+ Optional<QwPushCount> optional = qwPushCounts.stream().filter(e -> Objects.equals(e.getCompanyId(), companyId)).findFirst();
|
|
|
|
+ if(optional.isPresent()){
|
|
|
|
+ pushCount = optional.get().getPushCount();
|
|
|
|
+ }else{
|
|
|
|
+ Optional<QwPushCount> nullCount = qwPushCounts.stream().filter(e -> e.getCompanyId() == null).findFirst();
|
|
|
|
+ if(nullCount.isPresent()){
|
|
|
|
+ pushCount = nullCount.get().getPushCount();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- try {
|
|
|
|
- int delay = ThreadLocalRandom.current().nextInt(300, 1000);
|
|
|
|
- log.debug("pad发送消息等待:{}ms", delay);
|
|
|
|
- Thread.sleep(delay);
|
|
|
|
- } catch (InterruptedException e) {
|
|
|
|
- log.error("线程等待错误!");
|
|
|
|
|
|
+ //查询是否有设置限制客服推送消息次数
|
|
|
|
+// Integer pushCount=pushCountMap.containsKey(String.valueOf(companyId)) ? pushCountMap.get(String.valueOf(companyId)): pushCountMap.getOrDefault(String.valueOf(type), -99);
|
|
|
|
+ int salesPushCustomerMessageCount = qwRestrictionPushRecordMapper.selectQwRestrictionPushRecord(qwUserId, customerId, type, DateUtils.toStartTime(), DateUtils.toEndTime());
|
|
|
|
+ if (pushCount != -99 && salesPushCustomerMessageCount >= pushCount) {
|
|
|
|
+ content.setSendStatus(2);//设置发送失败状态
|
|
|
|
+ content.setSendRemarks("发送次数达到上限");
|
|
|
|
+ } else {
|
|
|
|
+ // 发送
|
|
|
|
+ sendServer.send(content, user, qwSopLogs, miniMap, parentVo);
|
|
|
|
+ //判断销售推送成功:保存记录
|
|
|
|
+ if (content.getSendStatus() != 2) {
|
|
|
|
+ QwRestrictionPushRecord qrpr = new QwRestrictionPushRecord();
|
|
|
|
+ qrpr.setType(type);
|
|
|
|
+ qrpr.setQwUserId(qwUserId);
|
|
|
|
+ qrpr.setQwExternalId(customerId);
|
|
|
|
+ qrpr.setCompanyId(companyId);
|
|
|
|
+ qrpr.setStatus(1);
|
|
|
|
+ qrpr.setCreateTime(DateUtils.getTime());
|
|
|
|
+ qrpr.setTime(System.currentTimeMillis());
|
|
|
|
+ qwRestrictionPushRecordMapper.insert(qrpr);
|
|
|
|
+ }
|
|
|
|
+ long end4 = System.currentTimeMillis();
|
|
|
|
+ log.info("请求pad发送完成:{}, {}, 时长4:{}", user.getQwUserName(), qwSopLogs.getId(), end4 - start4);
|
|
|
|
+ if(content.getSendStatus() == 2 && ("请求失败:消息发送过于频繁,请稍后再试".equals(content.getSendRemarks()) || "请求失败:请求频率异常".equals(content.getSendRemarks()))){
|
|
|
|
+ QwUser update = new QwUser();
|
|
|
|
+ update.setRemark("请求频率异常,暂停发送,三小时后恢复继续发送");
|
|
|
|
+ update.setUpdateTime(new Date());
|
|
|
|
+ qwUserMapper.update(update, new QueryWrapper<QwUser>().eq("id", user.getId()));
|
|
|
|
+ redisCache.setCacheObject("qw:user:id:" + user.getId(), user.getId(), 3, TimeUnit.HOURS);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ try {
|
|
|
|
+ int delay = ThreadLocalRandom.current().nextInt(300, 1000);
|
|
|
|
+ log.debug("pad发送消息等待:{}ms", delay);
|
|
|
|
+ Thread.sleep(delay);
|
|
|
|
+ } catch (InterruptedException e) {
|
|
|
|
+ log.error("线程等待错误!");
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// 推送 APP
|
|
// 推送 APP
|