Преглед на файлове

包邮范围内的报错

yuhongqi преди 1 ден
родител
ревизия
1167a0028c

+ 9 - 0
fs-service-system/src/main/java/com/fs/live/mapper/LiveMsgMapper.java

@@ -85,4 +85,13 @@ public interface LiveMsgMapper
      * @return 结果
      */
     int insertLiveMsgBatch(@Param("list") List<LiveMsg> liveMsgList);
+
+    /**
+     * 根据直播间ID查询用户ID列表(只返回userId,用于统计消息数量)
+     * @param liveId 直播间ID
+     * @return 用户ID列表(包含重复,用于统计每个用户的消息数量)
+     */
+    @Select("SELECT user_id FROM live_msg WHERE live_id = #{liveId} AND user_id IS NOT NULL")
+    @DataSource(DataSourceType.SLAVE)
+    List<Long> selectUserIdListByLiveId(@Param("liveId") Long liveId);
 }

+ 46 - 0
fs-service-system/src/main/java/com/fs/live/service/impl/LiveDataServiceImpl.java

@@ -12,6 +12,7 @@ import com.fs.company.mapper.CompanyUserMapper;
 import com.fs.live.domain.*;
 import com.fs.live.mapper.*;
 import com.fs.live.param.LiveDataParam;
+import com.fs.live.domain.LiveMsg;
 import com.fs.live.service.ILiveDataService;
 import com.fs.live.service.ILiveUserFavoriteService;
 import com.fs.live.service.ILiveUserFollowService;
@@ -78,6 +79,8 @@ public class LiveDataServiceImpl implements ILiveDataService {
     private LiveOrderMapper liveOrderMapper;
     @Autowired
     private LiveMapper liveMapper;
+    @Autowired
+    private LiveMsgMapper liveMsgMapper;
     /**
      * 查询直播数据
      *
@@ -940,6 +943,37 @@ public class LiveDataServiceImpl implements ILiveDataService {
             return new ArrayList<>();
         }
 
+        // 批量查询用户状态和消息数量,优化性能
+        List<Long> userIds = userDetailList.stream()
+                .map(LiveUserDetailVo::getUserId)
+                .filter(Objects::nonNull)
+                .distinct()
+                .collect(Collectors.toList());
+        
+        // 批量查询用户状态(分批查询,每批1000条)
+        Map<Long, Integer> userStatusMap = new HashMap<>();
+        int batchSize = 1000;
+        for (int i = 0; i < userIds.size(); i += batchSize) {
+            int end = Math.min(i + batchSize, userIds.size());
+            List<Long> batchUserIds = userIds.subList(i, end);
+            List<FsUser> statusList = fsUserMapper.selectUserStatusByIds(batchUserIds);
+            if (statusList != null) {
+                for (FsUser tempUser : statusList) {
+
+                    if (tempUser.getUserId() != null && tempUser.getStatus() != null) {
+                        Long userId = tempUser.getUserId();
+                        Integer status = tempUser.getStatus();
+                        userStatusMap.put(userId, status);
+                    }
+                }
+            }
+        }
+        
+        // 批量查询消息数量:只查询用户ID列表,然后统计
+        List<Long> msgUserIds = liveMsgMapper.selectUserIdListByLiveId(liveId);
+        Map<Long, Long> msgCountMap = msgUserIds.stream()
+                .collect(Collectors.groupingBy(userId -> userId, Collectors.counting()));
+
         // 转换为导出VO列表
         List<LiveUserDetailExportVO> exportList = new ArrayList<>();
         for (LiveUserDetailVo userDetail : userDetailList) {
@@ -949,6 +983,18 @@ public class LiveDataServiceImpl implements ILiveDataService {
             exportVO.setUserId(userDetail.getUserId());
             exportVO.setUserName(userDetail.getUserName());
 
+            // 设置用户状态
+            Integer status = userStatusMap.get(userDetail.getUserId());
+            if (status != null) {
+                exportVO.setUserStatus(status == 1 ? "正常" : "禁止");
+            } else {
+                exportVO.setUserStatus("未知");
+            }
+
+            // 设置消息数量
+            Long msgCount = msgCountMap.get(userDetail.getUserId());
+            exportVO.setMsgCount(msgCount != null ? msgCount.intValue() : 0);
+
             // 观看时长(秒转分钟)
             exportVO.setLiveWatchDuration(formatSecondsToMinutes(userDetail.getLiveWatchDuration()));
             exportVO.setPlaybackWatchDuration(formatSecondsToMinutes(userDetail.getPlaybackWatchDuration()));

+ 1 - 1
fs-service-system/src/main/java/com/fs/live/service/impl/LiveOrderServiceImpl.java

@@ -2256,7 +2256,7 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
         FsShippingTemplatesRegion shippingTemplatesRegion = shippingTemplatesRegionMap.get(tempId);
         if (shippingTemplatesRegion == null) {
             log.error("没有找到运费模板");
-            return storePostage;
+            throw new CustomException("当前地址,商品不在快递配送范围内!");
         }
         BigDecimal price = NumberUtil.round(NumberUtil.mul(totalNum, fsStoreProduct.getPrice()), 2);
 

+ 1 - 0
fs-service-system/src/main/java/com/fs/live/vo/LiveGoodsVo.java

@@ -15,6 +15,7 @@ public class LiveGoodsVo {
     private Integer status;
     private Integer fsStatus;
     private Integer sales;
+    private Integer sort;
     private Long productId;
     private BigDecimal otPrice;
     private Long storeId;

+ 8 - 0
fs-service-system/src/main/java/com/fs/live/vo/LiveUserDetailExportVO.java

@@ -52,5 +52,13 @@ public class LiveUserDetailExportVO {
 //    @Excel(name = "是否完课")
     private String isCompleted;
 
+    /** 用户状态 */
+    @Excel(name = "用户状态")
+    private String userStatus;
+
+    /** 发送消息次数 */
+    @Excel(name = "发送消息次数")
+    private Integer msgCount;
+
 }
 

