mitao
2024-04-30 ab4ea7b8f10c9b66aed9c2ea161a08b25c3851a7
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
package com.sinata.modular.mall.controller;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.sinata.core.base.controller.BaseController;
import com.sinata.core.base.tips.ErrorTip;
import com.sinata.core.common.annotion.BussinessLog;
import com.sinata.core.common.annotion.Permission;
import com.sinata.core.common.constant.factory.PageFactory;
import com.sinata.core.log.LogObjectHolder;
import com.sinata.modular.mall.model.MallClassifyOne;
import com.sinata.modular.mall.model.MallClassifyTwo;
import com.sinata.modular.mall.service.IMallClassifyOneService;
import com.sinata.modular.mall.service.IMallClassifyTwoService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
 
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
 
/**
 * 商品二级分类控制器
 *
 * @author goku
 */
@Controller
@RequestMapping("/mallClassifyTwo")
public class MallClassifyTwoController extends BaseController {
 
    private String PREFIX = "/mall/mallClassifyTwo/";
 
    @Autowired
    private IMallClassifyTwoService mallClassifyTwoService;
 
    @Autowired
    private IMallClassifyOneService mallClassifyOneService;
 
    /**
     * 跳转到商品二级分类首页
     */
    @RequestMapping("")
    public String index(Model model) {
        List<MallClassifyOne> mallClassifyOneList = this.mallClassifyOneService.selectList(new EntityWrapper<MallClassifyOne>().ne("is_delete", 1)
                .orderBy("sort", true));
        if (CollectionUtils.isEmpty(mallClassifyOneList)) {
            mallClassifyOneList = new ArrayList<MallClassifyOne>();
        }
        model.addAttribute("mallClassifyOneList", mallClassifyOneList);
        return PREFIX + "mallClassifyTwo.html";
    }
 
    /**
     * 跳转到添加商品二级分类
     */
    @RequestMapping("/mallClassifyTwo_add")
    public String mallClassifyTwoAdd(Model model) {
        List<MallClassifyOne> mallClassifyOneList = this.mallClassifyOneService
                .selectList(new EntityWrapper<MallClassifyOne>().eq("is_delete", 0).orderBy("sort", true));
        if (CollectionUtils.isEmpty(mallClassifyOneList)) {
            mallClassifyOneList = new ArrayList<MallClassifyOne>();
        }
        model.addAttribute("mallClassifyOneList", mallClassifyOneList);
        return PREFIX + "mallClassifyTwo_add.html";
    }
 
    /**
     * 跳转到修改商品二级分类
     */
    @RequestMapping("/mallClassifyTwo_update/{mallClassifyTwoId}")
    public String mallClassifyTwoUpdate(@PathVariable Integer mallClassifyTwoId, Model model) {
        MallClassifyTwo mallClassifyTwo = mallClassifyTwoService.selectById(mallClassifyTwoId);
        model.addAttribute("item", mallClassifyTwo);
        LogObjectHolder.me().set(mallClassifyTwo);
        List<MallClassifyOne> mallClassifyOneList = this.mallClassifyOneService.selectList(new EntityWrapper<MallClassifyOne>().eq("is_delete", 0).orderBy("sort", true));
        if (CollectionUtils.isEmpty(mallClassifyOneList)) {
            mallClassifyOneList = new ArrayList<MallClassifyOne>();
        }
        model.addAttribute("mallClassifyOneList", mallClassifyOneList);
        return PREFIX + "mallClassifyTwo_edit.html";
    }
 
