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
package com.yeshi.buwan.controller.admin.api;
 
import java.io.PrintWriter;
import java.util.List;
 
import net.sf.json.JSONObject;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
 
import com.yeshi.buwan.domain.VideoInfo;
import com.yeshi.buwan.domain.VideoType;
import com.yeshi.buwan.domain.recommend.CategoryRecommendCacheVideo;
import com.yeshi.buwan.service.imp.CategoryRecommendCacheVideoService;
import com.yeshi.buwan.service.imp.VideoInfoService;
import com.yeshi.buwan.service.imp.VideoTypeService;
import com.yeshi.buwan.util.JsonUtil;
import com.yeshi.buwan.web.tag.PageEntity;
 
@Controller
@RequestMapping("admin/new/api/top")
public class CategoryRecommendCacheVideoAdminController {
    
    @Autowired
    private CategoryRecommendCacheVideoService topService;
    
    @Autowired
    private VideoInfoService videoInfoService;
    
    @Autowired
    private VideoTypeService videoTypeService;
    
    @RequestMapping("getTopList")
    public void getTopList(long videotype,String key,int page,int pageSize,PrintWriter out){
        List<CategoryRecommendCacheVideo> list = topService.getList(videotype,key,page,pageSize);
        int count = topService.getCount(videotype,key);
        PageEntity pe = new PageEntity();
        pe.setPageIndex(page);
        pe.setPageSize(pageSize);
        pe.setTotalCount(count);
        JSONObject data = new JSONObject();
        data.put("list", list);
        data.put("pe",pe);
        String json = JsonUtil.loadTrueAdmin(data);
        out.print(json);
    }
    
    @RequestMapping("getTop")
    public void getTop(long id,PrintWriter out){
        CategoryRecommendCacheVideo crcv =topService.getTop(id);
        if(crcv == null){
            JsonUtil.loadFalseAdmin("不存在该对象");
            return;
        }
        String json = JsonUtil.loadTrueAdmin(crcv);
        out.print(json);
    }
    
    @RequestMapping("editTopOrderBy")
    public void editTopOrderBy(long id,int orderBy,int rank,PrintWriter out){
        CategoryRecommendCacheVideo crcv =topService.getTop(id);
        if(crcv == null){
            JsonUtil.loadFalseAdmin("不存在该对象");
            return;
        }
        crcv.setOrderby(orderBy);
        crcv.setRank(rank);
        topService.update(crcv);
        String json = JsonUtil.loadTrueAdmin("");
        out.print(json);
    }
    
    @RequestMapping("addTop")
    public void addTop(long[] vids,long tid,PrintWriter out){
        for (long vid : vids) {
            VideoInfo videoInfo = videoInfoService.getVideoInfo(vid+"");
            if(videoInfo==null){
                continue;
            }
            VideoType videoType = videoTypeService.getVideoType(tid);
            if(videoType == null){
                JsonUtil.loadFalseAdmin("不存在该分类");
                return;
            }
            CategoryRecommendCacheVideo find = topService.getTop(vid,tid);
            if(find != null){
                continue;
            }
            CategoryRecommendCacheVideo crcv = new CategoryRecommendCacheVideo();
            crcv.setOrderby(0);
            crcv.setVideoInfo(videoInfo);
            crcv.setVideoType(videoType);
            crcv.setCreatetime(System.currentTimeMillis()+"");
            topService.save(crcv);
        }
        out.print(JsonUtil.loadTrueAdmin(""));
    }
    
    @RequestMapping("deleteTop")
    public void deleteTop(long[] ids,PrintWriter out){
        for (long id : ids) {
            topService.delete(id);
        }
        out.print(JsonUtil.loadTrueAdmin(""));
    }
    
    
}