|
@@ -11,30 +11,35 @@ import com.zkqy.common.annotation.Log;
|
|
|
import com.zkqy.common.config.ZkqyConfig;
|
|
|
import com.zkqy.common.constant.Constants;
|
|
|
import com.zkqy.common.core.domain.AjaxResult;
|
|
|
+import com.zkqy.common.core.redis.RedisCache;
|
|
|
import com.zkqy.common.enums.BusinessType;
|
|
|
+import com.zkqy.common.utils.SecurityUtils;
|
|
|
import com.zkqy.common.utils.StringUtils;
|
|
|
import com.zkqy.common.utils.file.FileUploadUtils;
|
|
|
import com.zkqy.common.utils.file.FileUtils;
|
|
|
import com.zkqy.execution.produce.dispersed.entity.CommonEntity;
|
|
|
import com.zkqy.execution.produce.dispersed.entity.TableSql;
|
|
|
+import com.zkqy.execution.produce.dispersed.entity.vo.FileVo;
|
|
|
import com.zkqy.execution.produce.dispersed.service.ICommonService;
|
|
|
import com.zkqy.execution.produce.dispersed.service.ITableSqlService;
|
|
|
import com.zkqy.framework.config.ServerConfig;
|
|
|
import com.zkqy.business.controller.CommonController;
|
|
|
+import com.zkqy.system.service.sso.RedisService;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
+import io.swagger.v3.oas.annotations.parameters.RequestBody;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
import static com.zkqy.common.core.domain.AjaxResult.success;
|
|
|
|
|
@@ -63,6 +68,9 @@ public class CommonFileController {
|
|
|
@Resource
|
|
|
private IDragTableService dragTableService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private RedisCache redisCache;
|
|
|
+
|
|
|
private static final String FILE_DELIMETER = ",";
|
|
|
|
|
|
/**
|
|
@@ -117,8 +125,6 @@ public class CommonFileController {
|
|
|
/**
|
|
|
* 通用上传请求(单个)
|
|
|
*/
|
|
|
-// @Log(title = "动态表格", businessType = BusinessType.IMPORT)
|
|
|
- @Anonymous
|
|
|
@PostMapping("/upload")
|
|
|
public AjaxResult uploadFile(MultipartFile file) throws Exception {
|
|
|
try {
|
|
@@ -138,6 +144,103 @@ public class CommonFileController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 租户通用上传文件接口(需携带租户标识)
|
|
|
+ *
|
|
|
+ * @param file
|
|
|
+ * @param base64
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @PostMapping("/tenantUploadFile")
|
|
|
+ public AjaxResult tenantUploadFile(MultipartFile file, boolean base64) {
|
|
|
+ try {
|
|
|
+ // 每个租户都有属于自己的文件夹
|
|
|
+ String tenantCode = SecurityUtils.getLoginUser().getUser().getTenant().getTenantCode();
|
|
|
+ // 上传文件路径
|
|
|
+ String filePath = ZkqyConfig.getUploadPath() + "/" + tenantCode;
|
|
|
+ AjaxResult ajax = success();
|
|
|
+ // 当前文件是否使用base64来进行存储
|
|
|
+ if (base64) {
|
|
|
+ // 从MultipartFile获取字节数组
|
|
|
+ byte[] bytes = file.getBytes();
|
|
|
+ // 将字节数组转换为Base64编码的字符串
|
|
|
+ String base64Encoded = Base64.getEncoder().encodeToString(bytes);
|
|
|
+ String key = UUID.randomUUID().toString();
|
|
|
+ // 存储字节流 redis暂存30分钟
|
|
|
+ redisCache.setCacheObject(key, base64Encoded, Constants.BYTESTREAM_EXPIRATION, TimeUnit.MINUTES);
|
|
|
+ ajax.put("base64", key);
|
|
|
+ } else {
|
|
|
+ // 上传并返回新文件名称
|
|
|
+ String fileName = FileUploadUtils.upload(filePath, file);
|
|
|
+ // 存储文件
|
|
|
+ String url = serverConfig.getUrl() + fileName;
|
|
|
+ ajax.put("url", url);
|
|
|
+ ajax.put("fileName", fileName);
|
|
|
+ ajax.put("newFileName", FileUtils.getName(fileName));
|
|
|
+ ajax.put("originalFilename", file.getOriginalFilename());
|
|
|
+ }
|
|
|
+ return ajax;
|
|
|
+ } catch (Exception e) {
|
|
|
+ return AjaxResult.error(e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * * 租户通用批量上传文件接口(需携带租户标识)
|
|
|
+ * * * 批量上传无法使用流文件逻辑
|
|
|
+ *
|
|
|
+ * @param request
|
|
|
+ * @param files
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @PostMapping("/tenantUploadFiles")
|
|
|
+ @RequestBody
|
|
|
+ public AjaxResult tenantUploadFiles(HttpServletRequest request, List<MultipartFile> files) {
|
|
|
+ try {
|
|
|
+ // 每个租户都有属于自己的文件夹
|
|
|
+ String tenantCode = SecurityUtils.getLoginUser().getUser().getTenant().getTenantCode();
|
|
|
+ // 上传文件路径
|
|
|
+ String filePath = ZkqyConfig.getUploadPath() + "/" + tenantCode;
|
|
|
+ List<String> urls = new ArrayList<String>();
|
|
|
+ List<String> fileNames = new ArrayList<String>();
|
|
|
+ List<String> newFileNames = new ArrayList<String>();
|
|
|
+ List<String> originalFilenames = new ArrayList<String>();
|
|
|
+ List<String> base64Keys = new ArrayList<String>();
|
|
|
+ AjaxResult ajax = success();
|
|
|
+ for (MultipartFile file : files) {
|
|
|
+ boolean is = Boolean.parseBoolean(request.getParameter(file.getOriginalFilename().split("\\.")[0]));
|
|
|
+ if (is) {
|
|
|
+ // 从MultipartFile获取字节数组
|
|
|
+ byte[] bytes = file.getBytes();
|
|
|
+ // 将字节数组转换为Base64编码的字符串
|
|
|
+ String base64Encoded = Base64.getEncoder().encodeToString(bytes);
|
|
|
+ String key = UUID.randomUUID().toString();
|
|
|
+ // 存储字节流 redis暂存30分钟
|
|
|
+ redisCache.setCacheObject(key, base64Encoded, Constants.BYTESTREAM_EXPIRATION, TimeUnit.MINUTES);
|
|
|
+ base64Keys.add("file:base64:" + key);
|
|
|
+ ajax.put("base64", StringUtils.join(base64Keys, FILE_DELIMETER));
|
|
|
+ } else {
|
|
|
+ // 上传并返回新文件名称
|
|
|
+ String fileName = FileUploadUtils.upload(filePath, file);
|
|
|
+ String url = serverConfig.getUrl() + fileName;
|
|
|
+ urls.add(url);
|
|
|
+ fileNames.add(fileName);
|
|
|
+ newFileNames.add(FileUtils.getName(fileName));
|
|
|
+ originalFilenames.add(file.getOriginalFilename());
|
|
|
+
|
|
|
+ ajax.put("urls", StringUtils.join(urls, FILE_DELIMETER));
|
|
|
+ ajax.put("fileNames", StringUtils.join(fileNames, FILE_DELIMETER));
|
|
|
+ ajax.put("newFileNames", StringUtils.join(newFileNames, FILE_DELIMETER));
|
|
|
+ ajax.put("originalFilenames", StringUtils.join(originalFilenames, FILE_DELIMETER));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ajax;
|
|
|
+ } catch (Exception e) {
|
|
|
+ return AjaxResult.error(e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 通用上传请求(多个)
|
|
|
*/
|
|
@@ -262,7 +365,8 @@ public class CommonFileController {
|
|
|
listMap.remove(0);
|
|
|
CommonEntity commonEntity = new CommonEntity();
|
|
|
commonEntity.setBasicMap(
|
|
|
- JSONObject.parseObject("{ \"tableName\":\"" + tableName + "\"}", new TypeReference<Map<String, Object>>() {})
|
|
|
+ JSONObject.parseObject("{ \"tableName\":\"" + tableName + "\"}", new TypeReference<Map<String, Object>>() {
|
|
|
+ })
|
|
|
);
|
|
|
int state = 0; // 返回状态值
|
|
|
int batchSize = 1000; // 设置批量新增每次执行添加sql上线为1000条
|