package com.yeshi.buwan.controller.api;
|
|
import com.google.gson.Gson;
|
import com.google.gson.GsonBuilder;
|
import com.yeshi.buwan.domain.user.LoginUser;
|
import com.yeshi.buwan.domain.vip.OrderRecord;
|
import com.yeshi.buwan.domain.vip.OrderType;
|
import com.yeshi.buwan.dto.order.PPTVVideoPrice;
|
import com.yeshi.buwan.videos.pptv.PPTVApiUtil;
|
import com.yeshi.buwan.videos.pptv.PPTVUtil;
|
import com.yeshi.buwan.videos.pptv.entity.PPTVProgram;
|
import com.yeshi.buwan.videos.pptv.entity.PPTVSeries;
|
import com.yeshi.buwan.service.inter.LoginUserService;
|
import com.yeshi.buwan.service.inter.juhe.PPTVService;
|
import com.yeshi.buwan.service.inter.order.OrderService;
|
import com.yeshi.buwan.service.inter.system.SystemConfigService;
|
import com.yeshi.buwan.service.inter.vip.VIPService;
|
import com.yeshi.buwan.service.manager.GoldCornManager;
|
import com.yeshi.buwan.util.JsonUtilV2;
|
import com.yeshi.buwan.vo.AcceptData;
|
import net.sf.json.JSONObject;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.yeshi.utils.StringUtil;
|
|
import javax.annotation.Resource;
|
import java.util.HashSet;
|
import java.util.Set;
|
|
@Controller
|
@RequestMapping("api/v2/videoinfo")
|
public class VideoInfoController {
|
|
Logger logger = LoggerFactory.getLogger(VideoInfoController.class);
|
|
|
@Resource
|
private PPTVService pptvService;
|
|
@Resource
|
private LoginUserService loginUserService;
|
|
@Resource
|
private OrderService orderService;
|
|
@Resource
|
private VIPService vipService;
|
|
@Resource
|
private GoldCornManager goldCornManager;
|
|
@Resource
|
private SystemConfigService systemConfigService;
|
|
private String getDurationDesc(int duration) {
|
int h = duration / (60 * 60);
|
int m = (duration % (60 * 60)) / 60;
|
int s = duration % 60;
|
String st = "";
|
if (h > 0)
|
st += h + "时";
|
if (st.length() > 0 || m > 0) {
|
st += m + "分";
|
}
|
st += s + "秒";
|
return st;
|
}
|
|
|
@RequestMapping("getPPVideoInfo")
|
@ResponseBody
|
public String getPPVideoInfo(AcceptData acceptData, String loginUid, String cid,String vid) {
|
//获取PPTV的视频详情
|
PPTVSeries series = pptvService.selectSeriesBySeriesCode(cid);
|
if (series == null) {
|
return JsonUtilV2.loadFalseJson("当前影片不存在");
|
}
|
if (!PPTVUtil.getAvaiableStates().contains(series.getStatus())) {
|
return JsonUtilV2.loadFalseJson("当前影片已下线");
|
}
|
|
PPTVProgram pptvProgram=pptvService.selectProgramById(vid);
|
|
if (pptvProgram.getGoodsInfo() == null || StringUtil.isNullOrEmpty(pptvProgram.getGoodsInfo().getGoodsNo())) {
|
PPTVSeries detail = PPTVApiUtil.getDetail(cid);
|
series.setGoodsInfo(detail.getGoodsInfo());
|
pptvService.updateProgramGoodsInfo(series.getInfoID(), series.getGoodsInfo());
|
}
|
|
if (pptvProgram.getGoodsInfo() == null || StringUtil.isNullOrEmpty(pptvProgram.getGoodsInfo().getGoodsNo())) {
|
return JsonUtilV2.loadFalseJson("当前影片不能购买");
|
}
|
|
Set<String> typeSets = new HashSet<>();
|
|
try {
|
String[] sts = series.getProgramcategory().split(",");
|
for (String st : sts) {
|
typeSets.add(st.split("-")[0]);
|
}
|
typeSets.remove("好莱坞");
|
typeSets.remove("院线");
|
} catch (Exception e) {
|
}
|
|
PPTVSimpleVideoInfo videoInfo = new PPTVSimpleVideoInfo();
|
videoInfo.setInfoId(series.getInfoID());
|
videoInfo.setName(series.getName());
|
videoInfo.setPicture(series.getCover());
|
videoInfo.setCategory(com.yeshi.buwan.util.StringUtil.join(typeSets, " "));
|
videoInfo.setActors(series.getActor());
|
videoInfo.setDirectors(series.getDirector());
|
if (pptvProgram!=null && !StringUtil.isNullOrEmpty(pptvProgram.getDuration()))
|
videoInfo.setDuration(getDurationDesc(Integer.parseInt(pptvProgram.getDuration())));
|
videoInfo.setDesc(series.getDescription());
|
Gson gson = new GsonBuilder().create();
|
|
JSONObject data = new JSONObject();
|
data.put("video", gson.toJson(videoInfo));
|
|
PPTVVideoPrice price = new Gson().fromJson(systemConfigService.getConfigValueByKeyCache("videoPrice"), PPTVVideoPrice.class);
|
|
//加载价格信息
|
JSONObject priceInfo = new JSONObject();
|
priceInfo.put("discount", price.getTag());
|
priceInfo.put("actualPrice", price.getActualPrice());
|
data.put("price", priceInfo);
|
|
if (!StringUtil.isNullOrEmpty(loginUid)) {
|
LoginUser user = loginUserService.getLoginUser(loginUid);
|
if (user != null) {
|
JSONObject userInfo = new JSONObject();
|
userInfo.put("portrait", user.getPortrait());
|
userInfo.put("nickName", user.getName());
|
userInfo.put("id", user.getId());
|
long count = orderService.countOrderRecord(loginUid, OrderType.video, OrderRecord.STATE_PAY);
|
userInfo.put("vip", vipService.isVIP(loginUid));
|
userInfo.put("videoCount", count);
|
//影视豆
|
userInfo.put("goldCorn", goldCornManager.getBalance(loginUid));
|
data.put("user", userInfo);
|
}
|
}
|
|
return JsonUtilV2.loadTrueJson(data.toString());
|
}
|
|
class PPTVSimpleVideoInfo {
|
private String infoId;
|
private String picture;
|
private String name;
|
private String category;
|
private String actors;
|
private String directors;
|
private String duration;
|
private String desc;
|
|
public String getInfoId() {
|
return infoId;
|
}
|
|
public void setInfoId(String infoId) {
|
this.infoId = infoId;
|
}
|
|
public String getPicture() {
|
return picture;
|
}
|
|
public void setPicture(String picture) {
|
this.picture = picture;
|
}
|
|
public String getName() {
|
return name;
|
}
|
|
public void setName(String name) {
|
this.name = name;
|
}
|
|
public String getCategory() {
|
return category;
|
}
|
|
public void setCategory(String category) {
|
this.category = category;
|
}
|
|
public String getActors() {
|
return actors;
|
}
|
|
public void setActors(String actors) {
|
this.actors = actors;
|
}
|
|
public String getDirectors() {
|
return directors;
|
}
|
|
public void setDirectors(String directors) {
|
this.directors = directors;
|
}
|
|
public String getDuration() {
|
return duration;
|
}
|
|
public void setDuration(String duration) {
|
this.duration = duration;
|
}
|
|
public String getDesc() {
|
return desc;
|
}
|
|
public void setDesc(String desc) {
|
this.desc = desc;
|
}
|
}
|
|
|
}
|