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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
package com.yeshi.buwan.controller.admin.api;
 
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
 
 
import com.yeshi.buwan.service.inter.recommend.HomeVideoService;
import com.yeshi.buwan.util.*;
import com.yeshi.buwan.util.video.VideoUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
 
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
 
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.yeshi.buwan.domain.CategoryContry;
import com.yeshi.buwan.domain.system.DetailSystem;
import com.yeshi.buwan.domain.HomeType;
import com.yeshi.buwan.domain.HomeVideo;
import com.yeshi.buwan.domain.VideoInfo;
import com.yeshi.buwan.domain.VideoType;
import com.yeshi.buwan.domain.recommend.CategoryRecommendVideo;
import com.yeshi.buwan.domain.recommend.SuperCategoryRecommendVideo;
import com.yeshi.buwan.domain.web.CategoryRecommendVideoAdmin;
import com.yeshi.buwan.service.imp.CategoryAreaService;
import com.yeshi.buwan.service.imp.ClassService;
import com.yeshi.buwan.service.imp.HomeTypeService;
import com.yeshi.buwan.service.imp.SystemService;
import com.yeshi.buwan.service.imp.recommend.CategoryRecommendVideoService;
import com.yeshi.buwan.web.tag.PageEntity;
 
@Controller
@RequestMapping("admin/new/api/class")
public class ClassController {
 
    @Resource
    private ClassService classService;
 
    @Resource
    private HomeTypeService homeTypeService;
 
    @Resource
    private HomeVideoService homeVideoService;
 
    @Resource
    private CategoryRecommendVideoService categoryRecommendVideoService;
 
    @Resource
    private SystemService systemService;
 
    @Resource
    private CategoryAreaService categoryAreaService;
 
    @RequestMapping(value = "/getnextclass", method = RequestMethod.POST)
    public void getNextClass(int pid, PrintWriter out) {
        System.out.println("pid--" + pid);
        List<VideoType> list;
        if (pid <= 0)
            list = classService.getNextTypeList("");
        else
            list = classService.getNextTypeList(pid + "");
 
        JSONArray array = new JSONArray();
        if (list != null)
            for (VideoType type : list) {
                JSONObject obj = new JSONObject();
                obj.put("id", type.getId());
                obj.put("name", type.getName());
                array.add(obj);
            }
        JSONObject object = new JSONObject();
        object.put("code", 0);
        object.put("data", array);
        out.print(object);
    }
 
    @RequestMapping("getAllFirstClass")
    public void getAllFirstClass(PrintWriter out) {
        List<VideoType> list = classService.getAllVideoType();
        JSONArray array = new JSONArray();
        if (list != null)
            for (VideoType type : list) {
                JSONObject obj = new JSONObject();
                obj.put("id", type.getId());
                obj.put("name", type.getName());
                array.add(obj);
            }
        JSONObject object = new JSONObject();
        object.put("code", 0);
        object.put("data", array);
        out.print(object);
    }
 
    @RequestMapping(value = "/gethometypelist", method = RequestMethod.POST)
    public void getHomeTypeList(int pid, HttpSession session, PrintWriter out) {
        List<HomeType> list = homeTypeService.getHomeTypeList(SystemUtil.getAdminSelectedSystemId(session));
 
        JSONArray array = new JSONArray();
        if (list != null)
            for (HomeType type : list) {
                JSONObject obj = new JSONObject();
                obj.put("id", type.getId());
                obj.put("name", type.getName());
                array.add(obj);
            }
        JSONObject object = new JSONObject();
        object.put("code", 0);
        object.put("data", array);
        out.print(object);
    }
 
    @RequestMapping(value = "/addhomevideos", method = RequestMethod.POST)
    public void addHomeVideos(int hometypeid, String videos, String pictures,
                              String tags, PrintWriter out) {
        String[] videoStr = videos.split(",");
        String[] pictureStr = pictures.split(",");
        String[] tagStr = tags.split(",");
 
        List<HomeVideo> list = new ArrayList<HomeVideo>();
        for (int i = 0; i < videoStr.length; i++) {
            HomeVideo hv = new HomeVideo();
            hv.setCreatetime(System.currentTimeMillis() + "");
            hv.setTag(tagStr[i]);
            hv.setPicture(pictureStr[i]);
            hv.setType(new HomeType(hometypeid + ""));
            hv.setVideoId(videoStr[i]);
            hv.setFromType(VideoUtil.getVideoFromType(hv.getVideoId()));
            hv.setBigPicture(false);
        }
 
        homeVideoService.addHomeVideo(list);
        JSONObject object = new JSONObject();
        object.put("code", 0);
        object.put("msg", "添加成功");
        out.print(object);
    }
 
