jyy
2021-09-11 a4694bf4e0384df517464624748b366f533fda0f
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
package com.matrix.system.common.actions;
 
import com.matrix.core.anotations.RemoveRequestToken;
import com.matrix.core.anotations.SaveRequestToken;
import com.matrix.core.constance.MatrixConstance;
import com.matrix.core.pojo.AjaxResult;
import com.matrix.core.pojo.PaginationVO;
import com.matrix.core.tools.WebUtil;
import com.matrix.system.common.bean.SysUsers;
import com.matrix.system.hive.action.BaseController;
import com.matrix.system.common.bean.SystemDictionary;
import com.matrix.system.hive.plugin.util.CollectionUtils;
import com.matrix.system.common.service.SystemDictionaryService;
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 javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
 
 
/**
 * @description 系统管理使用的数据字典
 * @author jyy
 * @date 2016-07-12
 */
@Controller
@RequestMapping(value = "admin/dataDictionary")
public class SystemDictionaryController extends BaseController {
 
 
 
    // 数据字典
    @Resource
    private SystemDictionaryService currentService;
 
    @RequestMapping(value = "/showList")
    public @ResponseBody
    AjaxResult showList(HttpServletRequest request, SystemDictionary dictionary,
                        PaginationVO pageVo) {
 
        SysUsers sysUsers = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY);
        return showList(currentService, dictionary, pageVo);
    }
 
    @RequestMapping(value = "/addOrModify")
    @RemoveRequestToken
    public @ResponseBody AjaxResult addOrModify(SystemDictionary dictionary) {
        SysUsers sysUsers = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY);
 
        if (dictionary.getId() != null) {
            SystemDictionary dataDictionary = currentService.findById(dictionary.getId());
            if (dataDictionary.getType().equals(dictionary.getType()) && dataDictionary.getName().equals(dictionary.getName())) {
                return new AjaxResult(AjaxResult.STATUS_SUCCESS, "修改成功");
            } else {
                List<SystemDictionary> dataDictionaries = currentService.findByModel(dictionary);
                if (CollectionUtils.isNotEmpty(dataDictionaries)) {
                    return AjaxResult.buildFailInstance("该类型为基础数据或已存在");
                }
            }
            return modify(currentService, dictionary, "数据字典");
        } else {
            List<SystemDictionary> dataDictionary = currentService.findByModel(dictionary);
            if (CollectionUtils.isNotEmpty(dataDictionary)) {
                return AjaxResult.buildFailInstance("该类型为基础数据或已存在");
            }
            dictionary.setShopId(sysUsers.getShopId());
            dictionary.setCompanyId(sysUsers.getCompanyId());
 
            return add(currentService, dictionary, "数据字典");
        }
    }
 
    @RequestMapping(value = "/del")
    public @ResponseBody AjaxResult del(String keys) {
 
        return remove(currentService, keys);
    }
 
    @RequestMapping(value = "/editForm")
    @SaveRequestToken
    public String editForm(Long id, HttpServletRequest request) {
        SystemDictionary dictionary;
        List<String> list = currentService.getDictionaryType();
        request.setAttribute("dictionarys", list);
        if (id != null) {
            dictionary = currentService.findById(id);
            request.setAttribute("obj", dictionary);
        }
        return "super/dataDictionary-form";
    }
 
    /**
     * =======================================================
     * *******************公共的数据访问方法********************
     * =======================================================
     */
 
    @RequestMapping(value = "/all")
    public @ResponseBody AjaxResult all() {
        return findByModel(currentService, null);
    }
 
    /**
     * 显示所有的会员信息前查询
     */
    @RequestMapping(value = "/showDataDictionary")
    public @ResponseBody AjaxResult find(SystemDictionary dataDictionary) {
        List<SystemDictionary> dataDictionarys = currentService.findByModel(dataDictionary);
        return new AjaxResult(AjaxResult.STATUS_SUCCESS,  dataDictionarys, 0);
    }
 
 
    @RequestMapping(value = "/v2/showDataDictionary")
    public @ResponseBody AjaxResult findAll(@RequestBody SystemDictionary dataDictionary) {
 
        List<SystemDictionary> dataDictionarys = currentService.findByModel(dataDictionary);
        return new AjaxResult(AjaxResult.STATUS_SUCCESS,  dataDictionarys, 0);
    }
 
 
 
    /**
     * 查询数据字段类型
     *
     * @author jyy
     * @return
     */
    @RequestMapping(value = "/getDictionaryType")
    public @ResponseBody AjaxResult getDictionaryType() {
        List<String> dics = currentService.getDictionaryType();
        List<SystemDictionary> dictionarys = new ArrayList<SystemDictionary>();
        SystemDictionary dataDictionary;
        for (String dic : dics) {
            dataDictionary = new SystemDictionary();
            dataDictionary.setType(dic);
            dictionarys.add(dataDictionary);
        }
        return new AjaxResult(AjaxResult.STATUS_SUCCESS,  dictionarys, 0);
    }
 
}