소스 검색

配置修改

chenweida 7 년 전
부모
커밋
f5a6f7df7d

+ 14 - 12
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/util/CommonUtil.java

@ -149,7 +149,7 @@ public class CommonUtil {
            }
            return fileUrls;
        } else {
            String fileUrls = toNeiWang(voices);
            String fileUrls = toNeiWang(voices,null);
            return fileUrls;
        }
    }
@ -217,9 +217,9 @@ public class CommonUtil {
     * @throws Exception
     */
    public String copyTempImage(String files) throws Exception {
        String tempPath = SystemConf.getInstance().getTempPath() + File.separator;
        if (isneiwang) {
            // 文件保存的临时路径
            String tempPath = SystemConf.getInstance().getTempPath() + File.separator;
            String[] fileArray = files.split(",");
            FastDFSUtil fastDFSUtil = new FastDFSUtil();
            String fileUrls = "";
@ -246,7 +246,7 @@ public class CommonUtil {
            return fileUrls;
        } else {
            String fileUrls = toNeiWang(files);
            String fileUrls = toNeiWang(files,tempPath);
            return fileUrls;
        }
    }
@ -452,28 +452,30 @@ public class CommonUtil {
     *
     * @return
     */
    public String toNeiWang(String files) throws FileNotFoundException {
    public String toNeiWang(String files,String tempPath) throws FileNotFoundException {
        logger.info(" toNeiWang start files :"+tempPath+files);
        //转发到内网服务器
        String[] fileArray = files.split(",");
        String fileUrls = "";
        for (String file : fileArray) {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            File f = new File(file);
            File f = new File(tempPath+file);
            logger.info(" toNeiWang File exists :"+f.exists());
            if (f.exists()) {
                String fileName = f.getName();
                InputStream in = new FileInputStream(f);
                JSONObject result=JSONObject.fromObject(request(request, in, fileName));
                String returnStr=request(request, in, fileName);
                logger.info("returnStr :"+returnStr);
                logger.info("fileName :"+fileName);
                logger.info("result :"+result.toString());
                if (result != null) {
                logger.info("result :"+returnStr.toString());
                if (returnStr != null) {
                    //1.3.7去掉前缀
                    fileUrls += (StringUtils.isEmpty(fileUrls) ? "" : ",")
                            + result.get("groupName").toString().replaceAll("\"", "") + "/"
                            + result.get("remoteFileName").toString().replaceAll("\"", "");
                    fileUrls += returnStr;
                    f.delete();
                }
            }
        }
        logger.info(" toNeiWang end files :"+fileUrls);
        return fileUrls;
    }
@ -511,7 +513,7 @@ public class CommonUtil {
    public String request(HttpServletRequest request, InputStream in, String fileName) {
        String url = neiwangWlyy + request.getRequestURI();//uri请求路径 http://172.19.103.88/wlyy/upload/chat
        String url = neiwangWlyy + "/wlyy/upload/commonUpload";//uri请求路径 http://172.19.103.88/wlyy/upload/chat
        CloseableHttpClient httpClient = HttpClientBuilder.create().build();
        String result = "";

+ 31 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/common/FileUploadController.java

@ -11,6 +11,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
@ -40,6 +41,7 @@ import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.util.*;
@ -492,5 +494,34 @@ public class FileUploadController extends BaseController {
        }
    }
    @RequestMapping(value = "commonUpload", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("公共的文件上传")
    public String commonUpload(HttpServletRequest request) {
        try {
            MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
            // 文件保存的临时路径
            FastDFSUtil fastDFSUtil = new FastDFSUtil();
            String fileUrls = "";
            Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
            String fileName = null;
            for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
                // 上传文件
                MultipartFile mf = entity.getValue();
                fileName = mf.getOriginalFilename();
                InputStream in = mf.getInputStream();
                ObjectNode result = fastDFSUtil.upload(in, fileName.substring(fileName.lastIndexOf(".") + 1), "");
                if (result != null) {
                    fileUrls += (StringUtils.isEmpty(fileUrls) ? "" : ",")
                            + result.get("groupName").toString().replaceAll("\"", "") + "/"
                            + result.get("remoteFileName").toString().replaceAll("\"", "");
                }
            }
            return fileUrls;
        } catch (Exception e) {
            error(e);
            return error(-1, "上传失败!");
        }
    }
}