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