Merge remote-tracking branch 'origin/dev'

This commit is contained in:
wangliwen 2022-11-16 19:04:35 +08:00
commit 09274487bd
13 changed files with 126 additions and 70 deletions

View File

@ -82,33 +82,6 @@ public class ResourceController {
@Value("${qdyjj.ipAndPort}")
private String ipAndPort;
@Value("${zsk.appid}")
private String appId;
@Value("${zsk.appkey}")
private String appKey;
@Value("${zsk.url.sign}")
private String sign;
@Value("${zsk.url.gateway}")
private String gateway;
@Value("${zsk.methodId}")
private String methodId;
@Value("${zsk.param.charset}")
private String charset;
@Value("${zsk.param.origin}")
private String origin;
@Value("${zsk.param.version}")
private String version;
@Value("${zsk.catalogIds}")
private String[] catalogIds;
@Value("${resource.path}")
private String uploadPath;

View File

@ -83,6 +83,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;
@ -2742,7 +2743,13 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
param.add("userAccount", userAccount);
param.add("status", status);
HttpEntity<String> requestEntity = new HttpEntity(param, new HttpHeaders());
return restTemplate.postForEntity("http://15.72.183.88:8760/yzy/main/cloudresource/getResourceBusinessList", requestEntity, String.class).getBody();
String body;
try {
body = restTemplate.postForEntity("http://15.72.183.88:8760/yzy/main/cloudresource/getResourceBusinessList", requestEntity, String.class).getBody();
} catch (RestClientException e) {
throw new RuntimeException("云资源数据查询失败!");
}
return body;
}
@Override
@ -2752,7 +2759,13 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
param.add("userAccount", userAccount);
param.add("status", status);
HttpEntity<String> requestEntity = new HttpEntity(param, new HttpHeaders());
return restTemplate.postForEntity("http://15.72.183.88:8760/yzy/main/cloudresource/getVideoBusinessList", requestEntity, String.class).getBody();
String body;
try {
body = restTemplate.postForEntity("http://15.72.183.88:8760/yzy/main/cloudresource/getVideoBusinessList", requestEntity, String.class).getBody();
} catch (RestClientException e) {
throw new RuntimeException("云视频查询失败!");
}
return body;
}
}

View File

