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