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
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
package com.yeshi.buwan.controller.admin.api;
 
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
 
import com.yeshi.buwan.util.SystemUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
 
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.yeshi.buwan.domain.system.DetailSystem;
import com.yeshi.buwan.domain.VideoInfo;
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.web.SpecialAdmin;
import com.yeshi.buwan.service.imp.SpecialService;
import com.yeshi.buwan.service.imp.SystemService;
import com.yeshi.buwan.util.Constant;
import com.yeshi.buwan.util.StringUtil;
import com.yeshi.buwan.web.tag.PageEntity;
 
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
 
@Controller
@RequestMapping("admin/new/api/special")
public class SpecialController {
 
    @Resource
    private SpecialService specialService;
 
    @Resource
    private SystemService systemService;
 
    @RequestMapping(value = "/getspeciallist", method = RequestMethod.POST)
    public void getSpecialList(HttpSession session, PrintWriter out) {
        List<Special> list = specialService.getSpecialListBySystem(SystemUtil.getAdminSelectedSystemId(session));
        JSONArray array = new JSONArray();
        if (list != null)
            for (Special special : list) {
                JSONObject obj = new JSONObject();
                obj.put("id", special.getId());
                obj.put("name", special.getName());
                array.add(obj);
            }
        JSONObject object = new JSONObject();
        object.put("code", 0);
        object.put("data", array);
        out.print(object);
    }
 
    @RequestMapping(value = "/addspecialvideo", method = RequestMethod.POST)
    public void addSpecialVideo(String specialid, String videos, PrintWriter out) {
        String[] videoStr = videos.split(",");
        String[] sps = specialid.split(",");
        for (String videoid : videoStr) {
            for (String sp : sps) {
                SpecialVideo sv = new SpecialVideo();
                sv.setCreatetime(System.currentTimeMillis() + "");
                sv.setOrderby(0);
                sv.setSpecial(new Special(sp));
                sv.setVideo(new VideoInfo(videoid));
                specialService.addSpecialVideo(sv);
            }
        }
 
        JSONObject object = new JSONObject();
        object.put("code", 0);
        object.put("msg", "添加成功");
        out.print(object);
    }
 
    /**
     * 关键字搜索列表
     *
     * @return
     */
    @RequestMapping(value = "/specialList", method = RequestMethod.POST)
    public void specialList(int pageIndex, String key, int detailsystem, HttpSession session, PrintWriter out) {
 
        if (pageIndex == 0)
            pageIndex = 1;
 
        List<SpecialAdmin> list = specialService.getSpecialAdmin(key, SystemUtil.getAdminSelectedSystemId(session), detailsystem, pageIndex);
        long count = specialService.getSpecialAdminCount(key, SystemUtil.getAdminSelectedSystemId(session), detailsystem);
        PageEntity pe = new PageEntity();
        pe.setPageIndex(pageIndex);
        pe.setPageSize(Constant.pageCount);
        Map<String, String> map = new HashMap<String, String>();
        map.put("key", key);
        map.put("detailsystem", detailsystem + "");
        pe.setParams(map);
        pe.setTotalCount((int) count);
        Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
        JSONObject root = new JSONObject();
        root.put("code", "0");
        root.put("pageEntity", pe);
        root.put("SpecialAdminList", gson.toJson(list));
        System.out.println(root.toString());
        out.print(root);
        return;
    }
 
    @RequestMapping(value = "/delSpecial", method = RequestMethod.POST)
    public void delSpecial(String ids, PrintWriter out) {
        if (ids != null && !"".equals(ids.trim())) {
            String[] idArr = ids.split(",");
            for (String id : idArr) {
                specialService.deleteSpecial(new Special(id));
                System.out.println(id);
            }
            out.print("yes");
        }
    }
 
    @RequestMapping(value = "/setSpecialApp", method = RequestMethod.POST)
    public void set(String type, String detailSystem, String id, PrintWriter out) {
 
        System.out.println("type=" + type);
        System.out.println("detailSystem=" + detailSystem);
 
        if ("add".equalsIgnoreCase(type)) {// 获取来源列表
            if (!StringUtil.isNullOrEmpty(detailSystem) && !StringUtil.isNullOrEmpty(id)) {
                SuperSpecial sz = new SuperSpecial();
                sz.setDetailSystem(new DetailSystem(detailSystem));
                sz.setSpecial(new Special(id));
                specialService.addSuperSpecial(sz);
                out.print("yes");
            }
        } else if ("delete".equalsIgnoreCase(type)) {// 获取下级分类
            if (!StringUtil.isNullOrEmpty(detailSystem) && !StringUtil.isNullOrEmpty(id)) {
                specialService.deleteSpecialAdmin(id, detailSystem);
                out.print("yes");
            }
        }
    }
 
