From 60acccaebef503315c852f31677b44eb3fd40a4f Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期三, 25 六月 2025 10:29:29 +0800
Subject: [PATCH] 提交一把订单
---
/dev/null | 354 -----------------------------------
server/service/src/main/java/com/doumee/api/common/PublicController.java | 29 +-
server/service/src/main/java/com/doumee/api/common/CaptchaController.java | 0
server/service/src/main/java/com/doumee/core/utils/aliyun/ProgressModel.java | 18 +
company/src/components/common/upload.vue | 16
server/service/src/main/java/com/doumee/api/BaseController.java | 0
server/service/src/main/java/com/doumee/core/utils/aliyun/ALiYunUtil.java | 62 ++++++
server/service/src/main/java/com/doumee/core/utils/aliyun/PutObjectProgressListenerBiz.java | 83 ++++++++
8 files changed, 187 insertions(+), 375 deletions(-)
diff --git a/company/src/components/common/upload.vue b/company/src/components/common/upload.vue
index 4e350a5..a8c6b0d 100644
--- a/company/src/components/common/upload.vue
+++ b/company/src/components/common/upload.vue
@@ -73,13 +73,13 @@
}
}
- // const loading = this.$loading({
- // lock: true,
- // text: '涓婁紶涓紝璇风瓑寰�',
- // spinner: 'el-icon-loading',
- // background: 'rgba(0, 0, 0, 0.7)'
- // });
- // this.$emit('loading')
+ const loading = this.$loading({
+ lock: true,
+ text: '涓婁紶涓紝璇风瓑寰�',
+ spinner: 'el-icon-loading',
+ background: 'rgba(0, 0, 0, 0.7)'
+ });
+ this.$emit('loading')
const formdate = new FormData()
formdate.append('file', e.target.files[0])
formdate.append('folder', this.folder)
@@ -91,7 +91,7 @@
this.$message.error(e)
})
.finally(() => {
- // loading.close();
+ loading.close();
this.$refs.file.value = null
})
}
diff --git a/server/company/src/main/java/com/doumee/api/BaseController.java b/server/company/src/main/java/com/doumee/api/BaseController.java
deleted file mode 100644
index c45000d..0000000
--- a/server/company/src/main/java/com/doumee/api/BaseController.java
+++ /dev/null
@@ -1,60 +0,0 @@
-package com.doumee.api;
-
-import com.doumee.core.model.LoginUserInfo;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.shiro.SecurityUtils;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Controller鍩虹被
- * @author Eva.Caesar Liu
- * @date 2023/02/14 11:14
- */
-@Slf4j
-public class BaseController {
-
- /**
- * 鑾峰彇褰撳墠鐧诲綍鐢ㄦ埛
- * @author Eva.Caesar Liu
- * @date 2023/02/14 11:14
- */
- protected LoginUserInfo getLoginUser () {
- return (LoginUserInfo)SecurityUtils.getSubject().getPrincipal();
- }
-
- /**
- * 鑾峰彇ID闆嗗悎
- *
- * @param ids 浣跨敤","闅斿紑鐨勫涓狪D
- * @return List<Integer>
- */
- protected List<Integer> getIdList (String ids) {
- String [] idArray = ids.split(",");
- List<Integer> idList = new ArrayList<>();
- for (String id : idArray) {
- idList.add(Integer.valueOf(id));
- }
- return idList;
- }
-
- /**
- * 鑾峰彇鏂囦欢瀛楄妭娴�
- *
- * @param is 杈撳叆娴�
- * @return ByteArrayOutputStream
- */
- protected ByteArrayOutputStream getOutputStream (InputStream is) throws IOException {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- byte[] bs = new byte[is.available()];
- int len;
- while ((len = is.read(bs)) != -1) {
- baos.write(bs, 0, len);
- }
- return baos;
- }
-}
diff --git a/server/platform/src/main/java/com/doumee/api/BaseController.java b/server/platform/src/main/java/com/doumee/api/BaseController.java
deleted file mode 100644
index a830d8a..0000000
--- a/server/platform/src/main/java/com/doumee/api/BaseController.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package com.doumee.api;
-
-import com.doumee.core.model.LoginUserInfo;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.shiro.SecurityUtils;
-import com.doumee.core.model.ApiResponse;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Controller鍩虹被
- * @author Eva.Caesar Liu
- * @date 2023/02/14 11:14
- */
-@Slf4j
-public class BaseController {
-
- /**
- * 鑾峰彇褰撳墠鐧诲綍鐢ㄦ埛
- * @author Eva.Caesar Liu
- * @date 2023/02/14 11:14
- */
- protected LoginUserInfo getLoginUser () {
- return (LoginUserInfo)SecurityUtils.getSubject().getPrincipal();
- }
-
-
- /**
- * 鑾峰彇ID闆嗗悎
- *
- * @param ids 浣跨敤","闅斿紑鐨勫涓狪D
- * @return List<Integer>
- */
- protected List<Integer> getIdList (String ids) {
- String [] idArray = ids.split(",");
- List<Integer> idList = new ArrayList<>();
- for (String id : idArray) {
- idList.add(Integer.valueOf(id));
- }
- return idList;
- }
-
- /**
- * 鑾峰彇鏂囦欢瀛楄妭娴�
- *
- * @param is 杈撳叆娴�
- * @return ByteArrayOutputStream
- */
- protected ByteArrayOutputStream getOutputStream (InputStream is) throws IOException {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- byte[] bs = new byte[is.available()];
- int len;
- while ((len = is.read(bs)) != -1) {
- baos.write(bs, 0, len);
- }
- return baos;
- }
-}
diff --git a/server/platform/src/main/java/com/doumee/api/common/CaptchaController.java b/server/platform/src/main/java/com/doumee/api/common/CaptchaController.java
deleted file mode 100644
index 2162667..0000000
--- a/server/platform/src/main/java/com/doumee/api/common/CaptchaController.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package com.doumee.api.common;
-
-import com.doumee.api.BaseController;
-import com.doumee.core.annotation.trace.Trace;
-import com.doumee.core.model.ApiResponse;
-import com.doumee.service.common.CaptchaService;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-/**
- * @author Eva.Caesar Liu
- * @date 2023/02/14 11:14
- */
-@Api(tags = "鍥剧墖楠岃瘉鐮佹帴鍙�")
-@Trace(exclude = true)
-@RestController
-@RequestMapping("/common")
-public class CaptchaController extends BaseController {
-
- @Autowired
- private CaptchaService captchaService;
-
- /**
- * @author Eva.Caesar Liu
- * @date 2023/02/14 11:14
- */
- @ApiOperation("鑾峰彇鍥剧墖楠岃瘉鐮�")
- @GetMapping("/captcha")
- public ApiResponse<CaptchaService.Captcha> getCaptcha() {
- return ApiResponse.success(captchaService.genCaptcha());
- }
-}
diff --git a/server/platform/src/main/java/com/doumee/api/common/PublicController.java b/server/platform/src/main/java/com/doumee/api/common/PublicController.java
deleted file mode 100644
index 77dd080..0000000
--- a/server/platform/src/main/java/com/doumee/api/common/PublicController.java
+++ /dev/null
@@ -1,384 +0,0 @@
-package com.doumee.api.common;
-
-import com.alibaba.fastjson.JSONObject;
-import com.alibaba.fastjson.TypeReference;
-import com.doumee.api.BaseController;
-import com.doumee.biz.system.SystemDictDataBiz;
-import com.doumee.core.annotation.excel.ExcelToPdfTool;
-import com.doumee.core.annotation.trace.Trace;
-import com.doumee.core.constants.ResponseStatus;
-import com.doumee.core.exception.BusinessException;
-import com.doumee.core.model.ApiResponse;
-import com.doumee.core.utils.Constants;
-import com.doumee.core.utils.DateUtil;
-import com.doumee.core.utils.aliyun.ALiYunUtil;
-import com.doumee.dao.business.model.InsuranceApply;
-import com.doumee.dao.business.model.InterfaceLog;
-import com.doumee.dao.business.model.Solutions;
-import com.doumee.service.business.InsuranceApplyService;
-import com.doumee.service.business.InterfaceLogService;
-import com.doumee.service.business.third.SignService;
-import com.jzq.common.bean.sign.NotifyDataReq;
-import com.jzq.common.bean.sign.NotifyReq;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiImplicitParam;
-import io.swagger.annotations.ApiImplicitParams;
-import io.swagger.annotations.ApiOperation;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.codec.digest.DigestUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.shiro.authz.annotation.RequiresPermissions;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
-import org.springframework.web.multipart.MultipartFile;
-import org.springframework.web.multipart.MultipartHttpServletRequest;
-import org.springframework.web.multipart.commons.CommonsMultipartResolver;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.File;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.lang.reflect.Field;
-import java.util.*;
-
-/**
- * @author Eva.Caesar Liu
- * @date 2023/02/14 11:14
- */
-@Api(tags = "鍏叡鎺ュ彛")
-@Trace(exclude = true)
-@RestController
-@RequestMapping("/public")
-@Slf4j
-public class PublicController extends BaseController {
- @Autowired
- private SystemDictDataBiz systemDictDataBiz;
- @Autowired
- private InsuranceApplyService insuranceApplyService;
- @Autowired
- public InterfaceLogService interfaceLogService = null;
- @ApiOperation("鍚涘瓙绛剧绾﹀洖璋冮�氱煡")
- @PostMapping("/signNotify")
- public void updateStatus(@RequestParam Map<String,String> req, HttpServletResponse response) {
- Map<String, Object> context = new HashMap<>();
- context.put("success",true);
- InterfaceLog log=new InterfaceLog();
- log.setType(1);
- log.setCreateDate(new Date());
- log.setIsdeleted(0);
- log.setRequest(JSONObject.toJSONString(req));
- log.setName("鍚涘瓙绛剧绾﹀洖璋冮�氱煡");
- log.setUrl(systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.SIGN_DONE_NOTIFY_URL).getCode());
- try {
- String appKey = systemDictDataBiz.queryByCode(Constants.SIGN,Constants.SIGN_APPKEY).getCode();
- String appSecret = systemDictDataBiz.queryByCode(Constants.SIGN,Constants.SIGN_APPSECRET).getCode();
- if(!StringUtils.equals(appKey,req.get("appkey"))){
- throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"appkey涓嶅尮閰�");
- }
- String sign = DigestUtils.sha1Hex("data"+ req.get("data")+"method"+req.get("method")+"version"+req.get("version")+"timestamp"+req.get("timestamp")
- +"appKey"+appKey+"appSecret"+appSecret);
- if(!StringUtils.equals(sign,req.get("sign"))){
- throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"楠岀涓嶉�氳繃");
- }
- NotifyDataReq data = JSONObject.parseObject(req.get("data"), NotifyDataReq.class);
- String r = insuranceApplyService.dealSignResult(data);
- log.setRepose(r);
- }catch (Exception e){
- log.setRepose("澶勭悊寮傚父锛�"+e.getMessage());
- context.put("success",false);
- context.put("msg","澶勭悊鍙戠敓寮傚父");
- throw e;
- }finally {
- interfaceLogService.create(log);
- }
- writerJson(response, context);
- }
-
- @ApiOperation(value = "涓婁紶", notes = "涓婁紶", httpMethod = "POST", position = 6)
- @ApiImplicitParams({
- @ApiImplicitParam(name = "folder", value = "鏂囦欢澶�", required = true, paramType = "query", dataType = "String", dataTypeClass = String.class),
- })
- @PostMapping(value = "/upload", headers = "content-type=multipart/form-data")
- public void uploadMobile(String folder, HttpServletRequest request, HttpServletResponse response) throws Exception {
- MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
- upload(multipartRequest, response, folder + "/",
- systemDictDataBiz.queryByCode(Constants.OSS,Constants.BUCKETNAME).getCode(),
- systemDictDataBiz.queryByCode(Constants.OSS,Constants.ACCESS_ID).getCode(),
- systemDictDataBiz.queryByCode(Constants.OSS,Constants.ACCESS_KEY).getCode(),
- systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode(),
- systemDictDataBiz.queryByCode(Constants.OSS,Constants.ENDPOINT).getCode());
- }
- @ApiOperation(value = "涓婁紶鍥剧墖", notes = "涓婁紶鍥剧墖", httpMethod = "POST", position = 6)
- @ApiImplicitParams({
- @ApiImplicitParam(name = "folder", value = "鏂囦欢澶�", required = true, paramType = "query", dataType = "String", dataTypeClass = String.class),
- })
- @PostMapping(value = "/uploadPicture", headers = "content-type=multipart/form-data")
- public void uploadPicture(String folder, HttpServletRequest request, HttpServletResponse response) throws Exception {
- MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
- Iterator<String> fileNames = multipartRequest.getFileNames();
- Map<String, Object> context = new HashMap<>();
- while (fileNames.hasNext()){
- MultipartFile file = multipartRequest.getFile(fileNames.next());
- String fileName = file.getOriginalFilename();
- String suffix = fileName.substring(fileName.lastIndexOf("."));
- if ( !StringUtils.equalsIgnoreCase(suffix, ".jpg") || !StringUtils.equalsIgnoreCase(suffix, ".png")) {
- context.put("code", 0);
- context.put("message", "瀵逛笉璧凤紝鏂囦欢鏍煎紡涓婁紶鏈夎锛�");
- }
- }
- upload(multipartRequest, response, folder + "/",
- systemDictDataBiz.queryByCode(Constants.OSS,Constants.BUCKETNAME).getCode(),
- systemDictDataBiz.queryByCode(Constants.OSS,Constants.ACCESS_ID).getCode(),
- systemDictDataBiz.queryByCode(Constants.OSS,Constants.ACCESS_KEY).getCode(),
- systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode(),
- systemDictDataBiz.queryByCode(Constants.OSS,Constants.ENDPOINT).getCode());
- }
- public void upload(HttpServletRequest request, HttpServletResponse response, String folder, String bucketName,
- String access_id, String access_key, String resourcePath, String endpoint) throws Exception {
- response.setCharacterEncoding("UTF-8");
- response.setContentType("text/html;charset=UTF-8");
- Map<String, Object> context = new HashMap<>();
- CommonsMultipartResolver multipartResovler = new CommonsMultipartResolver();
- if (multipartResovler.isMultipart(request)) {
- MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
- Iterator<String> it = multipartRequest.getFileNames();
- while (it.hasNext()) {
- MultipartFile file = multipartRequest.getFile((String) it.next());// file
- // multipartRequest.getFile((String)
- // it.next());
- if (file != null) {
- // 1銆佷笂浼犲埌鏈嶅姟鍣ㄤ复鏃舵枃浠跺す
- String uploadFileName = file.getOriginalFilename();
- String originname = uploadFileName;
- if (originname.lastIndexOf("/") >= 0) {
- originname = originname.substring(originname.lastIndexOf("/") + 1);
- }
- String nfix = "";// 鍚庣紑鍚�
- if (StringUtils.isNotBlank(uploadFileName)) {
- nfix = uploadFileName.substring(uploadFileName.lastIndexOf("."));
- }
- if (StringUtils.equalsIgnoreCase(nfix, ".exe")) {
- context.put("code", 4000);
- context.put("message", "瀵逛笉璧凤紝鏂囦欢鏍煎紡\".exe\"涓婁紶鏈夎锛�");
- return;
- }
- if (StringUtils.equalsIgnoreCase(nfix, ".dll")) {
- context.put("code", 4000);
- context.put("message", "瀵逛笉璧凤紝鏂囦欢鏍煎紡\".dll\"涓婁紶鏈夎锛�");
- return;
- }
- String nowDate = DateUtil.getNowShortDate();// 褰撳墠鏃堕棿锛堝勾鏈堟棩锛�
- String fileName = UUID.randomUUID().toString() + nfix;
- String tempFileName = nowDate + "/" + fileName;
- String key = folder + tempFileName;// 鏂囦欢鍚�
- ALiYunUtil obs = new ALiYunUtil(endpoint,access_id, access_key);
- int type = 2;
- if(StringUtils.endsWith(key,".mp4")){
- type =1;
- }else if(StringUtils.endsWith(key,".jpg")
- || StringUtils.endsWith(key,".JPG")
- || StringUtils.endsWith(key,".png")
- || StringUtils.endsWith(key,".PNG")
- || StringUtils.endsWith(key,".jpeg")
- || StringUtils.endsWith(key,".JPEG")){
- type =0;
- }
- if (obs.uploadOnlineObject(file.getInputStream(),bucketName, key,null)) {
- // 绉诲姩鎴愬姛,杩斿洖鏂囦欢鍚�
- // sendSuccessMessage(response, resourcePath+key);
- context.put("success", true);
- context.put("code", 200);
- context.put("errno",0);
- JSONObject fileJSON = new JSONObject();
- fileJSON.put("url", resourcePath + key);
- fileJSON.put("imgaddr", tempFileName);
- fileJSON.put("type", type);
- fileJSON.put("imgname", fileName);
- fileJSON.put("originname", originname);
- context.put("data",fileJSON);
- context.put("message","璇锋眰鎴愬姛");
- writerJson(response, context);
- return;
- } else {
- // 绉诲姩澶辫触
- context.put("code", 0);
- context.put("message", "涓婁紶澶辫触");
- writerJson(response, context);
- return;
- }
- }
-
- }
- }
- context.put("code", 0);
- context.put("message", "涓婁紶澶辫触");
- context.put("errno",0);
- writerJson(response, context);
- return;
- }
-
- public static void writerJson(HttpServletResponse response, Object object) {
- response.setContentType("application/json");
- writer(response, JSONObject.toJSONString(object));
- }
-
- private static void writer(HttpServletResponse response, String str) {
- try {
- StringBuffer result = new StringBuffer();
- //璁剧疆椤甸潰涓嶇紦瀛�
- response.setHeader("Pragma", "No-cache");
- response.setHeader("Cache-Control", "no-cache");
- response.setCharacterEncoding("UTF-8");
- PrintWriter out = null;
- out = response.getWriter();
- out.print(str);
- out.flush();
- out.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
-
-
- @ApiOperation(value = "涓婁紶", notes = "涓婁紶", httpMethod = "POST", position = 6)
- @ApiImplicitParams({
- @ApiImplicitParam(name = "folder", value = "鏂囦欢澶�", required = true, paramType = "query", dataType = "String", dataTypeClass = String.class),
- })
- @PostMapping(value = "/uploadLocal", headers = "content-type=multipart/form-data")
- public void uploadLocal(String folder, HttpServletRequest request, HttpServletResponse response) throws Exception {
- MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
-
- // CommonsMultipartFile files = (CommonsMultipartFile) multipartRequest.getFile("filedata");
- uploadFileLocal(multipartRequest, folder+ "/", response,
- systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.GOODS_IMG_DIR).getCode() ,
- systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.FILE_DIR).getCode());
-
- }
-
- public void uploadFileLocal(HttpServletRequest request, String folder, HttpServletResponse response, String rootPath,String dir) throws Exception {
- response.setCharacterEncoding("UTF-8");
- response.setContentType("text/html;charset=UTF-8");
- CommonsMultipartResolver multipartResovler = new CommonsMultipartResolver();
- Map<String, Object> context = new HashMap<>();
- if (multipartResovler.isMultipart(request)) {
- MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
- Iterator<String> it = multipartRequest.getFileNames();
- while (it.hasNext()) {
- MultipartFile file = multipartRequest.getFile((String) it.next());// file
- // =
- // (CommonsMultipartFile)
- // multipartRequest.getFile((String)
- // it.next());
- if (file != null) {
- if (file.getSize() > 200 * 1024 * 1024L) {
- context.put("code", 4000);
- context.put("message", "涓婁紶鏂囦欢杩囧ぇ");
- return;
- }
- System.out.println(file.getOriginalFilename());
- if (file.getOriginalFilename() == null) {
- context.put("code", 4000);
- context.put("message", "鏂囦欢鍚嶄笉鍙负绌�");
- return;
- }
- /*
- * if(file.getOriginalFilename().contains(",")||file.getOriginalFilename().
- * contains(" ")){ sendFailureMessage(response,"鏂囦欢鍚嶇О鏈夎,涓嶅彲鍚湁閫楀彿绛夌壒娈婂瓧绗�"); }
- */
-
- String nowDate = DateUtil.getNowShortDate();
- folder += nowDate + "/";
- String strDirPath = rootPath + folder;
- File dirPath = new File(strDirPath);
- if (!dirPath.exists()) {
- dirPath.mkdirs();
- }
- String uploadFileName = file.getOriginalFilename();
- String x = UUID.randomUUID().toString().replace("-", "")
- + uploadFileName.substring(uploadFileName.lastIndexOf("."));
- String fileName = folder + x;
- String fileNames = nowDate + "/" + x;
- uploadFileName = uploadFileName.replace(" ", "");
- uploadFileName = uploadFileName.replace("锛�", ",");
- uploadFileName = uploadFileName.replaceAll(",", "-");
- System.err.println("R:" + fileName);
- String fileAndPath = dir + fileName;
- System.err.println("A:" + fileAndPath);
- // 鍒ゆ柇濡傛灉涓存椂鐩綍涓瓨鍦ㄧ浉鍚屽悕绉扮殑鏂囦欢鍏堝垹闄わ紝鍦ㄤ笂浼�
- File tempFile = new File(rootPath + fileName);
- if (tempFile.isFile() && tempFile.exists()) {
- tempFile.getAbsoluteFile().delete();
- }
- // 涓婁紶鍒版湇鍔″櫒涓存椂鏂囦欢澶�
- file.transferTo(tempFile);
- // 杞Щ鍒癋TP鏈嶅姟鍣�
- String nfix = "";
- if (null != uploadFileName) {
- nfix = uploadFileName.substring(uploadFileName.lastIndexOf("."));
- }
-
- if (StringUtils.equalsIgnoreCase(nfix, ".exe")) {
- context.put("code", 4000);
- context.put("message", "瀵逛笉璧凤紝鏂囦欢鏍煎紡\".exe\"涓婁紶鏈夎锛�");
- return;
- }
- if (StringUtils.equalsIgnoreCase(nfix, ".dll")) {
- context.put("code", 4000);
- context.put("message", "瀵逛笉璧凤紝鏂囦欢鏍煎紡\".dll\"涓婁紶鏈夎锛�");
- return;
- }
-
- String remoteName = fileName;
- String remoteFileName = fileAndPath;
-
- /* Map map = new HashMap();
- map.put("url", remoteFileName);
- map.put("alt", uploadFileName);
- map.put("href", remoteFileName);
- List maps = Arrays.asList(remoteFileName);*/
-
- if (true) {
- // 鍏抽棴FTP娴�
- // 绉诲姩鎴愬姛,杩斿洖鏂囦欢鍚�
-
- /*context.put("error", 0);
- context.put("url", remoteFileName);
- context.put("fullurl", remoteFileName);
- context.put("fname", uploadFileName);
- context.put("data", maps);
- context.put("halfurl", fileNames);*/
-
- context.put("success", true);
- context.put("code", 200);
- context.put("errno",0);
- JSONObject fileJSON = new JSONObject();
- fileJSON.put("url", remoteFileName);
- fileJSON.put("imgaddr", fileNames);
- fileJSON.put("imgname", uploadFileName);
- fileJSON.put("originname", uploadFileName);
- context.put("data",fileJSON);
- context.put("message","璇锋眰鎴愬姛");
-
- writerJson(response, context);
- return;
- } else {
- // 绉诲姩澶辫触
- context.put("code", 0);
- context.put("message", "涓婁紶澶辫触");
- writerJson(response, context);
- }
- }
- context.put("code", 0);
- context.put("message", "涓婁紶澶辫触");
- writerJson(response, context);
- return;
- }
- }
- context.put("code", 0);
- context.put("message", "涓婁紶澶辫触");
- writerJson(response, context);
- return;
- }
-}
diff --git a/server/shop/src/main/java/com/doumee/api/BaseController.java b/server/service/src/main/java/com/doumee/api/BaseController.java
similarity index 100%
rename from server/shop/src/main/java/com/doumee/api/BaseController.java
rename to server/service/src/main/java/com/doumee/api/BaseController.java
diff --git a/server/company/src/main/java/com/doumee/api/common/CaptchaController.java b/server/service/src/main/java/com/doumee/api/common/CaptchaController.java
similarity index 100%
rename from server/company/src/main/java/com/doumee/api/common/CaptchaController.java
rename to server/service/src/main/java/com/doumee/api/common/CaptchaController.java
diff --git a/server/company/src/main/java/com/doumee/api/common/PublicController.java b/server/service/src/main/java/com/doumee/api/common/PublicController.java
similarity index 94%
rename from server/company/src/main/java/com/doumee/api/common/PublicController.java
rename to server/service/src/main/java/com/doumee/api/common/PublicController.java
index 017b0f3..05dd57e 100644
--- a/server/company/src/main/java/com/doumee/api/common/PublicController.java
+++ b/server/service/src/main/java/com/doumee/api/common/PublicController.java
@@ -3,22 +3,21 @@
import com.alibaba.fastjson.JSONObject;
import com.doumee.api.BaseController;
import com.doumee.biz.system.SystemDictDataBiz;
-import com.doumee.core.annotation.excel.ExcelToPdfTool;
import com.doumee.core.annotation.trace.Trace;
+import com.doumee.core.model.ApiResponse;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.DateUtil;
import com.doumee.core.utils.aliyun.ALiYunUtil;
+import com.doumee.core.utils.aliyun.ProgressModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
+import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
@@ -53,21 +52,22 @@
@ApiImplicitParam(name = "folder", value = "鏂囦欢澶�", required = true, paramType = "query", dataType = "String", dataTypeClass = String.class),
})
@PostMapping(value = "/upload", headers = "content-type=multipart/form-data")
- public void uploadMobile(String folder, HttpServletRequest request, HttpServletResponse response) throws Exception {
+ public void uploadMobile(String folder, String uuid,HttpServletRequest request, HttpServletResponse response) throws Exception {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
upload(multipartRequest, response, folder + "/",
systemDictDataBiz.queryByCode(Constants.OSS,Constants.BUCKETNAME).getCode(),
systemDictDataBiz.queryByCode(Constants.OSS,Constants.ACCESS_ID).getCode(),
systemDictDataBiz.queryByCode(Constants.OSS,Constants.ACCESS_KEY).getCode(),
systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode(),
- systemDictDataBiz.queryByCode(Constants.OSS,Constants.ENDPOINT).getCode());
+ systemDictDataBiz.queryByCode(Constants.OSS,Constants.ENDPOINT).getCode(),
+ uuid);
}
@ApiOperation(value = "涓婁紶鍥剧墖", notes = "涓婁紶鍥剧墖", httpMethod = "POST", position = 6)
@ApiImplicitParams({
@ApiImplicitParam(name = "folder", value = "鏂囦欢澶�", required = true, paramType = "query", dataType = "String", dataTypeClass = String.class),
})
@PostMapping(value = "/uploadPicture", headers = "content-type=multipart/form-data")
- public void uploadPicture(String folder, HttpServletRequest request, HttpServletResponse response) throws Exception {
+ public void uploadPicture(String folder,String uuid, HttpServletRequest request, HttpServletResponse response) throws Exception {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Iterator<String> fileNames = multipartRequest.getFileNames();
Map<String, Object> context = new HashMap<>();
@@ -86,11 +86,16 @@
systemDictDataBiz.queryByCode(Constants.OSS,Constants.ACCESS_ID).getCode(),
systemDictDataBiz.queryByCode(Constants.OSS,Constants.ACCESS_KEY).getCode(),
systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode(),
- systemDictDataBiz.queryByCode(Constants.OSS,Constants.ENDPOINT).getCode());
+ systemDictDataBiz.queryByCode(Constants.OSS,Constants.ENDPOINT).getCode(),
+ uuid);
}
-
+ @ApiOperation("鏍规嵁uuid鏌ヨ涓婁紶杩涘害")
+ @GetMapping("/{uuid}")
+ public ApiResponse<ProgressModel> findById(@PathVariable String uuid) {
+ return ApiResponse.success(ALiYunUtil.queryProgressModel(uuid));
+ }
public void upload(HttpServletRequest request, HttpServletResponse response, String folder, String bucketName,
- String access_id, String access_key, String resourcePath, String endpoint) throws Exception {
+ String access_id, String access_key, String resourcePath, String endpoint,String uuid) throws Exception {
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
Map<String, Object> context = new HashMap<>();
@@ -139,7 +144,7 @@
|| StringUtils.endsWith(key,".JPEG")){
type =0;
}
- if (obs.uploadOnlineObject(file.getInputStream(),bucketName, key,null)) {
+ if (obs.uploadOnlineObject(file.getInputStream(),bucketName, key,uuid,null)) {
// 绉诲姩鎴愬姛,杩斿洖鏂囦欢鍚�
// sendSuccessMessage(response, resourcePath+key);
context.put("success", true);
diff --git a/server/service/src/main/java/com/doumee/core/utils/aliyun/ALiYunUtil.java b/server/service/src/main/java/com/doumee/core/utils/aliyun/ALiYunUtil.java
index 8e465b6..400a43c 100644
--- a/server/service/src/main/java/com/doumee/core/utils/aliyun/ALiYunUtil.java
+++ b/server/service/src/main/java/com/doumee/core/utils/aliyun/ALiYunUtil.java
@@ -5,6 +5,9 @@
import com.aliyun.oss.ClientException;
import com.aliyun.oss.OSSClient;
import com.aliyun.oss.OSSException;
+import com.aliyun.oss.event.ProgressEvent;
+import com.aliyun.oss.event.ProgressEventType;
+import com.aliyun.oss.event.ProgressListener;
import com.aliyun.oss.model.*;
import com.aliyun.sdk.service.cloudauth20190307.AsyncClient;
import com.aliyun.sdk.service.cloudauth20190307.models.Id2MetaVerifyRequest;
@@ -17,6 +20,7 @@
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
+import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
@@ -520,7 +524,7 @@
}
- public boolean uploadOnlineObject(InputStream inputStream, String bucketName, String key,
+ public boolean uploadOnlineObjectNew(InputStream inputStream, String bucketName, String key,
String mime) throws OSSException, ClientException, IOException {
if (inputStream != null) {
// 鍒ゆ柇鏄惁瀛樺湪锛屼笉瀛樺湪鍒涘缓
@@ -564,7 +568,63 @@
return false;
}
+ public static ProgressModel queryProgressModel(String id){
+ return PutObjectProgressListenerBiz.queryProgressModel(id);
+ }
+ public boolean uploadOnlineObject(InputStream inputStream, String bucketName, String key,String tempId,
+ String mime) throws OSSException, ClientException, IOException {
+ try {
+ isExistBucket(bucketName);
+ ObjectMetadata objectMeta = new ObjectMetadata();
+ objectMeta.setContentLength(inputStream.available());
+ // 鍙互鍦╩etadata涓爣璁版枃浠剁被鍨�
+ if (StringUtils.isNotBlank(mime)) {
+ objectMeta.setContentType(mime);
+ }
+ PutObjectRequest putObjectRequest = null;
+ if(StringUtils.isNotBlank(tempId)){
+ ProgressModel pmodel = new ProgressModel();
+ pmodel.setKey(key);
+ pmodel.setId(tempId);
+ pmodel.setStartDate(new Date());
+ putObjectRequest = new PutObjectRequest(bucketName, key,
+ inputStream).withProgressListener(new PutObjectProgressListenerBiz(pmodel));
+ }else{
+ putObjectRequest = new PutObjectRequest(bucketName, key,
+ inputStream);
+ }
+ PutObjectResult putObjectResult = client.putObject(putObjectRequest);
+ // 涓嬭浇鏂囦欢鐨勫悓鏃舵寚瀹氳繘搴︽潯鍙傛暟銆傛澶凣etObjectProgressListenerDemo涓鸿皟鐢ㄧ被鐨勭被鍚嶏紝璇峰湪瀹為檯浣跨敤鏃舵浛鎹负鐩稿簲鐨勭被鍚嶃��
+// ossClient.getObject(new GetObjectRequest(bucketName,objectName).
+// <GetObjectRequest>withProgressListener(new GetObjectProgressListenerDemo()));
+
+ } catch (OSSException oe) {
+ System.out.println("Caught an OSSException, which means your request made it to OSS, "
+ + "but was rejected with an error response for some reason.");
+ System.out.println("Error Message:" + oe.getErrorMessage());
+ System.out.println("Error Code:" + oe.getErrorCode());
+ System.out.println("Request ID:" + oe.getRequestId());
+ System.out.println("Host ID:" + oe.getHostId());
+ } catch (ClientException ce) {
+ System.out.println("Caught an ClientException, which means the client encountered "
+ + "a serious internal problem while trying to communicate with OSS, "
+ + "such as not being able to access the network.");
+ System.out.println("Error Message:" + ce.getMessage());
+ } finally {
+ if (inputStream != null) {
+ // 鍒ゆ柇鏄惁瀛樺湪锛屼笉瀛樺湪鍒涘缓
+ inputStream.close();
+ }
+ if (client != null) {
+ client.shutdown();
+ }
+ }
+
+
+ return false;
+
+ }
diff --git a/server/service/src/main/java/com/doumee/core/utils/aliyun/ProgressModel.java b/server/service/src/main/java/com/doumee/core/utils/aliyun/ProgressModel.java
new file mode 100644
index 0000000..76fa5a7
--- /dev/null
+++ b/server/service/src/main/java/com/doumee/core/utils/aliyun/ProgressModel.java
@@ -0,0 +1,18 @@
+package com.doumee.core.utils.aliyun;
+
+import lombok.Data;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+@Data
+public class ProgressModel {
+ private String id;
+ private String key;
+ private long totalBytes;//鎬诲ぇ灏�
+ private long bytesWritten;//宸蹭紶鏁版嵁
+ private double rate;//涓婁紶杩涘害%
+ private int status ;//鐘舵�� 0寰呬笂浼� 1涓婁紶涓� 2鎴愬姛 3澶辫触
+ private Date doneDate;
+ private Date startDate;
+}
diff --git a/server/service/src/main/java/com/doumee/core/utils/aliyun/PutObjectProgressListenerBiz.java b/server/service/src/main/java/com/doumee/core/utils/aliyun/PutObjectProgressListenerBiz.java
new file mode 100644
index 0000000..5b23380
--- /dev/null
+++ b/server/service/src/main/java/com/doumee/core/utils/aliyun/PutObjectProgressListenerBiz.java
@@ -0,0 +1,83 @@
+package com.doumee.core.utils.aliyun;
+
+import com.aliyun.oss.event.ProgressEvent;
+import com.aliyun.oss.event.ProgressEventType;
+import com.aliyun.oss.event.ProgressListener;
+import lombok.Data;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+@Data
+public class PutObjectProgressListenerBiz implements ProgressListener {
+ private static List<ProgressModel> currentUploadingList = new ArrayList<>();
+ private ProgressModel model;
+ public PutObjectProgressListenerBiz(ProgressModel model){
+ currentUploadingList.add(model);
+ this.model = model;
+ }
+ public static ProgressModel queryProgressModel(String id){
+ ProgressModel r = null;
+ if(currentUploadingList!=null && currentUploadingList.size()>0){
+
+ List<ProgressModel> tlist = new ArrayList<>();
+ for(ProgressModel m : currentUploadingList){
+ if(StringUtils.equals(id,m.getId())){
+ r = m;
+ }
+ if(System.currentTimeMillis() - m .getStartDate().getTime() > 24*60*60*1000){
+ //鍒犻櫎瓒呰繃1澶╃殑鏁版嵁
+ tlist.add(m);
+ }
+ }
+ if(tlist.size()>0){
+ //绉婚櫎涓�澶╁墠鐨勬暟鎹�
+ for(ProgressModel t : tlist){
+ currentUploadingList.remove(t);
+ }
+ }
+ }
+ return r;
+ }
+ @Override
+ public void progressChanged(ProgressEvent progressEvent) {
+ long bytes = progressEvent.getBytes();
+ ProgressEventType eventType = progressEvent.getEventType();
+ switch (eventType) {
+ case TRANSFER_STARTED_EVENT:
+ this.model.setDoneDate(new Date());
+ System.out.println("Start to upload......");
+ break;
+ case REQUEST_CONTENT_LENGTH_EVENT:
+ this.model.setTotalBytes(bytes);
+ System.out.println( this.model.getTotalBytes() + " bytes in total will be uploaded to OSS");
+ break;
+ case REQUEST_BYTE_TRANSFER_EVENT:
+ this.model.setStatus(1);
+ this.model.setBytesWritten(this.getModel().getBytesWritten()+bytes);
+ if (this.model.getTotalBytes() >0) {
+ int percent = (int)(this.getModel().getBytesWritten() * 100.0 / this.model.getTotalBytes());
+ this.model.setBytesWritten(this.getModel().getBytesWritten()+bytes);
+ System.out.println(bytes + " bytes have been written at this time, upload progress: " + percent + "%(" + this.getModel().getBytesWritten() + "/" + this.model.getTotalBytes()+ ")");
+ } else {
+ System.out.println(bytes + " bytes have been written at this time, upload ratio: unknown" + "(" + this.model.getBytesWritten() + "/...)");
+ }
+ break;
+ case TRANSFER_COMPLETED_EVENT:
+ this.model.setStatus(2);
+ this.model.setDoneDate(new Date());
+ System.out.println("Succeed to upload, " + this.getModel().getBytesWritten() + " bytes have been transferred in total");
+ break;
+ case TRANSFER_FAILED_EVENT:
+ this.model.setStatus(3);
+ this.model.setDoneDate(new Date());
+ System.out.println("Failed to upload, " + this.getModel().getBytesWritten() + " bytes have been transferred");
+ break;
+ default:
+ break;
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/server/shop/src/main/java/com/doumee/api/common/CaptchaController.java b/server/shop/src/main/java/com/doumee/api/common/CaptchaController.java
deleted file mode 100644
index 2162667..0000000
--- a/server/shop/src/main/java/com/doumee/api/common/CaptchaController.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package com.doumee.api.common;
-
-import com.doumee.api.BaseController;
-import com.doumee.core.annotation.trace.Trace;
-import com.doumee.core.model.ApiResponse;
-import com.doumee.service.common.CaptchaService;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-/**
- * @author Eva.Caesar Liu
- * @date 2023/02/14 11:14
- */
-@Api(tags = "鍥剧墖楠岃瘉鐮佹帴鍙�")
-@Trace(exclude = true)
-@RestController
-@RequestMapping("/common")
-public class CaptchaController extends BaseController {
-
- @Autowired
- private CaptchaService captchaService;
-
- /**
- * @author Eva.Caesar Liu
- * @date 2023/02/14 11:14
- */
- @ApiOperation("鑾峰彇鍥剧墖楠岃瘉鐮�")
- @GetMapping("/captcha")
- public ApiResponse<CaptchaService.Captcha> getCaptcha() {
- return ApiResponse.success(captchaService.genCaptcha());
- }
-}
diff --git a/server/shop/src/main/java/com/doumee/api/common/PublicController.java b/server/shop/src/main/java/com/doumee/api/common/PublicController.java
deleted file mode 100644
index 3a5b382..0000000
--- a/server/shop/src/main/java/com/doumee/api/common/PublicController.java
+++ /dev/null
@@ -1,354 +0,0 @@
-package com.doumee.api.common;
-
-import com.alibaba.fastjson.JSONObject;
-import com.doumee.api.BaseController;
-import com.doumee.biz.system.SystemDictDataBiz;
-import com.doumee.core.annotation.excel.ExcelToPdfTool;
-import com.doumee.core.annotation.trace.Trace;
-import com.doumee.core.model.ApiResponse;
-import com.doumee.core.utils.Constants;
-import com.doumee.core.utils.DateUtil;
-import com.doumee.core.utils.aliyun.ALiYunUtil;
-import com.doumee.dao.business.model.SmsEmail;
-import com.doumee.service.business.third.EmailService;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiImplicitParam;
-import io.swagger.annotations.ApiImplicitParams;
-import io.swagger.annotations.ApiOperation;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
-import org.springframework.web.multipart.MultipartFile;
-import org.springframework.web.multipart.MultipartHttpServletRequest;
-import org.springframework.web.multipart.commons.CommonsMultipartResolver;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.File;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.UUID;
-
-/**
- * @author Eva.Caesar Liu
- * @date 2023/02/14 11:14
- */
-@Api(tags = "鍏叡鎺ュ彛")
-@Trace(exclude = true)
-@RestController
-@RequestMapping("/public")
-@Slf4j
-public class PublicController extends BaseController {
-
-
- @Autowired
- private SystemDictDataBiz systemDictDataBiz;
- @Autowired
- private EmailService emailService;
- @ApiOperation("娴嬭瘯")
- @PostMapping("/testPdf")
- public String testPdf(@RequestParam Map<String,String> req, HttpServletResponse response) {
- ExcelToPdfTool.excelToPdf(req.get("f1"),req.get("f2"));
- return JSONObject.toJSONString(req);
- }
- @ApiOperation("娴嬭瘯閭")
- @PostMapping("/testEmail")
- public ApiResponse<Boolean> testEmail(@RequestBody SmsEmail smsEmail, HttpServletResponse response) {
- boolean result= emailService.sendEmail(smsEmail.getEmail(),smsEmail.getTitle(),smsEmail.getContent(),smsEmail.getFileList());
- return ApiResponse.success(result);
- }
-
- @ApiOperation(value = "涓婁紶", notes = "涓婁紶", httpMethod = "POST", position = 6)
- @ApiImplicitParams({
- @ApiImplicitParam(name = "folder", value = "鏂囦欢澶�", required = true, paramType = "query", dataType = "String", dataTypeClass = String.class),
- })
- @PostMapping(value = "/upload", headers = "content-type=multipart/form-data")
- public void uploadMobile(String folder, HttpServletRequest request, HttpServletResponse response) throws Exception {
- MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
- upload(multipartRequest, response, folder + "/",
- systemDictDataBiz.queryByCode(Constants.OSS,Constants.BUCKETNAME).getCode(),
- systemDictDataBiz.queryByCode(Constants.OSS,Constants.ACCESS_ID).getCode(),
- systemDictDataBiz.queryByCode(Constants.OSS,Constants.ACCESS_KEY).getCode(),
- systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode(),
- systemDictDataBiz.queryByCode(Constants.OSS,Constants.ENDPOINT).getCode());
- }
-
-
- @ApiOperation(value = "涓婁紶鍥剧墖", notes = "涓婁紶鍥剧墖", httpMethod = "POST", position = 6)
- @ApiImplicitParams({
- @ApiImplicitParam(name = "folder", value = "鏂囦欢澶�", required = true, paramType = "query", dataType = "String", dataTypeClass = String.class),
- })
- @PostMapping(value = "/uploadPicture", headers = "content-type=multipart/form-data")
- public void uploadPicture(String folder, HttpServletRequest request, HttpServletResponse response) throws Exception {
- MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
- Iterator<String> fileNames = multipartRequest.getFileNames();
- Map<String, Object> context = new HashMap<>();
- while (fileNames.hasNext()){
- MultipartFile file = multipartRequest.getFile(fileNames.next());
- String fileName = file.getOriginalFilename();
- String suffix = fileName.substring(fileName.lastIndexOf("."));
- if ( !StringUtils.equalsIgnoreCase(suffix, ".jpg") && !StringUtils.equalsIgnoreCase(suffix, ".png")) {
- context.put("code", 0);
- context.put("message", "瀵逛笉璧凤紝鏂囦欢鏍煎紡涓婁紶鏈夎锛�");
- return;
- }
- }
- upload(multipartRequest, response, folder + "/",
- systemDictDataBiz.queryByCode(Constants.OSS,Constants.BUCKETNAME).getCode(),
- systemDictDataBiz.queryByCode(Constants.OSS,Constants.ACCESS_ID).getCode(),
- systemDictDataBiz.queryByCode(Constants.OSS,Constants.ACCESS_KEY).getCode(),
- systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode(),
- systemDictDataBiz.queryByCode(Constants.OSS,Constants.ENDPOINT).getCode());
- }
-
- public void upload(HttpServletRequest request, HttpServletResponse response, String folder, String bucketName,
- String access_id, String access_key, String resourcePath, String endpoint) throws Exception {
- response.setCharacterEncoding("UTF-8");
- response.setContentType("text/html;charset=UTF-8");
- Map<String, Object> context = new HashMap<>();
- CommonsMultipartResolver multipartResovler = new CommonsMultipartResolver();
- if (multipartResovler.isMultipart(request)) {
- MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
- Iterator<String> it = multipartRequest.getFileNames();
- while (it.hasNext()) {
- MultipartFile file = multipartRequest.getFile((String) it.next());// file
- // multipartRequest.getFile((String)
- // it.next());
- if (file != null) {
- // 1銆佷笂浼犲埌鏈嶅姟鍣ㄤ复鏃舵枃浠跺す
- String uploadFileName = file.getOriginalFilename();
- String originname = uploadFileName;
- if (originname.lastIndexOf("/") >= 0) {
- originname = originname.substring(originname.lastIndexOf("/") + 1);
- }
- String nfix = "";// 鍚庣紑鍚�
- if (StringUtils.isNotBlank(uploadFileName)) {
- nfix = uploadFileName.substring(uploadFileName.lastIndexOf("."));
- }
- if (StringUtils.equalsIgnoreCase(nfix, ".exe")) {
- context.put("code", 4000);
- context.put("message", "瀵逛笉璧凤紝鏂囦欢鏍煎紡\".exe\"涓婁紶鏈夎锛�");
- return;
- }
- if (StringUtils.equalsIgnoreCase(nfix, ".dll")) {
- context.put("code", 4000);
- context.put("message", "瀵逛笉璧凤紝鏂囦欢鏍煎紡\".dll\"涓婁紶鏈夎锛�");
- return;
- }
- String nowDate = DateUtil.getNowShortDate();// 褰撳墠鏃堕棿锛堝勾鏈堟棩锛�
- String fileName = UUID.randomUUID().toString() + nfix;
- String tempFileName = nowDate + "/" + fileName;
- String key = folder + tempFileName;// 鏂囦欢鍚�
- ALiYunUtil obs = new ALiYunUtil(endpoint,access_id, access_key);
- int type = 2;
- if(StringUtils.endsWith(key,".mp4")){
- type =1;
- }else if(StringUtils.endsWith(key,".jpg")
- || StringUtils.endsWith(key,".JPG")
- || StringUtils.endsWith(key,".png")
- || StringUtils.endsWith(key,".PNG")
- || StringUtils.endsWith(key,".jpeg")
- || StringUtils.endsWith(key,".JPEG")){
- type =0;
- }
- if (obs.uploadOnlineObject(file.getInputStream(),bucketName, key,null)) {
- // 绉诲姩鎴愬姛,杩斿洖鏂囦欢鍚�
- // sendSuccessMessage(response, resourcePath+key);
- context.put("success", true);
- context.put("code", 200);
- context.put("errno",0);
- JSONObject fileJSON = new JSONObject();
- fileJSON.put("url", resourcePath + key);
- fileJSON.put("imgaddr", tempFileName);
- fileJSON.put("imgname", fileName);
- fileJSON.put("type", type);
- fileJSON.put("originname", originname);
- context.put("data",fileJSON);
- context.put("message","璇锋眰鎴愬姛");
- writerJson(response, context);
- return;
- } else {
- // 绉诲姩澶辫触
- context.put("code", 0);
- context.put("message", "涓婁紶澶辫触");
- writerJson(response, context);
- return;
- }
- }
-
- }
- }
- context.put("code", 0);
- context.put("message", "涓婁紶澶辫触");
- context.put("errno",0);
- writerJson(response, context);
- return;
- }
-
- public static void writerJson(HttpServletResponse response, Object object) {
- response.setContentType("application/json");
- writer(response, JSONObject.toJSONString(object));
- }
-
- private static void writer(HttpServletResponse response, String str) {
- try {
- StringBuffer result = new StringBuffer();
- //璁剧疆椤甸潰涓嶇紦瀛�
- response.setHeader("Pragma", "No-cache");
- response.setHeader("Cache-Control", "no-cache");
- response.setCharacterEncoding("UTF-8");
- PrintWriter out = null;
- out = response.getWriter();
- out.print(str);
- out.flush();
- out.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
-
-
- @ApiOperation(value = "涓婁紶", notes = "涓婁紶", httpMethod = "POST", position = 6)
- @ApiImplicitParams({
- @ApiImplicitParam(name = "folder", value = "鏂囦欢澶�", required = true, paramType = "query", dataType = "String", dataTypeClass = String.class),
- })
- @PostMapping(value = "/uploadLocal", headers = "content-type=multipart/form-data")
- public void uploadLocal(String folder, HttpServletRequest request, HttpServletResponse response) throws Exception {
- MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
-
- // CommonsMultipartFile files = (CommonsMultipartFile) multipartRequest.getFile("filedata");
- uploadFileLocal(multipartRequest, folder+ "/", response,
- systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.GOODS_IMG_DIR).getCode() ,
- systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.FILE_DIR).getCode());
-
- }
-
- public void uploadFileLocal(HttpServletRequest request, String folder, HttpServletResponse response, String rootPath,String dir) throws Exception {
- response.setCharacterEncoding("UTF-8");
- response.setContentType("text/html;charset=UTF-8");
- CommonsMultipartResolver multipartResovler = new CommonsMultipartResolver();
- Map<String, Object> context = new HashMap<>();
- if (multipartResovler.isMultipart(request)) {
- MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
- Iterator<String> it = multipartRequest.getFileNames();
- while (it.hasNext()) {
- MultipartFile file = multipartRequest.getFile((String) it.next());// file
- // =
- // (CommonsMultipartFile)
- // multipartRequest.getFile((String)
- // it.next());
- if (file != null) {
- if (file.getSize() > 200 * 1024 * 1024L) {
- context.put("code", 4000);
- context.put("message", "涓婁紶鏂囦欢杩囧ぇ");
- return;
- }
- System.out.println(file.getOriginalFilename());
- if (file.getOriginalFilename() == null) {
- context.put("code", 4000);
- context.put("message", "鏂囦欢鍚嶄笉鍙负绌�");
- return;
- }
- /*
- * if(file.getOriginalFilename().contains(",")||file.getOriginalFilename().
- * contains(" ")){ sendFailureMessage(response,"鏂囦欢鍚嶇О鏈夎,涓嶅彲鍚湁閫楀彿绛夌壒娈婂瓧绗�"); }
- */
-
- String nowDate = DateUtil.getNowShortDate();
- folder += nowDate + "/";
- String strDirPath = rootPath + folder;
- File dirPath = new File(strDirPath);
- if (!dirPath.exists()) {
- dirPath.mkdirs();
- }
- String uploadFileName = file.getOriginalFilename();
- String x = UUID.randomUUID().toString().replace("-", "")
- + uploadFileName.substring(uploadFileName.lastIndexOf("."));
- String fileName = folder + x;
- String fileNames = nowDate + "/" + x;
- uploadFileName = uploadFileName.replace(" ", "");
- uploadFileName = uploadFileName.replace("锛�", ",");
- uploadFileName = uploadFileName.replaceAll(",", "-");
- System.err.println("R:" + fileName);
- String fileAndPath = dir + fileName;
- System.err.println("A:" + fileAndPath);
- // 鍒ゆ柇濡傛灉涓存椂鐩綍涓瓨鍦ㄧ浉鍚屽悕绉扮殑鏂囦欢鍏堝垹闄わ紝鍦ㄤ笂浼�
- File tempFile = new File(rootPath + fileName);
- if (tempFile.isFile() && tempFile.exists()) {
- tempFile.getAbsoluteFile().delete();
- }
- // 涓婁紶鍒版湇鍔″櫒涓存椂鏂囦欢澶�
- file.transferTo(tempFile);
- // 杞Щ鍒癋TP鏈嶅姟鍣�
- String nfix = "";
- if (null != uploadFileName) {
- nfix = uploadFileName.substring(uploadFileName.lastIndexOf("."));
- }
-
- if (StringUtils.equalsIgnoreCase(nfix, ".exe")) {
- context.put("code", 4000);
- context.put("message", "瀵逛笉璧凤紝鏂囦欢鏍煎紡\".exe\"涓婁紶鏈夎锛�");
- return;
- }
- if (StringUtils.equalsIgnoreCase(nfix, ".dll")) {
- context.put("code", 4000);
- context.put("message", "瀵逛笉璧凤紝鏂囦欢鏍煎紡\".dll\"涓婁紶鏈夎锛�");
- return;
- }
-
- String remoteName = fileName;
- String remoteFileName = fileAndPath;
-
- /* Map map = new HashMap();
- map.put("url", remoteFileName);
- map.put("alt", uploadFileName);
- map.put("href", remoteFileName);
- List maps = Arrays.asList(remoteFileName);*/
-
- if (true) {
- // 鍏抽棴FTP娴�
- // 绉诲姩鎴愬姛,杩斿洖鏂囦欢鍚�
- /*context.put("error", 0);
- context.put("url", remoteFileName);
- context.put("fullurl", remoteFileName);
- context.put("fname", uploadFileName);
- context.put("data", maps);
- context.put("halfurl", fileNames);*/
-
- context.put("success", true);
- context.put("code", 200);
- context.put("errno",0);
- JSONObject fileJSON = new JSONObject();
- fileJSON.put("url", remoteFileName);
- fileJSON.put("imgaddr", fileNames);
- fileJSON.put("imgname", uploadFileName);
- fileJSON.put("originname", uploadFileName);
- context.put("data",fileJSON);
- context.put("message","璇锋眰鎴愬姛");
-
- writerJson(response, context);
- return;
- } else {
- // 绉诲姩澶辫触
- context.put("code", 0);
- context.put("message", "涓婁紶澶辫触");
- writerJson(response, context);
- }
- }
- context.put("code", 0);
- context.put("message", "涓婁紶澶辫触");
- writerJson(response, context);
- return;
- }
- }
- context.put("code", 0);
- context.put("message", "涓婁紶澶辫触");
- writerJson(response, context);
- return;
- }
-}
--
Gitblit v1.9.3