From 26c7992abd62b73840ff073b450d5672f6ade712 Mon Sep 17 00:00:00 2001 From: "youHong.ai" <774495953@qq.com> Date: Mon, 5 Dec 2022 15:09:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=9F=A5=E8=AF=A2=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E6=98=A0=E5=B0=84boolean=E7=B1=BB=E5=9E=8B=EF=BC=8C?= =?UTF-8?q?=E4=BF=9D=E6=97=B6=E6=8D=B7=E4=BA=BA=E5=91=98=E7=BB=84=E7=BB=87?= =?UTF-8?q?=E6=9E=B6=E6=9E=84=E5=9B=BE=E9=BB=98=E8=AE=A4=E5=85=A8=E9=83=A8?= =?UTF-8?q?=E5=B1=95=E5=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../utils/recordset/BooleanTypeHandler.java | 49 ++++++++++++++++++- .../orgchart/mapper/OrgChartMapper.java | 33 +++++++++++-- .../orgchart/pojo/ShowPointOrAll.java | 34 +++++++++++++ .../orgchart/service/OrgChartService.java | 42 +++++++++++++--- 4 files changed, 145 insertions(+), 13 deletions(-) create mode 100644 src/main/java/com/api/youhong/ai/pcn/organization/orgchart/pojo/ShowPointOrAll.java diff --git a/src/main/java/aiyh/utils/recordset/BooleanTypeHandler.java b/src/main/java/aiyh/utils/recordset/BooleanTypeHandler.java index dfc688a..5c018f3 100644 --- a/src/main/java/aiyh/utils/recordset/BooleanTypeHandler.java +++ b/src/main/java/aiyh/utils/recordset/BooleanTypeHandler.java @@ -1,5 +1,10 @@ package aiyh.utils.recordset; +import aiyh.utils.annotation.BooleanConverter; +import aiyh.utils.annotation.BooleanConverterEnum; +import aiyh.utils.excention.CustomerException; +import com.google.common.base.Strings; +import org.jetbrains.annotations.NotNull; import weaver.conn.RecordSet; import java.lang.reflect.Field; @@ -13,11 +18,51 @@ import java.lang.reflect.Field; public class BooleanTypeHandler implements TypeHandler{ @Override public Object getValue(RecordSet rs, String fieldName, Field declaredField) { - return rs.getBoolean(fieldName); + return getBoolean(declaredField, rs.getString(fieldName)); } @Override public Object getValue(RecordSet rs, int index,Field declaredField) { - return rs.getBoolean(index); + return getBoolean(declaredField, rs.getString(index)); + } + + @NotNull + private Object getBoolean(Field declaredField, String fieldValue) { + try { + BooleanConverter annotation = declaredField.getAnnotation(BooleanConverter.class); + BooleanConverterEnum value = annotation.value(); + String trueStr = annotation.trueStr(); + String falseStr = annotation.falseStr(); + String trueInteger = annotation.trueInteger(); + String falseInteger = annotation.falseInteger(); + boolean defaultValue = annotation.defaultValue(); + String booleanVal = null; + try { + booleanVal = fieldValue; + } catch (Exception ignored) { + } + boolean hasValueTrue = annotation.hasValueTrue(); + if (value == BooleanConverterEnum.STRING) { + if (booleanVal == null || booleanVal.equals(falseStr)) { + return false; + } else if ((hasValueTrue && !Strings.isNullOrEmpty(booleanVal)) || booleanVal.equals(trueStr)) { + return true; + } else { + return defaultValue; + } + } else if (value == BooleanConverterEnum.INTEGER) { + if (booleanVal == null || booleanVal.equals(falseInteger)) { + return false; + } else if ((hasValueTrue && !Strings.isNullOrEmpty(booleanVal)) || booleanVal.equals(trueInteger)) { + return true; + } else { + return defaultValue; + } + }else { + return defaultValue; + } + } catch (Exception e) { + throw new CustomerException("不支持的类型转换!"); + } } } 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 ecd7da2..f5f9551 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 @@ -4,6 +4,7 @@ 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; +import com.api.youhong.ai.pcn.organization.orgchart.pojo.ShowPointOrAll; import java.util.List; @@ -19,9 +20,19 @@ import java.util.List; public interface OrgChartMapper { + /** + *

查询所有的在职状态人员

+ * 2022/12/5 11:05 + * ****************************************** + * + * @param typeOfEmploymentField 人员自定义字段 + * @return List 返回的人员信息 + * @author youHong.ai + * ****************************************** + */ @Select("select hrm.id, " + " hrm.messagerurl avatar," + - " hrm.lastname last_name, " + + " cus.$t{lastNameEnField} last_name, " + " hrm.managerstr manager_str, " + " hrm.jobtitle job_title_id, " + " hrm.managerid manager_id, " + @@ -33,9 +44,25 @@ public interface OrgChartMapper { " 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) " + + " and cus.SCOPEID = -1 " + " inner join hrmdepartment dept on dept.id = hrm.DEPARTMENTID " + "where hrm.status in (0, 1)") - List selectAll(@ParamMapper("typeOfEmploymentFiled") String typeOfEmploymentField); + List selectAll(@ParamMapper("typeOfEmploymentFiled") String typeOfEmploymentField, + @ParamMapper("lastNameEnField") String lastNameEnField); + + + /** + *

查询当前人员配置信息,是否全部展开,是否显示小红点点

+ * 2022/12/5 11:51 + * ****************************************** + * + * @param userId 当前用户id + * @return ShowPointOrAll 展示与否的人员信息 + * @author youHong.ai + * ****************************************** + */ + @Select("select id,resources,show_all,show_type from uf_show_point_or_all " + + "where concat(',',resources,',') like concat('%,',#{userId},',%')") + ShowPointOrAll selectShowPointOrAll(@ParamMapper("userId") int userId); } diff --git a/src/main/java/com/api/youhong/ai/pcn/organization/orgchart/pojo/ShowPointOrAll.java b/src/main/java/com/api/youhong/ai/pcn/organization/orgchart/pojo/ShowPointOrAll.java new file mode 100644 index 0000000..0ee0dcd --- /dev/null +++ b/src/main/java/com/api/youhong/ai/pcn/organization/orgchart/pojo/ShowPointOrAll.java @@ -0,0 +1,34 @@ +package com.api.youhong.ai.pcn.organization.orgchart.pojo; + +import aiyh.utils.annotation.BooleanConverter; +import aiyh.utils.annotation.BooleanConverterEnum; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +/** + *

全部展开或展示不同人员的点

+ * + *

create: 2022-12-05 10:51

+ * + * @author youHong.ai + */ + +@Getter +@Setter +@ToString +public class ShowPointOrAll { + /** id */ + private Integer id; + + /** 多人力资源的人员id */ + private String resources; + + /** 是否全部展开 */ + @BooleanConverter(BooleanConverterEnum.INTEGER) + private boolean showAll; + + /** 是否显示不同的人员标识 */ + @BooleanConverter(BooleanConverterEnum.INTEGER) + private boolean showType; +} 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 c122d01..e2745d6 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 @@ -6,6 +6,7 @@ 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.pojo.ShowPointOrAll; import com.api.youhong.ai.pcn.organization.orgchart.vo.OrgChartNodeVo; import ebu7common.youhong.ai.bean.Builder; import weaver.hrm.User; @@ -41,7 +42,9 @@ public class OrgChartService { int userId = logInUser.getUID(); String typeOfEmploymentField = Util.getCusConfigValue("typeOfEmploymentField"); Assert.notBlank(typeOfEmploymentField, "config [typeOfEmploymentField] is null or blank!"); - List hrmResourceList = mapper.selectAll(typeOfEmploymentField); + String lastNameEnField = Util.getCusConfigValue("lastNameEnField"); + Assert.notBlank(lastNameEnField, "config [lastNameEnField] is null or blank!"); + List hrmResourceList = mapper.selectAll(typeOfEmploymentField, lastNameEnField); //List hrmResourceDtoList = new ArrayList(); AtomicReference currentUser = new AtomicReference<>(); /* ******************* 将pojo转换为Dto对象,对节点属性默认值赋值,找出当前用户并设置显示 ******************* */ @@ -82,17 +85,40 @@ public class OrgChartService { .with(HrmResourceDto::setCurrentParent, true) .endSet()); - /* ******************* 转换dto为Vo并且设置根节点标识 ******************* */ - List orgChartNodeVoList = hrmResourceDtoList.stream() - .map(struct::hrmResourceDtoToVo) - .collect(Collectors.toList()); + /* ******************* 查询当前用户的是否全部展示或显示小红点的配置信息 ******************* */ + ShowPointOrAll showPointOrAll = mapper.selectShowPointOrAll(userId); + List orgChartNodeVoList = null; + if (Objects.isNull(showPointOrAll)) { + /* ******************* 转换dto为Vo并且设置根节点标识 ******************* */ + orgChartNodeVoList = hrmResourceDtoList.stream() + .map(struct::hrmResourceDtoToVo) + .collect(Collectors.toList()); + } else { + /* ******************* 转换dto为Vo并且设置根节点标识 ******************* */ + orgChartNodeVoList = hrmResourceDtoList.stream() + .map(struct::hrmResourceDtoToVo) + .peek(item -> { + if (showPointOrAll.isShowAll()) { + Builder.startSet(item) + .with(OrgChartNodeVo::setShow, 1) + .with(OrgChartNodeVo::setShowBrother, 1) + .with(OrgChartNodeVo::setShowChildren, 1) + .endSet(); + } + if (!showPointOrAll.isShowType()) { + item.setType(-1); + } + }) + .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)) + .peek(item -> recursionChildrenNums(item, 0)) .collect(Collectors.toList()); } @@ -109,13 +135,13 @@ public class OrgChartService { */ private Integer recursionChildrenNums(OrgChartNodeVo chartNodeVo, int n) { List children = chartNodeVo.getChildren(); - if(Objects.isNull(children)|| children.size() == 0){ + if (Objects.isNull(children) || children.size() == 0) { chartNodeVo.setChildrenNum(0); return 0; } n += children.size(); for (OrgChartNodeVo child : children) { - child.setChildrenNum(recursionChildrenNums(child,0)); + child.setChildrenNum(recursionChildrenNums(child, 0)); n += child.getChildrenNum(); } chartNodeVo.setChildrenNum(n);