package com.yc.sdk.shopping.action.jiazhuang;
|
|
import java.text.ParseException;
|
import java.text.SimpleDateFormat;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.stream.Collectors;
|
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpSession;
|
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.context.annotation.Scope;
|
import org.springframework.dao.DataAccessException;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import com.google.gson.JsonArray;
|
import com.google.gson.JsonObject;
|
import com.yc.action.BaseAction;
|
import com.yc.entity.DataSourceEntity;
|
import com.yc.exception.ApplicationException;
|
import com.yc.multiData.MultiDataSource;
|
import com.yc.multiData.SpObserver;
|
import com.yc.sdk.miniapp.entity.LiveGoodsEntity;
|
import com.yc.sdk.miniapp.entity.LiveReplayVideoEntity;
|
import com.yc.sdk.miniapp.entity.LiveRoomEntity;
|
import com.yc.sdk.miniapp.entity.LiveRoomEntity.RoomInfo;
|
import com.yc.sdk.miniapp.service.MaLiveIfc;
|
import com.yc.sdk.shopping.action.api.LiveRoomVideo;
|
import com.yc.sdk.shopping.action.api.ShopCcCode;
|
import com.yc.sdk.shopping.entity.CreateLiveRoomParameterStep1Entity;
|
import com.yc.sdk.shopping.entity.CreateLiveRoomParameterStep2Entity;
|
import com.yc.sdk.shopping.entity.CreateLiveRoomParameterStep3Entity;
|
import com.yc.sdk.shopping.entity.CreateLiveRoomResultEntity;
|
import com.yc.sdk.shopping.entity.PanicBuyingEntity;
|
import com.yc.sdk.shopping.entity.SettingEntity;
|
import com.yc.sdk.shopping.entity.ShopCcCodeEntity;
|
import com.yc.sdk.shopping.service.SettingIfc;
|
import com.yc.sdk.shopping.service.panicBuying.PanicBuyingIfc;
|
import com.yc.sdk.shopping.util.SettingKey;
|
import com.yc.sdk.shopping.util.StringLengthUtil;
|
import com.yc.utils.SessionKey;
|
|
import me.chanjar.weixin.common.error.WxErrorException;
|
|
import com.yc.factory.FactoryBean;
|
|
@Controller
|
@Scope("prototype")
|
@RequestMapping("/shopping/panicBuyingLive/")
|
public class PanicBuyingLive extends BaseAction{
|
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
@Autowired
|
MaLiveIfc maLiveIfc ;
|
|
@Autowired
|
SettingIfc settingIfc;
|
@Autowired
|
PanicBuyingIfc panicBuyingIfc;
|
|
|
|
/**
|
* 获取我的直播间列信息(包含已经创建和未创建的,用于新建直接间)
|
* @param request
|
* @param response
|
*/
|
@GetMapping("/getLiveRoomListForOpenId.do")
|
public void getLiveRoomListForOpenId(HttpServletRequest request, HttpServletResponse response) {
|
HttpSession session=request.getSession();
|
JsonObject json = new JsonObject();
|
JsonObject errJson = new JsonObject();
|
//String roomId = request.getParameter("roomid") ;
|
//String docCode = request.getParameter(SettingKey.DOCCODE) ;
|
String hostUrl = SettingKey.getHostUrl(request);
|
|
//String userCode = (String) session.getAttribute(SessionKey.HRCODE) ;
|
String openId = (session.getAttribute(SessionKey.WEIXIN_OPENID) == null ? "": (String) session.getAttribute(SessionKey.WEIXIN_OPENID));
|
try {
|
DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap( request) ;
|
SpObserver.setDBtoInstance("_"+dataSourceEntity.getDbId());//切换数据源
|
|
//刷新房间及状态信息 ,不需要刷新,因为设置了定时刷新功能
|
//refreshLiveRoom(dataSourceEntity);
|
|
//SettingEntity settingEntity = settingIfc.getSettingEntity(request) ;
|
|
//取网店 shopcccode
|
//ShopCcCodeEntity shopCcCodeEntity = ShopCcCode.getShopCcCode(settingEntity,request);
|
|
//重新获取房间列表
|
//直播计划
|
LiveRoomEntity dataList = maLiveIfc.getLiveRoomListForOpenId(openId) ;
|
List<RoomInfo> liveList = dataList.getRoomInfo().stream().filter(s->s.getLiveStatus()==null||s.getLiveStatus().intValue()==101||s.getLiveStatus().intValue()==102).collect(Collectors.toList());
|
JsonArray liveRoomListArray = new JsonArray();
|
for (int i = 0 ; liveList!= null && i < liveList.size();i++) {
|
RoomInfo roomInfo = liveList.get(i) ;
|
|
JsonObject jsonItem = getRoomJsonObject( roomInfo, hostUrl, dataSourceEntity.getDbId());
|
liveRoomListArray.add(jsonItem) ;
|
}
|
json.add("liveList", liveRoomListArray);
|
|
//历史直播
|
List<RoomInfo> historyList = dataList.getRoomInfo().stream().filter(s->s.getLiveStatus()!=null&&s.getLiveStatus().intValue()!=101&&s.getLiveStatus().intValue()!=102).collect(Collectors.toList());
|
JsonArray historyRoomListArray = new JsonArray();
|
for (int i = 0 ; historyList!= null && i < historyList.size();i++) {
|
RoomInfo roomInfo = historyList.get(i) ;
|
|
JsonObject jsonItem = getRoomJsonObject( roomInfo, hostUrl, dataSourceEntity.getDbId());
|
historyRoomListArray.add(jsonItem) ;
|
}
|
json.add("historyList", historyRoomListArray);
|
|
|
json.addProperty("state", "success");
|
this.printJson(response, json.toString());
|
return;
|
}catch (Exception e) {
|
this.logger.error(e.getMessage(), e);
|
e.printStackTrace();
|
errJson.addProperty("warning",(e.getCause()!=null?e.getCause().getMessage(): e.getMessage())+"【/shopping/live/getLiveRoomListForMe.do】");
|
json.add("error", errJson);
|
this.printJson(response, json.toString());
|
}finally {
|
SpObserver.setDBtoInstance();
|
}
|
}
|
|
/**
|
* 获取直播间明细
|
* @param request
|
* @param response
|
*/
|
@GetMapping("/getLiveRoomDetailByDocCode.do")
|
public void getLiveRoomDetailByDocCode(HttpServletRequest request, HttpServletResponse response) {
|
//HttpSession session=request.getSession();
|
JsonObject json = new JsonObject();
|
JsonObject errJson = new JsonObject();
|
//String roomId = request.getParameter("roomid") ;
|
String docCode = request.getParameter(SettingKey.DOCCODE) ;
|
String hostUrl = SettingKey.getHostUrl(request);
|
|
//String userCode = (String) session.getAttribute(SessionKey.HRCODE) ;
|
try {
|
DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap( request) ;
|
SpObserver.setDBtoInstance("_"+dataSourceEntity.getDbId());//切换数据源
|
|
//刷新房间及状态信息 ,不需要刷新,因为设置了定时刷新功能
|
//refreshLiveRoom(dataSourceEntity);
|
|
//SettingEntity settingEntity = settingIfc.getSettingEntity(request) ;
|
|
//取网店 shopcccode
|
//ShopCcCodeEntity shopCcCodeEntity = ShopCcCode.getShopCcCode(settingEntity,request);
|
|
//重新获取房间列表
|
LiveRoomEntity liveRoomList = maLiveIfc.getLiveRoom(docCode) ;
|
JsonArray roomListArray = new JsonArray();
|
for (int i = 0 ; liveRoomList!= null && liveRoomList.getRoomInfo() != null && i < liveRoomList.getRoomInfo().size();i++) {
|
RoomInfo roomInfo = liveRoomList.getRoomInfo().get(i) ;
|
|
JsonObject jsonItem = getRoomJsonObject( roomInfo, hostUrl, dataSourceEntity.getDbId());
|
roomListArray.add(jsonItem) ;
|
}
|
json.add("list", roomListArray);
|
json.addProperty("state", "success");
|
this.printJson(response, json.toString());
|
return;
|
}catch (Exception e) {
|
this.logger.error(e.getMessage(), e);
|
e.printStackTrace();
|
errJson.addProperty("warning",(e.getCause()!=null?e.getCause().getMessage(): e.getMessage())+"【/shopping/live/getLiveRoomListForMe.do】");
|
json.add("error", errJson);
|
this.printJson(response, json.toString());
|
}finally {
|
SpObserver.setDBtoInstance();
|
}
|
}
|
|
|
|
|
|
/**
|
* 获取所有直播间信息(已经创建了的直播间)
|
* @param request
|
* @param response
|
*/
|
@GetMapping("/getLiveRoomList.do")
|
public void getLiveRoomList(HttpServletRequest request, HttpServletResponse response) {
|
HttpSession session=request.getSession();
|
JsonObject json = new JsonObject();
|
JsonObject errJson = new JsonObject();
|
String roomId = request.getParameter("roomid") ;
|
String docCode = request.getParameter(SettingKey.DOCCODE) ;
|
String hostUrl = SettingKey.getHostUrl(request);
|
|
@Deprecated
|
String isShowBannerPhotoOnHomePage = request.getParameter("isShowBannerPhotoOnHomePage") ; //是否只显示带有首页广告的直播间信息: true , false
|
|
String userCode = (String) session.getAttribute(SessionKey.HRCODE) ;
|
String isShowOwnerLiveRoom = request.getParameter("isShowOwnerLiveRoom") ; //只显示自己的直播间 ,包括没有正式创建成功的,因为没创建成功的记录可以再次创建
|
try {
|
DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap( request) ;
|
SpObserver.setDBtoInstance("_"+dataSourceEntity.getDbId());//切换数据源
|
|
//刷新房间及状态信息 ,不需要刷新,因为设置了定时刷新功能
|
//refreshLiveRoom(dataSourceEntity);
|
|
SettingEntity settingEntity = settingIfc.getSettingEntity(request) ;
|
|
//取网店 shopcccode
|
ShopCcCodeEntity shopCcCodeEntity = ShopCcCode.getShopCcCode(settingEntity,request);
|
|
//重新获取房间列表
|
LiveRoomEntity liveRoomList = maLiveIfc.getLiveRoomList(roomId==null?null:Integer.valueOf(roomId),shopCcCodeEntity.getShopCcCode(),
|
isShowBannerPhotoOnHomePage!=null&&"true".equalsIgnoreCase(isShowBannerPhotoOnHomePage),
|
isShowOwnerLiveRoom!=null&&"true".equalsIgnoreCase(isShowOwnerLiveRoom),
|
userCode,docCode) ;
|
JsonArray roomListArray = new JsonArray();
|
for (int i = 0 ; liveRoomList!= null && liveRoomList.getRoomInfo() != null && i < liveRoomList.getRoomInfo().size();i++) {
|
RoomInfo roomInfo = liveRoomList.getRoomInfo().get(i) ;
|
if (isShowOwnerLiveRoom==null||!"true".equalsIgnoreCase(isShowOwnerLiveRoom) ) {
|
if (roomInfo.getId() == null&& (docCode==null||"".equals(docCode))) {
|
continue;
|
}
|
}
|
|
JsonObject jsonItem = getRoomJsonObject( roomInfo, hostUrl, dataSourceEntity.getDbId());
|
roomListArray.add(jsonItem) ;
|
}
|
json.add("list", roomListArray);
|
json.addProperty("state", "success");
|
this.printJson(response, json.toString());
|
return;
|
}catch (Exception e) {
|
this.logger.error(e.getMessage(), e);
|
e.printStackTrace();
|
errJson.addProperty("warning",(e.getCause()!=null?e.getCause().getMessage(): e.getMessage())+"【/shopping/live/getLiveRoomList.do】");
|
json.add("error", errJson);
|
this.printJson(response, json.toString());
|
}finally {
|
SpObserver.setDBtoInstance();
|
}
|
}
|
|
|
/**
|
* 我的商品库
|
* @param request
|
* @param response
|
*/
|
@RequestMapping("/getGoodsListForMe.do")
|
public void getGoodsListForMe(HttpServletRequest request, HttpServletResponse response) {
|
HttpSession session = request.getSession();
|
JsonObject json = new JsonObject();
|
JsonObject errJson = new JsonObject();
|
String hostUrl = SettingKey.getHostUrl(request);
|
try {
|
DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap( request) ;
|
SpObserver.setDBtoInstance("_"+dataSourceEntity.getDbId());//切换数据源
|
//SettingEntity settingEntity = settingIfc.getSettingEntity(request) ;
|
|
String openId = (String)session.getAttribute(SessionKey.WEIXIN_OPENID);
|
JsonArray jsonArray = new JsonArray();
|
List<LiveGoodsEntity> list = maLiveIfc.getGoodsListForMe(openId) ;
|
for (int i = 0; list!=null&& i < list.size(); i++) {
|
LiveGoodsEntity liveGoodsEntity = list.get(i) ;
|
jsonArray.add(LiveRoomVideo.getGoodsJsonObject( liveGoodsEntity, hostUrl, dataSourceEntity.getDbId()+"") );
|
}
|
json.add("list", jsonArray);
|
this.printJson(response, json.toString());
|
return ;
|
} catch (DataAccessException e) {
|
this.logger.error(e.getMessage(), e);
|
e.printStackTrace();
|
errJson.addProperty("warning",(e.getCause()!=null?e.getCause().getMessage(): e.getMessage())+"【/shopping/live/getGoodsListForMe.do】");
|
json.add("error", errJson);
|
this.printJson(response, json.toString());
|
return ;
|
}catch (Exception e) {
|
this.logger.error(e.getMessage(), e);
|
e.printStackTrace();
|
errJson.addProperty("warning",(e.getCause()!=null?e.getCause().getMessage(): e.getMessage())+"【/shopping/live/getGoodsListForMe.do】");
|
json.add("error", errJson);
|
this.printJson(response, json.toString());
|
return ;
|
}finally {
|
SpObserver.setDBtoInstance();
|
}
|
}
|
|
|
/**
|
* 直播间商品列表
|
* @param request
|
* @param response
|
*/
|
@RequestMapping("/goodsListInRoom.do")
|
public void goodsListInRoom(HttpServletRequest request, HttpServletResponse response) {
|
//HttpSession session = request.getSession();
|
JsonObject json = new JsonObject();
|
JsonObject errJson = new JsonObject();
|
//CallBackMessage callBackMessage=new CallBackMessage();
|
String roomId = request.getParameter("roomid") ;
|
//String goodsId = request.getParameter("goodsid") ;
|
//String onSaleStr = request.getParameter("onSale") ;
|
//String nickName = request.getParameter("nickName") ;
|
//String goodsId = request.getParameter("goodsid") ;
|
if (roomId == null || "".equals(roomId) || "null".equals(roomId)) {
|
errJson.addProperty("warning","必须指定 roomid 参数【/shopping/live/goodsListInRoom.do】");
|
json.add("error", errJson);
|
this.printJson(response, json.toString());
|
return ;
|
}
|
|
String hostUrl = SettingKey.getHostUrl(request);
|
try {
|
DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap( request) ;
|
SpObserver.setDBtoInstance("_"+dataSourceEntity.getDbId());//切换数据源
|
|
List<LiveGoodsEntity> list = maLiveIfc.getGoodsListInRoom(Integer.parseInt(roomId));
|
JsonArray goodsJsonArray = new JsonArray();
|
for (int i = 0;list!=null&& i < list.size(); i++) {
|
LiveGoodsEntity liveGoodsEntity = list.get(i) ;
|
|
goodsJsonArray.add(LiveRoomVideo.getGoodsJsonObject( liveGoodsEntity, hostUrl, dataSourceEntity.getDbId()+"") );
|
|
}
|
json.add("list", goodsJsonArray);
|
|
json.addProperty("state", "success");
|
this.printJson(response, json.toString());
|
} catch (DataAccessException e) {
|
this.logger.error(e.getMessage(), e);
|
e.printStackTrace();
|
errJson.addProperty("warning",(e.getCause()!=null?e.getCause().getMessage(): e.getMessage())+"【/shopping/live/goodsListInRoom.do】");
|
json.add("error", errJson);
|
this.printJson(response, json.toString());
|
return ;
|
}catch (Exception e) {
|
this.logger.error(e.getMessage(), e);
|
e.printStackTrace();
|
errJson.addProperty("warning",(e.getCause()!=null?e.getCause().getMessage(): e.getMessage())+"【/shopping/live/goodsListInRoom.do】");
|
json.add("error", errJson);
|
this.printJson(response, json.toString());
|
return ;
|
}finally {
|
SpObserver.setDBtoInstance();
|
}
|
}
|
|
|
|
/**
|
* 获取可导入直播间的商品
|
* @param request
|
* @param response
|
*/
|
@RequestMapping("/getGoodsListForImportRoom.do")
|
public void getGoodsListForImportRoom(HttpServletRequest request, HttpServletResponse response) {
|
HttpSession session = request.getSession();
|
JsonObject json = new JsonObject();
|
JsonObject errJson = new JsonObject();
|
String hostUrl = SettingKey.getHostUrl(request);
|
String roomId = request.getParameter("roomid") ;
|
if (roomId == null||"".equals(roomId)) {
|
errJson.addProperty("warning","请传递 roomid 参数【/shopping/live/getGoodsListForImportRoom.do】");
|
json.add("error", errJson);
|
this.printJson(response, json.toString());
|
return ;
|
}
|
|
try {
|
DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap( request) ;
|
SpObserver.setDBtoInstance("_"+dataSourceEntity.getDbId());//切换数据源
|
//SettingEntity settingEntity = settingIfc.getSettingEntity(request) ;
|
|
String openId = (String)session.getAttribute(SessionKey.WEIXIN_OPENID);
|
JsonArray jsonArray = new JsonArray();
|
List<LiveGoodsEntity> list = maLiveIfc.getGoodsListForImportRoom(Integer.parseInt(roomId),openId) ;
|
for (int i = 0; list!=null&& i < list.size(); i++) {
|
LiveGoodsEntity liveGoodsEntity = list.get(i) ;
|
jsonArray.add(LiveRoomVideo.getGoodsJsonObject( liveGoodsEntity, hostUrl, dataSourceEntity.getDbId()+"") );
|
}
|
json.add("list", jsonArray);
|
this.printJson(response, json.toString());
|
return ;
|
} catch (DataAccessException e) {
|
this.logger.error(e.getMessage(), e);
|
e.printStackTrace();
|
errJson.addProperty("warning",(e.getCause()!=null?e.getCause().getMessage(): e.getMessage())+"【/shopping/live/getGoodsListForImportRoom.do】");
|
json.add("error", errJson);
|
this.printJson(response, json.toString());
|
return ;
|
}catch (Exception e) {
|
this.logger.error(e.getMessage(), e);
|
e.printStackTrace();
|
errJson.addProperty("warning",(e.getCause()!=null?e.getCause().getMessage(): e.getMessage())+"【/shopping/live/getGoodsListForImportRoom.do】");
|
json.add("error", errJson);
|
this.printJson(response, json.toString());
|
return ;
|
}finally {
|
SpObserver.setDBtoInstance();
|
}
|
}
|
|
|
|
/**
|
* 获取可导入商品库的活动列表
|
* @param request
|
* @param response
|
*/
|
@RequestMapping("/getPanicBuyingListForImportGoods.do")
|
//@RequestMapping("/shopping/live/getPanicBuyingListForLiveGoods.do")
|
public void getPanicBuyingListForImportGoods(HttpServletRequest request, HttpServletResponse response) {
|
HttpSession session = request.getSession();
|
JsonObject json = new JsonObject();
|
JsonObject errJson = new JsonObject();
|
//String cltCode = (session.getAttribute(SettingKey.CLTCODE) == null?"": (String)session.getAttribute(SettingKey.CLTCODE)) ;
|
String hostUrl = SettingKey.getHostUrl(request);
|
String openId = (session.getAttribute(SessionKey.WEIXIN_OPENID) == null ? "": (String) session.getAttribute(SessionKey.WEIXIN_OPENID));
|
|
DataSourceEntity dataSourceEntity ;
|
try {
|
dataSourceEntity = MultiDataSource.getDataSourceMap( request) ;
|
}catch (DataAccessException e) {
|
errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage()));
|
json.add("error", errJson);
|
this.printJson(response, json.toString());
|
return;
|
}catch (Exception e ){
|
errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage()));
|
json.add("error", errJson);
|
this.printJson(response, json.toString());
|
return;
|
}
|
|
try {
|
SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());// 切换数据源
|
//SettingEntity settingEntity = settingIfc.getSettingEntity();
|
|
List<PanicBuyingEntity> dataList = panicBuyingIfc.getPanicBuyingListForImportGoods(openId) ;
|
//草稿
|
JsonArray draftListJsonArray = new JsonArray();
|
for (int i = 0;dataList!=null&& i < dataList.size(); i++) {
|
draftListJsonArray.add(PanicBuying.getPanicBuyingJsonObject( dataList.get(i), hostUrl, dataSourceEntity.getDbId()+"",openId));
|
}
|
json.add("list", draftListJsonArray);
|
|
json.addProperty("state", "success");
|
this.printJson(response, json.toString());
|
return;
|
} catch (DataAccessException e) {
|
errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage()));
|
json.add("error", errJson);
|
this.printJson(response, json.toString());
|
return;
|
}catch (Exception e ){
|
errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage()));
|
json.add("error", errJson);
|
this.printJson(response, json.toString());
|
return;
|
} finally {
|
SpObserver.setDBtoInstance();
|
}
|
}
|
|
public static JsonObject getRoomJsonObject(RoomInfo roomInfo,String hostUrl,Integer dbId) {
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd");
|
JsonObject jsonItem = new JsonObject();
|
|
jsonItem.addProperty("DocCode", roomInfo.getDocCode());
|
jsonItem.addProperty("FormId", roomInfo.getFormId());
|
jsonItem.addProperty("DocDate", roomInfo.getDocDate()==null?"":format2.format( roomInfo.getDocDate()));
|
jsonItem.addProperty("EnterCode", roomInfo.getEnterCode());
|
jsonItem.addProperty("EnterName", roomInfo.getEnterName());
|
jsonItem.addProperty("EnterDate", roomInfo.getEnterDate()==null?"":format.format( roomInfo.getEnterDate()));
|
jsonItem.addProperty("RoomId", roomInfo.getId()); //房间号
|
jsonItem.addProperty("RoomName", roomInfo.getName()); //直播标题
|
jsonItem.addProperty("CoverImg", roomInfo.getCoverImg()); //直播间背景墙
|
jsonItem.addProperty("CoverImgUnid",roomInfo.getCoverImgUnid()); //直播间背景墙UNID
|
jsonItem.addProperty("CoverImgUnidUrl", SettingKey.getUrl(hostUrl, roomInfo.getCoverImgUnidUrl(), dbId+"",null)); //直播间背景墙URL
|
jsonItem.addProperty("LiveStatus", roomInfo.getLiveStatus()); //直播状态:101 直播中,102 未开始,103 已结束 ,104 禁播,105 暂停中,106 异常,107 已过期
|
jsonItem.addProperty("StartTime", roomInfo.getStartDateTime() == null ?"": format.format(roomInfo.getStartDateTime())); //开播开始时间
|
jsonItem.addProperty("EndTime", roomInfo.getEndDateTime() == null ? "" :format.format(roomInfo.getEndDateTime())); //开播结束时间
|
|
jsonItem.addProperty("AnchorWechat", roomInfo.getAnchorWechat()); //主播微信号
|
jsonItem.addProperty("AnchorName", roomInfo.getAnchorName()); //主播昵称
|
jsonItem.addProperty("AnchorImg", roomInfo.getAnchorImg()); //主播头像
|
jsonItem.addProperty("AnchorImgUnid", roomInfo.getAnchorImgUnid()); //主播头像Unid
|
jsonItem.addProperty("AnchorImgUnidUrl", SettingKey.getUrl(hostUrl, roomInfo.getAnchorImgUnidUrl(), dbId+"",null)); //主播头像Url
|
jsonItem.addProperty("SubAnchorWechat", roomInfo.getSubAnchorWechat()); //主播副号微信号
|
jsonItem.addProperty("ShareImg", roomInfo.getShareImg()); //分享卡片封面
|
jsonItem.addProperty("ShareImgUnid", roomInfo.getShareImgUnid()); //分享卡片封面Unid
|
jsonItem.addProperty("ShareImgUnidUrl", SettingKey.getUrl(hostUrl, roomInfo.getShareImgUnidUrl(), dbId+"",null)); //分享卡片封面Url
|
jsonItem.addProperty("ShopCcCode", roomInfo.getShopCcCode());
|
jsonItem.addProperty("LiveBalanceSecond", roomInfo.getLiveBalanceSecond().longValue()<0?0:roomInfo.getLiveBalanceSecond()); //直播到计时
|
jsonItem.addProperty("isShowBannerPhotoOnHomePage", roomInfo.isShowBannerPhotoOnHomePage());
|
|
jsonItem.addProperty("BannerPhoto", roomInfo.getBannerPhoto()); //广告图片Unid
|
jsonItem.addProperty("BannerPhotoUrl", SettingKey.getUrl(hostUrl, roomInfo.getBannerPhotoUrl(), dbId+"",null)); //广告图片Url
|
jsonItem.addProperty("FeedsImg", roomInfo.getFeedsImgUnid()); //购物直播频道封面图
|
jsonItem.addProperty("FeedsImgUnid", roomInfo.getFeedsImgUnid()); //购物直播频道封面图Unid
|
jsonItem.addProperty("FeedsImgUnidUrl", SettingKey.getUrl(hostUrl, roomInfo.getFeedsImgUnidUrl(), dbId+"",null)); //购物直播频道封面图Url
|
jsonItem.addProperty("isFeedsPublic", roomInfo.getIsFeedsPublic().equals(1)?true:false); //是否开启官方收录
|
jsonItem.addProperty("ScreenType", roomInfo.getScreenType()); //0竖屏,1横屏、
|
jsonItem.addProperty("Type", roomInfo.getType()); //直播间类型:0 手机直播, 1 推流
|
jsonItem.addProperty("isCloseLike", roomInfo.getCloseLike().equals(1)?true:false); //是否关闭点赞
|
jsonItem.addProperty("isCloseGoods", roomInfo.getCloseGoods().equals(1)?true:false); //是否关闭货架
|
jsonItem.addProperty("isCloseComment", roomInfo.getCloseComment().equals(1)?true:false); //是否关闭评论
|
jsonItem.addProperty("isCloseReplay", roomInfo.getCloseReplay().equals(1)?true:false); //是否关闭回放
|
jsonItem.addProperty("isCloseShare", roomInfo.getCloseShare().equals(1)?true:false); //是否关闭分享
|
jsonItem.addProperty("isCloseKf", roomInfo.getCloseKf().equals(1)?true:false); //是否关闭客服
|
|
JsonArray replayListArray = new JsonArray();
|
MaLiveIfc maLiveIfc = (MaLiveIfc)FactoryBean.getBean("MaLiveImpl");
|
LiveReplayVideoEntity replayList = maLiveIfc.getReplayVideo(roomInfo.getId()) ;
|
for (int j =0; replayList != null && replayList.getLiveReplay()!= null && j < replayList.getLiveReplay().size();j++) {
|
JsonObject replayItem = new JsonObject();
|
replayItem.addProperty("ExpireTime", replayList.getLiveReplay().get(j).getExpireTime()); //回放过期时间
|
replayItem.addProperty("CreateTime", replayList.getLiveReplay().get(j).getCreateTime()); //回放生成时间
|
replayItem.addProperty("MediaUrl", replayList.getLiveReplay().get(j).getMediaUrl()); //回放URL
|
replayListArray.add(replayItem);
|
}
|
jsonItem.add("ReplayVideoList",replayListArray ) ; //回放列表
|
|
jsonItem.addProperty("SubscribeTimes", roomInfo.getSubscribeTimes()); //直播间订阅次数
|
return jsonItem;
|
}
|
|
|
/**
|
* 保存小程序提交过来的新建直播间信息 , 第一步
|
* @param request
|
* @param response
|
*/
|
@RequestMapping("/saveRoomStep1.do")
|
public void saveRoomStep1(@RequestBody CreateLiveRoomParameterStep1Entity createLiveRoomParameterStep1Entity, HttpServletRequest request, HttpServletResponse response) {
|
HttpSession session=request.getSession();
|
JsonObject json = new JsonObject();
|
JsonObject errJson = new JsonObject();
|
String userCode = (String) session.getAttribute(SessionKey.HRCODE) ;
|
String userName = (String) session.getAttribute(SessionKey.HRNAME) ;
|
String openId = (session.getAttribute(SessionKey.WEIXIN_OPENID) == null ? "": (String) session.getAttribute(SessionKey.WEIXIN_OPENID));
|
|
if (createLiveRoomParameterStep1Entity.getName() == null||"".equals(createLiveRoomParameterStep1Entity.getName())) {
|
errJson.addProperty("warning","必须传递直播间标题 name 【最短3个汉字,最长17个汉字】");
|
json.add("error", errJson);
|
this.printJson(response, json.toString());
|
return ;
|
}
|
int len = StringLengthUtil.getWordCount(createLiveRoomParameterStep1Entity.getName());
|
if (len < 6 || len > 34) {
|
errJson.addProperty("warning","直播间标题最短3个汉字,最长17个汉字");
|
json.add("error", errJson);
|
this.printJson(response, json.toString());
|
return ;
|
}
|
if (createLiveRoomParameterStep1Entity.getAnchorName() == null||"".equals(createLiveRoomParameterStep1Entity.getAnchorName())) {
|
errJson.addProperty("warning","必须传递主播昵称 anchorName 【最短2个汉字,最长15个汉字】");
|
json.add("error", errJson);
|
this.printJson(response, json.toString());
|
return ;
|
}
|
|
len = StringLengthUtil.getWordCount(createLiveRoomParameterStep1Entity.getAnchorName());
|
if (len < 4 || len > 30) {
|
errJson.addProperty("warning","主播昵称最短2个汉字,最长15个汉字");
|
json.add("error", errJson);
|
this.printJson(response, json.toString());
|
return ;
|
}
|
|
if (createLiveRoomParameterStep1Entity.getAnchorWechat() == null||"".equals(createLiveRoomParameterStep1Entity.getAnchorWechat())) {
|
errJson.addProperty("warning","必须传递主播微信号 anchorWechat 【如果未实名认证,需要先前往“小程序直播”小程序进行实名验证】");
|
json.add("error", errJson);
|
this.printJson(response, json.toString());
|
return ;
|
}
|
|
if (createLiveRoomParameterStep1Entity.getShareImgUnid() == null||"".equals(createLiveRoomParameterStep1Entity.getShareImgUnid())) {
|
errJson.addProperty("warning","必须上传分享卡片封面 ShareImgUnid 字段");
|
json.add("error", errJson);
|
this.printJson(response, json.toString());
|
return ;
|
}
|
|
try {
|
DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap( request) ;
|
SpObserver.setDBtoInstance("_"+dataSourceEntity.getDbId());//切换数据源
|
SettingEntity settingEntity = settingIfc.getSettingEntity(request) ;
|
//取网店 shopcccode
|
ShopCcCodeEntity shopCcCodeEntity = ShopCcCode.getShopCcCode(settingEntity,request);
|
|
createLiveRoomParameterStep1Entity.setShopCcCode(shopCcCodeEntity.getShopCcCode());
|
createLiveRoomParameterStep1Entity.setOpenId(openId);
|
createLiveRoomParameterStep1Entity.setUserCode(userCode);
|
createLiveRoomParameterStep1Entity.setUserName(userName);
|
|
String newDocCode = maLiveIfc.createRoomStep1(createLiveRoomParameterStep1Entity);
|
|
json.addProperty(SettingKey.DOCCODE, newDocCode);
|
json.addProperty("state", "success");
|
this.printJson(response, json.toString());
|
return ;
|
|
}catch (Exception e) {
|
this.logger.error(e.getMessage(), e);
|
e.printStackTrace();
|
errJson.addProperty("warning",(e.getCause()!=null?e.getCause().getMessage(): e.getMessage()));
|
json.add("error", errJson);
|
this.printJson(response, json.toString());
|
return ;
|
}finally {
|
SpObserver.setDBtoInstance();
|
}
|
}
|
|
/**
|
* 保存小程序提交过来的新建直播间信息 , 第二步
|
* @param request
|
* @param response
|
*/
|
@RequestMapping("/saveRoomStep2.do")
|
public void saveRoomStep2(@RequestBody CreateLiveRoomParameterStep2Entity createLiveRoomParameterStep2Entity, HttpServletRequest request, HttpServletResponse response) {
|
//HttpSession session=request.getSession();
|
JsonObject json = new JsonObject();
|
JsonObject errJson = new JsonObject();
|
|
try {
|
DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap( request) ;
|
SpObserver.setDBtoInstance("_"+dataSourceEntity.getDbId());//切换数据源
|
|
maLiveIfc.createRoomStep2(createLiveRoomParameterStep2Entity);
|
|
json.addProperty(SettingKey.DOCCODE, createLiveRoomParameterStep2Entity.getDocCode());
|
json.addProperty("state", "success");
|
this.printJson(response, json.toString());
|
return ;
|
|
}catch (Exception e) {
|
this.logger.error(e.getMessage(), e);
|
e.printStackTrace();
|
errJson.addProperty("warning",(e.getCause()!=null?e.getCause().getMessage(): e.getMessage()));
|
json.add("error", errJson);
|
this.printJson(response, json.toString());
|
return ;
|
}finally {
|
SpObserver.setDBtoInstance();
|
}
|
}
|
|
|
/**
|
* 保存小程序提交过来的新建直播间信息 , 第三步
|
* @param request
|
* @param response
|
*/
|
@RequestMapping("/saveRoomStep3.do")
|
public void saveRoomStep3(@RequestBody CreateLiveRoomParameterStep3Entity createLiveRoomParameterStep3Entity, HttpServletRequest request, HttpServletResponse response) {
|
//HttpSession session=request.getSession();
|
JsonObject json = new JsonObject();
|
JsonObject errJson = new JsonObject();
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
try {
|
DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap( request) ;
|
SpObserver.setDBtoInstance("_"+dataSourceEntity.getDbId());//切换数据源
|
|
if (createLiveRoomParameterStep3Entity.getStartTime() == null||"".equals(createLiveRoomParameterStep3Entity.getStartTime())) {
|
errJson.addProperty("warning","必须传递直播计划开始时间 startTime ,格式:yyyy-MM-dd HH:mm:ss");
|
json.add("error", errJson);
|
this.printJson(response, json.toString());
|
return ;
|
}
|
if (createLiveRoomParameterStep3Entity.getEndTime() == null||"".equals(createLiveRoomParameterStep3Entity.getEndTime())) {
|
errJson.addProperty("warning","必须传递直播计划结束时间 endTime ,格式:yyyy-MM-dd HH:mm:ss");
|
json.add("error", errJson);
|
this.printJson(response, json.toString());
|
return ;
|
}
|
|
Date startDateTime = null,endDateTime = null;
|
try {
|
startDateTime = sdf.parse(createLiveRoomParameterStep3Entity.getStartTime()) ;
|
} catch (ParseException e) {
|
errJson.addProperty("warning","直播计划开始时间 startTime 不能转换为日期类型,请检查日期格式是否符合:yyyy-MM-dd HH:mm:ss ");
|
json.add("error", errJson);
|
this.printJson(response, json.toString());
|
return ;
|
}
|
try {
|
endDateTime = sdf.parse(createLiveRoomParameterStep3Entity.getEndTime()) ;
|
} catch (ParseException e) {
|
errJson.addProperty("warning","直播计划开始时间 endTime 不能转换为日期类型,请检查日期格式是否符合:yyyy-MM-dd HH:mm:ss ");
|
json.add("error", errJson);
|
this.printJson(response, json.toString());
|
return ;
|
}
|
createLiveRoomParameterStep3Entity.setStartDateTime(startDateTime);
|
createLiveRoomParameterStep3Entity.setEndDateTime(endDateTime);
|
|
|
maLiveIfc.createRoomStep3(createLiveRoomParameterStep3Entity);
|
|
//创建直播间
|
CreateLiveRoomResultEntity createLiveRoomResultEntity = LiveRoomVideo.CreateLiveRoom( dataSourceEntity, createLiveRoomParameterStep3Entity.getDocCode(), request);
|
|
json.addProperty("roomId", createLiveRoomResultEntity.getRoomId()); //当主播微信号没有在 “小程序直播“ 小程序实名认证 返回该字段
|
json.addProperty("qrcodeUrl", createLiveRoomResultEntity.getQrCodeUrl()); //当主播微信号没有在 “小程序直播“ 小程序实名认证 返回该字段
|
json.addProperty("qrcodeUrlUnid", createLiveRoomResultEntity.getQrCodeUrlUnid()); //当主播微信号没有在 “小程序直播“ 小程序实名认证 返回该字段
|
json.addProperty(SettingKey.DOCCODE, createLiveRoomParameterStep3Entity.getDocCode());
|
json.addProperty("state", createLiveRoomResultEntity.getState());
|
this.printJson(response, json.toString());
|
return ;
|
} catch (ApplicationException e) {
|
this.logger.error(e.getMessage(), e);
|
//e.printStackTrace(); //ApplicationException 例外不要输出这句话
|
errJson.addProperty("warning",(e.getCause()!=null?e.getCause().getMessage(): e.getMessage()));
|
json.add("error", errJson);
|
this.printJson(response, json.toString());
|
return ;
|
} catch(WxErrorException e) {
|
this.logger.error(e.getMessage(), e);
|
e.printStackTrace();
|
errJson.addProperty("warning","错误代码:" + e.getError().getErrorCode() + ",错误信息:" + e.getError().getErrorMsg());
|
json.add("error", errJson);
|
this.printJson(response, json.toString());
|
return ;
|
} catch (Exception e) {
|
this.logger.error(e.getMessage(), e);
|
e.printStackTrace();
|
errJson.addProperty("warning",(e.getCause()!=null?e.getCause().getMessage(): e.getMessage()));
|
json.add("error", errJson);
|
this.printJson(response, json.toString());
|
return ;
|
}finally {
|
SpObserver.setDBtoInstance();
|
}
|
}
|
}
|