From 3ef6e5c8f2f04484f34ff8e2ae1f8d63a3c541dd Mon Sep 17 00:00:00 2001
From: "1437892690@qq.com" <1437892690@qq.com>
Date: Mon, 31 Mar 2025 18:34:52 +0800
Subject: [PATCH] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E5=90=8E=E7=AB=AF-?=
=?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E7=9F=A9=E9=98=B5-=E6=97=A5?=
=?UTF-8?q?=E6=9C=9F=E7=BB=84=E4=BB=B6=E5=A2=9E=E5=8A=A0=E6=98=BE=E7=A4=BA?=
=?UTF-8?q?=E9=85=8D=E7=BD=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
关联 #[1389227483299840]后端-自定义矩阵-日期组件增加显示配置 http://192.168.0.96:8090/demo/rdm.html#/task-detail/939050947543040/939050947543050/1389227483299840
---
.../filter/JsonWebTokenValidFilter.java | 14 ++--
.../core/IntegrationHandlerBase.java | 4 +-
.../dao/mapper/MatrixAttributeMapper.java | 2 +
.../dao/mapper/MatrixAttributeMapper.xml | 24 ++++--
.../framework/matrix/dto/MatrixColumnVo.java | 16 ++--
.../handler/MatrixDataAttrTypeHandler.java | 24 +++++-
.../handler/CustomDataSourceHandler.java | 75 ++++++++++++++++---
7 files changed, 129 insertions(+), 30 deletions(-)
diff --git a/src/main/java/neatlogic/framework/filter/JsonWebTokenValidFilter.java b/src/main/java/neatlogic/framework/filter/JsonWebTokenValidFilter.java
index 2cb3e8248..3fce30d34 100644
--- a/src/main/java/neatlogic/framework/filter/JsonWebTokenValidFilter.java
+++ b/src/main/java/neatlogic/framework/filter/JsonWebTokenValidFilter.java
@@ -34,6 +34,7 @@ import neatlogic.framework.exception.core.ApiRuntimeException;
import neatlogic.framework.filter.core.ILoginAuthHandler;
import neatlogic.framework.filter.core.LoginAuthFactory;
import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.web.filter.OncePerRequestFilter;
import javax.annotation.Resource;
@@ -152,7 +153,7 @@ public class JsonWebTokenValidFilter extends OncePerRequestFilter {
logger.error(ex.getMessage(), ex);
try {
// 不返回跳转地址,直接到显示错误信息页面
- returnErrorResponseJson(false,ResponseCode.API_RUNTIME, response, loginAuth != null ? loginAuth : defaultLoginAuth, ex.getMessage());
+ returnErrorResponseJson(false,ResponseCode.API_RUNTIME, response, loginAuth != null ? loginAuth : defaultLoginAuth, ex, ex.getMessage());
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw new ApiRuntimeException(e);
@@ -160,7 +161,7 @@ public class JsonWebTokenValidFilter extends OncePerRequestFilter {
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
try {
- returnErrorResponseJson(false,ResponseCode.EXCEPTION, response, loginAuth != null ? loginAuth : defaultLoginAuth, ex.getClass().getName()+":"+ex.getMessage());
+ returnErrorResponseJson(false,ResponseCode.EXCEPTION, response, loginAuth != null ? loginAuth : defaultLoginAuth, ex, ex.getClass().getName()+":"+ex.getMessage());
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw new ApiRuntimeException(e);
@@ -177,7 +178,7 @@ public class JsonWebTokenValidFilter extends OncePerRequestFilter {
* @param args 异常码构造入参
* @throws IOException 异常
*/
- private void returnErrorResponseJson(boolean isRemoveCookie, ResponseCode responseCode, HttpServletResponse response, ILoginAuthHandler loginAuth, Object... args) throws Exception {
+ private void returnErrorResponseJson(boolean isRemoveCookie, ResponseCode responseCode, HttpServletResponse response, ILoginAuthHandler loginAuth, Exception ex, Object... args) throws Exception {
JSONObject redirectObj = new JSONObject();
String message = responseCode.getMessage(args);
redirectObj.put("Status", "FAILED");
@@ -186,6 +187,9 @@ public class JsonWebTokenValidFilter extends OncePerRequestFilter {
response.setStatus(responseCode.getCode());
redirectObj.put("DirectUrl", loginAuth.directUrl());
redirectObj.put("IsAutoDirect", loginAuth.isAutoDirect());
+ if (ex != null) {
+ redirectObj.put("stackTrace", ExceptionUtils.getStackFrames(ex));
+ }
if (isRemoveCookie) {
removeAuthCookie(response);
}
@@ -203,7 +207,7 @@ public class JsonWebTokenValidFilter extends OncePerRequestFilter {
* @throws IOException 异常
*/
private void returnErrorResponseJson(ResponseCode responseCode, HttpServletResponse response, ILoginAuthHandler loginAuth, Object... args) throws Exception {
- returnErrorResponseJson(true, responseCode, response, loginAuth, args);
+ returnErrorResponseJson(true, responseCode, response, loginAuth, null, args);
}
/**
@@ -215,7 +219,7 @@ public class JsonWebTokenValidFilter extends OncePerRequestFilter {
* @throws IOException 异常
*/
private void returnErrorResponseJson(ResponseCode responseCode, HttpServletResponse response, boolean isRemoveCookie, Object... args) throws Exception {
- returnErrorResponseJson(isRemoveCookie, responseCode, response, null, args);
+ returnErrorResponseJson(isRemoveCookie, responseCode, response, null, null, args);
}
/**
diff --git a/src/main/java/neatlogic/framework/integration/core/IntegrationHandlerBase.java b/src/main/java/neatlogic/framework/integration/core/IntegrationHandlerBase.java
index 26b48c17d..aca666703 100644
--- a/src/main/java/neatlogic/framework/integration/core/IntegrationHandlerBase.java
+++ b/src/main/java/neatlogic/framework/integration/core/IntegrationHandlerBase.java
@@ -324,8 +324,8 @@ public abstract class IntegrationHandlerBase implements IIntegrationHandler {
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
- resultVo.appendError("failed\n" + e.getMessage());
- integrationAuditVo.appendError("failed\n" + e.getMessage());
+ resultVo.appendError(e.getMessage());
+ integrationAuditVo.appendError(e.getMessage());
integrationAuditVo.setStatus("failed");
}
boolean hasTransferred = false;
diff --git a/src/main/java/neatlogic/framework/matrix/dao/mapper/MatrixAttributeMapper.java b/src/main/java/neatlogic/framework/matrix/dao/mapper/MatrixAttributeMapper.java
index f8c62257d..05f90951a 100644
--- a/src/main/java/neatlogic/framework/matrix/dao/mapper/MatrixAttributeMapper.java
+++ b/src/main/java/neatlogic/framework/matrix/dao/mapper/MatrixAttributeMapper.java
@@ -19,6 +19,8 @@ public interface MatrixAttributeMapper {
void addMatrixDynamicTableColumn(@Param("columnName") String columnName, @Param("matrixUuid") String matrixUuid);
+ void addMatrixDynamicTableDateColumn(@Param("columnName") String columnName, @Param("matrixUuid") String matrixUuid);
+
void addMatrixDynamicTableColumnSort(String matrixUuid);
void dropMatrixDynamicTableColumn(@Param("columnName") String columnName, @Param("matrixUuid") String matrixUuid);
diff --git a/src/main/java/neatlogic/framework/matrix/dao/mapper/MatrixAttributeMapper.xml b/src/main/java/neatlogic/framework/matrix/dao/mapper/MatrixAttributeMapper.xml
index f51090f74..73a27280c 100644
--- a/src/main/java/neatlogic/framework/matrix/dao/mapper/MatrixAttributeMapper.xml
+++ b/src/main/java/neatlogic/framework/matrix/dao/mapper/MatrixAttributeMapper.xml
@@ -42,14 +42,22 @@
- CREATE table `@{DATA_SCHEMA}`.`matrix_${matrixUuid}` (
- `id` bigint(20) NOT NULL AUTO_INCREMENT,
- `uuid` char(32) NOT NULL,
+ CREATE TABLE `@{DATA_SCHEMA}`.`matrix_${matrixUuid}` (
+ `id` BIGINT(20) NOT NULL AUTO_INCREMENT,
+ `uuid` CHAR(32) NOT NULL,
- `${attribute.uuid}` varchar(100) DEFAULT NULL
+
+
+ `${attribute.uuid}` TIMESTAMP DEFAULT NULL
+
+
+ `${attribute.uuid}` VARCHAR (100) DEFAULT NULL
+
+
+
,
- `sort` int(11) NOT NULL,
+ `sort` INT(11) NOT NULL,
PRIMARY KEY (`uuid`),
KEY `id`(`id`)
)ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci
@@ -61,7 +69,11 @@
- ALTER TABLE `@{DATA_SCHEMA}`.`matrix_${matrixUuid}` ADD COLUMN `${columnName}` VARCHAR (100)
+ ALTER TABLE `@{DATA_SCHEMA}`.`matrix_${matrixUuid}` ADD COLUMN `${columnName}` VARCHAR (100) NULL
+
+
+
+ ALTER TABLE `@{DATA_SCHEMA}`.`matrix_${matrixUuid}` ADD COLUMN `${columnName}` TIMESTAMP NULL
diff --git a/src/main/java/neatlogic/framework/matrix/dto/MatrixColumnVo.java b/src/main/java/neatlogic/framework/matrix/dto/MatrixColumnVo.java
index ec4ca15d4..7227b5763 100644
--- a/src/main/java/neatlogic/framework/matrix/dto/MatrixColumnVo.java
+++ b/src/main/java/neatlogic/framework/matrix/dto/MatrixColumnVo.java
@@ -1,11 +1,11 @@
package neatlogic.framework.matrix.dto;
-import java.util.ArrayList;
-import java.util.List;
-
import com.alibaba.fastjson.annotation.JSONField;
import org.apache.commons.collections4.CollectionUtils;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* @program: neatlogic
* @description:
@@ -19,9 +19,13 @@ public class MatrixColumnVo {
private List defaultValue;
private boolean isFilterList;
@JSONField(serialize = false)
- private String value;
+ private Object value;
public MatrixColumnVo() {
}
+ public MatrixColumnVo(String column, Object value) {
+ this.column = column;
+ this.value = value;
+ }
public MatrixColumnVo(String column, String value) {
this.column = column;
@@ -41,14 +45,14 @@ public class MatrixColumnVo {
this.column = column;
}
- public String getValue() {
+ public Object getValue() {
if(value == null && CollectionUtils.isNotEmpty(valueList)) {
value = valueList.get(0);
}
return value;
}
- public void setValue(String value) {
+ public void setValue(Object value) {
this.value = value;
}
diff --git a/src/main/java/neatlogic/module/framework/matrix/attrtype/handler/MatrixDataAttrTypeHandler.java b/src/main/java/neatlogic/module/framework/matrix/attrtype/handler/MatrixDataAttrTypeHandler.java
index 186abf5e3..d0317032c 100644
--- a/src/main/java/neatlogic/module/framework/matrix/attrtype/handler/MatrixDataAttrTypeHandler.java
+++ b/src/main/java/neatlogic/module/framework/matrix/attrtype/handler/MatrixDataAttrTypeHandler.java
@@ -21,10 +21,15 @@ import com.alibaba.fastjson.JSONObject;
import neatlogic.framework.matrix.constvalue.MatrixAttributeType;
import neatlogic.framework.matrix.core.MatrixAttrTypeBase;
import neatlogic.framework.matrix.dto.MatrixAttributeVo;
+import neatlogic.framework.util.TimeUtil;
+import org.apache.commons.collections4.MapUtils;
+import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
+import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
@Service
@@ -36,7 +41,24 @@ public class MatrixDataAttrTypeHandler extends MatrixAttrTypeBase {
@Override
public void getTextByValue(MatrixAttributeVo matrixAttribute, Object valueObj, JSONObject resultObj) {
- resultObj.put("text", valueObj.toString());
+ String newValue = null;
+ JSONObject config = matrixAttribute.getConfig();
+ if (MapUtils.isNotEmpty(config)) {
+ String format = config.getString("format");
+ if (StringUtils.isBlank(format)) {
+ format = TimeUtil.YYYY_MM_DD_HH_MM_SS;
+ }
+ String styleType = config.getString("styleType");
+ if (StringUtils.isNotBlank(styleType) && !Objects.equals(styleType, "-")) {
+ if ("|".equals(styleType)) {
+ styleType = "";
+ }
+ format = format.replace("-", styleType);
+ }
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
+ newValue = simpleDateFormat.format(valueObj);
+ }
+ resultObj.put("text", newValue);
}
@Override
diff --git a/src/main/java/neatlogic/module/framework/matrix/handler/CustomDataSourceHandler.java b/src/main/java/neatlogic/module/framework/matrix/handler/CustomDataSourceHandler.java
index dce9a553e..c41ebf636 100644
--- a/src/main/java/neatlogic/module/framework/matrix/handler/CustomDataSourceHandler.java
+++ b/src/main/java/neatlogic/module/framework/matrix/handler/CustomDataSourceHandler.java
@@ -33,6 +33,7 @@ import neatlogic.framework.matrix.dto.*;
import neatlogic.framework.matrix.exception.*;
import neatlogic.framework.util.ExcelUtil;
import neatlogic.framework.util.TableResultUtil;
+import neatlogic.framework.util.TimeUtil;
import neatlogic.framework.util.UuidUtil;
import neatlogic.framework.util.excel.ExcelPagedRowIterator;
import org.apache.commons.collections4.CollectionUtils;
@@ -48,6 +49,7 @@ import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.IOException;
import java.io.InputStream;
+import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
@@ -407,7 +409,7 @@ public class CustomDataSourceHandler extends MatrixDataSourceHandlerBase {
//删除数据
//调整表
List oldAttributeUuidList = oldMatrixAttributeList.stream().map(MatrixAttributeVo::getUuid).collect(Collectors.toList());
- List addAttributeUuidList = new ArrayList<>();
+ List addAttributeList = new ArrayList<>();
List existedAttributeUuidList = new ArrayList<>();
for (MatrixAttributeVo attributeVo : attributeVoList) {
attributeVo.setMatrixUuid(matrixUuid);
@@ -417,13 +419,17 @@ public class CustomDataSourceHandler extends MatrixDataSourceHandlerBase {
} else {
//过滤新增属性uuid
attributeMapper.insertMatrixAttribute(attributeVo);
- addAttributeUuidList.add(attributeVo.getUuid());
+ addAttributeList.add(attributeVo);
}
}
//添加新增字段
- for (String attributeUuid : addAttributeUuidList) {
- attributeMapper.addMatrixDynamicTableColumn(attributeUuid, matrixUuid);
+ for (MatrixAttributeVo attributeVo : addAttributeList) {
+ if (Objects.equals(attributeVo.getType(), MatrixAttributeType.DATE.getValue())) {
+ attributeMapper.addMatrixDynamicTableDateColumn(attributeVo.getUuid(), matrixUuid);
+ } else {
+ attributeMapper.addMatrixDynamicTableColumn(attributeVo.getUuid(), matrixUuid);
+ }
}
//找出需要删除的属性uuid列表
oldAttributeUuidList.removeAll(existedAttributeUuidList);
@@ -577,6 +583,7 @@ public class CustomDataSourceHandler extends MatrixDataSourceHandlerBase {
// 遍历过滤条件列表dataVo.getFilterList(),补充type字段值,即条件类型
List filterList = dataVo.getFilterList();
if (CollectionUtils.isNotEmpty(filterList)) {
+ SimpleDateFormat generalFormat = new SimpleDateFormat(TimeUtil.YYYY_MM_DD_HH_MM_SS);
for (MatrixFilterVo filterVo : filterList) {
MatrixAttributeVo matrixAttributeVo = matrixAttributeMap.get(filterVo.getUuid());
if (matrixAttributeVo != null) {
@@ -591,10 +598,34 @@ public class CustomDataSourceHandler extends MatrixDataSourceHandlerBase {
}
filterVo.setValueList(valueList);
}
+ } else if (Objects.equals(MatrixAttributeType.DATE.getValue(), matrixAttributeVo.getType())) {
+ JSONObject config = matrixAttributeVo.getConfig();
+ if (MapUtils.isNotEmpty(config)) {
+ String format = config.getString("format");
+ if (StringUtils.isBlank(format)) {
+ format = TimeUtil.YYYY_MM_DD_HH_MM_SS;
+ }
+ String styleType = config.getString("styleType");
+ if (StringUtils.isNotBlank(styleType) && !Objects.equals(styleType, "-")) {
+ if ("|".equals(styleType)) {
+ styleType = "";
+ }
+ format = format.replace("-", styleType);
+ }
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
+ List valueList = new ArrayList<>();
+ for (String value : filterVo.getValueList()) {
+ try {
+ Date date = simpleDateFormat.parse(value);
+ valueList.add(generalFormat.format(date));
+ } catch (ParseException e) {
+ valueList.add(value);
+ }
+ }
+ filterVo.setValueList(valueList);
+ }
} else {
-// if (StringUtils.isBlank(filterVo.getType())) {
filterVo.setType(matrixAttributeVo.getType());
-// }
}
}
}
@@ -676,18 +707,42 @@ public class CustomDataSourceHandler extends MatrixDataSourceHandlerBase {
boolean hasData = false;
List rowData = new ArrayList<>();
for (MatrixAttributeVo matrixAttributeVo : attributeList) {
+ Object newValue = null;
String value = rowDataObj.getString(matrixAttributeVo.getUuid());
if (StringUtils.isNotBlank(value)) {
hasData = true;
if (MatrixAttributeType.USER.getValue().equals(matrixAttributeVo.getType())) {
- value = value.split("#")[1];
+ newValue = value.split("#")[1];
} else if (MatrixAttributeType.TEAM.getValue().equals(matrixAttributeVo.getType())) {
- value = value.split("#")[1];
+ newValue = value.split("#")[1];
} else if (MatrixAttributeType.ROLE.getValue().equals(matrixAttributeVo.getType())) {
- value = value.split("#")[1];
+ newValue = value.split("#")[1];
+ } else if (MatrixAttributeType.DATE.getValue().equals(matrixAttributeVo.getType())) {
+ JSONObject config = matrixAttributeVo.getConfig();
+ if (MapUtils.isNotEmpty(config)) {
+ String format = config.getString("format");
+ if (StringUtils.isBlank(format)) {
+ format = TimeUtil.YYYY_MM_DD_HH_MM_SS;
+ }
+ String styleType = config.getString("styleType");
+ if (StringUtils.isNotBlank(styleType) && !Objects.equals(styleType, "-")) {
+ if ("|".equals(styleType)) {
+ styleType = "";
+ }
+ format = format.replace("-", styleType);
+ }
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
+ try {
+ newValue = simpleDateFormat.parse(value);
+ } catch (ParseException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ } else {
+ newValue = value;
}
}
- rowData.add(new MatrixColumnVo(matrixAttributeVo.getUuid(), value));
+ rowData.add(new MatrixColumnVo(matrixAttributeVo.getUuid(), newValue));
}
String uuidValue = rowDataObj.getString("uuid");
if (uuidValue == null) {
--
Gitee