ruoyi-admin/src/main/java/com/ruoyi/web/test/MQTest.java
@@ -3,13 +3,16 @@ import com.alibaba.fastjson2.JSONObject; import com.ruoyi.common.config.RuoYiConfig; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.utils.RSAPublicKeyExample; import com.ruoyi.common.utils.file.FileUploadUtils; import com.ruoyi.common.utils.file.FileUtils; import com.ruoyi.common.utils.http.HttpUtils; import com.smartor.domain.ServiceSubtaskDetail; import com.smartor.domain.ThiedInhospInfo; import com.smartor.service.IHNGatherPatArchiveService; import io.swagger.models.auth.In; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.mock.web.MockMultipartFile; import org.springframework.web.multipart.MultipartFile; @@ -32,6 +35,8 @@ //@SpringBootTest //@RunWith(SpringRunner.class) public class MQTest { @Autowired private IHNGatherPatArchiveService ihnGatherPatArchiveService; @Test public void testSend22() { @@ -54,9 +59,16 @@ @Test public void bb() { String wxCode="{\"code\":\"0\",\"succ\":true}"; Map<String, Object> map = JSONObject.parseObject(wxCode, Map.class); System.out.println(map); Boolean aBoolean = ihnGatherPatArchiveService.hnDataGather(null); } @Test public void cc() { RSAPublicKeyExample rsaPublicKeyExample = new RSAPublicKeyExample(); String s = rsaPublicKeyExample.encryptedData("1012320966", "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALQzqW1EIXBKGMu+2oEYSB5gM7Ox/ihyYTeeoE0yPX1qtt4++5yNOeTBVd6EEM4iKzVEzWj6REIWVwaSNPn/SvUCAwEAAQ=="); System.out.println("加密结果为:" + s); String s1 = rsaPublicKeyExample.decryptedData(s, "MIIBUwIBADANBgkqhkiG9w0BAQEFAASCAT0wggE5AgEAAkEAtDOpbUQhcEoYy77agRhIHmAzs7H+KHJhN56gTTI9fWq23j77nI055MFV3oQQziIrNUTNaPpEQhZXBpI0+f9K9QIDAQABAkB3n0fcWfrcoMN/FU3VnrnZOEF6CzFNxkgU9P8y36QECWKZ9JhYQkNpKrMC9oXlN3VSaRigV7B+L/I/a0Rs1W+tAiEA4jx7xcXJ4y4BNwAmVHt6NNiEkzIwWnwC/0qsEu8NsOsCIQDL6MMn1D2uznC6OuOWpxDCkBh1JL1NzZTZeH2G+hj7nwIgKGAC9tjFnvWm4dn0/T7MIIJDpsFeP8fCAS2iZ/6hwuECIAS/eLvWr1EAsZNEh8QcQ8GkBU3E+ztyjAK8UX/xFt/VAiBf79/1tDErX4/DChecM8w3c3DhbBcjuE3fHZn7p6/UKg=="); System.out.println("解密结果为:"+s1); } public void aa(MultipartFile file) throws IOException { ruoyi-common/src/main/java/com/ruoyi/common/core/domain/BaseEntity.java
@@ -54,6 +54,26 @@ private String orgid; private Integer pageNum; private Integer pageSize; public Integer getPageNum() { return pageNum; } public Integer getPageSize() { return pageSize; } public void setPageSize(Integer pageSize) { this.pageSize = pageSize; } public void setPageNum(Integer pageNum) { this.pageNum = pageNum; } public String getOrgid() { return orgid; } ruoyi-common/src/main/java/com/ruoyi/common/utils/RSAPublicKeyExample.java
@@ -19,37 +19,71 @@ @Component public class RSAPublicKeyExample { /** * 数据解密 * * @param encryptedData * @return */ public String decryptedData(String encryptedData, String pri_key) { String privateKeyString = "私钥的Base64编码字符串"; // 后端私钥的Base64编码字符串 try { // 将私钥Base64编码字符串转换为PrivateKey对象 byte[] privateKeyBytes = Base64.getDecoder().decode(pri_key); PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(privateKeyBytes); KeyFactory keyFactory = KeyFactory.getInstance("RSA"); PrivateKey privateKey = keyFactory.generatePrivate(keySpec); // 使用私钥解密数据 Cipher decryptCipher = Cipher.getInstance("RSA"); decryptCipher.init(Cipher.DECRYPT_MODE, privateKey); byte[] decryptedBytes = decryptCipher.doFinal(Base64.getDecoder().decode(encryptedData)); // 解密后的数据 String decryptedData = new String(decryptedBytes); System.out.println("解密后的数据:" + decryptedData); return decryptedData; } catch (Exception e) { log.error("解密报错了:{}", e.getMessage()); } return null; } // // /** // * 数据解密 // * // * @param encryptedData // * @return // */ // public String decryptedData(String encryptedData, String pri_key) { // String privateKeyString = "私钥的Base64编码字符串"; // 后端私钥的Base64编码字符串 // // try { // // 将私钥Base64编码字符串转换为PrivateKey对象 // byte[] privateKeyBytes = Base64.getDecoder().decode(pri_key); // PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(privateKeyBytes); // KeyFactory keyFactory = KeyFactory.getInstance("RSA"); // PrivateKey privateKey = keyFactory.generatePrivate(keySpec); // // // 使用私钥解密数据 // Cipher decryptCipher = Cipher.getInstance("RSA"); // decryptCipher.init(Cipher.DECRYPT_MODE, privateKey); // byte[] decryptedBytes = decryptCipher.doFinal(Base64.getDecoder().decode(encryptedData)); // // // 解密后的数据 // String decryptedData = new String(decryptedBytes); // System.out.println("解密后的数据:" + decryptedData); // return decryptedData; // } catch (Exception e) { // log.error("解密报错了:{}", e.getMessage()); // } // return null; // } // // /** // * 要加密的明文数据 // * // * @param plainText // * @return // */ // public String encryptedData(String plainText, String pub_key) { // log.info("需要加密的数据:{}", plainText); // try { // // byte[] publicKeyBytes = Base64.getDecoder().decode(pub_key); // X509EncodedKeySpec keySpec = new X509EncodedKeySpec(publicKeyBytes); // KeyFactory keyFactory = KeyFactory.getInstance("RSA"); // PublicKey publicKey = keyFactory.generatePublic(keySpec); // // // 使用公钥加密数据 // Cipher encryptCipher = Cipher.getInstance("RSA"); // encryptCipher.init(Cipher.ENCRYPT_MODE, publicKey); // byte[] encryptedBytes = encryptCipher.doFinal(plainText.getBytes()); // // // 将加密后的数据转换为Base64编码的字符串 // String encryptedText = Base64.getEncoder().encodeToString(encryptedBytes); // log.info("Base64加密后的数据:{}", encryptedText); // encryptedText = URLEncoder.encode(encryptedText, StandardCharsets.UTF_8.toString()); // log.info("URLEncoder编码后的数据:{}", encryptedText); // String decodedString = URLDecoder.decode(encryptedText, "UTF-8"); // log.info("URLEncoder解码后的数据:{}", decodedString); // return encryptedText; // } catch (Exception e) { // log.error("加密失败了:{}", e.getMessage()); // } // return null; // } /** * 要加密的明文数据 @@ -58,29 +92,50 @@ * @return */ public String encryptedData(String plainText, String pub_key) { log.info("需要加密的数据:{}", plainText); try { byte[] publicKeyBytes = Base64.getDecoder().decode(pub_key); X509EncodedKeySpec keySpec = new X509EncodedKeySpec(publicKeyBytes); KeyFactory keyFactory = KeyFactory.getInstance("RSA"); PublicKey publicKey = keyFactory.generatePublic(keySpec); // 使用公钥加密数据 Cipher encryptCipher = Cipher.getInstance("RSA"); Cipher encryptCipher = Cipher.getInstance("RSA/ECB/PKCS1Padding"); encryptCipher.init(Cipher.ENCRYPT_MODE, publicKey); byte[] encryptedBytes = encryptCipher.doFinal(plainText.getBytes()); byte[] encryptedBytes = encryptCipher.doFinal(plainText.getBytes(StandardCharsets.UTF_8)); // 将加密后的数据转换为Base64编码的字符串 String encryptedText = Base64.getEncoder().encodeToString(encryptedBytes); log.info("Base64加密后的数据:{}", encryptedText); encryptedText = URLEncoder.encode(encryptedText, StandardCharsets.UTF_8.toString()); log.info("URLEncoder编码后的数据:{}", encryptedText); String decodedString = URLDecoder.decode(encryptedText, "UTF-8"); log.info("URLEncoder解码后的数据:{}", decodedString); return encryptedText; // URL Safe Base64 编码 return Base64.getUrlEncoder().encodeToString(encryptedBytes); } catch (Exception e) { log.error("加密失败了:{}", e.getMessage()); log.error("加密失败: {}", e.getMessage()); } return null; } /** * 数据解密 * * @param encryptedData * @return */ public String decryptedData(String encryptedData, String pri_key) { try { // 将私钥Base64编码字符串转换为PrivateKey对象 byte[] privateKeyBytes = Base64.getDecoder().decode(pri_key); PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(privateKeyBytes); KeyFactory keyFactory = KeyFactory.getInstance("RSA"); PrivateKey privateKey = keyFactory.generatePrivate(keySpec); // URL Safe Base64 解码 byte[] cipherBytes = Base64.getUrlDecoder().decode(encryptedData); // 使用私钥解密数据 Cipher decryptCipher = Cipher.getInstance("RSA/ECB/PKCS1Padding"); decryptCipher.init(Cipher.DECRYPT_MODE, privateKey); byte[] decryptedBytes = decryptCipher.doFinal(cipherBytes); return new String(decryptedBytes, StandardCharsets.UTF_8); } catch (Exception e) { log.error("解密失败: {}", e.getMessage()); } return null; } ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml
@@ -123,9 +123,12 @@ u left join sys_dept d on u.dept_id = d.dept_id where u.del_flag = '0' <if test="userId != null and userId != 0"> <if test="userId != null"> AND u.user_id = #{userId} </if> <if test="orgid != null and orgid != ''"> AND u.orgid = #{orgid} </if> <if test="userName != null and userName != ''"> AND u.user_name like concat('%', #{userName}, '%') </if> smartor/src/main/java/com/smartor/service/impl/PatMedOuthospServiceImpl.java
@@ -1,5 +1,9 @@ package com.smartor.service.impl; import java.time.LocalDate; import java.time.Period; import java.time.ZoneId; import java.time.temporal.ChronoUnit; import java.util.*; import com.ruoyi.common.core.domain.entity.SysDept; @@ -11,6 +15,7 @@ import com.smartor.domain.*; import com.smartor.mapper.*; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.ObjectUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.smartor.service.IPatMedOuthospService; @@ -64,9 +69,74 @@ @Override public List<PatMedOuthosp> selectPatMedOuthospList(PatMedOuthosp patMedOuthosp) { List<PatMedOuthosp> patMedOuthosps = patMedOuthospMapper.selectPatMedOuthospList(patMedOuthosp); for (PatMedOuthosp patMedOuthosp1 : patMedOuthosps) { PatArchive patArchive = patArchiveMapper.selectPatArchiveByPatid(patMedOuthosp1.getPatid()); if (patArchive.getBirthdate() != null) { Map<String, String> map = calculateAge(patArchive.getBirthdate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(), LocalDate.now()); patArchive.setAge(ObjectUtils.isNotEmpty(map.get("age")) ? Long.valueOf(map.get("age")) : null); patArchive.setAgeUnit(map.get("ageUnit")); patArchive.setAge2(ObjectUtils.isNotEmpty(map.get("age2")) ? Long.valueOf(map.get("age2")) : null); patArchive.setAgeUnit2(map.get("ageUnit2")); patMedOuthosp1.setAge(patArchive.getAge() + patArchive.getAgeUnit() + patArchive.getAge2() + patArchive.getAgeUnit2()); patMedOuthosp1.setTelcode(patArchive.getTelcode()); patMedOuthosp1.setIdcardno(patArchive.getIdcardno()); } } return patMedOuthosps; } public Map<String, String> calculateAge(LocalDate birthdate, LocalDate today) { if (birthdate == null || today.isBefore(birthdate)) { return null; } Map<String, String> ageMap = new HashMap<>(); Period period = Period.between(birthdate, today); long totalDays = ChronoUnit.DAYS.between(birthdate, today); long totalMonths = ChronoUnit.MONTHS.between(birthdate, today); int years = period.getYears(); int months = period.getMonths(); int days = period.getDays(); String ageUnit; Integer age; String ageUnit2 = null; Integer age2 = null; if (totalDays < 30) { // 小于 1 个月,按天计算 ageUnit = "天"; age = (int) totalDays; ageMap.put("age", age != null ? age.toString() : null); ageMap.put("ageUnit", ageUnit); ageMap.put("age2", null); ageMap.put("ageUnit2", null); } else if (totalMonths < 12) { // 小于 一年,按月 + 天计算 ageUnit = "月"; age = (int) totalMonths; ageUnit2 = "天"; age2 = days; ageMap.put("age", age != null ? age.toString() : null); ageMap.put("ageUnit", ageUnit); ageMap.put("age2", age2 != null ? age2.toString() : null); ageMap.put("ageUnit2", ageUnit2); } else { // 大于等于 一年,按年 + 月计算 ageUnit = "岁"; age = years; ageUnit2 = "月"; age2 = months; ageMap.put("age", age != null ? age.toString() : null); ageMap.put("ageUnit", ageUnit); ageMap.put("age2", age2 != null ? age2.toString() : null); ageMap.put("ageUnit2", ageUnit2); } return ageMap; } /** * 新增患者门诊记录 * smartor/src/main/java/com/smartor/service/impl/ServiceExternalServiceImpl.java
@@ -891,6 +891,19 @@ patMedOuthosp.setOuthospno(externalInHospPatientInfo.getBingAnHao()); patMedOuthosp.setSerialnum(externalInHospPatientInfo.getJiuZhenYWID()); List<PatMedOuthosp> patMedOuthosps = patMedOuthospMapper.selectPatMedOuthospList(patMedOuthosp); for (PatMedOuthosp patMedOuthosp1 : patMedOuthosps) { PatArchive pa = patArchiveMapper.selectPatArchiveByPatid(patMedOuthosp1.getPatid()); if (patArchive.getBirthdate() != null) { Map<String, String> map = calculateAge(pa.getBirthdate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(), LocalDate.now()); pa.setAge(ObjectUtils.isNotEmpty(map.get("age")) ? Long.valueOf(map.get("age")) : null); pa.setAgeUnit(map.get("ageUnit")); pa.setAge2(ObjectUtils.isNotEmpty(map.get("age2")) ? Long.valueOf(map.get("age2")) : null); pa.setAgeUnit2(map.get("ageUnit2")); patMedOuthosp1.setAge(pa.getAge() + pa.getAgeUnit() + pa.getAge2() + pa.getAgeUnit2()); patMedOuthosp1.setTelcode(patArchive.getTelcode()); patMedOuthosp1.setIdcardno(patArchive.getIdcardno()); } } patMedOuthosp.setPatid(patArchive.getId()); patMedOuthosp.setPatno(externalInHospPatientInfo.getBingAnHao()); smartor/src/main/resources/mapper/smartor/PatMedOuthospMapper.xml
@@ -113,11 +113,8 @@ pmo.hpi, pmo.fuflag, pmo.patname, CONCAT(pa.age,pa.age_unit,pa.age2,pa.age_unit2) AS age, pa.telcode, pmo.mainsuit, pa.idcardno from pat_med_outhosp pmo left join pat_archive pa on pmo.patid = pa.id pmo.mainsuit from pat_med_outhosp pmo <where> pmo.del_flag=0 <if test="orgid != null ">and pmo.orgid = #{orgid}</if> @@ -135,6 +132,7 @@ date_format(#{endTime},'%y%m%d') </if> <if test="patid != null ">and pmo.patid = #{patid}</if> <if test="serialnum != null ">and pmo.serialnum = #{serialnum}</if> <if test="fuflag != null ">and pmo.fuflag = #{fuflag}</if> <if test="patno != null ">and pmo.patno = #{patno}</if> <if test="outhospno != null and outhospno != ''">and pmo.outhospno = #{outhospno}</if>