Parcourir la source

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

zouxuan il y a 3 ans
Parent
commit
264e738aa8

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

@@ -1,5 +1,7 @@
 package com.ym.mec.biz.dal.dao;
 
+import com.ym.mec.biz.dal.dto.LiveGoodsMapperDto;
+import com.ym.mec.biz.dal.entity.LiveGoods;
 import com.ym.mec.common.dal.BaseDAO;
 import com.ym.mec.biz.dal.entity.LiveGoodsMapper;
 import org.apache.ibatis.annotations.Param;
@@ -13,4 +15,6 @@ public interface LiveGoodsMapperDao extends BaseDAO<Integer, LiveGoodsMapper> {
     void updateStatus(@Param("liveId") String liveId, @Param("liveGoodsId") Integer liveGoodsId, @Param("status") boolean status);
 
     LiveGoodsMapper findByLiveIdAndGoodsId(@Param("liveId") String liveId, @Param("liveGoodsId") Integer liveGoodsId);
+
+    List<LiveGoodsMapperDto> getLiveGoodsList(@Param("liveId") String liveId);
 }

+ 139 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/LiveGoodsMapperDto.java

@@ -0,0 +1,139 @@
+package com.ym.mec.biz.dal.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+
+import java.math.BigDecimal;
+
+public class LiveGoodsMapperDto {
+    @ApiModelProperty(value = "商品编号",required = false)
+    private Integer id;
+
+    @ApiModelProperty(value = "商品名称",required = true)
+    private String name;
+
+    @ApiModelProperty(value = "展示图片的地址",required = true)
+    private String image;
+
+    @ApiModelProperty(value = "库存",required = true)
+    private Integer stockCount;
+
+    @ApiModelProperty(value = "销量",required = false)
+    private Integer sellCount = 0;
+
+    @ApiModelProperty(value = "现价",required = true)
+    private java.math.BigDecimal currentPrice;
+
+    @ApiModelProperty(value = "原价",required = true)
+    private java.math.BigDecimal originalPrice;
+
+    @ApiModelProperty(value = "页面简介",required = false)
+    private String brief;
+
+    @ApiModelProperty(value = "商品的详细描述",required = false)
+    private String desc;
+
+    @ApiModelProperty(value = "备注",required = false)
+    private String memo;
+
+    @ApiModelProperty(value = "状态(1,上下架  0,下架)",required = false)
+    private Boolean status = false;
+
+    @ApiModelProperty(value = "直播间销售价",required = false)
+    private BigDecimal livePrice;
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getImage() {
+        return image;
+    }
+
+    public void setImage(String image) {
+        this.image = image;
+    }
+
+    public Integer getStockCount() {
+        return stockCount;
+    }
+
+    public void setStockCount(Integer stockCount) {
+        this.stockCount = stockCount;
+    }
+
+    public Integer getSellCount() {
+        return sellCount;
+    }
+
+    public void setSellCount(Integer sellCount) {
+        this.sellCount = sellCount;
+    }
+
+    public BigDecimal getCurrentPrice() {
+        return currentPrice;
+    }
+
+    public void setCurrentPrice(BigDecimal currentPrice) {
+        this.currentPrice = currentPrice;
+    }
+
+    public BigDecimal getOriginalPrice() {
+        return originalPrice;
+    }
+
+    public void setOriginalPrice(BigDecimal originalPrice) {
+        this.originalPrice = originalPrice;
+    }
+
+    public String getBrief() {
+        return brief;
+    }
+
+    public void setBrief(String brief) {
+        this.brief = brief;
+    }
+
+    public String getDesc() {
+        return desc;
+    }
+
+    public void setDesc(String desc) {
+        this.desc = desc;
+    }
+
+    public String getMemo() {
+        return memo;
+    }
+
+    public void setMemo(String memo) {
+        this.memo = memo;
+    }
+
+    public Boolean getStatus() {
+        return status;
+    }
+
+    public void setStatus(Boolean status) {
+        this.status = status;
+    }
+
+    public BigDecimal getLivePrice() {
+        return livePrice;
+    }
+
+    public void setLivePrice(BigDecimal livePrice) {
+        this.livePrice = livePrice;
+    }
+}

+ 27 - 32
mec-biz/src/main/java/com/ym/mec/biz/service/impl/LiveGoodsMapperServiceImpl.java

@@ -1,25 +1,22 @@
 package com.ym.mec.biz.service.impl;
 
-import com.ym.mec.biz.dal.dao.ImLiveBroadcastRoomDao;
-import com.ym.mec.biz.dal.dao.LiveGoodsDao;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.ym.mec.biz.dal.dao.LiveGoodsMapperDao;
 import com.ym.mec.biz.dal.entity.ImLiveBroadcastRoom;
