|
@@ -1,107 +1,107 @@
|
|
|
-package com.minpay.shouhuo.system;
|
|
|
-
|
|
|
-import com.min.util.CommonUtil;
|
|
|
-import com.minpay.common.exception.BusinessCodeException;
|
|
|
-import com.minpay.common.service.IPublicService;
|
|
|
-import com.startup.minpay.frame.business.IMINAction;
|
|
|
-import com.startup.minpay.frame.business.MINHttpServletRequestContext;
|
|
|
-import com.startup.minpay.frame.business.res.MINActionResult;
|
|
|
-import com.startup.minpay.frame.exception.MINBusinessException;
|
|
|
-import com.startup.minpay.frame.service.base.Service;
|
|
|
-import com.startup.minpay.frame.target.MINAction;
|
|
|
-import com.startup.minpay.frame.target.MINComponent;
|
|
|
-import com.startup.minpay.frame.target.MINParam;
|
|
|
-import com.startup.minpay.util.Log;
|
|
|
-import org.apache.commons.fileupload.FileItem;
|
|
|
-import org.apache.commons.lang.StringUtils;
|
|
|
-import org.json.JSONObject;
|
|
|
-import org.springframework.web.multipart.MultipartFile;
|
|
|
-
|
|
|
-import javax.servlet.http.HttpServletResponse;
|
|
|
-import java.io.File;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-
|
|
|
-/**
|
|
|
- * 文件上传公共接口
|
|
|
- *
|
|
|
- * @author ZHANGZZ
|
|
|
- *
|
|
|
- */
|
|
|
-@MINComponent
|
|
|
-public class FileManageAction implements IMINAction {
|
|
|
-
|
|
|
- private final static String UPLOAD_BYBYTES = "uploadByBytes";
|
|
|
-
|
|
|
- private final static String UPLOAD_FILE = "uploadFile";
|
|
|
-
|
|
|
- /**
|
|
|
- *
|
|
|
- * @param MINRequest
|
|
|
- * @param fileType 文件类型00图片01文档02视频
|
|
|
- * @param response
|
|
|
- * @param size 文件大小
|
|
|
- * @param proportion 图片宽高比区间 格式最小区间,最大区间 例如 1.50,1.80
|
|
|
- * @return
|
|
|
- * @throws MINBusinessException
|
|
|
- */
|
|
|
- @MINAction(value = UPLOAD_FILE, session = false)
|
|
|
- public MINActionResult uploadFile(MINHttpServletRequestContext MINRequest,
|
|
|
- @MINParam(key = "fileFiledId") String fileFiledId, @MINParam(key = "fileType") String fileType,
|
|
|
- @MINParam(key = "size") int size, @MINParam(key = "proportion") String proportion,
|
|
|
- HttpServletResponse response) throws MINBusinessException {
|
|
|
- MINActionResult res = new MINActionResult();
|
|
|
-
|
|
|
- if (StringUtils.isEmpty(fileFiledId)) {
|
|
|
- fileFiledId = "file";
|
|
|
- }
|
|
|
-
|
|
|
- FileItem file = MINRequest.getFile(fileFiledId);
|
|
|
-
|
|
|
- // 判断文件大小上传抛出异常
|
|
|
- Log.info("文件大小:" + String.valueOf((file.getSize() / 1024D / 1024D)) + "M");
|
|
|
- if (size > 0 && (1024L * 1024L * size) < file.getSize()) {
|
|
|
- throw new MINBusinessException("请上传小于" + String.valueOf(size) + "M的文件");
|
|
|
- }
|
|
|
- if (size < 0) {
|
|
|
- throw new MINBusinessException("size参数异常,size不能小于0");
|
|
|
- }
|
|
|
-
|
|
|
- Map<String, Object> map = Service.lookup(IPublicService.class).uploadFile(file, fileType, 0, true);
|
|
|
-
|
|
|
- if ("00".equals(fileType) && !CommonUtil.isEmpty(proportion)) {
|
|
|
- double minRatio = -1;
|
|
|
- double maxRatio = -1;
|
|
|
- String[] proportions = null;
|
|
|
- if (proportion != null && !proportion.isEmpty()) {
|
|
|
- // 截取参数 图片的宽高比
|
|
|
- proportions = proportion.split(",");
|
|
|
- minRatio = Double.parseDouble(proportions[0].trim());
|
|
|
- maxRatio = Double.parseDouble(proportions[1].trim());
|
|
|
- }
|
|
|
- // 获取宽高
|
|
|
- Double width = (Double) map.get("width");
|
|
|
- Double height = (Double) map.get("height");
|
|
|
- // 判断宽高比是否符合规定
|
|
|
- Double ratio = width / height;
|
|
|
- Log.info("上传图片宽高比:" + String.valueOf(ratio));
|
|
|
- if (ratio < minRatio || ratio > maxRatio) {
|
|
|
- throw new MINBusinessException(
|
|
|
- "请上传宽高比" + proportions[0].trim() + "到" + proportions[1].trim() + "之间的图片");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- String url = (String) map.get("url");
|
|
|
-
|
|
|
- JSONObject js = new JSONObject();
|
|
|
- js.put("src", url);// 获取图片路径
|
|
|
-
|
|
|
- res.set("code", 0);
|
|
|
- res.set("msg", "");
|
|
|
- res.set("data", js);
|
|
|
- return res;
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
+//package com.minpay.shouhuo.system;
|
|
|
+//
|
|
|
+//import com.min.util.CommonUtil;
|
|
|
+//import com.minpay.common.exception.BusinessCodeException;
|
|
|
+//import com.minpay.common.service.IPublicService;
|
|
|
+//import com.startup.minpay.frame.business.IMINAction;
|
|
|
+//import com.startup.minpay.frame.business.MINHttpServletRequestContext;
|
|
|
+//import com.startup.minpay.frame.business.res.MINActionResult;
|
|
|
+//import com.startup.minpay.frame.exception.MINBusinessException;
|
|
|
+//import com.startup.minpay.frame.service.base.Service;
|
|
|
+//import com.startup.minpay.frame.target.MINAction;
|
|
|
+//import com.startup.minpay.frame.target.MINComponent;
|
|
|
+//import com.startup.minpay.frame.target.MINParam;
|
|
|
+//import com.startup.minpay.util.Log;
|
|
|
+//import org.apache.commons.fileupload.FileItem;
|
|
|
+//import org.apache.commons.lang.StringUtils;
|
|
|
+//import org.json.JSONObject;
|
|
|
+//import org.springframework.web.multipart.MultipartFile;
|
|
|
+//
|
|
|
+//import javax.servlet.http.HttpServletResponse;
|
|
|
+//import java.io.File;
|
|
|
+//import java.util.ArrayList;
|
|
|
+//import java.util.HashMap;
|
|
|
+//import java.util.List;
|
|
|
+//import java.util.Map;
|
|
|
+//
|
|
|
+///**
|
|
|
+// * 文件上传公共接口
|
|
|
+// *
|
|
|
+// * @author ZHANGZZ
|
|
|
+// *
|
|
|
+// */
|
|
|
+//@MINComponent
|
|
|
+//public class FileManageAction implements IMINAction {
|
|
|
+//
|
|
|
+// private final static String UPLOAD_BYBYTES = "uploadByBytes";
|
|
|
+//
|
|
|
+// private final static String UPLOAD_FILE = "uploadFile";
|
|
|
+//
|
|
|
+// /**
|
|
|
+// *
|
|
|
+// * @param MINRequest
|
|
|
+// * @param fileType 文件类型00图片01文档02视频
|
|
|
+// * @param response
|
|
|
+// * @param size 文件大小
|
|
|
+// * @param proportion 图片宽高比区间 格式最小区间,最大区间 例如 1.50,1.80
|
|
|
+// * @return
|
|
|
+// * @throws MINBusinessException
|
|
|
+// */
|
|
|
+// @MINAction(value = UPLOAD_FILE, session = false)
|
|
|
+// public MINActionResult uploadFile(MINHttpServletRequestContext MINRequest,
|
|
|
+// @MINParam(key = "fileFiledId") String fileFiledId, @MINParam(key = "fileType") String fileType,
|
|
|
+// @MINParam(key = "size") int size, @MINParam(key = "proportion") String proportion,
|
|
|
+// HttpServletResponse response) throws MINBusinessException {
|
|
|
+// MINActionResult res = new MINActionResult();
|
|
|
+//
|
|
|
+// if (StringUtils.isEmpty(fileFiledId)) {
|
|
|
+// fileFiledId = "file";
|
|
|
+// }
|
|
|
+//
|
|
|
+// FileItem file = MINRequest.getFile(fileFiledId);
|
|
|
+//
|
|
|
+// // 判断文件大小上传抛出异常
|
|
|
+// Log.info("文件大小:" + String.valueOf((file.getSize() / 1024D / 1024D)) + "M");
|
|
|
+// if (size > 0 && (1024L * 1024L * size) < file.getSize()) {
|
|
|
+// throw new MINBusinessException("请上传小于" + String.valueOf(size) + "M的文件");
|
|
|
+// }
|
|
|
+// if (size < 0) {
|
|
|
+// throw new MINBusinessException("size参数异常,size不能小于0");
|
|
|
+// }
|
|
|
+//
|
|
|
+// Map<String, Object> map = Service.lookup(IPublicService.class).uploadFile(file, fileType, 0, true);
|
|
|
+//
|
|
|
+// if ("00".equals(fileType) && !CommonUtil.isEmpty(proportion)) {
|
|
|
+// double minRatio = -1;
|
|
|
+// double maxRatio = -1;
|
|
|
+// String[] proportions = null;
|
|
|
+// if (proportion != null && !proportion.isEmpty()) {
|
|
|
+// // 截取参数 图片的宽高比
|
|
|
+// proportions = proportion.split(",");
|
|
|
+// minRatio = Double.parseDouble(proportions[0].trim());
|
|
|
+// maxRatio = Double.parseDouble(proportions[1].trim());
|
|
|
+// }
|
|
|
+// // 获取宽高
|
|
|
+// Double width = (Double) map.get("width");
|
|
|
+// Double height = (Double) map.get("height");
|
|
|
+// // 判断宽高比是否符合规定
|
|
|
+// Double ratio = width / height;
|
|
|
+// Log.info("上传图片宽高比:" + String.valueOf(ratio));
|
|
|
+// if (ratio < minRatio || ratio > maxRatio) {
|
|
|
+// throw new MINBusinessException(
|
|
|
+// "请上传宽高比" + proportions[0].trim() + "到" + proportions[1].trim() + "之间的图片");
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// String url = (String) map.get("url");
|
|
|
+//
|
|
|
+// JSONObject js = new JSONObject();
|
|
|
+// js.put("src", url);// 获取图片路径
|
|
|
+//
|
|
|
+// res.set("code", 0);
|
|
|
+// res.set("msg", "");
|
|
|
+// res.set("data", js);
|
|
|
+// return res;
|
|
|
+// }
|
|
|
+//
|
|
|
+//}
|