admin
2021-09-03 b41a6efe17ba61d150c5a9b7309651cebae54e0d
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
package com.yeshi.buwan.controller.admin.api;
 
import com.google.gson.*;
import com.yeshi.buwan.domain.VideoInfo;
import com.yeshi.buwan.domain.live.SuperTVLiveCategory;
import com.yeshi.buwan.domain.live.TVLiveCategory;
import com.yeshi.buwan.domain.special.Special;
import com.yeshi.buwan.domain.special.SpecialVideo;
import com.yeshi.buwan.domain.special.SuperSpecial;
import com.yeshi.buwan.domain.system.DetailSystem;
import com.yeshi.buwan.domain.system.SystemInfo;
import com.yeshi.buwan.domain.web.DetailSystemSelect;
import com.yeshi.buwan.domain.web.SpecialAdmin;
import com.yeshi.buwan.exception.live.TVLiveCategoryException;
import com.yeshi.buwan.service.imp.SpecialService;
import com.yeshi.buwan.service.imp.SystemService;
import com.yeshi.buwan.service.inter.live.TVLiveCategoryService;
import com.yeshi.buwan.util.*;
import com.yeshi.buwan.web.tag.PageEntity;
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 javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.io.PrintWriter;
import java.lang.reflect.Type;
import java.util.*;
 
@Controller
@RequestMapping("admin/new/api/tvlive/category")
public class TVLiveCategoryAdminController {
 
    @Resource
    private TVLiveCategoryService tvLiveCategoryService;
 
    @Resource
    private SystemService systemService;
 