-import com.ym.mec.biz.dal.entity.ImLiveBroadcastRoomData;
-import com.ym.mec.biz.dal.entity.LiveGoods;
+import com.ym.mec.biz.dal.entity.LiveGoodsMapper;
 import com.ym.mec.biz.service.ImLiveBroadcastRoomService;
-import com.ym.mec.biz.service.SysMessageService;
+import com.ym.mec.biz.service.LiveGoodsMapperService;
 import com.ym.mec.common.dal.BaseDAO;
+import com.ym.mec.common.entity.ImRoomMessage;
 import com.ym.mec.common.exception.BizException;
-import org.springframework.beans.factory.annotation.Autowired;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
-import com.ym.mec.biz.dal.entity.LiveGoodsMapper;
-import com.ym.mec.biz.service.LiveGoodsMapperService;
-import com.ym.mec.biz.dal.dao.LiveGoodsMapperDao;
+import com.ym.mec.im.ImFeignService;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.util.List;
 import java.util.Optional;
-import java.util.stream.Collectors;
 
 @Service
 public class LiveGoodsMapperServiceImpl extends BaseServiceImpl<Integer, LiveGoodsMapper>  implements LiveGoodsMapperService {
@@ -27,9 +24,7 @@ public class LiveGoodsMapperServiceImpl extends BaseServiceImpl<Integer, LiveGoo
 	@Autowired
 	private LiveGoodsMapperDao liveGoodsMapperDao;
 	@Autowired
-	private SysMessageService sysMessageService;
-	@Autowired
-	private LiveGoodsDao liveGoodsDao;
+	private ImFeignService imFeignService;
 	@Autowired
 	private ImLiveBroadcastRoomService imLiveBroadcastRoomService;
 
@@ -50,23 +45,29 @@ public class LiveGoodsMapperServiceImpl extends BaseServiceImpl<Integer, LiveGoo
 	@Transactional(rollbackFor = Exception.class)
 	public void upGoods(Integer liveGoodsId, String liveId) {
 		liveGoodsMapperDao.updateStatus(liveId,liveGoodsId,true);
-		LiveGoods liveGoods = Optional.of(liveGoodsDao.get(liveGoodsId)).
-				orElseThrow(() -> new RuntimeException("商品不存在"));
-		ImLiveBroadcastRoom imLiveBroadcastRoom = Optional.of(imLiveBroadcastRoomService.getById(liveId)).
+		ImLiveBroadcastRoom imLiveBroadcastRoom = Optional
+				.of(imLiveBroadcastRoomService.getBaseMapper().selectOne(new QueryWrapper<ImLiveBroadcastRoom>().eq("room_uid_",liveId))).
 				orElseThrow(() -> new RuntimeException("直播间不存在"));
 		//通知直播间商品上架
-		sysMessageService.batchSendImGroupMessage(liveGoods.getName() + "已上架",
-				imLiveBroadcastRoom.getSpeakerId().toString(),"",
-				new String[]{imLiveBroadcastRoom.getId().toString()},"DY:LIVE_GOODS_UP");
+		this.publishRoomMsg(imLiveBroadcastRoom,ImRoomMessage.LIVE_GOODS_UP);
+	}
+
+	private void publishRoomMsg(ImLiveBroadcastRoom imLiveBroadcastRoom,String msgType) {
+		ImRoomMessage message = new ImRoomMessage();
+		message.setIsIncludeSender(1);
+		message.setObjectName(msgType);
+		message.setToChatroomId(imLiveBroadcastRoom.getRoomUid());
+		message.setFromUserId(imLiveBroadcastRoom.getSpeakerId().toString());
+		message.setContent(liveGoodsMapperDao.getLiveGoodsList(imLiveBroadcastRoom.getRoomUid()));
+		imFeignService.publishRoomMsg(message);
 	}
 
 	@Override
 	@Transactional(rollbackFor = Exception.class)
 	public void downGoods(Integer liveGoodsId, String liveId){
-		ImLiveBroadcastRoom imLiveBroadcastRoom = Optional.of(imLiveBroadcastRoomService.getById(liveId)).
+		ImLiveBroadcastRoom imLiveBroadcastRoom = Optional
+				.of(imLiveBroadcastRoomService.getBaseMapper().selectOne(new QueryWrapper<ImLiveBroadcastRoom>().eq("room_uid_",liveId))).
 				orElseThrow(() -> new RuntimeException("直播间不存在"));
-		LiveGoods liveGoods = Optional.of(liveGoodsDao.get(liveGoodsId)).
-				orElseThrow(() -> new RuntimeException("商品不存在"));
 		LiveGoodsMapper liveGoodsMapper = Optional.of(liveGoodsMapperDao.findByLiveIdAndGoodsId(liveId, liveGoodsId)).
 				orElseThrow(() -> new RuntimeException("直播间不存在该商品"));
 		if(!liveGoodsMapper.getStatus()){
@@ -75,28 +76,22 @@ public class LiveGoodsMapperServiceImpl extends BaseServiceImpl<Integer, LiveGoo
 		//下架直播间商品
 		liveGoodsMapperDao.updateStatus(liveId,liveGoodsId,false);
 		//通知直播间,商品下架
-		sysMessageService.batchSendImGroupMessage(liveGoods.getName() + "已下架",
-				imLiveBroadcastRoom.getSpeakerId().toString(),"",
-				new String[]{imLiveBroadcastRoom.getId().toString()},"DY:LIVE_GOODS_DOWN");
+		this.publishRoomMsg(imLiveBroadcastRoom,ImRoomMessage.LIVE_GOODS_DOWN);
 	}
 
 	@Override
 	@Transactional(rollbackFor = Exception.class)
 	public void downGoods(Integer liveGoodsId){
-		LiveGoods liveGoods = Optional.of(liveGoodsDao.get(liveGoodsId)).
-				orElseThrow(() -> new RuntimeException("商品不存在"));
 		List<LiveGoodsMapper> liveGoodsMappers = liveGoodsMapperDao.findByLiveGoodsIdAndStatus(liveGoodsId,true);
 		if(liveGoodsMappers.size()>0){
 			//下架直播间商品
 			liveGoodsMapperDao.updateStatus(null,liveGoodsId,false);
 			//通知直播间,商品下架
-			String messageContent = liveGoods.getName() + "已下架";
 			for (LiveGoodsMapper liveGoodsMapper : liveGoodsMappers) {
-				ImLiveBroadcastRoom imLiveBroadcastRoom = Optional.of(imLiveBroadcastRoomService.getById(liveGoodsMapper.getLiveId())).
+				ImLiveBroadcastRoom imLiveBroadcastRoom = Optional
+						.of(imLiveBroadcastRoomService.getBaseMapper().selectOne(new QueryWrapper<ImLiveBroadcastRoom>().eq("room_uid_",liveGoodsMapper.getLiveId()))).
 						orElseThrow(() -> new RuntimeException("直播间不存在"));
-				sysMessageService.batchSendImGroupMessage(messageContent,
-						imLiveBroadcastRoom.getSpeakerId().toString(),"",
-						new String[]{imLiveBroadcastRoom.getId().toString()},"DY:LIVE_GOODS_DOWN");
+				this.publishRoomMsg(imLiveBroadcastRoom,ImRoomMessage.LIVE_GOODS_DOWN);
 			}
 		}
 	}

+ 21 - 0
mec-biz/src/main/resources/config/mybatis/LiveGoodsMapperMapper.xml

@@ -82,4 +82,25 @@
 	<select id="findByLiveIdAndGoodsId" resultMap="LiveGoodsMapper">
 		SELECT * FROM live_goods_mapper WHERE live_id_ = #{liveId} AND goods_id_ = #{goodsId}
 	</select>
+
+	<resultMap id="LiveGoodsMapperDto" type="com.ym.mec.biz.dal.dto.LiveGoodsMapperDto">
+		<result column="id_" property="id" />
+		<result column="image_" property="image" />
+		<result column="sell_count_" property="sellCount" />
+		<result column="live_price_" property="livePrice" />
+		<result column="status_" property="status" />
+		<result column="name_" property="name" />
+		<result column="original_price_" property="originalPrice" />
+		<result column="current_price_" property="currentPrice" />
+		<result column="brief_" property="brief" />
+		<result column="desc_" property="desc" />
+		<result column="memo_" property="memo" />
+	</resultMap>
+	<select id="getLiveGoodsList" resultMap="LiveGoodsMapperDto">
+		SELECT lg.id_,lg.image_,lgm.sell_count_,lgm.live_price_,
+		       lgm.status_,lg.name_,lg.original_price_,lg.current_price_,lg.brief_,lg.desc_,lg.memo_
+		FROM live_goods_mapper lgm
+		LEFT JOIN live_goods lg ON lgm.goods_id_ = lg.id_
+		WHERE lgm.live_id_ = #{liveId}
+	</select>
 </mapper>

+ 6 - 0
mec-common/common-core/src/main/java/com/ym/mec/common/entity/ImRoomMessage.java

@@ -15,6 +15,12 @@ public class ImRoomMessage extends BaseMessage {
     //objectName 类型-观看者数量-该消息只有主播端接
     public static final String MEMBER_COUNT = "RC:Chatroom:MemberCountUp";
 
+    //objectName 类型-商品上架
+    public static final String LIVE_GOODS_UP = "DY:LIVE_GOODS_UP";
+
+    //objectName 类型-商品下架
+    public static final String LIVE_GOODS_DOWN = "DY:LIVE_GOODS_DOWN";
+
     /**
      * <p>必传
      * 消息类型