Przeglądaj źródła

企业微信用户消费范围

zoujiajian 2 lat temu
rodzic
commit
40d6c33399

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

@@ -15,9 +15,9 @@ 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, @Param("userScope") Integer userScope);
+	List<CorpUserFollowRelationDto> selectCorpUserFollowRelationByTagIds(@Param("list") List<String> tagIds, @Param("wxCorpId") Long wxCorpId, @Param("followIds") List<String> followIds, @Param("userScope") Integer userScope, @Param("consumerScope") Integer consumerScope);
 
 	List<CorpUserFollowRelationDto> selectCorpUserFollowRelation(@Param("wxCorpId") Long wxCorpId, @Param("followIds") List<String> service_follow_ids);
 
-	List<CorpUserFollowRelationDto> selectCorpUserNotUnderTagIds(@Param("list") List<String> tagIds, @Param("wxCorpId") Long wxCorpId, @Param("followIds") List<String> followIds, @Param("userScope") Integer userScope);
+	List<CorpUserFollowRelationDto> selectCorpUserNotUnderTagIds(@Param("list") List<String> tagIds, @Param("wxCorpId") Long wxCorpId, @Param("followIds") List<String> followIds, @Param("userScope") Integer userScope, @Param("consumerScope") Integer consumerScope);
 }

+ 6 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/CorpMsgBulkTask.java

