Prechádzať zdrojové kódy

fix 优化企业微信标签管理列表

zoujiajian 3 rokov pred
rodič
commit
61183937bc

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

@@ -7,6 +7,8 @@ import com.cyksj.model.views.CorpTagBackView;
 import com.cyksj.model.views.CorpTagGroupView;
 import org.apache.ibatis.annotations.Param;
 
+import java.util.Map;
+
 /*
  *项目名: netflix
  *文件名: CorpTagGroupMapper
@@ -19,4 +21,6 @@ public interface CorpTagGroupMapper extends BaseMapper<CorpTagGroup> {
 	Page<CorpTagGroupView> getCorpTagList(@Param("groupName") String groupName, @Param("page") Page<CorpTagGroupView> page);
 
 	Page<CorpTagBackView> getCorpTagBackView(@Param("page") Page<CorpTagBackView> page, @Param("groupIds") String[] groupIds, @Param("sort") String sort, @Param("order") String order, @Param("wxCorpId") Long wxCorpId);
+
+	CorpTagBackView fillCorpGroupTagInfo(@Param("groupId") String groupId, @Param("wxCorpId") Long wxCorpI);
 }

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

@@ -23,4 +23,6 @@ public interface CorpTagMapper extends BaseMapper<CorpTag> {
 	CorpTag getCorpTagById(Long corpTagId);
 
 	CorpTagHeadDataView getCorpTagHeadDataView();
+
+	Integer selectCountOfCustomer(@Param("tagId") String tagId, @Param("wxCorpId") Long wxCorpId);
 }

+ 12 - 17
netflix-dao/src/main/resources/mapper/CorpTagGroupMapper.xml

@@ -41,26 +41,21 @@
         select * from (select cg.id as group_id,
         cg.group_id as groupIdStr,
         cg.group_name,
-        count(distinct ct.id) as tagSize,
-        count(cut.id) as numOfCustomer,
-        any_value(cg.update_time) as updateTime
+        cg.update_time
         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 and cufr.wx_corp_id = #{wxCorpId}
-        left join corp_user_auth cua on cua.external_userid = cufr.corp_user_id and cua.wx_corp_id = #{wxCorpId}
-        left join corp_user cu on cu.id = cua.corp_user_id and cu.unionid != ''
-        <where>
-            <if test="groupIds != null and groupIds.length >0">
-                cg.group_id in
-                <foreach collection="groupIds" item="item" open="(" separator="," close=")">
-                    #{item}
-                </foreach>
-            </if>
-        </where>
-        group by cg.id,cg.group_id,cg.group_name order by cg.id desc)s
+        )s
         <if test="sort != null">
             order by ${sort} ${order}
         </if>
     </select>
+
+    <select id="fillCorpGroupTagInfo" resultType="com.cyksj.model.views.CorpTagBackView">
+        select count(distinct ct.id)        as tagSize,
+               count(distinct corp_user_id) as numOfCustomer
+        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
+        where ct.group_id = #{groupId}
+          and cufr.wx_corp_id = #{wxCorpId}
+    </select>
 </mapper>

+ 7 - 15
netflix-dao/src/main/resources/mapper/CorpTagMapper.xml

@@ -17,23 +17,10 @@
         ct.type,
         ct.group_name,
         ct.name as tagName,
-        count(distinct cu.user_id) as numOfCustomer,
-        any_value(ct.update_time) as updateTime,
+        ct.update_time,
         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 and cufr.wx_corp_id = #{wxCorpId}
-        left join corp_user_auth cua on cua.external_userid = cufr.corp_user_id and cua.wx_corp_id = #{wxCorpId}
-        left join corp_user cu on cu.id = cua.corp_user_id and cu.unionid != ''
-        <where>
-            <if test="tagIds != null and tagIds.length > 0">
-                ct.id in
-                <foreach collection="tagIds" item="item" open="(" separator="," close=")">
-                    #{item}
-                </foreach>
-            </if>
-        </where>
-        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
+        ) s
         <if test="sort != null">
             order by ${sort} ${order}
         </if>
@@ -57,4 +44,9 @@
         from `corp_tag_group` cg
                  left join corp_tag ct on ct.group_id = ct.group_id
     </select>
+
+    <select id="selectCountOfCustomer" resultType="java.lang.Integer">
+        select count(distinct cufr.corp_user_id) from corp_user_tag cut left join corp_user_follow_relation cufr on cufr.id = cut.relation_id
+        where cufr.wx_corp_id = #{wxCorpId} and cut.tag_id = #{tagId}
+    </select>
 </mapper>

+ 8 - 1
netflix-service/src/main/java/com/cyksj/service/corp/impl/CorpTagServiceImpl.java

@@ -295,10 +295,17 @@ public class CorpTagServiceImpl implements CorpTagService {
 					} catch (Exception e) {
 					}
 				}
+				view.setNumOfCustomer(corpTagMapper.selectCountOfCustomer(view.getTagIdStr(), wxCorpId));
 			});
 			return corpTagBackViewPage;
 		}
-		return corpTagGroupMapper.getCorpTagBackView(new Page<>(start, limit), groupIds, sort, order, wxCorpId);
+		Page<CorpTagBackView> corpTagBackView = corpTagGroupMapper.getCorpTagBackView(new Page<>(start, limit), groupIds, sort, order, wxCorpId);
+		corpTagBackView.getRecords().forEach(data->{
+			CorpTagBackView info = corpTagGroupMapper.fillCorpGroupTagInfo(data.getGroupIdStr(), wxCorpId);
+			data.setTagSize(info.getTagSize());
+			data.setNumOfCustomer(info.getNumOfCustomer());
+		});
+		return corpTagBackView;
 	}
 
 	@Override