admin
2021-07-30 a66b556036c2b3936a51fd7b7e54a204eb31dc14
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
package com.yeshi.buwan.controller.admin.api;
 
import java.io.PrintWriter;
import java.io.Serializable;
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.domain.recommend.HomeRecommendSpecial;
import com.yeshi.buwan.service.inter.recommend.HomeRecommendSpecialService;
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.HomeAd;
import com.yeshi.buwan.domain.SuperHomeAd;
import com.yeshi.buwan.domain.VideoInfo;
import com.yeshi.buwan.domain.special.Special;
import com.yeshi.buwan.domain.web.DetailSystemSelect;
import com.yeshi.buwan.domain.web.HomeAdAdmin;
import com.yeshi.buwan.service.imp.HomeAdService;
import com.yeshi.buwan.service.imp.SpecialService;
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/homebanner")
public class HomeBannerController {
    @Resource
    private HomeAdService homeAdService;
    @Resource
    private SpecialService specialService;
 
    @Resource
    private HomeRecommendSpecialService homeRecommendSpecialService;
 
    @RequestMapping(value = "/gethomeadlistadmin", method = RequestMethod.POST)
    public void getHomeBannerListAdmin(int page, int detailsystem, String key,String special, HttpSession session, PrintWriter out) {
        key = StringUtil.isNullOrEmpty(key) ? "" : key;
        String dataKey = null;
        if (special != null && !special.equalsIgnoreCase("0")) {
            HomeRecommendSpecial bean = homeRecommendSpecialService.getSpecial(special);
            if (bean != null) {
                dataKey = bean.getDataKey();
            }
        }
 
 
        List<HomeAdAdmin> list = homeAdService.getHomeAdAdmin(key, SystemUtil.getAdminSelectedSystemId(session), detailsystem,dataKey, page);
 
        long count = homeAdService.getHomeAdAdminCount(key, SystemUtil.getAdminSelectedSystemId(session), detailsystem,dataKey);
        PageEntity pe = new PageEntity();
        pe.setPageIndex(page);
        pe.setPageSize(Constant.pageCount);
        pe.setTotalCount((int) count);
        JSONArray array = new JSONArray();
        Gson gson = new GsonBuilder().create();
 
        Map<String, HomeRecommendSpecial> specialMap = new HashMap<>();
 
        for (HomeAdAdmin ht : list) {
            String specialDataKey = ht.getHomeAd().getHomeAd().getSpecialDataKey();
            if (specialMap.get(specialDataKey) == null) {
                specialMap.put(specialDataKey, homeRecommendSpecialService.getSpecialByDataKey(specialDataKey));
            }
 
            JSONObject root = new JSONObject();
            ht.getHomeAd().getHomeAd().setSystem(null);
            ht.getHomeAd().getHomeAd().setTag(null);
            ht.getHomeAd().getHomeAd().setAdmin(null);
            ht.getHomeAd().getHomeAd().setVideo(null);
            root.put("homeAd", gson.toJson(ht.getHomeAd().getHomeAd()));
            JSONArray darray = new JSONArray();
            for (DetailSystemSelect dss : ht.getDetailSystemList()) {
                dss.getDetailSystem().setSystem(null);
                darray.add(gson.toJson(dss));
            }
            root.put("detailSystemList", darray);
            root.put("special", specialMap.get(specialDataKey));
            array.add(root);
        }
 
        JSONObject data = new JSONObject();
        data.put("pageEntity", gson.toJson(pe));
        data.put("data", array);
 
        JSONObject object = new JSONObject();
        object.put("code", 0);
        object.put("data", data);
        out.print(object);
    }
 
    @RequestMapping(value = "/deletesuperhomead", method = RequestMethod.POST)
    public void deleteSuperHomeAd(long id, int detailsystem, PrintWriter out) {
        homeAdService.deleteHomeAdAdmin(id + "", detailsystem + "");
        JSONObject object = new JSONObject();
        object.put("code", 0);
        object.put("msg", "删除成功");
        out.print(object);
    }
 
    @RequestMapping(value = "/addsuperhomead", method = RequestMethod.POST)
    public void addSuperHomeAd(long id, int detailsystem, PrintWriter out) {
        SuperHomeAd sht = new SuperHomeAd();
        sht.setCreatetime(System.currentTimeMillis() + "");
        sht.setDetailSystem(new DetailSystem(detailsystem + ""));
        sht.setHomeAd(new HomeAd(id + ""));
        homeAdService.addSuperHomeAd(sht);
        JSONObject object = new JSONObject();
        object.put("code", 0);
        object.put("msg", "添加成功");
        out.print(object);
    }
 
