admin
2021-08-27 8fee151ffae0c3818694b7318583814bf92663e2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
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;
        }
    }
 
 
}