فهرست منبع

Merge branch 'dev' of zd_123/wlyy2.0 into dev

huangwenjie 6 سال پیش
والد
کامیت
0eefad9711

+ 10 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/specialist/rehabilitation/PatientRehabilitationPlanDO.java

@ -32,6 +32,8 @@ public class PatientRehabilitationPlanDO extends UuidIdentityEntityWithOperator
    private String servicePackageId;//服务包id
    private String servicePackageId;//服务包id
    @Column(name = "status")
    @Column(name = "status")
    private Integer status;//状态(0已中止,1进行中,2已完成)
    private Integer status;//状态(0已中止,1进行中,2已完成)
    @Column(name = "service_qr_code")
    private String serviceQrCode;//服务码
    public String getSaasId() {
    public String getSaasId() {
        return saasId;
        return saasId;
@ -104,4 +106,12 @@ public class PatientRehabilitationPlanDO extends UuidIdentityEntityWithOperator
    public void setStatus(Integer status) {
    public void setStatus(Integer status) {
        this.status = status;
        this.status = status;
    }
    }
    public String getServiceQrCode() {
        return serviceQrCode;
    }
    public void setServiceQrCode(String serviceQrCode) {
        this.serviceQrCode = serviceQrCode;
    }
}
}

+ 6 - 0
common/common-request-mapping/src/main/java/com/yihu/jw/rm/specialist/SpecialistMapping.java

@ -41,6 +41,10 @@ public class SpecialistMapping {
    }
    public static  class common{
        public static final String file_upload =  "/fileUpload";
    }
    }
    public static class screen{
    public static class screen{
@ -57,6 +61,8 @@ public class SpecialistMapping {
        public static final String findTemplateDetailByTemplateId = "/findTemplateDetailByTemplateId";
        public static final String findTemplateDetailByTemplateId = "/findTemplateDetailByTemplateId";
        public static final String updateRehabilitationTemplateDetail = "/updateRehabilitationTemplateDetail";
        public static final String updateRehabilitationTemplateDetail = "/updateRehabilitationTemplateDetail";
        public static final String createPatientRehabilitationPlan = "/createPatientRehabilitationPlan";
        public static final String createPatientRehabilitationPlan = "/createPatientRehabilitationPlan";
        public static final String createServiceQrCode ="/createServiceQrCode";
        public static final String checkAfterQrCode = "checkAfterQrCode";
    }
    }
}
}

+ 12 - 0
common/common-util/pom.xml

@ -37,6 +37,18 @@
            <groupId>org.slf4j</groupId>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <artifactId>slf4j-api</artifactId>
        </dependency>
        </dependency>
        <!--二维码生成 start-->
        <dependency>
            <groupId>com.google.zxing</groupId>
            <artifactId>core</artifactId>
            <version>${version.zxing}</version>
        </dependency>
        <dependency>
            <groupId>com.google.zxing</groupId>
            <artifactId>javase</artifactId>
            <version>${version.zxing}</version>
        </dependency>
        <!--二维码生成 end-->
        <dependency>
        <dependency>
            <groupId>com.yihu.jw</groupId>
            <groupId>com.yihu.jw</groupId>
            <artifactId>common-util</artifactId>
            <artifactId>common-util</artifactId>

+ 80 - 0
common/common-util/src/main/java/com/yihu/jw/util/common/QrcodeUtil.java

@ -0,0 +1,80 @@
package com.yihu.jw.util.common;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import java.io.*;
import java.util.HashMap;
import java.util.Map;
/**
 * Created by lyr on 2016/08/10.
 */
