admin
2019-05-06 7f703a54a555334430e900941072f31e1c3b0210
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
package com.yeshi.fanli.controller.admin;
 
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
 
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.yeshi.utils.JsonUtil;
 
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.yeshi.fanli.entity.bus.clazz.GoodsClass;
import com.yeshi.fanli.exception.FloatADException;
import com.yeshi.fanli.exception.GoodsClassException;
import com.yeshi.fanli.service.inter.config.BusinessSystemService;
import com.yeshi.fanli.service.inter.goods.GoodsClassService;
import com.yeshi.fanli.service.inter.goods.GoodsSecondClassService;
import com.yeshi.fanli.service.inter.goods.GoodsSubClassService;
import com.yeshi.fanli.service.inter.goods.SuperGoodsClassService;
import com.yeshi.fanli.service.inter.lable.LabelClassService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.Utils;
 
import net.sf.json.JSONObject;
 
@Controller
@RequestMapping("admin/new/api/v1/goodsclass")
public class GoodsClassAdminCotroller {
 
    @Resource
    private GoodsClassService goodsClassService;
 
    @Resource
    private SuperGoodsClassService superGoodsClassService;
 
    @Resource
    private GoodsSecondClassService goodsSecondClassService;
 
    @Resource
    private GoodsSubClassService goodsSubClassService;
 
    @Resource
    private LabelClassService labelClassService;
 
    @Resource
    private BusinessSystemService businessSystemService;
 
    @RequestMapping(value = "queryAll")
    public void listquery(String callback, PrintWriter out) {
 
        try {
            List<GoodsClass> goodsClassList = goodsClassService.listquery();
 
            if (goodsClassList == null || goodsClassList.size() == 0) {
                JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("暂无数据"));
                return;
            }
 
            JSONObject data = new JSONObject();
            data.put("goodsClassList", goodsClassList);
 
            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
        } catch (Exception e) {
            e.printStackTrace();
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作异常"));
        }
 
    }
 
    @RequestMapping(value = "getGoodsClasAll")
    public void getGoodsClassAll(String callback, PrintWriter out) {
        List<GoodsClass> goodsClassList = goodsClassService.getGoodsClassAll();
 
        if (goodsClassList == null || goodsClassList.size() == 0) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("暂无数据"));
        } else {
 
            JSONObject data = new JSONObject();
            data.put("goodsClassList", goodsClassList);
            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
        }
    }
 
    /**
     * 保存信息
     * 
     * @param callback
     * @param special
     * @param out
     */
    @RequestMapping(value = "save")
    public void save(String callback, GoodsClass goodsClass, String jumpType, HttpServletRequest request,
            PrintWriter out) {
        if (goodsClass.getTaobaoCids() != null)
            goodsClass.setTaobaoCids(goodsClass.getTaobaoCids().replace(",", ","));
        try {
            // 1. 先判断httpRequest 是否含有文件类型
            if (request instanceof MultipartHttpServletRequest) {
                MultipartHttpServletRequest fileRequest = (MultipartHttpServletRequest) request;
                goodsClassService.saveObject(fileRequest.getFile("file"), goodsClass);
            } else {
                goodsClassService.saveObject(null, goodsClass);
            }
 
            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("保存成功"));
        } catch (FloatADException e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg()));
        } catch (Exception e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("保存失败"));
            e.printStackTrace();
        }
    }
 
    /**
     * 修改排序
     * 
     * @param callback
     * @param goodsClass
     * @param out
     */
    @RequestMapping(value = "updateOrder")
    public void updateOrder(String callback, Long id, Integer moveType, PrintWriter out) {
        try {
            goodsClassService.updateOrder(id, moveType);
            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("操作成功"));
        } catch (GoodsClassException e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg()));
        } catch (Exception e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作失败"));
            e.printStackTrace();
        }
    }
 
    /**
     * 批量删除
     * 
     * @param callback
     * @param ids
     * @param out
     */
    @RequestMapping(value = "deleteBatch")
    public void deleteBatch(String callback, String ids, PrintWriter out) {
 
        Gson gson = new Gson();
 
        try {
            List<String> recordIds = gson.fromJson(ids, new TypeToken<ArrayList<String>>() {
            }.getType());
 
            if (recordIds == null || recordIds.size() == 0) {
                JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请选择需删除数据"));
            } else {
 
                for (String id : recordIds) {
                    Long recordId = Long.parseLong(id);
 
                    superGoodsClassService.deleteSuperGoodsClass(recordId);
 
                    // 删除子类分类
                    goodsSubClassService.deleteByRootId(recordId);
                    // 删除类别关联标签
                    labelClassService.deleteByClassId(recordId);
 
                    goodsClassService.deleteGoodsClass(recordId);
                }
                JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("删除成功"));
            }
 
        } catch (Exception e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作异常"));
            e.printStackTrace();
        }
 
    }
 
    /**
     * 删除图片
     * 
     * @param callback
     * @param file
     * @param out
     * @param response
     */
    @RequestMapping(value = "removePicture")
    public void removePicture(String callback, Long id, PrintWriter out) {
 
        try {
            GoodsClass goodsClass = goodsClassService.getGoodsClass(id);
 
            if (goodsClass == null) {
                out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("该类别不存在或已被删除")));
                return;
            }
 
            goodsClassService.removePicture(goodsClass);
 
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult("图片删除成功")));
 
        } catch (Exception e) {
            e.printStackTrace();
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("操作异常")));
        }
    }
 
    @RequestMapping(value = "setSuperSystem")
    public void setSuperSystem(String callback, String type, Long gcid, String platform, String packageName,
            PrintWriter out) {
        platform = Utils.getMap().get(platform);
        if (Constant.DEL.equals(type)) {
            Integer integer = superGoodsClassService.deleteSuperGoodsClass(gcid, platform, packageName);
            if (integer > 0) {
                JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("删除成功"));
            } else {
                JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("删除失败"));
            }
        } else {
            superGoodsClassService.addSuperGoodsClass(gcid, platform, packageName);
            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("添加成功"));
        }
    }
 
    @RequestMapping(value = "getClassOption")
    public void getClassOption(String callback, PrintWriter out) {
 
        List<GoodsClass> goodsClassList = goodsClassService.getGoodsClassAll();
 
        JSONObject data = new JSONObject();
 
        data.put("result_list", goodsClassList);
 
        JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
 
    }
}