|
@@ -1,17 +1,25 @@
|
|
|
package org.jeecg.modules.okki.wechatinnergroup.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
+import org.jeecg.common.util.FastJsonUtil;
|
|
|
import org.jeecg.common.util.ThreadPoolUtil;
|
|
|
+import org.jeecg.modules.okki.site.entity.OkkiSite;
|
|
|
+import org.jeecg.modules.okki.site.service.IOkkiSiteService;
|
|
|
import org.jeecg.modules.okki.utils.HttpClientUtils;
|
|
|
import org.jeecg.modules.okki.wechatgroup.dto.WechatInnerGroupMsgRespDto;
|
|
|
+import org.jeecg.modules.okki.wechatinnergroup.dto.GroupMsgResult;
|
|
|
import org.jeecg.modules.okki.wechatinnergroup.entity.OkkiShopWechatInnerGroupMsg;
|
|
|
import org.jeecg.modules.okki.wechatinnergroup.mapper.OkkiShopWechatInnerGroupMsgMapper;
|
|
|
import org.jeecg.modules.okki.wechatinnergroup.service.IOkkiShopWechatInnerGroupMsgService;
|
|
|
+import org.jeecg.modules.okki.wechatinnergroup.service.WechatInnerGroupMongodbRepository;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.data.mongodb.core.aggregation.AggregationResults;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
@@ -36,6 +44,12 @@ public class OkkiShopWechatInnerGroupMsgServiceImpl extends ServiceImpl<OkkiShop
|
|
|
@Resource
|
|
|
private OkkiShopWechatInnerGroupMsgMapper okkiShopWechatInnerGroupMsgMapper;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private WechatInnerGroupMongodbRepository wechatInnerGroupMongodbRepository;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private IOkkiSiteService okkiSiteService;
|
|
|
+
|
|
|
|
|
|
* 获取站点信息
|
|
|
*
|
|
@@ -43,7 +57,7 @@ public class OkkiShopWechatInnerGroupMsgServiceImpl extends ServiceImpl<OkkiShop
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public void getSiteWechatInnerMsgMaxSeq(String siteId) {
|
|
|
+ public void getSiteWechatInnerMsgMaxSeqByMysql(String siteId) {
|
|
|
List<OkkiShopWechatInnerGroupMsg> shopWechatInnerGroupMsgs = okkiShopWechatInnerGroupMsgMapper.getSiteWechatInnerMsgList(siteId);
|
|
|
log.info("一共有:{}个站点,需要【企业微信-内部群】消息", shopWechatInnerGroupMsgs.size());
|
|
|
for (int i = 0; i < shopWechatInnerGroupMsgs.size(); i++) {
|
|
@@ -52,7 +66,35 @@ public class OkkiShopWechatInnerGroupMsgServiceImpl extends ServiceImpl<OkkiShop
|
|
|
OkkiShopWechatInnerGroupMsg okkiShopWechatInnerGroupMsg = shopWechatInnerGroupMsgs.get(finalI);
|
|
|
int maxSeq = okkiShopWechatInnerGroupMsg.getSeq() == 0 ? 1 : okkiShopWechatInnerGroupMsg.getSeq();
|
|
|
log.info("开始处理第{}个,站点ID为:{},seq为:{},【企业微信-内部群】消息", finalI + 1, okkiShopWechatInnerGroupMsg.getSiteId(), maxSeq);
|
|
|
- saveWechatInnerGroupMsg(String.valueOf(okkiShopWechatInnerGroupMsg.getSiteId()), maxSeq);
|
|
|
+ saveWechatInnerGroupMsg(String.valueOf(okkiShopWechatInnerGroupMsg.getSiteId()), maxSeq,"mysql");
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getSiteWechatInnerMsgMaxSeqByMongodb(String siteId) {
|
|
|
+ QueryWrapper<OkkiSite> queryWrapper = new QueryWrapper<>();
|
|
|
+ if(StringUtils.isNotBlank(siteId)){
|
|
|
+ queryWrapper.eq("site_id",siteId);
|
|
|
+ }
|
|
|
+ queryWrapper.eq("del_flag",0);
|
|
|
+ List<OkkiSite> okkiSites = okkiSiteService.list(queryWrapper);
|
|
|
+
|
|
|
+ log.info("一共有:{}个站点,需要【企业微信-内部群】消息", okkiSites.size());
|
|
|
+ for (int i = 0; i < okkiSites.size(); i++) {
|
|
|
+ int finalI = i;
|
|
|
+ ThreadPoolUtil.execute(() -> {
|
|
|
+ AggregationResults<GroupMsgResult> aggregationResults = wechatInnerGroupMongodbRepository.findMaxSeqBySiteId(Integer.valueOf(okkiSites.get(finalI).getSiteId()));
|
|
|
+ log.info("aggregationResults:{}",FastJsonUtil.toJSONString(aggregationResults));
|
|
|
+
|
|
|
+ long maxSeq = 1;
|
|
|
+ if(!CollectionUtil.isEmpty(aggregationResults)){
|
|
|
+ GroupMsgResult groupMsgResult = aggregationResults.getMappedResults().get(0);
|
|
|
+ maxSeq = groupMsgResult.getMaxSeq();
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("开始处理第{}个,站点ID为:{},seq为:{},【企业微信-内部群】消息", finalI + 1, okkiSites.get(finalI).getSiteId(), maxSeq);
|
|
|
+ saveWechatInnerGroupMsg(okkiSites.get(finalI).getSiteId(), Math.toIntExact(maxSeq),"mongodb");
|
|
|
});
|
|
|
}
|
|
|
}
|
|
@@ -63,8 +105,9 @@ public class OkkiShopWechatInnerGroupMsgServiceImpl extends ServiceImpl<OkkiShop
|
|
|
* @param siteId
|
|
|
* @param minSeq
|
|
|
*/
|
|
|
- public void saveWechatInnerGroupMsg(String siteId, Integer minSeq) {
|
|
|
+ public void saveWechatInnerGroupMsg(String siteId, Integer minSeq,String type) {
|
|
|
List<OkkiShopWechatInnerGroupMsg> wechatInnerGroupMsgList = sendWechatInnerGroupMsgRequest(siteId, minSeq);
|
|
|
+ log.info("获取站点ID为:{},seq为:{},【企业微信-内部群】消息 条数一共有:{}", siteId, minSeq, wechatInnerGroupMsgList.size());
|
|
|
List<OkkiShopWechatInnerGroupMsg> shopWechatInnerGroupMsgs = new ArrayList<>();
|
|
|
if (!CollectionUtils.isEmpty(wechatInnerGroupMsgList)) {
|
|
|
wechatInnerGroupMsgList.forEach(c -> {
|
|
@@ -84,11 +127,16 @@ public class OkkiShopWechatInnerGroupMsgServiceImpl extends ServiceImpl<OkkiShop
|
|
|
shopWechatInnerGroupMsg.setUpdateTime(c.getUpdateTime());
|
|
|
shopWechatInnerGroupMsgs.add(shopWechatInnerGroupMsg);
|
|
|
});
|
|
|
- this.saveBatch(shopWechatInnerGroupMsgs);
|
|
|
+
|
|
|
+ if("mongodb".equals(type)){
|
|
|
+ wechatInnerGroupMongodbRepository.saveAll(shopWechatInnerGroupMsgs);
|
|
|
+ }else{
|
|
|
+ this.saveBatch(shopWechatInnerGroupMsgs);
|
|
|
+ }
|
|
|
|
|
|
|
|
|
OkkiShopWechatInnerGroupMsg lastWechatInnerGroupMsg = shopWechatInnerGroupMsgs.get(shopWechatInnerGroupMsgs.size() - 1);
|
|
|
- saveWechatInnerGroupMsg(siteId, lastWechatInnerGroupMsg.getSeq());
|
|
|
+ saveWechatInnerGroupMsg(siteId, lastWechatInnerGroupMsg.getSeq(),type);
|
|
|
}
|
|
|
}
|
|
|
|