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);
|
}
|
}
|
}
|
}
|
}
|
}
|