From c1bde6da3ad13455c3d704b034eac8b1210b3d3b Mon Sep 17 00:00:00 2001 From: ty <1577900710@qq.com> Date: Sun, 28 Apr 2024 19:47:49 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E4=B8=AA?= =?UTF-8?q?=E4=BA=BA=E6=8E=92=E7=8F=AD=E5=A2=9E=E5=8A=A0=E7=8F=AD=E6=AC=A1?= =?UTF-8?q?=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/hnac/hzims/operational/duty/mapper/ImsDutyMainMapper.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/mapper/ImsDutyMainMapper.xml b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/mapper/ImsDutyMainMapper.xml index 267a575..c8952ac 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/mapper/ImsDutyMainMapper.xml +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/mapper/ImsDutyMainMapper.xml @@ -66,6 +66,7 @@ DM.DUTY_DATE AS dutyDate, CONCAT(CASE WHEN DM.`CLASS_ID` = 0 THEN '休息' ELSE DC.CLASS_NAME END, '-', CASE WHEN DG.GROUP_NAME is null THEN '临时班组' ELSE DG.GROUP_NAME END) AS name, + CONCAT(CASE WHEN DM.`CLASS_ID` = 0 THEN '休息' ELSE DC.CLASS_NAME END) AS className, DC.START_TIME AS startTime, DC.END_TIME AS endTime, DM.CREATE_USER, From e9359f34b7b60a6b17f1d70736bca014e1a00d17 Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Mon, 29 Apr 2024 16:50:36 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix:gitignore=E6=B7=BB=E5=8A=A0*.iml?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 215ebcf..bf2517a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ /hzims-service/*/target /hzims-service-api/*/target log +*.iml From 0658d127addfe99dee003c92c4010d1c336677d4 Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Mon, 29 Apr 2024 16:57:24 +0800 Subject: [PATCH 3/3] =?UTF-8?q?add:=E5=A4=A7=E6=A8=A1=E5=9E=8B=E7=AE=A1?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hzims-service-api/big-model-api/pom.xml | 17 ++++ .../com/hnac/hzims/bigmodel/BigModelConstants.java | 14 ++++ .../hzims/bigmodel/entity/FuncParamEntity.java | 38 +++++++++ .../hnac/hzims/bigmodel/entity/FunctionEntity.java | 45 +++++++++++ .../interactive/constants/FunctionConstants.java | 29 +++++++ .../bigmodel/interactive/req/ModelFunctionReq.java | 30 +++++++ .../hzims/bigmodel/interactive/vo/ExtraVO.java | 29 +++++++ hzims-service-api/pom.xml | 1 + hzims-service/hzims-big-model/pom.xml | 91 ++++++++++++++++++++++ .../hzims/bigmodel/HzimsBigModelApplication.java | 33 ++++++++ .../bigmodel/configuration/BigModelInvokeUrl.java | 18 +++++ .../function/controller/FunctionController.java | 73 +++++++++++++++++ .../controller/FunctionParamController.java | 74 ++++++++++++++++++ .../bigmodel/function/mapper/FuncParamMapper.java | 11 +++ .../bigmodel/function/mapper/FunctionMapper.java | 12 +++ .../function/service/IFuncParamService.java | 21 +++++ .../function/service/IFunctionService.java | 14 ++++ .../service/impl/FuncParamServiceImpl.java | 28 +++++++ .../function/service/impl/FunctionServiceImpl.java | 27 +++++++ .../controller/InteractiveController.java | 45 +++++++++++ .../interactive/service/IInteractiveService.java | 20 +++++ .../interactive/service/IJumpPageService.java | 16 ++++ .../service/impl/InteractiveServiceImpl.java | 85 ++++++++++++++++++++ .../service/impl/JumpPageServiceImpl.java | 54 +++++++++++++ .../bigmodel/schedule/InteractiveSchedule.java | 58 ++++++++++++++ .../bigmodel/schedule/XxlJobHandlerConstant.java | 13 ++++ .../bigmodel/websocket/config/WebSocketConfig.java | 28 +++++++ .../websocket/handler/InteractiveHandler.java | 41 ++++++++++ .../websocket/server/InteractiveWsServer.java | 9 +++ .../websocket/service/InteractiveWsService.java | 32 ++++++++ .../websocket/service/WebSocketService.java | 13 ++++ .../sessionManager/InteractiveSessionManager.java | 56 +++++++++++++ .../src/main/resources/db/1.0.0.sql | 34 ++++++++ .../hnac/hzinfo/inspect/task/mapper/TaskMapper.xml | 3 + hzims-service/pom.xml | 1 + 35 files changed, 1113 insertions(+) create mode 100644 hzims-service-api/big-model-api/pom.xml create mode 100644 hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/BigModelConstants.java create mode 100644 hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/entity/FuncParamEntity.java create mode 100644 hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/entity/FunctionEntity.java create mode 100644 hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FunctionConstants.java create mode 100644 hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/req/ModelFunctionReq.java create mode 100644 hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/ExtraVO.java create mode 100644 hzims-service/hzims-big-model/pom.xml create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/HzimsBigModelApplication.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/BigModelInvokeUrl.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/controller/FunctionController.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/controller/FunctionParamController.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/mapper/FuncParamMapper.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/mapper/FunctionMapper.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/IFuncParamService.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/IFunctionService.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/impl/FuncParamServiceImpl.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/impl/FunctionServiceImpl.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/InteractiveController.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IInteractiveService.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IJumpPageService.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/JumpPageServiceImpl.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/InteractiveSchedule.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/XxlJobHandlerConstant.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/config/WebSocketConfig.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/handler/InteractiveHandler.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/server/InteractiveWsServer.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/service/InteractiveWsService.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/service/WebSocketService.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/sessionManager/InteractiveSessionManager.java create mode 100644 hzims-service/hzims-big-model/src/main/resources/db/1.0.0.sql diff --git a/hzims-service-api/big-model-api/pom.xml b/hzims-service-api/big-model-api/pom.xml new file mode 100644 index 0000000..2df887f --- /dev/null +++ b/hzims-service-api/big-model-api/pom.xml @@ -0,0 +1,17 @@ + + + + hzims-service-api + com.hnac.hzims + 4.0.0-SNAPSHOT + + 4.0.0 + big-model-api + big-model-api + + + + + + diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/BigModelConstants.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/BigModelConstants.java new file mode 100644 index 0000000..91d93f8 --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/BigModelConstants.java @@ -0,0 +1,14 @@ +package com.hnac.hzims.bigmodel; + +/** + * @Author: huangxing + * @Date: 2024/04/26 10:15 + */ +public interface BigModelConstants { + + /**注册至NACOS服务名**/ + String APP_NAME = "hzims-big-model"; + /**前端展示服务名**/ + String MODULE_NAME = "大模型管理"; + +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/entity/FuncParamEntity.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/entity/FuncParamEntity.java new file mode 100644 index 0000000..99e55ed --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/entity/FuncParamEntity.java @@ -0,0 +1,38 @@ +package com.hnac.hzims.bigmodel.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.springblade.core.mp.support.QueryField; +import org.springblade.core.mp.support.SqlCondition; +import org.springblade.core.tenant.mp.TenantEntity; + +import javax.validation.constraints.Max; +import javax.validation.constraints.Size; + +/** + * @Author: huangxing + * @Date: 2024/04/26 10:56 + */ +@TableName("HZIMS_FUNC_PARAM") +@ApiModel(value = "大模型函数参数entity",description = "大模型函数参数entity") +@Data +public class FuncParamEntity extends TenantEntity { + + @ApiModelProperty(value = "函数表主键ID") + @QueryField(condition = SqlCondition.EQUAL) + @Max(20) + private Long funcId; + + @ApiModelProperty("参数名称") + @QueryField(condition = SqlCondition.LIKE) + @Size(min = 1,max = 50) + private String name; + + @ApiModelProperty(value = "参数别名,传参参数") + @QueryField(condition = SqlCondition.EQUAL) + @Size(min = 1,max = 25) + private String alias; + +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/entity/FunctionEntity.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/entity/FunctionEntity.java new file mode 100644 index 0000000..af01299 --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/entity/FunctionEntity.java @@ -0,0 +1,45 @@ +package com.hnac.hzims.bigmodel.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.springblade.core.mp.support.QueryField; +import org.springblade.core.mp.support.SqlCondition; +import org.springblade.core.tenant.mp.TenantEntity; + +import javax.validation.constraints.Max; +import javax.validation.constraints.Size; + +/** + * @Author: huangxing + * @Date: 2024/04/26 10:46 + */ +@Data +@ApiModel(value = "大模型函数entity",description = "大模型函数entity") +@TableName("HZIMS_FUNCTION") +public class FunctionEntity extends TenantEntity { + + @ApiModelProperty("函数名称") + @QueryField(condition = SqlCondition.LIKE) + private String name; + + @ApiModelProperty(value = "函数编号") + @QueryField(condition = SqlCondition.EQUAL) + private String code; + + @ApiModelProperty("动作类型") + @QueryField(condition = SqlCondition.EQUAL) + private String type; + + @ApiModelProperty("是否需要确认,0:否,1:是") + @QueryField(condition = SqlCondition.EQUAL) + private Boolean isConfirm; + + @ApiModelProperty("跳转路径") + private String path; + + @ApiModelProperty("描述") + private String remake; + +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FunctionConstants.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FunctionConstants.java new file mode 100644 index 0000000..7d34a5d --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FunctionConstants.java @@ -0,0 +1,29 @@ +package com.hnac.hzims.bigmodel.interactive.constants; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.util.Arrays; +import java.util.Optional; + +/** + * @Author: huangxing + * @Date: 2024/04/26 13:29 + */ +public interface FunctionConstants { + + @AllArgsConstructor + enum TypeEnum { + /**跳转页面**/ + JUMP("1") + ; + @Getter + private String type; + + public static TypeEnum getTypeEnumByType (String type) { + Optional typeEnumOptional = Arrays.stream(TypeEnum.class.getEnumConstants()).filter(e -> type.equals(e.getType())).findFirst(); + return typeEnumOptional.orElse(null); + } + } + +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/req/ModelFunctionReq.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/req/ModelFunctionReq.java new file mode 100644 index 0000000..a1fe20c --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/req/ModelFunctionReq.java @@ -0,0 +1,30 @@ +package com.hnac.hzims.bigmodel.interactive.req; + +import com.alibaba.fastjson.annotation.JSONField; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.util.Map; + +/** + * @Author: huangxing + * @Date: 2024/04/26 11:31 + */ +@Data +@ApiModel("大模型响应内容") +public class ModelFunctionReq implements Serializable { + + @ApiModelProperty("类型") + private String type; + + @JSONField(name = "function_name") + @ApiModelProperty("函数标识") + private String functionName; + + @JSONField(name = "function_args") + @ApiModelProperty("函数参数") + private Map functionArgs; + +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/ExtraVO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/ExtraVO.java new file mode 100644 index 0000000..303a21e --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/ExtraVO.java @@ -0,0 +1,29 @@ +package com.hnac.hzims.bigmodel.interactive.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/04/26 13:35 + */ +@Data +@ApiModel("响应内容") +public class ExtraVO implements Serializable { + + @ApiModelProperty("交互类型") + private String type; + + @ApiModelProperty("若为弹窗,则返回路由") + private String route; + + @ApiModelProperty("链接显示文字") + private String label; + + @ApiModelProperty("是否立即跳转") + private boolean isImmediatelyJump = true; + +} diff --git a/hzims-service-api/pom.xml b/hzims-service-api/pom.xml index e3ec04e..9974fff 100644 --- a/hzims-service-api/pom.xml +++ b/hzims-service-api/pom.xml @@ -29,6 +29,7 @@ common-api middle-api alarm-api + big-model-api diff --git a/hzims-service/hzims-big-model/pom.xml b/hzims-service/hzims-big-model/pom.xml new file mode 100644 index 0000000..ece5cf6 --- /dev/null +++ b/hzims-service/hzims-big-model/pom.xml @@ -0,0 +1,91 @@ + + + + com.hnac.hzims + hzims-service + 4.0.0-SNAPSHOT + + 4.0.0 + hzims-big-model + big-model + jar + + + + org.springblade + blade-core-boot + + + org.springblade + blade-starter-redis + + + + + + org.springblade + blade-starter-swagger + + + + org.springblade + blade-core-test + test + + + + org.springblade + blade-core-cloud + + + com.hnac.hzims + big-model-api + 4.0.0-SNAPSHOT + compile + + + + + org.springframework.boot + spring-boot-starter-websocket + + + org.springframework.boot + spring-boot-starter-tomcat + + + + + + com.xuxueli + xxl-job-core + + + org.springblade + blade-system-api + + + + + ${project.name}-${project.version} + + + com.spotify + dockerfile-maven-plugin + + ${docker.username} + ${docker.password} + ${docker.registry.url}/${docker.namespace}/${project.artifactId} + ${project.version} + true + + target/${project.build.finalName}.jar + + false + + + + + + diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/HzimsBigModelApplication.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/HzimsBigModelApplication.java new file mode 100644 index 0000000..2709c09 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/HzimsBigModelApplication.java @@ -0,0 +1,33 @@ +package com.hnac.hzims.bigmodel; + +import org.mybatis.spring.annotation.MapperScan; +import org.springblade.core.cloud.feign.EnableBladeFeign; +import org.springblade.core.launch.BladeApplication; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; +import org.springframework.cloud.client.SpringCloudApplication; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableScheduling; + +import javax.annotation.Resource; + +@EnableBladeFeign(basePackages = {"org.springblade","com.hnac"}) +@SpringCloudApplication +@MapperScan("com.hnac.hzims.**.mapper.**") +@ComponentScan(basePackages = {"com.hnac.hzims.bigmodel.*"}) +@Resource +@ComponentScan(basePackages = {"com.hnac.hzims.*"}) +public class HzimsBigModelApplication extends SpringBootServletInitializer { + + public static void main(String[] args) { + BladeApplication.run(BigModelConstants.APP_NAME, HzimsBigModelApplication.class, args); + } + + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { + return BladeApplication.createSpringApplicationBuilder(builder, BigModelConstants.APP_NAME, HzimsBigModelApplication.class); + } + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/BigModelInvokeUrl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/BigModelInvokeUrl.java new file mode 100644 index 0000000..5ff1f3e --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/BigModelInvokeUrl.java @@ -0,0 +1,18 @@ +package com.hnac.hzims.bigmodel.configuration; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +/** + * @Author: huangxing + * @Date: 2024/04/28 18:20 + */ +@Data +@Component +@ConfigurationProperties(prefix = "fdp.url") +public class BigModelInvokeUrl { + + private String assistantAsk; + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/controller/FunctionController.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/controller/FunctionController.java new file mode 100644 index 0000000..bffa1db --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/controller/FunctionController.java @@ -0,0 +1,73 @@ +package com.hnac.hzims.bigmodel.function.controller; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import com.hnac.hzims.bigmodel.BigModelConstants; +import com.hnac.hzims.bigmodel.entity.FunctionEntity; +import com.hnac.hzims.bigmodel.function.service.IFunctionService; +import com.hnac.hzims.common.utils.Condition; +import com.hnac.hzinfo.log.annotation.Business; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiOperation; +import lombok.AllArgsConstructor; +import org.springblade.core.mp.support.Query; +import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.BeanUtil; +import org.springblade.core.tool.utils.Func; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * @Author: huangxing + * @Date: 2024/04/29 14:39 + */ +@RestController +@RequestMapping("/function") +@Api(value = "大模型函数管理",tags = "大模型函数管理") +@Business(module = BigModelConstants.MODULE_NAME,value = "大模型函数管理") +@AllArgsConstructor +public class FunctionController { + + private final IFunctionService functionService; + + @PostMapping("/save") + @ApiOperation("保存函数") + @ApiOperationSupport(order = 1) + public R save(@RequestBody @Validated FunctionEntity req) { + return R.status(functionService.save(req)); + } + + @PutMapping("/save") + @ApiOperation("编辑函数") + @ApiOperationSupport(order = 2) + public R updateById(@RequestBody FunctionEntity req) { + return R.status(functionService.save(req)); + } + + @GetMapping("/list") + @ApiOperation("列表查询") + @ApiOperationSupport(order = 3) + public R> list(FunctionEntity req) { + return R.data(functionService.list(Condition.getQueryWrapper(BeanUtil.toMap(req),FunctionEntity.class))); + } + + @GetMapping("/page") + @ApiOperation("分页查询") + @ApiOperationSupport(order = 4) + public R> page(FunctionEntity req, Query query) { + QueryWrapper queryWrapper = Condition.getQueryWrapper(BeanUtil.toMap(req), FunctionEntity.class); + return R.data(functionService.page(Condition.getPage(query),queryWrapper)); + } + + @DeleteMapping("/remove") + @ApiOperation("删除函数") + @ApiOperationSupport(order = 4) + public R remove(String ids) { + return R.data(functionService.removeByIds(Func.toLongList(",",ids))); + } + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/controller/FunctionParamController.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/controller/FunctionParamController.java new file mode 100644 index 0000000..0f58067 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/controller/FunctionParamController.java @@ -0,0 +1,74 @@ +package com.hnac.hzims.bigmodel.function.controller; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import com.hnac.hzims.bigmodel.BigModelConstants; +import com.hnac.hzims.bigmodel.entity.FuncParamEntity; +import com.hnac.hzims.bigmodel.entity.FunctionEntity; +import com.hnac.hzims.bigmodel.function.service.IFuncParamService; +import com.hnac.hzims.bigmodel.function.service.IFunctionService; +import com.hnac.hzims.common.utils.Condition; +import com.hnac.hzinfo.log.annotation.Business; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.AllArgsConstructor; +import org.springblade.core.mp.support.Query; +import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.BeanUtil; +import org.springblade.core.tool.utils.Func; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * @Author: huangxing + * @Date: 2024/04/29 15:46 + */ +@RestController +@RequestMapping("/function/param") +@Api(value = "大模型函数参数管理",tags = "大模型函数参数管理") +@Business(module = BigModelConstants.MODULE_NAME,value = "大模型函数参数管理") +@AllArgsConstructor +public class FunctionParamController { + + private final IFuncParamService funcParamService; + + @PostMapping("/save") + @ApiOperation("保存函数参数") + @ApiOperationSupport(order = 1) + public R save(@RequestBody @Validated FuncParamEntity req) { + return R.status(funcParamService.save(req)); + } + + @PutMapping("/save") + @ApiOperation("编辑函数参数") + @ApiOperationSupport(order = 2) + public R updateById(@RequestBody FuncParamEntity req) { + return R.status(funcParamService.save(req)); + } + + @GetMapping("/list") + @ApiOperation("列表查询") + @ApiOperationSupport(order = 3) + public R> list(FuncParamEntity req) { + return R.data(funcParamService.list(Condition.getQueryWrapper(BeanUtil.toMap(req),FuncParamEntity.class))); + } + + @GetMapping("/page") + @ApiOperation("分页查询") + @ApiOperationSupport(order = 4) + public R> page(FuncParamEntity req, Query query) { + QueryWrapper queryWrapper = Condition.getQueryWrapper(BeanUtil.toMap(req), FuncParamEntity.class); + return R.data(funcParamService.page(Condition.getPage(query),queryWrapper)); + } + + @DeleteMapping("/remove") + @ApiOperation("删除函数参数") + @ApiOperationSupport(order = 4) + public R remove(String ids) { + return R.data(funcParamService.removeByIds(Func.toLongList(",",ids))); + } + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/mapper/FuncParamMapper.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/mapper/FuncParamMapper.java new file mode 100644 index 0000000..7a9723e --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/mapper/FuncParamMapper.java @@ -0,0 +1,11 @@ +package com.hnac.hzims.bigmodel.function.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.hnac.hzims.bigmodel.entity.FuncParamEntity; + +/** + * @Author: huangxing + * @Date: 2024/04/26 11:11 + */ +public interface FuncParamMapper extends BaseMapper { +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/mapper/FunctionMapper.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/mapper/FunctionMapper.java new file mode 100644 index 0000000..6d0e1c2 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/mapper/FunctionMapper.java @@ -0,0 +1,12 @@ +package com.hnac.hzims.bigmodel.function.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.hnac.hzims.bigmodel.entity.FunctionEntity; + +/** + * @Author: huangxing + * @Date: 2024/04/26 11:10 + */ +public interface FunctionMapper extends BaseMapper { + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/IFuncParamService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/IFuncParamService.java new file mode 100644 index 0000000..39fae6a --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/IFuncParamService.java @@ -0,0 +1,21 @@ +package com.hnac.hzims.bigmodel.function.service; + +import com.hnac.hzims.bigmodel.entity.FuncParamEntity; +import org.springblade.core.mp.base.BaseService; + +import java.util.List; + +/** + * @Author: huangxing + * @Date: 2024/04/26 11:12 + */ +public interface IFuncParamService extends BaseService { + + /** + * 根据函数ID获取参数列表 + * @param funcId 函数ID + * @return 参数列表 + */ + List getParamsByFuncId(Long funcId); + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/IFunctionService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/IFunctionService.java new file mode 100644 index 0000000..6a9e59d --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/IFunctionService.java @@ -0,0 +1,14 @@ +package com.hnac.hzims.bigmodel.function.service; + +import com.hnac.hzims.bigmodel.entity.FunctionEntity; +import org.springblade.core.mp.base.BaseService; + +/** + * @Author: huangxing + * @Date: 2024/04/26 11:08 + */ +public interface IFunctionService extends BaseService { + + FunctionEntity getFunctionByCode(String code); + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/impl/FuncParamServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/impl/FuncParamServiceImpl.java new file mode 100644 index 0000000..e7e2dae --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/impl/FuncParamServiceImpl.java @@ -0,0 +1,28 @@ +package com.hnac.hzims.bigmodel.function.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.hnac.hzims.bigmodel.entity.FuncParamEntity; +import com.hnac.hzims.bigmodel.function.mapper.FuncParamMapper; +import com.hnac.hzims.bigmodel.function.service.IFuncParamService; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * @Author: huangxing + * @Date: 2024/04/26 11:13 + */ +@Service +@Slf4j +public class FuncParamServiceImpl extends BaseServiceImpl implements IFuncParamService { + + @Override + public List getParamsByFuncId(Long funcId) { + LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery().eq(FuncParamEntity::getFuncId, funcId); + return this.list(queryWrapper); + } + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/impl/FunctionServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/impl/FunctionServiceImpl.java new file mode 100644 index 0000000..0619ddb --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/impl/FunctionServiceImpl.java @@ -0,0 +1,27 @@ +package com.hnac.hzims.bigmodel.function.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.hnac.hzims.bigmodel.entity.FunctionEntity; +import com.hnac.hzims.bigmodel.function.mapper.FunctionMapper; +import com.hnac.hzims.bigmodel.function.service.IFunctionService; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springframework.stereotype.Service; + +/** + * @Author: huangxing + * @Date: 2024/04/26 11:09 + */ +@Service +@Slf4j +@AllArgsConstructor +public class FunctionServiceImpl extends BaseServiceImpl implements IFunctionService { + + @Override + public FunctionEntity getFunctionByCode(String code) { + LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery().eq(FunctionEntity::getCode, code); + return this.getOne(queryWrapper); + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/InteractiveController.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/InteractiveController.java new file mode 100644 index 0000000..41f3885 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/InteractiveController.java @@ -0,0 +1,45 @@ +package com.hnac.hzims.bigmodel.interactive.controller; + +import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import com.hnac.hzims.bigmodel.BigModelConstants; +import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq; +import com.hnac.hzims.bigmodel.interactive.service.IInteractiveService; +import com.hnac.hzinfo.log.annotation.Business; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiModelProperty; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import lombok.AllArgsConstructor; +import org.springblade.core.tool.api.R; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; + +/** + * @Author: huangxing + * @Date: 2024/04/26 14:51 + */ +@RestController +@AllArgsConstructor +@Api(value = "FDP大模型交互层",tags = "FDP大模型交互层") +@RequestMapping("/interactive") +@Business(module = BigModelConstants.MODULE_NAME,value = "FDP大模型交互层") +public class InteractiveController { + + private final IInteractiveService interactiveService; + + @ApiOperation("解析大模型函数") + @ApiOperationSupport(order = 1) + @PostMapping("/resolve") + public R resolve(@RequestBody ModelFunctionReq req) { + return interactiveService.resolve(req); + } + + @ApiOperation("提问") + @ApiOperationSupport(order = 2) + @GetMapping("/ask") + public R ask(@RequestParam @ApiParam("用户提出问题") String question, HttpServletRequest request) { + return interactiveService.ask(request, question); + } + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IInteractiveService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IInteractiveService.java new file mode 100644 index 0000000..3fe695e --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IInteractiveService.java @@ -0,0 +1,20 @@ +package com.hnac.hzims.bigmodel.interactive.service; + +import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq; +import io.swagger.annotations.ApiParam; +import org.springblade.core.tool.api.R; +import org.springframework.web.bind.annotation.RequestParam; + +import javax.servlet.http.HttpServletRequest; + +/** + * @Author: huangxing + * @Date: 2024/04/26 14:51 + */ +public interface IInteractiveService { + + R resolve(ModelFunctionReq req); + + R ask(HttpServletRequest request, String question); + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IJumpPageService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IJumpPageService.java new file mode 100644 index 0000000..fa4f9d5 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IJumpPageService.java @@ -0,0 +1,16 @@ +package com.hnac.hzims.bigmodel.interactive.service; + +import com.hnac.hzims.bigmodel.entity.FunctionEntity; +import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; + +import java.util.Map; + +/** + * @Author: huangxing + * @Date: 2024/04/26 11:46 + */ +public interface IJumpPageService { + + String dealJumpTypeFunction(FunctionEntity function, Map args); + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java new file mode 100644 index 0000000..1a2b719 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java @@ -0,0 +1,85 @@ +package com.hnac.hzims.bigmodel.interactive.service.impl; + +import cn.hutool.http.HttpRequest; +import cn.hutool.http.HttpResponse; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.hnac.hzims.bigmodel.configuration.BigModelInvokeUrl; +import com.hnac.hzims.bigmodel.entity.FunctionEntity; +import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq; +import com.hnac.hzims.bigmodel.interactive.service.IInteractiveService; +import com.hnac.hzims.bigmodel.interactive.service.IJumpPageService; +import com.hnac.hzims.bigmodel.function.service.IFunctionService; +import lombok.AllArgsConstructor; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.log.exception.ServiceException; +import org.springblade.core.secure.utils.AuthUtil; +import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.Func; +import org.springblade.core.tool.utils.StringUtil; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Service; +import org.springframework.util.Assert; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import java.util.HashMap; +import java.util.Map; + +import static com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants.*; +/** + * @Author: huangxing + * @Date: 2024/04/26 14:51 + */ +@Service +@Slf4j +@RequiredArgsConstructor +public class InteractiveServiceImpl implements IInteractiveService { + + private final IJumpPageService jumpPageService; + private final IFunctionService functionService; + private final BigModelInvokeUrl bigModelInvokeUrl; + @Value("${fdp.host}") + private String fdpHost; + + @Override + public R resolve(ModelFunctionReq req) { + //TODO 数据鉴权 + FunctionEntity function = functionService.getFunctionByCode(req.getFunctionName()); + TypeEnum typeEnum = TypeEnum.getTypeEnumByType(function.getType()); + switch (typeEnum) { + // 页面跳转 + case JUMP: + String extra = jumpPageService.dealJumpTypeFunction(function, req.getFunctionArgs()); + Assert.isTrue(StringUtil.isNotBlank(extra) && Func.isNotEmpty(extra), () -> { + throw new ServiceException("解析" + function.getName() + "函数失败!"); + }); + R.data(extra); + default: + throw new ServiceException("函数解析失败!"); + } + } + + @Override + public R ask(HttpServletRequest request, String question) { + HttpSession session = request.getSession(true); + String sessionId = session.getId(); + Long userId = AuthUtil.getUserId(); + //TODO 保存问题 + Map params = new HashMap<>(); + params.put("id",sessionId); + params.put("userid",userId.toString()); + params.put("query",question); + HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAssistantAsk()) + .body(JSON.toJSONString(params)).execute(); + Assert.isTrue(response.getStatus() == HttpServletResponse.SC_OK && "1".equals(JSONObject.parseObject(response.body()).getString("success")), () -> { + throw new ServiceException("远程调用大模型【发起问答】接口失败!"); + }); + return R.data(JSONObject.parseObject(response.body()).getString("data")); + } + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/JumpPageServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/JumpPageServiceImpl.java new file mode 100644 index 0000000..2c95d1c --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/JumpPageServiceImpl.java @@ -0,0 +1,54 @@ +package com.hnac.hzims.bigmodel.interactive.service.impl; + +import com.alibaba.fastjson.JSON; +import com.hnac.hzims.bigmodel.entity.FuncParamEntity; +import com.hnac.hzims.bigmodel.entity.FunctionEntity; +import com.hnac.hzims.bigmodel.function.service.IFuncParamService; +import com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants; +import com.hnac.hzims.bigmodel.interactive.service.IJumpPageService; +import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.log.exception.ServiceException; +import org.springblade.core.tool.utils.StringUtil; +import org.springframework.stereotype.Service; +import org.springframework.util.Assert; + +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; + +/** + * @Author: huangxing + * @Date: 2024/04/26 11:46 + */ +@Service +@AllArgsConstructor +@Slf4j +public class JumpPageServiceImpl implements IJumpPageService { + + private final IFuncParamService paramService; + + @Override + public String dealJumpTypeFunction(FunctionEntity function,Map args) { + List params = paramService.getParamsByFuncId(function.getId()); + Optional paramOptional = params.stream().filter(p -> !args.containsKey(p)).findAny(); + Assert.isTrue(!paramOptional.isPresent(), () -> { + throw new ServiceException("解析参数失败,缺少参数:" + paramOptional.get().getName()); + }); + // 跳转页面逻辑 + ExtraVO extraVO = new ExtraVO(); + String path = function.getPath(); + Set> entries = args.entrySet(); + // 替换path中变量 + for (Map.Entry entry : entries) { + String replaceVariables = "{" + entry.getKey() + "}"; + path = StringUtil.replace(path,replaceVariables,entry.getValue()); + } + extraVO.setType(FunctionConstants.TypeEnum.JUMP.getType()); + extraVO.setRoute(path); + // TODO 将结果存入redis中供前端获取 + return JSON.toJSONString(extraVO); + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/InteractiveSchedule.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/InteractiveSchedule.java new file mode 100644 index 0000000..b50c578 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/InteractiveSchedule.java @@ -0,0 +1,58 @@ +package com.hnac.hzims.bigmodel.schedule; + +import com.alibaba.fastjson.JSON; +import com.hnac.hzims.bigmodel.websocket.server.InteractiveWsServer; +import com.hnac.hzims.bigmodel.websocket.service.InteractiveWsService; +import com.hnac.hzims.bigmodel.websocket.sessionManager.InteractiveSessionManager; +import com.xxl.job.core.biz.model.ReturnT; +import com.xxl.job.core.handler.annotation.XxlJob; +import lombok.AllArgsConstructor; +import org.springblade.core.log.exception.ServiceException; +import org.springblade.core.tool.utils.Func; +import org.springblade.system.cache.ParamCache; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Component; +import org.springframework.util.Assert; +import org.springframework.web.socket.TextMessage; +import org.springframework.web.socket.WebSocketSession; + +import java.util.List; +import java.util.Set; + +import static com.hnac.hzims.bigmodel.schedule.XxlJobHandlerConstant.*; + +/** + * @Author: huangxing + * @Date: 2024/04/28 16:18 + */ +@Component +@AllArgsConstructor +public class InteractiveSchedule { + + private final RedisTemplate redisTemplate; + private final InteractiveWsService wsService; + + @XxlJob(GET_INTERACTIVE_RESULT) + public ReturnT execute(String params) { + String resultKey = ParamCache.getValue(GET_INTERACTIVE_RESULT); + Set keySet = redisTemplate.keys(resultKey + "*"); + keySet.parallelStream().forEach(key -> { + // 根据Key获取sessionId + List keySplits = Func.toStrList(":", key); + String sessionId = keySplits.get(2); + // 查询websocket是否存在连接session + WebSocketSession session = InteractiveSessionManager.get(sessionId); + if(session == null) { + return; + } + TextMessage message = new TextMessage(JSON.toJSONString(redisTemplate.opsForValue().get(key))); + Boolean sendResult = wsService.sendMessage(sessionId, message); + Assert.isTrue(sendResult, () -> { + throw new ServiceException(key + "推送消息失败,推送消息体为:" + JSON.toJSONString(redisTemplate.opsForValue().get(key))); + }); + redisTemplate.delete(key); + }); + return ReturnT.SUCCESS; + } + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/XxlJobHandlerConstant.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/XxlJobHandlerConstant.java new file mode 100644 index 0000000..708d3e8 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/XxlJobHandlerConstant.java @@ -0,0 +1,13 @@ +package com.hnac.hzims.bigmodel.schedule; + +/** + * @Author: huangxing + * @Date: 2024/04/28 16:19 + */ +public interface XxlJobHandlerConstant { + + String GET_INTERACTIVE_RESULT = "getInteractiveResult"; + + String INTERACTIVE_RESULT_KEY = "hzllm:interactive:result"; + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/config/WebSocketConfig.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/config/WebSocketConfig.java new file mode 100644 index 0000000..04a4405 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/config/WebSocketConfig.java @@ -0,0 +1,28 @@ +package com.hnac.hzims.bigmodel.websocket.config; + +import com.hnac.hzims.bigmodel.websocket.handler.InteractiveHandler; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.socket.WebSocketHandler; +import org.springframework.web.socket.config.annotation.EnableWebSocket; +import org.springframework.web.socket.config.annotation.WebSocketConfigurer; +import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry; + +/** + * @Author: huangxing + * @Date: 2024/04/28 13:39 + */ +@Configuration +@EnableWebSocket +public class WebSocketConfig implements WebSocketConfigurer { + + @Override + public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { + registry.addHandler(interactiveHandler(), "/interactive/{sessionId}").setAllowedOrigins("*"); + } + @Bean + public WebSocketHandler interactiveHandler() { + return new InteractiveHandler(); + } + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/handler/InteractiveHandler.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/handler/InteractiveHandler.java new file mode 100644 index 0000000..1e4aae7 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/handler/InteractiveHandler.java @@ -0,0 +1,41 @@ +package com.hnac.hzims.bigmodel.websocket.handler; + +import com.hnac.hzims.bigmodel.websocket.sessionManager.InteractiveSessionManager; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.socket.CloseStatus; +import org.springframework.web.socket.TextMessage; +import org.springframework.web.socket.WebSocketSession; +import org.springframework.web.socket.handler.TextWebSocketHandler; + +/** + * @Author: huangxing + * @Date: 2024/04/28 13:45 + */ +@Slf4j +public class InteractiveHandler extends TextWebSocketHandler { + @Override + public void afterConnectionEstablished(WebSocketSession session) { + String[] split = session.getUri().toString().split("/"); + String sessionId = split[split.length - 1]; + session.getAttributes().put("sessionId", sessionId); + InteractiveSessionManager.add(sessionId, session); + log.info("sessionId: " + session.getId()); + log.info("uri: " + session.getUri()); + log.info("session connection successful!"); + } + + @Override + public void afterConnectionClosed(WebSocketSession session, CloseStatus status) { + String[] split = session.getUri().toString().split("/"); + String sessionId = split[split.length - 1]; + InteractiveSessionManager.removeAndClose(sessionId); + log.info("sessionId: " + session.getId()); + log.info("uri: " + session.getUri()); + log.info("session closed successful!"); + } + + @Override + protected void handleTextMessage(WebSocketSession session, TextMessage message) { + log.info("message handle successful!"); + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/server/InteractiveWsServer.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/server/InteractiveWsServer.java new file mode 100644 index 0000000..fdcd940 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/server/InteractiveWsServer.java @@ -0,0 +1,9 @@ +package com.hnac.hzims.bigmodel.websocket.server; + +/** + * @Author: huangxing + * @Date: 2024/04/28 13:38 + */ +public class InteractiveWsServer { + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/service/InteractiveWsService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/service/InteractiveWsService.java new file mode 100644 index 0000000..c7cce27 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/service/InteractiveWsService.java @@ -0,0 +1,32 @@ +package com.hnac.hzims.bigmodel.websocket.service; + +import com.alibaba.fastjson.JSON; +import com.hnac.hzims.bigmodel.websocket.sessionManager.InteractiveSessionManager; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.log.exception.ServiceException; +import org.springframework.stereotype.Service; +import org.springframework.web.socket.TextMessage; +import org.springframework.web.socket.WebSocketSession; + +import java.io.IOException; + +/** + * @Author: huangxing + * @Date: 2024/04/28 14:35 + */ +@Service +@Slf4j +public class InteractiveWsService implements WebSocketService { + + @Override + public Boolean sendMessage(String signage, TextMessage message) { + WebSocketSession session = InteractiveSessionManager.get(signage); + try { + session.sendMessage(message); + return true; + } catch (IOException e) { + log.error("消息推送失败,推送sessionId为:" + signage + ";消息体为:" + JSON.toJSONString(message)); + return false; + } + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/service/WebSocketService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/service/WebSocketService.java new file mode 100644 index 0000000..f4937ad --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/service/WebSocketService.java @@ -0,0 +1,13 @@ +package com.hnac.hzims.bigmodel.websocket.service; + +import org.springframework.web.socket.TextMessage; + +/** + * @Author: huangxing + * @Date: 2024/04/28 14:37 + */ +public interface WebSocketService { + + Boolean sendMessage(String signage, TextMessage message); + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/sessionManager/InteractiveSessionManager.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/sessionManager/InteractiveSessionManager.java new file mode 100644 index 0000000..6b13bbf --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/sessionManager/InteractiveSessionManager.java @@ -0,0 +1,56 @@ +package com.hnac.hzims.bigmodel.websocket.sessionManager; + +import org.springframework.web.socket.WebSocketSession; + +import java.io.IOException; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + +/** + * @Author: huangxing + * @Date: 2024/04/28 13:58 + */ +public class InteractiveSessionManager { + /** ws会话池 **/ + public static ConcurrentHashMap SESSION_POOL = new ConcurrentHashMap<>(); + + private static final Lock lock = new ReentrantLock(); + + /** + * 添加会话 + * @param sessionId 会话ID + * @param session 会话对象 + */ + public static void add(String sessionId, WebSocketSession session) { + if (SESSION_POOL.containsKey(sessionId)) { + InteractiveSessionManager.removeAndClose(sessionId); + } + SESSION_POOL.put(sessionId, session); + } + + /** + * 获取ws会话 + * @param sessionId 会话ID + */ + public static WebSocketSession get(String sessionId) { + return SESSION_POOL.get(sessionId); + } + + /** + * 移除ws会话并关闭会话 + * @param sessionId 会话ID + */ + public static void removeAndClose(String sessionId) { + WebSocketSession session = SESSION_POOL.get(sessionId); + if (session != null) { + try { + //关闭连接 + session.close(); + } catch (IOException ex) { + throw new RuntimeException("关闭ws会话失败!", ex); + } + } + SESSION_POOL.remove(sessionId); + } +} diff --git a/hzims-service/hzims-big-model/src/main/resources/db/1.0.0.sql b/hzims-service/hzims-big-model/src/main/resources/db/1.0.0.sql new file mode 100644 index 0000000..2a0cf7e --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/resources/db/1.0.0.sql @@ -0,0 +1,34 @@ +CREATE TABLE IF NOT EXISTS `hzims_function` ( + `ID` bigint(20) NOT NULL COMMENT '主键ID', + `NAME` varchar(50) COLLATE utf8mb4_bin NOT NULL COMMENT '函数名称', + `CODE` varchar(25) COLLATE utf8mb4_bin NOT NULL COMMENT '函数编号', + `TYPE` varchar(25) COLLATE utf8mb4_bin NOT NULL COMMENT '动作类型', + `IS_CONFIRM` tinyint(1) DEFAULT '0' COMMENT '是否需要确认,0:否,1:是', + `PATH` varchar(255) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '跳转路径', + `REMAKE` varchar(255) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '描述', + `TENANT_ID` varchar(12) CHARACTER SET utf8 DEFAULT NULL COMMENT '租户ID', + `STATUS` bigint(1) DEFAULT NULL COMMENT '状态', + `CREATE_DEPT` bigint(20) DEFAULT NULL COMMENT '创建单位', + `CREATE_USER` bigint(20) DEFAULT NULL COMMENT '创建人', + `CREATE_TIME` datetime DEFAULT NULL COMMENT '创建时间', + `UPDATE_USER` bigint(20) DEFAULT NULL COMMENT '修改人', + `UPDATE_TIME` datetime DEFAULT NULL COMMENT '更新时间', + `IS_DELETED` tinyint(4) NOT NULL COMMENT '是否删除', + PRIMARY KEY (`ID`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='模型函数'; + +CREATE TABLE IF NOT EXISTS `hzims_func_param` ( + `ID` bigint(20) NOT NULL COMMENT '主键ID', + `FUNC_ID` bigint(20) NOT NULL COMMENT '主键ID', + `NAME` varchar(50) COLLATE utf8mb4_bin NOT NULL COMMENT '参数名称', + `ALIAS` varchar(25) COLLATE utf8mb4_bin NOT NULL COMMENT '参数别名', + `TENANT_ID` varchar(12) CHARACTER SET utf8 DEFAULT NULL COMMENT '租户ID', + `STATUS` bigint(1) DEFAULT NULL COMMENT '状态', + `CREATE_DEPT` bigint(20) DEFAULT NULL COMMENT '创建单位', + `CREATE_USER` bigint(20) DEFAULT NULL COMMENT '创建人', + `CREATE_TIME` datetime DEFAULT NULL COMMENT '创建时间', + `UPDATE_USER` bigint(20) DEFAULT NULL COMMENT '修改人', + `UPDATE_TIME` datetime DEFAULT NULL COMMENT '更新时间', + `IS_DELETED` tinyint(4) NOT NULL COMMENT '是否删除', + PRIMARY KEY (`ID`) USING BTREE + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='模型函数参数'; \ No newline at end of file diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/mapper/TaskMapper.xml b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/mapper/TaskMapper.xml index 91b24ec..554313c 100644 --- a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/mapper/TaskMapper.xml +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/mapper/TaskMapper.xml @@ -15,6 +15,9 @@ and t.PLAN_START_TIME >= #{task.planStartTime} + + and t.PLAN_START_TIME >= #{task.planStartTime} + and t.PLAN_END_TIME <= #{task.planEndTime} diff --git a/hzims-service/pom.xml b/hzims-service/pom.xml index 05c9914..3bd858a 100644 --- a/hzims-service/pom.xml +++ b/hzims-service/pom.xml @@ -28,6 +28,7 @@ hzims-scheduled hzims-alarm hzims-basic + hzims-big-model