    /**
     * 搜索
     *
     * @param key
     * @param detailsystem
     * @param videotype
     * @param page
     * @param out
     */
    @RequestMapping(value = "/getseachList", method = RequestMethod.POST)
    public void categoryRecommendVideoList(String key, String detailsystem,
                                           String videotype, String page, HttpSession session, PrintWriter out) {
 
        if (detailsystem == null || "".equals(detailsystem.trim())) {
            detailsystem = "0";
        }
 
        if (page == null || "".equals(page.trim())) {
            page = "1";
        }
 
        int pageIndex = Integer.parseInt(page);
        if (pageIndex == 0)
            pageIndex = 1;
 
        videotype = StringUtil.isNullOrEmpty(videotype) ? "150" : videotype;
 
        List<CategoryRecommendVideoAdmin> list = categoryRecommendVideoService
                .getCategoryRecommendVideoAdmin(key,
                        Integer.parseInt(videotype), SystemUtil.getAdminSelectedSystemId(session), Integer.parseInt(detailsystem), pageIndex);
        long count = categoryRecommendVideoService
                .getCategoryRecommendVideoAdminCount(key,
                        Integer.parseInt(videotype), SystemUtil.getAdminSelectedSystemId(session), Integer.parseInt(detailsystem));
        PageEntity pe = new PageEntity();
        pe.setPageIndex(pageIndex);
        pe.setPageSize(Constant.pageCount);
        Map<String, String> map = new HashMap<String, String>();
        map.put("key", key);
        map.put("detailsystem", detailsystem + "");
        map.put("videotype", videotype + "");
        pe.setParams(map);
        pe.setTotalCount((int) count);
        Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation()
                .create();
        JSONObject root = new JSONObject();
        root.put("code", "0");
        root.put("pageEntity", pe);
        String json = gson.toJson(list);
        root.put("crv", json);
        System.out.println(root.toString());
        out.print(root);
    }
 
    @RequestMapping(value = "/deleteCategoryRecommendVideo", method = RequestMethod.POST)
    public void deleteCategoryRecommendVideo(String ids, PrintWriter out) {
 
        if (ids == null || ids.trim().length() == 0) {
            return;
        }
        String[] idArr = ids.split(",");
        for (String id : idArr) {
            System.out.println(id);
            categoryRecommendVideoService.deleteCategoryRecommendVideo(new CategoryRecommendVideo(id));
        }
        out.print("yes");
    }
 
    @RequestMapping(value = "/getCategoryRecommendVideo", method = RequestMethod.POST)
    public void getCategoryRecommendVideo(String id, PrintWriter out) {
 
//        id = StringUtil.isNullOrEmpty(id) ? request.getAttribute("id").toString() : id;
        Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation()
                .create();
        JSONObject root = new JSONObject();
        CategoryRecommendVideo categoryRecommendVideo = categoryRecommendVideoService.getCategoryRecommendVideoById(id);
        if (categoryRecommendVideo != null) {
            String json = gson.toJson(categoryRecommendVideo);
            root.put("code", "0");
            root.put("crv", json);
        } else {
            root.put("code", "1");
            root.put("crv", null);
        }
        out.print(root);
 
        //request.setAttribute("videoTypeList", classService.getFirstTypeList(""));
//        request.setAttribute("systemList", systemService.getSystemList());
//        request.setAttribute("categoryRecommendVideo", categoryRecommendVideo);
        return;
    }
 
