Browse Source

fix 标签客户数量

zoujiajian 3 years ago
parent
commit
7b0670c9eb

+ 1 - 1
netflix-dao/src/main/java/com/cyksj/mapper/corp/CorpTagGroupMapper.java

@@ -19,5 +19,5 @@ public interface CorpTagGroupMapper extends BaseMapper<CorpTagGroup> {
 
 	List<CorpTagGroupView> getCorpTagList();
 
-	List<CorpTagBackView> getCorpTagBackView(@Param("groupIds") String[] groupIds, @Param("sort") String sort, @Param("order") String order);
+	List<CorpTagBackView> getCorpTagBackView(@Param("groupIds") String[] groupIds, @Param("sort") String sort, @Param("order") String order, @Param("wxCorpId") Long wxCorpId);
 }

+ 1 - 1
netflix-dao/src/main/java/com/cyksj/mapper/corp/CorpTagMapper.java

@@ -15,7 +15,7 @@ import java.util.List;
  *创建时间:2022/10/13 18:07
  */
 public interface CorpTagMapper extends BaseMapper<CorpTag> {
-	List<CorpTagBackView> getCorpTagBackView(@Param("tagIds") String[] tagIds, @Param("sort") String sort, @Param("order") String order);
+	List<CorpTagBackView> getCorpTagBackView(@Param("tagIds") String[] tagIds, @Param("sort") String sort, @Param("order") String order, @Param("wxCorpId") Long wxCorpId);
 
 	List<String> selectTagsIdByGroupId(String groupId);
 

+ 7 - 1
netflix-dao/src/main/resources/mapper/CorpTagGroupMapper.xml

@@ -42,6 +42,9 @@
         from corp_tag_group cg
         left join corp_tag ct on ct.group_id = cg.group_id
         left join corp_user_tag cut on cut.tag_id = ct.tag_id
+        left join corp_user_follow_relation cufr on cufr.id = cut.relation_id
+        left join corp_user_auth cua on cua.external_userid = cufr.corp_user_id
+        left join corp_user cu on cu.id = cua.corp_user_id
         <where>
             <if test="groupIds != null and groupIds.length >0">
                 cg.group_id in
@@ -49,8 +52,11 @@
                     #{item}
                 </foreach>
             </if>
+            and cufr.wx_corp_id = #{wxCorpId}
+            and cua.wx_corp_id = #{wxCorpId}
+            and cu.unionid != ''
         </where>
-        group by cg.id,cg.group_id,cg.group_name)s
+        group by cg.id,cg.group_id,cg.group_name order by cg.id desc)s
         <if test="sort != null">
             order by ${sort} ${order}
         </if>

+ 8 - 2
netflix-dao/src/main/resources/mapper/CorpTagMapper.xml

@@ -17,11 +17,14 @@
         ct.type,
         ct.group_name,
         ct.name as tagName,
-        count(cut.id) as numOfCustomer,
+        count(distinct cu.user_id) as numOfCustomer,
         any_value(ct.update_time) as updateTime,
         ct.rule_name_list_str
         from `corp_tag` ct
         left join corp_user_tag cut on cut.tag_id = ct.tag_id
+        left join corp_user_follow_relation cufr on cufr.id = cut.relation_id
+        left join corp_user_auth cua on cua.external_userid = cufr.corp_user_id
+        left join corp_user cu on cu.id = cua.corp_user_id
         <where>
             <if test="tagIds != null and tagIds.length > 0">
                 ct.id in
@@ -29,8 +32,11 @@
                     #{item}
                 </foreach>
             </if>
+            and cufr.wx_corp_id = #{wxCorpId}
+            and cua.wx_corp_id = #{wxCorpId}
+            and cu.unionid != ''
         </where>
-        group by ct.id, ct.group_name, ct.name, ct.tag_id,ct.group_id,ct.rule_name_list_str) s
+        group by ct.id, ct.group_name, ct.name, ct.tag_id,ct.group_id,ct.rule_name_list_str order by ct.id desc) s
         <if test="sort != null">
             order by ${sort} ${order}
         </if>

+ 3 - 6
netflix-dao/src/main/resources/mapper/CorpUserTagMapper.xml

@@ -6,12 +6,10 @@
     <select id="selectCorpUserDetailByCondition" resultType="com.cyksj.model.views.CorpUserView">
         select * from (select cu.id,
         cu.unionid,
+        any_value(remark) as nickname,
         group_concat(ct.tag_name) as tagNames,
         group_concat(cf.name) as customers,
-        any_value(ct.created_time) as createdTime,
-        u.id as userId,
-        u.nickname,
-        u.headimgurl
+        any_value(ct.created_time) as createdTime
         from (select * from corp_user_tag where
         <choose>
             <when test="groupId!=null and groupId != ''">
@@ -26,8 +24,7 @@
         inner join corp_follow cf on cf.userid = cfr.follow_id and cf.wx_corp_id = #{wxCorpId}
         inner join corp_user_auth cua on cua.external_userid = cfr.corp_user_id and cua.wx_corp_id = #{wxCorpId}
         inner join corp_user cu on cu.id = cua.corp_user_id and cu.unionid != ''
-        inner join user u on u.id = cu.user_id
-        group by cu.id, cu.unionid) s order by s.createdTime desc, s.userId asc
+        group by cu.id, cu.unionid) s order by s.createdTime desc
     </select>
 
     <select id="exportUserTagDetail" resultType="com.cyksj.model.excel.CorpUserTagExcelData">

+ 13 - 2
netflix-service/src/main/java/com/cyksj/service/corp/impl/CorpTagServiceImpl.java

@@ -285,8 +285,9 @@ public class CorpTagServiceImpl implements CorpTagService {
 
 	@Override
 	public List<CorpTagBackView> getCorpTagBackView(Integer type, String[] tagIds, String[] groupIds, String sort, String order) {
+		Long wxCorpId = 2l;
 		if (type == 1) {
-			List<CorpTagBackView> corpTagBackView = corpTagMapper.getCorpTagBackView(tagIds, sort, order);
+			List<CorpTagBackView> corpTagBackView = corpTagMapper.getCorpTagBackView(tagIds, sort, order, wxCorpId);
 			corpTagBackView.forEach(view -> {
 				if (StrUtil.isNotEmpty(view.getRuleNameListStr())) {
 					try {
@@ -297,7 +298,7 @@ public class CorpTagServiceImpl implements CorpTagService {
 			});
 			return corpTagBackView;
 		}
-		return corpTagGroupMapper.getCorpTagBackView(groupIds, sort, order);
+		return corpTagGroupMapper.getCorpTagBackView(groupIds, sort, order, wxCorpId);
 	}
 
 	@Override
@@ -310,6 +311,16 @@ public class CorpTagServiceImpl implements CorpTagService {
 	public Page<CorpUserView> getCorpUserDetail(String tagId, String groupId, Integer start, Integer limit) {
 		Long wxCorpId = 2l;
 		Page<CorpUserView> page = corpUserTagMapper.selectCorpUserDetailByCondition(new Page<>(start, limit), groupId, tagId, wxCorpId);
+		page.getRecords().forEach(data -> {
+			Optional.ofNullable(userMapper.selectOne(Wrappers.lambdaQuery(User.class)
+					.eq(User::getUnionid, data.getUnionId())
+					.last("limit 1")))
+					.ifPresent(user -> {
+						data.setUserId(user.getId());
+						data.setNickname(user.getNickname());
+						data.setHeadimgurl(user.getHeadimgurl());
+					});
+		});
 		return page;
 	}