瀏覽代碼

小小训练营活动
直播间商品

zouxuan 3 年之前
父節點
當前提交
5548606855

+ 1 - 1
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/LiveGoodsMapperDao.java

@@ -17,7 +17,7 @@ public interface LiveGoodsMapperDao extends BaseDAO<Integer, LiveGoodsMapper> {
 
     LiveGoodsMapper findByLiveIdAndGoodsId(@Param("liveId") String liveId, @Param("liveGoodsId") Integer liveGoodsId);
 
-    List<LiveGoodsMapperDto> getLiveGoodsList(@Param("liveId") String liveId);
+    List<LiveGoodsMapperDto> getLiveGoodsList(@Param("liveId") String liveId, @Param("liveGoodsId") Integer liveGoodsId, @Param("status") boolean status);
 
     void batchInsert(@Param("liveGoodsMappers") List<LiveGoodsMapper> liveGoodsMappers);
 

+ 11 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/page/LiveGoodsMapperQueryInfo.java

@@ -11,6 +11,17 @@ public class LiveGoodsMapperQueryInfo extends QueryInfo {
     @ApiModelProperty(value = "直播房间号",required = false)
     private String liveId;
 
+    @ApiModelProperty(value = "商品编号",required = false)
+    private Integer liveGoodsId;
+
+    public Integer getLiveGoodsId() {
+        return liveGoodsId;
+    }
+
+    public void setLiveGoodsId(Integer liveGoodsId) {
+        this.liveGoodsId = liveGoodsId;
+    }
+
     public String getLiveId() {
         return liveId;
     }

+ 9 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/LiveGoodsMapperService.java

@@ -1,5 +1,7 @@
 package com.ym.mec.biz.service;
 
+import com.ym.mec.biz.dal.dao.LiveGoodsMapperDao;
+import com.ym.mec.biz.dal.dto.LiveGoodsMapperDto;
 import com.ym.mec.biz.dal.entity.LiveGoods;
 import com.ym.mec.biz.dal.entity.LiveGoodsMapper;
 import com.ym.mec.biz.dal.page.LiveGoodsMapperQueryInfo;
@@ -11,15 +13,22 @@ import java.util.List;
 
 public interface LiveGoodsMapperService extends BaseService<Integer, LiveGoodsMapper> {
 
+    //新增直播间商品
     void add(List<LiveGoodsMapper> liveGoodsMappers);
 
+    //商品下架
     void downGoods(Integer liveGoodsId);
 
+    //商品下架
     void downGoods(Integer liveGoodsId, String liveId);
 
+    //商品上架
     void upGoods(Integer liveGoodsId, String liveId);
 
     List<LiveGoodsMapper> findByLiveGoodsIdAndStatus(Integer goodsId, Boolean status);
 
+    //分页查询
     PageInfo<LiveGoods> queryGoodsPage(LiveGoodsMapperQueryInfo queryInfo);
+
+    List<LiveGoodsMapperDto> getLiveGoodsList(String liveId, Integer liveGoodsId, Boolean status);
 }

+ 8 - 2
mec-biz/src/main/java/com/ym/mec/biz/service/impl/LiveGoodsMapperServiceImpl.java

@@ -2,6 +2,7 @@ package com.ym.mec.biz.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.ym.mec.biz.dal.dao.LiveGoodsMapperDao;
+import com.ym.mec.biz.dal.dto.LiveGoodsMapperDto;
 import com.ym.mec.biz.dal.entity.ImLiveBroadcastRoom;
 import com.ym.mec.biz.dal.entity.LiveGoods;
 import com.ym.mec.biz.dal.entity.LiveGoodsMapper;
@@ -81,13 +82,18 @@ public class LiveGoodsMapperServiceImpl extends BaseServiceImpl<Integer, LiveGoo
 		return pageInfo;
     }
 
-    private void publishRoomMsg(ImLiveBroadcastRoom imLiveBroadcastRoom) {
+	@Override
+	public List<LiveGoodsMapperDto> getLiveGoodsList(String liveId, Integer liveGoodsId, Boolean status) {
+		return liveGoodsMapperDao.getLiveGoodsList(liveId,liveGoodsId,status);
+	}
+
+	private void publishRoomMsg(ImLiveBroadcastRoom imLiveBroadcastRoom) {
 		ImRoomMessage message = new ImRoomMessage();
 		message.setIsIncludeSender(1);
 		message.setObjectName(ImRoomMessage.LIVE_GOODS_CHANGE);
 		message.setToChatroomId(imLiveBroadcastRoom.getRoomUid());
 		message.setFromUserId(imLiveBroadcastRoom.getSpeakerId().toString());
-		message.setContent(liveGoodsMapperDao.getLiveGoodsList(imLiveBroadcastRoom.getRoomUid()));
+		message.setContent(liveGoodsMapperDao.getLiveGoodsList(imLiveBroadcastRoom.getRoomUid(),null,true));
 		imFeignService.publishRoomMsg(message);
 	}
 

+ 20 - 16
mec-biz/src/main/resources/config/mybatis/LiveGoodsMapperMapper.xml

@@ -83,6 +83,9 @@
 			<if test="status != null">
 				AND lgm.status_ = #{status}
 			</if>
+			<if test="liveGoodsId != null">
+				AND lg.goods_id_ = #{liveGoodsId}
+			</if>
 		</where>
 	</sql>
 	<!-- 分页查询 -->
@@ -100,6 +103,7 @@
 		LEFT JOIN live_goods lg ON lgm.goods_id_ = lg.id_
 		<include refid="queryPageSql" />
 	</select>
+
 	<select id="findByLiveGoodsIdAndStatus" resultMap="LiveGoodsMapper">
 		SELECT * FROM live_goods_mapper WHERE goods_id_ = #{liveGoodsId} AND status_ = #{status}
 	</select>
@@ -107,6 +111,19 @@
 		SELECT * FROM live_goods_mapper WHERE live_id_ = #{liveId} AND goods_id_ = #{liveGoodsId}
 	</select>
 
+	<sql id="queryGoodsPageSql">
+		<where>
+			<if test="liveId != null and liveId != ''">
+				AND lgm.live_id_ = #{liveId}
+			</if>
+			<if test="status != null">
+				AND lgm.status_ = #{status}
+			</if>
+			<if test="liveGoodsId != null">
+				AND lg.goods_id_ = #{liveGoodsId}
+			</if>
+		</where>
+	</sql>
 	<resultMap id="LiveGoodsMapperDto" type="com.ym.mec.biz.dal.dto.LiveGoodsMapperDto">
 		<result column="id_" property="id" />
 		<result column="image_" property="image" />
@@ -122,31 +139,18 @@
 		SELECT lg.*,lgm.status_
 		FROM live_goods_mapper lgm
 		LEFT JOIN live_goods lg ON lgm.goods_id_ = lg.id_
-		WHERE lgm.live_id_ = #{liveId}
+		<include refid="queryGoodsPageSql"/>
 	</select>
-	<sql id="queryPageSqlForGoods">
-		<where>
-			<if test="liveId != null and liveId != ''">
-				AND lgm.live_id_ = #{liveId}
-			</if>
-			<if test="search != null and search != ''">
-				AND (lg.name_ LIKE '%${search}%' OR lg.id_ = ${search})
-			</if>
-			<if test="status != null">
-				AND lgm.status_ = #{status}
-			</if>
-		</where>
-	</sql>
 	<select id="countLiveGoods" resultType="java.lang.Integer">
 		SELECT COUNT(lgm.id_) FROM live_goods_mapper lgm
 		LEFT JOIN live_goods lg ON lgm.goods_id_ = lg.id_
-		<include refid="queryPageSqlForGoods" />
+		<include refid="queryPageSql" />
 	</select>
 	<select id="queryGoodsPage" resultMap="LiveGoodsMapperDto">
 		SELECT lg.*,lgm.status_
 		FROM live_goods_mapper lgm
 		LEFT JOIN live_goods lg ON lgm.goods_id_ = lg.id_
-		<include refid="queryPageSqlForGoods" />
+		<include refid="queryPageSql" />
 		ORDER BY lgm.id_
 		<include refid="global.limit"/>
 	</select>

+ 18 - 2
mec-student/src/main/java/com/ym/mec/student/controller/LiveGoodsMapperController.java

@@ -1,12 +1,18 @@
 package com.ym.mec.student.controller;
 
+import com.ym.mec.biz.dal.dto.LiveGoodsMapperDto;
+import com.ym.mec.biz.dal.entity.LiveGoods;
 import com.ym.mec.biz.dal.page.LiveGoodsMapperQueryInfo;
 import com.ym.mec.biz.service.LiveGoodsMapperService;
 import com.ym.mec.common.controller.BaseController;
 import com.ym.mec.common.entity.HttpResponseResult;
+import com.ym.mec.common.page.PageInfo;
 import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
@@ -21,7 +27,17 @@ public class LiveGoodsMapperController extends BaseController {
 
     @ApiOperation("分页查询直播间商品")
     @PostMapping("/page")
-    public HttpResponseResult page(LiveGoodsMapperQueryInfo queryInfo) {
-        return succeed(liveGoodsMapperService.queryPage(queryInfo));
+    public HttpResponseResult<PageInfo<LiveGoods>> page(LiveGoodsMapperQueryInfo queryInfo) {
+        return succeed(liveGoodsMapperService.queryGoodsPage(queryInfo));
+    }
+
+    @ApiOperation("获取直播间商品详情")
+    @GetMapping(value = "/getGoodsDetail")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "liveGoodsId", value = "商品编号", required = true, dataType = "long"),
+            @ApiImplicitParam(name = "liveId", value = "房间号", required = true,dataType = "String")
+    })
+    public HttpResponseResult<LiveGoodsMapperDto> getGoodsDetail(Integer liveGoodsId, String liveId) {
+        return succeed(liveGoodsMapperService.getLiveGoodsList(liveId,liveGoodsId,null).get(0));
     }
 }

