admin
2022-04-16 04f09e52ffd4681bdfd85e51acd3da0d1280c3d3
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
package com.yeshi.buwan.controller.admin.api;
 
import com.google.gson.*;
import com.yeshi.buwan.domain.VideoResource;
import com.yeshi.buwan.service.imp.VideoResourceService;
import com.yeshi.buwan.vo.video.CommonVideoSearchQuery;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.yeshi.utils.JsonUtil;
import org.yeshi.utils.TimeUtil;
import com.google.gson.reflect.TypeToken;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.io.PrintWriter;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
 
import com.yeshi.buwan.domain.video.VideoResourceInfoMap;
import com.yeshi.buwan.service.inter.video.VideoResourceInfoMapService;
 
@Controller
@RequestMapping("admin/new/api/video/video_resource_info_map")
public class VideoResourceInfoMapAdminController {
 
    @Resource
    private VideoResourceInfoMapService videoResourceInfoMapService;
 
    @Resource
    private VideoResourceService videoResourceService;
 
 
    private String loadPrint(String callback, String root) {
        return root;
    }
 
    @RequestMapping("list")
    public void list(CommonVideoSearchQuery query, int page, int limit, String callback, PrintWriter out) {
        List<VideoResourceInfoMap> list = videoResourceInfoMapService.listByDetailSystemId(query.getDetailSystemId(), page, limit);
 
        if (list != null) {
            List<String> ridList = new ArrayList<>();
            for (VideoResourceInfoMap map : list) {
                ridList.add(map.getResourceId() + "");
            }
            List<VideoResource> resourceList = videoResourceService.getResource(ridList);
            Map<String, VideoResource> map = resourceList.stream().collect(Collectors.toMap(VideoResource::getId, videoResource -> videoResource));
            for (VideoResourceInfoMap info : list) {
                info.setResource(map.get(info.getResourceId() + ""));
            }
        }
 
        long count = videoResourceInfoMapService.countByDetailSystemId(query.getDetailSystemId());
        JSONObject data = new JSONObject();
        Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new JsonSerializer<Date>() {
 
            @Override
            public JsonElement serialize(Date date, Type type, JsonSerializationContext jsonSerializationContext) {
                return date == null ? new JsonPrimitive("") : new JsonPrimitive(TimeUtil.getGernalTime(date.getTime(), "yyyy.MM.dd HH:mm"));
            }
        }).create();
 
        data.put("list", gson.toJson(list));
        data.put("count", count);
        out.print(loadPrint(callback, JsonUtil.loadTrueResult(data)));
    }
 
    @RequestMapping("delete")
    public void delete(String ids, String callback, PrintWriter out) {
        Type type = new TypeToken<List<String>>() {
        }.getType();
        List<String> idList = new Gson().fromJson(ids, type);
        videoResourceInfoMapService.delete(idList);
        out.print(loadPrint(callback, JsonUtil.loadTrueResult("")));
    }
 
 
    @RequestMapping("add")
    public void add(VideoResourceInfoMap bean, HttpSession session, String callback, PrintWriter out) {
        try {
            videoResourceInfoMapService.add(bean);
            out.print(loadPrint(callback, JsonUtil.loadTrueResult("")));
        } catch (Exception e) {
            out.print(loadPrint(callback, JsonUtil.loadFalseResult(e.getMessage())));
        }
    }
 
 
    @RequestMapping("get")
    public void get(String id, HttpSession session, String callback, PrintWriter out) {
        VideoResourceInfoMap entity = videoResourceInfoMapService.get(id);
        entity.setResource(videoResourceService.getResource(entity.getResourceId() + ""));
        if (entity != null) {
            out.print(loadPrint(callback, JsonUtil.loadTrueResult(entity)));
        } else {
            out.print(loadPrint(callback, JsonUtil.loadFalseResult("ID不存在")));
        }
    }
 
 
    @RequestMapping("update")
    public void update(VideoResourceInfoMap bean, HttpSession session, String callback, PrintWriter out) {
        if (bean.getId() == null) {
            out.print(loadPrint(callback, JsonUtil.loadFalseResult("ID不能为空")));
        }
        try {
            videoResourceInfoMapService.update(bean);
        } catch (Exception e) {
            out.print(loadPrint(callback, JsonUtil.loadFalseResult(e.getMessage())));
        }
        out.print(loadPrint(callback, JsonUtil.loadTrueResult("")));
    }
 
 
}