From 8c4dd7ee60fcbfdcc4bd2cdfa60335d2a3591d7a Mon Sep 17 00:00:00 2001 From: chenhc <2369838784@qq.com> Date: Tue, 7 Jan 2025 11:34:45 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E6=9A=82=E6=97=B6=E5=8F=96=E6=B6=88?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1,=E6=89=8B=E5=8A=A8?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E9=9C=80=E8=A6=81=E6=9B=B4=E6=96=B0=E7=9A=84?= =?UTF-8?q?=E9=98=BF=E9=87=8C=E6=95=B0=E6=8D=AE=E8=BF=9B=E8=A1=8C=E5=86=99?= =?UTF-8?q?=E6=AD=BB=E6=97=B6=E9=97=B4=E7=9A=84=E8=BF=87=E6=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../udidl/admin/entity/auth/AuthAliUser.java | 13 +++++ .../ThirdAliDrugClearResCodeCountTask.java | 50 +++++++++++++++++++ .../admin/util/alihealth/AlihealthUtils.java | 12 +++++ src/main/resources/schemas/schema_v2.1.sql | 2 + 4 files changed, 77 insertions(+) create mode 100644 src/main/java/com/glxp/udidl/admin/thread/ThirdAliDrugClearResCodeCountTask.java diff --git a/src/main/java/com/glxp/udidl/admin/entity/auth/AuthAliUser.java b/src/main/java/com/glxp/udidl/admin/entity/auth/AuthAliUser.java index dfea7ff..75a8cc5 100644 --- a/src/main/java/com/glxp/udidl/admin/entity/auth/AuthAliUser.java +++ b/src/main/java/com/glxp/udidl/admin/entity/auth/AuthAliUser.java @@ -37,4 +37,17 @@ public class AuthAliUser { */ @TableField(value = "type") private String type; + + /** + * 当天药品查询接口次数 + */ + @TableField(value = "drugResCodeCount") + private Integer drugResCodeCount; + + /** + * 当天药品查询接口允许最大次数 + */ + @TableField(value = "drugResCodeCountMax") + private Integer drugResCodeCountMax; + } diff --git a/src/main/java/com/glxp/udidl/admin/thread/ThirdAliDrugClearResCodeCountTask.java b/src/main/java/com/glxp/udidl/admin/thread/ThirdAliDrugClearResCodeCountTask.java new file mode 100644 index 0000000..6473482 --- /dev/null +++ b/src/main/java/com/glxp/udidl/admin/thread/ThirdAliDrugClearResCodeCountTask.java @@ -0,0 +1,50 @@ +package com.glxp.udidl.admin.thread; + +import com.glxp.udidl.admin.dao.info.ScheduledMapper; +import com.glxp.udidl.admin.entity.auth.AuthAliUser; +import com.glxp.udidl.admin.entity.info.ScheduledEntity; +import com.glxp.udidl.admin.req.info.ScheduledRequest; +import com.glxp.udidl.admin.service.auth.AuthAliUserService; +import com.glxp.udidl.admin.service.chsapi.ChsYbHcxxService; +import com.glxp.udidl.admin.service.collect.ThirdAliDrugService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.scheduling.annotation.SchedulingConfigurer; +import org.springframework.scheduling.config.ScheduledTaskRegistrar; +import org.springframework.scheduling.support.CronTrigger; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; + +@Component +@EnableScheduling +public class ThirdAliDrugClearResCodeCountTask implements SchedulingConfigurer { + + + @Resource + private AuthAliUserService authAliUserService; + + + final Logger logger = LoggerFactory.getLogger(ThirdAliDrugClearResCodeCountTask.class); + + @Override + public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) { + scheduledTaskRegistrar.addTriggerTask(() -> process(), + triggerContext -> { + String cron = "0 0 * * * ?";//每天0点 + if (cron.isEmpty()) { + logger.error("cron is null"); + } + return new CronTrigger(cron).nextExecutionTime(triggerContext); + }); + } + + private void process() { + System.out.println("开始执行更新阿里健康数据访问重置"); + AuthAliUser one = authAliUserService.getOne(); + one.setDrugResCodeCount(0); + authAliUserService.updateById(one); + } + +} diff --git a/src/main/java/com/glxp/udidl/admin/util/alihealth/AlihealthUtils.java b/src/main/java/com/glxp/udidl/admin/util/alihealth/AlihealthUtils.java index 80d06b8..1a72884 100644 --- a/src/main/java/com/glxp/udidl/admin/util/alihealth/AlihealthUtils.java +++ b/src/main/java/com/glxp/udidl/admin/util/alihealth/AlihealthUtils.java @@ -6,6 +6,7 @@ import cn.hutool.http.HttpUtil; import com.glxp.udidl.admin.constant.AliConstants; import com.glxp.udidl.admin.entity.auth.AuthAliUser; import com.glxp.udidl.admin.entity.collect.ThirdAliDrug; +import com.glxp.udidl.admin.exception.JsonException; import com.glxp.udidl.admin.req.alihealth.AlihealthKytCommonParametersReqeust; import com.glxp.udidl.admin.req.alihealth.AlihealthKytDrugrescodeReqeust; import com.glxp.udidl.admin.req.alihealth.local.AlihealthThirdAliDrugInsertReqeust; @@ -148,6 +149,17 @@ public class AlihealthUtils { AlihealthKytDrugrescodeReqeust alihealthKytDrugrescodeReqeust = alihealthThirdAliDrugInsertReqeust.getAlihealthKytDrugrescodeReqeust(); // key组装 AuthAliUser authAliUser = authAliUserService.getOne(); + + //增加次数限制 + Integer drugResCodeCount = authAliUser.getDrugResCodeCount(); + Integer drugResCodeCountMax = authAliUser.getDrugResCodeCountMax(); + if (drugResCodeCount >= drugResCodeCountMax){ + throw new JsonException("当前系统调用阿里药品数据查询接口最大次数已达到,禁止访问,如需访问请联系管理员增加访问次数!"); + } + drugResCodeCount = drugResCodeCount + 1; + authAliUser.setDrugResCodeCount(drugResCodeCount); + authAliUserService.updateById(authAliUser); + alihealthThirdAliDrugInsertReqeust.setErpId(authAliUser.getErpid()); alihealthThirdAliDrugInsertReqeust.setAppSecret(authAliUser.getAppsecret()); alihealthKytDrugrescodeReqeust.setApp_key(authAliUser.getAppkey()); diff --git a/src/main/resources/schemas/schema_v2.1.sql b/src/main/resources/schemas/schema_v2.1.sql index 6e2225c..43f08e8 100644 --- a/src/main/resources/schemas/schema_v2.1.sql +++ b/src/main/resources/schemas/schema_v2.1.sql @@ -341,6 +341,8 @@ CREATE TABLE IF NOT EXISTS `auth_ali_user` `appSecret` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '阿里密钥', `refEntId` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '厂家标识', `type` varchar(255) DEFAULT NULL COMMENT '1 为生成企业 2为零售药店', + `drugResCodeCount` int DEFAULT 0 COMMENT '药品查询接口次数', + `drugResCodeCountMax` int DEFAULT 0 COMMENT '药品查询接口允许最大次数', PRIMARY KEY (`id`) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4