3
13693261870
2022-09-16 63ba114e70e380442fcbed4a5157ee52c9491216
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
package com.landtool.lanbase.modules.api.controller;
 
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
 
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SimplePropertyPreFilter;
import com.landtool.lanbase.common.utils.ComplexPropertyPreFilter;
import com.landtool.lanbase.common.utils.IPUtils;
 
import com.landtool.lanbase.modules.sys.entity.SysDiyApp;
import com.landtool.lanbase.modules.sys.service.SysDiyAppService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
 
import com.landtool.lanbase.modules.sys.entity.SysSysteminfo;
import com.landtool.lanbase.modules.sys.service.SysSysteminfoService;
 
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
@Controller
@RequestMapping(path="/api/sys/app")
@Api(value = "", tags = {"系统管理相关接口"})
public class SysAppApiController {
    @Autowired
    private SysSysteminfoService  sysSysteminfoService;
    @Autowired
    private SysDiyAppService sysDiyAppService;
    private String http = "http://";
    /*
     * 查询系统列表信息
     */
    @GetMapping(path="/queryList")
    @ApiOperation(
            value = "查询系统列表信息",
            notes = "返回未删除注销的系统列表信息"
    )
    public  void  queryList(HttpServletResponse response,
                            HttpServletRequest request) throws IOException {
        SimplePropertyPreFilter filter = new SimplePropertyPreFilter();
        filter.getExcludes().add("rcreatedate");
        filter.getExcludes().add("rcreateuser");
        filter.getExcludes().add("rlasteditdate");
        
        List<SysSysteminfo> sysSysteminfo = sysSysteminfoService.findList();
        String ourl = "";
        Iterator<SysSysteminfo> it = sysSysteminfo.iterator();
        while (it.hasNext()) {
            SysSysteminfo systeminfo = (SysSysteminfo) it.next();
            String sysimgurl = systeminfo.getSysimgurl();
            if(sysimgurl != null){
                ourl =  http + (IPUtils.getIpAddr(request)) + ":" + request.getServerPort() +"/uploadFile" + sysimgurl;
                systeminfo.setSysimgurl(ourl);
            }
        }
 
        response.setHeader("Content-Type","application/json;charset=UTF-8");
        response.getWriter().write(JSONObject.toJSONString(sysSysteminfo,filter));
        
    }
 
    /*
     * 查询某个用户可访问的系统列表
     */
    @GetMapping(path="/queryListByUserId/{userId}")
    @ApiOperation(
            value = "查询某个用户可访问的系统列表",
            notes = ""
            )
    public  void queryListByUserId(@ApiParam(name="userId",value="用户Id",required=true)
                                   @PathVariable(name = "userId")long userId,
                                   HttpServletResponse response,
                                   HttpServletRequest request) throws IOException {
        SimplePropertyPreFilter filter = new SimplePropertyPreFilter();
        filter.getExcludes().add("rcreateDate");
        filter.getExcludes().add("rcreateUser");
        filter.getExcludes().add("remark");
 
        response.setHeader("Content-Type","application/json;charset=UTF-8");
        response.getWriter().write(JSONObject.toJSONString(sysSysteminfoService.queryListByUserId(userId),filter));
        
    }
    
    /*
     * 查询系统信息
     */
    @GetMapping(path="/getInfoById/{appId}")
    @ApiOperation(
            value = "查询系统信息",
            notes = ""
            )
    public void getInfoById(@ApiParam(name="appId",value="系统Id",required=true)
                            @PathVariable(name = "appId")Long appId,
                            HttpServletResponse response,
                            HttpServletRequest request) throws IOException {
        SimplePropertyPreFilter filter = new SimplePropertyPreFilter();
        filter.getExcludes().add("rcreatedate");
        filter.getExcludes().add("rcreateuser");
        filter.getExcludes().add("rlasteditdate");
        
        SysSysteminfo sysSysteminfo = sysSysteminfoService.getInfoById(appId);
        String sysimgurl = "";
        if(sysSysteminfo.getSysimgurl() != null){
            sysimgurl =  http + (IPUtils.getIpAddr(request)) + ":" + request.getServerPort() +"/uploadFile" + sysSysteminfo.getSysimgurl();
            sysSysteminfo.setSysimgurl(sysimgurl);
        }
 
        response.setHeader("Content-Type","application/json;charset=UTF-8");
        response.getWriter().write(JSONObject.toJSONString(sysSysteminfo,filter));
        
    }
    
    /*
     * 添加系统用户访问权限
     */
    @PostMapping(path="/addUserList/{userId}/{appId}")
    @ApiOperation(
            value = "添加系统用户访问权限",
            notes = "由各系统决定哪些用户可以访问提交用户登录ID列表信息"
            )
    @ResponseBody
    public String addUserList(@ApiParam(name="userId",value="用户Id",required=true)
                              @PathVariable(name = "userId")Long userId,
                              @ApiParam(name="appId",value="系统Id",required=true)
                              @PathVariable(name = "appId")Long appId){
        sysSysteminfoService.addUserList(userId,appId);
        return "添加成功";
        
    }
    
    /*
     * 删除系统用户访问权限
     */
    @PostMapping(path="/deleteUserList/{appid}")
    @ApiOperation(
            value = "删除系统用户访问权限",
            notes = "由各系统决定哪些用户可以访问提交用户登录ID列表信息"
            )
    @ResponseBody
    public void deleteUserList(@ApiParam(name="appId",value="系统Id",required=true)
                               @PathVariable(name = "appid")Long appid){
        sysSysteminfoService.deleteUserList(appid);
    }
 
    /*
     * 删除系统用户访问权限(根据用户id和系统id)
     */
    @PostMapping(path="/deleteByUseridAndAppid")
    @ApiOperation(
            value = "删除系统用户访问权限",
            notes = "由各系统决定哪些用户可以访问提交用户登录ID列表信息"
    )
    @ResponseBody
    public void deleteByUseridAndAppid(@ApiParam(name="userId",value="用户Id",required=true) @RequestParam(name = "userId") Integer userid,
                                       @ApiParam(name="appId",value="系统Id",required=true) @RequestParam(name = "appId") Integer appid,
                                       @ApiParam(name="otherids",value="其余系统Id",required=true) @RequestParam(name = "otherids") String otherids,
                                       @ApiParam(name="type",value="参数类型") @RequestParam(name = "type", required = false) String type,
                                       @ApiParam(name="id",value="定制id" , required = true) @RequestParam(name = "id") Integer id,
                                       HttpServletResponse response, HttpServletRequest request) throws IOException {
        ComplexPropertyPreFilter filter = new ComplexPropertyPreFilter();
        if(id!=0){//用户有设置应用程序
            sysDiyAppService.delete(id.toString());
        }else{//没设置则把删除的除外,其余的应用程序添加到该用户设置
            //otherids英文逗号分隔
            if(otherids != null && otherids.length() != 0){
                String[] idList = otherids.split("\\,");
                String detype = "";
                if(type != null && type.length() != 0){
                    detype =java.net.URLDecoder.decode(type);
                }
                for (String ids : idList) {
                    if(Integer.parseInt(ids) != appid){
                        SysDiyApp sysDiyApp = new SysDiyApp();
                        sysDiyApp.setUserid(userid);
                        sysDiyApp.setAppid(Integer.parseInt(ids));
                        sysDiyApp.setType(detype);
                        sysDiyAppService.save(sysDiyApp);
                    }
                }
            }
        }
    }
}