parent
644866a392
commit
935b3bb986
File diff suppressed because one or more lines are too long
@ -0,0 +1,74 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.opsli.api.wrapper.system.logs;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.opsli.api.base.warpper.ApiWrapper;
|
||||
|
||||
/**
|
||||
* 登录 日志表
|
||||
*
|
||||
* @author Parker
|
||||
* @date 2020-09-16 17:33
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class LoginLogsModel extends ApiWrapper {
|
||||
|
||||
/**
|
||||
* 多租户字段
|
||||
*/
|
||||
private String tenantId;
|
||||
/**
|
||||
* 组织机构ID组 xxx,xxx
|
||||
*/
|
||||
private String orgIds;
|
||||
|
||||
/**
|
||||
* 用户名称
|
||||
*/
|
||||
@ApiModelProperty(value = "用户名称")
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 真实姓名
|
||||
*/
|
||||
@ApiModelProperty(value = "真实姓名")
|
||||
private String realName;
|
||||
|
||||
/**
|
||||
* 日志类型
|
||||
* 1 : 登录
|
||||
* 2 : 登出
|
||||
*/
|
||||
@ApiModelProperty(value = "日志类型")
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 操作IP地址
|
||||
*/
|
||||
@ApiModelProperty(value = "操作IP地址")
|
||||
private String remoteAddr;
|
||||
|
||||
/**
|
||||
* 用户代理
|
||||
*/
|
||||
@ApiModelProperty(value = "用户代理")
|
||||
private String userAgent;
|
||||
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.opsli.modulars.system.logs.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.opsli.core.base.entity.BaseEntity;
|
||||
|
||||
/**
|
||||
* 登录日志信息
|
||||
*
|
||||
* @author 周鹏程
|
||||
* @date 2022年3月18日17:45:18
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class SysLoginLogs extends BaseEntity {
|
||||
|
||||
|
||||
/**
|
||||
* 多租户字段
|
||||
*/
|
||||
private String tenantId;
|
||||
/**
|
||||
* 组织机构ID组 xxx,xxx
|
||||
*/
|
||||
private String orgIds;
|
||||
|
||||
/**
|
||||
* 用户名称
|
||||
*/
|
||||
private String username;
|
||||
/**
|
||||
* 真实姓名
|
||||
*/
|
||||
private String realName;
|
||||
|
||||
/**
|
||||
* 日志类型
|
||||
* 1 : 登录
|
||||
* 2 : 登出
|
||||
*/
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 操作IP地址
|
||||
*/
|
||||
private String remoteAddr;
|
||||
/**
|
||||
* 用户代理
|
||||
*/
|
||||
private String userAgent;
|
||||
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package org.opsli.modulars.system.logs.factory;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import org.opsli.api.wrapper.system.logs.LoginLogsModel;
|
||||
import org.opsli.api.wrapper.system.user.UserModel;
|
||||
import org.opsli.api.wrapper.system.user.UserOrgRefModel;
|
||||
import org.opsli.common.enums.DictType;
|
||||
import org.opsli.core.utils.UserUtil;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @author 周鹏程
|
||||
* @date 2022/3/18 14:34
|
||||
*/
|
||||
public final class UserLoginLogFactory {
|
||||
|
||||
/**
|
||||
* 获取日志记录实体对象
|
||||
* @param user 用户信息
|
||||
* @return 日志信息
|
||||
*/
|
||||
public static LoginLogsModel getUserLoginModel(HttpServletRequest request, UserModel user, boolean isLogin){
|
||||
//记录登入登出日志
|
||||
LoginLogsModel loginInfo = new LoginLogsModel();
|
||||
loginInfo.setUsername(user.getUsername());
|
||||
loginInfo.setRealName(user.getRealName());
|
||||
// *** 需要确保 user对象的ip信息是有值的
|
||||
loginInfo.setRemoteAddr(user.getLoginIp());
|
||||
String header = request.getHeader("User-Agent");
|
||||
loginInfo.setUserAgent(header);
|
||||
|
||||
loginInfo.setIzManual(true);
|
||||
loginInfo.setCreateBy(user.getId());
|
||||
loginInfo.setUpdateBy(user.getId());
|
||||
UserOrgRefModel orgByUserId = UserUtil.getUserDefOrgByUserId(user.getId());
|
||||
loginInfo.setOrgIds(ObjectUtils.isEmpty(orgByUserId)? null : orgByUserId.getOrgIds() );
|
||||
loginInfo.setTenantId(StrUtil.blankToDefault(user.getTenantId(),null));
|
||||
|
||||
if(isLogin){
|
||||
loginInfo.setType(DictType.LOGIN_LOG_TYPE_LOGIN.getValue());
|
||||
}else {
|
||||
loginInfo.setType(DictType.LOGIN_LOG_TYPE_LOGOUT.getValue());
|
||||
}
|
||||
return loginInfo;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.opsli.modulars.system.logs.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.opsli.modulars.system.logs.entity.SysLoginLogs;
|
||||
|
||||
/**
|
||||
* 登录信息 Mapper
|
||||
*
|
||||
* @author Parker
|
||||
* @date 2020-11-28 18:59:59
|
||||
*/
|
||||
@Mapper
|
||||
public interface SysLoginLogsMapper extends BaseMapper<SysLoginLogs> {
|
||||
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.opsli.modulars.system.logs.mapper.SysLoginLogsMapper">
|
||||
|
||||
|
||||
</mapper>
|
@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.opsli.modulars.system.logs.service;
|
||||
|
||||
|
||||
import org.opsli.api.wrapper.system.logs.LoginLogsModel;
|
||||
import org.opsli.core.base.service.interfaces.CrudServiceInterface;
|
||||
import org.opsli.modulars.system.logs.entity.SysLoginLogs;
|
||||
|
||||
/**
|
||||
* 登录日志 Service
|
||||
*
|
||||
* @author Parker
|
||||
* @date 2020-11-28 18:59:59
|
||||
*/
|
||||
public interface ILoginLogsService extends CrudServiceInterface<SysLoginLogs, LoginLogsModel> {
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.opsli.modulars.system.logs.service.impl;
|
||||
|
||||
|
||||
import org.opsli.api.wrapper.system.logs.LoginLogsModel;
|
||||
import org.opsli.core.base.service.impl.CrudServiceImpl;
|
||||
import org.opsli.modulars.system.logs.entity.SysLoginLogs;
|
||||
import org.opsli.modulars.system.logs.mapper.SysLoginLogsMapper;
|
||||
import org.opsli.modulars.system.logs.service.ILoginLogsService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
||||
/**
|
||||
* 登录日志 Service Impl
|
||||
*
|
||||
* @author Parker
|
||||
* @date 2020-11-28 18:59:59
|
||||
*/
|
||||
@Service
|
||||
public class LoginLogsServiceImpl extends CrudServiceImpl<SysLoginLogsMapper, SysLoginLogs, LoginLogsModel>
|
||||
implements ILoginLogsService {
|
||||
|
||||
@Autowired
|
||||
private SysLoginLogsMapper mapper;
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.opsli.modulars.system.logs.web;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.opsli.api.base.result.ResultVo;
|
||||
import org.opsli.api.web.system.logs.LoginLogsApi;
|
||||
import org.opsli.api.web.system.logs.LogsApi;
|
||||
import org.opsli.api.wrapper.system.logs.LoginLogsModel;
|
||||
import org.opsli.api.wrapper.system.logs.LogsModel;
|
||||
import org.opsli.common.annotation.ApiRestController;
|
||||
import org.opsli.common.annotation.EnableLog;
|
||||
import org.opsli.core.base.controller.BaseRestController;
|
||||
import org.opsli.core.persistence.Page;
|
||||
import org.opsli.core.persistence.querybuilder.QueryBuilder;
|
||||
import org.opsli.core.persistence.querybuilder.WebQueryBuilder;
|
||||
import org.opsli.modulars.system.logs.entity.SysLoginLogs;
|
||||
import org.opsli.modulars.system.logs.entity.SysLogs;
|
||||
import org.opsli.modulars.system.logs.service.ILoginLogsService;
|
||||
import org.opsli.modulars.system.logs.service.ILogsService;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
|
||||
/**
|
||||
* 登录日志 Controller
|
||||
*
|
||||
* @author Parker
|
||||
* @date 2020-11-28 18:59:59
|
||||
*/
|
||||
@Api(tags = LoginLogsApi.TITLE)
|
||||
@Slf4j
|
||||
@ApiRestController("/{ver}/system/login-logs")
|
||||
public class LoginLogsRestController extends BaseRestController<SysLoginLogs, LoginLogsModel, ILoginLogsService>
|
||||
implements LoginLogsApi {
|
||||
|
||||
/**
|
||||
* 登录日志 查询分页
|
||||
* @param pageNo 当前页
|
||||
* @param pageSize 每页条数
|
||||
* @param request request
|
||||
* @return ResultVo
|
||||
*/
|
||||
@ApiOperation(value = "获得分页数据", notes = "获得分页数据 - 查询构造器")
|
||||
@RequiresPermissions("devops_login_logs_select")
|
||||
@Override
|
||||
public ResultVo<?> findPage(Integer pageNo, Integer pageSize, HttpServletRequest request) {
|
||||
|
||||
QueryBuilder<SysLoginLogs> queryBuilder = new WebQueryBuilder<>(entityClazz, request.getParameterMap());
|
||||
Page<SysLoginLogs, LoginLogsModel> page = new Page<>(pageNo, pageSize);
|
||||
page.setQueryWrapper(queryBuilder.build());
|
||||
page = IService.findPage(page);
|
||||
|
||||
return ResultVo.success(page.getPageData());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue