Commit dbc08d24 authored by 廖旭伟's avatar 廖旭伟

Merge remote-tracking branch 'origin/master'

parents 9a8caf22 7923bd7e
...@@ -23,6 +23,7 @@ import org.springframework.stereotype.Service; ...@@ -23,6 +23,7 @@ import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
/** /**
* 同步用户 * 同步用户
...@@ -46,8 +47,19 @@ public class SyncUserTaskImpl implements ITaskExcuteService { ...@@ -46,8 +47,19 @@ public class SyncUserTaskImpl implements ITaskExcuteService {
userPdu.setPage(1); userPdu.setPage(1);
userPdu.setSize(-1); userPdu.setSize(-1);
Rest<RespData<List<UserPdu>>> list = userFeign.list(userPdu); Rest<RespData<List<UserPdu>>> list = userFeign.list(userPdu);
//更新本地用户信息,并且更新用户树
list.getData().getData().forEach(user -> { List<UserPdu> firstList = list.getData().getData();
List<UserEntity> secondList = userService.find(new UserQuery());
//交叉对比后,多的新增 少的删除
List<UserEntity> diffList = secondList.parallelStream()
.filter(item -> !firstList.parallelStream().map(e -> e.getId()).collect(Collectors.toList()).contains(item.getId()))
.collect(Collectors.toList());
log.info("diffList:{}",JSON.toJSONString(diffList));
//更新本地用户信息,并且更新用户站点树
firstList.forEach(user -> {
//查询用户是否存在, //查询用户是否存在,
//UserEntity userEntity = userService.get(user.getId()); //UserEntity userEntity = userService.get(user.getId());
......
...@@ -60,6 +60,8 @@ public interface SiteService extends ICRUDCacheService<SiteEntity, Long> { ...@@ -60,6 +60,8 @@ public interface SiteService extends ICRUDCacheService<SiteEntity, Long> {
void setSiteTree(List<SiteTreeSelect> list, Context context); void setSiteTree(List<SiteTreeSelect> list, Context context);
void removeSiteTree(List<SiteTreeSelect> list, Context context);
List<SiteEntity> getListAllInfoByQuery(SiteQuery query,Context context) throws AppException; List<SiteEntity> getListAllInfoByQuery(SiteQuery query,Context context) throws AppException;
......
...@@ -12,6 +12,7 @@ import com.mortals.framework.util.DataUtil; ...@@ -12,6 +12,7 @@ import com.mortals.framework.util.DataUtil;
import com.mortals.framework.util.StringUtils; import com.mortals.framework.util.StringUtils;
import com.mortals.xhx.common.key.Constant; import com.mortals.xhx.common.key.Constant;
import com.mortals.xhx.common.utils.SyncTreeSiteThread; import com.mortals.xhx.common.utils.SyncTreeSiteThread;
import com.mortals.xhx.feign.user.IUserFeign;
import com.mortals.xhx.module.area.model.AreaEntity; import com.mortals.xhx.module.area.model.AreaEntity;
import com.mortals.xhx.module.area.model.AreaQuery; import com.mortals.xhx.module.area.model.AreaQuery;
import com.mortals.xhx.module.area.service.AreaService; import com.mortals.xhx.module.area.service.AreaService;
...@@ -55,6 +56,8 @@ public class SiteServiceImpl extends AbstractCRUDCacheServiceImpl<SiteDao, SiteE ...@@ -55,6 +56,8 @@ public class SiteServiceImpl extends AbstractCRUDCacheServiceImpl<SiteDao, SiteE
private AreaService areaService; private AreaService areaService;
@Autowired @Autowired
private ModelService modelService; private ModelService modelService;
@Autowired
private IUserFeign userFeign;
@Override @Override
protected void validData(SiteEntity entity, Context context) throws AppException { protected void validData(SiteEntity entity, Context context) throws AppException {
...@@ -182,6 +185,8 @@ public class SiteServiceImpl extends AbstractCRUDCacheServiceImpl<SiteDao, SiteE ...@@ -182,6 +185,8 @@ public class SiteServiceImpl extends AbstractCRUDCacheServiceImpl<SiteDao, SiteE
protected void saveAfter(SiteEntity entity, Context context) throws AppException { protected void saveAfter(SiteEntity entity, Context context) throws AppException {
//刷新站点树 //刷新站点树
new Thread(new SyncTreeSiteThread(this, context)).start(); new Thread(new SyncTreeSiteThread(this, context)).start();
userFeign.synchSiteAuth();
super.saveAfter(entity, context); super.saveAfter(entity, context);
} }
...@@ -189,6 +194,8 @@ public class SiteServiceImpl extends AbstractCRUDCacheServiceImpl<SiteDao, SiteE ...@@ -189,6 +194,8 @@ public class SiteServiceImpl extends AbstractCRUDCacheServiceImpl<SiteDao, SiteE
@Override @Override
protected void removeAfter(Long[] ids, Context context, int result) throws AppException { protected void removeAfter(Long[] ids, Context context, int result) throws AppException {
new Thread(new SyncTreeSiteThread(this, context)).start(); new Thread(new SyncTreeSiteThread(this, context)).start();
userFeign.synchSiteAuth();
super.removeAfter(ids, context, result); super.removeAfter(ids, context, result);
} }
...@@ -255,7 +262,7 @@ public class SiteServiceImpl extends AbstractCRUDCacheServiceImpl<SiteDao, SiteE ...@@ -255,7 +262,7 @@ public class SiteServiceImpl extends AbstractCRUDCacheServiceImpl<SiteDao, SiteE
return true; return true;
} else { } else {
AreaEntity areaTemp = areaService.getExtCache(areaCode); AreaEntity areaTemp = areaService.getExtCache(areaCode);
if (!ObjectUtils.isEmpty(areaTemp)&&!ObjectUtils.isEmpty(areaTemp.getPid())) { if (!ObjectUtils.isEmpty(areaTemp) && !ObjectUtils.isEmpty(areaTemp.getPid())) {
AreaEntity areaEntity = areaService.selectOne(new AreaQuery().iid(areaTemp.getPid())); AreaEntity areaEntity = areaService.selectOne(new AreaQuery().iid(areaTemp.getPid()));
if (!ObjectUtils.isEmpty(areaEntity)) { if (!ObjectUtils.isEmpty(areaEntity)) {
return getSite(rootAreaCode, areaEntity.getAreaCode(), siteList, siteEntity); return getSite(rootAreaCode, areaEntity.getAreaCode(), siteList, siteEntity);
...@@ -270,15 +277,20 @@ public class SiteServiceImpl extends AbstractCRUDCacheServiceImpl<SiteDao, SiteE ...@@ -270,15 +277,20 @@ public class SiteServiceImpl extends AbstractCRUDCacheServiceImpl<SiteDao, SiteE
siteTreeMap.put(context.getUser().getId(), list); siteTreeMap.put(context.getUser().getId(), list);
} }
@Override
public void removeSiteTree(List<SiteTreeSelect> list, Context context) {
siteTreeMap.remove(context.getUser().getId());
}
@Override @Override
public List<SiteEntity> getListAllInfoByQuery(SiteQuery query, Context context) throws AppException { public List<SiteEntity> getListAllInfoByQuery(SiteQuery query, Context context) throws AppException {
List<SiteEntity> list = this.find(query,context); List<SiteEntity> list = this.find(query, context);
if(CollectionUtils.isNotEmpty(list)){ if (CollectionUtils.isNotEmpty(list)) {
list.stream().forEach(item->{ list.stream().forEach(item -> {
ModelQuery modelQuery = new ModelQuery(); ModelQuery modelQuery = new ModelQuery();
List<String> modelIds = StringUtils.converStr2List(item.getModelIds()); List<String> modelIds = StringUtils.converStr2List(item.getModelIds());
List<Long> ids = modelIds.stream().map(s -> DataUtil.converStr2Long(s.trim(),0)).collect(Collectors.toList()); List<Long> ids = modelIds.stream().map(s -> DataUtil.converStr2Long(s.trim(), 0)).collect(Collectors.toList());
if(ids.isEmpty()){ if (ids.isEmpty()) {
ids.add(0l); ids.add(0l);
} }
modelQuery.setIdList(ids); modelQuery.setIdList(ids);
......
...@@ -105,11 +105,11 @@ ...@@ -105,11 +105,11 @@
</trim> </trim>
</sql> </sql>
<!-- 新增 --> <!-- 新增 -->
<insert id="insert" parameterType="UserEntity" useGeneratedKeys="true" keyProperty="id"> <insert id="insert" parameterType="UserEntity" keyProperty="id">
insert into mortals_xhx_user insert into mortals_xhx_user
(loginName,loginPwd,loginPwd1,loginPwd2,loginPwd3,loginLimitAddress,realName,mobile,phone,email,qq,userType,siteId,status,customerId,createTime,createUserId,createUserName,lastLoginTime,lastLoginAddress,lastModPwdTime,lastModPwdAddr) (id,loginName,loginPwd,loginPwd1,loginPwd2,loginPwd3,loginLimitAddress,realName,mobile,phone,email,qq,userType,siteId,status,customerId,createTime,createUserId,createUserName,lastLoginTime,lastLoginAddress,lastModPwdTime,lastModPwdAddr)
VALUES VALUES
(#{loginName},#{loginPwd},#{loginPwd1},#{loginPwd2},#{loginPwd3},#{loginLimitAddress},#{realName},#{mobile},#{phone},#{email},#{qq},#{userType},#{siteId},#{status},#{customerId},#{createTime},#{createUserId},#{createUserName},#{lastLoginTime},#{lastLoginAddress},#{lastModPwdTime},#{lastModPwdAddr}) (#{id},#{loginName},#{loginPwd},#{loginPwd1},#{loginPwd2},#{loginPwd3},#{loginLimitAddress},#{realName},#{mobile},#{phone},#{email},#{qq},#{userType},#{siteId},#{status},#{customerId},#{createTime},#{createUserId},#{createUserName},#{lastLoginTime},#{lastLoginAddress},#{lastModPwdTime},#{lastModPwdAddr})
</insert> </insert>
<!-- 批量新增 --> <!-- 批量新增 -->
......
###系统基础皮肤列表 ###系统基础皮肤列表
POST {{baseUrl}}/skin/base/list POST {{baseUrl}}/skin/base/list
Authorization: {{authToken}}
Content-Type: application/json Content-Type: application/json
{ {
"page":1, "page":1,
"size":10, "size":10
"id": 7
} }
......
...@@ -2,13 +2,9 @@ ...@@ -2,13 +2,9 @@
###短信设置列表 ###短信设置列表
POST {{baseUrl}}/sms/set/list POST {{baseUrl}}/sms/set/list
Content-Type: application/json Content-Type: application/json
Authorization: Bearer {{authToken}}
{ {
"sign":"b0t82r" , "siteId":5291,
"username":"xshgou" ,
"messageoff":7796 ,
"siteId":5291 ,
"page":1, "page":1,
"size":10 "size":10
} }
......
...@@ -15,6 +15,7 @@ import java.util.List; ...@@ -15,6 +15,7 @@ import java.util.List;
/** /**
* 用户信息业务 Feign接口 * 用户信息业务 Feign接口
*
* @author zxfei * @author zxfei
* @date 2022-07-06 * @date 2022-07-06
*/ */
...@@ -48,7 +49,7 @@ public interface IUserFeign extends IFeign { ...@@ -48,7 +49,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);
/** /**
...@@ -58,7 +59,7 @@ public interface IUserFeign extends IFeign { ...@@ -58,7 +59,7 @@ 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")
...@@ -75,6 +76,9 @@ public interface IUserFeign extends IFeign { ...@@ -75,6 +76,9 @@ 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();
} }
...@@ -83,15 +87,15 @@ public interface IUserFeign extends IFeign { ...@@ -83,15 +87,15 @@ 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); 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,6 +119,11 @@ class UserFeignFallbackFactory implements FallbackFactory<IUserFeign> { ...@@ -115,6 +119,11 @@ class UserFeignFallbackFactory implements FallbackFactory<IUserFeign> {
return Rest.fail("token获取失败"); return Rest.fail("token获取失败");
} }
@Override
public Rest<String> synchSiteAuth() {
return Rest.fail("同步请求失败,稍后再试!");
}
}; };
} }
......
...@@ -12,6 +12,7 @@ import com.mortals.framework.util.DateUtils; ...@@ -12,6 +12,7 @@ import com.mortals.framework.util.DateUtils;
import com.mortals.framework.util.StringUtils; import com.mortals.framework.util.StringUtils;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController; import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.common.code.YesNoEnum; import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.common.key.Constant;
import com.mortals.xhx.common.pdu.SitePdu; import com.mortals.xhx.common.pdu.SitePdu;
import com.mortals.xhx.feign.model.IApiModelFeign; import com.mortals.xhx.feign.model.IApiModelFeign;
import com.mortals.xhx.feign.rsp.ApiResp; import com.mortals.xhx.feign.rsp.ApiResp;
...@@ -60,13 +61,15 @@ public class LoginController extends BaseCRUDJsonBodyMappingController<UserServi ...@@ -60,13 +61,15 @@ public class LoginController extends BaseCRUDJsonBodyMappingController<UserServi
loginForm.validate(); loginForm.validate();
userEntity = userService.doLogin(loginName, password, ip); userEntity = userService.doLogin(loginName, password, ip);
userEntity.setLastLoginAddress(ip); userEntity.setLastLoginAddress(ip);
List<MenuEntity> menuList = menuService.findTreeMenuByUser(userEntity);
userEntity.setMenuList(menuList);
userEntity.setLoginTime(System.currentTimeMillis()); userEntity.setLoginTime(System.currentTimeMillis());
userEntity.setToken(IdUtil.fastSimpleUUID()); String tmpToken = userEntity.getId() + ":" + IdUtil.fastSimpleUUID();
userEntity.setToken(tmpToken);
userEntity.setExpireTime(DateUtils.addCurrDate(7).getTime()); userEntity.setExpireTime(DateUtils.addCurrDate(7).getTime());
String token = authTokenService.createToken(userEntity); String token = authTokenService.createToken(userEntity);
data.put("token", token); data.put("token", token);
List<MenuEntity> menuList = menuService.findTreeMenuByUser(userEntity);
userEntity.setMenuList(menuList);
data.put("user", userEntity); data.put("user", userEntity);
if(StringUtils.isNotEmpty(userEntity.getAreaCodes())){ if(StringUtils.isNotEmpty(userEntity.getAreaCodes())){
SitePdu sitePdu = new SitePdu(); SitePdu sitePdu = new SitePdu();
...@@ -81,11 +84,15 @@ public class LoginController extends BaseCRUDJsonBodyMappingController<UserServi ...@@ -81,11 +84,15 @@ public class LoginController extends BaseCRUDJsonBodyMappingController<UserServi
data.put("siteList", apiResp.getData().get("data")); data.put("siteList", apiResp.getData().get("data"));
} }
recordSysLog(request, userEntity, "用户登录系统成功!"); recordSysLog(request, userEntity, "用户登录系统成功!");
ret.put(KEY_RESULT_DATA, data); ret.put(KEY_RESULT_DATA, data);
ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS); ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
ret.put(KEY_RESULT_MSG, "用户登录系统成功!"); ret.put(KEY_RESULT_MSG, "用户登录系统成功!");
//测试模糊获取所有redis中当前用户token user:login:tokens:1:
//Set<String> hkeys = cacheService.scan(Constant.LOGIN_TOKEN_KEY + userEntity.getId());
//log.info("loginKeys:{}",JSON.toJSONString(hkeys));
return ret.toJSONString(); return ret.toJSONString();
} catch (Exception e) { } catch (Exception e) {
log.error("login error ", e); log.error("login error ", e);
......
package com.mortals.xhx.module.user.service.impl; package com.mortals.xhx.module.user.service.impl;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.ap.SysConstains; import com.mortals.framework.ap.SysConstains;
...@@ -8,10 +9,14 @@ import com.mortals.framework.exception.AppException; ...@@ -8,10 +9,14 @@ import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context; 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.IAuthTokenService;
import com.mortals.framework.service.ICacheService;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl; import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.framework.util.DateUtils;
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.xhx.common.code.YesNoEnum; import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.common.key.Constant;
import com.mortals.xhx.feign.rsp.ApiResp; import com.mortals.xhx.feign.rsp.ApiResp;
import com.mortals.xhx.module.area.model.AreaQuery; import com.mortals.xhx.module.area.model.AreaQuery;
import com.mortals.xhx.module.area.service.AreaService; import com.mortals.xhx.module.area.service.AreaService;
...@@ -49,6 +54,10 @@ public class UserServiceImpl extends AbstractCRUDServiceImpl<UserDao, UserEntity ...@@ -49,6 +54,10 @@ public class UserServiceImpl extends AbstractCRUDServiceImpl<UserDao, UserEntity
private RoleService roleService; private RoleService roleService;
@Autowired @Autowired
private AreaService areaService; private AreaService areaService;
@Autowired
private IAuthTokenService authTokenService;
@Autowired
private ICacheService cacheService;
/* @Override /* @Override
...@@ -232,6 +241,15 @@ public class UserServiceImpl extends AbstractCRUDServiceImpl<UserDao, UserEntity ...@@ -232,6 +241,15 @@ public class UserServiceImpl extends AbstractCRUDServiceImpl<UserDao, UserEntity
userEntity.setAreaCodes(entityExt.getAreaCodeList().stream().collect(Collectors.joining(","))); userEntity.setAreaCodes(entityExt.getAreaCodeList().stream().collect(Collectors.joining(",")));
userEntity.setSiteIds(siteIds); userEntity.setSiteIds(siteIds);
this.update(userEntity, context); this.update(userEntity, context);
//更新redis中 所有用户session信息
Set<String> keys = cacheService.scan(Constant.LOGIN_TOKEN_KEY + userEntity.getId());
keys.forEach(item->{
String token = StrUtil.subAfter(item, Constant.LOGIN_TOKEN_KEY + userEntity.getId() + ":", false);
userEntity.setToken(token);
userEntity.setExpireTime(DateUtils.addCurrDate(7).getTime());
authTokenService.setUser(userEntity);
});
} }
......
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