|
@@ -0,0 +1,65 @@
|
|
|
+package com.hcloud.microserver.system.bank.controller.base;
|
|
|
+
|
|
|
+import com.hcloud.microserver.commoncore.annotation.AuthCarbonValidate;
|
|
|
+import com.hcloud.microserver.commoncore.base.BaseController;
|
|
|
+import com.hcloud.microserver.commoncore.base.ResponseBase;
|
|
|
+import com.hcloud.microserver.commoncore.base.ResultVO;
|
|
|
+import com.hcloud.microserver.commoncore.domain.FileDO;
|
|
|
+import com.hcloud.microserver.commoncore.enums.ResultEnum;
|
|
|
+import com.hcloud.microserver.commoncore.util.FileType;
|
|
|
+import com.hcloud.microserver.commoncore.util.FileUtil;
|
|
|
+import io.swagger.annotations.*;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+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.multipart.MultipartFile;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.util.Date;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("/web/normal")
|
|
|
+@Api(tags = "公共操作服务",description = "公共操作服务")
|
|
|
+public class NormalController extends BaseController {
|
|
|
+
|
|
|
+ private static final String TARGET_IMAGE_DIC_NAME="images/";
|
|
|
+
|
|
|
+ @Value("${img.location}")
|
|
|
+ private String UPLOAD_FILE_PATH;
|
|
|
+
|
|
|
+ @ApiOperation(value = "图片上传",notes = "上传问题图片,图片限制大小10MB")
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "file",value = "上传内容",dataType = "MultipartFile")
|
|
|
+ })
|
|
|
+ @ApiResponse(code = 0,message = "操作成功")
|
|
|
+ @AuthCarbonValidate
|
|
|
+ @PostMapping("/uploadPics")
|
|
|
+ public ResponseBase uploadPics(@RequestParam("file") MultipartFile file, HttpServletRequest request){
|
|
|
+ ResultVO resultVO = this.uploadImageFiles(file,TARGET_IMAGE_DIC_NAME);
|
|
|
+ return responseSuccess(resultVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 上传代码
|
|
|
+ * @param file
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResultVO uploadImageFiles(@RequestParam("file") MultipartFile file, String type){
|
|
|
+ String fileName = file.getOriginalFilename();
|
|
|
+ fileName = FileUtil.renameToUUID(fileName);
|
|
|
+ FileDO sysFile = new FileDO(FileType.fileType(fileName),fileName, new Date());
|
|
|
+ try {
|
|
|
+ String targetPath = UPLOAD_FILE_PATH;
|
|
|
+ if(null!=type && !"".equals(type)){
|
|
|
+ sysFile.setUrl(type+sysFile.getUrl());
|
|
|
+ targetPath=UPLOAD_FILE_PATH+type;
|
|
|
+ }
|
|
|
+ FileUtil.uploadFile(file.getBytes(),targetPath , fileName);
|
|
|
+ } catch (Exception e) {
|
|
|
+ return new ResultVO(ResultEnum.SYS_ERROR);
|
|
|
+ }
|
|
|
+ return success(sysFile.getUrl());
|
|
|
+ }
|
|
|
+}
|