@@ -142,6 +142,12 @@ public class CorpMsgBulkTask implements Serializable {
 	 */
 	private Integer sendScope;
 
+	/**
+	 * 消费范围
+	 * 1全部 2消费 3未消费
+	 */
+	private Integer consumerScope;
+
 	private Boolean deleted;
 
 	/**

+ 30 - 8
netflix-dao/src/main/resources/mapper/CorpUserFollowRelationMapper.xml

@@ -26,14 +26,25 @@
         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}
-          <choose>
-              <when test="userScope == 2">
-                  and cu.user_id != 0
-              </when>
-              <when test="userScope == 3">
-                  and cu.user_id = 0
-              </when>
-          </choose>
+        <choose>
+            <when test="userScope == 2">
+                and cu.user_id != 0
+            </when>
+            <when test="userScope == 3">
+                and cu.user_id = 0
+            </when>
+        </choose>
+        <choose>
+            <when test="consumerScope == 2">
+                and exists (select id from order_don o where o.user_id != 0 and o.user_id = cu.user_id and status not in
+                ('close','noPayment','refund') limit 1)
+            </when>
+            <when test="consumerScope == 3">
+                and not exists (select id from order_don o where o.user_id != 0 and o.user_id = cu.user_id and status
+                not in
+                ('close','noPayment','refund') limit 1)
+            </when>
+        </choose>
         and ca.wx_corp_id = #{wxCorpId}
         <if test="followIds != null and followIds.size() > 0">
             and cufr.follow_id in
@@ -75,6 +86,17 @@
                 and cu.user_id = 0
             </when>
         </choose>
+        <choose>
+            <when test="consumerScope == 2">
+                and exists (select id from order_don o where o.user_id != 0 and o.user_id = cu.user_id and status not in
+                ('close','noPayment','refund') limit 1)
+            </when>
+            <when test="consumerScope == 3">
+                and not exists (select id from order_don o where o.user_id != 0 and o.user_id = cu.user_id and status
+                not in
+                ('close','noPayment','refund') limit 1)
+            </when>
+        </choose>
         inner join corp_user_follow_relation cufr on cufr.corp_user_id = ca.external_userid
         and cufr.wx_corp_id = #{wxCorpId}
         <if test="followIds != null and followIds.size() > 0">

+ 19 - 13
netflix-service/src/main/java/com/cyksj/service/corp/impl/CorpMsgBulkTaskServiceImpl.java

@@ -113,6 +113,9 @@ public class CorpMsgBulkTaskServiceImpl extends ServiceImpl<CorpMsgBulkTaskMappe
 				throw BusinessRuntimeException.getInstance("标签筛选发送范围下,标签不能为空");
 			}
 		});
+		if (StrUtil.isAllEmpty(corpMsgBulkTask.getText(), corpMsgBulkTask.getAttachmentsStr())) {
+			throw BusinessRuntimeException.getInstance("群发消息文本和附件不能同时为空");
+		}
 		this.saveOrUpdate(corpMsgBulkTask);
 		//处理群发任务和标签的关系
 		handleTaskTagRelation(corpMsgBulkTask);
@@ -258,13 +261,16 @@ public class CorpMsgBulkTaskServiceImpl extends ServiceImpl<CorpMsgBulkTaskMappe
 		Integer userScope = corpMsgBulkTask.getUserScope();
 
 		Integer sendScope = corpMsgBulkTask.getSendScope();
+
+		Integer consumerScope = corpMsgBulkTask.getConsumerScope();
+
 		List<CorpUserFollowRelationDto> corpUserFollowRelations = null;
 		//全部用户
 		if (sendScope == 1) {
 			//此时tagIds是 需要过滤的用户标签
-			corpUserFollowRelations = corpUserFollowRelationMapper.selectCorpUserNotUnderTagIds(tagIds, wxCorpApp.getId(), service_follow_ids, userScope);
+			corpUserFollowRelations = corpUserFollowRelationMapper.selectCorpUserNotUnderTagIds(tagIds, wxCorpApp.getId(), service_follow_ids, userScope, consumerScope);
 		} else {
-			corpUserFollowRelations = corpUserFollowRelationMapper.selectCorpUserFollowRelationByTagIds(tagIds, wxCorpApp.getId(), service_follow_ids, userScope);
+			corpUserFollowRelations = corpUserFollowRelationMapper.selectCorpUserFollowRelationByTagIds(tagIds, wxCorpApp.getId(), service_follow_ids, userScope, consumerScope);
 		}
 		//将成员与客户相同关联聚合
 		Map<String, List<CorpUserFollowRelationDto>> userRelationMap = corpUserFollowRelations.stream().collect(Collectors.groupingBy(CorpUserFollowRelationDto::getFollowId));
@@ -429,17 +435,17 @@ public class CorpMsgBulkTaskServiceImpl extends ServiceImpl<CorpMsgBulkTaskMappe
 			}
 		}
 
-		if (CollectionUtil.isNotEmpty(failList)) {
-			List<CorpUserSendRecord> corpUserSendRecords = corpMsgBulkTaskMapper.getsSuccessCorpUser(failList);
-			if (CollectionUtil.isNotEmpty(corpUserSendRecords)) {
-				corpUserSendRecords.forEach(corpUserSendRecord -> {
-					log.info("失败群发记录大小:{}", corpUserSendRecords.size());
-					corpUserSendRecord.setCorpMsgRecordId(corpMsgBulkTaskRecord.getId());
-					corpMsgBulkTaskRecord.setTaskId(corpMsgBulkTaskRecord.getTaskId());
-					corpUserSendRecordService.saveBatch(corpUserSendRecords);
-				});
-			}
-		}
+//		if (CollectionUtil.isNotEmpty(failList)) {
+//			List<CorpUserSendRecord> corpUserSendRecords = corpMsgBulkTaskMapper.getsSuccessCorpUser(failList);
+//			if (CollectionUtil.isNotEmpty(corpUserSendRecords)) {
+//				corpUserSendRecords.forEach(corpUserSendRecord -> {
+//					log.info("失败群发记录大小:{}", corpUserSendRecords.size());
+//					corpUserSendRecord.setCorpMsgRecordId(corpMsgBulkTaskRecord.getId());
+//					corpMsgBulkTaskRecord.setTaskId(corpMsgBulkTaskRecord.getTaskId());
+//					corpUserSendRecordService.saveBatch(corpUserSendRecords);
+//				});
+//			}
+//		}
 	}
 
 	/**