Kaynağa Gözat

身份证上传优化

lihong 1 yıl önce
ebeveyn
işleme
d10b1a1fb7

+ 31 - 31
src/main/java/cn/hnthyy/thmz/Utils/WindowsUtil.java

@@ -1,31 +1,33 @@
 package cn.hnthyy.thmz.Utils;
 
+import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.io.resource.ClassPathResource;
+import cn.hutool.core.io.resource.ResourceUtil;
+import com.sun.image.codec.jpeg.JPEGCodec;
+import com.sun.image.codec.jpeg.JPEGEncodeParam;
+import com.sun.image.codec.jpeg.JPEGImageEncoder;
+import sun.misc.BASE64Decoder;
+
+import javax.imageio.ImageIO;
+import javax.imageio.stream.FileImageInputStream;
+import javax.swing.*;
 import java.awt.*;
 import java.awt.font.TextAttribute;
-import java.awt.image.*;
-import java.io.*;
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URL;
 import java.text.AttributedCharacterIterator;
 import java.text.AttributedString;
 import java.util.ArrayList;
-import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.Scanner;
-
-import javax.imageio.ImageIO;
-import javax.imageio.stream.FileImageInputStream;
-import javax.imageio.stream.FileImageOutputStream;
-import javax.swing.ImageIcon;
-
-import org.apache.commons.codec.binary.Base64;
-import org.springframework.util.ResourceUtils;
-import sun.misc.BASE64Decoder;
-import sun.misc.BASE64Encoder;
-
-import com.sun.image.codec.jpeg.JPEGCodec;
-import com.sun.image.codec.jpeg.JPEGEncodeParam;
-import com.sun.image.codec.jpeg.JPEGImageEncoder;
 
 public class WindowsUtil {
 
@@ -39,7 +41,7 @@ public class WindowsUtil {
      * @author zhongweihai newwei2001@yahoo.com.cn
      */
     public boolean createMark(String filePath, String outFile,
-                              List<Map<String, Object>> list, Boolean needPic) throws IOException {
+                              List<Map<String, Object>> list, Boolean needPic,String rootFilePath) throws IOException {
         ImageIcon imgIcon = new ImageIcon(filePath);
         Image theImg = imgIcon.getImage();
         int width = theImg.getWidth(null);
@@ -52,7 +54,7 @@ public class WindowsUtil {
             add(g, bimage, list.get(i));
         }
         if (needPic) {
-            BufferedImage content = ImageIO.read(new File(ResourceUtils.getFile("classpath:images") + "\\tx\\tx1.jpg"));
+            BufferedImage content = ImageIO.read(new File( rootFilePath+ "\\tx\\tx1.jpg"));
             // byte[] outImage= makeColorTransparent(content, new Color(254, 254, 254));
             g.drawImage(content.getScaledInstance(150, 180, Image.SCALE_DEFAULT), 320, 50, null);
         }
@@ -101,7 +103,7 @@ public class WindowsUtil {
      * @param idNum
      * @return
      */
-    public static boolean generateIdcodeZ(String name, String gender, String nation, String year, String month, String day, String address, String idNum) {
+    public static boolean generateIdcodeZ(String name, String gender, String nation, String year, String month, String day, String address, String idNum,String filePath) {
         boolean bool = false;
         try {
             WindowsUtil wm = new WindowsUtil();
@@ -196,10 +198,10 @@ public class WindowsUtil {
             map.put("fontType", "微软雅黑");
             map.put("fontSize", 24);
             list.add(map);
-            file1 = ResourceUtils.getFile("classpath:images") + "\\sfzzm.jpg";
-            String path = ResourceUtils.getFile("classpath:images") + "\\idcode";
+            file1 =  filePath + "\\sfzzm.jpg";
+            String path =  filePath + "\\idcode";
             createDir(path);
-            wm.createMark(file1, path + "\\idz.jpg", list, true);
+            wm.createMark(file1, path + "\\idz.jpg", list, true,filePath);
             // Thread.sleep(200);
             //bool = generateIdcodeF(wm, ResourceUtils.getFile("classpath:images") + "\\idcode\\idf.jpg", "安仁县公安局");
         } catch (Exception e) {
@@ -217,7 +219,7 @@ public class WindowsUtil {
      * @param ress
      * @return
      */
-    public static boolean generateIdcodeF(WindowsUtil wm, String tager, String ress) {
+    public static boolean generateIdcodeF(WindowsUtil wm, String tager, String ress,String filePath) {
         boolean bool = false;
         try {
             List<Map<String, Object>> list = new ArrayList<>();
@@ -238,7 +240,7 @@ public class WindowsUtil {
             map.put("fontType", "微软雅黑");
             map.put("fontSize", 18);
             list.add(map);
-            wm.createMark(file2, tager, list, false);
+            wm.createMark(file2, tager, list, false,filePath);
             bool = true;
             System.out.println("证件反面照【" + tager + "】生成成功");
         } catch (Exception e) {
@@ -308,7 +310,7 @@ public class WindowsUtil {
      * 将base64位的头像转为头像
      * @param imgStr
      */
-    public static void generateImage(String imgStr) {
+    public static void generateImage(String imgStr,String filePath) {
         if (imgStr == null) {
             return;
         } // 图像数据为空
@@ -323,7 +325,8 @@ public class WindowsUtil {
                     b[i] += 256;
                 }
             }
-            String filePath=ResourceUtils.getFile("classpath:images") + "\\tx";
+            //String filePath=ResourceUtils.getFile("classpath:images") + "\\tx";
+            filePath = filePath+ "\\tx";
             createDir(filePath);
             out = new FileOutputStream(filePath + "\\tx.jpg");
             out.write(b);
@@ -386,7 +389,4 @@ public class WindowsUtil {
 
 
 
-
-
-
 }

+ 10 - 5
src/main/java/cn/hnthyy/thmz/controller/mz/PatientMiSzController.java

@@ -11,6 +11,7 @@ import cn.hutool.core.collection.CollUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.util.ResourceUtils;
 import org.springframework.web.bind.annotation.*;
 import java.util.HashMap;
@@ -22,7 +23,11 @@ import java.util.Map;
 public class PatientMiSzController {
     @Autowired
     private PatientMiSfzService patientMiSfzService;
+    @Autowired
     private APatientMiService aPatientMiService;
+    @Value("${filepath.profile}")
+    private String filepath;
+
     /**
      * 查询用户的身份证信息
      * @return
@@ -142,12 +147,12 @@ public class PatientMiSzController {
                 resultMap.put("message", "门诊号不能为空");
                 return resultMap;
             }
-            WindowsUtil.generateImage(patientMiSfz.getTxImageBase64());
-            WindowsUtil.convert(ResourceUtils.getFile("classpath:images") + "\\tx\\tx.jpg",ResourceUtils.getFile("classpath:images") + "\\tx\\tx1.jpg");
-            patientMiSfz.setTxImage(WindowsUtil.image2byte(ResourceUtils.getFile("classpath:images") + "\\tx","tx1.jpg"));
+            WindowsUtil.generateImage(patientMiSfz.getTxImageBase64(),filepath);
+            WindowsUtil.convert(filepath + "\\tx\\tx.jpg",filepath + "\\tx\\tx1.jpg");
+            patientMiSfz.setTxImage(WindowsUtil.image2byte(filepath  + "\\tx","tx1.jpg"));
             String [] arr = patientMiSfz.getBirthDay().split("-");
-            WindowsUtil.generateIdcodeZ(patientMiSfz.getName(), GenderEnum.MAN.code.toString().equals(patientMiSfz.getSex())?GenderEnum.MAN.name:GenderEnum.WOMAN.name,patientMiSfz.getNation(),arr[0],arr[1],arr[2],patientMiSfz.getAddress(),patientMiSfz.getSocialNo());
-            patientMiSfz.setSfzImage(WindowsUtil.image2byte(ResourceUtils.getFile("classpath:images") + "\\idcode","idz.jpg"));
+            WindowsUtil.generateIdcodeZ(patientMiSfz.getName(), GenderEnum.MAN.code.toString().equals(patientMiSfz.getSex())?GenderEnum.MAN.name:GenderEnum.WOMAN.name,patientMiSfz.getNation(),arr[0],arr[1],arr[2],patientMiSfz.getAddress(),patientMiSfz.getSocialNo(),filepath);
+            patientMiSfz.setSfzImage(WindowsUtil.image2byte(filepath  + "\\idcode","idz.jpg"));
             patientMiSfz.setBirthDay(arr[0]+"年"+arr[1]+"月"+arr[2]+"日");
             int num = patientMiSfzService.savePatientMiSfz(patientMiSfz);
             if (num == 0) {

+ 4 - 1
src/main/java/cn/hnthyy/thmz/controller/mz/ZyReqController.java

@@ -19,6 +19,7 @@ import cn.hnthyy.thmz.service.his.mz.MzPatientMiService;
 import cn.hnthyy.thmz.service.his.mz.MzZyReqService;
 import cn.hnthyy.thmz.service.his.zd.ZdUnitCodeService;
 import cn.hnthyy.thmz.service.thmz.UserDeptRelationService;
+import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.StrUtil;
 import lombok.extern.slf4j.Slf4j;
@@ -81,7 +82,9 @@ public class ZyReqController {
                     result.addAll(temp);
                 }
             }
-
+            result.forEach(item->{
+                BeanUtil.trimStrFields(item);
+            });
             if (CollUtil.isEmpty(result)) {
                 resultMap.put("code", -1);
                 resultMap.put("message", "查询病人的住院证失败,当前病人没有对应的住院证");

+ 2 - 2
src/main/resources/application-dev.yml

@@ -175,6 +175,6 @@ misPossUrl:  "http://172.16.32.201:8080/ccbmis/transaction/"
 
 #调用医保药品更新最新报销比例测试地址
 hiDrugPostUrl: "http://172.16.30.26:8706/nationalMatch/queryPsnPayProp?hiListCode="
-#( Windows配置,Linux配置 /home/thmz/uploadPath)
+#( Windows配置,Linux配置 /home/thmz_system/uploadPath)
 filepath:
-  profile: D:/thmz/uploadPath
+  profile: D:\thmz_system\uploadPath

+ 4 - 1
src/main/resources/application-prod.yml

@@ -169,4 +169,7 @@ rationalUseOfMedicineUrl: "http://172.16.32.121:8016/Audit.ashx"
 misPossUrl: "http://172.16.32.201:8080/ccbmis/transaction/"
 
 #调用医保药品更新最新报销比例地址
-hiDrugPostUrl: "http://webhis.thyy.cn:8077/nationalMatch/queryPsnPayProp?hiListCode="
+hiDrugPostUrl: "http://webhis.thyy.cn:8077/nationalMatch/queryPsnPayProp?hiListCode="
+#( Windows配置,Linux配置 /home/thmz_system/uploadPath)
+filepath:
+  profile: D:\thmz_system\uploadPath