Эх сурвалжийг харах

好友 关注 粉丝 根据时间倒序排序

qinxuyang 13 цаг өмнө
parent
commit
8813250b72

+ 5 - 0
alien-entity/src/main/java/shop/alien/entity/store/vo/LifeFansVo.java

@@ -6,6 +6,8 @@ import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 
+import java.util.Date;
+
 @Data
 @JsonInclude
 @NoArgsConstructor
@@ -59,4 +61,7 @@ public class LifeFansVo {
 
     @ApiModelProperty(value = "是否是已入驻成功的商户 0-不是 1-是(只有 store_application_status = 1 时才是商户)")
     public String isMerchant;
+
+    @ApiModelProperty(value = "时间:我的关注为本人发出关注记录;我的粉丝为对方关注本人(followed_id=fansId)记录;互关为双方较大值。用于排序与回显")
+    private Date createdTime;
 }

+ 13 - 12
alien-entity/src/main/java/shop/alien/mapper/LifeFansMapper.java

@@ -16,17 +16,17 @@ import java.util.List;
 public interface LifeFansMapper extends BaseMapper<LifeFans> {
 
     @Select("<script>" +
-            "select MAX(foll.id) id, MAX(foll.name) name, MAX(foll.image) image, foll.phoneId, MAX(foll.blurb) blurb, MAX(foll.blockedType) blockedType, MAX(foll.blockedId) blockedId, MAX(foll.username) username, MAX(foll.accountBlurb) accountBlurb, MAX(foll.isMerchant) isMerchant, " +
+            "select MAX(foll.id) id, MAX(foll.name) name, MAX(foll.image) image, foll.phoneId, MAX(foll.blurb) blurb, MAX(foll.blockedType) blockedType, MAX(foll.blockedId) blockedId, MAX(foll.username) username, MAX(foll.accountBlurb) accountBlurb, MAX(foll.isMerchant) isMerchant, MAX(foll.created_time) created_time, " +
             "  MAX(lb.id) blackListid, MAX(if(isnull(fans.id), 0, 1)) isFollowMe, MAX(if(isnull(fans_this.id), 0, 1)) isFollowThis, MAX(if(isnull(lb.id), '0', '1')) isBlocked,  " +
             "  (select count(1) from life_fans where fans_id= foll.phoneId and delete_flag =0) followNum, " +
             "  (select count(1) from life_fans where followed_id= foll.phoneId and delete_flag =0) fansNum from ( " +
             "    with follow as (   " +
-            "        select substring_index(followed_id, '_', 1) as flag, substring_index(followed_id, '_', -1) as phone   " +
+            "        select substring_index(followed_id, '_', 1) as flag, substring_index(followed_id, '_', -1) as phone, created_time   " +
             "        from life_fans   " +
             "        where delete_flag = 0 and fans_id = #{fansId} " +
             "    )   " +
             "    select info.id, IF(info.store_application_status = 0, user.nick_name, info.store_name) AS NAME," +
-            "    user.head_img image, concat('store_', user.phone) phoneId, IF(info.store_application_status = 0, user.account_blurb, info.store_blurb) AS blurb, 1 blockedType,user.id blockedId ,IFNULL(user.nick_name, user.name) username, user.account_blurb accountBlurb, IF(info.store_application_status = 1, '1', '0') AS isMerchant " +
+            "    user.head_img image, concat('store_', user.phone) phoneId, IF(info.store_application_status = 0, user.account_blurb, info.store_blurb) AS blurb, 1 blockedType,user.id blockedId ,IFNULL(user.nick_name, user.name) username, user.account_blurb accountBlurb, IF(info.store_application_status = 1, '1', '0') AS isMerchant, foll.created_time " +
             "    from follow foll " +
             "    join store_user user on foll.phone = user.phone " +
             "    join store_info info on info.id = user.store_id " +
@@ -34,7 +34,7 @@ public interface LifeFansMapper extends BaseMapper<LifeFans> {
             "    where foll.flag = 'store' and user.delete_flag = 0 and info.delete_flag = 0 " +
             "<if test=\"onlyStoreFollowed == false\">" +
             "    union " +
-            "    select user.id, user.user_name name, user.user_image image, concat('user_', user.user_phone) phoneId, user.jianjie blurb, 2 blockedType,user.id blockedId,'' username, '' accountBlurb, '0' AS isMerchant " +
+            "    select user.id, user.user_name name, user.user_image image, concat('user_', user.user_phone) phoneId, user.jianjie blurb, 2 blockedType,user.id blockedId,'' username, '' accountBlurb, '0' AS isMerchant, foll.created_time " +
             "    from follow foll " +
             "    join life_user user on foll.phone = user.user_phone   " +
             "    where foll.flag = 'user' and user.delete_flag = 0   " +
@@ -70,17 +70,17 @@ public interface LifeFansMapper extends BaseMapper<LifeFans> {
     List<LifeFansVo> getMyFollowedAll(@Param("fansId") String fansId);
 
     @Select("<script>" +
-            "select MAX(foll.id) id, MAX(foll.name) name, MAX(foll.image) image, foll.phoneId, MAX(foll.blurb) blurb, MAX(foll.blockedType) blockedType, MAX(foll.blockedId) blockedId, MAX(foll.isMerchant) isMerchant, " +
+            "select MAX(foll.id) id, MAX(foll.name) name, MAX(foll.image) image, foll.phoneId, MAX(foll.blurb) blurb, MAX(foll.blockedType) blockedType, MAX(foll.blockedId) blockedId, MAX(foll.isMerchant) isMerchant, MAX(foll.created_time) created_time, " +
             "  MAX(lb.id) blackListid, MAX(if(isnull(fans.id), 0, 1)) isFollowThis, MAX(if(isnull(fans_me.id), 0, 1)) isFollowMe, MAX(if(isnull(lb.id), '0', '1')) isBlocked, " +
             "    (select count(1) from life_fans fans2 where fans2.followed_id = foll.phoneId and fans2.delete_flag = 0) fansNum, " +
             "    (select count(1) from life_fans fans3 where fans3.fans_id = foll.phoneId and fans3.delete_flag = 0) followNum " +
             "from ( " +
             "    with follow as ( " +
-            "        select substring_index(fans_id, '_', 1) as flag, substring_index(fans_id, '_', -1) as phone " +
+            "        select substring_index(fans_id, '_', 1) as flag, substring_index(fans_id, '_', -1) as phone, created_time " +
             "        from life_fans " +
             "        where delete_flag = 0 and followed_id = #{fansId} " +
             "    ) " +
-            "    select user.id, IF(info.store_application_status = 0, user.nick_name, info.store_name) AS name, user.head_img image, concat('store_', user.phone) phoneId, IF(info.store_application_status = 0, user.account_blurb, info.store_blurb) AS blurb, 1 blockedType,user.id blockedId, IF(info.store_application_status = 1, '1', '0') AS isMerchant" +
+            "    select user.id, IF(info.store_application_status = 0, user.nick_name, info.store_name) AS name, user.head_img image, concat('store_', user.phone) phoneId, IF(info.store_application_status = 0, user.account_blurb, info.store_blurb) AS blurb, 1 blockedType,user.id blockedId, IF(info.store_application_status = 1, '1', '0') AS isMerchant, foll.created_time " +
             "    from follow foll " +
             "    join store_user user on foll.phone = user.phone " +
             "    join store_info info on info.id = user.store_id " +
@@ -88,7 +88,7 @@ public interface LifeFansMapper extends BaseMapper<LifeFans> {
             "    where foll.flag = 'store' and user.delete_flag = 0 and info.delete_flag = 0" +
             "<if test=\"onlyStoreFans == false\">" +
             "    union " +
-            "    select user.id, user.user_name name, user.user_image image, concat('user_', user.user_phone) phoneId, user.jianjie blurb, 2 blockedType,user.id blockedId, '0' AS isMerchant" +
+            "    select user.id, user.user_name name, user.user_image image, concat('user_', user.user_phone) phoneId, user.jianjie blurb, 2 blockedType,user.id blockedId, '0' AS isMerchant, foll.created_time " +
             "    from follow foll " +
             "    join life_user user on foll.phone = user.user_phone " +
             "    where foll.flag = 'user' and user.delete_flag = 0 " +
@@ -209,25 +209,26 @@ public interface LifeFansMapper extends BaseMapper<LifeFans> {
             "${ew.customSqlSegment} ")
     IPage<LifeFansVo> getMyUserFans(IPage<LifeFansVo> iPage, @Param("fansId") String fansId, @Param(Constants.WRAPPER) QueryWrapper<LifeFansVo> wrapper);
 
-    @Select("select MAX(foll.id) id, MAX(foll.name) name, MAX(foll.image) image, foll.phoneId, MAX(foll.blurb) blurb, MAX(foll.blockedType) blockedType, MAX(foll.blockedId) blockedId, MAX(foll.username) username, MAX(foll.accountBlurb) accountBlurb, MAX(foll.isMerchant) isMerchant, " +
+    @Select("select MAX(foll.id) id, MAX(foll.name) name, MAX(foll.image) image, foll.phoneId, MAX(foll.blurb) blurb, MAX(foll.blockedType) blockedType, MAX(foll.blockedId) blockedId, MAX(foll.username) username, MAX(foll.accountBlurb) accountBlurb, MAX(foll.isMerchant) isMerchant, MAX(foll.created_time) created_time, " +
             "  MAX(lb.id) blackListid, 1 as isFollowThis, 1 as isFollowMe, " +
             "       (select count(1) from life_fans fans2 where fans2.followed_id = foll.phoneId and fans2.delete_flag = 0) fansNum, " +
             "       (select count(1) from life_fans fans3 where fans3.fans_id = foll.phoneId and fans3.delete_flag = 0) followNum " +
             "from ( " +
             "    with follow as ( " +
-            "        select substring_index(fans1.followed_id, '_', 1) as flag, substring_index(fans1.followed_id, '_', -1) as phone " +
+            "        select substring_index(fans1.followed_id, '_', 1) as flag, substring_index(fans1.followed_id, '_', -1) as phone, " +
+            "               GREATEST(fans1.created_time, fans2.created_time) as created_time " +
             "        from life_fans fans1 " +
             "        join life_fans fans2 on fans1.followed_id = fans2.fans_id and fans1.fans_id = fans2.followed_id " +
             "        where fans1.delete_flag = 0 and fans2.delete_flag = 0 and fans1.fans_id = #{fansId} " +
             "    ) " +
-            "    select info.id, IF(info.store_application_status = 0, user.nick_name, info.store_name) AS name, user.head_img image, concat('store_', user.phone) phoneId, IF(info.store_application_status = 0, user.account_blurb, info.store_blurb) AS blurb, 1 blockedType,user.id blockedId ,IFNULL(user.nick_name, user.name) username, user.account_blurb accountBlurb, IF(info.store_application_status = 1, '1', '0') AS isMerchant " +
+            "    select info.id, IF(info.store_application_status = 0, user.nick_name, info.store_name) AS name, user.head_img image, concat('store_', user.phone) phoneId, IF(info.store_application_status = 0, user.account_blurb, info.store_blurb) AS blurb, 1 blockedType,user.id blockedId ,IFNULL(user.nick_name, user.name) username, user.account_blurb accountBlurb, IF(info.store_application_status = 1, '1', '0') AS isMerchant, foll.created_time " +
             "    from follow foll " +
             "    join store_user user on foll.phone = user.phone " +
             "    join store_info info on info.id = user.store_id " +
             "    left join store_img img on img.store_id = user.store_id and img.img_type = '10' and img.delete_flag = 0 " +
             "    where foll.flag = 'store' and user.delete_flag = 0 and info.delete_flag = 0 " +
             "    union " +
-            "    select user.id, user.user_name name, user.user_image image, concat('user_', user.user_phone) phoneId, user.jianjie blurb, 2 blockedType,user.id blockedId,'' username, '' accountBlurb, '0' AS isMerchant " +
+            "    select user.id, user.user_name name, user.user_image image, concat('user_', user.user_phone) phoneId, user.jianjie blurb, 2 blockedType,user.id blockedId,'' username, '' accountBlurb, '0' AS isMerchant, foll.created_time " +
             "    from follow foll " +
             "    join life_user user on foll.phone = user.user_phone " +
             "    where foll.flag = 'user' and user.delete_flag = 0 " +

+ 3 - 0
alien-store/src/main/java/shop/alien/store/service/LifeStoreService.java

@@ -80,6 +80,7 @@ public class LifeStoreService {
                 .or(StringUtils.isNotEmpty(name))
                 .like(StringUtils.isNotEmpty(name), "foll.phoneId", name);
         wrapper.groupBy("foll.phoneId");
+        wrapper.last(" ORDER BY MAX(foll.created_time) DESC");
         String trimmedMyFansId = StringUtils.isNotEmpty(myFansId) ? myFansId.trim() : null;
         String relationFansId = StringUtils.isNotEmpty(trimmedMyFansId) ? trimmedMyFansId : fansId;
         String blockerSourceId = StringUtils.isNotEmpty(trimmedMyFansId) ? trimmedMyFansId : fansId;
@@ -122,6 +123,7 @@ public class LifeStoreService {
         QueryWrapper<LifeFansVo> wrapper = new QueryWrapper<>();
         wrapper.like(StringUtils.isNotEmpty(name), "foll.name", name);
         wrapper.groupBy("foll.phoneId");
+        wrapper.last(" ORDER BY MAX(foll.created_time) DESC");
         String trimmedMyFansId = StringUtils.isNotEmpty(myFansId) ? myFansId.trim() : null;
         String relationFansId = StringUtils.isNotEmpty(trimmedMyFansId) ? trimmedMyFansId : fansId;
         String blockerSourceId = StringUtils.isNotEmpty(trimmedMyFansId) ? trimmedMyFansId : fansId;
@@ -183,6 +185,7 @@ public class LifeStoreService {
         QueryWrapper<LifeFansVo> wrapper = new QueryWrapper<>();
         wrapper.like(StringUtils.isNotEmpty(name), "foll.name", name);
         wrapper.groupBy("foll.phoneId");
+        wrapper.last(" ORDER BY MAX(foll.created_time) DESC");
         String blockerType = "";
         String blockerId = "";
         if ("user".equals(fansId.split("_")[0])) {