From 27cddefb0cb28da699954ba1a1756d6bcabafbbe Mon Sep 17 00:00:00 2001
From: ludc <ludc@vci-tech.com>
Date: 星期三, 05 三月 2025 17:41:29 +0800
Subject: [PATCH] 集成申码接口调整:当码值按照约定传表名为空的业务场景下传null校验问题和码值组装问题。
---
Source/BladeX-Tool/blade-core-boot/src/main/java/org/springblade/core/boot/ctrl/BladeController.java | 279 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 279 insertions(+), 0 deletions(-)
diff --git a/Source/BladeX-Tool/blade-core-boot/src/main/java/org/springblade/core/boot/ctrl/BladeController.java b/Source/BladeX-Tool/blade-core-boot/src/main/java/org/springblade/core/boot/ctrl/BladeController.java
new file mode 100644
index 0000000..68991aa
--- /dev/null
+++ b/Source/BladeX-Tool/blade-core-boot/src/main/java/org/springblade/core/boot/ctrl/BladeController.java
@@ -0,0 +1,279 @@
+/*
+ * Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * Neither the name of the dreamlu.net developer nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ * Author: Chill 搴勯獮 (smallchill@163.com)
+ */
+package org.springblade.core.boot.ctrl;
+
+import org.springblade.core.boot.file.LocalFile;
+import org.springblade.core.boot.file.BladeFileUtil;
+import org.springblade.core.secure.BladeUser;
+import org.springblade.core.secure.utils.AuthUtil;
+import org.springblade.core.tool.api.R;
+import org.springblade.core.tool.utils.Charsets;
+import org.springblade.core.tool.utils.StringPool;
+import org.springblade.core.tool.utils.WebUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.io.FileSystemResource;
+import org.springframework.core.io.Resource;
+import org.springframework.core.io.support.ResourceRegion;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.multipart.MultipartFile;
+import org.springframework.web.util.UriUtils;
+
+import javax.servlet.http.HttpServletRequest;
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * Blade鎺у埗鍣ㄥ皝瑁呯被
+ *
+ * @author Chill
+ */
+public class BladeController {
+
+ /**
+ * ============================ REQUEST =================================================
+ */
+
+ @Autowired
+ private HttpServletRequest request;
+
+ /**
+ * 鑾峰彇request
+ */
+ public HttpServletRequest getRequest() {
+ return this.request;
+ }
+
+ /**
+ * 鑾峰彇褰撳墠鐢ㄦ埛
+ *
+ * @return
+ */
+ public BladeUser getUser() {
+ return AuthUtil.getUser();
+ }
+
+ /** ============================ API_RESULT ================================================= */
+
+ /**
+ * 杩斿洖ApiResult
+ *
+ * @param data
+ * @return R
+ */
+ public <T> R<T> data(T data) {
+ return R.data(data);
+ }
+
+ /**
+ * 杩斿洖ApiResult
+ *
+ * @param data
+ * @param message
+ * @return R
+ */
+ public <T> R<T> data(T data, String message) {
+ return R.data(data, message);
+ }
+
+ /**
+ * 杩斿洖ApiResult
+ *
+ * @param data
+ * @param message
+ * @param code
+ * @return R
+ */
+ public <T> R<T> data(T data, String message, int code) {
+ return R.data(code, data, message);
+ }
+
+ /**
+ * 杩斿洖ApiResult
+ *
+ * @param message
+ * @return R
+ */
+ public R success(String message) {
+ return R.success(message);
+ }
+
+ /**
+ * 杩斿洖ApiResult
+ *
+ * @param message
+ * @return R
+ */
+ public R fail(String message) {
+ return R.fail(message);
+ }
+
+ /**
+ * 杩斿洖ApiResult
+ *
+ * @param flag
+ * @return R
+ */
+ public R status(boolean flag) {
+ return R.status(flag);
+ }
+
+
+ /**============================ FILE ================================================= */
+
+ /**
+ * 鑾峰彇BladeFile灏佽绫�
+ *
+ * @param file
+ * @return
+ */
+ public LocalFile getFile(MultipartFile file) {
+ return BladeFileUtil.getFile(file);
+ }
+
+ /**
+ * 鑾峰彇BladeFile灏佽绫�
+ *
+ * @param file
+ * @param dir
+ * @return
+ */
+ public LocalFile getFile(MultipartFile file, String dir) {
+ return BladeFileUtil.getFile(file, dir);
+ }
+
+ /**
+ * 鑾峰彇BladeFile灏佽绫�
+ *
+ * @param file
+ * @param dir
+ * @param path
+ * @param virtualPath
+ * @return
+ */
+ public LocalFile getFile(MultipartFile file, String dir, String path, String virtualPath) {
+ return BladeFileUtil.getFile(file, dir, path, virtualPath);
+ }
+
+ /**
+ * 鑾峰彇BladeFile灏佽绫�
+ *
+ * @param files
+ * @return
+ */
+ public List<LocalFile> getFiles(List<MultipartFile> files) {
+ return BladeFileUtil.getFiles(files);
+ }
+
+ /**
+ * 鑾峰彇BladeFile灏佽绫�
+ *
+ * @param files
+ * @param dir
+ * @return
+ */
+ public List<LocalFile> getFiles(List<MultipartFile> files, String dir) {
+ return BladeFileUtil.getFiles(files, dir);
+ }
+
+ /**
+ * 鑾峰彇BladeFile灏佽绫�
+ *
+ * @param files
+ * @param path
+ * @param virtualPath
+ * @return
+ */
+ public List<LocalFile> getFiles(List<MultipartFile> files, String dir, String path, String virtualPath) {
+ return BladeFileUtil.getFiles(files, dir, path, virtualPath);
+ }
+ /**
+ * 涓嬭浇鏂囦欢
+ *
+ * @param file 鏂囦欢
+ * @return {ResponseEntity}
+ * @throws IOException io寮傚父
+ */
+ protected ResponseEntity<ResourceRegion> download(File file) throws IOException {
+ String fileName = file.getName();
+ return download(file, fileName);
+ }
+
+ /**
+ * 涓嬭浇
+ *
+ * @param file 鏂囦欢
+ * @param fileName 鐢熸垚鐨勬枃浠跺悕
+ * @return {ResponseEntity}
+ * @throws IOException io寮傚父
+ */
+ protected ResponseEntity<ResourceRegion> download(File file, String fileName) throws IOException {
+ Resource resource = new FileSystemResource(file);
+ return download(resource, fileName);
+ }
+
+ /**
+ * 涓嬭浇
+ *
+ * @param resource 璧勬簮
+ * @param fileName 鐢熸垚鐨勬枃浠跺悕
+ * @return {ResponseEntity}
+ * @throws IOException io寮傚父
+ */
+ protected ResponseEntity<ResourceRegion> download(Resource resource, String fileName) throws IOException {
+ HttpServletRequest request = WebUtil.getRequest();
+ String header = request.getHeader(HttpHeaders.USER_AGENT);
+ // 閬垮厤绌烘寚閽�
+ header = header == null ? StringPool.EMPTY : header.toUpperCase();
+ HttpStatus status;
+ String msie= "MSIE";
+ String trident= "TRIDENT";
+ String edge= "EDGE";
+ if (header.contains(msie) || header.contains(trident) || header.contains(edge)) {
+ status = HttpStatus.OK;
+ } else {
+ status = HttpStatus.CREATED;
+ }
+ // 鏂偣缁紶
+ long position = 0;
+ long count = resource.contentLength();
+ String range = request.getHeader(HttpHeaders.RANGE);
+ if (null != range) {
+ status = HttpStatus.PARTIAL_CONTENT;
+ String[] rangeRange = range.replace("bytes=", StringPool.EMPTY).split(StringPool.DASH);
+ position = Long.parseLong(rangeRange[0]);
+ if (rangeRange.length > 1) {
+ long end = Long.parseLong(rangeRange[1]);
+ count = end - position + 1;
+ }
+ }
+ HttpHeaders headers = new HttpHeaders();
+ headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
+ String encodeFileName = UriUtils.encode(fileName, Charsets.UTF_8);
+ // 鍏煎鍚勭娴忚鍣ㄤ笅杞斤細
+ // https://blog.robotshell.org/2012/deal-with-http-header-encoding-for-file-download/
+ String disposition = "attachment;" +
+ "filename=\"" + encodeFileName + "\";" +
+ "filename*=utf-8''" + encodeFileName;
+ headers.set(HttpHeaders.CONTENT_DISPOSITION, disposition);
+ return new ResponseEntity<>(new ResourceRegion(resource, position, count), headers, status);
+ }
+
+}
--
Gitblit v1.9.3