Browse Source

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

shikejing 4 years ago
parent
commit
67c26df325

+ 17 - 20
svr/svr-door-serivce/src/main/java/com/yihu/jw/door/controller/doctor/DoorOrderController.java

@ -11,6 +11,7 @@ import com.yihu.jw.door.service.WlyyDoorServiceOrderService;
import com.yihu.jw.door.service.common.HospitalService;
import com.yihu.jw.door.service.common.ServerPackageService;
import com.yihu.jw.door.service.prescription.JwDoorPrescriptionService;
import com.yihu.jw.door.util.StreamUtil;
import com.yihu.jw.entity.door.WlyyDoorConclusionDO;
import com.yihu.jw.entity.door.WlyyDoorServiceOrderDO;
import com.yihu.jw.restmodel.ResponseContant;
@ -1246,28 +1247,24 @@ public class DoorOrderController extends BaseController {
            response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
            OutputStream os = response.getOutputStream();
            //获取相对路径
            String pathName = DoorOrderController.class.getResource("/").getPath().replaceFirst("/", "");
            pathName = pathName.replace("target/classes/", "src/main/resources/conclusion.mht");
//            String pathName = DoorOrderController.class.getResource("/").getPath().replaceFirst("/", "");
//            pathName = pathName.replace("target/classes/", "src/main/resources/conclusion.mht");
//            Document doc = Jsoup.parse(new File(pathName), "UTF-8");
            String txt = "";
            ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
            Resource[] resources = resolver.getResources("/conclusion.mht");
            Resource resource = resources[0];
//获得文件流,因为在jar文件中,不能直接通过文件资源路径拿到文件,但是可以在jar包中拿到文件流
            InputStream stream = resource.getInputStream();
            StringBuilder buffer = new StringBuilder();
            byte[] bytes = new byte[1024];
            try {
                for (int n; (n = stream.read(bytes)) != -1; ) {
                    buffer.append(new String(bytes, 0, n));
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            txt = buffer.toString();
            System.out.println("txt ===== " + txt);
            Document aa = Jsoup.parse(txt,"UTF-8");
//            String txt =     StreamUtil.readResources();
//            ByteArrayInputStream ins = new ByteArrayInputStream(txt.getBytes());
//            File file = new File("conclusion.mht");
//            OutputStream os1 = new FileOutputStream(file);
//            int bytesRead = 0;
//            byte[] buffer1 = new byte[8192];
//            while ((bytesRead = ins.read(buffer1, 0, 8192)) != -1) {
//                os1.write(buffer1, 0, bytesRead);
//            }
//            os1.close();
//            ins.close();
//            Document aa = Jsoup.parse(file,"UTF-8");
            Document aa = Jsoup.parse(StreamUtil.readResources());
            String html = doorOrderService.handleData(aa,orderId);
            byte b[] = html.getBytes();
            ByteArrayInputStream bais = new ByteArrayInputStream(b);

+ 42 - 0
svr/svr-door-serivce/src/main/java/com/yihu/jw/door/util/StreamUtil.java

@ -0,0 +1,42 @@
package com.yihu.jw.door.util;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import java.io.IOException;
import java.io.InputStream;
/***
 * @ClassName: StreamUtil
 * @Description:
 * @Auther: shi kejing
 * @Date: 2021/1/5 19:40
 */
public class StreamUtil {
    /**
     *   jar包,读取resources配置
     *   /conclusion.mht    :resources下文件路径以及文件名
     * @return
     * @throws IOException
     */
    public static String readResources() throws IOException {
        ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
        Resource[] resources = resolver.getResources("/conclusion.mht");
        Resource resource = resources[0];
//获得文件流,因为在jar文件中,不能直接通过文件资源路径拿到文件,但是可以在jar包中拿到文件流
        InputStream stream = resource.getInputStream();
        StringBuilder buffer = new StringBuilder();
        byte[] bytes = new byte[1024];
        try {
            for (int n; (n = stream.read(bytes)) != -1; ) {
                buffer.append(new String(bytes, 0, n));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return buffer.toString();
    }
}