admin
2020-08-22 813d2cae75cbae3f216de5f493af643c5a560c82
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
package com.yeshi.buwan.controller.admin.api;
 
import java.io.PrintWriter;
import java.util.List;
 
import javax.annotation.Resource;
 
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
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.yeshi.buwan.acFun.AcFunUtil;
import com.yeshi.buwan.domain.VideoInfo;
import com.yeshi.buwan.iqiyi.util.IqiyiUtil;
import com.yeshi.buwan.service.imp.ClassService;
import com.yeshi.buwan.service.imp.ResourceVideoService;
import com.yeshi.buwan.service.imp.VideoManager;
import com.yeshi.buwan.util.JsonUtil;
import com.yeshi.buwan.util.StringUtil;
import com.yeshi.buwan.util.TimeUtil;
import com.yeshi.buwan.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;
 
    @Resource
    private AcFunUtil acFunUtil;
 
    @Resource
    private ThreadPoolTaskExecutor taskExecutor;
 
    @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.loadTrueAdmin("执行成功"));
    }
 
    @RequestMapping("updateIqiyiAlbum")
    public void updateIqiyiAlbum(String url, PrintWriter out) {
        String aid = IqiyiUtil.getAlbumIdFromPlayUrl(url);
        if (StringUtil.isNullOrEmpty(aid)) {
            out.print(JsonUtil.loadFalseAdmin("未能获取到专辑"));
        } else {
            iqiyiUtil.updateAlbum(aid);
            out.print(JsonUtil.loadTrueAdmin("专辑更新成功"));
        }
    }
 
    @RequestMapping("addIqiyiShortVideo")
    public void addIqiyiShortVideo(String urlJson, PrintWriter out) {
//        JSONArray array = JSONArray.fromObject(urlJson);
//        int count = 0;
//        for (int i = 0; i < array.size(); i++) {
//            String aid = IqiyiUtil.getAlbumIdFromPlayUrl(array.optString(i));
//            if (!StringUtil.isNullOrEmpty(aid))
//                count++;
//
//            // 添加小视频
//
//        }
//
//        String aid = IqiyiUtil.getAlbumIdFromPlayUrl("");
//        if (StringUtil.isNullOrEmpty(aid)) {
//            out.print(JsonUtil.loadFalseAdmin("未能获取到专辑"));
//        } else {
//            iqiyiUtil.updateAlbum(aid);
//            out.print(JsonUtil.loadTrueAdmin("专辑更新成功"));
//        }
    }
 
    @RequestMapping("iqiyiUpdate")
    public void iqiyiUpdate(PrintWriter out) {
        taskExecutor.execute(new Runnable() {
            @Override
            public void run() {
                iqiyiUtil.updateAll("");
            }
        });
        JSONObject data = new JSONObject();
        data.put("msg", "正在后台更新中");
        out.print(data);
    }
 
 
}