Explorar o código

直播代码 回调和在线人数和消息记录

yuhongqi hai 2 semanas
pai
achega
f317aa9c14

+ 2 - 2
fs-admin/src/main/java/com/fs/live/controller/LiveGoodsController.java

@@ -135,8 +135,8 @@ public class LiveGoodsController extends BaseController
      * 获取直播店铺
      * */
     @GetMapping("/liveStore/{liveId}")
-    public R liveGoodsStore(@PathVariable Long liveId)
+    public R liveGoodsStore(@PathVariable Long liveId,@RequestParam String key)
     {
-        return liveGoodsService.getStoreByLiveId(liveId);
+        return liveGoodsService.getStoreByLiveId(liveId, key);
     }
 }

+ 2 - 1
fs-live-app/src/main/java/com/fs/app/controller/FsStoreController.java

@@ -33,11 +33,12 @@ public class FsStoreController extends AppBaseController
      */
     @Login
     @GetMapping("/{storeId}")
-    public AjaxResult getInfo(@PathVariable("storeId") Long storeId)
+    public AjaxResult getInfo(@PathVariable("storeId") Long storeId,@RequestParam String key)
     {
         Map<String, Object> params = new HashMap<>();
         params.put("storeId", storeId);
         params.put("userId", getUserId());
+        params.put("productName", key);
         FsStoreLiveVO fsStore = fsStoreService.selectFsStoreLiveByMap(params);
         if (Objects.nonNull(fsStore)) {
             fsStore.setGoodsList(liveGoodsService.selectLiveGoodsListByMap(params));

+ 17 - 0
fs-live-app/src/main/java/com/fs/app/controller/LiveController.java

@@ -150,4 +150,21 @@ public class LiveController extends AppBaseController {
 //		sequence=702115889072680959, set_id=2, stream_id=667,
 //		stream_param=txSecret=6E89AECCA08DBEE82E7F5870BCED7132&txTime=688ACD21, user_ip=125.80.218.101, width=1920}
 	}
+
+	@PostMapping("/endLiving")
+	public R endLiving(HttpServletRequest request, @RequestBody  Map<String, String> params) {
+		log.info("请求参数:{}", params);
+		SendMsgVo sendMsgVo = new SendMsgVo();
+		sendMsgVo.setMsg("结束直播");
+		sendMsgVo.setCmd("live_end");
+		webSocketServer.broadcastMessage(Long.valueOf(params.get("stream_id")), JSONObject.toJSONString(R.ok().put("data",sendMsgVo)));
+		return R.ok();
+//		{app=200149.push.tlivecloud.com, appid=1319721001, appname=live, channel_id=673,
+//				errcode=1, errmsg=The push client actively stopped the push, event_time=1755571239,
+//				event_type=0, height=1080, idc_id=38, node=113.250.23.118, push_duration=1051237,
+//				sequence=721865018844564968, set_id=2, stream_id=673,
+//				stream_param=txSecret=A3EF362C9484D3D091C2E9B08C2C08CB&txTime=68A53145,
+//				user_ip=113.248.98.28, width=1920}
+
+	}
 }

+ 2 - 2
fs-live-app/src/main/java/com/fs/app/controller/LiveGoodsController.java

@@ -104,9 +104,9 @@ public class LiveGoodsController extends BaseController
      * 获取直播店铺
      * */
     @GetMapping("/liveStore/{liveId}")
-    public R liveGoodsStore(@PathVariable Long liveId)
+    public R liveGoodsStore(@PathVariable Long liveId,@RequestParam String key)
     {
-        return liveGoodsService.getStoreByLiveId(liveId);
+        return liveGoodsService.getStoreByLiveId(liveId, key);
     }
 
     /**

+ 90 - 0
fs-live-app/src/main/java/com/fs/app/controller/LiveMsgController.java

@@ -0,0 +1,90 @@
+package com.fs.app.controller;
+
+import com.fs.common.annotation.Log;
+import com.fs.common.core.controller.BaseController;
+import com.fs.common.core.domain.AjaxResult;
+import com.fs.common.core.page.TableDataInfo;
+import com.fs.common.enums.BusinessType;
+import com.fs.common.utils.poi.ExcelUtil;
+import com.fs.live.domain.LiveMsg;
+import com.fs.live.service.ILiveMsgService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+/**
+ * 直播讨论Controller
+ *
+ * @author fs
+ * @date 2025-01-17
+ */
+@RestController
+@RequestMapping("/app/live/liveMsg")
+public class LiveMsgController extends BaseController
+{
+    @Autowired
+    private ILiveMsgService liveMsgService;
+
+    /**
+     * 查询直播讨论列表
+     */
+    @PreAuthorize("@ss.hasPermi('live:liveMsg:list')")
+    @GetMapping("/list")
+    public TableDataInfo list(LiveMsg liveMsg)
+    {
+        startPage();
+        List<LiveMsg> list = liveMsgService.selectLiveMsgList(liveMsg);
+        return getDataTable(list);
+    }
+
+    /**
+     * 导出直播讨论列表
+     */
+    @PreAuthorize("@ss.hasPermi('live:liveMsg:export')")
+    @Log(title = "直播讨论", businessType = BusinessType.EXPORT)
+    @GetMapping("/export")
+    public AjaxResult export(LiveMsg liveMsg)
+    {
+        List<LiveMsg> list = liveMsgService.selectLiveMsgList(liveMsg);
+        ExcelUtil<LiveMsg> util = new ExcelUtil<LiveMsg>(LiveMsg.class);
+        return util.exportExcel(list, "直播讨论数据");
+    }
+
+
+
+    /**
+     * 新增直播讨论
+     */
+    @PreAuthorize("@ss.hasPermi('live:liveMsg:add')")
+    @Log(title = "直播讨论", businessType = BusinessType.INSERT)
+    @PostMapping
+    public AjaxResult add(@RequestBody LiveMsg liveMsg)
+    {
+        return toAjax(liveMsgService.insertLiveMsg(liveMsg));
+    }
+
+    /**
+     * 修改直播讨论
+     */
+    @PreAuthorize("@ss.hasPermi('live:liveMsg:edit')")
+    @Log(title = "直播讨论", businessType = BusinessType.UPDATE)
+    @PutMapping
+    public AjaxResult edit(@RequestBody LiveMsg liveMsg)
+    {
+        return toAjax(liveMsgService.updateLiveMsg(liveMsg));
+    }
+
+    /**
+     * 删除直播讨论
+     */
+    @PreAuthorize("@ss.hasPermi('live:liveMsg:remove')")
+    @Log(title = "直播讨论", businessType = BusinessType.DELETE)
+	@DeleteMapping("/{msgIds}")
+    public AjaxResult remove(@PathVariable Long[] msgIds)
+    {
+        return toAjax(liveMsgService.deleteLiveMsgByMsgIds(msgIds));
+    }
+
+}

+ 101 - 0
fs-live-app/src/main/java/com/fs/app/controller/LiveWatchUserController.java

@@ -0,0 +1,101 @@
+package com.fs.app.controller;
+
+import com.fs.common.annotation.Log;
+import com.fs.common.core.controller.BaseController;
+import com.fs.common.core.domain.AjaxResult;
+import com.fs.common.core.page.TableDataInfo;
+import com.fs.common.enums.BusinessType;
+import com.fs.common.utils.poi.ExcelUtil;
+import com.fs.live.domain.LiveWatchUser;
+import com.fs.live.service.ILiveWatchUserService;
+import com.fs.live.vo.LiveWatchUserVO;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * 直播间观看用户Controller
+ *
+ * @author fs
+ * @date 2025-01-18
+ */
+@RestController
+@RequestMapping("/app/live/liveWatchUser")
+public class LiveWatchUserController extends BaseController
+{
+    @Autowired
+    private ILiveWatchUserService liveWatchUserService;
+
+
+
+    @PreAuthorize("@ss.hasPermi('live:liveWatchUser:list')")
+    @GetMapping("/watchUserList")
+    public TableDataInfo watchUserList(@RequestParam Long liveId) {
+        Map<String, Object> params = new HashMap<>();
+        params.put("liveId", liveId);
+
+        startPage();
+        List<LiveWatchUserVO> onLineUserList = liveWatchUserService.selectWatchUserList(params).stream().filter(liveWatchUserVO -> liveWatchUserVO.getOnline() == 1).collect(Collectors.toList());
+        return getDataTable(onLineUserList);
+    }
+
+
+    /**
+     * 获取直播间观看用户详细信息
+     */
+    @PreAuthorize("@ss.hasPermi('live:liveWatchUser:query')")
+    @GetMapping(value = "/{id}")
+    public AjaxResult getInfo(@PathVariable("id") Long id)
+    {
+        return AjaxResult.success(liveWatchUserService.selectLiveWatchUserById(id));
+    }
+
+    /**
+     * 新增直播间观看用户
+     */
+    @PreAuthorize("@ss.hasPermi('live:liveWatchUser:add')")
+    @Log(title = "直播间观看用户", businessType = BusinessType.INSERT)
+    @PostMapping
+    public AjaxResult add(@RequestBody LiveWatchUser liveWatchUser)
+    {
+        return toAjax(liveWatchUserService.insertLiveWatchUser(liveWatchUser));
+    }
+
+    /**
+     * 修改直播间观看用户
+     */
+    @PreAuthorize("@ss.hasPermi('live:liveWatchUser:edit')")
+    @Log(title = "直播间观看用户", businessType = BusinessType.UPDATE)
+    @PutMapping
+    public AjaxResult edit(@RequestBody LiveWatchUser liveWatchUser)
+    {
+        return toAjax(liveWatchUserService.updateLiveWatchUser(liveWatchUser));
+    }
+
+    /**
+     * 删除直播间观看用户
+     */
+    @PreAuthorize("@ss.hasPermi('live:liveWatchUser:remove')")
+    @Log(title = "直播间观看用户", businessType = BusinessType.DELETE)
+	@DeleteMapping("/{ids}")
+    public AjaxResult remove(@PathVariable Long[] ids)
+    {
+        return toAjax(liveWatchUserService.deleteLiveWatchUserByIds(ids));
+    }
+
+    /**
+     * 修改直播间用户禁言状态
+     */
+    @PreAuthorize("@ss.hasPermi('live:liveWatchUser:edit')")
+    @Log(title = "直播间观看用户", businessType = BusinessType.UPDATE)
+    @PutMapping("/changeUserState")
+    public AjaxResult changeUserState(@RequestParam Long liveId, @RequestParam Long userId) {
+        return toAjax(liveWatchUserService.changeUserState(liveId, userId));
+    }
+
+}

+ 1 - 1
fs-service/src/main/java/com/fs/live/service/ILiveGoodsService.java

@@ -83,7 +83,7 @@ public interface ILiveGoodsService extends IService<LiveGoods>{
      * @return 直播商品集合
      */
     List<LiveGoodsVo> selectProductListByLiveId(LiveGoods liveGoods);
-    R getStoreByLiveId(Long liveId);
+    R getStoreByLiveId(Long liveId,String key);
 
     int insertLiveGoodsAdmin(Map<String, Object> payload, SysUser user);
 

+ 2 - 1
fs-service/src/main/java/com/fs/live/service/impl/LiveGoodsServiceImpl.java

@@ -118,9 +118,10 @@ public class LiveGoodsServiceImpl extends ServiceImpl<LiveGoodsMapper, LiveGoods
     }
 
     @Override
-    public R getStoreByLiveId(Long liveId) {
+    public R getStoreByLiveId(Long liveId, String key) {
         LiveGoods liveGoods = new LiveGoods();
         liveGoods.setLiveId(liveId);
+        liveGoods.setKeywords(key);
         List<LiveGoodsVo> liveGoodsVos = baseMapper.selectProductListByLiveId(liveGoods);
         if (liveGoodsVos.isEmpty()) {
             return R.ok();

+ 6 - 5
fs-service/src/main/java/com/fs/live/service/impl/LiveRedConfServiceImpl.java

@@ -149,6 +149,10 @@ public class LiveRedConfServiceImpl extends ServiceImpl<LiveRedConfMapper, LiveR
         keyList.add(lockKey);
 
         try {
+            Integer remaining = getRemaining(red.getRedId());
+            if (remaining <= 0) {
+                return false;
+            }
             //获取红包锁
             if (!tryLock(lockKey, red.getUserId().toString(), 5)) {
                 return false;
@@ -160,17 +164,14 @@ public class LiveRedConfServiceImpl extends ServiceImpl<LiveRedConfMapper, LiveR
             }
             //redis剩余红包数
             // 平均分 暂时不适用redis 记录红包数
-//            Integer remaining = getRemaining(red.getRedId());
-//            if (remaining <= 0) {
-//                return false;
-//            }
+
             Long integral = calculateIntegralAverage(conf);
             if (0L == integral) {
                 return false;
             }
             Date now = new Date();
             //剩余金额
-            //Integer remainingNum = getRemainingNum(red.getRedId());
+            Integer remainingNum = getRemainingNum(red.getRedId());
 
 
             conf.setTotalSend(conf.getTotalSend() + 1);

+ 4 - 1
fs-service/src/main/resources/mapper/live/LiveGoodsMapper.xml

@@ -209,10 +209,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <select id="selectLiveGoodsListByStoreId" resultType="com.fs.live.vo.LiveGoodsVo">
         select
             g.*,
-            if(uf.favorite_id is not null, true, false) isFavorite
+            if(uf.favorite_id is not null, true, false) isFavorite,
+            p.img_url, p.product_name, p.price, p.sales, p.ot_price
         from live_goods g
+        left join fs_store_product p on p.product_id = g.product_id and p.is_show = 1
         left join live_user_favorite uf on uf.product_id = g.goods_id and uf.user_id = #{params.userId}
         where g.store_id = #{params.storeId} and g.status = 1
+        <if test="params.productName != null "> and p.product_name like concat('%',#{params.productName},'%')</if>
     </select>
 
 </mapper>