chenweida hace 7 años
padre
commit
a5d0ed88ae

BIN
patient-co/patient-co-wlyy/doc/接口文档/对外接口文档/集美健康教育/集美健康教育对外接口文档.docx


+ 1 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/config/SwaggerConfig.java

@ -83,6 +83,7 @@ public class SwaggerConfig {
                .pathMapping("/")
                .select()
                .paths(or(regex("/doctor/.*"),
                        regex("/manage_util/.*"),
                        regex("/PC/.*")))
                .build()
                .globalOperationParameters(pars)

+ 110 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/gateway/controller/GcFileUploadController.java

@ -0,0 +1,110 @@
package com.yihu.wlyy.web.third.gateway.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.yihu.wlyy.util.CommonUtil;
import com.yihu.wlyy.util.fastdfs.FastDFSUtil;
import com.yihu.wlyy.web.third.gateway.vo.UploadModel;
import com.yihu.wlyy.web.third.gateway.vo.base.BaseResultModel;
import com.yihu.wlyy.web.third.gateway.vo.base.ResultOneModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
/**
 * Created by chenweida on 2017/8/29.
 */
@Controller
@RequestMapping(value = "/wlyygc/upload", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@ResponseBody
@Api(description = "文件上传")
public class GcFileUploadController {
    @Autowired
    FastDFSUtil fastDFSUtil;
    @Autowired
    private com.yihu.wlyy.util.CommonUtil CommonUtil;
    @Value("${fastDFS.fastdfs_file_url}")
    private String fastdfs_file_url;
    private Logger logger = LoggerFactory.getLogger(GcFileUploadController.class);
    /**
     * 聊天附件上传
     *
     * @return
     * @throws IOException
     * @throws IllegalStateException
     */
    @RequestMapping(value = "/file", method = RequestMethod.POST)
    @ApiOperation(value = "单文件上传")
    public ResultOneModel<UploadModel> uploadFile(
            @ApiParam(value = "文件", required = true) @RequestParam(value = "file", required = true) MultipartFile file
    ) {
        try {
            UploadModel uploadModel = fileUpload(file);
            return new ResultOneModel<UploadModel>(uploadModel);
        } catch (Exception e) {
            return new ResultOneModel(BaseResultModel.statusEm.file_upload_error.getCode(), BaseResultModel.statusEm.file_upload_error.getMessage() + "," + e.getMessage(), new JSONObject());
        }
    }
    @RequestMapping(value = "/files", method = RequestMethod.POST)
    @ApiOperation(value = "多文件上传")
    public ResultOneModel uploadFiles(
            @ApiParam(value = "文件", allowMultiple = true, required = true) @RequestPart(value = "files", required = true) MultipartFile[] files
    ) {
        try {
            List<UploadModel> uploadModels = new ArrayList<>();
            for (MultipartFile file : files) {
                uploadModels.add(fileUpload(file));
            }
            return new ResultOneModel(uploadModels);
        } catch (Exception e) {
            return new ResultOneModel(new JSONArray());
        }
    }
    /**
     * 文件上传到fastDfs
     *
     * @param mf
     * @return
     */
    private UploadModel fileUpload(MultipartFile mf) throws Exception {
        UploadModel uploadModel = new UploadModel();
        // 得到文件的完整名称  xxx.txt
        String fullName = mf.getOriginalFilename();
        //得到文件类型
        String fileType = fullName.substring(fullName.lastIndexOf(".") + 1).toLowerCase();
        String fileName = fullName.substring(0, fullName.lastIndexOf("."));
        //上传到fastdfs
        ObjectNode objectNode = fastDFSUtil.upload(mf.getInputStream(), fileType, "");
        //解析返回的objectNode
        uploadModel.setFileName(fileName);
        uploadModel.setFileType(fileType);
        uploadModel.setFullUri(objectNode.get("fid").toString().replaceAll("\"", ""));
        uploadModel.setFullUrl(fastdfs_file_url + objectNode.get("fid").toString().replaceAll("\"", ""));
        return uploadModel;
    }
}

+ 53 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/gateway/vo/UploadModel.java

@ -0,0 +1,53 @@
package com.yihu.wlyy.web.third.gateway.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
/**
 * Created by chenweida on 2017/8/29.
 */
@ApiModel(description = "文件上传实体")
public class UploadModel {
    @ApiModelProperty(value = "文件名字", required = true, access = "response")
    private String fileName; //xxx
    @ApiModelProperty(value = "文件类型", required = true, access = "response")
    private String fileType; //txt
    @ApiModelProperty(value = "完整的url", required = true, access = "response")
    private String fullUrl; //http://172.19.103.13/healthArchiveGroup/M00/00/24/rBFuH1XdQC6AP3CDAAzodQCbVVc052.jpg
    @ApiModelProperty(value = "完整的uri", required = true, access = "response")
    private String fullUri; //healthArchiveGroup/M00/00/24/rBFuH1XdQC6AP3CDAAzodQCbVVc052.jpg
    public String getFullUrl() {
        return fullUrl;
    }
    public void setFullUrl(String fullUrl) {
        this.fullUrl = fullUrl;
    }
    public String getFullUri() {
        return fullUri;
    }
    public void setFullUri(String fullUri) {
        this.fullUri = fullUri;
    }
    public String getFileName() {
        return fileName;
    }
    public void setFileName(String fileName) {
        this.fileName = fileName;
    }
    public String getFileType() {
        return fileType;
    }
    public void setFileType(String fileType) {
        this.fileType = fileType;
    }
}

+ 1 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/gateway/vo/base/BaseResultModel.java

@ -42,6 +42,7 @@ public class BaseResultModel {
        error_no_ip(-10010, "请求失败,获取IP失败"),//请求失败,获取IP失败
        login_system_error(-10020, "系统异常"),
        login_publickey_error(-10030, "获取公钥失败"),
        file_upload_error(-10040, "文件上传失败"),
        login_account_error(-20010, "账号不存在"),
        login_password_error(-20020, "密码错误"),

+ 5 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/gateway/vo/base/ResultOneModel.java

@ -31,4 +31,9 @@ public class ResultOneModel<T> extends BaseResultModel {
    public ResultOneModel(Integer code, String message) {
        super(code, message);
    }
    public ResultOneModel(Integer status, String message, T result) {
        super(status, message);
        this.result = result;
    }
}

+ 2 - 2
patient-co/patient-co-wlyy/src/main/resources/config/fdfs_client.conf

@ -9,8 +9,8 @@ http.secret_key = FastDFS1234567890
#tracker_server = 172.19.103.54:22122
#-------------测试环境---------------#
#tracker_server = 172.19.103.54:22122
tracker_server = 172.19.103.54:22122
#-------------正式环境---------------#
tracker_server = 192.168.120.172:22122
#tracker_server = 192.168.120.172:22122