mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-13 04:46:50 +08:00
整理机构同步
This commit is contained in:
@@ -1,22 +1,20 @@
|
||||
package com.xboe;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.xboe.common.utils.StringUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.xboe.basic.entity.OldOrganization;
|
||||
import com.xboe.basic.entity.OldUser;
|
||||
import com.xboe.basic.service.IOldService;
|
||||
import com.xboe.primary.entity.MainOrganization;
|
||||
import com.xboe.primary.entity.MainUser;
|
||||
import com.xboe.primary.service.IMainDbSyncService;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -45,10 +43,10 @@ public class StartRunner implements ApplicationRunner {
|
||||
try {
|
||||
//同步机构
|
||||
List<OldOrganization> allList =oldService.listAll();
|
||||
for(OldOrganization org :allList) {
|
||||
|
||||
Set<String> oldIds=new HashSet<String>();
|
||||
for(OldOrganization org :allList){
|
||||
oldIds.add(org.getKid());
|
||||
MainOrganization mainOrg = mainService.findByKid(org.getKid());
|
||||
|
||||
if(mainOrg==null) {
|
||||
//添加
|
||||
mainOrg=organizationToEntity(org);
|
||||
@@ -58,46 +56,55 @@ public class StartRunner implements ApplicationRunner {
|
||||
copyOrganizationToEntity(mainOrg,org);
|
||||
mainService.update(mainOrg);
|
||||
}
|
||||
|
||||
mainOrgMap.put(org.getKid(),mainOrg.getId());//
|
||||
|
||||
}
|
||||
List<MainOrganization> localList=mainService.getAllSysIdAndId();
|
||||
for(MainOrganization mainOrg : localList) {
|
||||
if(!oldIds.contains(mainOrg.getSysId())) {
|
||||
//把本地的设置为已删除
|
||||
if(StringUtils.isNotBlank(mainOrg.getId())) {
|
||||
mainService.deletedOrg(mainOrg.getId());
|
||||
}else {
|
||||
log.error("id错误【"+mainOrg.getSysId()+"】");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//同步用户信息,2022/11/04同步用户学习时长
|
||||
//查询出本地用户
|
||||
List<MainUser> allUsers=mainService.findAll();
|
||||
for(MainUser mainUser : allUsers) {
|
||||
|
||||
OldUser oldUser = oldService.getByUserKid(mainUser.getSysId());
|
||||
if(oldUser!=null) {
|
||||
|
||||
String newId=mainOrgMap.get(oldUser.getOrgnizationId());
|
||||
|
||||
if(StringUtils.isBlank(newId)) {
|
||||
log.error("本地未找到【"+oldUser.getKid()+"】对应的机构id,不更新用户");
|
||||
}else {
|
||||
mainUser.setSysDepartId(oldUser.getOrgnizationId());
|
||||
mainUser.setCompanyId(oldUser.getCompanyId());
|
||||
mainUser.setDepartId(newId);
|
||||
|
||||
mainUser.setLearningDuration(oldUser.getLearningDuration());
|
||||
mainUser.setStatus(oldUser.getStatus());
|
||||
if(oldUser.getIsDeleted()!=null) {
|
||||
mainUser.setDeleted(oldUser.getIsDeleted()==0? false:true);
|
||||
}
|
||||
if(mainUser.getDeleted()) {
|
||||
if(StringUtils.isNotBlank(oldUser.getEmployeeStatus())){
|
||||
mainUser.setDeleted(oldUser.getEmployeeStatus().equals("3")? true:false);
|
||||
}
|
||||
}
|
||||
mainService.updateUser(mainUser);
|
||||
}
|
||||
}else {
|
||||
//本地应该删除
|
||||
log.error("原系统中无【"+mainUser.getSysId()+"】对应的用户id,本地标识删除此用户");
|
||||
mainService.deleteAccount(mainUser.getId());
|
||||
|
||||
}
|
||||
}
|
||||
// List<MainUser> allUsers=mainService.findAll();
|
||||
// for(MainUser mainUser : allUsers) {
|
||||
//
|
||||
// OldUser oldUser = oldService.getByUserKid(mainUser.getSysId());
|
||||
// if(oldUser!=null) {
|
||||
// String newId=mainOrgMap.get(oldUser.getOrgnizationId());
|
||||
//
|
||||
// if(StringUtils.isBlank(newId)) {
|
||||
// log.error("本地未找到【"+oldUser.getKid()+"】对应的机构id,不更新用户");
|
||||
// }else {
|
||||
// mainUser.setSysDepartId(oldUser.getOrgnizationId());
|
||||
// mainUser.setCompanyId(oldUser.getCompanyId());
|
||||
// mainUser.setDepartId(newId);
|
||||
//
|
||||
// mainUser.setLearningDuration(oldUser.getLearningDuration());
|
||||
// mainUser.setStatus(oldUser.getStatus());
|
||||
// if(oldUser.getIsDeleted()!=null) {
|
||||
// mainUser.setDeleted(oldUser.getIsDeleted()==0? false:true);
|
||||
// }
|
||||
// if(mainUser.getDeleted()) {
|
||||
// if(StringUtils.isNotBlank(oldUser.getEmployeeStatus())){
|
||||
// mainUser.setDeleted(oldUser.getEmployeeStatus().equals("3")? true:false);
|
||||
// }
|
||||
// }
|
||||
// mainService.updateUser(mainUser);
|
||||
// }
|
||||
// }else {
|
||||
// //本地应该删除
|
||||
// log.error("原系统中无【"+mainUser.getSysId()+"】对应的用户id,本地标识删除此用户");
|
||||
// mainService.deleteAccount(mainUser.getId());
|
||||
//
|
||||
// }
|
||||
// }
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("执行失败",e);
|
||||
|
||||
@@ -26,4 +26,7 @@ public interface MainOrganizationDao extends JpaRepository<MainOrganization,Stri
|
||||
|
||||
@Query(value = "from MainOrganization where sysId=?1")
|
||||
public List<MainOrganization> findBySysId(String sysId);
|
||||
|
||||
@Query(value = "Select new MainOrganization(id,sysId) from MainOrganization")
|
||||
public List<MainOrganization> getSysIdAndId();
|
||||
}
|
||||
|
||||
@@ -113,5 +113,14 @@ public class MainOrganization extends BaseEntity {
|
||||
|
||||
@Column(name="deleted",length = 1)
|
||||
private Boolean deleted;
|
||||
|
||||
public MainOrganization() {
|
||||
|
||||
}
|
||||
|
||||
public MainOrganization(String id,String sysId) {
|
||||
this.setId(id);
|
||||
this.sysId=sysId;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,8 +19,14 @@ public interface IMainDbSyncService {
|
||||
List<MainUser> findAll();
|
||||
|
||||
MainOrganization findByKid(String kid);
|
||||
|
||||
void deletedOrg(String id);
|
||||
|
||||
|
||||
/**
|
||||
* 获取已有的机构的sys_id和id
|
||||
* @return
|
||||
*/
|
||||
List<MainOrganization> getAllSysIdAndId();
|
||||
|
||||
void save(MainOrganization mainOrg);
|
||||
|
||||
|
||||
@@ -73,4 +73,20 @@ public class MainDbSyncServiceImpl implements IMainDbSyncService {
|
||||
accountDao.updateStatusAndDeleted(muser.getStatus(),muser.getDeleted(), muser.getId());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public List<MainOrganization> getAllSysIdAndId() {
|
||||
List<MainOrganization> orgs=orgDao.getSysIdAndId();
|
||||
return orgs;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void deletedOrg(String id) {
|
||||
|
||||
orgDao.setDeleted(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user