+ 8 - 4
mec-web/src/main/java/com/ym/mec/web/controller/LiveGoodsController.java

@@ -9,10 +9,7 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 @Api(tags = "直播间商品管理")
 @RequestMapping("liveGoods")
@@ -22,6 +19,13 @@ public class LiveGoodsController extends BaseController {
     @Autowired
     private LiveGoodsService liveGoodsService;
 
+    @ApiOperation("获取商品详情")
+    @GetMapping(value = "/get")
+    @PreAuthorize("@pcs.hasPermissions('liveGoods/get')")
+    public HttpResponseResult get(Integer goodsId) {
+        return succeed(liveGoodsService.get(goodsId));
+    }
+
     @ApiOperation("分页查询直播间商品")
     @PostMapping(value = "/page")
     @PreAuthorize("@pcs.hasPermissions('liveGoods/page')")

+ 13 - 4
mec-web/src/main/java/com/ym/mec/web/controller/LiveGoodsMapperController.java

@@ -1,5 +1,6 @@
 package com.ym.mec.web.controller;
 
+import com.ym.mec.biz.dal.dto.LiveGoodsMapperDto;
 import com.ym.mec.biz.dal.entity.LiveGoods;
 import com.ym.mec.biz.dal.entity.LiveGoodsMapper;
 import com.ym.mec.biz.dal.page.LiveGoodsMapperQueryInfo;
@@ -15,10 +16,7 @@ import io.swagger.annotations.ApiOperation;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
 
@@ -45,6 +43,17 @@ public class LiveGoodsMapperController extends BaseController {
         return succeed();
     }
 
+    @ApiOperation("获取直播间商品详情")
+    @GetMapping(value = "/getGoodsDetail")
+    @PreAuthorize("@pcs.hasPermissions('liveGoodsMapper/getGoodsDetail')")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "liveGoodsId", value = "商品编号", required = true, dataType = "long"),
+            @ApiImplicitParam(name = "liveId", value = "房间号", required = true,dataType = "String")
+    })
+    public HttpResponseResult<LiveGoodsMapperDto> getGoodsDetail(Integer liveGoodsId, String liveId) {
+        return succeed(liveGoodsMapperService.getLiveGoodsList(liveId,liveGoodsId,null).get(0));
+    }
+
     @ApiOperation("上架、下架直播间商品")
     @PostMapping("/updateStatus")
     @PreAuthorize("@pcs.hasPermissions('liveGoodsMapper/updateStatus')")