    /**
     * 获取商品二级分类列表
     */
    @ResponseBody
    @RequestMapping(value = "/list")
    public Object list(String classifyName, Integer parentClassifyId) {
        Page<Map<String, Object>> page = new PageFactory().defaultPage();
        Wrapper wrapper = new EntityWrapper<MallClassifyTwo>()
                .ne("is_delete", 1).orderBy("sort", true);
 
        // 时间搜索
        if (!StringUtils.isEmpty(classifyName)) {
            wrapper.like("classify_name", classifyName);
        }
        if (parentClassifyId != null) {
            wrapper.eq("parent_classify_id", parentClassifyId);
        }
 
        // 查询数据列表
        List<Map<String, Object>> list = mallClassifyTwoService.selectMapsPage(page, wrapper).getRecords();
        for (Map<String, Object> map : list) {
            Integer parentClassifyIdOne = (Integer) map.get("parentClassifyId");
            map.put("parentClassifyName", "");
            if (parentClassifyIdOne != null) {
                MallClassifyOne mallClassifyOne = this.mallClassifyOneService.selectById(parentClassifyId);
                if (mallClassifyOne != null) {
                    map.put("parentClassifyName", mallClassifyOne.getClassifyName());
                }
            }
        }
        page.setRecords(list);
        return super.packForBT(page);
    }
 
    /**
     * 新增商品二级分类
     */
    @Permission
    @ResponseBody
    @BussinessLog(value = "新增商品二级分类")
    @RequestMapping(value = "/add")
    public Object add(MallClassifyTwo mallClassifyTwo) {
        int count = this.mallClassifyTwoService.selectCount(new EntityWrapper<MallClassifyTwo>().eq("classify_name", mallClassifyTwo.getClassifyName()).eq("is_delete", 0));
        if (count > 0) {
            ErrorTip errorTip = new ErrorTip(500, "分类名称已存在,请仔细检查!");
            return errorTip;
        }
        mallClassifyTwoService.insert(mallClassifyTwo);
        return SUCCESS_TIP;
    }
 
    /**
     * 删除/批量删除
     */
    @Permission
    @ResponseBody
    @BussinessLog(value = "删除/批量删除商品二级分类")
    @RequestMapping(value = "/delete")
    public Object delete(@RequestParam String ids) {
        // 逻辑删除
        mallClassifyTwoService.updateForSet("is_delete = 1", new EntityWrapper<MallClassifyTwo>().in("id", ids.split(",")));
        return SUCCESS_TIP;
    }
 
    /**
     * 修改商品二级分类
     */
    @Permission
    @ResponseBody
    @BussinessLog(value = "修改商品二级分类")
    @RequestMapping(value = "/update")
    public Object update(MallClassifyTwo mallClassifyTwo) {
        mallClassifyTwoService.updateById(mallClassifyTwo);
        return SUCCESS_TIP;
    }
 
    /**
     * 修改商品二级分类状态
     */
    @ResponseBody
    @BussinessLog(value = "修改商品二级分类状态")
    @RequestMapping(value = "/updateState")
    public Object updateState(Integer mallClassifyTwoId, Integer state) {
        mallClassifyTwoService.updateForSet("state = " + state, new EntityWrapper<MallClassifyTwo>().eq("id", mallClassifyTwoId));
        return SUCCESS_TIP;
    }
 
    /**
     * 跳转商品二级分类详情
     */
    @RequestMapping(value = "/detail/{mallClassifyTwoId}")
    public Object detail(@PathVariable("mallClassifyTwoId") Integer mallClassifyTwoId, Model model) {
        MallClassifyTwo mallClassifyTwo = mallClassifyTwoService.selectById(mallClassifyTwoId);
        model.addAttribute("item", mallClassifyTwo);
        return PREFIX + "mallClassifyTwo_detail.html";
    }
 
    @RequestMapping("/getMallClassTwoAll")
    @ResponseBody
    public Object getMallClassTwoAll(String classOneIds) {
        Wrapper<MallClassifyTwo> entityWrapper = new EntityWrapper<MallClassifyTwo>().eq("is_delete", 0);
        if (org.apache.commons.lang3.StringUtils.isNotEmpty(classOneIds)) {
            entityWrapper.in("parent_classify_id", classOneIds);
        }
        List<MallClassifyTwo> mallClassifyTwoList = this.mallClassifyTwoService.selectList(entityWrapper);
        return mallClassifyTwoList;
    }
 
}