    @RequestMapping(value = "/getSpecial", method = RequestMethod.POST)
    public void getSpecial(String id, PrintWriter out) {
        Special special = specialService.getSpecial(id);
        JSONObject json = new JSONObject();
        json.put("code", "0");
        json.put("data", new Gson().toJson(special));
        out.print(json);
        return;
    }
 
    @RequestMapping(value = "/updateSpecial", method = RequestMethod.POST)
    public void updateSpecial(String id, String introduction, String name, int orderby, String picture, String show, String showonmain, PrintWriter out) {
 
        System.out.println("id:" + id);
        System.out.println("name:" + name);
        System.out.println("show:" + show);
        System.out.println("showonmain:" + showonmain);
        System.out.println("picture:" + picture);
        System.out.println("orderby:" + orderby);
        System.out.println("introduction:" + introduction);
 
        Special special = specialService.getSpecial(id);
        special.setIntroduction(introduction);
        special.setName(name);
        special.setOrderby(orderby);
        special.setPicture(picture);
        if ("on".equalsIgnoreCase(show))
            special.setShow(true);
        else
            special.setShow(false);
 
        if ("on".equalsIgnoreCase(showonmain))
            special.setShowonmain(true);
        else
            special.setShowonmain(false);
 
        specialService.updateSpecial(special);
 
        out.print("yes");
        return;
    }
 
    @RequestMapping(value = "/addSpecial", method = RequestMethod.POST)
    public void addSpecial(String detailSystems, String introduction, String name, int orderby, String picture, String show, String showonmain, HttpSession session, PrintWriter out) {
 
        System.out.println("name:" + name);
        System.out.println("detailSystems:" + detailSystems);
        System.out.println("show:" + show);
        System.out.println("showonmain:" + showonmain);
        System.out.println("picture:" + picture);
        System.out.println("orderby:" + orderby);
        System.out.println("introduction:" + introduction);
 
 
        List<String> sysList = new ArrayList<String>();
        if (!StringUtil.isNullOrEmpty(detailSystems)) {
            if (detailSystems.contains(",")) {
                for (String st : detailSystems.split(","))
                    sysList.add(st);
            } else
                sysList.add(detailSystems);
        }
 
        Special special = new Special();
        special.setIntroduction(introduction);
        special.setName(name);
        special.setOrderby(orderby);
        special.setPicture(picture);
        special.setCreatetime(System.currentTimeMillis() + "");
        if ("on".equalsIgnoreCase(show))
            special.setShow(true);
        else
            special.setShow(false);
 
        if ("on".equalsIgnoreCase(showonmain))
            special.setShowonmain(true);
        else
            special.setShowonmain(false);
 
 
        special.setSystem(SystemUtil.getAdminSelectedSystem(session));
 
        specialService.addSpecial(special);
 
        for (String ds : sysList) {
            SuperSpecial ss = new SuperSpecial();
            ss.setDetailSystem(new DetailSystem(ds));
            ss.setSpecial(special);
            specialService.addSuperSpecial(ss);
        }
        out.print("yes");
 
        return;
    }
 
    @RequestMapping(value = "/specialVideoList", method = RequestMethod.POST)
    public void specialVideoList(String key, String specialId, int pageIndex, PrintWriter out) {
 
        System.out.println("key==" + key);
        System.out.println("specialId==" + specialId);
 
        long count = specialService.getSpecialVideoListCount(specialId, key);
        PageEntity pe = new PageEntity();
        pe.setPageIndex(pageIndex);
        pe.setPageSize(Constant.pageCount);
        Map<String, String> map = new HashMap<String, String>();
        map.put("key", key);
        map.put("specialId", specialId);
        pe.setParams(map);
        pe.setTotalCount((int) count);
        JSONObject json = new JSONObject();
        json.put("code", "0");
        json.put("pageEntity", pe);
        Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
        List<SpecialVideo> list = specialService.getSpecialVideoList(specialId, pe, key);
        json.put("specialVideoList", gson.toJson(list));
        out.print(json);
        return;
    }
 
    @RequestMapping(value = "/deleteSpecialVideoList", method = RequestMethod.POST)
    public void deleteSpecialVideoList(String ids, PrintWriter out) {
        if (!StringUtil.isNullOrEmpty(ids)) {
            String[] idArr = ids.split(",");
            for (String id : idArr) {
                specialService.deleteSpecialVideo(id);
                System.out.println("iiid--" + id);
            }
            out.print("yes");
        }
        return;
    }
 
}