+ 8 - 0
fs-service-system/src/main/java/com/fs/store/mapper/FsUserMapper.java

@@ -1,6 +1,7 @@
 package com.fs.store.mapper;
 
 import java.util.List;
+import java.util.Map;
 
 import com.fs.common.annotation.DataSource;
 import com.fs.common.enums.DataSourceType;
@@ -225,4 +226,11 @@ public interface FsUserMapper
     @Select("select user_id,avatar,nickname from fs_user where user_id = #{userId} limit 1")
     @DataSource(DataSourceType.SLAVE)
     FsUser selectWsFsUserById(@Param("userId") long userId);
+
+    /**
+     * 批量查询用户状态(只返回userId和status)
+     * @param userIds 用户ID列表
+     * @return List<Map> 每个Map包含user_id和status字段
+     */
+    List<FsUser> selectUserStatusByIds(@Param("userIds") List<Long> userIds);
 }

+ 7 - 2
fs-service-system/src/main/resources/mapper/live/LiveGoodsMapper.xml

@@ -41,6 +41,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="isShow != null "> and is_show = #{isShow}</if>
             <if test="sales != null "> and sales = #{sales}</if>
         </where>
+        order by sort
     </select>
 
     <select id="selectLiveGoodsByGoodsId" parameterType="Long" resultMap="LiveGoodsResult">
@@ -170,7 +171,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 
     <select id="selectProductListByLiveId" parameterType="LiveGoods" resultType="com.fs.live.vo.LiveGoodsVo">
 
-        select lg.goods_id,sp.image as img_url,sp.product_name,sp.price,sp.stock,lg.sales,lg.status,sp.product_id,sp.ot_price,case when lg.is_show = 1 then true else false end as is_show
+        select lg.goods_id,lg.sort ,sp.image as img_url,sp.product_name,sp.price,sp.stock,lg.sales,lg.status,sp.product_id,sp.ot_price,case when lg.is_show = 1 then true else false end as is_show
         <if test="companyUserId != null "> ,if(uf.favorite_id is not null, true, false) is_favorite </if>
 
         from live_goods lg
@@ -193,11 +194,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
                 and sp.product_name like concat('%',#{keywords},'%')
             </if>
         </where>
+
+        order by lg.sort
     </select>
 
     <select id="selectProductListByLiveIdAll" parameterType="LiveGoods" resultType="com.fs.live.vo.LiveGoodsVo">
 
-        select lg.goods_id,sp.image as img_url,sp.product_name,sp.price,lg.stock,lg.sales,lg.status,sp.product_id,sp.ot_price,case when lg.is_show = 1 then true else false end as is_show,sp.is_show as fs_status
+        select lg.goods_id,lg.sort,sp.image as img_url,sp.product_name,sp.price,lg.stock,lg.sales,lg.status,sp.product_id,sp.ot_price,case when lg.is_show = 1 then true else false end as is_show,sp.is_show as fs_status
         from live_goods lg
         left join fs_store_product sp
         ON  lg.product_id = sp.product_id
@@ -213,6 +216,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
                 and sp.product_name like concat('%',#{keywords},'%')
             </if>
         </where>
+        order by lg.sort
     </select>
 
     <select id="selectLiveGoodsVoByGoodsId"  resultType="com.fs.live.vo.LiveGoodsVo">
@@ -276,6 +280,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         where  g.status = 1
         <if test="params.productName != null "> and p.product_name like concat('%',#{params.productName},'%')</if>
         <if test="params.liveId != null "> and g.live_id = #{params.liveId}</if>
+        order by g.sort
     </select>
 
     <update id="handleShelfOrUnAdmin" parameterType="com.fs.live.vo.LiveGoodsListVo">

+ 3 - 1
fs-service-system/src/main/resources/mapper/store/FsStoreProductPackageMapper.xml

@@ -85,6 +85,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="icgCoupons != null">icg_coupons,</if>
             <if test="icgUrl != null">icg_url,</if>
             <if test="icgMark != null">icg_mark,</if>
+            <if test="templateId != null">template_id,</if>
          </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="packageId != null">#{packageId},</if>
@@ -92,7 +93,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="descs != null">#{descs},</if>
             <if test="content != null">#{content},</if>
             <if test="imgUrl != null">#{imgUrl},</if>
-            <if test="images != null">images,</if>
+            <if test="images != null">#{images},</if>
             <if test="products != null">#{products},</if>
             <if test="money != null">#{money},</if>
             <if test="payMoney != null">#{payMoney},</if>
@@ -108,6 +109,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="icgCoupons != null">#{icgCoupons},</if>
             <if test="icgUrl != null">#{icgUrl},</if>
             <if test="icgMark != null">#{icgMark},</if>
+            <if test="templateId != null">#{templateId},</if>
          </trim>
     </insert>
 

+ 9 - 0
fs-service-system/src/main/resources/mapper/store/FsUserMapper.xml

@@ -243,4 +243,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         </foreach>
     </delete>
 
+    <!-- 批量查询用户状态(只返回userId和status) -->
+    <select id="selectUserStatusByIds" parameterType="java.util.List" resultType="com.fs.store.domain.FsUser">
+        SELECT user_id, status FROM fs_user
+        WHERE user_id IN
+        <foreach item="userId" collection="userIds" open="(" separator="," close=")">
+            #{userId}
+        </foreach>
+    </select>
+
 </mapper>