Commit 85ff986c authored by wzp's avatar wzp

互动和日志修改

parent 6cbe2dd4
......@@ -6,6 +6,7 @@ import cn.wisenergy.chnmuseum.party.model.*;
import cn.wisenergy.chnmuseum.party.service.PermissionService;
import cn.wisenergy.chnmuseum.party.service.RolePermissionService;
import cn.wisenergy.chnmuseum.party.service.RoleService;
import cn.wisenergy.chnmuseum.party.service.TUserService;
import cn.wisenergy.chnmuseum.party.service.impl.EmployeeRoleServiceImpl;
import cn.wisenergy.chnmuseum.party.service.impl.EmployeeServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
......@@ -58,6 +59,9 @@ public class MyShiroRealm extends AuthorizingRealm {
@Resource
private StringRedisTemplate stringRedisTemplate;
@Resource
private TUserService userService;
/**
* 必须重写此方法,不然Shiro会报错
*/
......@@ -89,9 +93,9 @@ public class MyShiroRealm extends AuthorizingRealm {
// 通过username从数据库中查找
// 实际项目中,这里可以根据实际情况做缓存,如果不做,Shiro自己也是有时间间隔机制,2分钟内不会重复执行该方法
String employeeId = JwtTokenUtil.getEmployeeId(credentials);
Employee employee = this.employeeService.selectByEmpId(employeeId);
if (employee == null) {
String userId = JwtTokenUtil.getEmployeeId(credentials);
TUser user = userService.getById(userId);
if (user == null) {
throw new AuthenticationException("User does not exist!");
}
......@@ -99,7 +103,7 @@ public class MyShiroRealm extends AuthorizingRealm {
throw new AuthenticationException("token invalid");
}
return new SimpleAuthenticationInfo(new Employee(employee.getId(), credentials), credentials, getName());
return new SimpleAuthenticationInfo(new TUser(user.getId(), credentials), credentials, getName());
}
/**
......@@ -108,27 +112,29 @@ public class MyShiroRealm extends AuthorizingRealm {
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
System.out.println("权限认证方法:MyShiroRealm.doGetAuthorizationInfo()");
Employee employee = (Employee) principals.getPrimaryPrincipal();
Boolean hasToken = stringRedisTemplate.hasKey(SHIRO_JWT_TOKEN + employee.getJwtToken());
TUser user = (TUser) principals.getPrimaryPrincipal();
Boolean hasToken = stringRedisTemplate.hasKey(SHIRO_JWT_TOKEN + user.getJwtToken());
if (hasToken == null || !hasToken) {
throw new AuthenticationException("token invalid!");
}
String employeeId = JwtTokenUtil.getEmployeeId(employee.getJwtToken());
String userId = JwtTokenUtil.getEmployeeId(user.getJwtToken());
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
// 根据用户ID查询角色(role),放入到Authorization里。
Map<String, Object> map = new HashMap<>();
map.put("employee_id", employeeId);
List<EmployeeRole> employeeRoleList = this.employeeRoleService.listByMap(map);
List<Role> list = roleService.selectRoleByUserId(userId);
// // 根据用户ID查询角色(role),放入到Authorization里。
// Map<String, Object> map = new HashMap<>();
// map.put("user_id", userId);
// List<EmployeeRole> employeeRoleList = this.employeeRoleService.listByMap(map);
List<String> ridList = new LinkedList<>();
for (EmployeeRole employeeRole : employeeRoleList) {
ridList.add(employeeRole.getRoleId());
}
List<Role> roleList = this.roleService.listByIds(ridList);
// for (EmployeeRole employeeRole : employeeRoleList) {
// ridList.add(employeeRole.getRoleId());
// }
// List<Role> roleList = this.roleService.listByIds(ridList);
Set<String> roleSet = new HashSet<>();
for (Role role : roleList) {
for (Role role : list) {
roleSet.add(role.getAlias());
ridList.add(role.getId());
}
info.setRoles(roleSet);
......
......@@ -32,6 +32,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.time.LocalDate;
import java.util.*;
import java.util.concurrent.TimeUnit;
......@@ -120,6 +121,8 @@ public class LoginController {
TUser user;
if (StringUtils.isNoneBlank(username)) {
try {
//访问一次,计数一次
ValueOperations<String, String> opsForValue = stringRedisTemplate.opsForValue();
if ("LOCK".equals(opsForValue.get(SHIRO_IS_LOCK + username))) {
......@@ -129,8 +132,6 @@ public class LoginController {
}
user = userService.selectByUsername(username);
List<Role> roles = roleService.selectRoleByUserId(user.getId());
user.setRoleList(roles);
if (user == null) {
resultMap.put("status", 500);
resultMap.put("message", "用户名或密码不正确!");
......@@ -141,11 +142,13 @@ public class LoginController {
throw new DisabledAccountException("此帐号已禁用,请联系管理员!");
}
// if (!user.getAllowLogin()) {
// throw new DisabledAccountException("您无权访问,请联系管理员!");
// }
if (user.getPermanent()!=null&&!user.getPermanent()) {
if (user.getEffectiveDate().isAfter(LocalDate.now())||user.getExiredDate().isBefore(LocalDate.now())) {
throw new DisabledAccountException("此帐号已失效,请联系管理员!");
}
}
try {
byte[] salt = user.getPasswordSalt();
String s1 = new String(SHA256PasswordEncryptionService.createPasswordHash(password, salt));
if (!new String(SHA256PasswordEncryptionService.createPasswordHash(password, salt)).equals(new String(user.getPasswordHash()))) {
......@@ -160,7 +163,8 @@ public class LoginController {
}
throw new IncorrectCredentialsException("用户名或密码不正确!");
}
List<Role> roles = roleService.selectRoleByUserId(user.getId());
user.setRoleList(roles);
//获取当前用户角色拥有菜单
List<Menu> userMenuPerms = new ArrayList<>();
if (roles.size() > 0) {
......
......@@ -651,7 +651,7 @@ public class RoleController extends BaseController {
ew.eq("is_deleted", 0);
ew.eq("status", 1);
ew.orderByAsc("sortorder");
ew.orderByDesc("update_time");
ew.orderByDesc("create_time");
return ResponseEntity.ok(this.roleService.list(ew));
} catch (Exception e) {
LOGGER.error("查询角色列表出错!", e);
......
......@@ -31,8 +31,6 @@ import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@RestController
......@@ -127,7 +125,7 @@ public class SysLogController extends BaseController {
/**
* 插入机顶盒日志表
*/
@ApiOperation(value = "插入系统日志", notes = "插入系统日志")
@ApiOperation(value = "插入机顶盒日志表", notes = "插入机顶盒日志表")
@PostMapping(value = "/insertRunLog")
public Boolean insertRunLog(RunLog runLog) {
boolean b = runLogService.insertRunLog(runLog);
......
......@@ -124,9 +124,14 @@ public class TInteractionController extends BaseController {
@PostMapping("/getList")
@RequiresPermissions("/interaction/getList")
@ApiImplicitParams(value = {
@ApiImplicitParam(name = "_index", value = "分页起始偏移量", paramType = "query", dataType = "Integer"),
@ApiImplicitParam(name = "_size", value = "返回条数", paramType = "query", dataType = "Integer"),
@ApiImplicitParam(name = "orgId", value = "机构id", paramType = "query", dataType = "String")
})
@ApiOperation(value = "获取看板互动列表", notes = "获取看板互动列表")
public Map<String, Object> getTInteractionPageList(String orgId) {
List<TInteraction> list = tInteractionService.list(new UpdateWrapper<TInteraction>().eq("organ_id", orgId));
Page<TInteraction> list = tInteractionService.page(getPage(),new UpdateWrapper<TInteraction>().eq("organ_id", orgId));
return getResult(list);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment