Commit 26b3c42c authored by 廖旭伟's avatar 廖旭伟

集成到4.0框架下

parent 47125fee
package com.mortals.xhx.common.pdu.user; package com.mortals.xhx.common.pdu.user;
import com.mortals.framework.model.BaseEntityLong;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import com.mortals.framework.model.BaseEntityLong;
/** /**
* 用户信息业务Pdu对象 * 用户信息业务Pdu对象
......
package com.mortals.xhx.feign.user; package com.mortals.xhx.feign.user;
import com.mortals.xhx.common.pdu.RespData;
import com.mortals.xhx.common.pdu.user.UserPdu;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.mortals.framework.common.Rest; import com.mortals.framework.common.Rest;
import com.mortals.xhx.common.pdu.RespData;
import com.mortals.xhx.common.pdu.user.UserPdu;
import com.mortals.xhx.feign.IFeign; import com.mortals.xhx.feign.IFeign;
import feign.hystrix.FallbackFactory; import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -15,11 +15,10 @@ import java.util.List; ...@@ -15,11 +15,10 @@ import java.util.List;
/** /**
* 用户信息业务 Feign接口 * 用户信息业务 Feign接口
*
* @author zxfei * @author zxfei
* @date 2022-07-06 * @date 2022-07-06
*/ */
//@FeignClient(name = "portal-manager", path = "/zwfw", fallbackFactory = UserFeignFallbackFactory.class) @FeignClient(name = "portal-manager", path = "/zwfw", fallbackFactory = UserFeignFallbackFactory.class)
public interface IUserFeign extends IFeign { public interface IUserFeign extends IFeign {
...@@ -29,7 +28,7 @@ public interface IUserFeign extends IFeign { ...@@ -29,7 +28,7 @@ public interface IUserFeign extends IFeign {
* @param userPdu * @param userPdu
* @return * @return
*/ */
@PostMapping(value = "/user/list") @PostMapping(value = "/user/interlist")
Rest<RespData<List<UserPdu>>> list(@RequestBody UserPdu userPdu); Rest<RespData<List<UserPdu>>> list(@RequestBody UserPdu userPdu);
...@@ -39,7 +38,7 @@ public interface IUserFeign extends IFeign { ...@@ -39,7 +38,7 @@ public interface IUserFeign extends IFeign {
* @param id * @param id
* @return * @return
*/ */
@GetMapping(value = "/user/info") @GetMapping(value = "/user/interinfo")
Rest<UserPdu> info(@RequestParam(value = "id") Long id); Rest<UserPdu> info(@RequestParam(value = "id") Long id);
/** /**
...@@ -49,7 +48,7 @@ public interface IUserFeign extends IFeign { ...@@ -49,7 +48,7 @@ public interface IUserFeign extends IFeign {
* @return * @return
*/ */
@GetMapping(value = "/user/delete") @GetMapping(value = "/user/delete")
Rest<Void> delete(Long[] ids, @RequestHeader("Authorization") String authorization); Rest<Void> delete(Long[] ids,@RequestHeader("Authorization") String authorization);
/** /**
...@@ -59,12 +58,21 @@ public interface IUserFeign extends IFeign { ...@@ -59,12 +58,21 @@ public interface IUserFeign extends IFeign {
* @return * @return
*/ */
@PostMapping(value = "/user/save") @PostMapping(value = "/user/save")
Rest<RespData<UserPdu>> save(@RequestBody UserPdu userPdu, @RequestHeader("Authorization") String authorization); Rest<RespData<UserPdu>> save(@RequestBody UserPdu userPdu,@RequestHeader("Authorization") String authorization);
@PostMapping(value = "/login/login") @PostMapping(value = "/login/login")
String portalLogin(@RequestBody UserPdu userPdu); String portalLogin(@RequestBody UserPdu userPdu);
/**
* 查询用户列表
*
* @param userPdu
* @return
*/
@PostMapping("/api/user/findAllUser")
String findAllUser(@RequestBody UserPdu userPdu);
/** /**
* 获取token * 获取token
...@@ -76,9 +84,6 @@ public interface IUserFeign extends IFeign { ...@@ -76,9 +84,6 @@ public interface IUserFeign extends IFeign {
Rest<String> getToken(@RequestParam(value = "userKey") String userKey); Rest<String> getToken(@RequestParam(value = "userKey") String userKey);
@PostMapping(value = "/user/synchSiteAuth")
Rest<String> synchSiteAuth();
} }
...@@ -87,15 +92,14 @@ public interface IUserFeign extends IFeign { ...@@ -87,15 +92,14 @@ public interface IUserFeign extends IFeign {
class UserFeignFallbackFactory implements FallbackFactory<IUserFeign> { class UserFeignFallbackFactory implements FallbackFactory<IUserFeign> {
@Override @Override
public IUserFeign create(Throwable t) { public IUserFeign create(Throwable t) {
log.error("feign error", t);
return new IUserFeign() { return new IUserFeign() {
@Override @Override
public Rest<RespData<List<UserPdu>>> list(UserPdu userPdu) { public Rest<RespData<List<UserPdu>>> list(UserPdu userPdu) {
return Rest.fail("暂时无法获取用户信息业务列表,请稍后再试!"); return Rest.fail("暂时无法获取用户信息业务列表,请稍后再试!");
} }
@Override @Override
public Rest<UserPdu> info(Long id) { public Rest<UserPdu> info(Long id) {
return Rest.fail("暂时无法获取用户信息业务详细,请稍后再试!"); return Rest.fail("暂时无法获取用户信息业务详细,请稍后再试!");
} }
...@@ -115,16 +119,14 @@ class UserFeignFallbackFactory implements FallbackFactory<IUserFeign> { ...@@ -115,16 +119,14 @@ class UserFeignFallbackFactory implements FallbackFactory<IUserFeign> {
} }
@Override @Override
public Rest<String> getToken(String userKey) { public String findAllUser(UserPdu userPdu) {
return Rest.fail("token获取失败"); return null;
} }
@Override @Override
public Rest<String> synchSiteAuth() { public Rest<String> getToken(String userKey) {
return Rest.fail("同步请求失败,稍后再试!"); return Rest.fail("token获取失败");
} }
}; };
} }
} }
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
<profiles.publish.path>/home/publish</profiles.publish.path> <profiles.publish.path>/home/publish</profiles.publish.path>
<profiles.nacos.server-addr>192.168.0.252:8848</profiles.nacos.server-addr> <profiles.nacos.server-addr>192.168.0.252:8848</profiles.nacos.server-addr>
<profiles.nacos.group>DEFAULT_GROUP</profiles.nacos.group> <profiles.nacos.group>DEFAULT_GROUP</profiles.nacos.group>
<profiles.nacos.namespace>smart-gov-chuanshan</profiles.nacos.namespace> <profiles.nacos.namespace>smart-gov</profiles.nacos.namespace>
<profiles.log.path>/home/mortals/app/logs</profiles.log.path> <profiles.log.path>/home/mortals/app/logs</profiles.log.path>
<profiles.log.level>INFO</profiles.log.level> <profiles.log.level>INFO</profiles.log.level>
<package.environment>test</package.environment> <package.environment>test</package.environment>
...@@ -38,14 +38,13 @@ ...@@ -38,14 +38,13 @@
</profile> </profile>
<profile> <profile>
<id>test</id> <id>test</id>
<properties> <properties>
<profiles.active>test</profiles.active> <profiles.active>test</profiles.active>
<profiles.server.path>/sm</profiles.server.path> <profiles.server.path>/sm</profiles.server.path>
<profiles.publish.path>/home/publish</profiles.publish.path> <profiles.publish.path>/home/publish</profiles.publish.path>
<profiles.nacos.server-addr>192.168.0.252:8848</profiles.nacos.server-addr> <profiles.nacos.server-addr>192.168.0.252:8848</profiles.nacos.server-addr>
<profiles.nacos.group>DEFAULT_GROUP</profiles.nacos.group> <profiles.nacos.group>DEFAULT_GROUP</profiles.nacos.group>
<profiles.nacos.namespace>smart-gov-chuanshan</profiles.nacos.namespace> <profiles.nacos.namespace>smart-gov</profiles.nacos.namespace>
<profiles.log.path>/home/mortals/app/logs</profiles.log.path> <profiles.log.path>/home/mortals/app/logs</profiles.log.path>
<profiles.log.level>INFO</profiles.log.level> <profiles.log.level>INFO</profiles.log.level>
<package.environment>test</package.environment> <package.environment>test</package.environment>
...@@ -62,7 +61,7 @@ ...@@ -62,7 +61,7 @@
<profiles.publish.path>/home/publish</profiles.publish.path> <profiles.publish.path>/home/publish</profiles.publish.path>
<profiles.nacos.server-addr>127.0.0.1:8848</profiles.nacos.server-addr> <profiles.nacos.server-addr>127.0.0.1:8848</profiles.nacos.server-addr>
<profiles.nacos.group>DEFAULT_GROUP</profiles.nacos.group> <profiles.nacos.group>DEFAULT_GROUP</profiles.nacos.group>
<profiles.nacos.namespace>smart-gov-chuanshan</profiles.nacos.namespace> <profiles.nacos.namespace>smart-gov</profiles.nacos.namespace>
<profiles.log.path>/home/mortals/app/logs</profiles.log.path> <profiles.log.path>/home/mortals/app/logs</profiles.log.path>
<profiles.log.level>INFO</profiles.log.level> <profiles.log.level>INFO</profiles.log.level>
<package.environment>build</package.environment> <package.environment>build</package.environment>
......
...@@ -7,10 +7,11 @@ import com.mortals.framework.service.ICacheService; ...@@ -7,10 +7,11 @@ import com.mortals.framework.service.ICacheService;
import com.mortals.framework.service.IUser; import com.mortals.framework.service.IUser;
import com.mortals.framework.util.DateUtils; import com.mortals.framework.util.DateUtils;
import com.mortals.framework.util.StringUtils; import com.mortals.framework.util.StringUtils;
import com.mortals.xhx.base.system.resource.service.ResourceService;
import com.mortals.xhx.base.system.user.model.UserEntity; import com.mortals.xhx.base.system.user.model.UserEntity;
import com.mortals.xhx.base.system.user.model.UserQuery;
import com.mortals.xhx.base.system.user.service.UserService; import com.mortals.xhx.base.system.user.service.UserService;
import com.mortals.xhx.feign.user.IUserFeign; import com.mortals.xhx.common.key.RedisKey;
import com.mortals.xhx.common.utils.MenuEncodeUtil;
import io.jsonwebtoken.Claims; import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts; import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm; import io.jsonwebtoken.SignatureAlgorithm;
...@@ -19,6 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -19,6 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Primary; import org.springframework.context.annotation.Primary;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
...@@ -26,6 +28,7 @@ import javax.servlet.http.HttpServletRequest; ...@@ -26,6 +28,7 @@ import javax.servlet.http.HttpServletRequest;
import java.util.Base64; import java.util.Base64;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Set;
/** /**
* token验证处理 * token验证处理
...@@ -33,7 +36,7 @@ import java.util.Map; ...@@ -33,7 +36,7 @@ import java.util.Map;
* @author zxfei * @author zxfei
*/ */
@Primary @Primary
@Service @Service("authTokenService")
@Order(1) @Order(1)
@Slf4j @Slf4j
public class AuthTokenServiceImpl implements IAuthTokenService { public class AuthTokenServiceImpl implements IAuthTokenService {
...@@ -78,6 +81,10 @@ public class AuthTokenServiceImpl implements IAuthTokenService { ...@@ -78,6 +81,10 @@ public class AuthTokenServiceImpl implements IAuthTokenService {
@Autowired @Autowired
private ICacheService cacheService; private ICacheService cacheService;
@Autowired
private ResourceService resourceService;
/** /**
* 获取信息 * 获取信息
* *
...@@ -90,28 +97,42 @@ public class AuthTokenServiceImpl implements IAuthTokenService { ...@@ -90,28 +97,42 @@ public class AuthTokenServiceImpl implements IAuthTokenService {
String token = getToken(request); String token = getToken(request);
if (StringUtils.isNotEmpty(token)) { if (StringUtils.isNotEmpty(token)) {
try { try {
boolean signed = Jwts.parser().isSigned(token);
if (!signed) {
log.error("token非法!=>{}", token);
return null;
}
Claims claims = parseToken(token); Claims claims = parseToken(token);
String uuid = (String) claims.get(SysConstains.LOGIN_USER_KEY); String uuid = (String) claims.get(SysConstains.LOGIN_USER_KEY);
String userKey = getTokenKey(uuid); String userKey = getTokenKey(uuid);
//cacheService.select(portalDb); /* cacheService.select(portalDb);
String userStr = cacheService.get(userKey); String userStr = cacheService.get(userKey);*/
//cacheService.select(db);
RedisTemplate<String, String> redisTemplate = cacheService.selectDbRedisTemplate(portalDb);
// Rest<String> rest = userFeign.getToken(userKey); String userStr =redisTemplate.opsForValue().get(userKey);
// String userStr = rest.getData(); //刷新token时间
if (StringUtils.isNotEmpty(userStr)) { UserEntity userEntity = JSONObject.parseObject(userStr, UserEntity.class);
UserEntity userEntity = JSONObject.parseObject(userStr, UserEntity.class); if (!ObjectUtils.isEmpty(userEntity)) {
userEntity.setToken(token); verifyToken(userEntity);
}
UserEntity temp = userService.selectOne(new UserQuery().loginName(userEntity.getLoginName())); // cacheService.select(db);
if(!ObjectUtils.isEmpty(temp)){ if (!ObjectUtils.isEmpty(userEntity)) {
UserEntity temp = userService.getExtCache(userEntity.getLoginName());
if (!ObjectUtils.isEmpty(temp)) {
userEntity.setId(temp.getId()); userEntity.setId(temp.getId());
} }
//更新resource 路径
String menuUrlCode = cacheService.hget(RedisKey.KEY_USER_MENU_CACHE, userEntity.getId().toString(), String.class);
if (ObjectUtils.isEmpty(menuUrlCode)) {
Set<String> urls = resourceService.findUrlSetByUserId(userEntity.getId());
menuUrlCode = MenuEncodeUtil.generateMenuUrlCode(urls);
cacheService.hset(RedisKey.KEY_USER_MENU_CACHE, userEntity.getId().toString(), menuUrlCode);
}
userEntity.setMenuUrl(menuUrlCode);
return userEntity; return userEntity;
} }
} catch (Exception e) { } catch (Exception e) {
log.error("解析jwt token异常!", e); log.error("解析jwt token异常!,token:{}",token, e);
return null; return null;
} }
} }
...@@ -165,8 +186,8 @@ public class AuthTokenServiceImpl implements IAuthTokenService { ...@@ -165,8 +186,8 @@ public class AuthTokenServiceImpl implements IAuthTokenService {
public void verifyToken(IUser user) { public void verifyToken(IUser user) {
long expireTime = user.getExpireTime(); long expireTime = user.getExpireTime();
long currentTime = System.currentTimeMillis(); long currentTime = System.currentTimeMillis();
if (expireTime - currentTime <= SECOND_MINUTE_TEN) { if (expireTime - currentTime <= SECOND_MINUTE_TEN*1000) {
log.info("不足十分钟,刷新过期时间"); log.info("不足十分钟,刷新过期时间");
refreshToken(user); refreshToken(user);
} }
} }
...@@ -178,7 +199,7 @@ public class AuthTokenServiceImpl implements IAuthTokenService { ...@@ -178,7 +199,7 @@ public class AuthTokenServiceImpl implements IAuthTokenService {
*/ */
public void refreshToken(IUser user) { public void refreshToken(IUser user) {
//user.setLoginTime(System.currentTimeMillis()); //user.setLoginTime(System.currentTimeMillis());
user.setExpireTime(user.getLoginTime() == null ? System.currentTimeMillis() : user.getLoginTime() + expireTime * SECOND_MINUTE); user.setExpireTime(user.getLoginTime() == null ? System.currentTimeMillis() : user.getLoginTime() + expireTime * SECOND_MINUTE*1000);
// 根据uuid将user缓存 // 根据uuid将user缓存
String userKey = getTokenKey(user.getToken()); String userKey = getTokenKey(user.getToken());
//设置有效时间 单位秒 //设置有效时间 单位秒
...@@ -245,4 +266,11 @@ public class AuthTokenServiceImpl implements IAuthTokenService { ...@@ -245,4 +266,11 @@ public class AuthTokenServiceImpl implements IAuthTokenService {
private String getTokenKey(String uuid) { private String getTokenKey(String uuid) {
return SysConstains.LOGIN_TOKEN_KEY + uuid; return SysConstains.LOGIN_TOKEN_KEY + uuid;
} }
public static void main(String[] args) {
// boolean signed = Jwts.parser().isSigned("123");
boolean signed = Jwts.parser().isSigned("eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJuaW5naGFvLm5ldCIsImV4cCI6IjE0Mzg5NTU0NDUiLCJuYW1lIjoid2FuZ2hhbyIsImFkbWluIjp0cnVlfQ.SwyHTEx_RQppr97g4J5lKXtabJecpejuef8AqKYMAJc");
System.out.println(signed);
}
} }
...@@ -9,7 +9,6 @@ import com.mortals.framework.util.AESUtil; ...@@ -9,7 +9,6 @@ import com.mortals.framework.util.AESUtil;
import com.mortals.framework.utils.ServletUtils; import com.mortals.framework.utils.ServletUtils;
import com.mortals.framework.web.interceptor.BaseInterceptor; import com.mortals.framework.web.interceptor.BaseInterceptor;
import com.mortals.xhx.base.framework.config.InterceptorConfig; import com.mortals.xhx.base.framework.config.InterceptorConfig;
import com.mortals.xhx.common.code.ApiRespCodeEnum;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
...@@ -43,8 +42,8 @@ public class AuthUserInterceptor extends BaseInterceptor { ...@@ -43,8 +42,8 @@ public class AuthUserInterceptor extends BaseInterceptor {
@Override @Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception { throws Exception {
//response.setContentType("application/json"); JSONObject ret = new JSONObject();
if (handler instanceof HandlerMethod) { if(handler instanceof HandlerMethod){
HandlerMethod handlerMethod = (HandlerMethod) handler; HandlerMethod handlerMethod = (HandlerMethod) handler;
Method method = handlerMethod.getMethod(); Method method = handlerMethod.getMethod();
UnAuth annotation = method.getAnnotation(UnAuth.class); UnAuth annotation = method.getAnnotation(UnAuth.class);
...@@ -52,7 +51,7 @@ public class AuthUserInterceptor extends BaseInterceptor { ...@@ -52,7 +51,7 @@ public class AuthUserInterceptor extends BaseInterceptor {
//取消校验 //取消校验
return true; return true;
} }
} else if (handler instanceof ResourceHttpRequestHandler) { }else if(handler instanceof ResourceHttpRequestHandler){
return true; return true;
} }
try { try {
...@@ -73,7 +72,7 @@ public class AuthUserInterceptor extends BaseInterceptor { ...@@ -73,7 +72,7 @@ public class AuthUserInterceptor extends BaseInterceptor {
if (ObjectUtils.isEmpty(loginUser)) { if (ObjectUtils.isEmpty(loginUser)) {
ServletUtils.renderString(response, JSONObject.toJSONString(Rest.fail(ERROR_TOKEN_EXPIRED, ERROR_TOKEN_EXPIRED_CONTENT))); ServletUtils.renderString(response, JSONObject.toJSONString(Rest.fail(ERROR_TOKEN_EXPIRED, ERROR_TOKEN_EXPIRED_CONTENT)));
return false; return false;
} else if (loginUser.isAdmin() || loginUser.getUserType() == 1 || loginUser.getUserType() == 2) { } else if (loginUser.isAdmin() || loginUser.getUserType() == 1) {
return super.preHandle(request, response, handler); return super.preHandle(request, response, handler);
} else { } else {
ServletUtils.renderString(response, JSONObject.toJSONString(Rest.fail(ERROR_USER_OPERATION, ERROR_USER_OPERATION_CONTENT))); ServletUtils.renderString(response, JSONObject.toJSONString(Rest.fail(ERROR_USER_OPERATION, ERROR_USER_OPERATION_CONTENT)));
...@@ -105,5 +104,4 @@ public class AuthUserInterceptor extends BaseInterceptor { ...@@ -105,5 +104,4 @@ public class AuthUserInterceptor extends BaseInterceptor {
return false; return false;
} }
} }
...@@ -8,30 +8,14 @@ ...@@ -8,30 +8,14 @@
package com.mortals.xhx.base.system.resource.service.impl; package com.mortals.xhx.base.system.resource.service.impl;
import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException; import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl; import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.framework.util.StringUtils; import com.mortals.framework.util.StringUtils;
import com.mortals.framework.util.ThreadPool;
import com.mortals.xhx.base.system.resource.dao.ResourceDao; import com.mortals.xhx.base.system.resource.dao.ResourceDao;
import com.mortals.xhx.base.system.resource.model.ResourceEntity; import com.mortals.xhx.base.system.resource.model.ResourceEntity;
import com.mortals.xhx.base.system.resource.model.ResourceQuery; import com.mortals.xhx.base.system.resource.model.ResourceQuery;
import com.mortals.xhx.base.system.resource.service.ResourceService; import com.mortals.xhx.base.system.resource.service.ResourceService;
import com.mortals.xhx.base.system.user.model.UserEntity;
import com.mortals.xhx.base.system.user.model.UserQuery;
import com.mortals.xhx.base.system.user.service.UserService;
import com.mortals.xhx.common.pdu.RespData;
import com.mortals.xhx.common.pdu.user.UserPdu;
import com.mortals.xhx.common.utils.BeanUtil;
import com.mortals.xhx.common.utils.SyncTreeSiteThread;
import com.mortals.xhx.feign.user.IUserFeign;
import com.mortals.xhx.module.site.service.SiteService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
......
...@@ -10,6 +10,7 @@ package com.mortals.xhx.base.system.user.service; ...@@ -10,6 +10,7 @@ package com.mortals.xhx.base.system.user.service;
import com.mortals.framework.exception.AppException; import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Result; import com.mortals.framework.model.Result;
import com.mortals.framework.service.ICRUDCacheService;
import com.mortals.framework.service.ICRUDService; import com.mortals.framework.service.ICRUDService;
import com.mortals.framework.service.IUser; import com.mortals.framework.service.IUser;
import com.mortals.xhx.base.system.menu.model.MenuEntity; import com.mortals.xhx.base.system.menu.model.MenuEntity;
...@@ -29,7 +30,7 @@ import java.util.Set; ...@@ -29,7 +30,7 @@ import java.util.Set;
* @version 1.0.0 * @version 1.0.0
*/ */
public interface UserService extends ICRUDService<UserEntity,Long> { public interface UserService extends ICRUDCacheService<UserEntity,Long> {
/** /**
* 用户登录 * 用户登录
* *
......
...@@ -15,11 +15,11 @@ import com.mortals.framework.model.Context; ...@@ -15,11 +15,11 @@ import com.mortals.framework.model.Context;
import com.mortals.framework.model.PageInfo; import com.mortals.framework.model.PageInfo;
import com.mortals.framework.model.Result; import com.mortals.framework.model.Result;
import com.mortals.framework.service.IUser; import com.mortals.framework.service.IUser;
import com.mortals.framework.service.impl.AbstractCRUDCacheServiceImpl;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl; import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.framework.util.DataUtil; import com.mortals.framework.util.DataUtil;
import com.mortals.framework.util.SecurityUtil; import com.mortals.framework.util.SecurityUtil;
import com.mortals.framework.util.StringUtils; import com.mortals.framework.util.StringUtils;
import com.mortals.framework.util.ThreadPool;
import com.mortals.xhx.base.system.menu.model.MenuEntity; import com.mortals.xhx.base.system.menu.model.MenuEntity;
import com.mortals.xhx.base.system.menu.service.MenuService; import com.mortals.xhx.base.system.menu.service.MenuService;
import com.mortals.xhx.base.system.resource.model.ResourceEntity; import com.mortals.xhx.base.system.resource.model.ResourceEntity;
...@@ -32,12 +32,7 @@ import com.mortals.xhx.base.system.user.dao.UserDao; ...@@ -32,12 +32,7 @@ import com.mortals.xhx.base.system.user.dao.UserDao;
import com.mortals.xhx.base.system.user.model.UserEntity; import com.mortals.xhx.base.system.user.model.UserEntity;
import com.mortals.xhx.base.system.user.model.UserQuery; import com.mortals.xhx.base.system.user.model.UserQuery;
import com.mortals.xhx.base.system.user.service.UserService; import com.mortals.xhx.base.system.user.service.UserService;
import com.mortals.xhx.common.pdu.user.UserPhpPdu; import com.mortals.xhx.common.pdu.user.UserPhpPdu;
import com.mortals.xhx.common.utils.BeanUtil;
import com.mortals.xhx.common.utils.SyncTreeSiteThread;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
...@@ -56,7 +51,7 @@ import java.util.stream.Collectors; ...@@ -56,7 +51,7 @@ import java.util.stream.Collectors;
* @version 1.0.0 * @version 1.0.0
*/ */
@Service("userService") @Service("userService")
public class UserServiceImpl extends AbstractCRUDServiceImpl<UserDao, UserEntity, Long> implements UserService { public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserEntity, Long> implements UserService {
@Autowired @Autowired
......
...@@ -10,4 +10,5 @@ public class RedisKey { ...@@ -10,4 +10,5 @@ public class RedisKey {
*/ */
public static final String KEY_MENU_CACHE = "iot:base:MenuCacheKey:"; public static final String KEY_MENU_CACHE = "iot:base:MenuCacheKey:";
public static final String KEY_USER_MENU_CACHE = "user:menu";
} }
package com.mortals.xhx.common.utils;
import com.mortals.framework.ap.GlobalSysInfo;
import com.mortals.framework.ap.SysConstains;
import com.mortals.framework.util.AESUtil;
import lombok.extern.slf4j.Slf4j;
import java.util.Set;
@Slf4j
public class MenuEncodeUtil {
public static String generateMenuUrlCode(Set<String> urls) {
try {
String securityKey = GlobalSysInfo.getPropertyValue(SysConstains.PROP_COOKIE_SECURITY_KEY);
StringBuilder sb = new StringBuilder();
if (urls != null && urls.size() > 0) {
for (String url : urls) {
int index = url.hashCode() & (Integer.MAX_VALUE - 1);
sb.append(index).append(",");
}
}
String menuUrl = sb.toString();
return AESUtil.encrypt(menuUrl, securityKey);
} catch (Throwable e) {
log.error("编码异常",e);
return null;
}
}
}
package com.mortals.xhx.common.utils; //package com.mortals.xhx.common.utils;
//
import com.alibaba.fastjson.JSON; //import com.alibaba.fastjson.JSON;
import com.mortals.framework.model.Context; //import com.mortals.framework.model.Context;
import com.mortals.xhx.module.site.model.SiteTreeSelect; //import com.mortals.xhx.module.site.model.SiteTreeSelect;
import com.mortals.xhx.module.site.service.SiteService; //import com.mortals.xhx.module.site.service.SiteService;
import com.mortals.xhx.utils.SpringUtils; //import com.mortals.xhx.utils.SpringUtils;
import lombok.AllArgsConstructor; //import lombok.AllArgsConstructor;
import lombok.extern.apachecommons.CommonsLog; //import lombok.extern.apachecommons.CommonsLog;
import lombok.extern.slf4j.Slf4j; //import lombok.extern.slf4j.Slf4j;
import org.springframework.util.ObjectUtils; //import org.springframework.util.ObjectUtils;
//
import java.util.List; //import java.util.List;
//
/** ///**
* @author: zxfei // * @author: zxfei
* @date: 2022/4/13 13:34 // * @date: 2022/4/13 13:34
* @description: // * @description:
**/ // **/
@AllArgsConstructor //@AllArgsConstructor
@Slf4j //@Slf4j
public class SyncTreeSiteThread implements Runnable { //public class SyncTreeSiteThread implements Runnable {
//
private Context context; // private Context context;
//
@Override // @Override
public void run() { // public void run() {
SiteService siteService = SpringUtils.getBean(SiteService.class); // SiteService siteService = SpringUtils.getBean(SiteService.class);
List<SiteTreeSelect> siteTreeSelects = siteService.siteTree(context); // List<SiteTreeSelect> siteTreeSelects = siteService.siteTree(context);
siteService.setSiteTree(siteTreeSelects, context); // siteService.setSiteTree(siteTreeSelects, context);
log.info("刷新用户站点树=》userID:{} siteIds:{} siteTree:{}",context.getUser().getId(),context.getUser().getSiteIds(), JSON.toJSONString(siteService.getSiteTree(context))); // log.info("刷新用户站点树=》userID:{} siteIds:{} siteTree:{}",context.getUser().getId(),context.getUser().getSiteIds(), JSON.toJSONString(siteService.getSiteTree(context)));
} // }
//
} //}
package com.mortals.xhx.daemon.applicationservice; //package com.mortals.xhx.daemon.applicationservice;
//
import com.mortals.framework.model.Context; //import com.mortals.framework.model.Context;
import com.mortals.framework.service.ICacheService; //import com.mortals.framework.springcloud.service.IApplicationStartedService;
import com.mortals.framework.service.IUser; //import com.mortals.framework.util.ThreadPool;
import com.mortals.framework.springcloud.config.web.BaseWebMvcConfigurer; //import com.mortals.xhx.base.system.user.model.UserEntity;
import com.mortals.framework.util.ThreadPool; //import com.mortals.xhx.base.system.user.service.UserService;
import com.mortals.xhx.base.system.user.model.UserEntity; //import com.mortals.xhx.common.utils.SyncTreeSiteThread;
import com.mortals.xhx.base.system.user.model.UserQuery; //import lombok.extern.slf4j.Slf4j;
import com.mortals.xhx.base.system.user.service.UserService; //import org.apache.commons.logging.Log;
import com.mortals.xhx.common.pdu.user.UserPdu; //import org.apache.commons.logging.LogFactory;
import com.mortals.xhx.common.utils.BeanUtil; //import org.springframework.beans.factory.annotation.Autowired;
import com.mortals.xhx.common.utils.SyncTreeSiteThread; //import org.springframework.stereotype.Component;
import com.mortals.xhx.feign.user.IUserFeign; //@Component
import com.mortals.xhx.module.site.model.SiteTreeSelect; //@Slf4j
import com.mortals.xhx.module.site.service.SiteService; //public class DemoStartedService implements IApplicationStartedService {
import lombok.extern.slf4j.Slf4j; //
import org.apache.commons.logging.Log; // private static Log logger = LogFactory.getLog(DemoStartedService.class);
import org.apache.commons.logging.LogFactory; //// @Autowired
import org.springframework.beans.BeanUtils; //// private IUserFeign userFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;
import com.mortals.framework.springcloud.service.IApplicationStartedService;
import org.springframework.util.ObjectUtils;
import java.util.List;
@Component
@Slf4j
public class DemoStartedService implements IApplicationStartedService {
private static Log logger = LogFactory.getLog(DemoStartedService.class);
// @Autowired // @Autowired
// private IUserFeign userFeign; // private UserService userService;
@Autowired //
private UserService userService; // @Override
// public void start() {
@Override // logger.info("开始服务..[初始化用户站点树]");
public void start() { // UserEntity userEntity = new UserEntity();
logger.info("开始服务..[初始化用户站点树]"); // userEntity.initAttrValue();
UserEntity userEntity = new UserEntity(); // userEntity.setId(0L);
userEntity.initAttrValue(); // Context contextTemp = new Context();
userEntity.setId(0L); // contextTemp.setUser(userEntity);
Context contextTemp = new Context(); // SyncTreeSiteThread syncTreeSiteThread = new SyncTreeSiteThread(contextTemp);
contextTemp.setUser(userEntity); // ThreadPool.getInstance().execute(syncTreeSiteThread);
SyncTreeSiteThread syncTreeSiteThread = new SyncTreeSiteThread(contextTemp); //
ThreadPool.getInstance().execute(syncTreeSiteThread); // userEntity = new UserEntity();
// userEntity.initAttrValue();
userEntity = new UserEntity(); // userEntity.setId(1L);
userEntity.initAttrValue(); // contextTemp = new Context();
userEntity.setId(1L); // contextTemp.setUser(userEntity);
contextTemp = new Context(); // syncTreeSiteThread = new SyncTreeSiteThread(contextTemp);
contextTemp.setUser(userEntity); // ThreadPool.getInstance().execute(syncTreeSiteThread);
syncTreeSiteThread = new SyncTreeSiteThread(contextTemp); //
ThreadPool.getInstance().execute(syncTreeSiteThread); //
///* userService.find(new UserQuery()).forEach(user->{
// Context context = new Context();
/* userService.find(new UserQuery()).forEach(user->{ // context.setUser(user);
Context context = new Context(); // ThreadPool.getInstance().execute(new SyncTreeSiteThread(context));
context.setUser(user); // });*/
ThreadPool.getInstance().execute(new SyncTreeSiteThread(context)); //
});*/ ///* if(ObjectUtils.isEmpty(userFeign)){
// logger.info("userFeign未加载,加载本地用户");
/* if(ObjectUtils.isEmpty(userFeign)){ // userService.find(new UserQuery()).forEach(user->{
logger.info("userFeign未加载,加载本地用户"); // Context context = new Context();
userService.find(new UserQuery()).forEach(user->{ // context.setUser(user);
Context context = new Context(); // ThreadPool.getInstance().execute(new SyncTreeSiteThread(context));
context.setUser(user); // });
ThreadPool.getInstance().execute(new SyncTreeSiteThread(context)); //
}); // return;
// }*/
return; //
}*/ ///* userFeign.list(new UserPdu()).getData().getData().stream().forEach(userPdu->{
// Context context = new Context();
/* userFeign.list(new UserPdu()).getData().getData().stream().forEach(userPdu->{ //
Context context = new Context(); // UserEntity entity = new UserEntity();
// entity.initAttrValue();
UserEntity entity = new UserEntity(); // BeanUtils.copyProperties(userPdu, entity, BeanUtil.getNullPropertyNames(userPdu));
entity.initAttrValue(); //
BeanUtils.copyProperties(userPdu, entity, BeanUtil.getNullPropertyNames(userPdu)); // context.setUser(entity);
// ThreadPool.getInstance().execute(new SyncTreeSiteThread(context));
context.setUser(entity); // });*/
ThreadPool.getInstance().execute(new SyncTreeSiteThread(context)); // }
});*/ //
} // @Override
// public void stop() {
@Override // logger.info("停止服务..");
public void stop() { // }
logger.info("停止服务.."); //
} // @Override
// public int getOrder() {
@Override // return 10;
public int getOrder() { // }
return 10; //
} //}
}
package com.mortals.xhx.daemon.task;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.service.ITask;
import com.mortals.framework.service.ITaskExcuteService;
import com.mortals.xhx.module.dept.model.DeptEntity;
import com.mortals.xhx.module.dept.model.DeptQuery;
import com.mortals.xhx.module.dept.service.DeptService;
import com.mortals.xhx.module.matter.model.MatterEntity;
import com.mortals.xhx.module.matter.model.MatterQuery;
import com.mortals.xhx.module.matter.service.MatterService;
import com.mortals.xhx.module.matters.service.MattersService;
import com.mortals.xhx.module.site.model.SiteMatterQuery;
import com.mortals.xhx.module.site.service.SiteMatterService;
import com.mortals.xhx.module.site.service.SiteService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
/**
* 统计站点部门事项
*/
@Slf4j
@Service("StatSiteDeptMatterTask")
public class StatSiteDeptMatterTaskImpl implements ITaskExcuteService {
@Autowired
private DeptService deptService;
@Autowired
private MatterService matterService;
@Override
public void excuteTask(ITask task) throws AppException {
log.info("开始同步事项列表!");
List<DeptEntity> deptEntities = deptService.find(new DeptQuery());
for (DeptEntity deptEntity : deptEntities) {
int total = matterService.count(new MatterQuery().deptCode(deptEntity.getDeptNumber()), null);
if (total > 0) {
DeptEntity deptQuery = new DeptEntity();
deptQuery.setTotal(total);
deptQuery.setUpdateTime(new Date());
DeptEntity condition = new DeptEntity();
condition.setId(deptEntity.getId());
deptService.getDao().update(deptQuery, condition);
// deptService.update(deptEntity, null);
}
}
}
@Override
public void stopTask(ITask task) throws AppException {
}
}
package com.mortals.xhx.daemon.task;
import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.service.ITask;
import com.mortals.framework.service.ITaskExcuteService;
import com.mortals.xhx.base.system.user.model.UserEntity;
import com.mortals.xhx.base.system.user.model.UserQuery;
import com.mortals.xhx.base.system.user.service.UserService;
import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.common.pdu.RespData;
import com.mortals.xhx.common.pdu.user.UserPdu;
import com.mortals.xhx.feign.user.IUserFeign;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 同步门户用户
*/
@Slf4j
@Service("SyncPortalUserTask")
public class SyncPortalUserTaskImpl implements ITaskExcuteService {
@Autowired
private IUserFeign userFeign;
@Autowired
private UserService userService;
@Override
public void excuteTask(ITask task) throws AppException {
try {
log.info("同步门户用户");
syncPersons();
} catch (Exception e) {
log.error("同步门户异常", e);
}
}
private void syncPersons() {
UserPdu userPdu = new UserPdu();
userPdu.setPage(1);
userPdu.setSize(-1);
Rest<RespData<List<UserPdu>>> resp = userFeign.list(userPdu);
if (resp.getCode() == YesNoEnum.YES.getValue()) {
List<UserPdu> userPduList = resp.getData().getData();
log.info("用户总数量:{}", userPduList.size());
if (!ObjectUtils.isEmpty(userPduList)) {
List<UserEntity> newUserList = userPduList.stream().map(newUser -> {
UserEntity userEntity = new UserEntity();
userEntity.initAttrValue();
BeanUtils.copyProperties(newUser, userEntity, new String[]{"id", "lastLoginTime", "lastLoginAddress"});
return userEntity;
}).collect(Collectors.toList());
List<UserEntity> oldUserList = userService.find(new UserQuery());
log.info(" oldUserList size:{}", oldUserList.size());
//当前用户map
Map<String, UserEntity> oldUserMap = oldUserList.parallelStream().collect(Collectors.toMap(x -> x.getLoginName(), y -> y, (o, n) -> n));
//门户用户map
// Map<String, UserEntity> newUserMap = newUserList.stream().collect(Collectors.toMap(x -> x.getLoginName(), y -> y, (o, n) -> n));
List<UserEntity> saveUserList = newUserList.stream().map(item -> {
if (!oldUserMap.containsKey(item.getLoginName())) {
item.setCreateUserId(1L);
item.setCreateUserName("系统管理员");
item.setCreateTime(new Date());
return item;
}
return null;
}).filter(f -> f != null).collect(Collectors.toList());
if (!ObjectUtils.isEmpty(saveUserList)) {
log.info("用户新增,size:{}", saveUserList.size());
saveUserList.stream().forEach(item -> {
userService.getUserDao().insert(item);
});
}
}
//查找新增 与更新
}
}
@Override
public void stopTask(ITask task) throws AppException {
}
}
package com.mortals.xhx.daemon.task; //package com.mortals.xhx.daemon.task;
//
import com.alibaba.fastjson.JSON; //import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; //import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; //import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.ap.GlobalSysInfo; //import com.mortals.framework.ap.GlobalSysInfo;
import com.mortals.framework.common.Rest; //import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException; //import com.mortals.framework.exception.AppException;
import com.mortals.framework.service.ITask; //import com.mortals.framework.service.ITask;
import com.mortals.framework.service.ITaskExcuteService; //import com.mortals.framework.service.ITaskExcuteService;
import com.mortals.framework.util.HttpUtil; //import com.mortals.framework.util.HttpUtil;
import com.mortals.xhx.base.system.user.service.UserService; //import com.mortals.xhx.base.system.user.service.UserService;
import com.mortals.xhx.common.pdu.user.UserPhpPdu; //import com.mortals.xhx.common.pdu.user.UserPhpPdu;
import com.mortals.xhx.module.apply.service.ApproverService; //import com.mortals.xhx.module.apply.service.ApproverService;
import lombok.extern.slf4j.Slf4j; //import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; //import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; //import org.springframework.stereotype.Service;
//
import java.util.HashMap; //import java.util.HashMap;
import java.util.List; //import java.util.List;
//
import static com.mortals.xhx.common.key.Constant.PARAM_SERVER_PHP_HTTP_URL; //import static com.mortals.xhx.common.key.Constant.PARAM_SERVER_PHP_HTTP_URL;
//
/** ///**
* 同步用户 // * 同步用户
*/ // */
@Slf4j //@Slf4j
@Service("SyncUserTask") //@Service("SyncUserTask")
public class SyncUserTaskImpl implements ITaskExcuteService { //public class SyncUserTaskImpl implements ITaskExcuteService {
//
@Autowired // @Autowired
private UserService userService; // private UserService userService;
@Autowired // @Autowired
private ApproverService approverService; // private ApproverService approverService;
//
@Override // @Override
public void excuteTask(ITask task) throws AppException { // public void excuteTask(ITask task) throws AppException {
//
log.info("同步用户"); // log.info("同步用户");
String phpUrl = GlobalSysInfo.getParamValue(PARAM_SERVER_PHP_HTTP_URL, "http://172.15.28.116:8090"); // String phpUrl = GlobalSysInfo.getParamValue(PARAM_SERVER_PHP_HTTP_URL, "http://172.15.28.116:8090");
phpUrl += "/doors/inter/user/userList"; // phpUrl += "/doors/inter/user/userList";
String resp = null; // String resp = null;
try { // try {
HashMap<String, String> paramsMap = new HashMap<>(); // HashMap<String, String> paramsMap = new HashMap<>();
resp = HttpUtil.doGet(phpUrl, paramsMap); // resp = HttpUtil.doGet(phpUrl, paramsMap);
Rest<List<JSONObject>> list = JSON.parseObject(resp,Rest.class); // Rest<List<JSONObject>> list = JSON.parseObject(resp,Rest.class);
List<UserPhpPdu> upp = JSONArray.parseArray(JSONObject.toJSONString(list.getData()),UserPhpPdu.class); // List<UserPhpPdu> upp = JSONArray.parseArray(JSONObject.toJSONString(list.getData()),UserPhpPdu.class);
userService.updateUserList(upp); // userService.updateUserList(upp);
approverService.updateUserList(upp); // approverService.updateUserList(upp);
} catch (Exception e) { // } catch (Exception e) {
log.error("同步用户发生异常",e); // log.error("同步用户发生异常",e);
} // }
//
} // }
//
//
@Override // @Override
public void stopTask(ITask task) throws AppException { // public void stopTask(ITask task) throws AppException {
//
} // }
//
//
} //}
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