admin
2021-03-06 7804263c6061aef813f0db27cb3046f746572606
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
package com.yeshi.buwan.controller.admin.api;
 
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
 
import com.yeshi.buwan.util.SystemUtil;
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 com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.yeshi.buwan.domain.DetailSystem;
import com.yeshi.buwan.domain.HotStar;
import com.yeshi.buwan.domain.SuperHotStar;
import com.yeshi.buwan.domain.web.HotStarAdmin;
import com.yeshi.buwan.service.imp.StarService;
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;
 
@Controller
@RequestMapping("admin/new/api/hotstar")
public class HotStarController {
    @Resource
    private StarService starService;
    @Resource
    private SystemService systemService;
 
    @RequestMapping(value = "/hotStarList", method = RequestMethod.POST)
    public void hotStarList(int pageIndex, String key, int detailsystem, HttpSession session,
                            PrintWriter out) {
        if (pageIndex <= 0) {
            pageIndex = 1;
        }
        List<HotStarAdmin> list = starService.getHotStarAdmin(key, SystemUtil.getAdminSelectedSystemId(session),
                detailsystem, pageIndex);
        long count = starService.getHotStarAdminCount(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);
 
        JSONObject json = new JSONObject();
        json.put("code", "0");
        json.put("pageEntity", pe);
        Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation()
                .create();
        json.put("hotStarAdminList", gson.toJson(list));
        // List<DetailSystem> detailSystemList = .getDetailSystemList();
        // json.put("detailSystemList", gson.toJson(detailSystemList));
        out.print(json);
 
        return;
    }
 
    @RequestMapping("/getHotStar")
    public void getHotStar(String id, PrintWriter out) {
        HotStar hotStar = starService.getStar(id);
        JSONObject json = new JSONObject();
        json.put("code", "0");
        Gson gson = new Gson();
        json.put("hotStar", gson.toJson(hotStar));
        System.out.println(json.toString());
        out.print(json);
        return;
    }
 
    @RequestMapping("/updateHotStar")
    public void updateHotStar(String id, String beizhu, String country,
                              String job, String name, String orderby, String works,
                              String portrait, PrintWriter out) {
        HotStar hotStar = starService.getStar(id);
        if (hotStar == null) {
            out.print("no");
            return;
        }
        hotStar.setBeizhu(beizhu);
        hotStar.setCreatetime(System.currentTimeMillis() + "");
        hotStar.setCountry(country);
        hotStar.setJob(job);
        hotStar.setName(name);
        orderby = StringUtil.isNullOrEmpty(orderby) ? "0" : orderby;
        hotStar.setOrderby(Integer.parseInt(orderby));
        hotStar.setPortrait(portrait);
        hotStar.setWorks(works);
        starService.updateStar(hotStar);
        out.print("yes");
        return;
    }
 
    @RequestMapping("/addHotStar")
    public void addHotStar(String detailSystems, String beizhu, String country, String job, String name, String orderby, String portrait, String works, HttpSession session, PrintWriter out) {
        List<String> sysList = new ArrayList<>();
        if (!StringUtil.isNullOrEmpty(detailSystems)) {
            if (detailSystems.contains(",")) {
                for (String st : detailSystems.split(","))
                    sysList.add(st);
            } else
                sysList.add(detailSystems);
        }
        HotStar hotStar = new HotStar();
        hotStar.setBeizhu(beizhu);
        hotStar.setCreatetime(System.currentTimeMillis() + "");
        hotStar.setCountry(country);
        hotStar.setJob(job);
        hotStar.setName(name);
        orderby = StringUtil.isNullOrEmpty(orderby) ? "0" : orderby;
        hotStar.setOrderby(Integer.parseInt(orderby));
        hotStar.setPortrait(portrait);
        hotStar.setWorks(works);
        hotStar.setSystem(SystemUtil.getAdminSelectedSystem(session));
        hotStar = starService.addStar(hotStar);
        for (String ds : sysList) {
            SuperHotStar ss = new SuperHotStar();
            ss.setDetailSystem(new DetailSystem(ds));
            ss.setHotStar(hotStar);
            ss.setCreatetime(System.currentTimeMillis() + "");
            starService.addSuperHotStar(ss);
        }
        out.print("yes");
        return;
    }
 
    @RequestMapping(value = "/deleteHotStarList", method = RequestMethod.POST)
    public void deleteHotStarList(String ids, PrintWriter out) {
        String[] idArr = ids.split(",");
        for (String st : idArr) {
            starService.deleteStar(new HotStar(st));
            System.out.println(st);
        }
        out.print("yes");
        return;
    }
 
    @RequestMapping("setStarDetailSystem")
    public void setStarDetailSystem(String type, String detailSystem, String id, PrintWriter out) {
        System.out.println("type-" + type);
        System.out.println("detailSystem-" + detailSystem);
        System.out.println("id-" + id);
        if ("add".equalsIgnoreCase(type)) {
            if (!StringUtil.isNullOrEmpty(detailSystem) && !StringUtil.isNullOrEmpty(id)) {
                SuperHotStar sz = new SuperHotStar();
                sz.setCreatetime(System.currentTimeMillis() + "");
                sz.setDetailSystem(new DetailSystem(detailSystem));
                sz.setHotStar(new HotStar(id));
                starService.addSuperHotStar(sz);
            }
            out.print("yes");
        } else if ("delete".equalsIgnoreCase(type)) {// 获取下级分类
            if (!StringUtil.isNullOrEmpty(detailSystem) && !StringUtil.isNullOrEmpty(id)) {
                starService.deleteHotStarAdmin(id, detailSystem);
            }
            out.print("yes");
        }
    }
}