jyy
2021-01-25 2620b87fd24feaa0b60cd8b529cd44c3a7557c30
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
package com.matrix.system.common.actions;
 
import com.matrix.system.common.bean.CustomerDataDictionary;
import com.matrix.system.common.dao.CustomerDataDictionaryDao;
import com.matrix.core.anotations.RemoveRequestToken;
import com.matrix.core.anotations.SaveRequestToken;
import com.matrix.core.constance.MatrixConstance;
import com.matrix.core.constance.SystemErrorCode;
import com.matrix.core.constance.SystemMessageCode;
import com.matrix.core.exception.GlobleException;
import com.matrix.core.pojo.AjaxResult;
import com.matrix.core.pojo.PaginationVO;
import com.matrix.core.tools.ModelUtils;
import com.matrix.core.tools.StringUtils;
import com.matrix.core.tools.UUIDUtil;
import com.matrix.core.tools.WebUtil;
 
import com.matrix.system.common.bean.SysUsers;
import com.matrix.system.common.tools.ServiceUtil;
import com.matrix.system.hive.action.util.QueryUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
 
import java.util.Arrays;
import java.util.List;
import java.util.Map;
 
/**
 * @author 姜友瑶
 * @description 数据字典
 * @date 2018-07-10 07:52
 */
@Controller
@RequestMapping(value = "/admin/customerDictionary")
public class CustomerDictionaryAction {
 
    @Autowired
    private CustomerDataDictionaryDao dataDictionaryDao;
 
 
    @Autowired
    private ServiceUtil serviceUtil;
 
 
    /**
     * 列表显示
     */
    @RequestMapping(value = "/showList")
    public @ResponseBody
    AjaxResult showList(CustomerDataDictionary dataDictionary, PaginationVO pageVo) {
        if (pageVo == null) {
            pageVo = new PaginationVO();
        }
        pageVo.setSort("createTime");
        QueryUtil.setQueryLimitCom(dataDictionary);
        List<CustomerDataDictionary> dataList = dataDictionaryDao.selectInPage(dataDictionary, pageVo);
        AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, dataList,
                dataDictionaryDao.selectTotalRecord(dataDictionary));
        return result;
    }
 
 
    /**
     * 根据id查询字典值
     */
    @GetMapping(value = "/findById/{id}")
    public @ResponseBody
    AjaxResult findById(@PathVariable String id) {
        return AjaxResult.buildSuccessInstance(Arrays.asList(dataDictionaryDao.selectById(id)));
    }
 
 
    //显示所有属性
    @RequestMapping(value = "/all")
    @ResponseBody
    public AjaxResult showAll(CustomerDataDictionary dataDictionary) {
        QueryUtil.setQueryLimitCom(dataDictionary);
        return new AjaxResult(AjaxResult.STATUS_SUCCESS, dataDictionaryDao.selectByModel(dataDictionary));
    }
 
    /**
     * 新增
     */
    @RemoveRequestToken
    @RequestMapping(value = "/addDataDictionary")
    public @ResponseBody
    AjaxResult addDataDictionary(CustomerDataDictionary dataDictionary) {
        SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY);
        dataDictionary.setId(UUIDUtil.getRandomID());
        dataDictionary.setCreateBy(user.getSuName());
        dataDictionary.setUpdateBy(user.getSuName());
        dataDictionary.setCompanyId(user.getCompanyId());
        boolean isRepetition = serviceUtil.addCheckRepeat("customer_data_dictionary", "value", dataDictionary.getTypeCode());
        if (isRepetition) {
            return new AjaxResult(AjaxResult.STATUS_FAIL, dataDictionary.getValue() + "已经存在");
        }
        int i = dataDictionaryDao.insert(dataDictionary);
        if (i > 0) {
            return new AjaxResult(AjaxResult.STATUS_SUCCESS, SystemMessageCode.ADD_SUCCES, "数据字典");
        } else {
            throw new GlobleException(SystemErrorCode.DATA_ADD_FAIL);
        }
    }
 
    /**
     * 修改
     */
    @RemoveRequestToken
    @RequestMapping(value = "/modifyDataDictionary")
    public @ResponseBody
    AjaxResult modifyDataDictionary(CustomerDataDictionary newDataDictionary) {
        // 自己不能是自己的父节点
        if (newDataDictionary.getParentId() != null && newDataDictionary.getParentId().equals(newDataDictionary.getId())) {
            throw new GlobleException("父级不能是自己");
        }
        dataDictionaryDao.updateByModel(newDataDictionary);
        return new AjaxResult(AjaxResult.STATUS_SUCCESS, SystemMessageCode.UPDATE_SUCCES, "数据字典");
 
    }
 
    /**
     * 进入修改界面
     */
    @SaveRequestToken
    @RequestMapping(value = "/editForm")
    public ModelAndView editForm(String id) {
        CustomerDataDictionary dataDictionary = new CustomerDataDictionary();
        ModelAndView modelAndView = new ModelAndView("admin/sys/customerDataDictionary-form");
        if (id != null) {
            dataDictionary = dataDictionaryDao.selectById(id);
        }
        modelAndView.addObject("obj", dataDictionary);
        return modelAndView;
 
 
    }
 
    /**
     * 删除
     */
    @RequestMapping(value = "/del")
    public @ResponseBody
    AjaxResult del(String keys) {
        List<String> ids = StringUtils.strToCollToString(keys, ",");
        //校验是否为默认的配置
        for (String id:ids) {
            CustomerDataDictionary customerDataDictionary = dataDictionaryDao.selectById(id);
            if(customerDataDictionary.getParentId().equals(CustomerDataDictionary.TYPE_DEFAULT)){
                return AjaxResult.buildFailInstance("默认配置不能删除");
            }
        }
        int i = dataDictionaryDao.deleteByIds(ids);
        if (i > 0) {
            return new AjaxResult(AjaxResult.STATUS_SUCCESS, SystemMessageCode.DELETE_SUCCES, i);
        } else {
            throw new GlobleException(SystemErrorCode.DATA_DELETE_FAIL);
        }
    }
 
 
    /**
     * @param parentCode 父级code
     * @return
     * @auther kingsley
     */
    @RequestMapping(value = "getListByParentCode/{parentCode}")
    public @ResponseBody
    AjaxResult getListByParentCode(@PathVariable String parentCode) {
        SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY);
 
        List<CustomerDataDictionary> list = dataDictionaryDao.selectByParentCode(parentCode, user.getCompanyId());
        return new AjaxResult(AjaxResult.STATUS_SUCCESS, list, list.size());
    }
 
}