|
|
@@ -21,6 +21,7 @@ import com.cyksj.mapper.manage.coupon.CouponMapper;
|
|
|
import com.cyksj.model.dto.CornMetaDto;
|
|
|
import com.cyksj.model.dto.CorpUserFollowRelationDto;
|
|
|
import com.cyksj.model.entity.*;
|
|
|
+import com.cyksj.model.request.CorpActiveBulkMsg;
|
|
|
import com.cyksj.model.request.corp.Attachments;
|
|
|
import com.cyksj.model.request.corp.CorpMsgTemplate;
|
|
|
import com.cyksj.model.request.corp.Text;
|
|
|
@@ -161,6 +162,66 @@ public class CorpMsgBulkTaskServiceImpl extends ServiceImpl<CorpMsgBulkTaskMappe
|
|
|
XxlJobResult xxlJobResult = XxlJobUtil.executeMarkDynamicRuleTagJob(XxlJobInfo.getExecuteTaskInstance(taskId, String.valueOf(tagId)).toString());
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void sendActiveCorpBulkMsg(CorpActiveBulkMsg msg) {
|
|
|
+ String content = msg.getContent();
|
|
|
+ String img = msg.getImg();
|
|
|
+ Long wxCorpId = Optional.ofNullable(msg.getWxCorpId()).orElse(2l);
|
|
|
+ WxCorpApp wxCorpApp = wxCorpAppMapper.selectById(wxCorpId);
|
|
|
+ Assert.notNull(wxCorpApp, "企业微信未配置");
|
|
|
+ //客服集合
|
|
|
+ List<String> service_follow_ids = null;
|
|
|
+ SysConfig serviceConfig = sysConfigService.getOne(Wrappers.lambdaQuery(SysConfig.class)
|
|
|
+ .eq(SysConfig::getSysKey, Constant.CORP_SERVICE_FOLLOWS_KEY).last("limit 1"));
|
|
|
+ if (serviceConfig != null && StrUtil.isNotBlank(serviceConfig.getSysValue())) {
|
|
|
+ try {
|
|
|
+ service_follow_ids = Jsons.parseList(serviceConfig.getSysValue(), String.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<CorpUserFollowRelationDto> corpUserFollowRelations = corpUserFollowRelationMapper.selectCorpUserFollowRelationB(wxCorpApp.getId(), service_follow_ids);
|
|
|
+ //将成员与客户相同关联聚合
|
|
|
+ Map<String, List<CorpUserFollowRelationDto>> collect = corpUserFollowRelations.stream().collect(Collectors.groupingBy(CorpUserFollowRelationDto::getFollowId));
|
|
|
+ //附件
|
|
|
+ LinkedList<Attachments> attachments = null;
|
|
|
+ if (StrUtil.isNotEmpty(img)) {
|
|
|
+ attachments = new LinkedList<>();
|
|
|
+ Attachments attachment = new Attachments();
|
|
|
+ Attachments.Image image = new Attachments.Image();
|
|
|
+ image.setPicUrl(img);
|
|
|
+ attachment.setImage(image);
|
|
|
+ attachments.add(corpService.updateMaterial(attachment, wxCorpApp.getCorpId(), 1));
|
|
|
+ }
|
|
|
+ CorpMsgTemplate corpMsgTemplate = new CorpMsgTemplate();
|
|
|
+ corpMsgTemplate.setAttachments(attachments);
|
|
|
+ corpMsgTemplate.setChatType("single");
|
|
|
+ if (StringUtils.isNotBlank(content)) {
|
|
|
+ Text text = new Text();
|
|
|
+ text.setContent(content);
|
|
|
+ corpMsgTemplate.setText(text);
|
|
|
+ }
|
|
|
+ collect.forEach((followId, val) -> {
|
|
|
+ try {
|
|
|
+ List<String> extendIds = new ArrayList<>(val.size());
|
|
|
+ List<Long> userIds = null;
|
|
|
+ for (CorpUserFollowRelationDto dto : val) {
|
|
|
+ extendIds.add(dto.getCorpUserId());
|
|
|
+ if (userIds != null && dto.getUserId() != null) {
|
|
|
+ userIds.add(dto.getUserId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<List<String>> split = CollectionUtil.split(extendIds, LIMIT);
|
|
|
+ for (List<String> corpUserIdList : split) {
|
|
|
+ corpMsgTemplate.setSender(followId);
|
|
|
+ corpMsgTemplate.setExternalUserid(corpUserIdList);
|
|
|
+ CorpMsgTemplateAddResult result = corpOps.addMsgTemplate(wxCorpApp.getCorpId(), corpMsgTemplate);
|
|
|
+ System.out.println(result.getErrMsg());
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 创建企业群发
|
|
|
*/
|