diff --git a/.gitignore b/.gitignore
index 6ef8ddb..02d3554 100644
--- a/.gitignore
+++ b/.gitignore
@@ -36,6 +36,7 @@ DirectoryV2.xml
/lib/classbeanLib/ecology-dev-lib.jar
/lib/classbeanLib/web-inf-class-lib.jar
/lib/weaverLib/
+*.groovy
diff --git a/ecology-9-dev.iml b/ecology-9-dev.iml
new file mode 100644
index 0000000..c545449
--- /dev/null
+++ b/ecology-9-dev.iml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/aiyh/utils/action/CusBaseCronJob.java b/src/main/java/aiyh/utils/action/CusBaseCronJob.java
new file mode 100644
index 0000000..654f78d
--- /dev/null
+++ b/src/main/java/aiyh/utils/action/CusBaseCronJob.java
@@ -0,0 +1,60 @@
+package aiyh.utils.action;
+
+import aiyh.utils.Util;
+import aiyh.utils.excention.CustomerException;
+import org.apache.log4j.Logger;
+import weaver.interfaces.schedule.BaseCronJob;
+
+/**
+ *
基础定时任务模板方法
+ *
+ * create: 2022-12-04 13:52
+ *
+ * @author youHong.ai
+ */
+
+public abstract class CusBaseCronJob extends BaseCronJob {
+
+
+ Logger log = Util.getLogger();
+
+
+ @Override
+ public final void execute() {
+ try {
+ Util.verifyRequiredField(this);
+ } catch (CustomerException e) {
+ log.error("require param is not configuration! " + e.getMessage());
+ }
+ try {
+ this.runCode();
+ } catch (Exception e) {
+ this.exceptionCallback(e);
+ }
+ }
+
+
+ /**
+ * 运行代码
+ * 2022/12/4 13:59
+ * ******************************************
+ *
+ * @author youHong.ai
+ * ******************************************
+ */
+ public abstract void runCode();
+
+
+ /**
+ * 程序异常回调
+ * 2022/12/4 13:59
+ * ******************************************
+ *
+ * @param e 异常类
+ * @author youHong.ai
+ * ******************************************
+ */
+ public void exceptionCallback(Throwable e) {
+ log.error("execute cronJon failure! error detail msg \n" + Util.getErrString(e));
+ }
+}
diff --git a/src/main/java/com/api/youhong/ai/pcn/organization/orgchart/dto/HrmResourceDto.java b/src/main/java/com/api/youhong/ai/pcn/organization/orgchart/dto/HrmResourceDto.java
new file mode 100644
index 0000000..f692657
--- /dev/null
+++ b/src/main/java/com/api/youhong/ai/pcn/organization/orgchart/dto/HrmResourceDto.java
@@ -0,0 +1,64 @@
+package com.api.youhong.ai.pcn.organization.orgchart.dto;
+
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+
+/**
+ * 人员组织架构图人员信息dto
+ *
+ * create: 2022-12-02 12:26
+ *
+ * @author youHong.ai
+ */
+
+@Getter
+@Setter
+@ToString
+public class HrmResourceDto {
+
+ /** 用户id */
+ private Integer id;
+
+ /** 姓名 */
+ private String lastName;
+
+ /** 所有上级 */
+ private String managerStr;
+
+ /** 职位id */
+ private Integer jobTitleId;
+
+ /** 上级 */
+ private Integer managerId;
+
+ /** 部门id */
+ private Integer departmentId;
+
+ /** 部门名称 */
+ private String departmentName;
+
+ /** 职位名称 */
+ private String jobTitleName;
+
+ /** 用工类型 */
+ private Integer typeOfEmployment;
+
+ /** 是否是当前登陆用户的直接上级们 */
+ private boolean currentParent;
+
+ /** 是否是当前登陆用户 */
+ private boolean current;
+
+ /** 是否展示子节点 */
+ private Integer showChildren;
+
+ /** 是否展示子节点兄弟节点 */
+ private Integer showBrother;
+
+ /** 是否显示当前节点 */
+ private Integer show;
+
+ /** 头像地址 */
+ private String avatar;
+}
diff --git a/src/main/java/com/api/youhong/ai/pcn/organization/orgchart/mapper/OrgChartMapper.java b/src/main/java/com/api/youhong/ai/pcn/organization/orgchart/mapper/OrgChartMapper.java
index 26234ca..ecd7da2 100644
--- a/src/main/java/com/api/youhong/ai/pcn/organization/orgchart/mapper/OrgChartMapper.java
+++ b/src/main/java/com/api/youhong/ai/pcn/organization/orgchart/mapper/OrgChartMapper.java
@@ -1,5 +1,6 @@
package com.api.youhong.ai.pcn.organization.orgchart.mapper;
+import aiyh.utils.annotation.recordset.ParamMapper;
import aiyh.utils.annotation.recordset.Select;
import aiyh.utils.annotation.recordset.SqlMapper;
import com.api.youhong.ai.pcn.organization.orgchart.pojo.HrmResource;
@@ -18,6 +19,23 @@ import java.util.List;
public interface OrgChartMapper {
- @Select("select * from hrmresource")
- List selectAll();
+ @Select("select hrm.id, " +
+ " hrm.messagerurl avatar," +
+ " hrm.lastname last_name, " +
+ " hrm.managerstr manager_str, " +
+ " hrm.jobtitle job_title_id, " +
+ " hrm.managerid manager_id, " +
+ " hrm.departmentid department_id, " +
+ " dept.DEPARTMENTNAME department_name, " +
+ " job.JOBTITLENAME job_title_name, " +
+ " cus.$t{typeOfEmploymentFiled} type_of_employment " +
+ "from hrmresource hrm " +
+ " inner join hrmjobtitles job on hrm.JOBTITLE = job.id " +
+ " inner join cus_fielddata cus on cus.ID = hrm.ID " +
+ " and cus.SCOPE = 'HrmCustomFieldByInfoType' " +
+ " and (cus.SCOPEID = -1 or cus.SCOPEID = 3) " +
+ " inner join hrmdepartment dept on dept.id = hrm.DEPARTMENTID " +
+ "where hrm.status in (0, 1)")
+ List selectAll(@ParamMapper("typeOfEmploymentFiled") String typeOfEmploymentField);
+
}
diff --git a/src/main/java/com/api/youhong/ai/pcn/organization/orgchart/mapstruct/OrgChartMapStruct.java b/src/main/java/com/api/youhong/ai/pcn/organization/orgchart/mapstruct/OrgChartMapStruct.java
new file mode 100644
index 0000000..d745d5a
--- /dev/null
+++ b/src/main/java/com/api/youhong/ai/pcn/organization/orgchart/mapstruct/OrgChartMapStruct.java
@@ -0,0 +1,48 @@
+package com.api.youhong.ai.pcn.organization.orgchart.mapstruct;
+
+import com.api.youhong.ai.pcn.organization.orgchart.dto.HrmResourceDto;
+import com.api.youhong.ai.pcn.organization.orgchart.pojo.HrmResource;
+import com.api.youhong.ai.pcn.organization.orgchart.vo.OrgChartNodeVo;
+import org.mapstruct.Mapper;
+import org.mapstruct.Mapping;
+import org.mapstruct.factory.Mappers;
+
+/**
+ * mapstruct映射关系
+ *
+ * create: 2022-12-02 12:29
+ *
+ * @author youHong.ai
+ */
+
+@Mapper
+public interface OrgChartMapStruct {
+
+ OrgChartMapStruct INSTANCE = Mappers.getMapper(OrgChartMapStruct.class);
+
+
+ /**
+ * hrmResource 对象转换为Dto对象
+ *
+ * @param hrmResource hrmResource对象
+ * @return dto对象
+ */
+ @Mapping(target = "showChildren", ignore = true)
+ @Mapping(target = "showBrother", ignore = true)
+ @Mapping(target = "show", ignore = true)
+ @Mapping(target = "currentParent", ignore = true)
+ @Mapping(target = "current", ignore = true)
+ HrmResourceDto hrmResourceToDto(HrmResource hrmResource);
+
+
+ @Mapping(target = "childrenNum", ignore = true)
+ @Mapping(target = "isRoot", ignore = true)
+ @Mapping(target = "managerIds", expression = "java(OrgChartMapStructConvert.getManagerIds(dto.getManagerStr()))")
+ @Mapping(target = "jobId", source = "jobTitleId")
+ @Mapping(target = "type", source = "typeOfEmployment")
+ @Mapping(target = "name", source = "lastName")
+ @Mapping(target = "job", source = "jobTitleName")
+ @Mapping(target = "department", source = "departmentName")
+ @Mapping(target = "children", ignore = true)
+ OrgChartNodeVo hrmResourceDtoToVo(HrmResourceDto dto);
+}
diff --git a/src/main/java/com/api/youhong/ai/pcn/organization/orgchart/mapstruct/OrgChartMapStructConvert.java b/src/main/java/com/api/youhong/ai/pcn/organization/orgchart/mapstruct/OrgChartMapStructConvert.java
new file mode 100644
index 0000000..0237ea9
--- /dev/null
+++ b/src/main/java/com/api/youhong/ai/pcn/organization/orgchart/mapstruct/OrgChartMapStructConvert.java
@@ -0,0 +1,41 @@
+package com.api.youhong.ai.pcn.organization.orgchart.mapstruct;
+
+import aiyh.utils.Util;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+/**
+ * 自定义转换规则
+ *
+ * create: 2022-12-03 12:40
+ *
+ * @author youHong.ai
+ */
+
+public class OrgChartMapStructConvert {
+
+
+ /**
+ * 获取上级id数组
+ * 2022/12/3 12:43
+ * ******************************************
+ *
+ * @param managerStr 所有上级id逗号分割的字符串
+ * @return List 上级id数组
+ * @author youHong.ai
+ * ******************************************
+ */
+ public static List getManagerIds(String managerStr) {
+ if (Objects.isNull(managerStr) || "".equals(managerStr)) {
+ return Collections.emptyList();
+ }
+ managerStr = Util.removeSeparator(managerStr, ",");
+ return Arrays.stream(managerStr.split(","))
+ .map(Integer::parseInt)
+ .collect(Collectors.toList());
+ }
+}
diff --git a/src/main/java/com/api/youhong/ai/pcn/organization/orgchart/pojo/HrmResource.java b/src/main/java/com/api/youhong/ai/pcn/organization/orgchart/pojo/HrmResource.java
index 9e438a9..85a8cd9 100644
--- a/src/main/java/com/api/youhong/ai/pcn/organization/orgchart/pojo/HrmResource.java
+++ b/src/main/java/com/api/youhong/ai/pcn/organization/orgchart/pojo/HrmResource.java
@@ -16,4 +16,36 @@ import lombok.ToString;
@Getter
@ToString
public class HrmResource {
+
+ /** 用户id */
+ private Integer id;
+
+ /** 姓名 */
+ private String lastName;
+
+ /** 头像地址 */
+ private String avatar;
+
+ /** 所有上级 */
+ private String managerStr;
+
+ /** 职位id */
+ private Integer jobTitleId;
+
+ /** 上级 */
+ private Integer managerId;
+
+ /** 部门id */
+ private Integer departmentId;
+
+ /** 部门名称 */
+ private String departmentName;
+
+ /** 职位名称 */
+ private String jobTitleName;
+
+ /** 用工类型 */
+ private Integer typeOfEmployment;
+
+
}
diff --git a/src/main/java/com/api/youhong/ai/pcn/organization/orgchart/service/OrgChartService.java b/src/main/java/com/api/youhong/ai/pcn/organization/orgchart/service/OrgChartService.java
index 5a3b552..c122d01 100644
--- a/src/main/java/com/api/youhong/ai/pcn/organization/orgchart/service/OrgChartService.java
+++ b/src/main/java/com/api/youhong/ai/pcn/organization/orgchart/service/OrgChartService.java
@@ -1,11 +1,20 @@
package com.api.youhong.ai.pcn.organization.orgchart.service;
import aiyh.utils.Util;
+import cn.hutool.core.lang.Assert;
+import com.api.youhong.ai.pcn.organization.orgchart.dto.HrmResourceDto;
import com.api.youhong.ai.pcn.organization.orgchart.mapper.OrgChartMapper;
+import com.api.youhong.ai.pcn.organization.orgchart.mapstruct.OrgChartMapStruct;
+import com.api.youhong.ai.pcn.organization.orgchart.pojo.HrmResource;
import com.api.youhong.ai.pcn.organization.orgchart.vo.OrgChartNodeVo;
+import ebu7common.youhong.ai.bean.Builder;
import weaver.hrm.User;
+import java.util.Arrays;
import java.util.List;
+import java.util.Objects;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.stream.Collectors;
/**
* 人员组织架构图逻辑处理
@@ -19,14 +28,99 @@ public class OrgChartService {
private final OrgChartMapper mapper = Util.getMapper(OrgChartMapper.class);
+ private final OrgChartMapStruct struct = OrgChartMapStruct.INSTANCE;
+
/**
* 获取人员组织架构图数据
*
* @param logInUser 当前登陆对象
* @return 组织架构图数据
+ * @author youHong.ai
*/
public List getOrgChartTree(User logInUser) {
int userId = logInUser.getUID();
- return null;
+ String typeOfEmploymentField = Util.getCusConfigValue("typeOfEmploymentField");
+ Assert.notBlank(typeOfEmploymentField, "config [typeOfEmploymentField] is null or blank!");
+ List hrmResourceList = mapper.selectAll(typeOfEmploymentField);
+ //List hrmResourceDtoList = new ArrayList();
+ AtomicReference currentUser = new AtomicReference<>();
+ /* ******************* 将pojo转换为Dto对象,对节点属性默认值赋值,找出当前用户并设置显示 ******************* */
+ List hrmResourceDtoList = hrmResourceList.stream()
+ .map(struct::hrmResourceToDto)
+ .peek(item -> Builder.startSet(item)
+ .with(HrmResourceDto::setShow, 0)
+ .with(HrmResourceDto::setShowBrother, 0)
+ .with(HrmResourceDto::setShowChildren, 0)
+ .endSet())
+ .collect(Collectors.toList());
+ hrmResourceDtoList.stream()
+ .filter(item -> item.getId() == userId)
+ .forEach(item -> {
+ Builder.startSet(item)
+ .with(HrmResourceDto::setShow, 1)
+ .with(HrmResourceDto::setShowBrother, 1)
+ .with(HrmResourceDto::setShowChildren, 1)
+ .with(HrmResourceDto::setCurrent, true)
+ .endSet();
+ currentUser.set(item);
+ });
+ Assert.notNull(currentUser, "not find current login user info!");
+ /* ******************* 查找当前登陆人员的所有上级 ******************* */
+ String currentUserManagerStr = currentUser.get().getManagerStr();
+ if (Objects.isNull(currentUserManagerStr)) {
+ currentUserManagerStr = "";
+ }
+ currentUserManagerStr = Util.removeSeparator(currentUserManagerStr, ",");
+ List currentUserManagerList = Arrays.stream(currentUserManagerStr.split(","))
+ .map(Integer::parseInt)
+ .collect(Collectors.toList());
+ /* ******************* 对当前用户的所有直接上级设置标识 ******************* */
+ hrmResourceDtoList.stream()
+ .filter(item -> currentUserManagerList.contains(item.getId()))
+ .forEach(item -> Builder.startSet(item)
+ .with(HrmResourceDto::setShowChildren, 1)
+ .with(HrmResourceDto::setCurrentParent, true)
+ .endSet());
+
+ /* ******************* 转换dto为Vo并且设置根节点标识 ******************* */
+ List orgChartNodeVoList = hrmResourceDtoList.stream()
+ .map(struct::hrmResourceDtoToVo)
+ .collect(Collectors.toList());
+ return Util.listToTree(orgChartNodeVoList, OrgChartNodeVo::getId,
+ OrgChartNodeVo::getManagerId, OrgChartNodeVo::getChildren,
+ OrgChartNodeVo::setChildren,
+ parentId -> parentId == null || parentId <= 0)
+ .stream()
+ .peek(item -> item.setIsRoot(true))
+ .peek(item->recursionChildrenNums(item,0))
+ .collect(Collectors.toList());
}
+
+
+ /**
+ * 计算节点所有子节点的数量
+ * 2022/12/3 17:55
+ * ******************************************
+ *
+ * @param chartNodeVo 节点对象
+ * @return Integer 对应节点的所有子节点的数量
+ * @author youHong.ai
+ * ******************************************
+ */
+ private Integer recursionChildrenNums(OrgChartNodeVo chartNodeVo, int n) {
+ List children = chartNodeVo.getChildren();
+ if(Objects.isNull(children)|| children.size() == 0){
+ chartNodeVo.setChildrenNum(0);
+ return 0;
+ }
+ n += children.size();
+ for (OrgChartNodeVo child : children) {
+ child.setChildrenNum(recursionChildrenNums(child,0));
+ n += child.getChildrenNum();
+ }
+ chartNodeVo.setChildrenNum(n);
+ return n;
+ }
+
}
+
diff --git a/src/main/java/com/api/youhong/ai/pcn/organization/orgchart/vo/OrgChartNodeVo.java b/src/main/java/com/api/youhong/ai/pcn/organization/orgchart/vo/OrgChartNodeVo.java
index 0b1a5cf..ab21d57 100644
--- a/src/main/java/com/api/youhong/ai/pcn/organization/orgchart/vo/OrgChartNodeVo.java
+++ b/src/main/java/com/api/youhong/ai/pcn/organization/orgchart/vo/OrgChartNodeVo.java
@@ -18,61 +18,57 @@ import java.util.List;
@ToString
public class OrgChartNodeVo {
- /**
- * 人员id
- */
+ /** 用户id */
private Integer id;
- /**
- * 人员姓名
- */
+ /** 姓名 */
private String name;
- /**
- * 人员头像
- */
- private String avatar;
+ /** 上级 */
+ private Integer managerId;
- /**
- * 人员部门
- */
+ /** 部门Id */
+ private Integer departmentId;
+
+ /** 部门名称 */
private String department;
- /**
- * 人员职位
- */
+ /** 所有上级 */
+ private List managerIds;
+
+ /** 职位名称 */
private String job;
- /**
- * 人员国籍类型
- */
- private String type;
+ /** 职位id */
+ private Integer jobId;
- /**
- * 是否展示
- */
- private Integer show;
+ /** 用工类型 */
+ private Integer type;
- /**
- * 是否展示下级兄弟
- */
- private Integer showBrother;
+ /** 是否是当前登陆用户的直接上级们 */
+ private boolean currentParent;
- /**
- * 是否是当前的登陆人员
- */
+ /** 是否是当前登陆用户 */
private boolean current;
- /**
- * 是否是当前登陆人员的直属上级
- */
- private boolean currenParent;
-
- /**
- * 是否展示子节点
- */
+ /** 是否展示子节点 */
private Integer showChildren;
+ /** 是否展示子节点兄弟节点 */
+ private Integer showBrother;
+
+ /** 是否显示当前节点 */
+ private Integer show;
+
+ /** 是否是根节点 */
+ private Boolean isRoot;
+
+ /** 当前用户的所有下级的总数 */
+ private Integer childrenNum;
+
+ /** 头像地址 */
+ private String avatar;
+
/**
* 子节点
*/
diff --git a/src/main/java/ebu7common/youhong/ai/bean/Builder.java b/src/main/java/ebu7common/youhong/ai/bean/Builder.java
index 788b728..4eef414 100644
--- a/src/main/java/ebu7common/youhong/ai/bean/Builder.java
+++ b/src/main/java/ebu7common/youhong/ai/bean/Builder.java
@@ -17,12 +17,18 @@ public class Builder {
private Supplier constructor;
+ private T target;
+
private List> propertiesInjects = new ArrayList<>();
private Builder(Supplier constructor) {
this.constructor = constructor;
}
+ private Builder(T instance) {
+ this.target = instance;
+ }
+
/**
* 获取建造者对象
@@ -35,6 +41,10 @@ public class Builder {
return new Builder(constructor);
}
+ public static Builder startSet(T instance) {
+ return new Builder(instance);
+ }
+
/**
* 设置值方法
*
@@ -56,11 +66,26 @@ public class Builder {
* @return 目标对象
*/
public T build() {
- T instance = this.constructor.get();
+ T instance;
+ if (this.target == null) {
+ instance = this.constructor.get();
+ } else {
+ instance = target;
+ }
this.propertiesInjects.forEach(inject -> inject.accept(instance));
return instance;
}
+ public void endSet() {
+ T instance;
+ if (this.target == null) {
+ instance = this.constructor.get();
+ } else {
+ instance = target;
+ }
+ this.propertiesInjects.forEach(inject -> inject.accept(instance));
+ }
+
@FunctionalInterface
public interface PropertiesInject {
void accept(T setFun, V value);
diff --git a/src/main/java/weaver/youhong/ai/xinbake/schedule/hrmresource/UpdateManagerId.java b/src/main/java/weaver/youhong/ai/xinbake/schedule/hrmresource/UpdateManagerId.java
new file mode 100644
index 0000000..fad9f4c
--- /dev/null
+++ b/src/main/java/weaver/youhong/ai/xinbake/schedule/hrmresource/UpdateManagerId.java
@@ -0,0 +1,28 @@
+package weaver.youhong.ai.xinbake.schedule.hrmresource;
+
+import aiyh.utils.Util;
+import aiyh.utils.action.CusBaseCronJob;
+import org.apache.log4j.Logger;
+import weaver.interfaces.schedule.BaseCronJob;
+import weaver.youhong.ai.xinbake.schedule.hrmresource.mapper.UpdateManagerIdMapper;
+
+/**
+ * 更新人员组织架构的上级Id
+ *
+ * create: 2022-12-04 13:49
+ *
+ * @author youHong.ai
+ */
+
+public class UpdateManagerId extends CusBaseCronJob {
+
+
+ private final UpdateManagerIdMapper mapper = Util.getMapper(UpdateManagerIdMapper.class);
+
+
+ @Override
+ public void runCode() {
+
+
+ }
+}
diff --git a/src/main/java/weaver/youhong/ai/xinbake/schedule/hrmresource/mapper/UpdateManagerIdMapper.java b/src/main/java/weaver/youhong/ai/xinbake/schedule/hrmresource/mapper/UpdateManagerIdMapper.java
new file mode 100644
index 0000000..b8cef63
--- /dev/null
+++ b/src/main/java/weaver/youhong/ai/xinbake/schedule/hrmresource/mapper/UpdateManagerIdMapper.java
@@ -0,0 +1,15 @@
+package weaver.youhong.ai.xinbake.schedule.hrmresource.mapper;
+
+import aiyh.utils.annotation.recordset.SqlMapper;
+
+/**
+ * 更新人员组织架构上级id数据库操作
+ *
+ * create: 2022-12-04 13:50
+ *
+ * @author youHong.ai
+ */
+
+@SqlMapper
+public interface UpdateManagerIdMapper {
+}
diff --git a/src/test/java/youhong/ai/pcn/TestOrganization.java b/src/test/java/youhong/ai/pcn/TestOrganization.java
index 5caff6a..a275676 100644
--- a/src/test/java/youhong/ai/pcn/TestOrganization.java
+++ b/src/test/java/youhong/ai/pcn/TestOrganization.java
@@ -5,12 +5,15 @@ import aiyh.utils.httpUtil.ResponeVo;
import aiyh.utils.httpUtil.util.HttpUtils;
import basetest.BaseTest;
import com.alibaba.fastjson.JSON;
+import com.api.youhong.ai.pcn.organization.orgchart.service.OrgChartService;
+import com.api.youhong.ai.pcn.organization.orgchart.vo.OrgChartNodeVo;
import com.fasterxml.jackson.core.JsonProcessingException;
import ebu7common.youhong.ai.bean.Builder;
import ebu7common.youhong.ai.sftp.SftpConnectUtil;
import org.junit.Test;
import weaver.conn.RecordSet;
import weaver.general.GCONST;
+import weaver.hrm.User;
import weaver.xiao.commons.config.entity.MultipartFile;
import weaver.xiao.commons.config.entity.RequestMappingConfig;
import weaver.xiao.commons.config.service.DealWithMapping;
@@ -188,4 +191,13 @@ public class TestOrganization extends BaseTest {
e.printStackTrace();
}
}
+
+
+ @Test
+ public void testOrgChart() {
+ User user = new User(88);
+ OrgChartService orgChartService = new OrgChartService();
+ List orgChartTree = orgChartService.getOrgChartTree(user);
+ System.out.println(JSON.toJSONString(orgChartTree));
+ }
}