yujian
2020-01-08 81ed418ee16df24b768a3f78cd22d02f020d6314
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
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.yeshi.utils.JsonUtil;
 
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.yeshi.fanli.entity.common.AdminUser;
import com.yeshi.fanli.service.inter.lable.LabelGoodsService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.StringUtil;
 
@Controller
@RequestMapping("admin/new/api/v1/labelGoods")
public class LabelGoodsAdminController {
 
    @Resource
    private LabelGoodsService labelGoodsService;
 
 
    /**
     * 批量商品添加标签-关联lableId
     * 
     * @param callback
     * @param labIds
     * @param goodIds
     * @param request
     * @param out
     */
    @RequestMapping(value = "batchGoodsAddLables")
    public void batchGoodsAddLables(String callback, String labIds, String ids, 
            HttpServletRequest request, PrintWriter out) {
 
        if (StringUtil.isNullOrEmpty(ids)) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请选择需操作的商品"));
            return;
        }
 
        Gson gson = new Gson();
        List<Long> goodsIdList = gson.fromJson(ids, new TypeToken<ArrayList<Long>>() {}.getType());
        if (goodsIdList == null || goodsIdList.size() == 0) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请选择需操作的商品"));
            return;
        }
        
        try {
            // 获取当前操作用户
            AdminUser admin = (AdminUser) request.getSession().getAttribute(Constant.SESSION_ADMIN);
 
            if (goodsIdList.size() == 1) {
                List<Long> labIdList = null;
                if (!StringUtil.isNullOrEmpty(labIds)) {
                    labIdList = gson.fromJson(labIds, new TypeToken<ArrayList<Long>>() {}.getType());
                }
                
                // 单个处理
                Long goodsId = goodsIdList.get(0);
                labelGoodsService.singleGoodsAddLables(goodsId, labIdList, admin);
            } else {
                if (StringUtil.isNullOrEmpty(labIds)) {
                    JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请选择添加的标签"));
                    return;
                }
                
                List<Long> labIdList = gson.fromJson(labIds, new TypeToken<ArrayList<Long>>() {}.getType());
                if (labIdList == null || labIdList.size() == 0) {
                    JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请选择添加的标签"));
                    return;
                }
                // 批量处理
                labelGoodsService.batchGoodsAddLables(goodsIdList, labIdList, admin);
            }
 
            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("操作成功"));
 
        } catch (Exception e) {
            // TODO Auto-generated catch block
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作异常"));
            e.printStackTrace();
        }
    }
 
    /**
     * 批量商品添加标签-关联lableId
     * 
     * @param callback
     * @param labIds
     * @param goodIds
     * @param request
     * @param out
     */
    @RequestMapping(value = "singleGoodsAddLables")
    public void singleGoodsAddLables(String callback, String labIds, Long goodsId, 
            HttpServletRequest request, PrintWriter out) {
 
        try {
            // 获取当前操作用户
            AdminUser admin = (AdminUser) request.getSession().getAttribute(Constant.SESSION_ADMIN);
 
 
            if (goodsId == null) {
                JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请选择需操作的商品"));
                return;
            }
 
            Gson gson = new Gson();
            List<Long> labIdList = gson.fromJson(labIds, new TypeToken<ArrayList<Long>>() {}.getType());
 
            labelGoodsService.singleGoodsAddLables(goodsId, labIdList, admin);
 
            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("操作成功"));
 
        } catch (Exception e) {
            // TODO Auto-generated catch block
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作异常"));
            e.printStackTrace();
        }
    }
    
    
}