فهرست منبع

Merge branch 'dev' of http://192.168.1.220:10080/Amoy2/wlyy2.0 into dev

# Conflicts:
#	business/base-service/src/main/java/com/yihu/jw/hospital/prescription/service/PrescriptionService.java
wangzhinan 4 سال پیش
والد
کامیت
9b121d3af5

+ 30 - 27
business/base-service/src/main/java/com/yihu/jw/hospital/prescription/service/PrescriptionService.java

@ -10762,33 +10762,36 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
                            baseNatAppointmentDO.setCancelTime(new Date());
                            baseNatAppointmentDO.setCancelBy(patientId);
                            baseNatAppointmentDao.save(baseNatAppointmentDO);
                            //删除处方
                            logger.info("删除处方开始");
                            net.sf.json.JSONObject jsondate = new JSONObject();
                            jsondate.put("checkPart","鼻/咽拭子");
                            jsondate.put("cardNo",baseNatAppointmentDO.getMedicare());
                            jsondate.put("chargeFlag","2");
                            jsondate.put("chargeCode","361322");
                            jsondate.put("icdCode","Z00.000");
                            jsondate.put("socialNo",baseNatAppointmentDO.getCardNo());
                            jsondate.put("tellPhone",baseNatAppointmentDO.getMobile());
                            jsondate.put("address1",baseNatAppointmentDO.getProvinceName());
                            jsondate.put("address2",baseNatAppointmentDO.getCityName());
                            jsondate.put("address3",baseNatAppointmentDO.getTownName());
                            jsondate.put("address4",baseNatAppointmentDO.getStreetName());
                            jsondate.put("address5",2);
                            jsondate.put("area",baseNatAppointmentDO.getAddress());
                            jsondate.put("winNo",6);
                            jsondate.put("target",2);
                            jsondate.put("quantity",1);
                            jsondate.put("serialNo",baseNatAppointmentDO.getRegisterNo());
                            jsondate.put("dept",baseNatAppointmentDO.getDept());
                            jsondate.put("doctor",baseNatAppointmentDO.getDoctorId());
                            jsondate.put("realOrder",baseNatAppointmentDO.getRealOrder());
                            JSONArray array = new JSONArray();
                            array.add(jsondate);
                            JSONObject object1  = entranceService.BS10112(array.toString(),demoFlag);
                            logger.info("删除处方结束");
                            if (StringUtils.isNoneBlank(baseNatAppointmentDO.getRealOrder())){
                                //删除处方
                                logger.info("删除处方开始");
                                net.sf.json.JSONObject jsondate = new JSONObject();
                                jsondate.put("checkPart","鼻/咽拭子");
                                jsondate.put("cardNo",baseNatAppointmentDO.getMedicare());
                                jsondate.put("chargeFlag","2");
                                jsondate.put("chargeCode","361322");
                                jsondate.put("icdCode","Z00.000");
                                jsondate.put("socialNo",baseNatAppointmentDO.getCardNo());
                                jsondate.put("tellPhone",baseNatAppointmentDO.getMobile());
                                jsondate.put("address1",baseNatAppointmentDO.getProvinceName());
                                jsondate.put("address2",baseNatAppointmentDO.getCityName());
                                jsondate.put("address3",baseNatAppointmentDO.getTownName());
                                jsondate.put("address4",baseNatAppointmentDO.getStreetName());
                                jsondate.put("address5",2);
                                jsondate.put("area",baseNatAppointmentDO.getAddress());
                                jsondate.put("winNo",6);
                                jsondate.put("target",2);
                                jsondate.put("quantity",1);
                                jsondate.put("serialNo",baseNatAppointmentDO.getRegisterNo());
                                jsondate.put("dept",baseNatAppointmentDO.getDept());
                                jsondate.put("doctor",baseNatAppointmentDO.getDoctorId());
                                jsondate.put("realOrder",baseNatAppointmentDO.getRealOrder());
                                JSONArray array = new JSONArray();
                                array.add(jsondate);
                                JSONObject object1  = entranceService.BS10112(array.toString(),demoFlag);
                                logger.info("删除处方结束");
                            }
                        }
                    }

+ 168 - 0
business/base-service/src/main/java/com/yihu/jw/utils/AES.java

