|
@@ -32,6 +32,7 @@ import me.zhengjie.modules.system.service.DeptService;
|
|
|
import me.zhengjie.utils.SecurityUtils;
|
|
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.util.ObjectUtils;
|
|
|
|
|
|
import java.text.DateFormat;
|
|
|
import java.text.SimpleDateFormat;
|
|
@@ -167,12 +168,14 @@ public class ZkDataSyncTask {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 人员数据同步
|
|
|
+ */
|
|
|
/**
|
|
|
* 人员数据同步
|
|
|
*/
|
|
|
private void userSync() {
|
|
|
-
|
|
|
- String api = "/api/thirdparty/v1/user/getzkusers";
|
|
|
+ String api = "/api/thirdparty/v1/user/getZkSysUsers";
|
|
|
|
|
|
JSONArray createTme = new JSONArray();
|
|
|
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
@@ -186,7 +189,7 @@ public class ZkDataSyncTask {
|
|
|
createTme.add(todayDate);
|
|
|
|
|
|
//计算总页数
|
|
|
- int total = getDatas(api,createTme,0,100,1).getJSONObject("data").getInteger("totalElements");
|
|
|
+ int total = getDatas(api,createTme,0,1,1).getJSONObject("data").getInteger("totalElements");
|
|
|
int pageSize = 100;
|
|
|
int pageTotal = (total / pageSize);
|
|
|
if (total % pageSize != 0) {
|
|
@@ -204,18 +207,42 @@ public class ZkDataSyncTask {
|
|
|
JSONObject userData = content.getJSONObject(i);
|
|
|
|
|
|
user.setId(userData.getString("id"));
|
|
|
- user.setUsername(userData.getString("username"));
|
|
|
+ if(userData.containsKey("username")) {
|
|
|
+ user.setUsername(userData.getString("username"));
|
|
|
+ }
|
|
|
user.setPassword(passwordEncoder.encode("12345678"));
|
|
|
user.setOrgPassword("12345678");
|
|
|
- Set<Job> jobs = new HashSet<>(JSONArray.parseArray(userData.getString("jobs"),Job.class));
|
|
|
- user.setJobs(jobs);
|
|
|
- Set<Role> roles = new HashSet<>(JSONArray.parseArray(userData.getString("roles"),Role.class));
|
|
|
- user.setRoles(roles);
|
|
|
- user.setGender(userData.getString("sex"));
|
|
|
- user.setDept(JSONObject.parseObject(userData.getString("dept"),Dept.class));
|
|
|
- user.setEmail(userData.getString("email"));
|
|
|
- user.setNickName(userData.getString("name"));
|
|
|
- user.setPhone(userData.getString("contacts"));
|
|
|
+ if(userData.containsKey("jobs")) {
|
|
|
+ Set<Job> jobs = new HashSet<>(JSONArray.parseArray(userData.getString("jobs"), Job.class));
|
|
|
+ user.setJobs(jobs);
|
|
|
+ }
|
|
|
+ if(userData.containsKey("roles")) {
|
|
|
+ Set<Role> roles = new HashSet<>(JSONArray.parseArray(userData.getString("roles"), Role.class));
|
|
|
+ user.setRoles(roles);
|
|
|
+ }
|
|
|
+ if(userData.containsKey("gender")) {
|
|
|
+ user.setGender(userData.getString("gender"));
|
|
|
+ }
|
|
|
+
|
|
|
+ if(userData.containsKey("dept")) {
|
|
|
+ user.setDept(JSONObject.parseObject(userData.getString("dept"), Dept.class));
|
|
|
+ }
|
|
|
+
|
|
|
+ if(userData.containsKey("email")) {
|
|
|
+ user.setEmail(userData.getString("email"));
|
|
|
+ }
|
|
|
+
|
|
|
+ if(userData.containsKey("nickName")) {
|
|
|
+ user.setNickName(userData.getString("nickName"));
|
|
|
+ }
|
|
|
+
|
|
|
+ if(userData.containsKey("phone")) {
|
|
|
+ user.setPhone(userData.getString("phone"));
|
|
|
+ }
|
|
|
+
|
|
|
+ if(userData.containsKey("enabled")) {
|
|
|
+ user.setEnabled(userData.getBoolean("enabled"));
|
|
|
+ }
|
|
|
|
|
|
DmUser dmUser = new DmUser();
|
|
|
dmUser.setDept(user.getDept());
|
|
@@ -225,10 +252,18 @@ public class ZkDataSyncTask {
|
|
|
dmUser.setName(user.getNickName());
|
|
|
dmUser.setSex(user.getGender());
|
|
|
|
|
|
- JSONObject dmUserObject = userData.getJSONObject("dmUser");
|
|
|
- dmUser.setCardId(dmUserObject.getString("cardid"));
|
|
|
- dmUser.setFaceid(dmUserObject.getString("faceid"));
|
|
|
- dmUser.setUserNumber(dmUserObject.getString("userNumber"));
|
|
|
+ if(!ObjectUtils.isEmpty(userData.getJSONObject("dmUser"))){
|
|
|
+ JSONObject dmUserObject = userData.getJSONObject("dmUser");
|
|
|
+ if(dmUserObject.containsKey("cardid")) {
|
|
|
+ dmUser.setCardId(dmUserObject.getString("cardid"));
|
|
|
+ }
|
|
|
+ if(dmUserObject.containsKey("userNumber")) {
|
|
|
+ dmUser.setUserNumber(dmUserObject.getString("userNumber"));
|
|
|
+ }
|
|
|
+ if(dmUserObject.containsKey("faceid")) {
|
|
|
+ dmUser.setFaceid(dmUserObject.getString("faceid"));
|
|
|
+ }
|
|
|
+ }
|
|
|
DmUser newDmUser = dmUserRepository.save(dmUser);
|
|
|
user.setDmUser(newDmUser);
|
|
|
userRepository.save(user);
|
|
@@ -242,7 +277,7 @@ public class ZkDataSyncTask {
|
|
|
*/
|
|
|
private void userSyncAll() {
|
|
|
|
|
|
- String api = "/api/thirdparty/v1/user/getzkusers";
|
|
|
+ String api = "/api/thirdparty/v1/user/getZkSysUsers";
|
|
|
|
|
|
//计算总页数
|
|
|
int total = getDatas(api,null,0,100,2).getJSONObject("data").getInteger("totalElements");
|
|
@@ -255,7 +290,7 @@ public class ZkDataSyncTask {
|
|
|
|
|
|
//按页获取
|
|
|
for (int k = 0; k < pageTotal; k++) {
|
|
|
- JSONObject json = getDatas(api,null,k,pageSize,2);
|
|
|
+ JSONObject json = getDatas(api, null,k,pageSize,1);
|
|
|
JSONObject data = json.getJSONObject("data");
|
|
|
JSONArray content = data.getJSONArray("content");
|
|
|
for (int i = 0; i < content.size(); i++) {
|
|
@@ -265,19 +300,40 @@ public class ZkDataSyncTask {
|
|
|
user.setId(userData.getString("id"));
|
|
|
if(userData.containsKey("username")) {
|
|
|
user.setUsername(userData.getString("username"));
|
|
|
- System.out.println("账号:"+userData.getString("username"));
|
|
|
}
|
|
|
user.setPassword(passwordEncoder.encode("12345678"));
|
|
|
user.setOrgPassword("12345678");
|
|
|
- Set<Job> jobs = new HashSet<>(JSONArray.parseArray(userData.getString("jobs"),Job.class));
|
|
|
- user.setJobs(jobs);
|
|
|
- Set<Role> roles = new HashSet<>(JSONArray.parseArray(userData.getString("roles"),Role.class));
|
|
|
- user.setRoles(roles);
|
|
|
- user.setGender(userData.getString("sex"));
|
|
|
- user.setDept(JSONObject.parseObject(userData.getString("dept"),Dept.class));
|
|
|
- user.setEmail(userData.getString("email"));
|
|
|
- user.setNickName(userData.getString("name"));
|
|
|
- user.setPhone(userData.getString("contacts"));
|
|
|
+ if(userData.containsKey("jobs")) {
|
|
|
+ Set<Job> jobs = new HashSet<>(JSONArray.parseArray(userData.getString("jobs"), Job.class));
|
|
|
+ user.setJobs(jobs);
|
|
|
+ }
|
|
|
+ if(userData.containsKey("roles")) {
|
|
|
+ Set<Role> roles = new HashSet<>(JSONArray.parseArray(userData.getString("roles"), Role.class));
|
|
|
+ user.setRoles(roles);
|
|
|
+ }
|
|
|
+ if(userData.containsKey("gender")) {
|
|
|
+ user.setGender(userData.getString("gender"));
|
|
|
+ }
|
|
|
+
|
|
|
+ if(userData.containsKey("dept")) {
|
|
|
+ user.setDept(JSONObject.parseObject(userData.getString("dept"), Dept.class));
|
|
|
+ }
|
|
|
+
|
|
|
+ if(userData.containsKey("email")) {
|
|
|
+ user.setEmail(userData.getString("email"));
|
|
|
+ }
|
|
|
+
|
|
|
+ if(userData.containsKey("nickName")) {
|
|
|
+ user.setNickName(userData.getString("nickName"));
|
|
|
+ }
|
|
|
+
|
|
|
+ if(userData.containsKey("phone")) {
|
|
|
+ user.setPhone(userData.getString("phone"));
|
|
|
+ }
|
|
|
+
|
|
|
+ if(userData.containsKey("enabled")) {
|
|
|
+ user.setEnabled(userData.getBoolean("enabled"));
|
|
|
+ }
|
|
|
|
|
|
DmUser dmUser = new DmUser();
|
|
|
dmUser.setDept(user.getDept());
|
|
@@ -287,9 +343,18 @@ public class ZkDataSyncTask {
|
|
|
dmUser.setName(user.getNickName());
|
|
|
dmUser.setSex(user.getGender());
|
|
|
|
|
|
- JSONObject dmUserObject = userData.getJSONObject("dmUser");
|
|
|
- dmUser.setCardId(dmUserObject.getString("cardid"));
|
|
|
- dmUser.setFaceid(dmUserObject.getString("faceid"));
|
|
|
+ if(!ObjectUtils.isEmpty(userData.getJSONObject("dmUser"))){
|
|
|
+ JSONObject dmUserObject = userData.getJSONObject("dmUser");
|
|
|
+ if(dmUserObject.containsKey("cardid")) {
|
|
|
+ dmUser.setCardId(dmUserObject.getString("cardid"));
|
|
|
+ }
|
|
|
+ if(dmUserObject.containsKey("userNumber")) {
|
|
|
+ dmUser.setUserNumber(dmUserObject.getString("userNumber"));
|
|
|
+ }
|
|
|
+ if(dmUserObject.containsKey("faceid")) {
|
|
|
+ dmUser.setFaceid(dmUserObject.getString("faceid"));
|
|
|
+ }
|
|
|
+ }
|
|
|
DmUser newDmUser = dmUserRepository.save(dmUser);
|
|
|
user.setDmUser(newDmUser);
|
|
|
userRepository.save(user);
|