diff --git a/buyer-api/src/main/java/cn/lili/controller/other/broadcast/StudioController.java b/buyer-api/src/main/java/cn/lili/controller/other/broadcast/StudioController.java new file mode 100644 index 00000000..83d96f3b --- /dev/null +++ b/buyer-api/src/main/java/cn/lili/controller/other/broadcast/StudioController.java @@ -0,0 +1,43 @@ +package cn.lili.controller.other.broadcast; + +import cn.lili.common.enums.ResultUtil; +import cn.lili.common.utils.PageUtil; +import cn.lili.common.vo.PageVO; +import cn.lili.common.vo.ResultMessage; +import cn.lili.modules.broadcast.entity.dos.Studio; +import cn.lili.modules.broadcast.service.StudioService; +import com.baomidou.mybatisplus.core.metadata.IPage; +import io.swagger.annotations.Api; +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.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * 买家端,直播间接口 + * + * @author Bulbasaur + * @date: 2021/5/20 12:03 下午 + */ +@RestController +@Api(tags = "买家端,直播间接口") +@RequestMapping("/buyer/broadcast/studio") +public class StudioController { + + @Autowired + private StudioService studioService; + + @ApiOperation(value = "获取店铺直播间列表") + @GetMapping + public ResultMessage> page(PageVO pageVO) { + return ResultUtil.data(studioService.page(PageUtil.initPage(pageVO))); + } + + @ApiOperation(value = "获取店铺直播间回放地址") + @GetMapping("/getLiveInfo/{roomId}") + public ResultMessage getLiveInfo(Integer roomId){ + return ResultUtil.data(studioService.getLiveInfo(roomId)); + } + +} diff --git a/consumer/src/main/java/cn/lili/timetask/handler/impl/broadcast/BroadcastExecute.java b/consumer/src/main/java/cn/lili/timetask/handler/impl/broadcast/BroadcastExecute.java new file mode 100644 index 00000000..9982d57d --- /dev/null +++ b/consumer/src/main/java/cn/lili/timetask/handler/impl/broadcast/BroadcastExecute.java @@ -0,0 +1,25 @@ +package cn.lili.timetask.handler.impl.broadcast; + +import cn.lili.modules.broadcast.service.CommodityService; +import cn.lili.timetask.handler.EveryHourExecute; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * 小程序直播状态获取 + * + * @author Bulbasaur + * @date: 2021/5/20 2:52 下午 + */ +@Component +public class BroadcastExecute implements EveryHourExecute { + + @Autowired + private CommodityService commodityService; + + @Override + public void execute() { + //同步直播商品状态 + commodityService.getGoodsWareHouse(); + } +} diff --git a/framework/src/main/java/cn/lili/modules/broadcast/entity/dos/Commodity.java b/framework/src/main/java/cn/lili/modules/broadcast/entity/dos/Commodity.java index 72fd6f94..da71b825 100644 --- a/framework/src/main/java/cn/lili/modules/broadcast/entity/dos/Commodity.java +++ b/framework/src/main/java/cn/lili/modules/broadcast/entity/dos/Commodity.java @@ -22,8 +22,8 @@ import javax.persistence.Table; @Table(name = "li_commodity") public class Commodity extends BaseEntity { - @ApiModelProperty(value = "图片mediaID") - private String coverImgUrl; + @ApiModelProperty(value = "图片") + private String goodsImage; @ApiModelProperty(value = "商品名称") private String name; diff --git a/framework/src/main/java/cn/lili/modules/broadcast/entity/dos/Studio.java b/framework/src/main/java/cn/lili/modules/broadcast/entity/dos/Studio.java index 19ef6180..9f90bb4d 100644 --- a/framework/src/main/java/cn/lili/modules/broadcast/entity/dos/Studio.java +++ b/framework/src/main/java/cn/lili/modules/broadcast/entity/dos/Studio.java @@ -70,16 +70,19 @@ public class Studio extends BaseEntity { @ApiModelProperty(value = "封面图") private String feedsImg; - /** - * 回放视频链接 - */ + @ApiModelProperty(value = "回放视频链接") private String mediaUrl; - @ApiModelProperty(value = "房间ID") private Integer roomId; @ApiModelProperty(value = "店铺ID") private String storeId; + + @ApiModelProperty(value = "直播间商品数量") + private Integer roomGoodsNum; + + @ApiModelProperty(value = "直播间商品(最多展示两个商品:name/goodsImage)") + private String roomGoodsList; } diff --git a/framework/src/main/java/cn/lili/modules/broadcast/entity/dto/SimpleCommodity.java b/framework/src/main/java/cn/lili/modules/broadcast/entity/dto/SimpleCommodity.java new file mode 100644 index 00000000..0b24cc76 --- /dev/null +++ b/framework/src/main/java/cn/lili/modules/broadcast/entity/dto/SimpleCommodity.java @@ -0,0 +1,18 @@ +package cn.lili.modules.broadcast.entity.dto; + +import io.swagger.annotations.ApiModelProperty; + +/** + * 用于直播间前台使用的直播间商品DTO + * + * @author Bulbasaur + * @date: 2021/5/20 2:34 下午 + */ +public class SimpleCommodity { + + @ApiModelProperty(value = "图片") + private String goodsImage; + + @ApiModelProperty(value = "商品名称") + private String name; +} diff --git a/framework/src/main/java/cn/lili/modules/broadcast/entity/vos/StudioVO.java b/framework/src/main/java/cn/lili/modules/broadcast/entity/vos/StudioVO.java index c20b29d4..b058c6bb 100644 --- a/framework/src/main/java/cn/lili/modules/broadcast/entity/vos/StudioVO.java +++ b/framework/src/main/java/cn/lili/modules/broadcast/entity/vos/StudioVO.java @@ -18,4 +18,5 @@ public class StudioVO extends Studio { @ApiModelProperty(value = "直播间商品列表") private List CommodityList; + } diff --git a/framework/src/main/java/cn/lili/modules/broadcast/mapper/CommodityMapper.java b/framework/src/main/java/cn/lili/modules/broadcast/mapper/CommodityMapper.java index 7578eb2e..530d59d6 100644 --- a/framework/src/main/java/cn/lili/modules/broadcast/mapper/CommodityMapper.java +++ b/framework/src/main/java/cn/lili/modules/broadcast/mapper/CommodityMapper.java @@ -1,6 +1,7 @@ package cn.lili.modules.broadcast.mapper; import cn.lili.modules.broadcast.entity.dos.Commodity; +import cn.lili.modules.broadcast.entity.dto.SimpleCommodity; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Select; @@ -14,7 +15,13 @@ import java.util.List; */ public interface CommodityMapper extends BaseMapper { - @Select("SELECT live_goods_id FROM li_commodity WHERE audit_status='0' or audit_status='1'") - List getAuditCommodity(); + @Select("SELECT live_goods_id FROM li_commodity WHERE audit_status='0' or audit_status='1' AND store_id =#{storeId}") + List getAuditCommodity(String storeId); + + @Select("SELECT * FROM li_commodity c WINNER JOIN li_studio_commodity sc ON sc.goods_id = c.live_goods_id WHERE sc.room_id =#{roomId}") + List getCommodityByRoomId(Integer roomId); + + @Select("SELECT name,goods_image FROM li_commodity c WINNER JOIN li_studio_commodity sc ON sc.goods_id = c.live_goods_id WHERE sc.room_id =#{roomId}") + List getSimpleCommodityByRoomId(Integer roomId); } \ No newline at end of file diff --git a/framework/src/main/java/cn/lili/modules/broadcast/service/CommodityService.java b/framework/src/main/java/cn/lili/modules/broadcast/service/CommodityService.java index b227be65..310687be 100644 --- a/framework/src/main/java/cn/lili/modules/broadcast/service/CommodityService.java +++ b/framework/src/main/java/cn/lili/modules/broadcast/service/CommodityService.java @@ -27,5 +27,5 @@ public interface CommodityService extends IService { /** * 查询微信小程序直播商品审核状态 */ - void getGoodsWarehouse(); + void getGoodsWareHouse(); } diff --git a/framework/src/main/java/cn/lili/modules/broadcast/service/StudioService.java b/framework/src/main/java/cn/lili/modules/broadcast/service/StudioService.java index 1a476a67..b1eb0fc4 100644 --- a/framework/src/main/java/cn/lili/modules/broadcast/service/StudioService.java +++ b/framework/src/main/java/cn/lili/modules/broadcast/service/StudioService.java @@ -1,6 +1,7 @@ package cn.lili.modules.broadcast.service; import cn.lili.modules.broadcast.entity.dos.Studio; +import cn.lili.modules.broadcast.entity.vos.StudioVO; import com.baomidou.mybatisplus.extension.service.IService; /** @@ -20,12 +21,19 @@ public interface StudioService extends IService { */ Boolean create(Studio studio); + /** + * 获取直播间信息 + * @param id 直播间ID + * @return 直播间VO + */ + StudioVO getStudioVO(String id); + /** * 获取直播间回放 * @param roomId 房间ID * @return 直播间回放地址 */ - String getLiveInfo(String roomId); + String getLiveInfo(Integer roomId); /** * 推送商品 diff --git a/framework/src/main/java/cn/lili/modules/broadcast/serviceimpl/CommodityServiceImpl.java b/framework/src/main/java/cn/lili/modules/broadcast/serviceimpl/CommodityServiceImpl.java index 23be52ca..1e524984 100644 --- a/framework/src/main/java/cn/lili/modules/broadcast/serviceimpl/CommodityServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/broadcast/serviceimpl/CommodityServiceImpl.java @@ -28,7 +28,7 @@ public class CommodityServiceImpl extends ServiceImpl goodsIdList=this.baseMapper.getAuditCommodity(); + List goodsIdList = this.baseMapper.getAuditCommodity(UserContext.getCurrentUser().getStoreId()); //同步状态 - JSONObject json =wechatLivePlayerUtil.deleteGoods(goodsIdList); + JSONObject json = wechatLivePlayerUtil.getGoodsWareHouse(goodsIdList); //修改状态 - List> list=(List)json.get("goods"); - for (Map map:list){ + List> list = (List) json.get("goods"); + for (Map map : list) { //修改审核状态 this.update(this.lambdaUpdate() - .eq(Commodity::getLiveGoodsId,map.get("goods_id")) - .set(Commodity::getAuditStatus,map.get("audit_status"))); + .eq(Commodity::getLiveGoodsId, map.get("goods_id")) + .set(Commodity::getAuditStatus, map.get("audit_status"))); } } diff --git a/framework/src/main/java/cn/lili/modules/broadcast/serviceimpl/StudioServiceImpl.java b/framework/src/main/java/cn/lili/modules/broadcast/serviceimpl/StudioServiceImpl.java index 4a49cd13..db466178 100644 --- a/framework/src/main/java/cn/lili/modules/broadcast/serviceimpl/StudioServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/broadcast/serviceimpl/StudioServiceImpl.java @@ -1,10 +1,14 @@ package cn.lili.modules.broadcast.serviceimpl; +import cn.hutool.json.JSONUtil; import cn.lili.common.enums.ResultCode; import cn.lili.common.exception.ServiceException; import cn.lili.common.security.context.UserContext; +import cn.lili.common.utils.BeanUtil; import cn.lili.modules.broadcast.entity.dos.Studio; import cn.lili.modules.broadcast.entity.dos.StudioCommodity; +import cn.lili.modules.broadcast.entity.vos.StudioVO; +import cn.lili.modules.broadcast.mapper.CommodityMapper; import cn.lili.modules.broadcast.mapper.StudioMapper; import cn.lili.modules.broadcast.service.StudioCommodityService; import cn.lili.modules.broadcast.service.StudioService; @@ -14,6 +18,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import javax.annotation.Resource; + /** * 小程序直播间业务层实现 * @@ -21,22 +27,24 @@ import org.springframework.stereotype.Service; * @date: 2021/5/17 10:04 上午 */ @Service -public class StudioServiceImpl extends ServiceImpl implements StudioService { +public class StudioServiceImpl extends ServiceImpl implements StudioService { @Autowired private WechatLivePlayerUtil wechatLivePlayerUtil; @Autowired private StudioCommodityService studioCommodityService; + @Resource + private CommodityMapper commodityMapper; @Override public Boolean create(Studio studio) { try { //创建小程序直播 - Integer roomId=wechatLivePlayerUtil.create(studio); + Integer roomId = wechatLivePlayerUtil.create(studio); studio.setRoomId(roomId); studio.setStoreId(UserContext.getCurrentUser().getStoreId()); return this.save(studio); - }catch (Exception e){ + } catch (Exception e) { e.printStackTrace(); throw new ServiceException(ResultCode.ERROR); } @@ -44,13 +52,23 @@ public class StudioServiceImpl extends ServiceImpl implem } @Override - public String getLiveInfo(String roomId) { - Studio studio=this.getByRoomId(roomId); + public StudioVO getStudioVO(String id) { + StudioVO studioVO = new StudioVO(); + //获取直播间信息 + BeanUtil.copyProperties(this.getById(id), studioVO); + //获取直播间商品信息 + studioVO.setCommodityList(commodityMapper.getCommodityByRoomId(studioVO.getRoomId())); + return studioVO; + } + + @Override + public String getLiveInfo(Integer roomId) { + Studio studio = this.getByRoomId(roomId); //获取直播间并判断回放内容是否为空,如果为空则获取直播间回放并保存 - if(studio.getMediaUrl()!=null){ + if (studio.getMediaUrl() != null) { return studio.getMediaUrl(); - }else{ - String mediaUrl= wechatLivePlayerUtil.getLiveInfo(roomId); + } else { + String mediaUrl = wechatLivePlayerUtil.getLiveInfo(roomId); studio.setMediaUrl(mediaUrl); this.save(studio); return mediaUrl; @@ -60,8 +78,16 @@ public class StudioServiceImpl extends ServiceImpl implem @Override public Boolean push(Integer roomId, Integer goodsId) { //调用微信接口添加直播间商品并进行记录 - if(wechatLivePlayerUtil.pushGoods(roomId,goodsId)){ - return studioCommodityService.save(new StudioCommodity(roomId,goodsId)); + if (wechatLivePlayerUtil.pushGoods(roomId, goodsId)) { + studioCommodityService.save(new StudioCommodity(roomId, goodsId)); + //添加直播间商品数量 + Studio studio = this.getByRoomId(roomId); + studio.setRoomGoodsNum(studio.getRoomGoodsNum() != null ? studio.getRoomGoodsNum() + 1 : 1); + //设置直播间默认的商品(前台展示)只展示两个 + if(studio.getRoomGoodsNum()<3){ + studio.setRoomGoodsList(JSONUtil.toJsonStr(commodityMapper.getSimpleCommodityByRoomId(roomId)));; + } + return this.updateById(studio); } return false; } @@ -69,18 +95,27 @@ public class StudioServiceImpl extends ServiceImpl implem @Override public Boolean goodsDeleteInRoom(Integer roomId, Integer goodsId) { //调用微信接口删除直播间商品并进行记录 - if(wechatLivePlayerUtil.goodsDeleteInRoom(roomId,goodsId)){ - return studioCommodityService.remove(new QueryWrapper().eq("room_id",roomId).eq("goods_id",goodsId)); + if (wechatLivePlayerUtil.goodsDeleteInRoom(roomId, goodsId)) { + studioCommodityService.remove(new QueryWrapper().eq("room_id", roomId).eq("goods_id", goodsId)); + //减少直播间商品数量 + Studio studio = this.getByRoomId(roomId); + studio.setRoomGoodsNum(studio.getRoomGoodsNum() - 1); + //设置直播间默认的商品(前台展示)只展示两个 + if(studio.getRoomGoodsNum()<3){ + studio.setRoomGoodsList(JSONUtil.toJsonStr(commodityMapper.getSimpleCommodityByRoomId(roomId)));; + } + return this.updateById(studio); } return false; } /** * 根据直播间ID获取直播间 + * * @param roomId 直播间ID * @return 直播间 */ - private Studio getByRoomId(String roomId){ - return this.getOne(this.lambdaQuery().eq(Studio::getRoomId,roomId)) ; + private Studio getByRoomId(Integer roomId) { + return this.getOne(this.lambdaQuery().eq(Studio::getRoomId, roomId)); } } diff --git a/framework/src/main/java/cn/lili/modules/broadcast/util/WechatLivePlayerUtil.java b/framework/src/main/java/cn/lili/modules/broadcast/util/WechatLivePlayerUtil.java index 717d9c6a..4852a419 100644 --- a/framework/src/main/java/cn/lili/modules/broadcast/util/WechatLivePlayerUtil.java +++ b/framework/src/main/java/cn/lili/modules/broadcast/util/WechatLivePlayerUtil.java @@ -83,12 +83,12 @@ public class WechatLivePlayerUtil { * @param roomId 房间ID * @return 回放地址 */ - public String getLiveInfo(String roomId) { + public String getLiveInfo(Integer roomId) { //获取token String token = wechatAccessTokenUtil.cgiAccessToken(ClientTypeEnum.WECHAT_MP); //发送url String url = "https://api.weixin.qq.com/wxa/business/getliveinfo?access_token=" + token; - Map map = new HashMap<>(); + Map map = new HashMap<>(); // 获取回放 map.put("action", "get_replay"); // 直播间ID @@ -162,7 +162,9 @@ public class WechatLivePlayerUtil { String token = wechatAccessTokenUtil.cgiAccessToken(ClientTypeEnum.WECHAT_MP); //发送url String url = "https://api.weixin.qq.com/wxaapi/broadcast/goods/add?access_token=" + token; + //新建微信商品DTO GoodsInfo goodsInfo = new GoodsInfo(commodity); + goodsInfo.setCoverImgUrl(wechatMediaUtil.uploadMedia(token,"image",commodity.getGoodsImage())); String content = HttpUtils.doPostWithJson(url, goodsInfo); JSONObject json = new JSONObject(content); log.info("微信小程序添加直播商品结果:" + content); @@ -192,7 +194,7 @@ public class WechatLivePlayerUtil { * @param goodsIdList 商品ID列表 * @return 删除结果 */ - public JSONObject deleteGoods(List goodsIdList) { + public JSONObject getGoodsWareHouse(List goodsIdList) { //获取token String token = wechatAccessTokenUtil.cgiAccessToken(ClientTypeEnum.WECHAT_MP); //发送url diff --git a/seller-api/src/main/java/cn/lili/controller/other/broadcast/StudioController.java b/seller-api/src/main/java/cn/lili/controller/other/broadcast/StudioController.java index 7d7937a6..ff3d0a57 100644 --- a/seller-api/src/main/java/cn/lili/controller/other/broadcast/StudioController.java +++ b/seller-api/src/main/java/cn/lili/controller/other/broadcast/StudioController.java @@ -6,7 +6,6 @@ import cn.lili.common.exception.ServiceException; import cn.lili.common.utils.PageUtil; import cn.lili.common.vo.PageVO; import cn.lili.common.vo.ResultMessage; -import cn.lili.modules.base.entity.enums.ClientTypeEnum; import cn.lili.modules.broadcast.entity.dos.Studio; import cn.lili.modules.broadcast.service.StudioService; import cn.lili.modules.message.util.WechatAccessTokenUtil; @@ -83,10 +82,4 @@ public class StudioController { } throw new ServiceException(ResultCode.ERROR); } - - @ApiOperation(value = "获取素材,调用接口凭证") - @PutMapping(value = "/getCgiAccessToken") - public ResultMessage getCgiAccessToken() { - return ResultUtil.data(wechatAccessTokenUtil.cgiAccessToken(ClientTypeEnum.WECHAT_MP)); - } }