mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-06 17:36:47 +08:00
用户同步
This commit is contained in:
@@ -8,6 +8,7 @@ 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;
|
||||
@@ -34,15 +35,19 @@ public class StartRunner implements ApplicationRunner {
|
||||
@Autowired
|
||||
IMainDbSyncService mainService;
|
||||
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
//用于存放 kid=newId
|
||||
|
||||
Map<String,String> mainOrgMap=new HashMap<String,String>();
|
||||
try {
|
||||
//同步机构
|
||||
List<OldOrganization> allList =oldService.listAll();
|
||||
for(OldOrganization org :allList) {
|
||||
|
||||
MainOrganization mainOrg = mainService.findByKid(org.getKid());
|
||||
|
||||
if(mainOrg==null) {
|
||||
//添加
|
||||
mainOrg=organizationToEntity(org);
|
||||
@@ -52,15 +57,20 @@ public class StartRunner implements ApplicationRunner {
|
||||
copyOrganizationToEntity(mainOrg,org);
|
||||
mainService.update(mainOrg);
|
||||
}
|
||||
|
||||
mainOrgMap.put(org.getKid(),mainOrg.getId());//
|
||||
|
||||
}
|
||||
//同步用户信息
|
||||
//查询出本地用户
|
||||
List<MainUser> allUsers=mainService.findAll();
|
||||
for(MainUser mainUser : allUsers) {
|
||||
|
||||
OldUser oldUser = oldService.getByUserKid(mainUser.getSysId());
|
||||
if(oldUser!=null) {
|
||||
String newId=mainOrgMap.get(oldUser.getKid());
|
||||
|
||||
String newId=mainOrgMap.get(oldUser.getOrgnizationId());
|
||||
|
||||
if(StringUtils.isBlank(newId)) {
|
||||
log.error("未找到【"+oldUser.getKid()+"】对应的机构id,不更新用户");
|
||||
}else {
|
||||
|
||||
@@ -24,8 +24,6 @@ public class OldOrganizationDao extends BaseDao<OldOrganization> {
|
||||
/**
|
||||
* 查询全部机构信息
|
||||
*
|
||||
* @param org
|
||||
* @param order
|
||||
* @return
|
||||
*/
|
||||
public List<OldOrganization> listAll() {
|
||||
@@ -33,7 +31,7 @@ public class OldOrganizationDao extends BaseDao<OldOrganization> {
|
||||
//filters.add(FieldFilters.eq("isDeleted", Constants.DELETED_NORMAL));
|
||||
//String hql="Select org,tn.namePath from FwOrganization org,FwOrgTreeNode tn where org.treeNodeId=tn.kid and tn.isDeleted=0";
|
||||
|
||||
QueryBuilder query=QueryBuilder.from("FwOrganization org,FwOrgTreeNode tn");
|
||||
QueryBuilder query=QueryBuilder.from("OldOrganization org,OldTreeNode tn");
|
||||
query.addFields("org","tn.namePath");
|
||||
|
||||
query.addFilter(FieldFilters.eqField("org.treeNodeId", "tn.kid"));
|
||||
@@ -43,9 +41,9 @@ public class OldOrganizationDao extends BaseDao<OldOrganization> {
|
||||
List<OldOrganization> list=new ArrayList<OldOrganization>();
|
||||
|
||||
try {
|
||||
PageList<Object[]> rs = this.findPageFields(query.builder());
|
||||
List<Object[]> rs = this.findListFields(query.builder());
|
||||
//List<Object[]> rs=this.findListFields(query.builder());
|
||||
for(Object[] objs : rs.getList()) {
|
||||
for(Object[] objs : rs) {
|
||||
OldOrganization fworg=(OldOrganization)objs[0];
|
||||
String namePath=(String)objs[1];
|
||||
fworg.setNamePath(namePath);
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.xboe.basic.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
/**
|
||||
* 机构treeNode表
|
||||
* @author seastar
|
||||
*
|
||||
*/
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name = "eln_fw_tree_node")
|
||||
public class OldTreeNode {
|
||||
|
||||
@Id
|
||||
@Column(name = "kid", length = 36)
|
||||
private String kid;
|
||||
|
||||
@Column(name = "tree_node_name", length = 100)
|
||||
private String nodeName;
|
||||
|
||||
@Column(name = "node_name_path", length = 500)
|
||||
private String namePath;
|
||||
|
||||
@Column(name = "is_deleted", length = 1)
|
||||
private Integer isDeleted;
|
||||
}
|
||||
@@ -8,10 +8,12 @@ import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.xboe.primary.entity.MainUser;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* 用户DAO
|
||||
*/
|
||||
@Transactional
|
||||
@Repository("userAllDao")
|
||||
public interface MainUserDao extends JpaRepository<MainUser,String> {
|
||||
|
||||
@@ -20,13 +22,14 @@ public interface MainUserDao extends JpaRepository<MainUser,String> {
|
||||
public Integer setDeleted(String id);
|
||||
|
||||
@Modifying
|
||||
@Query(value = "upate MainUser set departId=?1, sysDepartId=?2,companyId=?3 where id=?4")
|
||||
@Query(value = "update MainUser set departId=?1, sysDepartId=?2,companyId=?3 where id=?4")
|
||||
public Integer update(String departId,String sysDepartId,String companyId,String id);
|
||||
|
||||
|
||||
@Query(value = "from MainUser where id=?1")
|
||||
public MainUser get(String id);
|
||||
|
||||
|
||||
@Query(value = "Select new MainUser(id,sysId,userNo) from MainUser where id=?1")
|
||||
public List<MainUser> findAll(String id);
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ public class MainUser extends IdEntity {
|
||||
/**
|
||||
* 所在部门
|
||||
*/
|
||||
@Column(name = "depart_id", length = 18)
|
||||
@Column(name = "depart_id", length = 20)
|
||||
private String departId;
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,6 +20,8 @@ public interface IMainDbSyncService {
|
||||
|
||||
MainOrganization findByKid(String kid);
|
||||
|
||||
|
||||
|
||||
void save(MainOrganization mainOrg);
|
||||
|
||||
void update(MainOrganization mainOrg);
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.xboe.primary.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.xboe.common.utils.IDGenerator;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -42,9 +43,12 @@ public class MainDbSyncServiceImpl implements IMainDbSyncService {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional("transactionManagerPrimary")
|
||||
public void save(MainOrganization mainOrg) {
|
||||
mainOrg.setId(IDGenerator.generate());
|
||||
orgDao.save(mainOrg);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user