admin
2021-01-04 aa6ef62aef83e277d4171df1d9f0803f91738216
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
package com.newvideo.controller.admin.api;
 
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
 
import javax.annotation.Resource;
 
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
 
import com.google.gson.GsonBuilder;
import com.newvideo.domain.ResourceVideo;
import com.newvideo.domain.VideoInfo;
import com.newvideo.iqiyi.util.IqiyiUtil;
import com.newvideo.service.imp.ClassService;
import com.newvideo.service.imp.ResourceVideoService;
import com.newvideo.service.imp.VideoManager;
import com.newvideo.util.JsonUtil;
import com.newvideo.util.SolrUtil;
import com.newvideo.util.StringUtil;
import com.newvideo.util.TimeUtil;
import com.newvideo.web.tag.PageEntity;
 
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
 
@Controller
@RequestMapping("admin/new/api/video")
public class VideoAdminController {
 
    @Resource
    private VideoManager videoManager;
 
    @Resource
    private ClassService classService;
 
    @Resource
    private ResourceVideoService resourceVideoService;
 
    @Resource
    private IqiyiUtil iqiyiUtil;
 
    @RequestMapping(value = "/changevideoshow", method = RequestMethod.POST)
    public void changeVideoShow(String id, int show, PrintWriter out) {
        VideoInfo vi = videoManager.getVideoInfo(id);
        if (vi != null) {
            vi.setShow(show + "");
            videoManager.changeVideoShow(vi);
        }
        JSONObject object = new JSONObject();
        object.put("code", 0);
        object.put("msg", "修改成功");
        out.print(object);
    }
 
    @RequestMapping(value = "/deletevideo", method = RequestMethod.POST)
    public void deleteVideo(String id, PrintWriter out) {
        String[] ids = id.split(",");
        for (String idStr : ids)
            videoManager.deleteVideo(idStr);
 
        JSONObject object = new JSONObject();
        object.put("code", 0);
        object.put("msg", "删除成功");
        out.print(object);
    }
 
    @RequestMapping(value = "/videolist", method = RequestMethod.POST)
    public void videoList(int videotype, int page, String key, int contenttype, PrintWriter out) {
        List<VideoInfo> list = classService.getTypeVideoListAdmin(videotype == 0 ? "" : videotype + "", page, key,
                contenttype);
        long count = classService.getTypeVideoListAdminCount(videotype == 0 ? "" : videotype + "", key, contenttype);
        JSONObject object = new JSONObject();
        object.put("code", 0);
        JSONObject data = new JSONObject();
        JSONArray array = new JSONArray();
        for (VideoInfo vi : list) {
            JSONObject item = new JSONObject();
            item.put("id", vi.getId());
            item.put("name", vi.getName());
            item.put("picture", vi.getHpicture());
            item.put("updatetime",
                    TimeUtil.getGernalTime(
                            Long.parseLong(
                                    StringUtil.isNullOrEmpty(vi.getCreatetime() + "") ? "0" : vi.getCreatetime() + ""),
                            "yyyy-MM-dd"));
            item.put("show", vi.getShow());
            array.add(item);
        }
        PageEntity entity = new PageEntity();
        entity.setPageIndex(page);
        entity.setPageSize(20);
        entity.setTotalCount((int) count);
 
        data.put("pageEntity", new GsonBuilder().create().toJson(entity));
        data.put("data", array);
        object.put("data", data);
        out.println(object);
    }
 
    @RequestMapping("updateVideos")
    public void updateVideos(PrintWriter out) {
        iqiyiUtil.updateAll("");
        out.print(JsonUtil.loadTrueJson("执行成功"));
    }
 
    @RequestMapping("updateIqiyiAlbum")
    public void updateIqiyiAlbum(String url, PrintWriter out) {
        String aid = IqiyiUtil.getAlbumIdFromPlayUrl(url);
        if (StringUtil.isNullOrEmpty(aid)) {
            JSONObject data = new JSONObject();
            data.put("code", 1);
            data.put("msg", "未能获取到专辑");
            out.print(data);
        } else {
            iqiyiUtil.updateAlbum(aid);
            JSONObject data = new JSONObject();
            data.put("code", 0);
            data.put("data", "专辑更新成功");
            out.print(data);
        }
    }
 
}