WangHan
2025-04-03 a1b85ef72062ca80db35546e4216dd564f3e0f57
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
package com.iplatform.base.controller;
 
import com.iplatform.base.ArgumentsConstants;
import com.iplatform.base.SystemController;
import com.iplatform.base.service.CodeServiceImpl;
import com.iplatform.base.support.DictTreeGenerator;
import com.iplatform.model.po.S_dict_data;
import com.walker.file.FileInfo;
import com.walker.infrastructure.tree.TreeNode;
import com.walker.infrastructure.utils.StringUtils;
import com.walker.web.ResponseValue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
 
/**
 * 公共权限操作方法。<p></p>
 * 在该对象里面的方法,都无需配置菜单权限,只要登录用户都有权使用。
 * <pre>
 *     1)比如:获取字典树等
 * </pre>
 * @author 时克英
 * @date 2023-03-13
 */
@RestController
@RequestMapping("/permit")
public class PermitController extends SystemController {
 
//    @RequestMapping("/copyright/get/info")
//    public ResponseValue getCopyRight(){
//        CopyRightVo copyRightVo = new CopyRightVo();
//        copyRightVo.setCompanyName(this.getArgumentVariable(ArgumentsConstants.CONFIG_COPYRIGHT_COMPANY_INFO).getStringValue());
//        copyRightVo.setCompanyImage(this.getArgumentVariable(ArgumentsConstants.CONFIG_COPYRIGHT_COMPANY_IMAGE).getStringValue());
//        return ResponseValue.success(copyRightVo);
//    }
 
    /**
     * 获取移动端访问站点域名(地址),如:localhost:8080
     * @return
     * @date 2023-05-12
     */
    @RequestMapping("/config/front/domain")
    public ResponseValue getConfigFrontDomain(){
        String data = this.getArgumentVariable(ArgumentsConstants.CONFIG_KEY_SITE_URL).getStringValue();
        return ResponseValue.success("success", data);
    }
 
    /**
     * 根据文件id下载本地文件
     * @param id 文件id(系统存储的唯一编号)
     * @throws Exception
     * @date 2023-03-13
     */
    @RequestMapping("/file/{id}")
    public void downloadLocalFile(@PathVariable String id) throws Exception{
        FileInfo fileInfo = this.getFileInfo(id);
        if(fileInfo == null){
            throw new IllegalArgumentException("文件未找到,id=" + id);
        }
        logger.info("开始下载本地文件:{}", fileInfo);
        this.downloadSimpleFile(this.getLocalFileData(fileInfo), fileInfo.getFileName());
    }
 
    /**
     * 根据代码表名字,查询包含的代码项集合。
     * @param dictType
     * @return
     * @date 2023-03-22 该接口在字典管理中存在,这里需要放在公共权限里面一份,方便所有用户查询某个字典类型下的所有项目集合。
     * @date 2023-04-15 使用缓存,这里只能返回一级的情况,如果存在树结构则需要调用方法,参考 API:{@linkplain PermitController#selectDictTreeList(String)}
     */
    @RequestMapping("/dict/data/type/{dictType}")
    public ResponseValue<List<S_dict_data>> dictTypeList(@PathVariable String dictType){
        logger.debug("dictType = " + dictType);
        String id = this.getDictCacheProvider().getDictTypeId(dictType);
        List<S_dict_data> list = this.getDictCacheProvider().getRootChildrenOneLevelList(id);
//        List<S_dict_data> list = this.codeService.queryDictDataByType(dictType);
        if(StringUtils.isEmptyList(list)){
            list = new ArrayList<S_dict_data>(2);
        }
        list.sort(new Comparator<S_dict_data>() {
            @Override
            public int compare(S_dict_data stu1, S_dict_data stu2) {
                return stu1.getDict_sort() - stu2.getDict_sort();
            }
        });
        return ResponseValue.success(list);
    }
 
    /**
     * 返回代码树结构(列表集合),由前端展示组装。
     * @param dictType 数据字典类型
     * @return
     * @auth 时克英
     * @date 2023-03-13
     */
    @RequestMapping("/dict/list_tree/{dictType}")
    public ResponseValue selectDictTreeList(@PathVariable String dictType){
        if(StringUtils.isEmpty(dictType)){
            return ResponseValue.error("请提供字典类型!");
        }
        List<TreeNode> treeNodeList = new ArrayList<>(8);
//        this.getDictCacheProvider().getCodeChildrenList()
        List<S_dict_data> dictDataList = this.codeService.queryDictTreeList(dictType);
        if(StringUtils.isEmptyList(dictDataList)){
            return ResponseValue.success(treeNodeList);
        }
 
        // s_dict_data表:第一个根节点的'parent_id'
        // TreeGenerator组件使用的默认父id=0,所以对于字典来说,父id不是0可能是其他数值,所以这里需要先设置。
        long defaultParentId = dictDataList.get(0).getParent_id();
        DictTreeGenerator generator = new DictTreeGenerator(null);
        generator.setDefaultParentId(defaultParentId);
        generator.setEntityList(dictDataList);
        return ResponseValue.success(generator.getTreeRootList());
    }
 
    @Autowired
    public PermitController(CodeServiceImpl codeService){
        this.codeService = codeService;
    }
 
    private CodeServiceImpl codeService;
}