Commit 82f33892 authored by 赵啸非's avatar 赵啸非

添加用户同步接口

parent c8531e80
......@@ -8,6 +8,9 @@
package com.mortals.xhx.base.system.user.service.impl;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.mortals.framework.ap.SysConstains;
import com.mortals.framework.common.Rest;
import com.mortals.framework.common.code.UserType;
......@@ -30,10 +33,13 @@ 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.busiz.rsp.ApiResp;
import com.mortals.xhx.busiz.rsp.UserResp;
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 com.mortals.xhx.module.company.model.CompanyEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -318,71 +324,39 @@ public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserE
@Override
public Rest<Void> refreshUser() {
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)) {
Map<String, UserPdu> userPduMap = userPduList.stream().collect(Collectors.toMap(x -> x.getLoginName(), y -> y, (x, y) -> x));
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> saveUpdateUserList = newUserList.parallelStream().map(item -> {
UserEntity extCache = this.getExtCache(item.getLoginName());
if (ObjectUtils.isEmpty(extCache)) {
item.setCreateUserId(1L);
item.setCreateUserName("系统管理员");
item.setCreateTime(new Date());
return item;
} else {
//更新用户列表
item.setId(extCache.getId());
item.setUpdateUserId(1L);
item.setUpdateUserName("系统管理员");
item.setUpdateTime(new Date());
return item;
}
}).collect(Collectors.toList());
Map<Boolean, List<UserEntity>> saveUpdateCollect = saveUpdateUserList.stream().collect(Collectors.partitioningBy(x -> x.getId() == null));
if (!ObjectUtils.isEmpty(saveUpdateCollect.get(true))) {
//需要新增的用户
log.info("需要新增用户数量:{}", saveUpdateCollect.get(true).size());
saveUpdateCollect.get(true).stream().forEach(item -> {
UserPdu pdu = userPduMap.get(item.getLoginName());
if(!ObjectUtils.isEmpty(pdu)){
item.setId(pdu.getId());
//todo 请求php获取用户
String respJson = HttpUtil.get("http://192.168.0.231:8076/zwfw_yx/inter/user/userlist");
ApiResp<List<UserResp>> rest = JSON.parseObject(respJson, new TypeReference<ApiResp<List<UserResp>>>() {
});
if (200 == rest.getCode()) {
List<UserResp> userList = rest.getData();
if (!ObjectUtils.isEmpty(userList)) {
//判断 如果不存在 在新增
for (UserResp userResp : userList) {
String username = userResp.getUsername();
UserQuery userQuery = new UserQuery();
userQuery.setLoginName(username);
UserEntity userEntity = this.selectOne(userQuery);
if (ObjectUtils.isEmpty(userEntity)) {
try {
userEntity = new UserEntity();
userEntity.initAttrValue();
userEntity.setLoginName(userResp.getUsername());
userEntity.setRealName(userResp.getName());
userEntity.setPhone(userResp.getPhone());
userEntity.setMobile(userResp.getPhone());
userEntity.setLoginPwd(SecurityUtil.md5DoubleEncoding("123"));
userEntity.setUserType(2);
this.save(userEntity);
} catch (Exception e) {
log.error("保存用户失败!", e.getMessage());
}
this.getUserDao().insert(item);
this.putCache(item.getId() == null ? "" : item.getId().toString(), item);
//更新默认用户角色
RoleUserQuery roleUserQuery = new RoleUserQuery();
roleUserQuery.setUserId(item.getId());
roleUserQuery.setRoleIdList(Arrays.asList(1L));
roleUserService.doDistributionRole(roleUserQuery);
});
}
}
if (!ObjectUtils.isEmpty(saveUpdateCollect.get(false))) {
//需要新增的用户
log.info("需要更新用户数量:{}", saveUpdateCollect.get(false).size());
saveUpdateCollect.get(false).stream().forEach(item -> {
this.getUserDao().update(item);
this.putCache(item.getId() == null ? "" : item.getId().toString(), item);
});
}
}
//查找新增 与更新
}
return Rest.ok();
}
......
package com.mortals.xhx.busiz.rsp;
import lombok.Data;
/**
* @author karlhoo
*/
@Data
public class UserResp {
private String username;
private String name;
private String phone;
}
###
GET http://localhost:80/api/item?id=99
Accept: application/json
###
###登录
POST http://192.168.0.250:11072/zwfw/login/login
POST {{baseUrl}}/login/login
Content-Type: application/json
{
"loginName":"admin",
"password":"xhxADMIN8@a",
"password":"admin",
"securityCode":"admin"
}
> {%
client.global.set("SmsSet_id", JSON.parse(response.body).data.id);
client.global.set("authToken", JSON.parse(response.body).data.token);
client.global.set("SmsSet_id", JSON.parse(response.body).data.id);
client.global.set("authToken", JSON.parse(response.body).data.token);
%}
......@@ -51,7 +44,6 @@ Content-Type: application/json
###短信设置查看
GET {{baseUrl}}/sms/set/interinfo?id=1
Authorization: {{authToken}}
Accept: application/json
###解析token
......
......@@ -109,6 +109,10 @@
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
</dependencies>
......
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