| /** | 
|  * Copyright (c) 2018 人人开源 All rights reserved. | 
|  * | 
|  * https://www.renren.io | 
|  * | 
|  * 版权所有,侵权必究! | 
|  */ | 
|   | 
| package com.zt.modules.log.service; | 
|   | 
| import com.zt.common.db.query.QueryFilter; | 
| import com.zt.common.service.BaseService; | 
| import com.zt.core.context.UserContext; | 
| import com.zt.modules.log.dao.SysLogLoginDao; | 
| import com.zt.modules.log.model.SysLogLogin; | 
| import com.zt.modules.sys.dto.RoleDto; | 
| import com.zt.modules.sys.model.SysRole; | 
| import com.zt.modules.sys.service.SysRoleService; | 
| import com.zt.modules.sys.service.SysRoleUserService; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.stereotype.Service; | 
| import org.springframework.transaction.annotation.Transactional; | 
|   | 
| import java.util.List; | 
| import java.util.stream.Collectors; | 
|   | 
| /** | 
|  * 登录日志 | 
|  * | 
|  * @author Mark sunlightcs@gmail.com | 
|  * @since 1.0.0 | 
|  */ | 
| @Service | 
| public class SysLogLoginService extends BaseService<SysLogLoginDao, SysLogLogin> { | 
|     @Autowired | 
|     private SysRoleService sysRoleService; | 
|   | 
|     @Autowired | 
|     private SysRoleUserService sysRoleUserService; | 
|   | 
|   | 
|   | 
|     public List<SysLogLogin> page(QueryFilter queryFilter) { | 
|         String roleName = ""; | 
|         List<RoleDto> roles = sysRoleUserService.getUserRoles(UserContext.getUser().getId()); | 
|         if (roles != null && roles.size() > 0) { | 
|             // 同时拥有两种权限查看全部 | 
|             if (roles.stream().filter(p -> p.getCode().equals("xtbmybm")).count() > 0 | 
|                     && roles.stream().filter(p -> p.getCode().equals("xtsjybm")).count() > 0) { | 
|                 roleName = "all"; | 
|             } else { | 
|                 // 如果当前用户拥有角色编码为xtbmy的角色权限,则查看除系统管理员(拥有角色编码为xtgly权限的用户)、系统保密员(拥有角色编码为xtsjy权限的用户)以外的用户登录、操作日志 | 
|                 if (roles.stream().filter(p -> p.getCode().equals("xtbmybm")).count() > 0) { | 
|                     roleName = "xtbmybm"; | 
|                 } | 
|                 // 如果当前用户拥有角色编码为xtsjy的角色权限,则查看系统管理员(拥有角色编码为xtgly权限的用户)、系统保密员的登录(拥有角色编码为xtsjy权限的用户)、操作日志 | 
|                 else if (roles.stream().filter(p -> p.getCode().equals("xtsjybm")).count() > 0) { | 
|                     roleName = "xtsjybm"; | 
|                 } else { | 
|                     roleName = "other"; | 
|                 } | 
|             } | 
|         } else { | 
|             roleName = "other"; | 
|         } | 
|         queryFilter.addParam("action", roleName); | 
|         queryFilter.addParam("currentUserId", UserContext.getUser().getId()); | 
|         List<SysLogLogin> list = baseDao.getList(queryFilter.getQueryParams()); | 
|         return queryFilter.getPageList(list); | 
|     } | 
|   | 
|     public List<SysLogLogin> list(QueryFilter queryFilter) { | 
|         return super.query(queryFilter); | 
|     } | 
|   | 
|     @Transactional(rollbackFor = Exception.class) | 
|     public void insert(SysLogLogin entity) { | 
|         baseDao.insert(entity); | 
|     } | 
| } |