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

添加用户同步接口

parent c8531e80
...@@ -8,6 +8,9 @@ ...@@ -8,6 +8,9 @@
package com.mortals.xhx.base.system.user.service.impl; 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.ap.SysConstains;
import com.mortals.framework.common.Rest; import com.mortals.framework.common.Rest;
import com.mortals.framework.common.code.UserType; import com.mortals.framework.common.code.UserType;
...@@ -30,10 +33,13 @@ import com.mortals.xhx.base.system.user.dao.UserDao; ...@@ -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.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.busiz.rsp.ApiResp;
import com.mortals.xhx.busiz.rsp.UserResp;
import com.mortals.xhx.common.code.YesNoEnum; import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.common.pdu.RespData; import com.mortals.xhx.common.pdu.RespData;
import com.mortals.xhx.common.pdu.user.UserPdu; import com.mortals.xhx.common.pdu.user.UserPdu;
import com.mortals.xhx.feign.user.IUserFeign; import com.mortals.xhx.feign.user.IUserFeign;
import com.mortals.xhx.module.company.model.CompanyEntity;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -318,71 +324,39 @@ public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserE ...@@ -318,71 +324,39 @@ public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserE
@Override @Override
public Rest<Void> refreshUser() { public Rest<Void> refreshUser() {
UserPdu userPdu = new UserPdu(); //todo 请求php获取用户
userPdu.setPage(1); String respJson = HttpUtil.get("http://192.168.0.231:8076/zwfw_yx/inter/user/userlist");
userPdu.setSize(-1); ApiResp<List<UserResp>> rest = JSON.parseObject(respJson, new TypeReference<ApiResp<List<UserResp>>>() {
Rest<RespData<List<UserPdu>>> resp = userFeign.list(userPdu); });
if (resp.getCode() == YesNoEnum.YES.getValue()) { if (200 == rest.getCode()) {
List<UserPdu> userPduList = resp.getData().getData(); List<UserResp> userList = rest.getData();
log.info("用户总数量:{}", userPduList.size()); if (!ObjectUtils.isEmpty(userList)) {
if (!ObjectUtils.isEmpty(userPduList)) { //判断 如果不存在 在新增
for (UserResp userResp : userList) {
Map<String, UserPdu> userPduMap = userPduList.stream().collect(Collectors.toMap(x -> x.getLoginName(), y -> y, (x, y) -> x)); String username = userResp.getUsername();
UserQuery userQuery = new UserQuery();
List<UserEntity> newUserList = userPduList.stream().map(newUser -> { userQuery.setLoginName(username);
UserEntity userEntity = new UserEntity(); UserEntity userEntity = this.selectOne(userQuery);
userEntity.initAttrValue(); if (ObjectUtils.isEmpty(userEntity)) {
BeanUtils.copyProperties(newUser, userEntity, new String[]{"id", "lastLoginTime", "lastLoginAddress"}); try {
return userEntity; userEntity = new UserEntity();
}).collect(Collectors.toList()); userEntity.initAttrValue();
userEntity.setLoginName(userResp.getUsername());
List<UserEntity> saveUpdateUserList = newUserList.parallelStream().map(item -> { userEntity.setRealName(userResp.getName());
UserEntity extCache = this.getExtCache(item.getLoginName()); userEntity.setPhone(userResp.getPhone());
if (ObjectUtils.isEmpty(extCache)) { userEntity.setMobile(userResp.getPhone());
item.setCreateUserId(1L); userEntity.setLoginPwd(SecurityUtil.md5DoubleEncoding("123"));
item.setCreateUserName("系统管理员"); userEntity.setUserType(2);
item.setCreateTime(new Date()); this.save(userEntity);
return item; } catch (Exception e) {
} else { log.error("保存用户失败!", e.getMessage());
//更新用户列表
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());
} }
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(); 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 Content-Type: application/json
{ {
"loginName":"admin", "loginName":"admin",
"password":"xhxADMIN8@a", "password":"admin",
"securityCode":"admin" "securityCode":"admin"
} }
> {% > {%
client.global.set("SmsSet_id", JSON.parse(response.body).data.id); client.global.set("SmsSet_id", JSON.parse(response.body).data.id);
client.global.set("authToken", JSON.parse(response.body).data.token); client.global.set("authToken", JSON.parse(response.body).data.token);
%} %}
...@@ -51,7 +44,6 @@ Content-Type: application/json ...@@ -51,7 +44,6 @@ Content-Type: application/json
###短信设置查看 ###短信设置查看
GET {{baseUrl}}/sms/set/interinfo?id=1 GET {{baseUrl}}/sms/set/interinfo?id=1
Authorization: {{authToken}}
Accept: application/json Accept: application/json
###解析token ###解析token
......
...@@ -109,6 +109,10 @@ ...@@ -109,6 +109,10 @@
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
</dependencies> </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