/*    */ package com.picc.grab.controller;
/*    */ 
/*    */ import com.picc.grab.common.CommonProperties;
/*    */ import com.picc.grab.common.OSSMethod;
/*    */ import com.picc.grab.config.UploadConfig;
/*    */ import com.picc.grab.entity.common.vo.ResultVO;
/*    */ import java.io.File;
/*    */ import java.io.InputStream;
/*    */ import java.util.UUID;
/*    */ import org.apache.commons.lang3.StringUtils;
/*    */ import org.slf4j.Logger;
/*    */ import org.slf4j.LoggerFactory;
/*    */ import org.springframework.beans.factory.annotation.Autowired;
/*    */ import org.springframework.web.bind.annotation.RequestMapping;
/*    */ import org.springframework.web.bind.annotation.RequestParam;
/*    */ import org.springframework.web.bind.annotation.ResponseBody;
/*    */ import org.springframework.web.bind.annotation.RestController;
/*    */ import org.springframework.web.multipart.MultipartFile;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ @RestController
/*    */ @RequestMapping({"/common"})
/*    */ public class CommonController
/*    */ {
/* 28 */   private static Logger logger = LoggerFactory.getLogger(CommonController.class);
/*    */ 
/*    */ 
/*    */   
/*    */   @Autowired
/*    */   UploadConfig uploadConfig;
/*    */ 
/*    */ 
/*    */   
/*    */   @RequestMapping({"/upload"})
/*    */   @ResponseBody
/*    */   public ResultVO<String> uploadImg(@RequestParam(required = true, value = "img") MultipartFile img) {
/* 40 */     ResultVO<String> vo = ResultVO.error("图片上传失败");
/* 41 */     String imgPath = "";
/* 42 */     if (img != null && !StringUtils.isEmpty(img.getOriginalFilename())) {
/*    */       
/* 44 */       String prefix = img.getOriginalFilename().substring(img.getOriginalFilename().lastIndexOf("."));
/*    */       
/* 46 */       String sjc = UUID.randomUUID().toString().replaceAll("-", "");
/*    */       
/* 48 */       if (this.uploadConfig.uploadType == 0) {
/*    */         
/*    */         try {
/* 51 */           imgPath = "upload/img/" + sjc + prefix;
/*    */           
/* 53 */           String savePath = "img" + CommonProperties.fileSep;
/*    */           
/* 55 */           if (this.uploadConfig.uploadPathType == 0) {
/* 56 */             savePath = CommonProperties.PATH + "static" + CommonProperties.fileSep + "upload" + CommonProperties.fileSep + savePath;
/*    */           } else {
/* 58 */             savePath = this.uploadConfig.uploadPath + savePath;
/*    */           } 
/*    */           
/* 61 */           if (StringUtils.equals(CommonProperties.fileSep, "\\")) {
/* 62 */             savePath = savePath.substring(1, savePath.length());
/* 63 */             savePath = savePath.replaceAll("\\\\", "/");
/*    */           } 
/*    */           
/* 66 */           File outPath = new File(savePath);
/* 67 */           if (!outPath.exists()) {
/* 68 */             outPath.mkdirs();
/*    */           }
/*    */           
/* 71 */           savePath = savePath + sjc + prefix;
/*    */           
/* 73 */           img.transferTo(new File(savePath));
/* 74 */           vo = ResultVO.success();
/* 75 */           vo.setData(imgPath);
/* 76 */         } catch (Exception exception) {}
/*    */       } else {
/*    */         
/*    */         try {
/* 80 */           imgPath = this.uploadConfig.logoImgPath + sjc + prefix;
/* 81 */           InputStream is = img.getInputStream();
/*    */           
/* 83 */           OSSMethod.putObject(this.uploadConfig.getSingletonInstance(), this.uploadConfig.bucketName, imgPath, is);
/*    */           
/* 85 */           vo = ResultVO.success();
/* 86 */           vo.setData(this.uploadConfig.readUrl + imgPath);
/* 87 */         } catch (Exception e) {
/* 88 */           logger.info("CommonController uploadImg error: " + e.getMessage(), e);
/*    */         } 
/*    */       } 
/*    */     } 
/*    */     
/* 93 */     return vo;
/*    */   }
/*    */ }


/* Location:              C:\Users\Administrator\Desktop\ROOT\WEB-INF\classes\!\com\picc\grab\controller\CommonController.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */