From add5fecbca9a8792bca8ee69af3e9497b9639e27 Mon Sep 17 00:00:00 2001 From: yewj Date: Fri, 8 Nov 2024 15:35:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=A4=87=E4=BB=BD=EF=BC=8C?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=85=B3=E8=81=94=E5=85=B3=E7=B3=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 5 ++ .../mipsdl/client/sjpwxyy/SjpwxyyClient.java | 4 ++ .../mipsdl/dao/basic/RelCodeDetailMapper.java | 9 ++++ .../mipsdl/entity/basic/RelCodeDetail.java | 47 +++++++++++++++++++ .../service/basic/RelCodeDetailService.java | 39 +++++++++++++++ .../java/com/glxp/mipsdl/util/DdlUtils.java | 27 +++++++++++ .../java/com/glxp/mipsdl/util/GMEncrypt.java | 44 +++++++++++++++++ .../master/basic/RelCodeDetailMapper.xml | 18 +++++++ 8 files changed, 193 insertions(+) create mode 100644 src/main/java/com/glxp/mipsdl/dao/basic/RelCodeDetailMapper.java create mode 100644 src/main/java/com/glxp/mipsdl/entity/basic/RelCodeDetail.java create mode 100644 src/main/java/com/glxp/mipsdl/service/basic/RelCodeDetailService.java create mode 100644 src/main/java/com/glxp/mipsdl/util/DdlUtils.java create mode 100644 src/main/java/com/glxp/mipsdl/util/GMEncrypt.java create mode 100644 src/main/resources/mybatis/mapper/master/basic/RelCodeDetailMapper.xml diff --git a/pom.xml b/pom.xml index 91ed9b6..c05df81 100644 --- a/pom.xml +++ b/pom.xml @@ -167,6 +167,11 @@ bcprov 1.6.0 + + net.java.dev.jna + jna + 5.11.0 + diff --git a/src/main/java/com/glxp/mipsdl/client/sjpwxyy/SjpwxyyClient.java b/src/main/java/com/glxp/mipsdl/client/sjpwxyy/SjpwxyyClient.java index be86383..88bf603 100644 --- a/src/main/java/com/glxp/mipsdl/client/sjpwxyy/SjpwxyyClient.java +++ b/src/main/java/com/glxp/mipsdl/client/sjpwxyy/SjpwxyyClient.java @@ -1916,6 +1916,10 @@ public class SjpwxyyClient extends CommonHttpClient { List drugTraceList = new ArrayList<>(); // 遍历fruits数组 for (String code : codes) { + + //todo + + DrugInfoRequest request = new DrugInfoRequest(); request.setDrug_trac_codg(code); drugTraceList.add(request); diff --git a/src/main/java/com/glxp/mipsdl/dao/basic/RelCodeDetailMapper.java b/src/main/java/com/glxp/mipsdl/dao/basic/RelCodeDetailMapper.java new file mode 100644 index 0000000..a172ecb --- /dev/null +++ b/src/main/java/com/glxp/mipsdl/dao/basic/RelCodeDetailMapper.java @@ -0,0 +1,9 @@ +package com.glxp.mipsdl.dao.basic; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.glxp.mipsdl.entity.basic.RelCodeDetail; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface RelCodeDetailMapper extends BaseMapper { +} \ No newline at end of file diff --git a/src/main/java/com/glxp/mipsdl/entity/basic/RelCodeDetail.java b/src/main/java/com/glxp/mipsdl/entity/basic/RelCodeDetail.java new file mode 100644 index 0000000..955bde8 --- /dev/null +++ b/src/main/java/com/glxp/mipsdl/entity/basic/RelCodeDetail.java @@ -0,0 +1,47 @@ +package com.glxp.mipsdl.entity.basic; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import java.io.Serializable; +import lombok.Data; + +@Data +@TableName(value = "rel_code_detail") +public class RelCodeDetail implements Serializable { + @TableId(value = "id", type = IdType.INPUT) + private Integer id; + + /** + * 当前条码 + */ + @TableField(value = "curCode") + private String curCode; + + /** + * 包装级别 + */ + @TableField(value = "packLayer") + private Byte packLayer; + + /** + * 父级码 + */ + @TableField(value = "parentCode") + private String parentCode; + + /** + * 状态 + */ + @TableField(value = "flag") + private Byte flag; + + /** + * 产品批次ID外键 + */ + @TableField(value = "batchIdFk") + private Integer batchIdFk; + + private static final long serialVersionUID = 1L; +} \ No newline at end of file diff --git a/src/main/java/com/glxp/mipsdl/service/basic/RelCodeDetailService.java b/src/main/java/com/glxp/mipsdl/service/basic/RelCodeDetailService.java new file mode 100644 index 0000000..3d61893 --- /dev/null +++ b/src/main/java/com/glxp/mipsdl/service/basic/RelCodeDetailService.java @@ -0,0 +1,39 @@ +package com.glxp.mipsdl.service.basic; + +import cn.hutool.core.collection.CollUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.glxp.mipsdl.entity.basic.RelCodeDetail; +import com.glxp.mipsdl.dao.basic.RelCodeDetailMapper; + +@Service +public class RelCodeDetailService extends ServiceImpl { + /** + * 获取下级所有码 + * + * @return + */ + public List getAllNext(String code) { + List list = new ArrayList<>(); + fetchAllChildren(code, list); + return list; + } + + private void fetchAllChildren(String code, List list) { + List relCodeDetails = this.baseMapper.selectList( + new LambdaQueryWrapper().eq(RelCodeDetail::getParentCode, code)); + + if (CollUtil.isNotEmpty(relCodeDetails)) { + list.addAll(relCodeDetails); + for (RelCodeDetail relCodeDetail : relCodeDetails) { + fetchAllChildren(relCodeDetail.getCurCode(), list); + } + } + } +} diff --git a/src/main/java/com/glxp/mipsdl/util/DdlUtils.java b/src/main/java/com/glxp/mipsdl/util/DdlUtils.java new file mode 100644 index 0000000..ec0799c --- /dev/null +++ b/src/main/java/com/glxp/mipsdl/util/DdlUtils.java @@ -0,0 +1,27 @@ +package com.glxp.mipsdl.util; + +import cn.hutool.core.util.StrUtil; +import com.sun.tools.javac.Main; + +public class DdlUtils { + static { +// String path = System.getProperty("user.dir"); +// path = path + "/dll/hsafsiyhsafe.dll"; +// System.out.println(path); + System.loadLibrary("hsafsiyhsafe"); // + } + + public native int gm_ecb_encrypt_key(String pub_key, String plain, int plain_len, String cipher); + + public native int gm_ecb_decrypt_key(String pub_key, String cipher, int cipher_len, String plain); + + + public static void main(String[] args) { + DdlUtils ddlUtils = new DdlUtils(); + String key = "D7F322E4541DB0C48EB7B0AF2093BEE3F1AC6A3FAB1BDE30E72816571EEC50B7"; + String code = "H51072700564"; + String data = ""; + ddlUtils.gm_ecb_decrypt_key(code, key, key.length(), data); + } + +} diff --git a/src/main/java/com/glxp/mipsdl/util/GMEncrypt.java b/src/main/java/com/glxp/mipsdl/util/GMEncrypt.java new file mode 100644 index 0000000..68e61c8 --- /dev/null +++ b/src/main/java/com/glxp/mipsdl/util/GMEncrypt.java @@ -0,0 +1,44 @@ +package com.glxp.mipsdl.util; + +import com.sun.jna.Native; + +/** + * @author AnthonyYwj + * @date 2024/11/6 + */ + + +import com.sun.jna.Library; +import com.sun.jna.Native; + +import java.nio.charset.StandardCharsets; + +public interface GMEncrypt { + // 定义接口,映射 DLL 中的函数 + public interface GMEncryptLibrary extends Library { + GMEncryptLibrary INSTANCE = (GMEncryptLibrary) Native.load("hsafsiyhsafe", GMEncryptLibrary.class); + + // 映射 gm_ecb_encrypt_key 函数 + int gm_ecb_encrypt_key(byte[] pub_key, byte[] plain, int plain_len, byte[] cipher); + int gm_ecb_decrypt_key(byte[] pub_key, byte[] plain, int plain_len, byte[] cipher); + } + + public static void main(String[] args) { + // 准备输入数据 + String pubKeyStr = "D7F322E4541DB0C48EB7B0AF2093BEE3F1AC6A3FAB1BDE30E72816571EEC50B7"; + byte[] plain = "test plaintext".getBytes(); + int plainLen = plain.length; + byte[] cipher = new byte[1024]; // cipher 大小依据加密算法决定 + + // 调用加密方法 + int result = GMEncryptLibrary.INSTANCE.gm_ecb_encrypt_key(pubKeyStr.getBytes(StandardCharsets.UTF_8), plain, plainLen, cipher); + + // 输出结果 + if (result == 0) { + System.out.println("Encryption successful!"); + System.out.println("Encrypted data: " + new String(cipher)); + } else { + System.out.println("Encryption failed with error code: " + result); + } + } +} diff --git a/src/main/resources/mybatis/mapper/master/basic/RelCodeDetailMapper.xml b/src/main/resources/mybatis/mapper/master/basic/RelCodeDetailMapper.xml new file mode 100644 index 0000000..9b932d2 --- /dev/null +++ b/src/main/resources/mybatis/mapper/master/basic/RelCodeDetailMapper.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + id, curCode, packLayer, parentCode, flag, batchIdFk + + \ No newline at end of file