同步直播状态、直播间新增商品数量
This commit is contained in:
parent
2326a5963f
commit
a8a6506516
@ -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<IPage<Studio>> page(PageVO pageVO) {
|
||||
return ResultUtil.data(studioService.page(PageUtil.initPage(pageVO)));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取店铺直播间回放地址")
|
||||
@GetMapping("/getLiveInfo/{roomId}")
|
||||
public ResultMessage<Object> getLiveInfo(Integer roomId){
|
||||
return ResultUtil.data(studioService.getLiveInfo(roomId));
|
||||
}
|
||||
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
@ -18,4 +18,5 @@ public class StudioVO extends Studio {
|
||||
|
||||
@ApiModelProperty(value = "直播间商品列表")
|
||||
private List<Commodity> CommodityList;
|
||||
|
||||
}
|
||||
|
@ -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<Commodity> {
|
||||
|
||||
@Select("SELECT live_goods_id FROM li_commodity WHERE audit_status='0' or audit_status='1'")
|
||||
List<String> getAuditCommodity();
|
||||
@Select("SELECT live_goods_id FROM li_commodity WHERE audit_status='0' or audit_status='1' AND store_id =#{storeId}")
|
||||
List<String> 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<Commodity> 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<SimpleCommodity> getSimpleCommodityByRoomId(Integer roomId);
|
||||
|
||||
}
|
@ -27,5 +27,5 @@ public interface CommodityService extends IService<Commodity> {
|
||||
/**
|
||||
* 查询微信小程序直播商品审核状态
|
||||
*/
|
||||
void getGoodsWarehouse();
|
||||
void getGoodsWareHouse();
|
||||
}
|
||||
|
@ -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<Studio> {
|
||||
*/
|
||||
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);
|
||||
|
||||
/**
|
||||
* 推送商品
|
||||
|
@ -28,7 +28,7 @@ public class CommodityServiceImpl extends ServiceImpl<CommodityMapper, Commodity
|
||||
|
||||
@Override
|
||||
public boolean addCommodity(Commodity commodity) {
|
||||
JSONObject json =wechatLivePlayerUtil.addGoods(commodity);
|
||||
JSONObject json = wechatLivePlayerUtil.addGoods(commodity);
|
||||
commodity.setLiveGoodsId(Convert.toInt(json.getStr("goodsId")));
|
||||
commodity.setAuditId(json.getStr("auditId"));
|
||||
commodity.setStoreId(UserContext.getCurrentUser().getStoreId());
|
||||
@ -37,26 +37,26 @@ public class CommodityServiceImpl extends ServiceImpl<CommodityMapper, Commodity
|
||||
|
||||
@Override
|
||||
public boolean deleteCommodity(String goodsId) {
|
||||
JSONObject json =wechatLivePlayerUtil.deleteGoods(goodsId);
|
||||
if(json.getStr("errcode").equals("0")){
|
||||
return this.remove(this.lambdaQuery().eq(Commodity::getLiveGoodsId,goodsId));
|
||||
JSONObject json = wechatLivePlayerUtil.deleteGoods(goodsId);
|
||||
if (json.getStr("errcode").equals("0")) {
|
||||
return this.remove(this.lambdaQuery().eq(Commodity::getLiveGoodsId, goodsId));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getGoodsWarehouse() {
|
||||
public void getGoodsWareHouse() {
|
||||
//查询审核中的商品
|
||||
List<String> goodsIdList=this.baseMapper.getAuditCommodity();
|
||||
List<String> goodsIdList = this.baseMapper.getAuditCommodity(UserContext.getCurrentUser().getStoreId());
|
||||
//同步状态
|
||||
JSONObject json =wechatLivePlayerUtil.deleteGoods(goodsIdList);
|
||||
JSONObject json = wechatLivePlayerUtil.getGoodsWareHouse(goodsIdList);
|
||||
//修改状态
|
||||
List<Map<String,String>> list=(List)json.get("goods");
|
||||
for (Map<String,String> map:list){
|
||||
List<Map<String, String>> list = (List) json.get("goods");
|
||||
for (Map<String, String> 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")));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<StudioMapper, Studio> implements StudioService {
|
||||
public class StudioServiceImpl extends ServiceImpl<StudioMapper, Studio> 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<StudioMapper, Studio> 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<StudioMapper, Studio> 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<StudioMapper, Studio> implem
|
||||
@Override
|
||||
public Boolean goodsDeleteInRoom(Integer roomId, Integer goodsId) {
|
||||
//调用微信接口删除直播间商品并进行记录
|
||||
if(wechatLivePlayerUtil.goodsDeleteInRoom(roomId,goodsId)){
|
||||
return studioCommodityService.remove(new QueryWrapper<StudioCommodity>().eq("room_id",roomId).eq("goods_id",goodsId));
|
||||
if (wechatLivePlayerUtil.goodsDeleteInRoom(roomId, goodsId)) {
|
||||
studioCommodityService.remove(new QueryWrapper<StudioCommodity>().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));
|
||||
}
|
||||
}
|
||||
|
@ -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<String, String> map = new HashMap<>();
|
||||
Map<String, Object> 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<String> goodsIdList) {
|
||||
public JSONObject getGoodsWareHouse(List<String> goodsIdList) {
|
||||
//获取token
|
||||
String token = wechatAccessTokenUtil.cgiAccessToken(ClientTypeEnum.WECHAT_MP);
|
||||
//发送url
|
||||
|
@ -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<Object> getCgiAccessToken() {
|
||||
return ResultUtil.data(wechatAccessTokenUtil.cgiAccessToken(ClientTypeEnum.WECHAT_MP));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user