package com.landtool.lanbase.modules.api.controller; import com.landtool.lanbase.common.utils.Result; import com.landtool.lanbase.modules.org.entity.OrgUser; import com.landtool.lanbase.modules.org.entity.OrgUserJoinUnit; import com.landtool.lanbase.modules.org.service.OrgUserService; 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 org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import com.landtool.lanbase.modules.log.service.LogLogininfoService; import java.util.List; /** * @Description: 登录验证日志提供的api */ @Controller @RequestMapping(path = "/api/log/logininfo") @Api(value = "", tags = {"登录验证日志相关接口"}) public class LogLoginInfoApiController { @Autowired private LogLogininfoService logininfoService; @Autowired private OrgUserService orgUserService; @Autowired private SysSysteminfoService sysSysteminfoService; /** * 登录验证日志写入 */ @PostMapping(path = "/addLoginInfo") @ApiOperation( value = "登录验证日志写入", notes = "" ) @ResponseBody public String addLoginInfo(@ApiParam(name = "loginname", value = "登录名loginname", required = true) @RequestParam(name = "loginname") String loginname, @ApiParam(name = "loginip", value = "请求IP地址loginip", required = true) @RequestParam(name = "loginip") String loginip, @ApiParam(name = "logintype", value = "操作类型logintype", required = true) @RequestParam(name = "logintype") Long logintype, @ApiParam(name = "rstatus", value = "操作状态rstatus", required = true) @RequestParam(name = "rstatus") Long rstatus, @ApiParam(name = "broserversion", value = "用户访问浏览器版本broserversion", required = true) @RequestParam(name = "broserversion") String broserversion, @ApiParam(name = "appurl", value = "应用程序地址") @RequestParam(name = "appurl" , required = false) String appurl) { //通过用户登录名获取用户ID OrgUser orgUser = orgUserService.queryByUserName(loginname); Long userid = Long.valueOf(-1); if (orgUser != null) { userid = orgUser.getUserid(); } //通过应用程序URL获取应用程序ID Long appid = Long.valueOf(-1); if (appurl != null) { //如果后台进来,这个值就会为空 String[] urls = appurl.split("/"); String url = urls[0]+"//"; for(int i = 2; i < urls.length; i++) { if(i != 2) url += "/"; url += urls[i]; List appCount = sysSysteminfoService.queryAppByUrl(url); if(appCount.size() < 2) { if (appCount.size() == 1) { appid = appCount.get(0).getAppid(); } break; } } } else { appurl = ""; } logininfoService.addLoginInfo(userid, appid, loginname, loginip, logintype, rstatus, broserversion, appurl); return "success"; } /** * 通过用户登录名获取用户ID */ @GetMapping("/getUseridByLoginName/{loginname}") @ResponseBody @ApiOperation(value = "通过用户登录名获取用户ID", notes = "") public Long getUseridByLoginName(@ApiParam(name = "loginname", value = "用户登录名", required = true) @PathVariable(name = "loginname") String loginname) { OrgUser orgUser = orgUserService.queryByUserName(loginname); Long userid = Long.valueOf(-1); if (orgUser != null) { userid = orgUser.getUserid(); } return userid; } /** * 通过应用程序URL获取应用程序ID */ @GetMapping("/getAppidByAppurl") @ResponseBody @ApiOperation(value = "通过应用程序URL获取应用程序ID", notes = "") public Long getAppidByAppurl(@ApiParam(name = "appurl", value = "应用程序URL", required = true) @RequestParam(name = "appurl") String appurl) { Long appid = Long.valueOf(-1); String[] urls = appurl.split("/"); String url = urls[0]+"//"; for(int i = 2; i < urls.length; i++) { if(i!=2) url += "/"; url += urls[i]; List appCount = sysSysteminfoService.queryAppByUrl(url); if(appCount.size() < 2) { if (appCount.size() == 1) { appid = appCount.get(0).getAppid(); } break; } } return appid; } }