Commit c95fe372 authored by 赵啸非's avatar 赵啸非

优化用户同步更新所属站点代码

parent b85541d5
......@@ -4,6 +4,7 @@ import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.ap.SysConstains;
import com.mortals.framework.common.Rest;
import com.mortals.framework.common.code.UserType;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
......@@ -270,8 +271,34 @@ public class UserServiceImpl extends AbstractCRUDServiceImpl<UserDao, UserEntity
public void synchSitesAuth() throws AppException {
//todo 批量更新 用户太多 该接口查询非常缓慢 用户根据所属区域分组查询后更新
UserEntity query = new UserEntity();
List<UserEntity> all = this.find(query);
all.forEach(item -> {
List<UserEntity> allUsers = this.find(query);
//区域分组编码
allUsers.stream().collect(Collectors.groupingBy(x -> x.getAreaCodes())).entrySet().forEach(item -> {
String areaCodes = item.getKey();
if (!ObjectUtils.isEmpty(areaCodes)) {
List<String> areaCodeList = Arrays.asList(areaCodes.split(","));
String resp = areaService.getFlatSitesByAreaCodes(new AreaQuery().areaCodeList(areaCodeList), null);
JSONObject apiResp = JSON.parseObject(resp);
if (apiResp.getInteger("code") == YesNoEnum.YES.getValue()) {
String siteIds = apiResp.getString("data");
//更新用户站点
List<UserEntity> userEntityList = item.getValue();
if (!ObjectUtils.isEmpty(userEntityList)) {
userEntityList.stream().forEach(userEntity -> {
userEntity.setSiteIds(siteIds);
updateRedisUserSession(userEntity);
});
this.dao.updateBatch(userEntityList);
}
} else {
log.info("获取用户站点列表树数据失败:" + apiResp.getString("msg"));
}
}
});
/* all.forEach(item -> {
if (StringUtils.isNotEmpty(item.getAreaCodes())) {
List<String> areaCodeList = Arrays.asList(item.getAreaCodes().split(","));
String resp = areaService.getFlatSitesByAreaCodes(new AreaQuery().areaCodeList(areaCodeList), null);
......@@ -287,7 +314,7 @@ public class UserServiceImpl extends AbstractCRUDServiceImpl<UserDao, UserEntity
updateRedisUserSession(userEntity);
}
});
});*/
}
@Override
......@@ -353,7 +380,7 @@ public class UserServiceImpl extends AbstractCRUDServiceImpl<UserDao, UserEntity
entity.setCreateTime(new Date());
entity.setLoginPwd(SecurityUtil.md5DoubleEncoding(entity.getLoginPwd()));
int insert = this.getDao().insert(entity);
if (insert >0) {
if (insert > 0) {
successNum++;
RoleUserQuery roleUserQuery = new RoleUserQuery();
roleUserQuery.setUserId(entity.getId());
......
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