@ -0,0 +1,168 @@
package com.yihu.jw.utils;
import com.yihu.jw.utils.encode.Base64;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.security.NoSuchAlgorithmException;
public class AES {
    public static String encrypt(String strKey, String strIn) {
        try {
            SecretKeySpec skeySpec = getKey(strKey);
            Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
            IvParameterSpec iv = new IvParameterSpec(
                    "0102030405060708".getBytes());
            cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv);
            byte[] encrypted = cipher.doFinal(strIn.getBytes("UTF-8"));
            return Base64.encode(encrypted);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    public static String decrypt(String strKey, String strIn) throws Exception {
        try {
            SecretKeySpec skeySpec = getKey(strKey);
            Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
            IvParameterSpec iv = new IvParameterSpec(
                    "0102030405060708".getBytes());
            cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv);
            byte[] encrypted1 = Base64.decode(strIn);
            byte[] original = cipher.doFinal(encrypted1);
            String originalString = new String(original, "UTF-8");
            return originalString;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    private static SecretKeySpec getKey(String strKey) throws Exception {
        byte[] arrBTmp = strKey.getBytes();
        byte[] arrB = new byte[16]; // 创建一个空的16位字节数组(默认值为0)
        for (int i = 0; i < arrBTmp.length && i < arrB.length; i++) {
            arrB[i] = arrBTmp[i];
        }
        SecretKeySpec skeySpec = new SecretKeySpec(arrB, "AES");
        return skeySpec;
    }
    /**
     * 随机生成秘钥
     */
    public static void generateKey(){
        try {
            KeyGenerator kg = KeyGenerator.getInstance("AES");
            kg.init(128);//要生成多少位,只需要修改这里即可128, 192或256
            SecretKey sk = kg.generateKey();
            byte[] b = sk.getEncoded();
            String s = byteToHexString(b);
            System.out.println(s);
            System.out.println("十六进制密钥长度为"+s.length());
            System.out.println("二进制密钥的长度为"+s.length()*4);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            System.out.println("没有此算法。");
        }
    }
    /**
     * byte数组转化为16进制字符串
     * @param bytes
     * @return
     */
    public static String byteToHexString(byte[] bytes){
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < bytes.length; i++) {
            String strHex=Integer.toHexString(bytes[i]);
            if(strHex.length() > 3){
                sb.append(strHex.substring(6));
            } else {
                if(strHex.length() < 2){
                    sb.append("0" + strHex);
                } else {
                    sb.append(strHex);
                }
            }
        }
        return  sb.toString();
    }
    public static String signConvertToPara(String region) {
        String target = "";
        if (region != null) {
            target = region.replaceAll("\\+", "%2B").replaceAll("\\ ", "%20")
                    .replaceAll("\\/", "%2F").replaceAll("\\?", "%3F")
                    .replaceAll("\\#", "%23").replaceAll("\\&", "%26")
                    .replaceAll("\\=", "%3D");
        }
        return target;
    }
    public static String paraConvertsign(String region) {
        String target = "";
        if (region != null) {
            target = region.replaceAll("%2B", "+").replaceAll("%20", " ")
                    .replaceAll("%2F", "/").replaceAll("%3F", "?")
                    .replaceAll("%25", "%").replaceAll("%23", "#")
                    .replaceAll("%26", "&").replaceAll("%3D", "=");
        }
        return target;
    }
    //用于和c#互通的加解密
    //https://www.jianshu.com/p/9483c9ea3a04
    /**
     * AES的加密函数
     * @param str 传入需要加密的字符
     * @param key 传入一个16位长度的密钥。否则报错
     * @return 执行成功返回加密结果,否则报错
     * @throws Exception 抛出一个加密异常
     */
    public static String aesEncrypt(String str, String key) throws Exception {
        if (str == null || key == null) return null;
        Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
        cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(key.getBytes("utf-8"), "AES"));
        byte[] bytes = cipher.doFinal(str.getBytes("utf-8"));
        return new BASE64Encoder().encode(bytes);
    }
    /**
     * AES的解密函数
     * @param str 传入需要解密的字符
     * @param key 传入一个16位长度的密钥。否则报错
     * @return 执行成功返回加密结果,否则报错
     * @throws Exception 抛出一个解密异常
     */
    public static String aesDecrypt(String str, String key) throws Exception {
        if (str == null || key == null) return null;
        Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
        cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(key.getBytes("utf-8"), "AES"));
        byte[] bytes = new BASE64Decoder().decodeBuffer(str);
        bytes = cipher.doFinal(bytes);
        return new String(bytes, "utf-8");
    }
    public static void main(String[] args) throws Exception {
        generateKey();
        String testKey = "xmxzzxtj";
        String testEn = AES.encrypt(testKey, "{'function':'healthExam','yyid00':'220006','userId':'','name':'','phone':'','identityCard':'','icCard':''}");
        System.out.println(testEn);
        String testDe = AES.decrypt(testKey, testEn);
        System.out.println(testDe);
    }
}