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

集成到4.0框架下

parent 47125fee
package com.mortals.xhx.common.pdu.user;
import com.mortals.framework.model.BaseEntityLong;
import java.util.Date;
import java.util.List;
import com.mortals.framework.model.BaseEntityLong;
/**
* 用户信息业务Pdu对象
......
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.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 feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
......@@ -15,11 +15,10 @@ import java.util.List;
/**
* 用户信息业务 Feign接口
*
* @author zxfei
* @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 {
......@@ -29,7 +28,7 @@ public interface IUserFeign extends IFeign {
* @param userPdu
* @return
*/
@PostMapping(value = "/user/list")
@PostMapping(value = "/user/interlist")
Rest<RespData<List<UserPdu>>> list(@RequestBody UserPdu userPdu);
......@@ -39,7 +38,7 @@ public interface IUserFeign extends IFeign {
* @param id
* @return
*/
@GetMapping(value = "/user/info")
@GetMapping(value = "/user/interinfo")
Rest<UserPdu> info(@RequestParam(value = "id") Long id);
/**
......@@ -49,7 +48,7 @@ public interface IUserFeign extends IFeign {
* @return
*/
@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 {
* @return
*/
@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")
String portalLogin(@RequestBody UserPdu userPdu);
/**
* 查询用户列表
*
* @param userPdu
* @return
*/
@PostMapping("/api/user/findAllUser")
String findAllUser(@RequestBody UserPdu userPdu);
/**
* 获取token
......@@ -76,9 +84,6 @@ public interface IUserFeign extends IFeign {
Rest<String> getToken(@RequestParam(value = "userKey") String userKey);
@PostMapping(value = "/user/synchSiteAuth")
Rest<String> synchSiteAuth();
}
......@@ -87,15 +92,14 @@ public interface IUserFeign extends IFeign {
class UserFeignFallbackFactory implements FallbackFactory<IUserFeign> {
@Override
public IUserFeign create(Throwable t) {
log.error("feign error", t);
return new IUserFeign() {
@Override
public Rest<RespData<List<UserPdu>>> list(UserPdu userPdu) {
public Rest<RespData<List<UserPdu>>> list(UserPdu userPdu) {
return Rest.fail("暂时无法获取用户信息业务列表,请稍后再试!");
}
@Override
public Rest<UserPdu> info(Long id) {
public Rest<UserPdu> info(Long id) {
return Rest.fail("暂时无法获取用户信息业务详细,请稍后再试!");
}
......@@ -115,16 +119,14 @@ class UserFeignFallbackFactory implements FallbackFactory<IUserFeign> {
}
@Override
public Rest<String> getToken(String userKey) {
return Rest.fail("token获取失败");
public String findAllUser(UserPdu userPdu) {
return null;
}
@Override
public Rest<String> synchSiteAuth() {
return Rest.fail("同步请求失败,稍后再试!");
public Rest<String> getToken(String userKey) {
return Rest.fail("token获取失败");
}
};
}
}
......
......@@ -29,7 +29,7 @@
<profiles.publish.path>/home/publish</profiles.publish.path>
<profiles.nacos.server-addr>192.168.0.252:8848</profiles.nacos.server-addr>
<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.level>INFO</profiles.log.level>
<package.environment>test</package.environment>
......@@ -38,14 +38,13 @@
</profile>
<profile>
<id>test</id>
<properties>
<profiles.active>test</profiles.active>
<profiles.server.path>/sm</profiles.server.path>
<profiles.publish.path>/home/publish</profiles.publish.path>
<profiles.nacos.server-addr>192.168.0.252:8848</profiles.nacos.server-addr>
<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.level>INFO</profiles.log.level>
<package.environment>test</package.environment>
......@@ -62,7 +61,7 @@
<profiles.publish.path>/home/publish</profiles.publish.path>
<profiles.nacos.server-addr>127.0.0.1:8848</profiles.nacos.server-addr>
<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.level>INFO</profiles.log.level>
<package.environment>build</package.environment>
......
......@@ -7,10 +7,11 @@ import com.mortals.framework.service.ICacheService;
import com.mortals.framework.service.IUser;
import com.mortals.framework.util.DateUtils;
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.UserQuery;
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.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
......@@ -19,6 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Primary;
import org.springframework.core.annotation.Order;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
......@@ -26,6 +28,7 @@ import javax.servlet.http.HttpServletRequest;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
/**
* token验证处理
......@@ -33,7 +36,7 @@ import java.util.Map;
* @author zxfei
*/
@Primary
@Service
@Service("authTokenService")
@Order(1)
@Slf4j
public class AuthTokenServiceImpl implements IAuthTokenService {
......@@ -78,6 +81,10 @@ public class AuthTokenServiceImpl implements IAuthTokenService {
@Autowired
private ICacheService cacheService;
@Autowired
private ResourceService resourceService;
/**
* 获取信息
*
......@@ -90,28 +97,42 @@ public class AuthTokenServiceImpl implements IAuthTokenService {
String token = getToken(request);
if (StringUtils.isNotEmpty(token)) {
try {
boolean signed = Jwts.parser().isSigned(token);
if (!signed) {
log.error("token非法!=>{}", token);
return null;
}
Claims claims = parseToken(token);
String uuid = (String) claims.get(SysConstains.LOGIN_USER_KEY);
String userKey = getTokenKey(uuid);
//cacheService.select(portalDb);
String userStr = cacheService.get(userKey);
//cacheService.select(db);
// Rest<String> rest = userFeign.getToken(userKey);
// String userStr = rest.getData();
if (StringUtils.isNotEmpty(userStr)) {
UserEntity userEntity = JSONObject.parseObject(userStr, UserEntity.class);
userEntity.setToken(token);
UserEntity temp = userService.selectOne(new UserQuery().loginName(userEntity.getLoginName()));
if(!ObjectUtils.isEmpty(temp)){
/* cacheService.select(portalDb);
String userStr = cacheService.get(userKey);*/
RedisTemplate<String, String> redisTemplate = cacheService.selectDbRedisTemplate(portalDb);
String userStr =redisTemplate.opsForValue().get(userKey);
//刷新token时间
UserEntity userEntity = JSONObject.parseObject(userStr, UserEntity.class);
if (!ObjectUtils.isEmpty(userEntity)) {
verifyToken(userEntity);
}
// cacheService.select(db);
if (!ObjectUtils.isEmpty(userEntity)) {
UserEntity temp = userService.getExtCache(userEntity.getLoginName());
if (!ObjectUtils.isEmpty(temp)) {
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;
}
} catch (Exception e) {
log.error("解析jwt token异常!", e);
log.error("解析jwt token异常!,token:{}",token, e);
return null;
}
}
......@@ -165,8 +186,8 @@ public class AuthTokenServiceImpl implements IAuthTokenService {
public void verifyToken(IUser user) {
long expireTime = user.getExpireTime();
long currentTime = System.currentTimeMillis();
if (expireTime - currentTime <= SECOND_MINUTE_TEN) {
log.info("不足十分钟,刷新过期时间");
if (expireTime - currentTime <= SECOND_MINUTE_TEN*1000) {
log.info("不足十分钟,刷新过期时间");
refreshToken(user);
}
}
......@@ -178,7 +199,7 @@ public class AuthTokenServiceImpl implements IAuthTokenService {
*/
public void refreshToken(IUser user) {
//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缓存
String userKey = getTokenKey(user.getToken());
//设置有效时间 单位秒
......@@ -245,4 +266,11 @@ public class AuthTokenServiceImpl implements IAuthTokenService {
private String getTokenKey(String 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;
import com.mortals.framework.utils.ServletUtils;
import com.mortals.framework.web.interceptor.BaseInterceptor;
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.stereotype.Component;
import org.springframework.util.ObjectUtils;
......@@ -43,8 +42,8 @@ public class AuthUserInterceptor extends BaseInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception {
//response.setContentType("application/json");
if (handler instanceof HandlerMethod) {
JSONObject ret = new JSONObject();
if(handler instanceof HandlerMethod){
HandlerMethod handlerMethod = (HandlerMethod) handler;
Method method = handlerMethod.getMethod();
UnAuth annotation = method.getAnnotation(UnAuth.class);
......@@ -52,7 +51,7 @@ public class AuthUserInterceptor extends BaseInterceptor {
//取消校验
return true;
}
} else if (handler instanceof ResourceHttpRequestHandler) {
}else if(handler instanceof ResourceHttpRequestHandler){
return true;
}
try {
......@@ -73,7 +72,7 @@ public class AuthUserInterceptor extends BaseInterceptor {
if (ObjectUtils.isEmpty(loginUser)) {
ServletUtils.renderString(response, JSONObject.toJSONString(Rest.fail(ERROR_TOKEN_EXPIRED, ERROR_TOKEN_EXPIRED_CONTENT)));
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);
} else {
ServletUtils.renderString(response, JSONObject.toJSONString(Rest.fail(ERROR_USER_OPERATION, ERROR_USER_OPERATION_CONTENT)));
......@@ -105,5 +104,4 @@ public class AuthUserInterceptor extends BaseInterceptor {
return false;
}
}
......@@ -8,30 +8,14 @@
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.model.Context;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
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.model.ResourceEntity;
import com.mortals.xhx.base.system.resource.model.ResourceQuery;
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.util.ObjectUtils;
import java.util.HashSet;
import java.util.List;
......
......@@ -10,6 +10,7 @@ package com.mortals.xhx.base.system.user.service;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Result;
import com.mortals.framework.service.ICRUDCacheService;
import com.mortals.framework.service.ICRUDService;
import com.mortals.framework.service.IUser;
import com.mortals.xhx.base.system.menu.model.MenuEntity;
......@@ -29,7 +30,7 @@ import java.util.Set;
* @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;
import com.mortals.framework.model.PageInfo;
import com.mortals.framework.model.Result;
import com.mortals.framework.service.IUser;
import com.mortals.framework.service.impl.AbstractCRUDCacheServiceImpl;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.framework.util.DataUtil;
import com.mortals.framework.util.SecurityUtil;
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.service.MenuService;
import com.mortals.xhx.base.system.resource.model.ResourceEntity;
......@@ -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.UserQuery;
import com.mortals.xhx.base.system.user.service.UserService;
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.stereotype.Service;
import org.springframework.util.CollectionUtils;
......@@ -56,7 +51,7 @@ import java.util.stream.Collectors;
* @version 1.0.0
*/
@Service("userService")
public class UserServiceImpl extends AbstractCRUDServiceImpl<UserDao, UserEntity, Long> implements UserService {
public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserEntity, Long> implements UserService {
@Autowired
......
......@@ -10,4 +10,5 @@ public class RedisKey {
*/
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;
import com.alibaba.fastjson.JSON;
import com.mortals.framework.model.Context;
import com.mortals.xhx.module.site.model.SiteTreeSelect;
import com.mortals.xhx.module.site.service.SiteService;
import com.mortals.xhx.utils.SpringUtils;
import lombok.AllArgsConstructor;
import lombok.extern.apachecommons.CommonsLog;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.ObjectUtils;
import java.util.List;
/**
* @author: zxfei
* @date: 2022/4/13 13:34
* @description:
**/
@AllArgsConstructor
@Slf4j
public class SyncTreeSiteThread implements Runnable {
private Context context;
@Override
public void run() {
SiteService siteService = SpringUtils.getBean(SiteService.class);
List<SiteTreeSelect> siteTreeSelects = siteService.siteTree(context);
siteService.setSiteTree(siteTreeSelects, context);
log.info("刷新用户站点树=》userID:{} siteIds:{} siteTree:{}",context.getUser().getId(),context.getUser().getSiteIds(), JSON.toJSONString(siteService.getSiteTree(context)));
}
}
//package com.mortals.xhx.common.utils;
//
//import com.alibaba.fastjson.JSON;
//import com.mortals.framework.model.Context;
//import com.mortals.xhx.module.site.model.SiteTreeSelect;
//import com.mortals.xhx.module.site.service.SiteService;
//import com.mortals.xhx.utils.SpringUtils;
//import lombok.AllArgsConstructor;
//import lombok.extern.apachecommons.CommonsLog;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.util.ObjectUtils;
//
//import java.util.List;
//
///**
// * @author: zxfei
// * @date: 2022/4/13 13:34
// * @description:
// **/
//@AllArgsConstructor
//@Slf4j
//public class SyncTreeSiteThread implements Runnable {
//
// private Context context;
//
// @Override
// public void run() {
// SiteService siteService = SpringUtils.getBean(SiteService.class);
// List<SiteTreeSelect> siteTreeSelects = siteService.siteTree(context);
// siteService.setSiteTree(siteTreeSelects, context);
// log.info("刷新用户站点树=》userID:{} siteIds:{} siteTree:{}",context.getUser().getId(),context.getUser().getSiteIds(), JSON.toJSONString(siteService.getSiteTree(context)));
// }
//
//}
package com.mortals.xhx.daemon.applicationservice;
import com.mortals.framework.model.Context;
import com.mortals.framework.service.ICacheService;
import com.mortals.framework.service.IUser;
import com.mortals.framework.springcloud.config.web.BaseWebMvcConfigurer;
import com.mortals.framework.util.ThreadPool;
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.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.model.SiteTreeSelect;
import com.mortals.xhx.module.site.service.SiteService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeanUtils;
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);
//package com.mortals.xhx.daemon.applicationservice;
//
//import com.mortals.framework.model.Context;
//import com.mortals.framework.springcloud.service.IApplicationStartedService;
//import com.mortals.framework.util.ThreadPool;
//import com.mortals.xhx.base.system.user.model.UserEntity;
//import com.mortals.xhx.base.system.user.service.UserService;
//import com.mortals.xhx.common.utils.SyncTreeSiteThread;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.logging.Log;
//import org.apache.commons.logging.LogFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//@Component
//@Slf4j
//public class DemoStartedService implements IApplicationStartedService {
//
// private static Log logger = LogFactory.getLog(DemoStartedService.class);
//// @Autowired
//// private IUserFeign userFeign;
// @Autowired
// private IUserFeign userFeign;
@Autowired
private UserService userService;
@Override
public void start() {
logger.info("开始服务..[初始化用户站点树]");
UserEntity userEntity = new UserEntity();
userEntity.initAttrValue();
userEntity.setId(0L);
Context contextTemp = new Context();
contextTemp.setUser(userEntity);
SyncTreeSiteThread syncTreeSiteThread = new SyncTreeSiteThread(contextTemp);
ThreadPool.getInstance().execute(syncTreeSiteThread);
userEntity = new UserEntity();
userEntity.initAttrValue();
userEntity.setId(1L);
contextTemp = new Context();
contextTemp.setUser(userEntity);
syncTreeSiteThread = new SyncTreeSiteThread(contextTemp);
ThreadPool.getInstance().execute(syncTreeSiteThread);
/* userService.find(new UserQuery()).forEach(user->{
Context context = new Context();
context.setUser(user);
ThreadPool.getInstance().execute(new SyncTreeSiteThread(context));
});*/
/* if(ObjectUtils.isEmpty(userFeign)){
logger.info("userFeign未加载,加载本地用户");
userService.find(new UserQuery()).forEach(user->{
Context context = new Context();
context.setUser(user);
ThreadPool.getInstance().execute(new SyncTreeSiteThread(context));
});
return;
}*/
/* userFeign.list(new UserPdu()).getData().getData().stream().forEach(userPdu->{
Context context = new Context();
UserEntity entity = new UserEntity();
entity.initAttrValue();
BeanUtils.copyProperties(userPdu, entity, BeanUtil.getNullPropertyNames(userPdu));
context.setUser(entity);
ThreadPool.getInstance().execute(new SyncTreeSiteThread(context));
});*/
}
@Override
public void stop() {
logger.info("停止服务..");
}
@Override
public int getOrder() {
return 10;
}
}
// private UserService userService;
//
// @Override
// public void start() {
// logger.info("开始服务..[初始化用户站点树]");
// UserEntity userEntity = new UserEntity();
// userEntity.initAttrValue();
// userEntity.setId(0L);
// Context contextTemp = new Context();
// contextTemp.setUser(userEntity);
// SyncTreeSiteThread syncTreeSiteThread = new SyncTreeSiteThread(contextTemp);
// ThreadPool.getInstance().execute(syncTreeSiteThread);
//
// userEntity = new UserEntity();
// userEntity.initAttrValue();
// userEntity.setId(1L);
// contextTemp = new Context();
// contextTemp.setUser(userEntity);
// syncTreeSiteThread = new SyncTreeSiteThread(contextTemp);
// ThreadPool.getInstance().execute(syncTreeSiteThread);
//
//
///* userService.find(new UserQuery()).forEach(user->{
// Context context = new Context();
// context.setUser(user);
// ThreadPool.getInstance().execute(new SyncTreeSiteThread(context));
// });*/
//
///* if(ObjectUtils.isEmpty(userFeign)){
// logger.info("userFeign未加载,加载本地用户");
// userService.find(new UserQuery()).forEach(user->{
// Context context = new Context();
// context.setUser(user);
// ThreadPool.getInstance().execute(new SyncTreeSiteThread(context));
// });
//
// return;
// }*/
//
///* userFeign.list(new UserPdu()).getData().getData().stream().forEach(userPdu->{
// Context context = new Context();
//
// UserEntity entity = new UserEntity();
// entity.initAttrValue();
// BeanUtils.copyProperties(userPdu, entity, BeanUtil.getNullPropertyNames(userPdu));
//
// context.setUser(entity);
// ThreadPool.getInstance().execute(new SyncTreeSiteThread(context));
// });*/
// }
//
// @Override
// public void stop() {
// logger.info("停止服务..");
// }
//
// @Override
// 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;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.ap.GlobalSysInfo;
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.framework.util.HttpUtil;
import com.mortals.xhx.base.system.user.service.UserService;
import com.mortals.xhx.common.pdu.user.UserPhpPdu;
import com.mortals.xhx.module.apply.service.ApproverService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import static com.mortals.xhx.common.key.Constant.PARAM_SERVER_PHP_HTTP_URL;
/**
* 同步用户
*/
@Slf4j
@Service("SyncUserTask")
public class SyncUserTaskImpl implements ITaskExcuteService {
@Autowired
private UserService userService;
@Autowired
private ApproverService approverService;
@Override
public void excuteTask(ITask task) throws AppException {
log.info("同步用户");
String phpUrl = GlobalSysInfo.getParamValue(PARAM_SERVER_PHP_HTTP_URL, "http://172.15.28.116:8090");
phpUrl += "/doors/inter/user/userList";
String resp = null;
try {
HashMap<String, String> paramsMap = new HashMap<>();
resp = HttpUtil.doGet(phpUrl, paramsMap);
Rest<List<JSONObject>> list = JSON.parseObject(resp,Rest.class);
List<UserPhpPdu> upp = JSONArray.parseArray(JSONObject.toJSONString(list.getData()),UserPhpPdu.class);
userService.updateUserList(upp);
approverService.updateUserList(upp);
} catch (Exception e) {
log.error("同步用户发生异常",e);
}
}
@Override
public void stopTask(ITask task) throws AppException {
}
}
//package com.mortals.xhx.daemon.task;
//
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONArray;
//import com.alibaba.fastjson.JSONObject;
//import com.mortals.framework.ap.GlobalSysInfo;
//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.framework.util.HttpUtil;
//import com.mortals.xhx.base.system.user.service.UserService;
//import com.mortals.xhx.common.pdu.user.UserPhpPdu;
//import com.mortals.xhx.module.apply.service.ApproverService;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//
//import java.util.HashMap;
//import java.util.List;
//
//import static com.mortals.xhx.common.key.Constant.PARAM_SERVER_PHP_HTTP_URL;
//
///**
// * 同步用户
// */
//@Slf4j
//@Service("SyncUserTask")
//public class SyncUserTaskImpl implements ITaskExcuteService {
//
// @Autowired
// private UserService userService;
// @Autowired
// private ApproverService approverService;
//
// @Override
// public void excuteTask(ITask task) throws AppException {
//
// log.info("同步用户");
// String phpUrl = GlobalSysInfo.getParamValue(PARAM_SERVER_PHP_HTTP_URL, "http://172.15.28.116:8090");
// phpUrl += "/doors/inter/user/userList";
// String resp = null;
// try {
// HashMap<String, String> paramsMap = new HashMap<>();
// resp = HttpUtil.doGet(phpUrl, paramsMap);
// Rest<List<JSONObject>> list = JSON.parseObject(resp,Rest.class);
// List<UserPhpPdu> upp = JSONArray.parseArray(JSONObject.toJSONString(list.getData()),UserPhpPdu.class);
// userService.updateUserList(upp);
// approverService.updateUserList(upp);
// } catch (Exception e) {
// log.error("同步用户发生异常",e);
// }
//
// }
//
//
// @Override
// 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