public class QrcodeUtil {
    /**
     * 二维码图片生成
     *
     * @param content 二维码内容
     * @param imgType 图片类型
     * @param size    图片尺寸
     * @return
     */
    public static File QrcodeEncode(String content, String fileName, String path, String imgType, int size) throws Exception {
        File pathFile = new File(path);
        File outputFile = new File(path + File.separator + fileName + ".png");
        if (!pathFile.exists()) {
            pathFile.mkdir();
        }
        if (outputFile.exists()) {
            outputFile.delete();
        }
        outputFile.createNewFile();
        Map<EncodeHintType, String> hints = new HashMap<EncodeHintType, String>();
        // 内容所使用字符集编码
        hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
        BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, size, size, hints);
        // 生成二维码
        MatrixToImageWriter.writeToFile(bitMatrix, imgType, outputFile);
        return outputFile;
    }
    /**
     * 创建二维码
     * @param content
     * @return
     */
    public static InputStream createQrcode(String content,int size,String imgType) {
        byte[] imagesStream=null;
        ByteArrayOutputStream os = null;
        try {
            HashMap<EncodeHintType, Object> hints = new HashMap<EncodeHintType, Object>();
            hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
            hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
            hints.put(EncodeHintType.MARGIN, 0);
            BitMatrix bitMatrix = new MultiFormatWriter().encode(content,
              BarcodeFormat.QR_CODE, size, size, hints);
             os = new ByteArrayOutputStream();
            MatrixToImageWriter.writeToStream(bitMatrix, imgType, os);
            return new ByteArrayInputStream(os.toByteArray());
        } catch (Exception e) {
            e.printStackTrace();
        }finally{
            if(os!=null){
                try {
                    os.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return null;
    }
}

+ 7 - 0
svr/svr-wlyy-specialist/pom.xml

@ -107,6 +107,13 @@
            <!--<artifactId>commons-util</artifactId>-->
            <!--<artifactId>commons-util</artifactId>-->
            <!--<version>1.1.0</version>-->
            <!--<version>1.1.0</version>-->
        <!--</dependency>-->
        <!--</dependency>-->
        <!-- jkzl starter -->
        <dependency>
            <groupId>com.yihu</groupId>
            <artifactId>fastdfs-starter</artifactId>
            <version>2.0.0</version>
        </dependency>
    </dependencies>
    </dependencies>
    <build>
    <build>

+ 268 - 0
svr/svr-wlyy-specialist/src/main/java/com/yihu/jw/controller/common/FileUploadController.java

@ -0,0 +1,268 @@
package com.yihu.jw.controller.common;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.yihu.fastdfs.FastDFSUtil;
import com.yihu.jw.restmodel.iot.common.UploadVO;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.rm.iot.IotRequestMapping;
import com.yihu.jw.rm.specialist.SpecialistMapping;
import com.yihu.jw.service.FileUploadService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import javax.servlet.http.HttpServletRequest;
import java.io.*;
import java.net.URLDecoder;
import java.util.Base64;
import java.util.Map;
/**
 * @author yeshijie on 2017/12/7.
 */
@RestController
@RequestMapping(SpecialistMapping.common.file_upload)
@Api(tags = "文件上传相关操作", description = "文件上传相关操作")
public class FileUploadController {
    @Autowired
    private FastDFSUtil fastDFSHelper;
    @Value("${fast-dfs.public-server}")
    private String fastdfs_file_url;
    @Autowired
    private FileUploadService fileUploadService;
    @Value("${neiwang.enable}")
    private Boolean isneiwang;  //如果不是内网项目要转到到内网在上传
    @Autowired
    protected HttpServletRequest request;
    /*@PostMapping(value = IotRequestMapping.FileUpload.api_upload_stream_img)
    @ApiOperation(value = "文件流上传图片", notes = "文件流上传图片")
    public MixEnvelop<UploadVO, UploadVO> uploadImg(@ApiParam(value = "文件", required = true)
                                       @RequestParam(value = "file", required = true) MultipartFile file){
        try {
            // 得到文件的完整名称  xxx.txt
            String fullName = file.getOriginalFilename();
            if(StringUtils.isBlank(fullName)){
                return MixEnvelop.getError(IotRequestMapping.FileUpload.message_fail_upload_format,IotRequestMapping.api_iot_fail);
            }
            //得到文件类型
            String fileType = fullName.substring(fullName.lastIndexOf(".") + 1).toLowerCase();
            if(StringUtils.isBlank(fileType)||!"jpg,jpeg,png".contains(fileType)){
                return MixEnvelop.getError(IotRequestMapping.FileUpload.message_fail_upload_format,IotRequestMapping.api_iot_fail);
            }
            long size = file.getSize();
            long max = 5*1024*1024;
            if(size>max){
                return MixEnvelop.getError("文件大小不超过5M",IotRequestMapping.api_iot_fail);
            }
            String fileName = fullName.substring(0, fullName.lastIndexOf("."));
            //上传到fastdfs
            ObjectNode objectNode = null;
            //解析返回的objectNode
            UploadVO uploadVO = null;
            if(isneiwang){
                objectNode = fastDFSHelper.upload(file.getInputStream(), fileType, "");
                uploadVO = new UploadVO();
                uploadVO.setFileName(fileName);
                uploadVO.setFileType(fileType);
                uploadVO.setFullUri(objectNode.get("fileId").toString().replaceAll("\"", ""));
                uploadVO.setFullUrl(fastdfs_file_url + objectNode.get("fileId").toString().replaceAll("\"", ""));
            }else {
                uploadVO = fileUploadService.request(request,file.getInputStream(),fullName);
                if(uploadVO==null){
                    return MixEnvelop.getError("文件上传失败",IotRequestMapping.api_iot_fail);
                }
            }
            return MixEnvelop.getSuccess(IotRequestMapping.Common.message_success_create, uploadVO);
        }catch (Exception e){
            e.printStackTrace();
            return MixEnvelop.getError(IotRequestMapping.FileUpload.message_fail_upload, IotRequestMapping.api_iot_fail);
        }
    }
    @PostMapping(value = IotRequestMapping.FileUpload.api_upload_stream_attachment)
    @ApiOperation(value = "文件流上传附件", notes = "文件流上传附件")
    public MixEnvelop<UploadVO, UploadVO> uploadAttachment(@ApiParam(value = "文件", required = true)
                                              @RequestParam(value = "file", required = true) MultipartFile file){
        try {
            // 得到文件的完整名称  xxx.txt
            String fullName = file.getOriginalFilename();
            if(StringUtils.isBlank(fullName)){
                return MixEnvelop.getError(IotRequestMapping.FileUpload.message_fail_upload_format,IotRequestMapping.api_iot_fail);
            }
            //得到文件类型
            String fileType = fullName.substring(fullName.lastIndexOf(".") + 1).toLowerCase();
            if(StringUtils.isBlank(fileType)||!"doc、docx、pdf、xls、xlsx、jpg、jpeg、png".contains(fileType)){
                return MixEnvelop.getError(IotRequestMapping.FileUpload.message_fail_upload_format,IotRequestMapping.api_iot_fail);
            }
            long size = file.getSize();
            long max = 5*1024*1024;
            if(size>max){
                return MixEnvelop.getError("文件大小不超过5M",IotRequestMapping.api_iot_fail);
            }
            String fileName = fullName.substring(0, fullName.lastIndexOf("."));
            //上传到fastdfs
            ObjectNode objectNode = null;
            //解析返回的objectNode
            UploadVO uploadVO = null;
            if(isneiwang){
                objectNode = fastDFSHelper.upload(file.getInputStream(), fileType, "");
                uploadVO = new UploadVO();
                uploadVO.setFileName(fileName);
                uploadVO.setFileType(fileType);
                uploadVO.setFullUri(objectNode.get("fileId").toString().replaceAll("\"", ""));
                uploadVO.setFullUrl(fastdfs_file_url + objectNode.get("fileId").toString().replaceAll("\"", ""));
            }else {
                uploadVO = fileUploadService.request(request,file.getInputStream(),fullName);
                if(uploadVO==null){
                    return MixEnvelop.getError("文件上传失败",IotRequestMapping.api_iot_fail);
                }
            }
            return MixEnvelop.getSuccess(IotRequestMapping.Common.message_success_create, uploadVO);
        }catch (Exception e){
            e.printStackTrace();
            return MixEnvelop.getError(IotRequestMapping.FileUpload.message_fail_upload, IotRequestMapping.api_iot_fail);
        }
    }
    @PostMapping(value = IotRequestMapping.FileUpload.api_upload_stream)
    @ApiOperation(value = "文件流上传文件", notes = "文件流上传文件")
    public MixEnvelop<UploadVO, UploadVO> uploadStream(@ApiParam(value = "文件", required = true) @RequestParam(value = "file", required = true) MultipartFile file) {
        try {
            // 得到文件的完整名称  xxx.txt
            String fullName = file.getOriginalFilename();
            //得到文件类型
            String fileType = fullName.substring(fullName.lastIndexOf(".") + 1).toLowerCase();
            String fileName = fullName.substring(0, fullName.lastIndexOf("."));
            //上传到fastdfs
            ObjectNode objectNode = null;
            //解析返回的objectNode
            UploadVO uploadVO = null;
            if(isneiwang){
                objectNode = fastDFSHelper.upload(file.getInputStream(), fileType, "");
                uploadVO = new UploadVO();
                uploadVO.setFileName(fileName);
                uploadVO.setFileType(fileType);
                uploadVO.setFullUri(objectNode.get("fileId").toString().replaceAll("\"", ""));
                uploadVO.setFullUrl(fastdfs_file_url + objectNode.get("fileId").toString().replaceAll("\"", ""));
            }else {
                uploadVO = fileUploadService.request(request,file.getInputStream(),fullName);
                if(uploadVO==null){
                    return MixEnvelop.getError("文件上传失败",IotRequestMapping.api_iot_fail);
                }
            }
            return MixEnvelop.getSuccess(IotRequestMapping.Common.message_success_create, uploadVO);
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError(IotRequestMapping.FileUpload.message_fail_upload, IotRequestMapping.api_iot_fail);
        }
    }
    @PostMapping(value = IotRequestMapping.FileUpload.api_upload_string)
    @ApiOperation(value = "base64上传图片",notes = "base64上传图片")
    public MixEnvelop<UploadVO, UploadVO> uploadImages(@ApiParam(name = "jsonData", value = "头像转化后的输入流") @RequestBody String jsonData) throws Exception {
        try {
            String date = URLDecoder.decode(jsonData,"UTF-8");
            String[] fileStreams = date.split(",");
            String is = URLDecoder.decode(fileStreams[1],"UTF-8").replace(" ","+");
            byte[] in = Base64.getDecoder().decode(is);
            InputStream inputStream = new ByteArrayInputStream(in);
            ObjectNode objectNode = null;
            //上传到fastdfs
            String fileType = "png";
            //解析返回的objectNode
            UploadVO uploadVO = null;
            if(isneiwang){
                objectNode = fastDFSHelper.upload(inputStream, fileType, "");
                String groupName = objectNode.get("groupName").toString();
                String remoteFileName = objectNode.get("remoteFileName").toString();
                uploadVO = new UploadVO();
                uploadVO.setFileName(remoteFileName);
                uploadVO.setFileType(groupName);
                uploadVO.setFullUri(objectNode.get("fileId").toString().replaceAll("\"", ""));
                uploadVO.setFullUrl(fastdfs_file_url + objectNode.get("fileId").toString().replaceAll("\"", ""));
            }else {
                uploadVO = fileUploadService.request(request,inputStream,"");
                if(uploadVO ==null){
                    return MixEnvelop.getError("文件上传失败",IotRequestMapping.api_iot_fail);
                }
            }
            //返回文件路径
            return MixEnvelop.getSuccess(IotRequestMapping.FileUpload.message_success_upload, uploadVO);
        }catch (Exception e){
            e.printStackTrace();
            return MixEnvelop.getError(IotRequestMapping.FileUpload.message_fail_upload, IotRequestMapping.api_iot_fail);
        }
    }*/
    @RequestMapping(value = "commonUpload", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("公共的文件上传")
    public MixEnvelop<UploadVO, UploadVO> commonUpload(HttpServletRequest request) {
        InputStream in = null;
        try {
            String paths = request.getParameter("filePaths");
            ObjectNode result = null;
            if (StringUtils.isBlank(paths)) {
                //为空是文件上传
                MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
                // 文件保存的临时路径
                Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
                String fileName = null;
                for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
                    // 上传文件
                    MultipartFile mf = entity.getValue();
                    fileName = mf.getOriginalFilename();
                    in = mf.getInputStream();
                    result = fastDFSHelper.upload(in, fileName.substring(fileName.lastIndexOf(".") + 1), "");
                }
            } else {
                String[] pathArr = paths.split(",");
                for (String path : pathArr) {
                    //传路径自己去路径上传
                    File file = new File(path);
                    String fileName = null;
                    if (file.exists()) {
                        fileName = file.getName();
                        in = new FileInputStream(file);
                        result = fastDFSHelper.upload(in, fileName.substring(fileName.lastIndexOf(".") + 1), "");
                    }
                }
            }
            //解析返回的objectNode
            UploadVO uploadVO = new UploadVO();
            uploadVO.setFullUri(result.get("fileId").toString().replaceAll("\"", ""));
            uploadVO.setFullUrl(fastdfs_file_url + result.get("fileId").toString().replaceAll("\"", ""));
            return MixEnvelop.getSuccess(IotRequestMapping.FileUpload.message_success_upload, result);
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError(IotRequestMapping.FileUpload.message_fail_upload, IotRequestMapping.api_iot_fail);
        }finally {
            if(in!=null){
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

+ 39 - 2
svr/svr-wlyy-specialist/src/main/java/com/yihu/jw/controller/rehabilitation/RehabilitationPlanController.java

@ -6,6 +6,7 @@ import com.yihu.jw.entity.specialist.rehabilitation.PatientRehabilitationPlanDO;
import com.yihu.jw.entity.specialist.rehabilitation.RehabilitationDetailDO;
import com.yihu.jw.entity.specialist.rehabilitation.RehabilitationDetailDO;
import com.yihu.jw.entity.specialist.rehabilitation.RehabilitationPlanTemplateDO;
import com.yihu.jw.entity.specialist.rehabilitation.RehabilitationPlanTemplateDO;
import com.yihu.jw.entity.specialist.rehabilitation.RehabilitationTemplateDetailDO;
import com.yihu.jw.entity.specialist.rehabilitation.RehabilitationTemplateDetailDO;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.specialist.SpecialistMapping;
import com.yihu.jw.rm.specialist.SpecialistMapping;
@ -37,8 +38,6 @@ public class RehabilitationPlanController extends EnvelopRestEndpoint {
    @Autowired
    @Autowired
    private Tracer tracer;
    private Tracer tracer;
    /******************************** 康复服务套餐模板 ****************************************/
    @PostMapping(value = SpecialistMapping.rehabilitation.createRehabilitationPlanTemplate)
    @PostMapping(value = SpecialistMapping.rehabilitation.createRehabilitationPlanTemplate)
    @ApiOperation(value = "康复服务套餐模板创建")
    @ApiOperation(value = "康复服务套餐模板创建")
    public MixEnvelop<String, String> createRehabilitationPlanTemplate(@ApiParam(name = "rehabilitationTemplate", value = "实体JSON")
    public MixEnvelop<String, String> createRehabilitationPlanTemplate(@ApiParam(name = "rehabilitationTemplate", value = "实体JSON")
@ -155,5 +154,43 @@ public class RehabilitationPlanController extends EnvelopRestEndpoint {
        }
        }
    }
    }
    @PostMapping(value = SpecialistMapping.rehabilitation.createServiceQrCode)
    @ApiOperation(value = "根据康复计划id和居民code生成服务码")
    public MixEnvelop<String,String> createServiceQrCode(@ApiParam(name = "planId", value = "计划居民关系唯一标识")@RequestParam(value = "planId", required = true)String planId,
                                                         @ApiParam(name = "patientCode", value = "居民code")@RequestParam(value = "patientCode", required = true)String patientCode){
        try {
            return rehabilitationPlanService.createServiceQrCode(planId,patientCode);
        }catch (Exception e){
            e.printStackTrace();
            tracer.getCurrentSpan().logEvent(e.getMessage());
            return MixEnvelop.getError(e.getMessage());
        }
    }
    @PostMapping(value = SpecialistMapping.rehabilitation.checkAfterQrCode)
    @ApiOperation(value = "居民扫码后验证是否是关联的居民扫码")
    public MixEnvelop<Boolean,Boolean> checkAfterQrCode(@ApiParam(name = "planId", value = "计划居民关系唯一标识")@RequestParam(value = "planId", required = true)String planId,
                                                         @ApiParam(name = "patientCode", value = "居民端登录的居民code")@RequestParam(value = "patientCode", required = true)String patientCode){
        try {
            String message="";
            Boolean flag = true;
            if (rehabilitationPlanService.checkAfterQrCode(planId,patientCode)==1){
                message = "验证成功!";
            }
            if (rehabilitationPlanService.checkAfterQrCode(planId,patientCode)==-1){
                message = "请相关居民扫描二维码";
                flag=false;
            }
            if (rehabilitationPlanService.checkAfterQrCode(planId,patientCode)==-10000){
                message = "相关康复管理数据错误,请联系工作人员!";
                flag=false;
            }
            return MixEnvelop.getSuccess(message,flag);
        }catch (Exception e){
            e.printStackTrace();
            tracer.getCurrentSpan().logEvent(e.getMessage());
            return MixEnvelop.getError(e.getMessage());
        }
    }
}
}

+ 3 - 1
svr/svr-wlyy-specialist/src/main/java/com/yihu/jw/dao/rehabilitation/PatientRehabilitationPlanDao.java

@ -1,7 +1,9 @@
package com.yihu.jw.dao.rehabilitation;
package com.yihu.jw.dao.rehabilitation;
import com.yihu.jw.entity.specialist.PatientHospitalRecordDO;
import com.yihu.jw.entity.specialist.rehabilitation.PatientRehabilitationPlanDO;
import com.yihu.jw.entity.specialist.rehabilitation.PatientRehabilitationPlanDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
/**
@ -9,5 +11,5 @@ import org.springframework.data.repository.PagingAndSortingRepository;
 */
 */
public interface PatientRehabilitationPlanDao extends PagingAndSortingRepository<PatientRehabilitationPlanDO, Long>,JpaSpecificationExecutor<PatientRehabilitationPlanDO> {
public interface PatientRehabilitationPlanDao extends PagingAndSortingRepository<PatientRehabilitationPlanDO, Long>,JpaSpecificationExecutor<PatientRehabilitationPlanDO> {
    PatientRehabilitationPlanDO findById(String id);
}
}

+ 91 - 0
svr/svr-wlyy-specialist/src/main/java/com/yihu/jw/service/FileUploadService.java

@ -0,0 +1,91 @@
package com.yihu.jw.service;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.restmodel.iot.common.UploadVO;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
/**
 * @author zhangdan on 2018/08/22.
 */
@Service
public class FileUploadService{
    @Value("${neiwang.wlyy}")
    private String neiwangWlyy;  //内网的项目地址
    /**
     * 通用的文件上传
     * @param request
     * @param in
     * @param fileName
     * @return
     */
    public UploadVO request(HttpServletRequest request, InputStream in, String fileName) {
        String url = neiwangWlyy + "/fileUpload/commonUpload";//uri请求路径 http://172.19.103.88/wlyy/upload/chat
        CloseableHttpClient httpClient = HttpClientBuilder.create().build();
        String result = "";
        UploadVO uploadVO = null;
        try {
            HttpPost httpPost = new HttpPost(url);
            MultipartEntityBuilder builder = MultipartEntityBuilder.create();
            builder.addBinaryBody("file", in, ContentType.MULTIPART_FORM_DATA, fileName);// 文件流
            builder.addTextBody("filename", fileName);// 类似浏览器表单提交,对应input的name和value
            if (!org.springframework.util.StringUtils.isEmpty(request.getParameter("type"))) {
                builder.addTextBody("type", request.getParameter("type")); //发送类型
            }
            HttpEntity entity = builder.build();
            httpPost.setEntity(entity);
            HttpResponse response = httpClient.execute(httpPost);// 执行提交
            HttpEntity responseEntity = response.getEntity();
            if (responseEntity != null) {
                // 将响应内容转换为字符串
                result = EntityUtils.toString(responseEntity, Charset.forName("UTF-8"));
            }
            JSONObject jsonObject = JSONObject.parseObject(result);
            if(jsonObject.getInteger("status")==200){
                JSONObject obj = jsonObject.getJSONObject("obj");
                uploadVO = new UploadVO();
                uploadVO.setFileName(obj.getString("groupName"));
                uploadVO.setFileType(obj.getString("remoteFileName"));
                uploadVO.setFullUri(obj.getString("fileId"));
                uploadVO.setFullUrl(obj.getString("fileUrl"));
            }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                httpClient.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return uploadVO;
    }
}

+ 82 - 0
svr/svr-wlyy-specialist/src/main/java/com/yihu/jw/service/rehabilitation/RehabilitationPlanService.java

@ -2,20 +2,32 @@ package com.yihu.jw.service.rehabilitation;
import com.yihu.jw.dao.rehabilitation.PatientRehabilitationPlanDao;
import com.yihu.jw.dao.rehabilitation.PatientRehabilitationPlanDao;
import com.yihu.jw.dao.rehabilitation.RehabilitationDetailDao;
import com.yihu.jw.dao.rehabilitation.RehabilitationDetailDao;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.yihu.jw.dao.rehabilitation.PatientRehabilitationPlanDao;
import com.yihu.jw.dao.rehabilitation.RehabilitationPlanTemplateDao;
import com.yihu.jw.dao.rehabilitation.RehabilitationPlanTemplateDao;
import com.yihu.jw.dao.rehabilitation.RehabilitationTemplateDetailDao;
import com.yihu.jw.dao.rehabilitation.RehabilitationTemplateDetailDao;
import com.yihu.jw.entity.specialist.rehabilitation.PatientRehabilitationPlanDO;
import com.yihu.jw.entity.specialist.rehabilitation.PatientRehabilitationPlanDO;
import com.yihu.jw.entity.specialist.rehabilitation.RehabilitationDetailDO;
import com.yihu.jw.entity.specialist.rehabilitation.RehabilitationDetailDO;
import com.yihu.jw.entity.specialist.rehabilitation.PatientRehabilitationPlanDO;
import com.yihu.jw.entity.specialist.rehabilitation.RehabilitationPlanTemplateDO;
import com.yihu.jw.entity.specialist.rehabilitation.RehabilitationPlanTemplateDO;
import com.yihu.jw.entity.specialist.rehabilitation.RehabilitationTemplateDetailDO;
import com.yihu.jw.entity.specialist.rehabilitation.RehabilitationTemplateDetailDO;
import com.yihu.jw.restmodel.iot.common.UploadVO;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.rm.specialist.SpecialistMapping;
import com.yihu.jw.rm.specialist.SpecialistMapping;
import com.yihu.jw.service.FileUploadService;
import com.yihu.jw.util.common.QrcodeUtil;
import com.yihu.fastdfs.FastDFSUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import javax.servlet.http.HttpServletRequest;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.Date;
import java.util.List;
import java.util.List;
@ -26,6 +38,10 @@ import java.util.List;
@Transactional
@Transactional
public class RehabilitationPlanService {
public class RehabilitationPlanService {
    @Value("${neiwang.enable}")
    private Boolean isneiwang;  //如果不是内网项目要转到到内网wlyy在上传
    @Value("${fastDFS.fastdfs_file_url}")
    private String fastdfs_file_url;
    @Autowired
    @Autowired
    private RehabilitationPlanTemplateDao templateDao;
    private RehabilitationPlanTemplateDao templateDao;
    @Autowired
    @Autowired
@ -36,6 +52,12 @@ public class RehabilitationPlanService {
    private RehabilitationDetailDao rehabilitationDetailDao;
    private RehabilitationDetailDao rehabilitationDetailDao;
    @Autowired
    @Autowired
    private JdbcTemplate jdbcTemplate;
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private FastDFSUtil fastDFSHelper;
    @Autowired
    private FileUploadService fileUploadService;
    @Autowired
    protected HttpServletRequest request;
    public MixEnvelop<String, String> createRehabilitationTemplate(RehabilitationPlanTemplateDO templateDO) {
    public MixEnvelop<String, String> createRehabilitationTemplate(RehabilitationPlanTemplateDO templateDO) {
        templateDO.setCreateTime(new Date());
        templateDO.setCreateTime(new Date());
@ -95,4 +117,64 @@ public class RehabilitationPlanService {
        }
        }
        return (List<RehabilitationDetailDO>)rehabilitationDetailDao.save(details);
        return (List<RehabilitationDetailDO>)rehabilitationDetailDao.save(details);
    }
    }
    public MixEnvelop<String,String> createServiceQrCode(String planId,String patientCode){
        PatientRehabilitationPlanDO patientRehabilitationPlanDO = patientRehabilitationPlanDao.findById(planId);
        String fileUrl = "";
        if (patientRehabilitationPlanDO!=null) {
            if (org.apache.commons.lang3.StringUtils.isNotBlank(patientRehabilitationPlanDO.getServiceQrCode())) {
                fileUrl = patientRehabilitationPlanDO.getServiceQrCode();
            } else {
                InputStream ipt = QrcodeUtil.createQrcode(planId+"|"+patientCode, 300, "png");
                isneiwang = false;
                if (isneiwang) {
                    // 圖片列表
                    List<String> tempPaths = new ArrayList<String>();
                    try {
                        ObjectNode imgNode = fastDFSHelper.upload(ipt, "png", "plan_service_qrcode" + System.currentTimeMillis());
                        com.alibaba.fastjson.JSONObject json = com.alibaba.fastjson.JSONObject.parseObject(imgNode.toString());
                        tempPaths.add(json.getString("fileId"));
                        String urls = "";
                        for (String image : tempPaths) {
                            if (urls.length() == 0) {
                                urls = image;
                            } else {
                                urls += "," + image;
                            }
                        }
                        fileUrl = fastdfs_file_url + urls;
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                } else {
                    try {
                        UploadVO uploadVO = fileUploadService.request(request, ipt, "png");
                        if (uploadVO!=null){
                            fileUrl = uploadVO.getFullUrl();
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                //更新到康复计划居民关系表中
                String sql = "update wlyy_patient_rehabilitation_plan set service_qr_code='" + fileUrl + "' where id='" + planId + "'";
                jdbcTemplate.update(sql);
            }
        }
        return MixEnvelop.getSuccess("获取二维码成功!",fileUrl);
    }
    public Integer checkAfterQrCode(String planId,String patietCode){
        int result = 0;
        PatientRehabilitationPlanDO patientRehabilitationPlanDO =  patientRehabilitationPlanDao.findById(planId);
        if (patientRehabilitationPlanDO!=null){
            if (StringUtils.pathEquals(patientRehabilitationPlanDO.getPatient(),patietCode)){
                result =200;
            }else {
                result = -1;
            }
        }else {
            result = -10000;
        }
        return result;
    }
}
}

+ 32 - 0
svr/svr-wlyy-specialist/src/main/resources/application.yml

@ -77,6 +77,14 @@ spring:
fastDFS:
fastDFS:
  fastdfs_file_url: http://172.19.103.54:80/
  fastdfs_file_url: http://172.19.103.54:80/
fast-dfs:
  tracker-server: 172.19.103.54:22122
  public-server: http://172.19.103.54:80/
neiwang:
  enable: true
  wlyy: http://localhost:10051/
---
---
spring:
spring:
  profiles: jwtest
  profiles: jwtest
@ -87,6 +95,14 @@ spring:
    password: ssgg
    password: ssgg
fastDFS:
fastDFS:
  fastdfs_file_url: http://172.19.103.54:80/
  fastdfs_file_url: http://172.19.103.54:80/
fast-dfs:
  tracker-server: 172.19.103.54:22122
  public-server: http://172.19.103.54:80/
neiwang:
  enable: false
  wlyy: http://59.61.92.90:10051/
---
---
spring:
spring:
  profiles: jwdevtest
  profiles: jwdevtest
@ -97,6 +113,14 @@ spring:
    password: linzhou
    password: linzhou
fastDFS:
fastDFS:
  fastdfs_file_url: http://172.19.103.54:80/
  fastdfs_file_url: http://172.19.103.54:80/
fast-dfs:
  tracker-server: 172.19.103.54:22122
  public-server: http://172.19.103.54:80/
neiwang:
  enable: true
  #wlyy: http://172.19.103.88:10051/svr-slyy-specialist/
---
---
spring:
spring:
  profiles: prod
  profiles: prod
@ -106,3 +130,11 @@ spring:
    password: jkzlehr@123
    password: jkzlehr@123
fastDFS:
fastDFS:
  fastdfs_file_url: http://172.19.103.54:80/
  fastdfs_file_url: http://172.19.103.54:80/
fast-dfs:
  #tracker-server: 172.19.103.54:22122
  #public-server: http://172.19.103.54:80/
neiwang:
  enable: false
  #wlyy: http://59.61.92.90:9099/iot/

+ 2 - 0
wlyy-parent-pom/pom.xml

@ -93,6 +93,8 @@
        <version.joda-time>2.8.2</version.joda-time>
        <version.joda-time>2.8.2</version.joda-time>
        <version.yihu.admin>1.2.0</version.yihu.admin>
        <version.yihu.admin>1.2.0</version.yihu.admin>
        <version.spring-boot-admin>1.5.7</version.spring-boot-admin>
        <version.spring-boot-admin>1.5.7</version.spring-boot-admin>
        <version.zxing>3.2.0</version.zxing>
        <version.fastdfs>1.25</version.fastdfs>
        <!-- Version end -->
        <!-- Version end -->
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>