yang_shj
7 months ago
37 changed files with 1115 additions and 0 deletions
@ -0,0 +1,17 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||||
|
<parent> |
||||||
|
<artifactId>hzims-service-api</artifactId> |
||||||
|
<groupId>com.hnac.hzims</groupId> |
||||||
|
<version>4.0.0-SNAPSHOT</version> |
||||||
|
</parent> |
||||||
|
<modelVersion>4.0.0</modelVersion> |
||||||
|
<name>big-model-api</name> |
||||||
|
<artifactId>big-model-api</artifactId> |
||||||
|
|
||||||
|
<dependencies> |
||||||
|
|
||||||
|
</dependencies> |
||||||
|
|
||||||
|
</project> |
@ -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 = "大模型管理"; |
||||||
|
|
||||||
|
} |
@ -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; |
||||||
|
|
||||||
|
} |
@ -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; |
||||||
|
|
||||||
|
} |
@ -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<TypeEnum> typeEnumOptional = Arrays.stream(TypeEnum.class.getEnumConstants()).filter(e -> type.equals(e.getType())).findFirst(); |
||||||
|
return typeEnumOptional.orElse(null); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -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<String,String> functionArgs; |
||||||
|
|
||||||
|
} |
@ -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; |
||||||
|
|
||||||
|
} |
@ -0,0 +1,91 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||||
|
<parent> |
||||||
|
<groupId>com.hnac.hzims</groupId> |
||||||
|
<artifactId>hzims-service</artifactId> |
||||||
|
<version>4.0.0-SNAPSHOT</version> |
||||||
|
</parent> |
||||||
|
<modelVersion>4.0.0</modelVersion> |
||||||
|
<artifactId>hzims-big-model</artifactId> |
||||||
|
<name>big-model</name> |
||||||
|
<packaging>jar</packaging> |
||||||
|
|
||||||
|
<dependencies> |
||||||
|
<dependency> |
||||||
|
<groupId>org.springblade</groupId> |
||||||
|
<artifactId>blade-core-boot</artifactId> |
||||||
|
<exclusions> |
||||||
|
<exclusion> |
||||||
|
<groupId>org.springblade</groupId> |
||||||
|
<artifactId>blade-starter-redis</artifactId> |
||||||
|
</exclusion> |
||||||
|
</exclusions> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>org.springblade</groupId> |
||||||
|
<artifactId>blade-starter-swagger</artifactId> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>org.springblade</groupId> |
||||||
|
<artifactId>blade-core-test</artifactId> |
||||||
|
<scope>test</scope> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>org.springblade</groupId> |
||||||
|
<artifactId>blade-core-cloud</artifactId> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>com.hnac.hzims</groupId> |
||||||
|
<artifactId>big-model-api</artifactId> |
||||||
|
<version>4.0.0-SNAPSHOT</version> |
||||||
|
<scope>compile</scope> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<!-- spring-boot-websocket start --> |
||||||
|
<dependency> |
||||||
|
<groupId>org.springframework.boot</groupId> |
||||||
|
<artifactId>spring-boot-starter-websocket</artifactId> |
||||||
|
<exclusions> |
||||||
|
<exclusion> |
||||||
|
<groupId>org.springframework.boot</groupId> |
||||||
|
<artifactId>spring-boot-starter-tomcat</artifactId> |
||||||
|
</exclusion> |
||||||
|
</exclusions> |
||||||
|
</dependency> |
||||||
|
<!-- spring-boot-websocket end --> |
||||||
|
<dependency> |
||||||
|
<groupId>com.xuxueli</groupId> |
||||||
|
<artifactId>xxl-job-core</artifactId> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>org.springblade</groupId> |
||||||
|
<artifactId>blade-system-api</artifactId> |
||||||
|
</dependency> |
||||||
|
</dependencies> |
||||||
|
|
||||||
|
<build> |
||||||
|
<finalName>${project.name}-${project.version}</finalName> |
||||||
|
<plugins> |
||||||
|
<plugin> |
||||||
|
<groupId>com.spotify</groupId> |
||||||
|
<artifactId>dockerfile-maven-plugin</artifactId> |
||||||
|
<configuration> |
||||||
|
<username>${docker.username}</username> |
||||||
|
<password>${docker.password}</password> |
||||||
|
<repository>${docker.registry.url}/${docker.namespace}/${project.artifactId}</repository> |
||||||
|
<tag>${project.version}</tag> |
||||||
|
<useMavenSettingsForAuth>true</useMavenSettingsForAuth> |
||||||
|
<buildArgs> |
||||||
|
<JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE> |
||||||
|
</buildArgs> |
||||||
|
<skip>false</skip> |
||||||
|
</configuration> |
||||||
|
</plugin> |
||||||
|
</plugins> |
||||||
|
</build> |
||||||
|
|
||||||
|
</project> |
@ -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); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -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; |
||||||
|
|
||||||
|
} |
@ -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>> list(FunctionEntity req) { |
||||||
|
return R.data(functionService.list(Condition.getQueryWrapper(BeanUtil.toMap(req),FunctionEntity.class))); |
||||||
|
} |
||||||
|
|
||||||
|
@GetMapping("/page") |
||||||
|
@ApiOperation("分页查询") |
||||||
|
@ApiOperationSupport(order = 4) |
||||||
|
public R<IPage<FunctionEntity>> page(FunctionEntity req, Query query) { |
||||||
|
QueryWrapper<FunctionEntity> 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))); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -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>> list(FuncParamEntity req) { |
||||||
|
return R.data(funcParamService.list(Condition.getQueryWrapper(BeanUtil.toMap(req),FuncParamEntity.class))); |
||||||
|
} |
||||||
|
|
||||||
|
@GetMapping("/page") |
||||||
|
@ApiOperation("分页查询") |
||||||
|
@ApiOperationSupport(order = 4) |
||||||
|
public R<IPage<FuncParamEntity>> page(FuncParamEntity req, Query query) { |
||||||
|
QueryWrapper<FuncParamEntity> 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))); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -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<FuncParamEntity> { |
||||||
|
} |
@ -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<FunctionEntity> { |
||||||
|
|
||||||
|
} |
@ -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<FuncParamEntity> { |
||||||
|
|
||||||
|
/** |
||||||
|
* 根据函数ID获取参数列表 |
||||||
|
* @param funcId 函数ID |
||||||
|
* @return 参数列表 |
||||||
|
*/ |
||||||
|
List<FuncParamEntity> getParamsByFuncId(Long funcId); |
||||||
|
|
||||||
|
} |
@ -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> { |
||||||
|
|
||||||
|
FunctionEntity getFunctionByCode(String code); |
||||||
|
|
||||||
|
} |
@ -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<FuncParamMapper, FuncParamEntity> implements IFuncParamService { |
||||||
|
|
||||||
|
@Override |
||||||
|
public List<FuncParamEntity> getParamsByFuncId(Long funcId) { |
||||||
|
LambdaQueryWrapper<FuncParamEntity> queryWrapper = Wrappers.<FuncParamEntity>lambdaQuery().eq(FuncParamEntity::getFuncId, funcId); |
||||||
|
return this.list(queryWrapper); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -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<FunctionMapper, FunctionEntity> implements IFunctionService { |
||||||
|
|
||||||
|
@Override |
||||||
|
public FunctionEntity getFunctionByCode(String code) { |
||||||
|
LambdaQueryWrapper<FunctionEntity> queryWrapper = Wrappers.<FunctionEntity>lambdaQuery().eq(FunctionEntity::getCode, code); |
||||||
|
return this.getOne(queryWrapper); |
||||||
|
} |
||||||
|
} |
@ -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); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -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); |
||||||
|
|
||||||
|
} |
@ -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<String,String> args); |
||||||
|
|
||||||
|
} |
@ -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<String,String> 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")); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -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<String,String> args) { |
||||||
|
List<FuncParamEntity> params = paramService.getParamsByFuncId(function.getId()); |
||||||
|
Optional<FuncParamEntity> 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<Map.Entry<String, String>> entries = args.entrySet(); |
||||||
|
// 替换path中变量
|
||||||
|
for (Map.Entry<String, String> 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); |
||||||
|
} |
||||||
|
} |
@ -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<String> keySet = redisTemplate.keys(resultKey + "*"); |
||||||
|
keySet.parallelStream().forEach(key -> { |
||||||
|
// 根据Key获取sessionId
|
||||||
|
List<String> 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; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -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"; |
||||||
|
|
||||||
|
} |
@ -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(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -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!"); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,9 @@ |
|||||||
|
package com.hnac.hzims.bigmodel.websocket.server; |
||||||
|
|
||||||
|
/** |
||||||
|
* @Author: huangxing |
||||||
|
* @Date: 2024/04/28 13:38 |
||||||
|
*/ |
||||||
|
public class InteractiveWsServer { |
||||||
|
|
||||||
|
} |
@ -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; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -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); |
||||||
|
|
||||||
|
} |
@ -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<String, WebSocketSession> 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); |
||||||
|
} |
||||||
|
} |
@ -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='模型函数参数'; |
Loading…
Reference in new issue