@ -13,6 +13,7 @@ import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.util.List;
@ -26,6 +27,9 @@ public class Oauth2Realm extends AuthorizingRealm {
@Autowired
private ShiroService shiroService;
@Value("${system.allowSimultaneousLogin}")
private int allowSimultaneousLogin;
@Override
public boolean supports(AuthenticationToken token) {
return token instanceof Oauth2Token;
@ -55,8 +59,15 @@ public class Oauth2Realm extends AuthorizingRealm {
//根据accessToken查询用户信息
SysUserTokenEntity tokenEntity = shiroService.getByToken(accessToken);
//判断是否允许同时登录,0不允许1允许
//允许同时在线时不校验过期时间
if (allowSimultaneousLogin != 1 && tokenEntity.getExpireDate().getTime() < System.currentTimeMillis()) {
throw new IncorrectCredentialsException(MessageUtils.getMessage(ErrorCode.TOKEN_INVALID));
}
//token失效
if (tokenEntity == null || tokenEntity.getExpireDate().getTime() < System.currentTimeMillis()) {
if (tokenEntity == null) {
throw new IncorrectCredentialsException(MessageUtils.getMessage(ErrorCode.TOKEN_INVALID));
}
@ -66,11 +77,15 @@ public class Oauth2Realm extends AuthorizingRealm {
//转换成UserDetail对象
UserDetail userDetail = ConvertUtils.sourceToTarget(userEntity, UserDetail.class);
//账号锁定
//账号停用
if (userDetail.getStatus() == 0) {
throw new LockedAccountException(MessageUtils.getMessage(ErrorCode.ACCOUNT_LOCK));
}
if (userDetail.getStatus() == 2) {
throw new LockedAccountException(MessageUtils.getMessage(500 ,"账号已锁定!"));
}
//获取用户对应的部门数据权限
List<Long> deptIdList = shiroService.getDataScopeList(userDetail.getId());
userDetail.setDeptIdList(deptIdList);

View File

@ -12,6 +12,7 @@ import io.renren.modules.security.entity.SysUserTokenEntity;
import io.renren.modules.security.oauth2.TokenGenerator;
import io.renren.modules.security.service.SysUserTokenService;
import io.renren.modules.sys.entity.SysOnlineEntity;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.Date;
@ -21,11 +22,17 @@ import java.util.Map;
@Service
public class SysUserTokenServiceImpl extends BaseServiceImpl<SysUserTokenDao, SysUserTokenEntity> implements SysUserTokenService {
/**
* 12小时后过期
*/
private final static int EXPIRE = 3600 * 12;
@Value("${system.allowSimultaneousLogin}")
private int allowSimultaneousLogin;
/*
@Override
public Result createToken(Long userId) {
//用户token
@ -81,6 +88,56 @@ public class SysUserTokenServiceImpl extends BaseServiceImpl<SysUserTokenDao, Sy
map.put("expire", EXPIRE);
return new Result().ok(map);
}
*/
@Override
public Result createToken(Long userId) {
//用户token
String token;
//当前时间
Date now = new Date();
//过期时间
Date expireTime = new Date(now.getTime() + EXPIRE * 1000);
//判断是否生成过token
SysUserTokenEntity tokenEntity = baseDao.getByUserId(userId);
if(tokenEntity == null){
//生成一个token
token = TokenGenerator.generateValue();
tokenEntity = new SysUserTokenEntity();
tokenEntity.setUserId(userId);
tokenEntity.setToken(token);
tokenEntity.setUpdateDate(now);
tokenEntity.setExpireDate(expireTime);
//保存token
this.insert(tokenEntity);
}else{
//判断是否允许同时登录,0不允许1允许
//允许同时在线时返回同一token且不校验过期时间
if (allowSimultaneousLogin == 0 && tokenEntity.getExpireDate().getTime() < System.currentTimeMillis()) {
//token过期重新生成token
token = TokenGenerator.generateValue();
tokenEntity.setToken(token);
tokenEntity.setUpdateDate(now);
tokenEntity.setExpireDate(expireTime);
//更新token
this.updateById(tokenEntity);
} else {
token = tokenEntity.getToken();
}
}
Map<String, Object> map = new HashMap<>(2);
map.put(Constant.TOKEN_HEADER, token);
map.put("expire", EXPIRE);
return new Result().ok(map);
}
@Override
public void logout(Long userId) {

View File

@ -55,8 +55,8 @@ public class SysMenuController {
@ApiOperation("列表")
@ApiImplicitParam(name = "type", value = "菜单类型 0菜单 1按钮 null全部", paramType = "query", dataType = "int")
// @RequiresPermissions("sys:menu:list")
public Result<List<SysMenuDTO>> list(Integer type) {
List<SysMenuDTO> list = sysMenuService.getAllMenuList(type);
public Result<List<SysMenuDTO>> list(Integer type, String name) {
List<SysMenuDTO> list = sysMenuService.getAllMenuList(type, name);
return new Result<List<SysMenuDTO>>().ok(list);
}

View File

@ -21,7 +21,7 @@ public interface SysMenuDao extends BaseDao<SysMenuEntity> {
* @param type 菜单类型
* @param language 语言
*/
List<SysMenuEntity> getMenuList(@Param("type") Integer type, @Param("language") String language);
List<SysMenuEntity> getMenuList(@Param("type") Integer type, @Param("language") String language, @Param("name") String name);
/**
* 查询用户菜单列表

View File

@ -26,7 +26,7 @@ public interface SysMenuService extends BaseService<SysMenuEntity> {
*
* @param type 菜单类型
*/
List<SysMenuDTO> getAllMenuList(Integer type);
List<SysMenuDTO> getAllMenuList(Integer type, String name);
/**
* 用户菜单列表

View File

@ -76,8 +76,8 @@ public class SysMenuServiceImpl extends BaseServiceImpl<SysMenuDao, SysMenuEntit
}
@Override
public List<SysMenuDTO> getAllMenuList(Integer type) {
List<SysMenuEntity> menuList = baseDao.getMenuList(type, HttpContextUtils.getLanguage());
public List<SysMenuDTO> getAllMenuList(Integer type, String name) {
List<SysMenuEntity> menuList = baseDao.getMenuList(type, HttpContextUtils.getLanguage(), name);
List<SysMenuDTO> dtoList = ConvertUtils.sourceToTarget(menuList, SysMenuDTO.class);
@ -90,7 +90,7 @@ public class SysMenuServiceImpl extends BaseServiceImpl<SysMenuDao, SysMenuEntit
//系统管理员拥有最高权限
if (user.getSuperAdmin() == SuperAdminEnum.YES.value()) {
menuList = baseDao.getMenuList(type, HttpContextUtils.getLanguage());
menuList = baseDao.getMenuList(type, HttpContextUtils.getLanguage(), null);
} else {
menuList = baseDao.getUserMenuList(user.getId(), type, HttpContextUtils.getLanguage());
}

View File

@ -0,0 +1,7 @@
DELETE
FROM sys_user_token
WHERE id NOT IN (SELECT s.id
FROM (SELECT sut.id,
ROW_NUMBER() OVER ( PARTITION BY sut.user_id ORDER BY sut.create_date DESC ) AS group_idx
FROM sys_user_token sut) s
WHERE s.group_idx = 1);

View File

@ -0,0 +1,11 @@
INSERT INTO `sys_dict_type`(`id`, `dict_type`, `dict_name`, `remark`, `sort`, `creator`, `create_date`, `updater`, `update_date`, `status`) VALUES (1592357067014803457, ' encryptedRoute', '加密路由', '', 0, 1067246875800000001, '2022-11-15 11:21:24', 1067246875800000001, '2022-11-15 11:21:24', 1);
INSERT INTO `sys_dict_data`(`id`, `dict_type_id`, `dict_label`, `dict_value`, `remark`, `sort`, `creator`, `create_date`, `updater`, `update_date`, `status`) VALUES (1592357815098281986, 1592357067014803457, '个人中心', '/personalCenter', '', 0, 1067246875800000001, '2022-11-15 11:24:22', 1067246875800000001, '2022-11-15 11:24:22', 1);
INSERT INTO `sys_dict_data`(`id`, `dict_type_id`, `dict_label`, `dict_value`, `remark`, `sort`, `creator`, `create_date`, `updater`, `update_date`, `status`) VALUES (1592357749759414274, 1592357067014803457, '消息通知', '/mynoticeView', '', 0, 1067246875800000001, '2022-11-15 11:24:07', 1067246875800000001, '2022-11-15 11:24:07', 1);
INSERT INTO `sys_dict_data`(`id`, `dict_type_id`, `dict_label`, `dict_value`, `remark`, `sort`, `creator`, `create_date`, `updater`, `update_date`, `status`) VALUES (1592357668599631874, 1592357067014803457, '融合服务详情', '/integrationServicesDetails', '', 0, 1067246875800000001, '2022-11-15 11:23:47', 1067246875800000001, '2022-11-15 11:23:47', 1);
INSERT INTO `sys_dict_data`(`id`, `dict_type_id`, `dict_label`, `dict_value`, `remark`, `sort`, `creator`, `create_date`, `updater`, `update_date`, `status`) VALUES (1592357561145757698, 1592357067014803457, '融合服务', '/integrationServices', '', 0, 1067246875800000001, '2022-11-15 11:23:22', 1067246875800000001, '2022-11-15 11:23:22', 1);
INSERT INTO `sys_dict_data`(`id`, `dict_type_id`, `dict_label`, `dict_value`, `remark`, `sort`, `creator`, `create_date`, `updater`, `update_date`, `status`) VALUES (1592357495567814658, 1592357067014803457, '能力统计', '/abilityStatistics', '', 0, 1067246875800000001, '2022-11-15 11:23:06', 1067246875800000001, '2022-11-15 11:23:06', 1);
INSERT INTO `sys_dict_data`(`id`, `dict_type_id`, `dict_label`, `dict_value`, `remark`, `sort`, `creator`, `create_date`, `updater`, `update_date`, `status`) VALUES (1592357417113358338, 1592357067014803457, '能力详情', '/details', '', 0, 1067246875800000001, '2022-11-15 11:22:47', 1067246875800000001, '2022-11-15 11:22:47', 1);
INSERT INTO `sys_dict_data`(`id`, `dict_type_id`, `dict_label`, `dict_value`, `remark`, `sort`, `creator`, `create_date`, `updater`, `update_date`, `status`) VALUES (1592357337807458305, 1592357067014803457, '能力集市', '/DetailsPageconetent', '', 0, 1067246875800000001, '2022-11-15 11:22:29', 1067246875800000001, '2022-11-15 11:22:29', 1);

View File

@ -1,26 +0,0 @@
<?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="io.renren.modules.security.dao.SysUserTokenDao">
<select id="getByToken" resultType="io.renren.modules.security.entity.SysUserTokenEntity">
select * from sys_user_token where token = #{value}
</select>
<select id="getByUserId" resultType="io.renren.modules.security.entity.SysUserTokenEntity">
select * from sys_user_token where user_id = #{value}
</select>
<update id="logout">
update sys_user_token set expire_date = #{expireDate} where user_id = #{userId}
</update>
<select id="getOnlineList" resultType="io.renren.modules.sys.entity.SysOnlineEntity">
select t1.user_id, t1.expire_date, t1.update_date as login_date, t2.username, t2.real_name
from sys_user_token t1, sys_user t2
where t1.user_id = t2.id and expire_date > #{expireDate}
<if test="username != null and username.trim() != ''">
and t2.username like #{username}
</if>
</select>
</mapper>

View File

@ -14,14 +14,20 @@
</select>
<select id="getMenuList" resultType="io.renren.modules.sys.entity.SysMenuEntity">
select t1.*, (select lang.field_value from sys_language lang where lang.table_name='sys_menu' and
lang.field_name='name'
and lang.table_id=t1.id and lang.language=#{language}) as name
from sys_menu t1
select t1.*, lang.field_value as "name"
from sys_menu t1, sys_language lang
<where>
1 = 1
<if test="type != null">
t1.type = #{type}
and t1.type = #{type}
</if>
<if test="name != null and name != ''">
and lang.field_value like CONCAT('%', #{name}, '%')
</if>
and lang.table_name = 'sys_menu'
and lang.field_name = 'name'
and lang.table_id = t1.id
and lang.language = #{language}
</where>
order by t1.sort asc
</select>

View File

@ -8,7 +8,7 @@
</select>
<select id="getByUserId" resultType="io.renren.modules.security.entity.SysUserTokenEntity">
select * from sys_user_token where user_id = #{value}
select * from sys_user_token where user_id = #{value} ORDER BY create_date DESC LIMIT 1
</select>
<update id="logout">