    @RequestMapping(value = "/deletehomead", method = RequestMethod.POST)
    public void deleteHomeAd(String ids, PrintWriter out) {
        String[] idStrs = ids.split(",");
        for (String id : idStrs) {
            homeAdService.deleteHomeAd(id);
        }
        JSONObject object = new JSONObject();
        object.put("code", 0);
        object.put("msg", "删除成功");
        out.print(object);
    }
 
    @RequestMapping(value = "/gethomead", method = RequestMethod.POST)
    public void getHomeAd(String id, PrintWriter out) {
        HomeAd ht = homeAdService.getHomeAdById(id);
        String linkValue = "";
        switch (ht.getLinkType()) {
            case 1:
                linkValue = ht.getVideo().getId();
                break;
            case 2:
                linkValue = JSONObject.fromObject(ht.getParams()).optString("url");
                break;
            case 3:
                linkValue = JSONObject.fromObject(ht.getParams()).optString("id");
                break;
        }
        ht.setVideo(null);
        ht.setAdmin(null);
        ht.setSystem(null);
        Gson gson = new GsonBuilder().create();
        JSONObject obj = JSONObject.fromObject(gson.toJson(ht));
        obj.put("linkValue", linkValue);
 
        JSONObject object = new JSONObject();
        object.put("code", 0);
        object.put("data", obj);
        out.print(object);
    }
 
    @RequestMapping(value = "/updatehomead", method = RequestMethod.POST)
    public void updateHomeAd(HomeAd homeAd, String linkValue, PrintWriter out) {
        HomeAd ht = homeAdService.getHomeAdById(homeAd.getId());
        ht.setClazz(homeAd.getClazz());
        ht.setIntroduction(homeAd.getIntroduction());
        ht.setLinkType(homeAd.getLinkType());
        ht.setOrderby(homeAd.getOrderby());
        ht.setPicture(homeAd.getPicture());
        ht.setSpecialDataKey(homeAd.getSpecialDataKey());
        if (homeAd.getLinkType() == 1) {
            ht.setVideo(new VideoInfo(linkValue));
        } else if (homeAd.getLinkType() == 2) {
            JSONObject obj = new JSONObject();
            obj.put("url", linkValue);
            ht.setClazz("com.weikou.beibeivideo.ui.mine.BrowserActivity");
            ht.setVideo(new VideoInfo("1"));
            ht.setParams(obj.toString());
        } else if (homeAd.getLinkType() == 3) {
            JSONObject obj = new JSONObject();
            obj.put("id", linkValue);
            Special se = specialService.getSpecial(linkValue);
            if (se != null) {
                obj.put("title", se.getName());
            }
            ht.setVideo(new VideoInfo("1"));
            ht.setClazz("com.weikou.beibeivideo.ui.common.MVideosActivity");
            ht.setParams(obj.toString());
        }
 
        homeAdService.updateHomeAd(ht);
 
        JSONObject object = new JSONObject();
        object.put("code", 0);
        object.put("msg", "更改成功");
        out.print(object);
    }
 
    @RequestMapping(value = "/addhomead", method = RequestMethod.POST)
    public void addHomeAd(HomeAd homeAd, String linkValue, String detailsystemids,HttpSession session, PrintWriter out) {
        if (homeAd.getLinkType() == 1) {
            homeAd.setVideo(new VideoInfo(linkValue));
        } else if (homeAd.getLinkType() == 2) {
            JSONObject obj = new JSONObject();
            obj.put("url", linkValue);
            homeAd.setClazz("com.weikou.beibeivideo.ui.mine.BrowserActivity");
            homeAd.setVideo(new VideoInfo("1"));
            homeAd.setParams(obj.toString());
        } else if (homeAd.getLinkType() == 3) {
            JSONObject obj = new JSONObject();
            obj.put("id", linkValue);
            Special se = specialService.getSpecial(linkValue);
            if (se != null) {
                obj.put("title", se.getName());
            }
            homeAd.setVideo(new VideoInfo("1"));
            homeAd.setClazz("com.weikou.beibeivideo.ui.common.MVideosActivity");
            homeAd.setParams(obj.toString());
        }
        homeAd.setCreatetime(System.currentTimeMillis() + "");
        homeAd.setSystem(SystemUtil.getAdminSelectedSystem(session));
        Serializable id = homeAdService.addHomeAd(homeAd);
 
        if (id != null && !StringUtil.isNullOrEmpty(detailsystemids)) {
            homeAd.setId(id + "");
            String[] dss = detailsystemids.split(",");
            for (String did : dss) {
                SuperHomeAd sht = new SuperHomeAd();
                sht.setCreatetime(System.currentTimeMillis() + "");
                sht.setDetailSystem(new DetailSystem(did));
                sht.setHomeAd(new HomeAd(homeAd.getId()));
                homeAdService.addSuperHomeAd(sht);
            }
        }
 
        JSONObject object = new JSONObject();
        object.put("code", 0);
        object.put("msg", "添加成功");
        out.print(object);
    }
 
}