Helius
2021-03-09 8fe37f0f7af3667b60e0f29a1ce8188c08c35bb1
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
package com.matrix.system.hive.action;
 
import com.matrix.core.pojo.AjaxResult;
import com.matrix.core.pojo.PaginationVO;
import com.matrix.core.tools.StringUtils;
import com.matrix.core.tools.WebUtil;
import com.matrix.system.common.bean.SysUsers;
import com.matrix.system.constance.Dictionary;
import com.matrix.system.hive.bean.SysVipLabel;
import com.matrix.system.hive.dao.SysVipLabelDao;
import com.matrix.system.hive.plugin.util.CollectionUtils;
import jodd.util.CollectionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;
 
/**
 * @author wzy
 * @date 2020-12-17
 **/
@Controller
@RequestMapping(value = "/admin/label")
public class SysVipLabelController extends BaseController{
 
    @Autowired
    private SysVipLabelDao sysVipLabelDao;
 
 
    @RequestMapping(value = "/showList")
    @ResponseBody
    private AjaxResult showList(SysVipLabel sysVipLabel, PaginationVO pageVo) {
        SysUsers user = getMe();
        sysVipLabel.setCompanyId(user.getCompanyId());
        return AjaxResult.buildSuccessInstance(sysVipLabelDao.selectInPage(sysVipLabel, pageVo), sysVipLabelDao.selectTotal(sysVipLabel));
    }
 
    @RequestMapping(value = "/add")
    @ResponseBody
    public AjaxResult add(SysVipLabel sysVipLabel) {
        SysUsers sysUsers = getMe();
 
        sysVipLabel.setIsAll(1);
        sysVipLabel.setCompanyId(sysUsers.getCompanyId());
        List<SysVipLabel> sysVipLabels = sysVipLabelDao.selectByModel(sysVipLabel);
        if (CollectionUtils.isNotEmpty(sysVipLabels)) {
            return AjaxResult.buildFailInstance("已存在该标签");
        }
 
        sysVipLabel.setCreateBy(sysUsers.getSuName());
        sysVipLabel.setCreateTime(new Date());
        sysVipLabel.setColor(Dictionary.COLORS[new Random().nextInt(6)]);
 
        int i = sysVipLabelDao.insert(sysVipLabel);
        if (i > 0) {
            AjaxResult ajaxResult = AjaxResult.buildSuccessInstance("添加成功");
            ajaxResult.putInMap("label", sysVipLabel);
            return ajaxResult;
        }
        return AjaxResult.buildFailInstance("添加失败");
    }
 
    @RequestMapping(value = "/modify")
    @ResponseBody
    public AjaxResult modify(SysVipLabel sysVipLabel) {
        SysUsers sysUsers = getMe();
 
        SysVipLabel hasExist = sysVipLabelDao.selectById(sysVipLabel.getId());
        if (!sysVipLabel.getLabel().equals(hasExist.getLabel())) {
            SysVipLabel query = new SysVipLabel();
            query.setIsAll(1);
            query.setCompanyId(sysUsers.getCompanyId());
            query.setLabel(sysVipLabel.getLabel());
            List<SysVipLabel> sysVipLabels = sysVipLabelDao.selectByModel(sysVipLabel);
            if (CollectionUtils.isNotEmpty(sysVipLabels)) {
                return AjaxResult.buildFailInstance("已存在该标签");
            }
        }
 
        sysVipLabel.setColor(Dictionary.COLORS[new Random().nextInt(6)]);
 
        int i = sysVipLabelDao.update(sysVipLabel);
        if (i > 0) {
            AjaxResult ajaxResult = AjaxResult.buildSuccessInstance("编辑成功");
            ajaxResult.putInMap("label", sysVipLabel);
            return ajaxResult;
        }
        return AjaxResult.buildFailInstance("编辑失败");
    }
 
    @RequestMapping(value = "/del")
    @ResponseBody
    public AjaxResult del(String keys) {
        List<Long> ids = StringUtils.strToCollToLong(keys, ",");
        int i = sysVipLabelDao.deleteByIds(ids);
        if (i > 0) {
            return AjaxResult.buildSuccessInstance("删除成功");
        } else {
            return AjaxResult.buildFailInstance("删除失败");
        }
    }
 
 
 
    @RequestMapping(value = "/edit")
    public String edit(Long id) {
        if (id != null) {
            SysVipLabel sysVipLabel = sysVipLabelDao.selectById(id);
            WebUtil.getRequest().setAttribute("obj", sysVipLabel);
        }
        return "admin/hive/operate/label-form";
    }
}