From 9f08f99e711d611eed1c15931036f057a15ce704 Mon Sep 17 00:00:00 2001 From: linbangquan <1437892690@qq.com> Date: Thu, 14 Mar 2024 16:13:42 +0800 Subject: [PATCH 1/3] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E7=9F=A9=E9=98=B5?= =?UTF-8?q?=E7=AE=A1=E7=90=86-=E5=A2=9E=E5=8A=A0=E5=87=BA=E5=8E=82?= =?UTF-8?q?=E8=87=AA=E5=B8=A6=E7=9A=84=E7=94=A8=E6=88=B7=E3=80=81=E5=88=86?= =?UTF-8?q?=E7=BB=84=E3=80=81=E8=A7=92=E8=89=B2=E4=B8=89=E4=B8=AA=E7=9F=A9?= =?UTF-8?q?=E9=98=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1021566328995840]矩阵管理-增加出厂自带的用户、分组、角色三个矩阵 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1021566328995840 --- .../framework/dao/mapper/RoleMapper.java | 8 +- .../framework/dao/mapper/RoleMapper.xml | 123 ++++++++++ .../framework/dao/mapper/TeamMapper.java | 5 + .../framework/dao/mapper/TeamMapper.xml | 110 +++++++++ .../framework/dao/mapper/UserMapper.java | 5 + .../framework/dao/mapper/UserMapper.xml | 137 +++++++++++ .../dao/mapper/MatrixViewDataMapper.xml | 6 +- .../RoleMatrixPrivateDataSourceHandler.java | 156 ++++++++++++ .../TeamMatrixPrivateDataSourceHandler.java | 165 +++++++++++++ .../UserMatrixPrivateDataSourceHandler.java | 222 ++++++++++++++++++ 10 files changed, 933 insertions(+), 4 deletions(-) create mode 100644 src/main/java/neatlogic/module/framework/matrix/privatedatasource/handler/RoleMatrixPrivateDataSourceHandler.java create mode 100644 src/main/java/neatlogic/module/framework/matrix/privatedatasource/handler/TeamMatrixPrivateDataSourceHandler.java create mode 100644 src/main/java/neatlogic/module/framework/matrix/privatedatasource/handler/UserMatrixPrivateDataSourceHandler.java diff --git a/src/main/java/neatlogic/framework/dao/mapper/RoleMapper.java b/src/main/java/neatlogic/framework/dao/mapper/RoleMapper.java index 2f624da71..1dcb12a06 100644 --- a/src/main/java/neatlogic/framework/dao/mapper/RoleMapper.java +++ b/src/main/java/neatlogic/framework/dao/mapper/RoleMapper.java @@ -18,6 +18,7 @@ package neatlogic.framework.dao.mapper; import neatlogic.framework.common.dto.ValueTextVo; import neatlogic.framework.dto.*; +import neatlogic.framework.matrix.dto.MatrixDataVo; import org.apache.ibatis.annotations.Param; import java.util.List; @@ -57,6 +58,8 @@ public interface RoleMapper { List getRoleByUuidList(List uuidList); + List getRoleListContainsDeletedByUuidList(List uuidList); + List getRoleByIdList(List idList); List getRoleRuleByUuidList(List uuidList); @@ -99,6 +102,10 @@ public interface RoleMapper { */ List getParentTeamRoleListWithCheckedChildrenByTeam(TeamVo teamVo); + int searchRoleCountForMatrix(MatrixDataVo searchVo); + + List searchRoleListForMatrix(MatrixDataVo searchVo); + int insertRoleAuth(RoleAuthVo roleAuthVo); int insertRole(RoleVo roleVo); @@ -132,5 +139,4 @@ public interface RoleMapper { int deleteTeamRoleByRoleUuidAndTeamUuidList(@Param("roleUuid") String roleUuid, @Param("teamUuidList") List teamUuidList); int deleteTeamRole(RoleTeamVo roleTeamVo); - } diff --git a/src/main/java/neatlogic/framework/dao/mapper/RoleMapper.xml b/src/main/java/neatlogic/framework/dao/mapper/RoleMapper.xml index 0c4f0af14..0c98d9713 100644 --- a/src/main/java/neatlogic/framework/dao/mapper/RoleMapper.xml +++ b/src/main/java/neatlogic/framework/dao/mapper/RoleMapper.xml @@ -178,6 +178,21 @@ limitations under the License. + + + + + AND (`name` LIKE CONCAT('%', #{keyword}, '%') OR `description` LIKE CONCAT('%', #{keyword}, '%')) + + + AND + + + + + + `${filter.uuid}` IN + + #{item} + + + + `${filter.uuid}` = #{filter.valueList[0]} + + + + + + + (`${filter.uuid}` NOT IN + + #{item} + + OR `${filter.uuid}` IS NULL) + + + `${filter.uuid}` != #{filter.valueList[0]} + + + + + + + `${filter.uuid}` IN + + #{item} + + + + `${filter.uuid}` LIKE CONCAT('%', #{filter.valueList[0]}, '%') + + + + + + + (`${filter.uuid}` NOT IN + + #{item} + + OR `${filter.uuid}` IS NULL) + + + (`${filter.uuid}` NOT LIKE CONCAT('%', #{filter.valueList[0]}, '%') OR `${filter.uuid}` IS NULL) + + + + + (`${filter.uuid}` IS NULL OR `${filter.uuid}` = '') + + + (`${filter.uuid}` IS NOT NULL AND `${filter.uuid}` != '') + + + + + `${filter.uuid}` IN + + #{item} + + + + `${filter.uuid}` = #{filter.valueList[0]} + + + + + + + + + + + + INSERT INTO `role` (`id`, `uuid`, `name`, `description`, `rule`, `is_delete`) VALUES (#{id}, #{uuid}, #{name}, #{description}, #{rule}, 0) diff --git a/src/main/java/neatlogic/framework/dao/mapper/TeamMapper.java b/src/main/java/neatlogic/framework/dao/mapper/TeamMapper.java index cc760fe77..a6fb9f196 100644 --- a/src/main/java/neatlogic/framework/dao/mapper/TeamMapper.java +++ b/src/main/java/neatlogic/framework/dao/mapper/TeamMapper.java @@ -3,6 +3,7 @@ package neatlogic.framework.dao.mapper; import neatlogic.framework.dto.TeamUserTitleVo; import neatlogic.framework.dto.TeamUserVo; import neatlogic.framework.dto.TeamVo; +import neatlogic.framework.matrix.dto.MatrixDataVo; import org.apache.ibatis.annotations.Param; import java.util.Date; @@ -75,6 +76,10 @@ public interface TeamMapper { int checkTitleIsReferenceByTitleId(Long id); + int searchTeamCountForMatrix(MatrixDataVo searchVo); + + List searchTeamListForMatrix(MatrixDataVo searchVo); + int insertTeam(TeamVo teamVo); void insertTeamForLdap(TeamVo teamVo); diff --git a/src/main/java/neatlogic/framework/dao/mapper/TeamMapper.xml b/src/main/java/neatlogic/framework/dao/mapper/TeamMapper.xml index 10e72a7b7..f79fa6598 100644 --- a/src/main/java/neatlogic/framework/dao/mapper/TeamMapper.xml +++ b/src/main/java/neatlogic/framework/dao/mapper/TeamMapper.xml @@ -562,6 +562,116 @@ limitations under the License. SELECT `uuid` FROM `team` WHERE `upward_name_path` = #{value} + + + AND (a.`name` LIKE CONCAT('%', #{keyword}, '%') OR a.`description` LIKE CONCAT('%', #{keyword}, '%')) + + + AND + + + + + + ${filter.uuid} IN + + #{item} + + + + ${filter.uuid} = #{filter.valueList[0]} + + + + + + + (${filter.uuid} NOT IN + + #{item} + + OR ${filter.uuid} IS NULL) + + + ${filter.uuid} != #{filter.valueList[0]} + + + + + + + ${filter.uuid} IN + + #{item} + + + + ${filter.uuid} LIKE CONCAT('%', #{filter.valueList[0]}, '%') + + + + + + + (${filter.uuid} NOT IN + + #{item} + + OR ${filter.uuid} IS NULL) + + + (${filter.uuid} NOT LIKE CONCAT('%', #{filter.valueList[0]}, '%') OR ${filter.uuid} IS NULL) + + + + + (${filter.uuid} IS NULL OR ${filter.uuid} = '') + + + (${filter.uuid} IS NOT NULL AND ${filter.uuid} != '') + + + + + ${filter.uuid} IN + + #{item} + + + + ${filter.uuid} = #{filter.valueList[0]} + + + + + + + + + + + + INSERT INTO `team` (`id`, `uuid`, diff --git a/src/main/java/neatlogic/framework/dao/mapper/UserMapper.java b/src/main/java/neatlogic/framework/dao/mapper/UserMapper.java index 1de06a5db..e177cab7f 100644 --- a/src/main/java/neatlogic/framework/dao/mapper/UserMapper.java +++ b/src/main/java/neatlogic/framework/dao/mapper/UserMapper.java @@ -17,6 +17,7 @@ package neatlogic.framework.dao.mapper; import neatlogic.framework.dto.*; +import neatlogic.framework.matrix.dto.MatrixDataVo; import org.apache.ibatis.annotations.Param; import java.util.Date; @@ -186,6 +187,10 @@ public interface UserMapper { List getUserIdByUserIdList(List userIdList); + int searchUserCountForMatrix(MatrixDataVo searchVo); + + List searchUserListForMatrix(MatrixDataVo searchVo); + int insertUserAuth(UserAuthVo userAuthVo); int insertUser(UserVo userVo); diff --git a/src/main/java/neatlogic/framework/dao/mapper/UserMapper.xml b/src/main/java/neatlogic/framework/dao/mapper/UserMapper.xml index 5a317d1cf..726324427 100644 --- a/src/main/java/neatlogic/framework/dao/mapper/UserMapper.xml +++ b/src/main/java/neatlogic/framework/dao/mapper/UserMapper.xml @@ -1180,6 +1180,143 @@ limitations under the License. where is_super_admin = 1 + + + AND (a.`user_id` LIKE CONCAT('%', #{keyword}, '%') OR a.`user_name` LIKE CONCAT('%', #{keyword}, '%')) + + + AND + + + + + + ${filter.uuid} IN + + #{item} + + + + ${filter.uuid} = #{filter.valueList[0]} + + + + + + + (${filter.uuid} NOT IN + + #{item} + + OR ${filter.uuid} IS NULL) + + + ${filter.uuid} != #{filter.valueList[0]} + + + + + + + ${filter.uuid} IN + + #{item} + + + + ${filter.uuid} LIKE CONCAT('%', #{filter.valueList[0]}, '%') + + + + + + + (${filter.uuid} NOT IN + + #{item} + + OR ${filter.uuid} IS NULL) + + + (${filter.uuid} NOT LIKE CONCAT('%', #{filter.valueList[0]}, '%') OR ${filter.uuid} IS NULL) + + + + + (${filter.uuid} IS NULL OR ${filter.uuid} = '') + + + (${filter.uuid} IS NOT NULL AND ${filter.uuid} != '') + + + + + ${filter.uuid} IN + + #{item} + + + + ${filter.uuid} = #{filter.valueList[0]} + + + + + + + + + + SELECT + a.`id`, + a.`uuid`, + a.`user_id`, + a.`user_name`, + a.`email`, + a.`phone`, + a.`vip_level`, + a.`is_active`, + a.`is_delete`, + GROUP_CONCAT(`c`.`name` SEPARATOR ',') AS `teamName` + FROM `user` a + left join `user_team` b on b.`user_uuid` = a.`uuid` + left join `team` c on c.`uuid` = b.`team_uuid` + WHERE a.`is_delete` = 0 + AND a.`is_active` = 1 + group by a.`uuid` + + + + + + REPLACE INTO `user_authority`(`user_uuid`, `auth_group`, diff --git a/src/main/java/neatlogic/framework/matrix/dao/mapper/MatrixViewDataMapper.xml b/src/main/java/neatlogic/framework/matrix/dao/mapper/MatrixViewDataMapper.xml index 493515007..590698cd9 100644 --- a/src/main/java/neatlogic/framework/matrix/dao/mapper/MatrixViewDataMapper.xml +++ b/src/main/java/neatlogic/framework/matrix/dao/mapper/MatrixViewDataMapper.xml @@ -178,15 +178,15 @@ OR `${filter.uuid}` IS NULL) - (`${filter.uuid}` NOT LIKE CONCAT('%', #{filter.valueList[0]}, '%') OR a.`${filter.uuid}` IS NULL) + (`${filter.uuid}` NOT LIKE CONCAT('%', #{filter.valueList[0]}, '%') OR `${filter.uuid}` IS NULL) - `${filter.uuid}` IS NULL + (`${filter.uuid}` IS NULL OR `${filter.uuid}` = '') - `${filter.uuid}` IS NOT NULL + (`${filter.uuid}` IS NOT NULL AND `${filter.uuid}` != '') diff --git a/src/main/java/neatlogic/module/framework/matrix/privatedatasource/handler/RoleMatrixPrivateDataSourceHandler.java b/src/main/java/neatlogic/module/framework/matrix/privatedatasource/handler/RoleMatrixPrivateDataSourceHandler.java new file mode 100644 index 000000000..1f104fdb9 --- /dev/null +++ b/src/main/java/neatlogic/module/framework/matrix/privatedatasource/handler/RoleMatrixPrivateDataSourceHandler.java @@ -0,0 +1,156 @@ +package neatlogic.module.framework.matrix.privatedatasource.handler; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.dao.mapper.RoleMapper; +import neatlogic.framework.dto.RoleVo; +import neatlogic.framework.matrix.constvalue.SearchExpression; +import neatlogic.framework.matrix.core.IMatrixPrivateDataSourceHandler; +import neatlogic.framework.matrix.dto.MatrixAttributeVo; +import neatlogic.framework.matrix.dto.MatrixDataVo; +import neatlogic.framework.matrix.dto.MatrixFilterVo; +import neatlogic.framework.util.UuidUtil; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.*; + +@Component +public class RoleMatrixPrivateDataSourceHandler implements IMatrixPrivateDataSourceHandler { + + private final List matrixAttributeList = new ArrayList<>(); + + private final Map columnsMap = new HashMap<>(); + + { + JSONArray attributeDefinedList = new JSONArray(); + { + JSONObject jsonObj = new JSONObject(); + jsonObj.put("name", "UUID"); + jsonObj.put("label", "uuid"); + jsonObj.put("isPrimaryKey", 1); + jsonObj.put("isSearchable", 0); + attributeDefinedList.add(jsonObj); + } + { + JSONObject jsonObj = new JSONObject(); + jsonObj.put("name", "ID"); + jsonObj.put("label", "id"); + jsonObj.put("isPrimaryKey", 0); + jsonObj.put("isSearchable", 0); + attributeDefinedList.add(jsonObj); + } + { + JSONObject jsonObj = new JSONObject(); + jsonObj.put("name", "名称"); + jsonObj.put("label", "name"); + jsonObj.put("isPrimaryKey", 0); + jsonObj.put("isSearchable", 1); + attributeDefinedList.add(jsonObj); + } + { + JSONObject jsonObj = new JSONObject(); + jsonObj.put("name", "描述"); + jsonObj.put("label", "description"); + jsonObj.put("isPrimaryKey", 0); + jsonObj.put("isSearchable", 1); + attributeDefinedList.add(jsonObj); + } + this.setAttribute(matrixAttributeList , attributeDefinedList); + for(MatrixAttributeVo matrixAttributeVo : matrixAttributeList){ + columnsMap.put(matrixAttributeVo.getLabel() , matrixAttributeVo.getUuid()); + } + } + + @Resource + private RoleMapper roleMapper; + + @Override + public String getUuid() { + return UuidUtil.getCustomUUID(getLabel()); + } + + @Override + public String getName() { + return "角色"; + } + + @Override + public String getLabel() { + return "role"; + } + + @Override + public List getAttributeList() { + return matrixAttributeList; + } + + @Override + public List> searchTableData(MatrixDataVo dataVo) { + List roleList = new ArrayList<>(); + JSONArray defaultValue = dataVo.getDefaultValue(); + if (CollectionUtils.isNotEmpty(defaultValue)) { + List uuidList = defaultValue.toJavaList(String.class); + roleList = roleMapper.getRoleListContainsDeletedByUuidList(uuidList); + } else { + MatrixDataVo searchVo = matrixDataVoConvertSearchCondition(dataVo); + int rowNum = roleMapper.searchRoleCountForMatrix(searchVo); + if (rowNum > 0) { + searchVo.setRowNum(rowNum); + roleList = roleMapper.searchRoleListForMatrix(searchVo); + } + } + return roleListConvertDataList(roleList); + } + + private MatrixDataVo matrixDataVoConvertSearchCondition(MatrixDataVo dataVo) { + List filterList = dataVo.getFilterList(); + if (CollectionUtils.isEmpty(filterList)) { + return dataVo; + } + List newFilterList = new ArrayList<>(); + for (MatrixFilterVo filter : filterList) { + String uuid = filter.getUuid(); + if (StringUtils.isBlank(uuid)) { + continue; + } + if (!Objects.equals(filter.getExpression(), SearchExpression.NULL.getExpression()) && !Objects.equals(filter.getExpression(), SearchExpression.NOTNULL.getExpression())) { + List valueList = filter.getValueList(); + if (CollectionUtils.isEmpty(valueList)) { + continue; + } + String value = valueList.get(0); + if (StringUtils.isBlank(value)) { + continue; + } + } + if (columnsMap.get("uuid").equals(uuid)) { + newFilterList.add(new MatrixFilterVo("uuid", filter.getExpression(), filter.getValueList())); + } else if (columnsMap.get("id").equals(uuid)) { + newFilterList.add(new MatrixFilterVo("id", filter.getExpression(), filter.getValueList())); + } else if (columnsMap.get("name").equals(uuid)) { + newFilterList.add(new MatrixFilterVo("name", filter.getExpression(), filter.getValueList())); + } else if (columnsMap.get("description").equals(uuid)) { + newFilterList.add(new MatrixFilterVo("description", filter.getExpression(), filter.getValueList())); + } + } + dataVo.setFilterList(newFilterList); + return dataVo; + } + + private List> roleListConvertDataList(List roleList) { + List> dataList = new ArrayList<>(); + for (RoleVo roleVo : roleList) { + Map data = new HashMap<>(); + data.put("uuid", roleVo.getUuid()); + data.put(columnsMap.get("uuid"), roleVo.getUuid()); + data.put(columnsMap.get("name"), roleVo.getName()); + data.put(columnsMap.get("id"), roleVo.getId().toString()); + data.put(columnsMap.get("description"), roleVo.getDescription()); + dataList.add(data); + } + return dataList; + } +} diff --git a/src/main/java/neatlogic/module/framework/matrix/privatedatasource/handler/TeamMatrixPrivateDataSourceHandler.java b/src/main/java/neatlogic/module/framework/matrix/privatedatasource/handler/TeamMatrixPrivateDataSourceHandler.java new file mode 100644 index 000000000..0395ef5e3 --- /dev/null +++ b/src/main/java/neatlogic/module/framework/matrix/privatedatasource/handler/TeamMatrixPrivateDataSourceHandler.java @@ -0,0 +1,165 @@ +package neatlogic.module.framework.matrix.privatedatasource.handler; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.dao.mapper.TeamMapper; +import neatlogic.framework.dto.TeamVo; +import neatlogic.framework.matrix.constvalue.SearchExpression; +import neatlogic.framework.matrix.core.IMatrixPrivateDataSourceHandler; +import neatlogic.framework.matrix.dto.MatrixAttributeVo; +import neatlogic.framework.matrix.dto.MatrixDataVo; +import neatlogic.framework.matrix.dto.MatrixFilterVo; +import neatlogic.framework.util.UuidUtil; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.*; +import java.util.stream.Collectors; + +@Component +public class TeamMatrixPrivateDataSourceHandler implements IMatrixPrivateDataSourceHandler { + + private final List matrixAttributeList = new ArrayList<>(); + + private final Map columnsMap = new HashMap<>(); + + { + JSONArray attributeDefinedList = new JSONArray(); + { + JSONObject jsonObj = new JSONObject(); + jsonObj.put("name", "UUID"); + jsonObj.put("label", "uuid"); + jsonObj.put("isPrimaryKey", 1); + jsonObj.put("isSearchable", 0); + attributeDefinedList.add(jsonObj); + } + { + JSONObject jsonObj = new JSONObject(); + jsonObj.put("name", "ID"); + jsonObj.put("label", "id"); + jsonObj.put("isPrimaryKey", 0); + jsonObj.put("isSearchable", 0); + attributeDefinedList.add(jsonObj); + } + { + JSONObject jsonObj = new JSONObject(); + jsonObj.put("name", "名称"); + jsonObj.put("label", "name"); + jsonObj.put("isPrimaryKey", 0); + jsonObj.put("isSearchable", 1); + attributeDefinedList.add(jsonObj); + } + { + JSONObject jsonObj = new JSONObject(); + jsonObj.put("name", "父级名称"); + jsonObj.put("label", "parentName"); + jsonObj.put("isPrimaryKey", 0); + jsonObj.put("isSearchable", 1); + attributeDefinedList.add(jsonObj); + } + this.setAttribute(matrixAttributeList , attributeDefinedList); + for(MatrixAttributeVo matrixAttributeVo : matrixAttributeList){ + columnsMap.put(matrixAttributeVo.getLabel() , matrixAttributeVo.getUuid()); + } + } + + @Resource + private TeamMapper teamMapper; + + @Override + public String getUuid() { + return UuidUtil.getCustomUUID(getLabel()); + } + + @Override + public String getName() { + return "分组"; + } + + @Override + public String getLabel() { + return "team"; + } + + @Override + public List getAttributeList() { + return matrixAttributeList; + } + + @Override + public List> searchTableData(MatrixDataVo dataVo) { + List teamList = new ArrayList<>(); + JSONArray defaultValue = dataVo.getDefaultValue(); + if (CollectionUtils.isNotEmpty(defaultValue)) { + List uuidList = defaultValue.toJavaList(String.class); + teamList = teamMapper.getTeamListContainsDeletedByUuidList(uuidList); + } else { + MatrixDataVo searchVo = matrixDataVoConvertSearchCondition(dataVo); + int rowNum = teamMapper.searchTeamCountForMatrix(searchVo); + if (rowNum > 0) { + searchVo.setRowNum(rowNum); + teamList = teamMapper.searchTeamListForMatrix(searchVo); + } + } + if (CollectionUtils.isNotEmpty(teamList)) { + List parentUuidList = teamList.stream().map(TeamVo::getParentUuid).collect(Collectors.toList()); + List parentList = teamMapper.getTeamListContainsDeletedByUuidList(parentUuidList); + Map map = parentList.stream().collect(Collectors.toMap(TeamVo::getUuid, TeamVo::getName)); + for (TeamVo teamVo : teamList) { + teamVo.setParentName(map.get(teamVo.getParentUuid())); + } + } + return teamListConvertDataList(teamList); + } + + private MatrixDataVo matrixDataVoConvertSearchCondition(MatrixDataVo dataVo) { + List filterList = dataVo.getFilterList(); + if (CollectionUtils.isEmpty(filterList)) { + return dataVo; + } + List newFilterList = new ArrayList<>(); + for (MatrixFilterVo filter : filterList) { + String uuid = filter.getUuid(); + if (StringUtils.isBlank(uuid)) { + continue; + } + if (!Objects.equals(filter.getExpression(), SearchExpression.NULL.getExpression()) && !Objects.equals(filter.getExpression(), SearchExpression.NOTNULL.getExpression())) { + List valueList = filter.getValueList(); + if (CollectionUtils.isEmpty(valueList)) { + continue; + } + String value = valueList.get(0); + if (StringUtils.isBlank(value)) { + continue; + } + } + if (columnsMap.get("uuid").equals(uuid)) { + newFilterList.add(new MatrixFilterVo("a.`uuid`", filter.getExpression(), filter.getValueList())); + } else if (columnsMap.get("id").equals(uuid)) { + newFilterList.add(new MatrixFilterVo("a.`id`", filter.getExpression(), filter.getValueList())); + } else if (columnsMap.get("name").equals(uuid)) { + newFilterList.add(new MatrixFilterVo("a.`name`", filter.getExpression(), filter.getValueList())); + } else if (columnsMap.get("parentName").equals(uuid)) { + newFilterList.add(new MatrixFilterVo("b.`name`", filter.getExpression(), filter.getValueList())); + } + } + dataVo.setFilterList(newFilterList); + return dataVo; + } + + private List> teamListConvertDataList(List teamList) { + List> dataList = new ArrayList<>(); + for (TeamVo teamVo : teamList) { + Map data = new HashMap<>(); + data.put("uuid", teamVo.getUuid()); + data.put(columnsMap.get("uuid"), teamVo.getUuid()); + data.put(columnsMap.get("id"), teamVo.getId().toString()); + data.put(columnsMap.get("name"), teamVo.getName()); + data.put(columnsMap.get("parentName"), teamVo.getParentName()); + dataList.add(data); + } + return dataList; + } +} diff --git a/src/main/java/neatlogic/module/framework/matrix/privatedatasource/handler/UserMatrixPrivateDataSourceHandler.java b/src/main/java/neatlogic/module/framework/matrix/privatedatasource/handler/UserMatrixPrivateDataSourceHandler.java new file mode 100644 index 000000000..a07ffcc3f --- /dev/null +++ b/src/main/java/neatlogic/module/framework/matrix/privatedatasource/handler/UserMatrixPrivateDataSourceHandler.java @@ -0,0 +1,222 @@ +package neatlogic.module.framework.matrix.privatedatasource.handler; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.dao.mapper.TeamMapper; +import neatlogic.framework.dao.mapper.UserMapper; +import neatlogic.framework.dto.TeamVo; +import neatlogic.framework.dto.UserVo; +import neatlogic.framework.matrix.constvalue.SearchExpression; +import neatlogic.framework.matrix.core.IMatrixPrivateDataSourceHandler; +import neatlogic.framework.matrix.dto.MatrixAttributeVo; +import neatlogic.framework.matrix.dto.MatrixDataVo; +import neatlogic.framework.matrix.dto.MatrixFilterVo; +import neatlogic.framework.util.UuidUtil; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.*; +import java.util.stream.Collectors; + +@Component +public class UserMatrixPrivateDataSourceHandler implements IMatrixPrivateDataSourceHandler { + + private final List matrixAttributeList = new ArrayList<>(); + + private final Map columnsMap = new HashMap<>(); + + { + JSONArray attributeDefinedList = new JSONArray(); + { + JSONObject jsonObj = new JSONObject(); + jsonObj.put("name", "UUID"); + jsonObj.put("label", "uuid"); + jsonObj.put("isPrimaryKey", 1); + jsonObj.put("isSearchable", 0); + attributeDefinedList.add(jsonObj); + } + { + JSONObject jsonObj = new JSONObject(); + jsonObj.put("name", "ID"); + jsonObj.put("label", "id"); + jsonObj.put("isPrimaryKey", 0); + jsonObj.put("isSearchable", 0); + attributeDefinedList.add(jsonObj); + } + { + JSONObject jsonObj = new JSONObject(); + jsonObj.put("name", "用户ID"); + jsonObj.put("label", "userId"); + jsonObj.put("isPrimaryKey", 0); + jsonObj.put("isSearchable", 1); + attributeDefinedList.add(jsonObj); + } + { + JSONObject jsonObj = new JSONObject(); + jsonObj.put("name", "名称"); + jsonObj.put("label", "userName"); + jsonObj.put("isPrimaryKey", 0); + jsonObj.put("isSearchable", 1); + attributeDefinedList.add(jsonObj); + } + { + JSONObject jsonObj = new JSONObject(); + jsonObj.put("name", "是否vip"); + jsonObj.put("label", "vipLevel"); + jsonObj.put("isPrimaryKey", 0); + jsonObj.put("isSearchable", 1); + attributeDefinedList.add(jsonObj); + } + { + JSONObject jsonObj = new JSONObject(); + jsonObj.put("name", "邮箱"); + jsonObj.put("label", "email"); + jsonObj.put("isPrimaryKey", 0); + jsonObj.put("isSearchable", 1); + attributeDefinedList.add(jsonObj); + } + { + JSONObject jsonObj = new JSONObject(); + jsonObj.put("name", "电话"); + jsonObj.put("label", "phone"); + jsonObj.put("isPrimaryKey", 0); + jsonObj.put("isSearchable", 1); + attributeDefinedList.add(jsonObj); + } + { + JSONObject jsonObj = new JSONObject(); + jsonObj.put("name", "所属组"); + jsonObj.put("label", "teamNameList"); + jsonObj.put("isPrimaryKey", 0); + jsonObj.put("isSearchable", 1); + attributeDefinedList.add(jsonObj); + } + this.setAttribute(matrixAttributeList , attributeDefinedList); + for(MatrixAttributeVo matrixAttributeVo : matrixAttributeList){ + columnsMap.put(matrixAttributeVo.getLabel() , matrixAttributeVo.getUuid()); + } + } + + @Resource + private UserMapper userMapper; + + @Resource + private TeamMapper teamMapper; + + @Override + public String getUuid() { + return UuidUtil.getCustomUUID(getLabel()); + } + + @Override + public String getName() { + return "用户"; + } + + @Override + public String getLabel() { + return "user"; + } + + @Override + public List getAttributeList() { + return matrixAttributeList; + } + + @Override + public List> searchTableData(MatrixDataVo dataVo) { + List userList = new ArrayList<>(); + JSONArray defaultValue = dataVo.getDefaultValue(); + if (CollectionUtils.isNotEmpty(defaultValue)) { + List uuidList = defaultValue.toJavaList(String.class); + userList = userMapper.getUserListByUuidList(uuidList); + } else { + MatrixDataVo searchVo = matrixDataVoConvertSearchCondition(dataVo); + int rowNum = userMapper.searchUserCountForMatrix(searchVo); + if (rowNum > 0) { + searchVo.setRowNum(rowNum); + userList = userMapper.searchUserListForMatrix(searchVo); + } + } + if (CollectionUtils.isNotEmpty(userList)) { + for (UserVo userVo : userList) { + List teamList = teamMapper.getTeamListByUserUuid(userVo.getUuid()); + List teamNameList = teamList.stream().map(TeamVo::getName).collect(Collectors.toList()); + userVo.setTeamNameList(teamNameList); + } + } + return userListConvertDataList(userList); + } + + private MatrixDataVo matrixDataVoConvertSearchCondition(MatrixDataVo dataVo) { + List filterList = dataVo.getFilterList(); + if (CollectionUtils.isEmpty(filterList)) { + return dataVo; + } + List newFilterList = new ArrayList<>(); + for (MatrixFilterVo filter : filterList) { + String uuid = filter.getUuid(); + if (StringUtils.isBlank(uuid)) { + continue; + } + if (!Objects.equals(filter.getExpression(), SearchExpression.NULL.getExpression()) && !Objects.equals(filter.getExpression(), SearchExpression.NOTNULL.getExpression())) { + List valueList = filter.getValueList(); + if (CollectionUtils.isEmpty(valueList)) { + continue; + } + String value = valueList.get(0); + if (StringUtils.isBlank(value)) { + continue; + } + } + if (columnsMap.get("uuid").equals(uuid)) { + newFilterList.add(new MatrixFilterVo("a.`uuid`", filter.getExpression(), filter.getValueList())); + } else if (columnsMap.get("id").equals(uuid)) { + newFilterList.add(new MatrixFilterVo("a.`id`", filter.getExpression(), filter.getValueList())); + } else if (columnsMap.get("userId").equals(uuid)) { + newFilterList.add(new MatrixFilterVo("a.`user_id`", filter.getExpression(), filter.getValueList())); + } else if (columnsMap.get("userName").equals(uuid)) { + newFilterList.add(new MatrixFilterVo("a.`user_name`", filter.getExpression(), filter.getValueList())); + } else if (columnsMap.get("vipLevel").equals(uuid)) { + List valueList = new ArrayList<>(); + if (CollectionUtils.isNotEmpty(filter.getValueList())) { + String value = filter.getValueList().get(0); + if (Objects.equals(value, "是")) { + valueList.add("1"); + } else if (Objects.equals(value, "否")) { + valueList.add("0"); + } + } + newFilterList.add(new MatrixFilterVo("a.`vip_level`", filter.getExpression(), valueList)); + } else if (columnsMap.get("email").equals(uuid)) { + newFilterList.add(new MatrixFilterVo("a.`email`", filter.getExpression(), filter.getValueList())); + } else if (columnsMap.get("phone").equals(uuid)) { + newFilterList.add(new MatrixFilterVo("a.`phone`", filter.getExpression(), filter.getValueList())); + } else if (columnsMap.get("teamNameList").equals(uuid)) { + newFilterList.add(new MatrixFilterVo("a.`team_name`", filter.getExpression(), filter.getValueList())); + } + } + dataVo.setFilterList(newFilterList); + return dataVo; + } + + private List> userListConvertDataList(List userList) { + List> dataList = new ArrayList<>(); + for (UserVo userVo : userList) { + Map data = new HashMap<>(); + data.put("uuid", userVo.getUuid()); + data.put(columnsMap.get("uuid"), userVo.getUuid()); + data.put(columnsMap.get("id"), userVo.getId().toString()); + data.put(columnsMap.get("userId"), userVo.getUserId()); + data.put(columnsMap.get("userName"), userVo.getUserName()); + data.put(columnsMap.get("teamNameList"), String.join(",", userVo.getTeamNameList())); + data.put(columnsMap.get("vipLevel"), Objects.equals(userVo.getVipLevel(), 1) ? "是" : "否"); + data.put(columnsMap.get("email"), userVo.getEmail() == null ? "" : userVo.getEmail()); + data.put(columnsMap.get("phone"), userVo.getPhone() == null ? "" : userVo.getPhone()); + dataList.add(data); + } + return dataList; + } +} -- Gitee From 0865bedbe2e8ec2e627456c5235754292ce8d60e Mon Sep 17 00:00:00 2001 From: linbangquan <1437892690@qq.com> Date: Thu, 14 Mar 2024 16:19:00 +0800 Subject: [PATCH 2/3] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E7=9F=A9=E9=98=B5?= =?UTF-8?q?=E7=AE=A1=E7=90=86-=E5=A2=9E=E5=8A=A0=E5=87=BA=E5=8E=82?= =?UTF-8?q?=E8=87=AA=E5=B8=A6=E7=9A=84=E7=94=A8=E6=88=B7=E3=80=81=E5=88=86?= =?UTF-8?q?=E7=BB=84=E3=80=81=E8=A7=92=E8=89=B2=E4=B8=89=E4=B8=AA=E7=9F=A9?= =?UTF-8?q?=E9=98=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1021566328995840]矩阵管理-增加出厂自带的用户、分组、角色三个矩阵 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1021566328995840 --- .../handler/UserMatrixPrivateDataSourceHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/neatlogic/module/framework/matrix/privatedatasource/handler/UserMatrixPrivateDataSourceHandler.java b/src/main/java/neatlogic/module/framework/matrix/privatedatasource/handler/UserMatrixPrivateDataSourceHandler.java index a07ffcc3f..49676c1cb 100644 --- a/src/main/java/neatlogic/module/framework/matrix/privatedatasource/handler/UserMatrixPrivateDataSourceHandler.java +++ b/src/main/java/neatlogic/module/framework/matrix/privatedatasource/handler/UserMatrixPrivateDataSourceHandler.java @@ -131,7 +131,7 @@ public class UserMatrixPrivateDataSourceHandler implements IMatrixPrivateDataSou JSONArray defaultValue = dataVo.getDefaultValue(); if (CollectionUtils.isNotEmpty(defaultValue)) { List uuidList = defaultValue.toJavaList(String.class); - userList = userMapper.getUserListByUuidList(uuidList); + userList = userMapper.getUserByUserUuidList(uuidList); } else { MatrixDataVo searchVo = matrixDataVoConvertSearchCondition(dataVo); int rowNum = userMapper.searchUserCountForMatrix(searchVo); -- Gitee From 8abd51a56698699d9e0cca7ec2ed7fd2223982c8 Mon Sep 17 00:00:00 2001 From: linbangquan <1437892690@qq.com> Date: Thu, 14 Mar 2024 17:33:18 +0800 Subject: [PATCH 3/3] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E7=9F=A9=E9=98=B5?= =?UTF-8?q?=E7=AE=A1=E7=90=86-=E5=A2=9E=E5=8A=A0=E5=87=BA=E5=8E=82?= =?UTF-8?q?=E8=87=AA=E5=B8=A6=E7=9A=84=E7=94=A8=E6=88=B7=E3=80=81=E5=88=86?= =?UTF-8?q?=E7=BB=84=E3=80=81=E8=A7=92=E8=89=B2=E4=B8=89=E4=B8=AA=E7=9F=A9?= =?UTF-8?q?=E9=98=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1021566328995840]矩阵管理-增加出厂自带的用户、分组、角色三个矩阵 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1021566328995840 --- src/main/java/neatlogic/framework/dao/mapper/UserMapper.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/neatlogic/framework/dao/mapper/UserMapper.xml b/src/main/java/neatlogic/framework/dao/mapper/UserMapper.xml index 726324427..33e9cd359 100644 --- a/src/main/java/neatlogic/framework/dao/mapper/UserMapper.xml +++ b/src/main/java/neatlogic/framework/dao/mapper/UserMapper.xml @@ -1277,7 +1277,7 @@ limitations under the License. a.`vip_level`, a.`is_active`, a.`is_delete`, - GROUP_CONCAT(`c`.`name` SEPARATOR ',') AS `teamName` + GROUP_CONCAT(`c`.`name` SEPARATOR ',') AS `team_name` FROM `user` a left join `user_team` b on b.`user_uuid` = a.`uuid` left join `team` c on c.`uuid` = b.`team_uuid` -- Gitee