liusheng
2024-09-04 9526971c403417c1c007804f24884c443b9e6cd7
ruoyi-admin/src/main/java/com/ruoyi/web/test/MQTest.java
@@ -1,94 +1,173 @@
package com.ruoyi.web.test;
import com.ruoyi.web.task.PhoneTask;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.smartor.domain.ThiedInhospInfo;
import org.junit.Test;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import java.security.*;
import java.security.spec.PKCS8EncodedKeySpec;
import java.util.Base64;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.lang.reflect.Type;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
//@SpringBootTest
//@RunWith(SpringRunner.class)
public class MQTest {
    @Autowired
    private RabbitTemplate rabbitTemplate;
    @Test
    public void testSend() {
        try {
            // 生成RSA密钥对
            KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
            keyPairGenerator.initialize(2048);
            KeyPair keyPair = keyPairGenerator.generateKeyPair();
            // 获取公钥和私钥
            PublicKey publicKey = keyPair.getPublic();
            PrivateKey privateKey = keyPair.getPrivate();
            String publicKeyString = Base64.getEncoder().encodeToString(privateKey.getEncoded());
            System.out.println(publicKeyString);
            // 明文
            String plainText = "Hello, World!";
            // 加密
            Cipher encryptCipher = Cipher.getInstance("RSA");
            encryptCipher.init(Cipher.ENCRYPT_MODE, publicKey);
            byte[] encryptedBytes = encryptCipher.doFinal(plainText.getBytes());
            // 将加密后的数据转换为Base64编码的字符串
            String encryptedText = Base64.getEncoder().encodeToString(encryptedBytes);
            System.out.println("加密后的数据:" + encryptedText);
            // 解密
            Cipher decryptCipher = Cipher.getInstance("RSA");
            decryptCipher.init(Cipher.DECRYPT_MODE, privateKey);
            byte[] decryptedBytes = decryptCipher.doFinal(Base64.getDecoder().decode(encryptedBytes));
            // 明文
            String decryptedText = new String(decryptedBytes);
            System.out.println("解密后的数据:" + decryptedText);
        } catch (Exception e) {
        }
//        String str = "absdf";
//        String c = Character.toUpperCase(str.charAt(0)) + str.substring(1);
//        System.out.println(c);
        "您好,我是浙二医院张医生,您是${name}吗?还是家属?".replaceAll("$$*variable", "AA");
//        Pattern pattern = Pattern.compile("^(?!.*(好|太好)).*$");
//        Matcher matcher = pattern.matcher("睡眠不好");
//        System.out.println(matcher.matches());
        // 创建固定大小的线程池
//        ExecutorService executorService = Executors.newFixedThreadPool(10);
//
//        executorService.submit(new PhoneTask());
    }
    String result="{\n" +
            "    \"code\": \"0\",\n" +
            "    \"message\": \"success\",\n" +
            "    \"data\": {\n" +
            "        \"result\": ["+
            " {\n" +
            "                \"admissDeptName\": \"测试科室\",\n" +
            "                \"patiTypeId\": \"22\",\n" +
            "                \"companyTelNum\": \"\",\n" +
            "                \"currDeptCode\": \"1024\",\n" +
            "                \"currWardCode\": \"1331\",\n" +
            "                \"patiIdCardNo\": \"\",\n" +
            "                \"PatiHomeAddr\": \"浙江省杭州市拱墅区\",\n" +
            "                \"patiMediaId\": \"69674\",\n" +
            "                \"admissBedNo\": \"\",\n" +
            "                \"patiBirthday\": \"2009-03-03 00:00:00\",\n" +
            "                \"Education\": null,\n" +
            "                \"nationalityAddr\": \"\",\n" +
            "                \"admissWardCode\": \"1331\",\n" +
            "                \"doctId\": \"6af3708533e645edb10a655cabead79f\",\n" +
            "                \"inpatientId\": \"2403000055\",\n" +
            "                \"ProfessionId\": \"\",\n" +
            "                \"admissWardId\": \"7f95c670151746bca580c866ae56cfeb\",\n" +
            "                \"doctName\": \"测试医生\",\n" +
            "                \"currBedId\": \"7aeeb24077b1434d8f2b6ccb204f9159\",\n" +
            "                \"diagName\": \"僵\",\n" +
            "                \"currWardName\": \"测试病区\",\n" +
            "                \"totalAmount\": 0.00,\n" +
            "                \"admissWardName\": \"测试病区\",\n" +
            "                \"contactPersonName\": null,\n" +
            "                \"patiMediaNo\": \"024000070\",\n" +
            "                \"patiIndex\": \"024000070\",\n" +
            "                \"diagIcd10\": \"M20.200\",\n" +
            "                \"admissDeptCode\": \"1024\",\n" +
            "                \"patiRecordGender\": \"女\",\n" +
            "                \"patiNatureId\": \"22\",\n" +
            "                \"treateAge\": 15,\n" +
            "                \"suggestAmount\": \"\",\n" +
            "                \"contactPersonAddr\": null,\n" +
            "                \"contactPersonPhone\": null,\n" +
            "                \"admissBedId\": \"\",\n" +
            "                \"treatAgeunit\": \"岁\",\n" +
            "                \"currBedNo\": \"T-003\",\n" +
            "                \"PatiNation\": \"汉族\",\n" +
            "                \"patiRecordName\": \"既往3-5\",\n" +
            "                \"currDeptId\": \"416a047536b411e7bff40242ac103005\",\n" +
            "                \"outWayName\": null,\n" +
            "                \"RelationShip\": \"\",\n" +
            "                \"admitFormId\": null,\n" +
            "                \"patiNatureName\": \"非记账医保\",\n" +
            "                \"PatiNationality\": \"中国\",\n" +
            "                \"outDate\": null,\n" +
            "                \"admissDeptId\": \"416a047536b411e7bff40242ac103005\",\n" +
            "                \"admissDate\": \"2024-03-05 14:33:00\",\n" +
            "                \"currStatus\": 2,\n" +
            "                \"DocName\": \"\",\n" +
            "                \"patiTypeName\": \"非记账医保\",\n" +
            "                \"currDeptName\": \"测试科室\",\n" +
            "                \"currWardId\": \"7f95c670151746bca580c866ae56cfeb\",\n" +
            "                \"areaId\": \"\",\n" +
            "                \"PatiMaritalStatus\": null,\n" +
            "                \"PatiHomePhone\": \"\",\n" +
            "                \"preoutDate\": null,\n" +
            "                \"outWayId\": null,\n" +
            "                \"inhospitalTimes\": 3,\n" +
            "                \"patiRecordId\": \"69409\",\n" +
            "                \"age\": \"15岁\",\n" +
            "                \"diagId\": \"314216\"\n" +
            "            },\n" +
            "            {\n" +
            "                \"admissDeptName\": \"测试科室\",\n" +
            "                \"patiTypeId\": \"22\",\n" +
            "                \"companyTelNum\": \"\",\n" +
            "                \"currDeptCode\": \"1024\",\n" +
            "                \"currWardCode\": \"1331\",\n" +
            "                \"patiIdCardNo\": \"330106198001030057\",\n" +
            "                \"PatiHomeAddr\": \"浙江省杭州市西湖区\",\n" +
            "                \"patiMediaId\": \"69675\",\n" +
            "                \"admissBedNo\": \"\",\n" +
            "                \"patiBirthday\": \"1980-01-03 00:00:00\",\n" +
            "                \"Education\": null,\n" +
            "                \"nationalityAddr\": \"\",\n" +
            "                \"admissWardCode\": \"1331\",\n" +
            "                \"doctId\": \"7d3f0eaaec304bbfad8a8471998e38e4\",\n" +
            "                \"inpatientId\": \"2403000056\",\n" +
            "                \"ProfessionId\": \"\",\n" +
            "                \"admissWardId\": \"7f95c670151746bca580c866ae56cfeb\",\n" +
            "                \"doctName\": \"住院病历\",\n" +
            "                \"currBedId\": \"377f94ca047e4786aef56a1ac22678b7\",\n" +
            "                \"diagName\": \"瘟病\",\n" +
            "                \"currWardName\": \"测试病区\",\n" +
            "                \"totalAmount\": 0.00,\n" +
            "                \"admissWardName\": \"测试病区\",\n" +
            "                \"contactPersonName\": \"\",\n" +
            "                \"patiMediaNo\": \"024000071\",\n" +
            "                \"patiIndex\": \"024000071\",\n" +
            "                \"diagIcd10\": \"A01.03.01.\",\n" +
            "                \"admissDeptCode\": \"1024\",\n" +
            "                \"patiRecordGender\": \"男\",\n" +
            "                \"patiNatureId\": \"22\",\n" +
            "                \"treateAge\": 44,\n" +
            "                \"suggestAmount\": \"\",\n" +
            "                \"contactPersonAddr\": \"\",\n" +
            "                \"contactPersonPhone\": \"\",\n" +
            "                \"admissBedId\": \"\",\n" +
            "                \"treatAgeunit\": \"岁\",\n" +
            "                \"currBedNo\": \"T-006\",\n" +
            "                \"PatiNation\": \"汉族\",\n" +
            "                \"patiRecordName\": \"担保金额01\",\n" +
            "                \"currDeptId\": \"416a047536b411e7bff40242ac103005\",\n" +
            "                \"outWayName\": null,\n" +
            "                \"RelationShip\": \"\",\n" +
            "                \"admitFormId\": null,\n" +
            "                \"patiNatureName\": \"非记账医保\",\n" +
            "                \"PatiNationality\": \"中国\",\n" +
            "                \"outDate\": null,\n" +
            "                \"admissDeptId\": \"416a047536b411e7bff40242ac103005\",\n" +
            "                \"admissDate\": \"2024-03-07 14:04:00\",\n" +
            "                \"currStatus\": 2,\n" +
            "                \"DocName\": \"\",\n" +
            "                \"patiTypeName\": \"非记账医保\",\n" +
            "                \"currDeptName\": \"测试科室\",\n" +
            "                \"currWardId\": \"7f95c670151746bca580c866ae56cfeb\",\n" +
            "                \"areaId\": \"\",\n" +
            "                \"PatiMaritalStatus\": null,\n" +
            "                \"PatiHomePhone\": \"\",\n" +
            "                \"preoutDate\": null,\n" +
            "                \"outWayId\": null,\n" +
            "                \"inhospitalTimes\": 1,\n" +
            "                \"patiRecordId\": \"69410\",\n" +
            "                \"age\": \"44岁\",\n" +
            "                \"diagId\": \"1000040\"\n" +
            "            }\n" +
            "        ],\n" +
            "        \"hasNext\": false\n" +
            "    }\n" +
            "}";
    @Test
    public void testSend22() {
        try {
            byte[] privateKeyBytes = Base64.getDecoder().decode("");
            PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(privateKeyBytes);
            KeyFactory keyFactory = KeyFactory.getInstance("RSA");
            PrivateKey privateKey = keyFactory.generatePrivate(keySpec);
        Gson gson = new Gson();
        JsonObject jsonObject = gson.fromJson(result, JsonObject.class);
        JsonArray resultArray = jsonObject.getAsJsonObject("data").getAsJsonArray("result");
            // 使用私钥解密数据
            Cipher decryptCipher = Cipher.getInstance("RSA");
            decryptCipher.init(Cipher.DECRYPT_MODE, privateKey);
            byte[] decryptedBytes = decryptCipher.doFinal(Base64.getDecoder().decode(""));
            // 解密后的数据
            String decryptedData = new String(decryptedBytes);
            System.out.println("解密后的数据:" + decryptedData);
        } catch (Exception e) {
        }
        // 定义 ResultItem 的类型
        Type resultType = new TypeToken<List<ThiedInhospInfo>>() {}.getType();
        List<ThiedInhospInfo> resultList = gson.fromJson(resultArray, resultType);
        System.out.println(resultList);
    }
}