ÎļþÃû´Ó server/dmvisit_web/src/main/java/com/doumee/api/common/PublicController.java ÐÞ¸Ä |
| | |
| | | package com.doumee.api.common; |
| | | package com.doumee.api.web; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.doumee.api.BaseController; |
| | |
| | | import com.doumee.core.annotation.trace.Trace; |
| | | import com.doumee.core.utils.Constants; |
| | | import com.doumee.core.utils.DateUtil; |
| | | import com.doumee.core.utils.FtpUtil; |
| | | import com.doumee.core.utils.aliyun.ALiYunUtil; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | 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.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; |
| | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.io.PrintWriter; |
| | | import java.util.HashMap; |
| | | import java.util.Iterator; |
| | | import java.util.Map; |
| | | import java.util.UUID; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * @author Eva.Caesar Liu |
| | |
| | | systemDictDataBiz.queryByCode(Constants.OSS,Constants.ENDPOINT).getCode()); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | public static FtpUtil ftp = null; |
| | | |
| | | @ApiOperation(value = "ä¸ä¼ æä»¶å°FTP") |
| | | @RequestMapping(method= RequestMethod.POST,value="api/uploadFtp.do") |
| | | @ResponseBody |
| | | public void uploadFtp(HttpServletRequest request, HttpServletResponse response, String folderCode) throws Exception { |
| | | String folder = systemDictDataBiz.queryByCode(Constants.FTP,folderCode).getCode(); |
| | | String prefixPath = systemDictDataBiz.queryByCode(Constants.FTP,Constants.FTP_RESOURCE_PATH).getCode(); |
| | | InputStream is = null; |
| | | response.setCharacterEncoding("UTF-8"); |
| | | response.setContentType("text/html;charset=UTF-8"); |
| | | Map<String, Object> context = new HashMap<>(); |
| | | try { |
| | | if(ftp == null){ |
| | | ftp = new FtpUtil(systemDictDataBiz.queryByCode(Constants.FTP,Constants.FTP_HOST).getCode(), |
| | | Integer.parseInt(systemDictDataBiz.queryByCode(Constants.FTP,Constants.FTP_PORT).getCode()), |
| | | systemDictDataBiz.queryByCode(Constants.FTP,Constants.FTP_USERNAME).getCode(), |
| | | systemDictDataBiz.queryByCode(Constants.FTP,Constants.FTP_PWD).getCode()); |
| | | }else{ |
| | | ftp.connect(); |
| | | } |
| | | |
| | | CommonsMultipartResolver multipartResovler = new CommonsMultipartResolver(); |
| | | if (multipartResovler.isMultipart(request)) { |
| | | MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; |
| | | Iterator<String> it = multipartRequest.getFileNames(); |
| | | while (it.hasNext()) { |
| | | MultipartFile file = multipartRequest.getFile(it.next()); |
| | | is = file.getInputStream(); |
| | | String date = DateUtil.getNowShortDate(); |
| | | String fName = date+"/"+ UUID.randomUUID()+".jpg"; |
| | | String fileName = folder+fName; |
| | | boolean r = ftp.uploadInputstream(is,fileName); |
| | | if(r){ |
| | | context.put("success", true); |
| | | context.put("code", 200); |
| | | context.put("errno",0); |
| | | JSONObject fileJSON = new JSONObject(); |
| | | fileJSON.put("halfPath", fName); |
| | | fileJSON.put("prefixPath", prefixPath); |
| | | fileJSON.put("folder", folder); |
| | | context.put("data",fileJSON); |
| | | context.put("message","è¯·æ±æå"); |
| | | writerJson(response, context); |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("ãä¸ä¼ FTP失败ã======================"+e.getMessage()); |
| | | } |
| | | context.put("code", 0); |
| | | context.put("message", "ä¸ä¼ 失败"); |
| | | context.put("errno",0); |
| | | writerJson(response, context); |
| | | return; |
| | | } |
| | | |
| | | |
| | | |
| | | 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"); |