|
@@ -1,136 +0,0 @@
|
|
|
-package org.dromara.server.base.service.dept.strategy.impl;
|
|
|
|
|
-
|
|
|
|
|
-import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
-import cn.hutool.core.util.ObjUtil;
|
|
|
|
|
-import lombok.RequiredArgsConstructor;
|
|
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
-import org.dromara.common.core.constant.DefaultConstants;
|
|
|
|
|
-import org.dromara.common.core.domain.R;
|
|
|
|
|
-import org.dromara.common.core.utils.StringUtils;
|
|
|
|
|
-import org.dromara.common.json.utils.JsonUtils;
|
|
|
|
|
-import org.dromara.server.base.service.dept.SyncRemoteDeptService;
|
|
|
|
|
-import org.dromara.server.base.service.dept.strategy.ISyncDeptStrategy;
|
|
|
|
|
-import org.dromara.server.common.constant.SyncResourceConstants;
|
|
|
|
|
-import org.dromara.server.common.domain.bo.ResourceDept;
|
|
|
|
|
-import org.dromara.system.api.domain.bo.RemoteDeptBo;
|
|
|
|
|
-import org.dromara.system.api.domain.vo.RemoteDeptVo;
|
|
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
|
|
-
|
|
|
|
|
-import java.text.MessageFormat;
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
-
|
|
|
|
|
-/**
|
|
|
|
|
- * name: HrDeptStrategyImpl
|
|
|
|
|
- * package: org.dromara.server.base.dept.service.strategy.impl
|
|
|
|
|
- * description: 人事部门同步处理策略
|
|
|
|
|
- * date: 2024-10-18 14:40:23 14:40
|
|
|
|
|
- *
|
|
|
|
|
- * @author luoyibo
|
|
|
|
|
- * @version 0.1
|
|
|
|
|
- * @since JDK 1.8
|
|
|
|
|
- */
|
|
|
|
|
-@Slf4j
|
|
|
|
|
-@RequiredArgsConstructor
|
|
|
|
|
-@Service(SyncResourceConstants.HR_DEPT)
|
|
|
|
|
-public class HrDeptStrategyImpl implements ISyncDeptStrategy {
|
|
|
|
|
- private final SyncRemoteDeptService syncRemoteDeptService;
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void syncDept(List<ResourceDept> deptList) {
|
|
|
|
|
- List<String> syncMessage = new ArrayList<>();
|
|
|
|
|
- deptList.forEach(resourceDept -> {
|
|
|
|
|
- R<Object> result = syncDept(resourceDept);
|
|
|
|
|
- if (result.getCode() == R.SUCCESS) {
|
|
|
|
|
- syncMessage.add(MessageFormat.format("[同步部门成功]-[{0}]", JsonUtils.toJsonString(resourceDept)));
|
|
|
|
|
- } else {
|
|
|
|
|
- syncMessage.add(MessageFormat.format("[同步部门失败]-[{0}]-[{1}]", JsonUtils.toJsonString(resourceDept), result.getMsg()));
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- syncMessage.forEach(System.out::println);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void syncDelDept(List<ResourceDept> deptList) {
|
|
|
|
|
- List<String> syncDelMessage = new ArrayList<>();
|
|
|
|
|
- deptList.forEach(resourceDept -> {
|
|
|
|
|
- R<Object>result = syncRemoteDeptService.deleteDeptByOtherId(resourceDept.getDept_id());
|
|
|
|
|
-
|
|
|
|
|
- if (result.getCode() == R.SUCCESS) {
|
|
|
|
|
- syncDelMessage.add(MessageFormat.format("[同步删除部门成功]-[{0}]", JsonUtils.toJsonString(resourceDept)));
|
|
|
|
|
- } else {
|
|
|
|
|
- syncDelMessage.add(MessageFormat.format("[同步删除部门失败]-[{0}]-[{1}]", JsonUtils.toJsonString(resourceDept), result.getMsg()));
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- syncDelMessage.forEach(System.out::println);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 单个部门处理
|
|
|
|
|
- *
|
|
|
|
|
- * @param resourceDept 源部门
|
|
|
|
|
- * @return 入库部门模型
|
|
|
|
|
- */
|
|
|
|
|
- public R<Object> syncDept(ResourceDept resourceDept) {
|
|
|
|
|
- try {
|
|
|
|
|
- String tenantId = resourceDept.getTenantId();
|
|
|
|
|
- String otherId = resourceDept.getDept_id();
|
|
|
|
|
- String parentId = resourceDept.getParent_id();
|
|
|
|
|
- // 获取同步的部门在一卡通系统中对应的部门
|
|
|
|
|
- RemoteDeptVo remoteDeptVo = syncRemoteDeptService.selectDeptByOtherId(otherId, tenantId);
|
|
|
|
|
- // 获取同步的部门在一卡通系统中对应的父部门
|
|
|
|
|
- RemoteDeptVo remoteParentDeptVo = syncRemoteDeptService.selectDeptByOtherId(parentId, tenantId);
|
|
|
|
|
- // 组装写库的部门业务对象
|
|
|
|
|
- RemoteDeptBo remoteDeptBo = setRemoteDeptBo(resourceDept, remoteDeptVo, remoteParentDeptVo);
|
|
|
|
|
- if (remoteDeptVo != null) {
|
|
|
|
|
- // 已存在此部门,更新
|
|
|
|
|
- return syncRemoteDeptService.updateDept(remoteDeptBo);
|
|
|
|
|
- } else {
|
|
|
|
|
- return syncRemoteDeptService.insertDept(remoteDeptBo);
|
|
|
|
|
- }
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- log.error(e.getMessage(), e);
|
|
|
|
|
- return R.fail(e.getMessage());
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 同步部门预处理
|
|
|
|
|
- *
|
|
|
|
|
- * @param resourceDept 源部门
|
|
|
|
|
- * @param remoteDeptVo 一卡通系统对应部门
|
|
|
|
|
- * @param remoteParentDeptVo 一卡通系统对应父部门
|
|
|
|
|
- * @return 部门业务对象
|
|
|
|
|
- */
|
|
|
|
|
- private RemoteDeptBo setRemoteDeptBo(ResourceDept resourceDept, RemoteDeptVo remoteDeptVo, RemoteDeptVo remoteParentDeptVo) {
|
|
|
|
|
- String deptNum = resourceDept.getDept_num();
|
|
|
|
|
- String tenantId = resourceDept.getTenantId();
|
|
|
|
|
- RemoteDeptBo remoteDeptBo;
|
|
|
|
|
- if (ObjUtil.isEmpty(remoteDeptVo)) {
|
|
|
|
|
- remoteDeptBo = new RemoteDeptBo();
|
|
|
|
|
- // 业中同步的部门默认类型为03-部门
|
|
|
|
|
- remoteDeptBo.setDeptType(DefaultConstants.DEPT_DEPT_TYPE);
|
|
|
|
|
- remoteDeptBo.setCreateBy(resourceDept.getOperatorId());
|
|
|
|
|
- } else {
|
|
|
|
|
- remoteDeptBo = BeanUtil.copyProperties(remoteDeptVo, RemoteDeptBo.class);
|
|
|
|
|
- remoteDeptBo.setUpdateBy(resourceDept.getOperatorId());
|
|
|
|
|
- }
|
|
|
|
|
- remoteDeptBo.setDeptName(resourceDept.getDept_name());
|
|
|
|
|
- remoteDeptBo.setOtherId(resourceDept.getDept_id());
|
|
|
|
|
- if (StringUtils.isNotEmpty(tenantId)) {
|
|
|
|
|
- remoteDeptBo.setTenantId(tenantId);
|
|
|
|
|
- }
|
|
|
|
|
- if (remoteParentDeptVo != null) {
|
|
|
|
|
- remoteDeptBo.setParentId(remoteParentDeptVo.getDeptId());
|
|
|
|
|
- } else {
|
|
|
|
|
- // 如果同步的部门的父部门在系统中不存在,则父部门为学校
|
|
|
|
|
- if (!remoteDeptBo.getDeptId().equals(DefaultConstants.ROOT_DEPT_ID)) {
|
|
|
|
|
- remoteDeptBo.setParentId(DefaultConstants.ROOT_DEPT_ID);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- if (StringUtils.isNotEmpty(deptNum)) {
|
|
|
|
|
- remoteDeptBo.setOrderNum(Integer.valueOf(deptNum));
|
|
|
|
|
- }
|
|
|
|
|
- return remoteDeptBo;
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|