浏览代码

fix 活动企业群发消息推送

zoujiajian 3 年之前
父节点
当前提交
0051493592

+ 2 - 0
netflix-dao/src/main/java/com/cyksj/mapper/corp/CorpUserFollowRelationMapper.java

@@ -16,4 +16,6 @@ public interface CorpUserFollowRelationMapper extends BaseMapper<CorpUserFollowR
 	String selectCorpCustomers(@Param("unionid") String unionid, @Param("wxCorpId") Long wxCorpId);
 
 	List<CorpUserFollowRelationDto> selectCorpUserFollowRelationByTagIds(@Param("list") List<String> tagIds, @Param("wxCorpId") Long wxCorpId, @Param("followIds") List<String> followIds);
+
+	List<CorpUserFollowRelationDto> selectCorpUserFollowRelationB(@Param("wxCorpId") Long wxCorpId, @Param("followIds") List<String> service_follow_ids);
 }

+ 20 - 0
netflix-dao/src/main/java/com/cyksj/model/request/CorpActiveBulkMsg.java

@@ -0,0 +1,20 @@
+package com.cyksj.model.request;
+
+import lombok.Getter;
+import lombok.Setter;
+
+/*
+ *项目名: netflix
+ *文件名: CorpActiveBulkMsg
+ *创建者: JavaZou
+ *创建时间:2023/8/28 16:51
+ */
+@Getter
+@Setter
+public class CorpActiveBulkMsg {
+	private String content;
+
+	private String img;
+
+	private Long wxCorpId;
+}

+ 19 - 0
netflix-dao/src/main/resources/mapper/CorpUserFollowRelationMapper.xml

@@ -26,6 +26,7 @@
         left join `corp_user_auth` ca on ca.external_userid = cufr.corp_user_id
         left join `corp_user` cu on cu.id = ca.corp_user_id
         where cufr.wx_corp_id = #{wxCorpId} and cu.user_id != 0
+        and ca.wx_corp_id = #{wxCorpId}
         <if test="followIds != null and followIds.size() > 0">
             and cufr.follow_id in
             <foreach collection="followIds" item="item" open="(" separator="," close=")">
@@ -34,4 +35,22 @@
         </if>
         group by cufr.corp_user_id
     </select>
+
+    <select id="selectCorpUserFollowRelationB" resultType="com.cyksj.model.dto.CorpUserFollowRelationDto">
+        select cufr.corp_user_id,
+        any_value(cufr.follow_id) as follow_id,
+        any_value(cu.user_id) as user_id
+        from `corp_user_follow_relation` cufr left join `corp_user_auth` ca on ca.external_userid = cufr.corp_user_id
+        left join `corp_user` cu on cu.id = ca.corp_user_id
+        where cufr.wx_corp_id = #{wxCorpId} and cu.user_id != 0
+        and ca.wx_corp_id = #{wxCorpId}
+<!--        <if test="followIds != null and followIds.size() > 0">-->
+<!--            and cufr.follow_id in-->
+<!--            <foreach collection="followIds" item="item" open="(" separator="," close=")">-->
+<!--                #{item}-->
+<!--            </foreach>-->
+<!--        </if>-->
+        and cufr.follow_id = 'NianFeng'
+        group by cufr.corp_user_id
+    </select>
 </mapper>

+ 3 - 0
netflix-service/src/main/java/com/cyksj/service/corp/CorpMsgBulkTaskService.java

@@ -3,6 +3,7 @@ package com.cyksj.service.corp;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.cyksj.model.entity.CorpMsgBulkTask;
 import com.cyksj.model.entity.CorpTag;
+import com.cyksj.model.request.CorpActiveBulkMsg;
 
 import java.util.List;
 import java.util.Map;
@@ -21,4 +22,6 @@ public interface CorpMsgBulkTaskService extends IService<CorpMsgBulkTask> {
 	Map<String, List<CorpTag>> getTagDetail(Long id) throws Exception;
 
 	void executeDynamicRuleTagTask(Long tagId) throws Exception;
+
+	void sendActiveCorpBulkMsg(CorpActiveBulkMsg msg);
 }

+ 61 - 0
netflix-service/src/main/java/com/cyksj/service/corp/impl/CorpMsgBulkTaskServiceImpl.java

@@ -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) {
+			}
+		});
+	}
+
 	/**
 	 * 创建企业群发
 	 */

+ 1 - 1
netflix-web/src/main/java/com/cyksj/web/controller/coupon/CouponFrontController.java

@@ -327,7 +327,7 @@ public class CouponFrontController {
 		}
 		List<CouponView> couponViews = beanSearcher.searchAll(CouponView.class, MapUtils.builder()
 				.field(CouponView::getId, couponIds).op(Operator.InList)
-				.orderBy(CouponView ::getId).desc()
+				.orderBy(CouponView::getId).desc()
 				.build());
 		return GatewayResponse.SUCCESS.newBuilder().toResult(couponViews);
 	}

+ 10 - 0
netflix-web/src/main/java/com/cyksj/web/controller/manage/corp/CorpMsgBulkTaskController.java

@@ -16,6 +16,7 @@ import com.cyksj.model.dto.CornMetaDto;
 import com.cyksj.model.entity.CorpMsgBulkTask;
 import com.cyksj.model.entity.CorpTag;
 import com.cyksj.model.excel.ExcelCorpMsgBulkTaskSendRecordData;
+import com.cyksj.model.request.CorpActiveBulkMsg;
 import com.cyksj.model.request.corp.Attachments;
 import com.cyksj.model.views.CorpMsgBulkTaskCorpFollowSendRecordView;
 import com.cyksj.model.views.CorpMsgBulkTaskSendRecordView;
@@ -234,4 +235,13 @@ public class CorpMsgBulkTaskController {
 		corpMsgBulkTaskService.executeDynamicRuleTagTask(tagId);
 		return GatewayResponse.SUCCESS.newBuilder().toResult();
 	}
+
+	/**
+	 * 群发任务通知
+	 */
+	@PostMapping("/send/active/corpBulkMsg")
+	public Result<String> sendActiveCorpBulkMsg(@RequestBody CorpActiveBulkMsg msg) {
+		corpMsgBulkTaskService.sendActiveCorpBulkMsg(msg);
+		return GatewayResponse.SUCCESS.newBuilder().toResult();
+	}
 }