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
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<SysSysteminfo> 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<SysSysteminfo> appCount = sysSysteminfoService.queryAppByUrl(url);
            if(appCount.size() < 2) {
                if (appCount.size() == 1) {
                    appid = appCount.get(0).getAppid();
                }
                break;
            }
        }
        return appid;
    }
 
 
}