    private Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new JsonSerializer<Date>() {
 
        @Override
        public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) {
            return  src==null? new JsonPrimitive(""): new JsonPrimitive(TimeUtil.getGernalTime(src.getTime(),"yyyy.MM.dd HH:mm"));
        }
    }).create();
 
    @RequestMapping(value = "/getCategoryList", method = RequestMethod.POST)
    public void getCategoryList(HttpSession session, String detailSystemId, String key, int page, PrintWriter out) {
        SystemInfo systemInfo = SystemUtil.getAdminSelectedSystem(session);
        detailSystemId = StringUtil.isNullOrEmpty(detailSystemId) ? null : detailSystemId;
        List<TVLiveCategory> list = tvLiveCategoryService.list(detailSystemId, systemInfo.getId(), key, page, Constant.pageCount);
        List<DetailSystem> detailSystemList = systemService.getDetailSystemList(systemInfo.getId());
        List<TVLiveCategoryAdmin> resultList = new ArrayList<>();
        if (list != null)
            for (TVLiveCategory category : list) {
                Set<String> selectedDetailSystemSet = new HashSet<>();
                List<SuperTVLiveCategory> superList = tvLiveCategoryService.listSuper(category.getId());
                for (SuperTVLiveCategory cy : superList) {
                    selectedDetailSystemSet.add(cy.getDetailSystemId());
                }
                List<DetailSystemSelect> selectList = new ArrayList<>();
                for (DetailSystem detailSystem : detailSystemList) {
                    detailSystem.setSystem(null);
                    detailSystem.setInfo(null);
                    DetailSystemSelect select = new DetailSystemSelect();
                    select.setDetailSystem(detailSystem);
                    select.setSelected(selectedDetailSystemSet.contains(detailSystem.getId()));
                    selectList.add(select);
                }
                resultList.add(new TVLiveCategoryAdmin(category, selectList));
            }
 
        long count = tvLiveCategoryService.count(detailSystemId, systemInfo.getId(), key);
        JSONObject data = new JSONObject();
        data.put("pageEntity", new PageEntity(page, Constant.pageCount, (int) count));
        data.put("data", gson.toJson(resultList));
        out.print(JsonUtil.loadTrueAdmin(data.toString()));
    }
 
    @RequestMapping(value = "/addCategory", method = RequestMethod.POST)
    public void addCategory(TVLiveCategory category, String detailsystemids, HttpSession session, PrintWriter out) {
 
        if (StringUtil.isNullOrEmpty(category.getName())) {
            out.print(JsonUtil.loadFalseAdmin("数据不完整"));
            return;
        }
 
        category.setSystemId(SystemUtil.getAdminSelectedSystem(session).getId());
 
        List<String> detailSystemList = new ArrayList<>();
        if (!StringUtil.isNullOrEmpty(detailsystemids)) {
            String[] sps = detailsystemids.split(",");
            for (String sp : sps) {
                detailSystemList.add(sp);
            }
        }
 
        try {
            tvLiveCategoryService.addCategory(category, detailSystemList);
            out.print(JsonUtil.loadTrueAdmin(""));
        } catch (TVLiveCategoryException e) {
            out.print(JsonUtil.loadFalseAdmin(e.getMsg()));
        }
    }
 
 
    @RequestMapping(value = "/updateCategory", method = RequestMethod.POST)
    public void updateCategory(TVLiveCategory category, PrintWriter out) {
 
        if (StringUtil.isNullOrEmpty(category.getName())) {
            out.print(JsonUtil.loadFalseAdmin("数据不完整"));
            return;
        }
        tvLiveCategoryService.updateCategory(category);
        out.print(JsonUtil.loadTrueAdmin(""));
    }
 
 
    @RequestMapping(value = "/getCategory", method = RequestMethod.POST)
    public void getCategory(String id, PrintWriter out) {
        TVLiveCategory category = tvLiveCategoryService.selectCategoryBuPrimaryKey(id);
        out.print(JsonUtil.loadTrueAdmin(new Gson().toJson(category)));
    }
 
 
    /**
     * 删除分类
     *
     * @param ids
     * @param out
     */
    @RequestMapping(value = "/deleteCategory", method = RequestMethod.POST)
    public void deleteCategory(String ids, PrintWriter out) {
        if (StringUtil.isNullOrEmpty(ids)) {
            out.print(JsonUtil.loadFalseAdmin("ids不能为空"));
            return;
        }
        tvLiveCategoryService.deleteCateogry(Arrays.asList(ids.split(",")));
        out.print(JsonUtil.loadTrueAdmin(""));
    }
 
 
    @RequestMapping(value = "/deleteSuperCategory", method = RequestMethod.POST)
    public void deleteSuperCategory(String cid, String detailSystemId, PrintWriter out) {
        if (StringUtil.isNullOrEmpty(cid) || StringUtil.isNullOrEmpty(detailSystemId)) {
            out.print(JsonUtil.loadFalseAdmin("信息不完整"));
            return;
        }
        tvLiveCategoryService.deleteSuperCategory(cid, detailSystemId);
        out.print(JsonUtil.loadTrueAdmin(""));
    }
 
 
    @RequestMapping(value = "/addSuperCategory", method = RequestMethod.POST)
    public void addSuperCategory(String cid, String detailSystemId, Integer weight, String icon, PrintWriter out) {
 
        SuperTVLiveCategory superTVLiveCategory = new SuperTVLiveCategory();
        superTVLiveCategory.setCid(cid);
        superTVLiveCategory.setDetailSystemId(detailSystemId);
        superTVLiveCategory.setWeight(weight);
        superTVLiveCategory.setIcon(icon);
        tvLiveCategoryService.addSuperCategory(superTVLiveCategory);
        out.print(JsonUtil.loadTrueAdmin(""));
    }
 
 
    class TVLiveCategoryAdmin {
        private TVLiveCategory category;
        private List<DetailSystemSelect> detailSystemSelectList;
 
        public TVLiveCategoryAdmin(TVLiveCategory category, List<DetailSystemSelect> detailSystemSelectList) {
            this.category = category;
            this.detailSystemSelectList = detailSystemSelectList;
        }
 
        public TVLiveCategory getCategory() {
            return category;
        }
 
        public void setCategory(TVLiveCategory category) {
            this.category = category;
        }
 
        public List<DetailSystemSelect> getDetailSystemSelectList() {
            return detailSystemSelectList;
        }
 
        public void setDetailSystemSelectList(List<DetailSystemSelect> detailSystemSelectList) {
            this.detailSystemSelectList = detailSystemSelectList;
        }
    }
 
}