|
|
@@ -1,5 +1,6 @@ |
|
|
|
package com.hz.pm.api.user.manage; |
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
import cn.hutool.core.collection.ListUtil; |
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
@@ -19,7 +20,10 @@ import com.hz.pm.api.meta.helper.DictionaryCache; |
|
|
|
import com.hz.pm.api.meta.model.dto.DictionaryDTO; |
|
|
|
import com.hz.pm.api.meta.model.entity.ExpertDictionary; |
|
|
|
import com.hz.pm.api.meta.service.IExpertDictionaryService; |
|
|
|
import com.hz.pm.api.user.helper.MhUnitCache; |
|
|
|
import com.hz.pm.api.projectlib.model.entity.MhProject; |
|
|
|
import com.hz.pm.api.projectlib.model.entity.MhProjectSchemaTargetData; |
|
|
|
import com.hz.pm.api.projectlib.service.IMhProjectSchemaTargetDataService; |
|
|
|
import com.hz.pm.api.projectlib.service.IMhProjectService; |
|
|
|
import com.hz.pm.api.user.model.entity.MhCompany; |
|
|
|
import com.hz.pm.api.user.model.entity.MhUnit; |
|
|
|
import com.hz.pm.api.user.model.entity.UserInfo; |
|
|
@@ -32,6 +36,7 @@ import com.ningdatech.basic.util.CollUtils; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.util.ArrayList; |
|
|
@@ -62,6 +67,40 @@ public class SyncMhUserOrgManage { |
|
|
|
private final IMhCompanyService mhCompanyService; |
|
|
|
private final DictionaryCache dictionaryCache; |
|
|
|
private final IExpertDictionaryService expertDictionaryService; |
|
|
|
private final IMhProjectService mhProjectService; |
|
|
|
private final IMhProjectSchemaTargetDataService mhProjectSchemaTargetDataService; |
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void syncMhProjects() { |
|
|
|
MhRetDTO<List<MhProjectDTO>> mhRet = mhApiClient.listProjects(); |
|
|
|
if (mhRet.isOk()) { |
|
|
|
List<MhProjectDTO> mhRetData = mhRet.getData(); |
|
|
|
if (CollUtil.isEmpty(mhRetData)) { |
|
|
|
log.warn("未获取到可同步的项目信息:{}", JSONUtil.toJsonStr(mhRet)); |
|
|
|
return; |
|
|
|
} |
|
|
|
Map<String, MhProjectDTO> retProjectMap = CollUtils.listToMap(mhRetData, w -> w.getProjectName() + "#" + w.getUnitId()); |
|
|
|
List<MhProject> preProjects = mhProjectService.list(); |
|
|
|
Map<String, MhProject> preProjectMap = CollUtils.listToMap(preProjects, w -> w.getProjectName() + "#" + w.getUnitId()); |
|
|
|
retProjectMap.forEach((k, v) -> { |
|
|
|
MhProject preProject = preProjectMap.get(k); |
|
|
|
if (preProject != null) { |
|
|
|
BeanUtil.copyProperties(v, preProject); |
|
|
|
} else { |
|
|
|
preProject = BeanUtil.copyProperties(v, MhProject.class); |
|
|
|
} |
|
|
|
mhProjectService.saveOrUpdate(preProject); |
|
|
|
if (v.getSchemeTargetData() != null) { |
|
|
|
MhProjectSchemaTargetData schemaTargetData = new MhProjectSchemaTargetData(); |
|
|
|
BeanUtil.copyProperties(v.getSchemeTargetData(), schemaTargetData); |
|
|
|
schemaTargetData.setMhProjectId(preProject.getId()); |
|
|
|
mhProjectSchemaTargetDataService.saveOrUpdate(schemaTargetData); |
|
|
|
} |
|
|
|
}); |
|
|
|
} else { |
|
|
|
log.error("同步项目信息失败:{}", JSONUtil.toJsonStr(mhRet)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public void syncUsers(LocalDateTime syncDateTime) { |
|
|
|
MhRetDTO<List<MhUserDTO>> mhRet = mhApiClient.queryUsers(syncDateTime); |
|
|
|