    @RequestMapping(value = "/setCategoryRecommendVideo", method = RequestMethod.POST)
    public void updateCategoryRecommendVideo(String id, String beizhu, String desc, int orderby, String picture, String videoid, String videotype, HttpSession session, PrintWriter out) {
 
        //id为空则新加
        if (id == null || "".equals(id.trim())) {
            CategoryRecommendVideo newCategoryRecommendVideo = new CategoryRecommendVideo();
            newCategoryRecommendVideo.setBeizhu(beizhu);
            newCategoryRecommendVideo.setCreatetime(System.currentTimeMillis() + "");
            newCategoryRecommendVideo.setDesc(desc);
            newCategoryRecommendVideo.setOrderby(orderby);
            newCategoryRecommendVideo.setPicture(picture);
            newCategoryRecommendVideo.setVideoInfo(new VideoInfo(videoid));
            newCategoryRecommendVideo.setVideoType(new VideoType(Long.parseLong(videotype)));
            newCategoryRecommendVideo.setSystem(SystemUtil.getAdminSelectedSystem(session));
 
            categoryRecommendVideoService.addCategoryRecommendVideo(newCategoryRecommendVideo);
 
            SuperCategoryRecommendVideo sz = null;
            List<DetailSystem> list = systemService.getDetailSystemList(SystemUtil.getAdminSelectedSystem(session).getId());
            for (DetailSystem ds : list) {
                sz = new SuperCategoryRecommendVideo();
                sz.setDetailSystem(new DetailSystem(ds.getId()));
                sz.setCategoryRecommendVideo(newCategoryRecommendVideo);
                categoryRecommendVideoService.addSuperCategoryRecommendVideo(sz);
            }
 
            out.print("yes");
            return;
        }
        CategoryRecommendVideo categoryRecommendVideo = categoryRecommendVideoService.getCategoryRecommendVideoById(id);
        categoryRecommendVideo.setBeizhu(beizhu);
        categoryRecommendVideo.setCreatetime(System.currentTimeMillis() + "");
        categoryRecommendVideo.setDesc(desc);
//        categoryRecommendVideo.setJpos(jpos);
        categoryRecommendVideo.setOrderby(orderby);
        categoryRecommendVideo.setPicture(picture);
        categoryRecommendVideo.setVideoInfo(new VideoInfo(videoid));
        categoryRecommendVideo.setVideoType(new VideoType(Long.parseLong(videotype)));
        categoryRecommendVideoService.updateCategoryRecommendVideo(categoryRecommendVideo);
        out.print("yes");
        return;
    }
 
 
    @RequestMapping(value = "/CategoryRecommendVideoAdminServlet", method = RequestMethod.POST)
    public void set(String type, String id, String systemid, PrintWriter out) {
 
        System.out.println("type--" + type);
        System.out.println("id--" + id);
        System.out.println("systemid--" + systemid);
 
        if ("add".equalsIgnoreCase(type)) {// 获取来源列表
            if (!StringUtil.isNullOrEmpty(systemid) && !StringUtil.isNullOrEmpty(id)) {
                SuperCategoryRecommendVideo sz = new SuperCategoryRecommendVideo();
                sz.setDetailSystem(new DetailSystem(systemid));
                sz.setCategoryRecommendVideo(new CategoryRecommendVideo(id));
                categoryRecommendVideoService.addSuperCategoryRecommendVideo(sz);
            }
            out.print("yes");
        } else if ("delete".equalsIgnoreCase(type)) {
            if (!StringUtil.isNullOrEmpty(systemid) && !StringUtil.isNullOrEmpty(id)) {
                categoryRecommendVideoService.deleteCategoryRecommendVideoAdmin(id, systemid);
            }
            out.print("yes");
        }
    }
 
    @RequestMapping("getAreaList")
    public void getAreaList(long cid, PrintWriter out) {
        List<CategoryContry> list = categoryAreaService.getCategoryContryListByCid(cid + "");
        if (list.size() == 0) {
            out.print(JsonUtil.loadFalseAdmin("加载错误"));
            return;
        }
        List<CategoryContry> categoryContryList = categoryAreaService.categoryContryList(list.get(0).getId() + "");
        PageEntity pe = new PageEntity();
        pe.setPageIndex(1);
        pe.setPageSize(categoryContryList.size());
        pe.setTotalCount(categoryContryList.size());
        JSONObject data = new JSONObject();
        Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
        data.put("pe", pe);
        data.put("list", gson.toJson(categoryContryList));
        String json = JsonUtil.loadTrueAdmin(data);
        out.print(json);
    }
 
    @RequestMapping("getArea")
    public void getArea(long id, PrintWriter out) {
        CategoryContry area = categoryAreaService.getCategoryArea(id + "");
        if (area == null) {
            out.print(JsonUtil.loadFalseAdmin(""));
            return;
        }
        Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
        out.print(JsonUtil.loadTrueAdmin(gson.toJson(area)));
    }
 
    @RequestMapping("updateArea")
    public void updateArea(long id, int orderBy, PrintWriter out) {
        CategoryContry area = categoryAreaService.getCategoryArea(id + "");
        if (area == null) {
            out.print(JsonUtil.loadFalseAdmin(""));
            return;
        }
        area.setOrderby(orderBy);
        categoryAreaService.updateArea(area);
        out.print(JsonUtil.loadTrueAdmin(""));
    }
 
 
}