Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
deep-ask
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
deepseek
deep-ask
Commits
8b435801
Commit
8b435801
authored
Feb 27, 2025
by
luojun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
对话记录添加
parent
4122cde8
Changes
67
Hide whitespace changes
Inline
Side-by-side
Showing
67 changed files
with
4130 additions
and
9 deletions
+4130
-9
pom.xml
pom.xml
+69
-0
DataPermission.java
src/main/java/admin/annotation/DataPermission.java
+52
-0
Query.java
src/main/java/admin/annotation/Query.java
+89
-0
Scene.java
src/main/java/admin/annotation/Scene.java
+17
-0
BaseDTO.java
src/main/java/admin/base/BaseDTO.java
+23
-0
BaseEntity.java
src/main/java/admin/base/BaseEntity.java
+65
-0
CommonMapper.java
src/main/java/admin/base/CommonMapper.java
+33
-0
CommonModel.java
src/main/java/admin/base/CommonModel.java
+13
-0
CommonService.java
src/main/java/admin/base/CommonService.java
+12
-0
PageInfo.java
src/main/java/admin/base/PageInfo.java
+31
-0
QueryHelpMybatisPlus.java
src/main/java/admin/base/QueryHelpMybatisPlus.java
+338
-0
CommonServiceImpl.java
src/main/java/admin/base/impl/CommonServiceImpl.java
+13
-0
DeepSeekAiListener.java
src/main/java/admin/listener/DeepSeekAiListener.java
+20
-2
WebSocketModel.java
src/main/java/admin/model/WebSocketModel.java
+28
-0
ChatgptRole.java
src/main/java/admin/modules/chatgpt/domain/ChatgptRole.java
+75
-0
ChatgptRoleDesc.java
...in/java/admin/modules/chatgpt/domain/ChatgptRoleDesc.java
+75
-0
ChatgptRoleRecords.java
...java/admin/modules/chatgpt/domain/ChatgptRoleRecords.java
+53
-0
ChatgptRoleSession.java
...java/admin/modules/chatgpt/domain/ChatgptRoleSession.java
+56
-0
ChatgptRoleType.java
...in/java/admin/modules/chatgpt/domain/ChatgptRoleType.java
+46
-0
RiskControlWords.java
...n/java/admin/modules/chatgpt/domain/RiskControlWords.java
+38
-0
ChatgptRoleDescService.java
...admin/modules/chatgpt/service/ChatgptRoleDescService.java
+59
-0
ChatgptRoleRecordsService.java
...in/modules/chatgpt/service/ChatgptRoleRecordsService.java
+86
-0
ChatgptRoleService.java
...ava/admin/modules/chatgpt/service/ChatgptRoleService.java
+54
-0
ChatgptRoleSessionService.java
...in/modules/chatgpt/service/ChatgptRoleSessionService.java
+58
-0
ChatgptRoleTypeService.java
...admin/modules/chatgpt/service/ChatgptRoleTypeService.java
+54
-0
RiskControlWordsService.java
...dmin/modules/chatgpt/service/RiskControlWordsService.java
+59
-0
ChatgptRoleDescDto.java
...admin/modules/chatgpt/service/dto/ChatgptRoleDescDto.java
+102
-0
ChatgptRoleDescQueryCriteria.java
...les/chatgpt/service/dto/ChatgptRoleDescQueryCriteria.java
+34
-0
ChatgptRoleDto.java
...ava/admin/modules/chatgpt/service/dto/ChatgptRoleDto.java
+64
-0
ChatgptRoleQueryCriteria.java
...modules/chatgpt/service/dto/ChatgptRoleQueryCriteria.java
+20
-0
ChatgptRoleRecordsDto.java
...in/modules/chatgpt/service/dto/ChatgptRoleRecordsDto.java
+46
-0
ChatgptRoleRecordsQueryCriteria.java
.../chatgpt/service/dto/ChatgptRoleRecordsQueryCriteria.java
+20
-0
ChatgptRoleSessionDto.java
...in/modules/chatgpt/service/dto/ChatgptRoleSessionDto.java
+49
-0
ChatgptRoleSessionQueryCriteria.java
.../chatgpt/service/dto/ChatgptRoleSessionQueryCriteria.java
+18
-0
ChatgptRoleTypeDto.java
...admin/modules/chatgpt/service/dto/ChatgptRoleTypeDto.java
+40
-0
ChatgptRoleTypeQueryCriteria.java
...les/chatgpt/service/dto/ChatgptRoleTypeQueryCriteria.java
+12
-0
RiskControlWordsDto.java
...dmin/modules/chatgpt/service/dto/RiskControlWordsDto.java
+36
-0
RiskControlWordsQueryCriteria.java
...es/chatgpt/service/dto/RiskControlWordsQueryCriteria.java
+17
-0
ChatgptRoleDescServiceImpl.java
...ules/chatgpt/service/impl/ChatgptRoleDescServiceImpl.java
+206
-0
ChatgptRoleRecordsServiceImpl.java
...s/chatgpt/service/impl/ChatgptRoleRecordsServiceImpl.java
+150
-0
ChatgptRoleServiceImpl.java
.../modules/chatgpt/service/impl/ChatgptRoleServiceImpl.java
+123
-0
ChatgptRoleSessionServiceImpl.java
...s/chatgpt/service/impl/ChatgptRoleSessionServiceImpl.java
+122
-0
ChatgptRoleTypeServiceImpl.java
...ules/chatgpt/service/impl/ChatgptRoleTypeServiceImpl.java
+114
-0
RiskControlWordsServiceImpl.java
...les/chatgpt/service/impl/RiskControlWordsServiceImpl.java
+125
-0
ChatgptRoleDescMapper.java
...modules/chatgpt/service/mapper/ChatgptRoleDescMapper.java
+16
-0
ChatgptRoleMapper.java
...min/modules/chatgpt/service/mapper/ChatgptRoleMapper.java
+16
-0
ChatgptRoleRecordsMapper.java
...ules/chatgpt/service/mapper/ChatgptRoleRecordsMapper.java
+29
-0
ChatgptRoleSessionMapper.java
...ules/chatgpt/service/mapper/ChatgptRoleSessionMapper.java
+18
-0
ChatgptRoleTypeMapper.java
...modules/chatgpt/service/mapper/ChatgptRoleTypeMapper.java
+16
-0
RiskControlWordsMapper.java
...odules/chatgpt/service/mapper/RiskControlWordsMapper.java
+16
-0
ChatgptRoleRecordsController.java
src/main/java/admin/rest/ChatgptRoleRecordsController.java
+53
-0
VoiceWebSocketServer.java
src/main/java/admin/server/VoiceWebSocketServer.java
+53
-3
DeepSeekOpenApiServiceImpl.java
...n/java/admin/service/impl/DeepSeekOpenApiServiceImpl.java
+1
-1
MaxkbOpenApiServiceImpl.java
...main/java/admin/service/impl/MaxkbOpenApiServiceImpl.java
+4
-1
ConvertUtil.java
src/main/java/admin/util/ConvertUtil.java
+38
-0
DateUtil.java
src/main/java/admin/util/DateUtil.java
+705
-0
HttpUtil.java
src/main/java/admin/util/HttpUtil.java
+2
-2
PageUtil.java
src/main/java/admin/util/PageUtil.java
+87
-0
ScreenEnum.java
src/main/java/admin/util/ScreenEnum.java
+54
-0
application.yml
src/main/resources/config/application.yml
+68
-0
log4jdbc.log4j2.properties
src/main/resources/log4jdbc.log4j2.properties
+4
-0
logback.xml
src/main/resources/logback.xml
+45
-0
ChatgptRoleDescMapper.xml
src/main/resources/mapper/ChatgptRoleDescMapper.xml
+11
-0
ChatgptRoleMapper.xml
src/main/resources/mapper/ChatgptRoleMapper.xml
+11
-0
ChatgptRoleRecordsMapper.xml
src/main/resources/mapper/ChatgptRoleRecordsMapper.xml
+44
-0
ChatgptRoleSessionMapper.xml
src/main/resources/mapper/ChatgptRoleSessionMapper.xml
+14
-0
ChatgptRoleTypeMapper.xml
src/main/resources/mapper/ChatgptRoleTypeMapper.xml
+11
-0
No files found.
pom.xml
View file @
8b435801
...
...
@@ -25,6 +25,11 @@
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-jpa
</artifactId>
</dependency>
<!-- sse长连接 -->
<dependency>
<groupId>
com.squareup.okhttp3
</groupId>
...
...
@@ -75,6 +80,70 @@
<version>
2.1.0.RELEASE
</version>
</dependency>
<!-- mybatis-plus -->
<dependency>
<groupId>
com.baomidou
</groupId>
<artifactId>
mybatis-plus-boot-starter
</artifactId>
<version>
3.5.3.1
</version>
</dependency>
<!-- mybatis-plus支持复合主键插件 -->
<dependency>
<groupId>
com.github.jeffreyning
</groupId>
<artifactId>
mybatisplus-plus
</artifactId>
<version>
1.5.1-RELEASE
</version>
</dependency>
<!-- mybatis-plus连表查询插件 -->
<dependency>
<groupId>
com.github.yulichang
</groupId>
<artifactId>
mybatis-plus-join-boot-starter
</artifactId>
<version>
1.4.5
</version>
</dependency>
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger2
</artifactId>
<version>
2.9.2
</version>
</dependency>
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger-ui
</artifactId>
<version>
2.9.2
</version>
</dependency>
<dependency>
<groupId>
cn.hutool
</groupId>
<artifactId>
hutool-all
</artifactId>
<version>
5.3.4
</version>
</dependency>
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-lang3
</artifactId>
</dependency>
<!--Mysql依赖包-->
<dependency>
<groupId>
mysql
</groupId>
<artifactId>
mysql-connector-java
</artifactId>
<version>
8.0.27
</version>
</dependency>
<!--监控sql日志-->
<dependency>
<groupId>
org.bgee.log4jdbc-log4j2
</groupId>
<artifactId>
log4jdbc-log4j2-jdbc4.1
</artifactId>
<version>
1.16
</version>
</dependency>
<!-- druid数据源驱动 -->
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
druid-spring-boot-starter
</artifactId>
<version>
1.1.22
</version>
</dependency>
<!--lombok插件-->
<dependency>
<groupId>
org.projectlombok
</groupId>
...
...
src/main/java/admin/annotation/DataPermission.java
0 → 100644
View file @
8b435801
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
admin
.
annotation
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
/**
* <p>
* 用于判断是否过滤数据权限
* 1、如果没有用到 @OneToOne 这种关联关系,只需要填写 fieldName [参考:DeptQueryCriteria.class]
* 2、如果用到了 @OneToOne ,fieldName 和 joinName 都需要填写,拿UserQueryCriteria.class举例:
* 应该是 @DataPermission(joinName = "dept", fieldName = "id")
* </p>
* @website https://el-admin.vip
* @date 2020-05-07
**/
@Target
(
ElementType
.
TYPE
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
public
@interface
DataPermission
{
/**
* Entity 中的字段名称
*/
String
fieldName
()
default
""
;
/**
* Entity 中与部门关联的字段名称
*/
String
joinName
()
default
""
;
/**
* 忽略场景配置
* 与 @Scene 配合使用
*/
String
[]
ignoreScene
()
default
{};
}
src/main/java/admin/annotation/Query.java
0 → 100644
View file @
8b435801
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
admin
.
annotation
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
/**
* @author Zheng Jie
* @date 2019-6-4 13:52:30
*/
@Target
(
ElementType
.
FIELD
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
public
@interface
Query
{
// Dong ZhaoYang 2017/8/7 基本对象的属性名
String
propName
()
default
""
;
// Dong ZhaoYang 2017/8/7 查询方式
Type
type
()
default
Type
.
EQUAL
;
/**
* 连接查询的属性名,如User类中的dept
*/
String
joinName
()
default
""
;
/**
* 默认左连接
*/
Join
join
()
default
Join
.
LEFT
;
/**
* 多字段模糊搜索,仅支持String类型字段,多个用逗号隔开, 如@Query(blurry = "email,username")
*/
String
blurry
()
default
""
;
enum
Type
{
// jie 2019/6/4 相等
EQUAL
// Dong ZhaoYang 2017/8/7 大于等于
,
GREATER_THAN
// Dong ZhaoYang 2017/8/7 小于等于
,
LESS_THAN
// Dong ZhaoYang 2017/8/7 中模糊查询
,
INNER_LIKE
// Dong ZhaoYang 2017/8/7 左模糊查询
,
LEFT_LIKE
// Dong ZhaoYang 2017/8/7 右模糊查询
,
RIGHT_LIKE
// Dong ZhaoYang 2017/8/7 小于
,
LESS_THAN_NQ
// jie 2019/6/4 包含
,
IN
// 不包含
,
NOT_IN
// 不等于
,
NOT_EQUAL
// between
,
BETWEEN
// 不为空
,
NOT_NULL
// 为空
,
IS_NULL
}
/**
* 适用于简单连接查询,复杂的请自定义该注解,或者使用sql查询
*/
enum
Join
{
/** jie 2019-6-4 13:18:30 */
LEFT
,
RIGHT
,
INNER
}
}
src/main/java/admin/annotation/Scene.java
0 → 100644
View file @
8b435801
package
admin
.
annotation
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
/**
* 场景值注解 用于标识参数字段 是场景值字段
* @author fanglei
* @date 2021/09/06
*/
@Target
(
ElementType
.
FIELD
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
public
@interface
Scene
{
}
src/main/java/admin/base/BaseDTO.java
0 → 100644
View file @
8b435801
package
admin
.
base
;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.util.Date
;
/**
* @date 2019年10月24日20:48:53
*/
@Data
public
class
BaseDTO
implements
Serializable
{
private
String
createBy
;
private
String
updatedBy
;
private
Date
createTime
;
private
Date
updateTime
;
}
src/main/java/admin/base/BaseEntity.java
0 → 100644
View file @
8b435801
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
admin
.
base
;
import
com.baomidou.mybatisplus.annotation.FieldFill
;
import
com.baomidou.mybatisplus.annotation.TableField
;
import
com.baomidou.mybatisplus.extension.activerecord.Model
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
org.springframework.data.annotation.CreatedBy
;
import
org.springframework.data.annotation.LastModifiedBy
;
import
java.io.Serializable
;
import
java.lang.reflect.Field
;
import
java.util.Date
;
/**
* 抽象实体类 :带有公共字段,根据需求自行添加
* @Date 2019年10月24日20:46:32
*/
@Data
public
abstract
class
BaseEntity
<
T
extends
Model
<?>>
extends
CommonModel
<
T
>
implements
Serializable
{
@CreatedBy
// @Column(name = "create_by", updatable = false)
@ApiModelProperty
(
value
=
"创建人"
,
hidden
=
true
)
@TableField
(
value
=
"create_by"
)
private
String
createBy
;
@LastModifiedBy
// @Column(name = "update_by")
@TableField
(
value
=
"update_by"
)
@ApiModelProperty
(
value
=
"更新人"
,
hidden
=
true
)
private
String
updatedBy
;
@TableField
(
value
=
"create_time"
,
fill
=
FieldFill
.
INSERT
)
// @Column(name = "create_time", updatable = false)
@ApiModelProperty
(
value
=
"创建时间"
,
hidden
=
true
)
private
Date
createTime
;
@TableField
(
value
=
"update_time"
,
fill
=
FieldFill
.
INSERT_UPDATE
)
// @Column(name = "update_time")
@ApiModelProperty
(
value
=
"更新时间"
,
hidden
=
true
)
private
Date
updateTime
;
/* 分组校验 */
public
@interface
Create
{}
/* 分组校验 */
public
@interface
Update
{}
}
src/main/java/admin/base/CommonMapper.java
0 → 100644
View file @
8b435801
package
admin
.
base
;
import
com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper
;
import
com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper
;
import
com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper
;
import
com.baomidou.mybatisplus.extension.conditions.update.UpdateChainWrapper
;
import
com.baomidou.mybatisplus.extension.toolkit.ChainWrappers
;
import
com.github.yulichang.base.MPJBaseMapper
;
import
org.apache.ibatis.annotations.Mapper
;
/**
* 公共抽象Mapper接口类
* @author fanglei
* @date 2021/07/28
*/
@Mapper
public
interface
CommonMapper
<
E
>
extends
MPJBaseMapper
<
E
>
{
default
QueryChainWrapper
<
E
>
query
()
{
return
ChainWrappers
.
queryChain
(
this
);
}
default
LambdaQueryChainWrapper
<
E
>
lambdaQuery
()
{
return
ChainWrappers
.
lambdaQueryChain
(
this
);
}
default
UpdateChainWrapper
<
E
>
update
()
{
return
ChainWrappers
.
updateChain
(
this
);
}
default
LambdaUpdateChainWrapper
<
E
>
lambdaUpdate
()
{
return
ChainWrappers
.
lambdaUpdateChain
(
this
);
}
}
src/main/java/admin/base/CommonModel.java
0 → 100644
View file @
8b435801
package
admin
.
base
;
import
com.baomidou.mybatisplus.extension.activerecord.Model
;
/**
* 抽象实体类:无公共字段
*
* @author fanglei
* @date 2021/07/28 15:26
**/
public
abstract
class
CommonModel
<
T
extends
Model
<?>>
extends
Model
<
T
>
{
}
src/main/java/admin/base/CommonService.java
0 → 100644
View file @
8b435801
package
admin
.
base
;
import
com.github.yulichang.base.MPJBaseService
;
/**
* 公共抽象接口类
* @author fanglei
* @date 2021/07/28
*/
public
interface
CommonService
<
T
>
extends
MPJBaseService
<
T
>
{
}
src/main/java/admin/base/PageInfo.java
0 → 100644
View file @
8b435801
package
admin
.
base
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.experimental.Accessors
;
import
java.io.Serializable
;
import
java.util.List
;
/**
* Created by jinjin on 2020-09-22.
*/
@Data
@Builder
@Accessors
(
chain
=
true
)
public
class
PageInfo
<
T
>
implements
Serializable
{
@ApiModelProperty
(
"总数量"
)
private
long
totalElements
;
@ApiModelProperty
(
"内容"
)
private
List
<
T
>
content
;
public
PageInfo
(
long
totalElements
,
List
<
T
>
content
)
{
this
.
totalElements
=
totalElements
;
this
.
content
=
content
;
}
public
PageInfo
()
{
}
}
src/main/java/admin/base/QueryHelpMybatisPlus.java
0 → 100644
View file @
8b435801
package
admin
.
base
;
import
admin.annotation.DataPermission
;
import
admin.annotation.Query
;
import
admin.annotation.Scene
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.util.ArrayUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.core.util.StrUtil
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.github.yulichang.wrapper.MPJLambdaWrapper
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.util.ReflectionUtils
;
import
java.lang.reflect.Field
;
import
java.util.*
;
/**
* @author Zheng Jie
* @date 2019-6-4 14:59:48
*/
@Slf4j
public
class
QueryHelpMybatisPlus
{
// TODO DataPermission
public
static
<
R
,
Q
>
QueryWrapper
<
R
>
getPredicate
(
Q
query
)
{
QueryWrapper
<
R
>
queryWrapper
=
new
QueryWrapper
<>();
if
(
query
==
null
)
{
return
queryWrapper
;
}
// 数据权限验证
DataPermission
permission
=
query
.
getClass
().
getAnnotation
(
DataPermission
.
class
);
if
(
permission
!=
null
){
// 获取数据权限
// List<Long> dataScopes = SecurityUtils.getCurrentUserDataScope();
// if(CollectionUtil.isNotEmpty(dataScopes)){
// 过滤场景
boolean
ignoreScene
=
false
;
if
(
ArrayUtil
.
isNotEmpty
(
permission
.
ignoreScene
()))
{
boolean
exits
=
query
.
getClass
().
isAnnotationPresent
(
Scene
.
class
);
if
(
exits
)
{
for
(
Field
field
:
query
.
getClass
().
getDeclaredFields
())
{
Scene
scene
=
field
.
getAnnotation
(
Scene
.
class
);
if
(
scene
!=
null
)
{
Object
sceneValue
=
ReflectionUtils
.
getField
(
field
,
query
);
if
(
Objects
.
nonNull
(
sceneValue
))
{
if
(
StringUtils
.
equalsAny
(
String
.
valueOf
(
sceneValue
),
permission
.
ignoreScene
()))
{
ignoreScene
=
true
;
break
;
}
}
}
}
}
else
{
throw
new
RuntimeException
(
"需要用 @Scene 注解标识场景字段值, 根据字段对应的值判断是否忽略"
);
}
}
if
(!
ignoreScene
)
{
if
(
StringUtils
.
isNotBlank
(
permission
.
joinName
())
&&
StringUtils
.
isNotBlank
(
permission
.
fieldName
()))
{
//Join join = root.join(permission.joinName(), JoinType.LEFT);
//list.add(getExpression(permission.fieldName(),join, root).in(dataScopes));
throw
new
RuntimeException
(
"未实现"
);
}
// else if (StringUtils.isBlank(permission.joinName()) && StringUtils.isNotBlank(permission.fieldName())) {
// //list.add(getExpression(permission.fieldName(),null, root).in(dataScopes));
// queryWrapper.in(permission.fieldName(), dataScopes);
// }
}
// }
}
try
{
List
<
Field
>
fields
=
getAllFields
(
query
.
getClass
(),
new
ArrayList
<>());
for
(
Field
field
:
fields
)
{
boolean
accessible
=
field
.
isAccessible
();
field
.
setAccessible
(
true
);
Query
q
=
field
.
getAnnotation
(
Query
.
class
);
if
(
q
!=
null
)
{
String
propName
=
q
.
propName
();
String
blurry
=
q
.
blurry
();
String
attributeName
=
StrUtil
.
isBlank
(
propName
)
?
field
.
getName
()
:
propName
;
attributeName
=
humpToUnderline
(
attributeName
);
Class
<?>
fieldType
=
field
.
getType
();
Object
val
=
field
.
get
(
query
);
if
(
ObjectUtil
.
isNull
(
val
)
||
""
.
equals
(
val
))
{
continue
;
}
// 模糊多字段
if
(
ObjectUtil
.
isNotEmpty
(
blurry
))
{
String
[]
blurrys
=
blurry
.
split
(
","
);
//queryWrapper.or();
queryWrapper
.
and
(
wrapper
->
{
for
(
String
blurry1
:
blurrys
)
{
String
column
=
humpToUnderline
(
blurry1
);
//if(i!=0){
wrapper
.
or
();
//}
wrapper
.
like
(
column
,
val
.
toString
());
}
});
continue
;
}
String
finalAttributeName
=
attributeName
;
switch
(
q
.
type
())
{
case
EQUAL:
//queryWrapper.and(wrapper -> wrapper.eq(finalAttributeName, val));
queryWrapper
.
eq
(
attributeName
,
val
);
break
;
case
GREATER_THAN:
queryWrapper
.
ge
(
finalAttributeName
,
val
);
break
;
case
LESS_THAN:
queryWrapper
.
le
(
finalAttributeName
,
val
);
break
;
case
LESS_THAN_NQ:
queryWrapper
.
lt
(
finalAttributeName
,
val
);
break
;
case
INNER_LIKE:
queryWrapper
.
like
(
finalAttributeName
,
val
);
break
;
case
LEFT_LIKE:
queryWrapper
.
likeLeft
(
finalAttributeName
,
val
);
break
;
case
RIGHT_LIKE:
queryWrapper
.
likeRight
(
finalAttributeName
,
val
);
break
;
case
IN:
if
(
CollUtil
.
isNotEmpty
((
Collection
<
Long
>)
val
))
{
queryWrapper
.
in
(
finalAttributeName
,
(
Collection
<
Long
>)
val
);
}
break
;
case
NOT_IN:
if
(
CollUtil
.
isNotEmpty
((
Collection
<
Long
>)
val
))
{
queryWrapper
.
notIn
(
finalAttributeName
,
(
Collection
<
Long
>)
val
);
}
break
;
case
NOT_EQUAL:
queryWrapper
.
ne
(
finalAttributeName
,
val
);
break
;
case
NOT_NULL:
queryWrapper
.
isNotNull
(
finalAttributeName
);
break
;
case
IS_NULL:
queryWrapper
.
isNull
(
finalAttributeName
);
break
;
case
BETWEEN:
List
<
Object
>
between
=
new
ArrayList
<>((
List
<
Object
>)
val
);
queryWrapper
.
between
(
finalAttributeName
,
between
.
get
(
0
),
between
.
get
(
1
));
break
;
default
:
break
;
}
}
field
.
setAccessible
(
accessible
);
}
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
}
return
queryWrapper
;
}
// TODO DataPermission
public
static
<
R
,
Q
>
MPJLambdaWrapper
<
R
>
getPredicateMPJ
(
Q
query
)
{
MPJLambdaWrapper
<
R
>
queryWrapper
=
new
MPJLambdaWrapper
<>();
if
(
query
==
null
)
{
return
queryWrapper
;
}
// 数据权限验证
DataPermission
permission
=
query
.
getClass
().
getAnnotation
(
DataPermission
.
class
);
if
(
permission
!=
null
){
// 获取数据权限
// List<Long> dataScopes = SecurityUtils.getCurrentUserDataScope();
// if(CollectionUtil.isNotEmpty(dataScopes)){
// 过滤场景
boolean
ignoreScene
=
false
;
if
(
ArrayUtil
.
isNotEmpty
(
permission
.
ignoreScene
()))
{
boolean
exits
=
query
.
getClass
().
isAnnotationPresent
(
Scene
.
class
);
if
(
exits
)
{
for
(
Field
field
:
query
.
getClass
().
getDeclaredFields
())
{
Scene
scene
=
field
.
getAnnotation
(
Scene
.
class
);
if
(
scene
!=
null
)
{
Object
sceneValue
=
ReflectionUtils
.
getField
(
field
,
query
);
if
(
Objects
.
nonNull
(
sceneValue
))
{
if
(
StringUtils
.
equalsAny
(
String
.
valueOf
(
sceneValue
),
permission
.
ignoreScene
()))
{
ignoreScene
=
true
;
break
;
}
}
}
}
}
else
{
throw
new
RuntimeException
(
"需要用 @Scene 注解标识场景字段值, 根据字段对应的值判断是否忽略"
);
}
}
if
(!
ignoreScene
)
{
if
(
StringUtils
.
isNotBlank
(
permission
.
joinName
())
&&
StringUtils
.
isNotBlank
(
permission
.
fieldName
()))
{
//Join join = root.join(permission.joinName(), JoinType.LEFT);
//list.add(getExpression(permission.fieldName(),join, root).in(dataScopes));
throw
new
RuntimeException
(
"未实现"
);
}
// else if (StringUtils.isBlank(permission.joinName()) && StringUtils.isNotBlank(permission.fieldName())) {
// //list.add(getExpression(permission.fieldName(),null, root).in(dataScopes));
// queryWrapper.in(permission.fieldName(), dataScopes);
// }
}
// }
}
try
{
List
<
Field
>
fields
=
getAllFields
(
query
.
getClass
(),
new
ArrayList
<>());
for
(
Field
field
:
fields
)
{
boolean
accessible
=
field
.
isAccessible
();
field
.
setAccessible
(
true
);
Query
q
=
field
.
getAnnotation
(
Query
.
class
);
if
(
q
!=
null
)
{
String
propName
=
q
.
propName
();
String
blurry
=
q
.
blurry
();
String
attributeName
=
StrUtil
.
isBlank
(
propName
)
?
field
.
getName
()
:
propName
;
attributeName
=
humpToUnderline
(
attributeName
);
Class
<?>
fieldType
=
field
.
getType
();
Object
val
=
field
.
get
(
query
);
if
(
ObjectUtil
.
isNull
(
val
)
||
""
.
equals
(
val
))
{
continue
;
}
// 模糊多字段
if
(
ObjectUtil
.
isNotEmpty
(
blurry
))
{
String
[]
blurrys
=
blurry
.
split
(
","
);
//queryWrapper.or();
queryWrapper
.
and
(
wrapper
->
{
for
(
String
blurry1
:
blurrys
)
{
String
column
=
humpToUnderline
(
blurry1
);
//if(i!=0){
wrapper
.
or
();
//}
wrapper
.
like
(
column
,
val
.
toString
());
}
});
continue
;
}
String
finalAttributeName
=
attributeName
;
switch
(
q
.
type
())
{
case
EQUAL:
//queryWrapper.and(wrapper -> wrapper.eq(finalAttributeName, val));
queryWrapper
.
eq
(
attributeName
,
val
);
break
;
case
GREATER_THAN:
queryWrapper
.
ge
(
finalAttributeName
,
val
);
break
;
case
LESS_THAN:
queryWrapper
.
le
(
finalAttributeName
,
val
);
break
;
case
LESS_THAN_NQ:
queryWrapper
.
lt
(
finalAttributeName
,
val
);
break
;
case
INNER_LIKE:
queryWrapper
.
like
(
finalAttributeName
,
val
);
break
;
case
LEFT_LIKE:
queryWrapper
.
likeLeft
(
finalAttributeName
,
val
);
break
;
case
RIGHT_LIKE:
queryWrapper
.
likeRight
(
finalAttributeName
,
val
);
break
;
case
IN:
if
(
CollUtil
.
isNotEmpty
((
Collection
<
Long
>)
val
))
{
queryWrapper
.
in
(
finalAttributeName
,
(
Collection
<
Long
>)
val
);
}
break
;
case
NOT_IN:
if
(
CollUtil
.
isNotEmpty
((
Collection
<
Long
>)
val
))
{
queryWrapper
.
notIn
(
finalAttributeName
,
(
Collection
<
Long
>)
val
);
}
break
;
case
NOT_EQUAL:
queryWrapper
.
ne
(
finalAttributeName
,
val
);
break
;
case
NOT_NULL:
queryWrapper
.
isNotNull
(
finalAttributeName
);
break
;
case
IS_NULL:
queryWrapper
.
isNull
(
finalAttributeName
);
break
;
case
BETWEEN:
List
<
Object
>
between
=
new
ArrayList
<>((
List
<
Object
>)
val
);
queryWrapper
.
between
(
finalAttributeName
,
between
.
get
(
0
),
between
.
get
(
1
));
break
;
default
:
break
;
}
}
field
.
setAccessible
(
accessible
);
}
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
}
return
queryWrapper
;
}
public
static
List
<
Field
>
getAllFields
(
Class
clazz
,
List
<
Field
>
fields
)
{
if
(
clazz
!=
null
)
{
fields
.
addAll
(
Arrays
.
asList
(
clazz
.
getDeclaredFields
()));
getAllFields
(
clazz
.
getSuperclass
(),
fields
);
}
return
fields
;
}
/***
* 驼峰命名转为下划线命名
*
* @param para
* 驼峰命名的字符串
*/
public
static
String
humpToUnderline
(
String
para
)
{
return
StrUtil
.
toUnderlineCase
(
para
);
}
// public static void main(String[] args) {
// QueryWrapper<Paging> query = new QueryWrapper<Paging>();
// //query.or();
// query.or(wrapper -> wrapper.eq("store_id", 1).or().eq("store_id", 2));
// //query.like("a",1);
// //query.or();
// //query.like("b",2);
// //query.and(wrapper->wrapper.eq("c",1));
// query.eq("1", 1);
//
// System.out.println(query.getSqlSegment());
// }
}
src/main/java/admin/base/impl/CommonServiceImpl.java
0 → 100644
View file @
8b435801
package
admin
.
base
.
impl
;
import
admin.base.CommonService
;
import
com.github.yulichang.base.MPJBaseMapper
;
import
com.github.yulichang.base.MPJBaseServiceImpl
;
/**
* 公共抽象service实现类
* @author fanglei
* @date 2021/07/28
*/
public
abstract
class
CommonServiceImpl
<
M
extends
MPJBaseMapper
<
T
>,
T
>
extends
MPJBaseServiceImpl
<
M
,
T
>
implements
CommonService
<
T
>
{
}
src/main/java/admin/listener/DeepSeekAiListener.java
View file @
8b435801
...
...
@@ -3,7 +3,10 @@ package admin.listener;
import
admin.model.deepseek.resp.stream.ChatStreamResponse
;
import
admin.model.maxdb.resp.MaxdbStreamResponse
;
import
admin.modules.chatgpt.domain.ChatgptRoleRecords
;
import
admin.modules.chatgpt.service.ChatgptRoleRecordsService
;
import
admin.service.TextToSpeechService
;
import
admin.util.DateUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.fasterxml.jackson.databind.DeserializationFeature
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
...
...
@@ -31,14 +34,22 @@ public class DeepSeekAiListener extends EventSourceListener {
StringBuffer
stringBuffer
=
new
StringBuffer
();
private
Session
session
;
private
String
sessionId
;
private
static
TextToSpeechService
textToSpeechService
;
private
static
ChatgptRoleRecordsService
chatgptRoleRecordsService
;
@Resource
public
static
void
setTextToSpeechService
(
TextToSpeechService
textToSpeechService
){
DeepSeekAiListener
.
textToSpeechService
=
textToSpeechService
;
}
public
DeepSeekAiListener
(
Session
session
)
{
@Resource
public
static
void
setChatgptRoleRecordsService
(
ChatgptRoleRecordsService
chatgptRoleRecordsService
){
DeepSeekAiListener
.
chatgptRoleRecordsService
=
chatgptRoleRecordsService
;
}
public
DeepSeekAiListener
(
Session
session
,
String
sessionId
)
{
this
.
session
=
session
;
this
.
sessionId
=
sessionId
;
}
@Override
...
...
@@ -51,7 +62,7 @@ public class DeepSeekAiListener extends EventSourceListener {
@Override
public
void
onEvent
(
EventSource
eventSource
,
String
id
,
String
type
,
String
data
)
{
super
.
onEvent
(
eventSource
,
id
,
type
,
data
);
//回复内容添加 sessionId
Gson
gson
=
new
Gson
();
try
{
MaxdbStreamResponse
completionResponse
=
gson
.
fromJson
(
data
,
MaxdbStreamResponse
.
class
);
...
...
@@ -76,6 +87,13 @@ public class DeepSeekAiListener extends EventSourceListener {
String
msg
=
JSON
.
toJSONString
(
map
);
this
.
session
.
getBasicRemote
().
sendText
(
msg
);
}
//存储聊天记录
ChatgptRoleRecords
chatgptRoleRecords
=
new
ChatgptRoleRecords
();
chatgptRoleRecords
.
setMessage
(
this
.
stringBuffer
.
toString
());
chatgptRoleRecords
.
setReceiverId
(
Integer
.
valueOf
(
sessionId
));
chatgptRoleRecords
.
setSenderId
(
10001
);
chatgptRoleRecords
.
setCreateTime
(
DateUtil
.
getNowTimestamp
());
chatgptRoleRecordsService
.
save
(
chatgptRoleRecords
);
}
catch
(
Exception
e
){
System
.
out
.
println
(
e
.
getMessage
());
}
...
...
src/main/java/admin/model/WebSocketModel.java
0 → 100644
View file @
8b435801
package
admin
.
model
;
import
lombok.Data
;
/**
* @author lj
* @date 2025/2/27 17:38
*/
@Data
public
class
WebSocketModel
{
private
String
action
;
private
String
content
;
private
String
type
;
/**
* 会话id
*/
private
String
sessionId
;
/**
* 数据
*/
private
String
data
;
/**
* 大屏账号名称
*/
private
String
name
;
}
src/main/java/admin/modules/chatgpt/domain/ChatgptRole.java
0 → 100644
View file @
8b435801
package
admin
.
modules
.
chatgpt
.
domain
;
import
cn.hutool.core.bean.BeanUtil
;
import
cn.hutool.core.bean.copier.CopyOptions
;
import
com.baomidou.mybatisplus.annotation.*
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.*
;
import
lombok.experimental.Accessors
;
import
javax.validation.constraints.NotBlank
;
import
javax.validation.constraints.NotNull
;
import
java.io.Serializable
;
import
java.sql.Timestamp
;
/**
* @author wk
* @date 2023-11-27
*/
@Data
@Builder
@Accessors
(
chain
=
true
)
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode
(
callSuper
=
false
)
@TableName
(
"chatgpt_role"
)
public
class
ChatgptRole
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
@ApiModelProperty
(
value
=
"唯一标识,自动递增"
)
@TableId
(
type
=
IdType
.
AUTO
)
private
Integer
id
;
@ApiModelProperty
(
value
=
"角色名称"
)
private
String
roleName
;
@ApiModelProperty
(
value
=
"角色prompt"
)
private
String
roleMessage
;
@ApiModelProperty
(
value
=
"模型"
)
@NotBlank
private
String
model
;
@ApiModelProperty
(
value
=
"创建时间"
)
@NotNull
@TableField
(
fill
=
FieldFill
.
INSERT
)
private
Timestamp
createTime
;
@ApiModelProperty
(
value
=
"内容创意 该值越大,输出内容更加随机,推荐值:1"
)
@NotNull
private
Double
temperature
;
@ApiModelProperty
(
value
=
"最大token"
)
@NotNull
private
Integer
maxTokens
;
@ApiModelProperty
(
value
=
"质量概率 核心采样,指选用前多少概率质量的内容,推荐值:1"
)
@NotNull
private
Double
topP
;
@ApiModelProperty
(
value
=
"重复词汇 输出文本同一个词汇出现情况,默认为0,值越大,重复性越小,推荐值:0"
)
@NotNull
private
Double
presencePenalty
;
@ApiModelProperty
(
value
=
"罕见词汇 输出文本罕见词汇出现情况,默认为0,值越大,罕见词汇越多,推荐值:0"
)
@NotNull
private
Double
frequencyPenalty
;
@ApiModelProperty
(
value
=
"回答数量 为每个问题回答的内容数量,当多个时,会消耗大量Token,推荐值:1"
)
@NotNull
private
Integer
n
;
public
void
copyFrom
(
ChatgptRole
source
){
BeanUtil
.
copyProperties
(
source
,
this
,
CopyOptions
.
create
().
setIgnoreNullValue
(
true
));
}
}
src/main/java/admin/modules/chatgpt/domain/ChatgptRoleDesc.java
0 → 100644
View file @
8b435801
package
admin
.
modules
.
chatgpt
.
domain
;
import
cn.hutool.core.bean.BeanUtil
;
import
cn.hutool.core.bean.copier.CopyOptions
;
import
com.baomidou.mybatisplus.annotation.*
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.*
;
import
lombok.experimental.Accessors
;
import
javax.validation.constraints.NotBlank
;
import
javax.validation.constraints.NotNull
;
import
java.io.Serializable
;
import
java.math.BigDecimal
;
import
java.util.Date
;
/**
* @author wk
* @date 2023-11-27
*/
@Data
@Builder
@Accessors
(
chain
=
true
)
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode
(
callSuper
=
false
)
@TableName
(
"chatgpt_role_desc"
)
public
class
ChatgptRoleDesc
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
@ApiModelProperty
(
value
=
"主键"
)
@TableId
(
type
=
IdType
.
AUTO
)
private
Integer
id
;
@ApiModelProperty
(
value
=
"标题"
)
@NotBlank
private
String
title
;
@ApiModelProperty
(
value
=
"内容"
)
private
String
description
;
@ApiModelProperty
(
value
=
"进入聊天提示内容"
)
private
String
chat
;
@ApiModelProperty
(
value
=
"图片"
)
@NotBlank
private
String
image
;
@ApiModelProperty
(
value
=
"角色id"
)
private
Integer
roleId
;
@ApiModelProperty
(
value
=
"排序序号"
)
@NotNull
private
BigDecimal
sortNum
;
@ApiModelProperty
(
value
=
"上线状态"
)
private
Integer
postStatus
;
@ApiModelProperty
(
value
=
"创建时间"
)
@TableField
(
fill
=
FieldFill
.
INSERT
)
private
Date
createDate
;
@ApiModelProperty
(
value
=
"更新时间"
)
@TableField
(
fill
=
FieldFill
.
INSERT_UPDATE
)
private
Date
updateDate
;
@ApiModelProperty
(
value
=
"角色类型"
)
private
String
roleTypeId
;
@ApiModelProperty
(
value
=
"类别[1=角色对话,2=AI创作,3=首页]"
)
private
Integer
classify
;
public
void
copyFrom
(
ChatgptRoleDesc
source
){
BeanUtil
.
copyProperties
(
source
,
this
,
CopyOptions
.
create
().
setIgnoreNullValue
(
true
));
}
}
src/main/java/admin/modules/chatgpt/domain/ChatgptRoleRecords.java
0 → 100644
View file @
8b435801
package
admin
.
modules
.
chatgpt
.
domain
;
import
cn.hutool.core.bean.BeanUtil
;
import
cn.hutool.core.bean.copier.CopyOptions
;
import
com.baomidou.mybatisplus.annotation.*
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.*
;
import
lombok.experimental.Accessors
;
import
javax.validation.constraints.NotNull
;
import
java.io.Serializable
;
import
java.sql.Timestamp
;
/**
* @author wk
* @date 2023-11-27
*/
@Data
@Builder
@Accessors
(
chain
=
true
)
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode
(
callSuper
=
false
)
@TableName
(
"chatgpt_role_records"
)
public
class
ChatgptRoleRecords
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
@ApiModelProperty
(
value
=
"唯一标识,自动递增"
)
@TableId
(
type
=
IdType
.
AUTO
)
private
Integer
id
;
@ApiModelProperty
(
value
=
"会话id"
)
private
Integer
sessionId
;
@ApiModelProperty
(
value
=
"发送者id"
)
@NotNull
private
Integer
senderId
;
@ApiModelProperty
(
value
=
"接收者id"
)
@NotNull
private
Integer
receiverId
;
@ApiModelProperty
(
value
=
"聊天消息的内容"
)
private
String
message
;
@ApiModelProperty
(
value
=
"创建时间"
)
@TableField
(
fill
=
FieldFill
.
INSERT
)
private
Timestamp
createTime
;
public
void
copyFrom
(
ChatgptRoleRecords
source
){
BeanUtil
.
copyProperties
(
source
,
this
,
CopyOptions
.
create
().
setIgnoreNullValue
(
true
));
}
}
src/main/java/admin/modules/chatgpt/domain/ChatgptRoleSession.java
0 → 100644
View file @
8b435801
package
admin
.
modules
.
chatgpt
.
domain
;
import
cn.hutool.core.bean.BeanUtil
;
import
cn.hutool.core.bean.copier.CopyOptions
;
import
com.baomidou.mybatisplus.annotation.*
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.*
;
import
lombok.experimental.Accessors
;
import
javax.validation.constraints.NotBlank
;
import
javax.validation.constraints.NotNull
;
import
java.io.Serializable
;
import
java.sql.Timestamp
;
/**
* @author wk
* @date 2023-11-28
*/
@Data
@Builder
@Accessors
(
chain
=
true
)
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode
(
callSuper
=
false
)
@TableName
(
"chatgpt_role_session"
)
public
class
ChatgptRoleSession
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
@ApiModelProperty
(
value
=
"唯一标识,自动递增"
)
@TableId
(
type
=
IdType
.
AUTO
)
private
Integer
id
;
@ApiModelProperty
(
value
=
"名称"
)
@NotBlank
private
String
name
;
@ApiModelProperty
(
value
=
"角色描述id"
)
@NotNull
private
Integer
roleDescId
;
@ApiModelProperty
(
value
=
"用户id"
)
@NotNull
private
Integer
userId
;
@ApiModelProperty
(
value
=
"创建时间"
)
@TableField
(
fill
=
FieldFill
.
INSERT
)
private
Timestamp
createTime
;
@ApiModelProperty
(
value
=
"更新时间"
)
@TableField
(
fill
=
FieldFill
.
INSERT_UPDATE
)
private
Timestamp
updateTime
;
public
void
copyFrom
(
ChatgptRoleSession
source
){
BeanUtil
.
copyProperties
(
source
,
this
,
CopyOptions
.
create
().
setIgnoreNullValue
(
true
));
}
}
src/main/java/admin/modules/chatgpt/domain/ChatgptRoleType.java
0 → 100644
View file @
8b435801
package
admin
.
modules
.
chatgpt
.
domain
;
import
cn.hutool.core.bean.BeanUtil
;
import
cn.hutool.core.bean.copier.CopyOptions
;
import
com.baomidou.mybatisplus.annotation.IdType
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.*
;
import
lombok.experimental.Accessors
;
import
javax.validation.constraints.NotBlank
;
import
javax.validation.constraints.NotNull
;
import
java.io.Serializable
;
import
java.math.BigDecimal
;
/**
* @author wk
* @date 2023-11-27
*/
@Data
@Builder
@Accessors
(
chain
=
true
)
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode
(
callSuper
=
false
)
@TableName
(
"chatgpt_role_type"
)
public
class
ChatgptRoleType
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
@ApiModelProperty
(
value
=
"主键"
)
@TableId
(
type
=
IdType
.
ASSIGN_ID
)
private
String
id
;
@ApiModelProperty
(
value
=
"类别名称"
)
@NotBlank
private
String
roleTypeName
;
@ApiModelProperty
(
value
=
"排序序号"
)
@NotNull
private
BigDecimal
sortNum
;
public
void
copyFrom
(
ChatgptRoleType
source
){
BeanUtil
.
copyProperties
(
source
,
this
,
CopyOptions
.
create
().
setIgnoreNullValue
(
true
));
}
}
src/main/java/admin/modules/chatgpt/domain/RiskControlWords.java
0 → 100644
View file @
8b435801
package
admin
.
modules
.
chatgpt
.
domain
;
import
cn.hutool.core.bean.BeanUtil
;
import
cn.hutool.core.bean.copier.CopyOptions
;
import
com.baomidou.mybatisplus.annotation.IdType
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.*
;
import
lombok.experimental.Accessors
;
import
java.io.Serializable
;
/**
* @author yan
* @date 2024-02-27
*/
@Data
@Builder
@Accessors
(
chain
=
true
)
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode
(
callSuper
=
false
)
@TableName
(
"risk_control_words"
)
public
class
RiskControlWords
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
@ApiModelProperty
(
value
=
"主键"
)
@TableId
(
type
=
IdType
.
AUTO
)
private
Long
id
;
@ApiModelProperty
(
value
=
"风控词"
)
private
String
name
;
public
void
copyFrom
(
RiskControlWords
source
){
BeanUtil
.
copyProperties
(
source
,
this
,
CopyOptions
.
create
().
setIgnoreNullValue
(
true
));
}
}
src/main/java/admin/modules/chatgpt/service/ChatgptRoleDescService.java
0 → 100644
View file @
8b435801
package
admin
.
modules
.
chatgpt
.
service
;
import
admin.base.CommonService
;
import
admin.base.PageInfo
;
import
admin.modules.chatgpt.domain.ChatgptRoleDesc
;
import
admin.modules.chatgpt.service.dto.ChatgptRoleDescDto
;
import
admin.modules.chatgpt.service.dto.ChatgptRoleDescQueryCriteria
;
import
org.springframework.data.domain.Pageable
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
/**
* @author wk
* @date 2023-11-27
*/
public
interface
ChatgptRoleDescService
extends
CommonService
<
ChatgptRoleDesc
>
{
static
final
String
CACHE_KEY
=
"chatgptRoleDesc"
;
/**
* 查询数据分页
* @param query 条件
* @param pageable 分页参数
* @return PageInfo<ChatgptRoleDescDto>
*/
PageInfo
<
ChatgptRoleDescDto
>
queryAll
(
ChatgptRoleDescQueryCriteria
query
,
Pageable
pageable
);
/**
* 查询所有数据不分页
* @param query 条件参数
* @return List<ChatgptRoleDescDto>
*/
List
<
ChatgptRoleDescDto
>
queryAll
(
ChatgptRoleDescQueryCriteria
query
);
ChatgptRoleDesc
getById
(
Integer
id
);
ChatgptRoleDescDto
findById
(
Integer
id
);
/**
* 插入一条新数据。
*/
int
insert
(
ChatgptRoleDescDto
resources
);
int
updateById
(
ChatgptRoleDescDto
resources
);
int
removeById
(
Integer
id
);
int
removeByIds
(
Set
<
Integer
>
ids
);
/**
* 导出数据
* @param all 待导出的数据
* @param response /
* @throws IOException /
*/
// void download(List<ChatgptRoleDescDto> all, HttpServletResponse response) throws IOException;
List
<
Map
<
String
,
Object
>>
queryIndexList
();
List
<
Map
<
String
,
Object
>>
queryAIList
();
}
src/main/java/admin/modules/chatgpt/service/ChatgptRoleRecordsService.java
0 → 100644
View file @
8b435801
package
admin
.
modules
.
chatgpt
.
service
;
import
admin.base.CommonService
;
import
admin.base.PageInfo
;
import
admin.modules.chatgpt.domain.ChatgptRoleRecords
;
import
admin.modules.chatgpt.service.dto.ChatgptRoleRecordsDto
;
import
admin.modules.chatgpt.service.dto.ChatgptRoleRecordsQueryCriteria
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.scheduling.annotation.Async
;
import
java.util.List
;
import
java.util.Set
;
/**
* @author wk
* @date 2023-11-27
*/
public
interface
ChatgptRoleRecordsService
extends
CommonService
<
ChatgptRoleRecords
>
{
static
final
String
CACHE_KEY
=
"chatgptRoleRecords"
;
/**
* 查询数据分页
* @param query 条件
* @param pageable 分页参数
* @return PageInfo<ChatgptRoleRecordsDto>
*/
PageInfo
<
ChatgptRoleRecordsDto
>
queryAll
(
ChatgptRoleRecordsQueryCriteria
query
,
Pageable
pageable
);
/**
* 查询所有数据不分页
* @param query 条件参数
* @return List<ChatgptRoleRecordsDto>
*/
List
<
ChatgptRoleRecordsDto
>
queryAll
(
ChatgptRoleRecordsQueryCriteria
query
);
ChatgptRoleRecords
getById
(
Integer
id
);
ChatgptRoleRecordsDto
findById
(
Integer
id
);
/**
* 插入一条新数据。
*/
@Async
Integer
insert
(
ChatgptRoleRecordsDto
resources
);
Integer
updateById
(
ChatgptRoleRecordsDto
resources
);
Integer
removeById
(
Integer
id
);
Integer
removeByIds
(
Set
<
Integer
>
ids
);
/**
* 导出数据
* @param all 待导出的数据
* @param response /
* @throws IOException /
*/
// void download(List<ChatgptRoleRecordsDto> all, HttpServletResponse response) throws IOException;
PageInfo
<
ChatgptRoleRecordsDto
>
queryRoleSessionListPage
(
Pageable
pageable
,
Long
userId
,
Integer
roleDescId
);
/**
* 累计对话文本字数
* @param memberId
* @return
*/
Integer
findByTextCount
(
Long
memberId
);
/**
* 累计会话次数
* @param memberId
* @return
*/
Integer
findBySessionCount
(
Long
memberId
);
/**
* 累计对话次数
* @param memberId
* @return
*/
Integer
findByDialogueCount
(
Long
memberId
);
/**
* 获取最新的会话id
* @return
*/
String
queryMaxSessionId
();
}
src/main/java/admin/modules/chatgpt/service/ChatgptRoleService.java
0 → 100644
View file @
8b435801
package
admin
.
modules
.
chatgpt
.
service
;
import
admin.base.CommonService
;
import
admin.base.PageInfo
;
import
admin.modules.chatgpt.domain.ChatgptRole
;
import
admin.modules.chatgpt.service.dto.ChatgptRoleDto
;
import
admin.modules.chatgpt.service.dto.ChatgptRoleQueryCriteria
;
import
org.springframework.data.domain.Pageable
;
import
java.util.List
;
import
java.util.Set
;
/**
* @author wk
* @date 2023-11-27
*/
public
interface
ChatgptRoleService
extends
CommonService
<
ChatgptRole
>
{
static
final
String
CACHE_KEY
=
"chatgptRole"
;
/**
* 查询数据分页
* @param query 条件
* @param pageable 分页参数
* @return PageInfo<ChatgptRoleDto>
*/
PageInfo
<
ChatgptRoleDto
>
queryAll
(
ChatgptRoleQueryCriteria
query
,
Pageable
pageable
);
/**
* 查询所有数据不分页
* @param query 条件参数
* @return List<ChatgptRoleDto>
*/
List
<
ChatgptRoleDto
>
queryAll
(
ChatgptRoleQueryCriteria
query
);
ChatgptRole
getById
(
Integer
id
);
ChatgptRoleDto
findById
(
Integer
id
);
/**
* 插入一条新数据。
*/
int
insert
(
ChatgptRoleDto
resources
);
int
updateById
(
ChatgptRoleDto
resources
);
int
removeById
(
Integer
id
);
int
removeByIds
(
Set
<
Integer
>
ids
);
/**
* 导出数据
* @param all 待导出的数据
* @param response /
* @throws IOException /
*/
// void download(List<ChatgptRoleDto> all, HttpServletResponse response) throws IOException;
}
src/main/java/admin/modules/chatgpt/service/ChatgptRoleSessionService.java
0 → 100644
View file @
8b435801
package
admin
.
modules
.
chatgpt
.
service
;
import
admin.base.CommonService
;
import
admin.base.PageInfo
;
import
admin.modules.chatgpt.domain.ChatgptRoleSession
;
import
admin.modules.chatgpt.service.dto.ChatgptRoleSessionDto
;
import
admin.modules.chatgpt.service.dto.ChatgptRoleSessionQueryCriteria
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.scheduling.annotation.Async
;
import
java.util.List
;
import
java.util.Set
;
/**
* @author wk
* @date 2023-11-28
*/
public
interface
ChatgptRoleSessionService
extends
CommonService
<
ChatgptRoleSession
>
{
static
final
String
CACHE_KEY
=
"chatgptRoleSession"
;
/**
* 查询数据分页
* @param query 条件
* @param pageable 分页参数
* @return PageInfo<ChatgptRoleSessionDto>
*/
PageInfo
<
ChatgptRoleSessionDto
>
queryAll
(
ChatgptRoleSessionQueryCriteria
query
,
Pageable
pageable
);
/**
* 查询所有数据不分页
* @param query 条件参数
* @return List<ChatgptRoleSessionDto>
*/
List
<
ChatgptRoleSessionDto
>
queryAll
(
ChatgptRoleSessionQueryCriteria
query
);
ChatgptRoleSession
getById
(
Integer
id
);
ChatgptRoleSessionDto
findById
(
Integer
id
);
/**
* 插入一条新数据。
*/
ChatgptRoleSession
insert
(
ChatgptRoleSessionDto
resources
);
int
updateById
(
ChatgptRoleSessionDto
resources
);
int
removeById
(
Integer
id
);
int
removeByIds
(
Set
<
Integer
>
ids
);
@Async
Integer
updateUpdateTime
(
Integer
id
);
/**
* 导出数据
* @param all 待导出的数据
* @param response /
* @throws IOException /
*/
// void download(List<ChatgptRoleSessionDto> all, HttpServletResponse response) throws IOException;
}
src/main/java/admin/modules/chatgpt/service/ChatgptRoleTypeService.java
0 → 100644
View file @
8b435801
package
admin
.
modules
.
chatgpt
.
service
;
import
admin.base.CommonService
;
import
admin.base.PageInfo
;
import
admin.modules.chatgpt.domain.ChatgptRoleType
;
import
admin.modules.chatgpt.service.dto.ChatgptRoleTypeDto
;
import
admin.modules.chatgpt.service.dto.ChatgptRoleTypeQueryCriteria
;
import
org.springframework.data.domain.Pageable
;
import
java.util.List
;
import
java.util.Set
;
/**
* @author wk
* @date 2023-11-27
*/
public
interface
ChatgptRoleTypeService
extends
CommonService
<
ChatgptRoleType
>
{
static
final
String
CACHE_KEY
=
"chatgptRoleType"
;
/**
* 查询数据分页
* @param query 条件
* @param pageable 分页参数
* @return PageInfo<ChatgptRoleTypeDto>
*/
PageInfo
<
ChatgptRoleTypeDto
>
queryAll
(
ChatgptRoleTypeQueryCriteria
query
,
Pageable
pageable
);
/**
* 查询所有数据不分页
* @param query 条件参数
* @return List<ChatgptRoleTypeDto>
*/
List
<
ChatgptRoleTypeDto
>
queryAll
(
ChatgptRoleTypeQueryCriteria
query
);
ChatgptRoleType
getById
(
String
id
);
ChatgptRoleTypeDto
findById
(
String
id
);
/**
* 插入一条新数据。
*/
int
insert
(
ChatgptRoleTypeDto
resources
);
int
updateById
(
ChatgptRoleTypeDto
resources
);
int
removeById
(
String
id
);
int
removeByIds
(
Set
<
String
>
ids
);
/**
* 导出数据
* @param all 待导出的数据
* @param response /
* @throws IOException /
*/
// void download(List<ChatgptRoleTypeDto> all, HttpServletResponse response) throws IOException;
}
src/main/java/admin/modules/chatgpt/service/RiskControlWordsService.java
0 → 100644
View file @
8b435801
package
admin
.
modules
.
chatgpt
.
service
;
import
admin.base.CommonService
;
import
admin.base.PageInfo
;
import
admin.modules.chatgpt.domain.RiskControlWords
;
import
admin.modules.chatgpt.service.dto.RiskControlWordsDto
;
import
admin.modules.chatgpt.service.dto.RiskControlWordsQueryCriteria
;
import
org.springframework.data.domain.Pageable
;
import
java.util.List
;
import
java.util.Set
;
/**
* @author yan
* @date 2024-02-27
*/
public
interface
RiskControlWordsService
extends
CommonService
<
RiskControlWords
>
{
static
final
String
CACHE_KEY
=
"riskControlWords"
;
/**
* 查询数据分页
* @param query 条件
* @param pageable 分页参数
* @return PageInfo<RiskControlWordsDto>
*/
PageInfo
<
RiskControlWordsDto
>
queryAll
(
RiskControlWordsQueryCriteria
query
,
Pageable
pageable
);
/**
* 查询所有数据不分页
* @param query 条件参数
* @return List<RiskControlWordsDto>
*/
List
<
RiskControlWordsDto
>
queryAll
(
RiskControlWordsQueryCriteria
query
);
RiskControlWords
getById
(
Long
id
);
RiskControlWordsDto
findById
(
Long
id
);
/**
* 插入一条新数据。
*/
int
insert
(
RiskControlWordsDto
resources
);
int
updateById
(
RiskControlWordsDto
resources
);
int
removeById
(
Long
id
);
int
removeByIds
(
Set
<
Long
>
ids
);
/**
*
*/
void
addAll
(
String
words
);
/**
* 导出数据
* @param all 待导出的数据
* @param response /
* @throws IOException /
*/
// void download(List<RiskControlWordsDto> all, HttpServletResponse response) throws IOException;
}
src/main/java/admin/modules/chatgpt/service/dto/ChatgptRoleDescDto.java
0 → 100644
View file @
8b435801
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
admin
.
modules
.
chatgpt
.
service
.
dto
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.math.BigDecimal
;
import
java.util.Date
;
/**
* @website https://el-admin.vip
* @description /
* @author wk
* @date 2023-11-27
**/
@Data
public
class
ChatgptRoleDescDto
implements
Serializable
{
@ApiModelProperty
(
value
=
"主键"
)
private
Integer
id
;
@ApiModelProperty
(
value
=
"标题"
)
private
String
title
;
@ApiModelProperty
(
value
=
"内容"
)
private
String
description
;
@ApiModelProperty
(
value
=
"进入聊天提示内容"
)
private
String
chat
;
@ApiModelProperty
(
value
=
"图片"
)
private
String
image
;
@ApiModelProperty
(
value
=
"角色id"
)
private
Integer
roleId
;
@ApiModelProperty
(
value
=
"排序序号"
)
private
BigDecimal
sortNum
;
@ApiModelProperty
(
value
=
"上线状态"
)
private
Integer
postStatus
;
@ApiModelProperty
(
value
=
"角色类型"
)
private
String
roleTypeId
;
@ApiModelProperty
(
value
=
"类别[1=角色对话,2=AI创作,3=首页]"
)
private
Integer
classify
;
@ApiModelProperty
(
value
=
"创建时间"
)
private
Date
createDate
;
@ApiModelProperty
(
value
=
"更新时间"
)
private
Date
updateDate
;
@ApiModelProperty
(
value
=
"角色名称"
)
private
String
roleName
;
@ApiModelProperty
(
value
=
"角色prompt"
)
private
String
roleMessage
;
@ApiModelProperty
(
value
=
"模型"
)
private
String
model
;
@ApiModelProperty
(
value
=
"内容创意 该值越大,输出内容更加随机,推荐值:1"
)
private
Double
temperature
;
@ApiModelProperty
(
value
=
"最大token"
)
private
Integer
maxTokens
;
@ApiModelProperty
(
value
=
"质量概率 核心采样,指选用前多少概率质量的内容,推荐值:1"
)
private
Double
topP
;
@ApiModelProperty
(
value
=
"重复词汇 输出文本同一个词汇出现情况,默认为0,值越大,重复性越小,推荐值:0"
)
private
Double
presencePenalty
;
@ApiModelProperty
(
value
=
"罕见词汇 输出文本罕见词汇出现情况,默认为0,值越大,罕见词汇越多,推荐值:0"
)
private
Double
frequencyPenalty
;
@ApiModelProperty
(
value
=
"回答数量 为每个问题回答的内容数量,当多个时,会消耗大量Token,推荐值:1"
)
private
Integer
n
;
@ApiModelProperty
(
value
=
"类别名称"
)
private
String
roleTypeName
;
}
src/main/java/admin/modules/chatgpt/service/dto/ChatgptRoleDescQueryCriteria.java
0 → 100644
View file @
8b435801
package
admin
.
modules
.
chatgpt
.
service
.
dto
;
import
admin.annotation.Query
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
/**
* @author wk
* @date 2023-11-27
*/
@Data
public
class
ChatgptRoleDescQueryCriteria
{
/** 精确 */
@ApiModelProperty
(
value
=
"类别[1=角色对话,2=AI创作,3=首页]"
)
@Query
private
Integer
classify
;
/** 精确 */
@Query
private
Integer
postStatus
;
@Query
(
type
=
Query
.
Type
.
INNER_LIKE
)
private
String
title
;
@Query
(
type
=
Query
.
Type
.
INNER_LIKE
)
private
String
description
;
@Query
private
Integer
roleId
;
@Query
private
Integer
roleTypeId
;
}
src/main/java/admin/modules/chatgpt/service/dto/ChatgptRoleDto.java
0 → 100644
View file @
8b435801
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
admin
.
modules
.
chatgpt
.
service
.
dto
;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.sql.Timestamp
;
/**
* @website https://el-admin.vip
* @description /
* @author wk
* @date 2023-11-27
**/
@Data
public
class
ChatgptRoleDto
implements
Serializable
{
/** 唯一标识,自动递增 */
private
Integer
id
;
/** 角色名称 */
private
String
roleName
;
/** 角色prompt */
private
String
roleMessage
;
/** 模型 */
private
String
model
;
/** 创建时间 */
private
Timestamp
createTime
;
/** 内容创意 该值越大,输出内容更加随机,推荐值:1 */
private
Double
temperature
;
/** 最大token */
private
Integer
maxTokens
;
/** 质量概率 核心采样,指选用前多少概率质量的内容,推荐值:1 */
private
Double
topP
;
/** 重复词汇 输出文本同一个词汇出现情况,默认为0,值越大,重复性越小,推荐值:0 */
private
Double
presencePenalty
;
/** 罕见词汇 输出文本罕见词汇出现情况,默认为0,值越大,罕见词汇越多,推荐值:0 */
private
Double
frequencyPenalty
;
/** 回答数量 为每个问题回答的内容数量,当多个时,会消耗大量Token,推荐值:1 */
private
Integer
n
;
}
src/main/java/admin/modules/chatgpt/service/dto/ChatgptRoleQueryCriteria.java
0 → 100644
View file @
8b435801
package
admin
.
modules
.
chatgpt
.
service
.
dto
;
import
admin.annotation.Query
;
import
lombok.Data
;
/**
* @author wk
* @date 2023-11-27
*/
@Data
public
class
ChatgptRoleQueryCriteria
{
@Query
(
type
=
Query
.
Type
.
INNER_LIKE
)
private
String
roleName
;
@Query
(
type
=
Query
.
Type
.
INNER_LIKE
)
private
String
roleMessage
;
@Query
private
String
model
;
}
src/main/java/admin/modules/chatgpt/service/dto/ChatgptRoleRecordsDto.java
0 → 100644
View file @
8b435801
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
admin
.
modules
.
chatgpt
.
service
.
dto
;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.sql.Timestamp
;
/**
* @website https://el-admin.vip
* @description /
* @author wk
* @date 2023-11-27
**/
@Data
public
class
ChatgptRoleRecordsDto
implements
Serializable
{
/** 唯一标识,自动递增 */
private
Integer
id
;
/** 发送者id */
private
Integer
senderId
;
/** 接收者id */
private
Integer
receiverId
;
/** 聊天消息的内容 */
private
String
message
;
/** 创建时间 */
private
Timestamp
createTime
;
}
src/main/java/admin/modules/chatgpt/service/dto/ChatgptRoleRecordsQueryCriteria.java
0 → 100644
View file @
8b435801
package
admin
.
modules
.
chatgpt
.
service
.
dto
;
import
admin.annotation.Query
;
import
lombok.Data
;
/**
* @author wk
* @date 2023-11-27
*/
@Data
public
class
ChatgptRoleRecordsQueryCriteria
{
/** 精确 */
@Query
private
Integer
sessionId
;
/** 精确 */
@Query
private
Integer
roleDescId
;
}
src/main/java/admin/modules/chatgpt/service/dto/ChatgptRoleSessionDto.java
0 → 100644
View file @
8b435801
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
admin
.
modules
.
chatgpt
.
service
.
dto
;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.sql.Timestamp
;
/**
* @website https://el-admin.vip
* @description /
* @author wk
* @date 2023-11-28
**/
@Data
public
class
ChatgptRoleSessionDto
implements
Serializable
{
/** 唯一标识,自动递增 */
private
Integer
id
;
/** 名称 */
private
String
name
;
/** 角色描述id */
private
Integer
roleDescId
;
/** 用户id */
private
Integer
userId
;
/** 创建时间 */
private
Timestamp
createTime
;
/** 更新时间 */
private
Timestamp
updateTime
;
}
src/main/java/admin/modules/chatgpt/service/dto/ChatgptRoleSessionQueryCriteria.java
0 → 100644
View file @
8b435801
package
admin
.
modules
.
chatgpt
.
service
.
dto
;
import
admin.annotation.Query
;
import
lombok.Data
;
/**
* @author wk
* @date 2023-11-28
*/
@Data
public
class
ChatgptRoleSessionQueryCriteria
{
/** 精确 */
@Query
private
Integer
userId
;
private
String
name
;
}
src/main/java/admin/modules/chatgpt/service/dto/ChatgptRoleTypeDto.java
0 → 100644
View file @
8b435801
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
admin
.
modules
.
chatgpt
.
service
.
dto
;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.math.BigDecimal
;
/**
* @website https://el-admin.vip
* @description /
* @author wk
* @date 2023-11-27
**/
@Data
public
class
ChatgptRoleTypeDto
implements
Serializable
{
/** 主键 */
private
String
id
;
/** 类别名称 */
private
String
roleTypeName
;
/** 排序序号 */
private
BigDecimal
sortNum
;
}
src/main/java/admin/modules/chatgpt/service/dto/ChatgptRoleTypeQueryCriteria.java
0 → 100644
View file @
8b435801
package
admin
.
modules
.
chatgpt
.
service
.
dto
;
import
lombok.Data
;
/**
* @author wk
* @date 2023-11-27
*/
@Data
public
class
ChatgptRoleTypeQueryCriteria
{
}
src/main/java/admin/modules/chatgpt/service/dto/RiskControlWordsDto.java
0 → 100644
View file @
8b435801
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
admin
.
modules
.
chatgpt
.
service
.
dto
;
import
lombok.Data
;
import
java.io.Serializable
;
/**
* @website https://el-admin.vip
* @description /
* @author yan
* @date 2024-02-27
**/
@Data
public
class
RiskControlWordsDto
implements
Serializable
{
/** 主键 */
private
Long
id
;
/** 风控词 */
private
String
name
;
}
src/main/java/admin/modules/chatgpt/service/dto/RiskControlWordsQueryCriteria.java
0 → 100644
View file @
8b435801
package
admin
.
modules
.
chatgpt
.
service
.
dto
;
import
admin.annotation.Query
;
import
lombok.Data
;
/**
* @author yan
* @date 2024-02-27
*/
@Data
public
class
RiskControlWordsQueryCriteria
{
/** 模糊 */
@Query
(
type
=
Query
.
Type
.
INNER_LIKE
)
private
String
name
;
}
src/main/java/admin/modules/chatgpt/service/impl/ChatgptRoleDescServiceImpl.java
0 → 100644
View file @
8b435801
package
admin
.
modules
.
chatgpt
.
service
.
impl
;
import
admin.base.PageInfo
;
import
admin.base.QueryHelpMybatisPlus
;
import
admin.base.impl.CommonServiceImpl
;
import
admin.modules.chatgpt.domain.ChatgptRole
;
import
admin.modules.chatgpt.domain.ChatgptRoleDesc
;
import
admin.modules.chatgpt.domain.ChatgptRoleType
;
import
admin.modules.chatgpt.service.ChatgptRoleDescService
;
import
admin.modules.chatgpt.service.dto.ChatgptRoleDescDto
;
import
admin.modules.chatgpt.service.dto.ChatgptRoleDescQueryCriteria
;
import
admin.modules.chatgpt.service.mapper.ChatgptRoleDescMapper
;
import
admin.modules.chatgpt.service.mapper.ChatgptRoleMapper
;
import
admin.util.ConvertUtil
;
import
admin.util.PageUtil
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.github.yulichang.wrapper.MPJLambdaWrapper
;
import
lombok.AllArgsConstructor
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.*
;
import
java.util.stream.Collectors
;
/**
* @author wk
* @date 2023-11-27
*/
@Service
@AllArgsConstructor
// @CacheConfig(cacheNames = ChatgptRoleDescService.CACHE_KEY)
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
public
class
ChatgptRoleDescServiceImpl
extends
CommonServiceImpl
<
ChatgptRoleDescMapper
,
ChatgptRoleDesc
>
implements
ChatgptRoleDescService
{
// private final RedisUtils redisUtils;
private
final
ChatgptRoleDescMapper
chatgptRoleDescMapper
;
private
final
ChatgptRoleMapper
chatgptRoleMapper
;
@Override
public
PageInfo
<
ChatgptRoleDescDto
>
queryAll
(
ChatgptRoleDescQueryCriteria
query
,
Pageable
pageable
)
{
IPage
<
ChatgptRoleDescDto
>
queryPage
=
PageUtil
.
toMybatisPage
(
pageable
);
MPJLambdaWrapper
<
ChatgptRoleDesc
>
mpjLambdaWrapper
=
QueryHelpMybatisPlus
.
getPredicateMPJ
(
query
);
mpjLambdaWrapper
//查询表1的全部字段
.
selectAll
(
ChatgptRoleDesc
.
class
)
//查询表2的全部字段
.
selectAll
(
ChatgptRole
.
class
)
//左查询表2条件为表二的productId=表一的id
.
innerJoin
(
ChatgptRole
.
class
,
ChatgptRole:
:
getId
,
ChatgptRoleDesc:
:
getRoleId
);
IPage
<
ChatgptRoleDescDto
>
page
=
chatgptRoleDescMapper
.
selectJoinPage
(
queryPage
,
ChatgptRoleDescDto
.
class
,
mpjLambdaWrapper
);
return
ConvertUtil
.
convertPage
(
page
,
ChatgptRoleDescDto
.
class
);
}
@Override
public
List
<
ChatgptRoleDescDto
>
queryAll
(
ChatgptRoleDescQueryCriteria
query
){
return
ConvertUtil
.
convertList
(
chatgptRoleDescMapper
.
selectList
(
QueryHelpMybatisPlus
.
getPredicate
(
query
)),
ChatgptRoleDescDto
.
class
);
}
@Override
public
ChatgptRoleDesc
getById
(
Integer
id
)
{
return
chatgptRoleDescMapper
.
selectById
(
id
);
}
@Override
// @Cacheable(key = "'id:' + #p0")
public
ChatgptRoleDescDto
findById
(
Integer
id
)
{
return
ConvertUtil
.
convert
(
getById
(
id
),
ChatgptRoleDescDto
.
class
);
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
int
insert
(
ChatgptRoleDescDto
resources
)
{
ChatgptRoleDesc
entity
=
ConvertUtil
.
convert
(
resources
,
ChatgptRoleDesc
.
class
);
return
chatgptRoleDescMapper
.
insert
(
entity
);
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
int
updateById
(
ChatgptRoleDescDto
resources
){
ChatgptRoleDesc
entity
=
ConvertUtil
.
convert
(
resources
,
ChatgptRoleDesc
.
class
);
int
ret
=
chatgptRoleDescMapper
.
updateById
(
entity
);
ChatgptRole
chatgptRole
=
ConvertUtil
.
convert
(
resources
,
ChatgptRole
.
class
);
chatgptRole
.
setId
(
resources
.
getRoleId
());
chatgptRoleMapper
.
updateById
(
chatgptRole
);
// delCaches(resources.id);
return
ret
;
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
int
removeByIds
(
Set
<
Integer
>
ids
){
// delCaches(ids);
return
chatgptRoleDescMapper
.
deleteBatchIds
(
ids
);
}
@Override
public
List
<
Map
<
String
,
Object
>>
queryIndexList
()
{
ChatgptRoleDescQueryCriteria
query
=
new
ChatgptRoleDescQueryCriteria
();
query
.
setClassify
(
3
);
query
.
setPostStatus
(
0
);
MPJLambdaWrapper
<
ChatgptRoleDesc
>
mpjLambdaWrapper
=
QueryHelpMybatisPlus
.
getPredicateMPJ
(
query
);
mpjLambdaWrapper
//查询表1的全部字段
.
selectAll
(
ChatgptRoleDesc
.
class
)
//查询表2的全部字段
.
selectAll
(
ChatgptRole
.
class
)
//查询类别表类别字段
.
select
(
ChatgptRoleType:
:
getRoleTypeName
)
//左查询表2条件为表二的productId=表一的id
.
innerJoin
(
ChatgptRole
.
class
,
ChatgptRole:
:
getId
,
ChatgptRoleDesc:
:
getRoleId
)
.
innerJoin
(
ChatgptRoleType
.
class
,
ChatgptRoleType:
:
getId
,
ChatgptRoleDesc:
:
getRoleTypeId
)
.
orderByAsc
(
ChatgptRoleType:
:
getSortNum
);
List
<
ChatgptRoleDescDto
>
chatgptRoleDescDtos
=
chatgptRoleDescMapper
.
selectJoinList
(
ChatgptRoleDescDto
.
class
,
mpjLambdaWrapper
);
Map
<
String
,
List
<
ChatgptRoleDescDto
>>
collect
=
chatgptRoleDescDtos
.
stream
().
collect
(
Collectors
.
groupingBy
(
ChatgptRoleDescDto:
:
getRoleTypeName
));
List
<
Map
<
String
,
Object
>>
result
=
new
ArrayList
<>();
collect
.
forEach
((
k
,
v
)->{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"roleTypeName"
,
k
);
map
.
put
(
"list"
,
v
);
result
.
add
(
map
);
});
Collections
.
shuffle
(
result
);
return
result
;
}
@Override
public
List
<
Map
<
String
,
Object
>>
queryAIList
()
{
ChatgptRoleDescQueryCriteria
query
=
new
ChatgptRoleDescQueryCriteria
();
query
.
setPostStatus
(
0
);
query
.
setClassify
(
2
);
MPJLambdaWrapper
<
ChatgptRoleDesc
>
mpjLambdaWrapper
=
QueryHelpMybatisPlus
.
getPredicateMPJ
(
query
);
mpjLambdaWrapper
//查询表1的全部字段
.
selectAll
(
ChatgptRoleDesc
.
class
)
//查询表2的全部字段
.
selectAll
(
ChatgptRole
.
class
)
.
selectAll
(
ChatgptRoleType
.
class
)
//左查询表2条件为表二的productId=表一的id
.
innerJoin
(
ChatgptRole
.
class
,
ChatgptRole:
:
getId
,
ChatgptRoleDesc:
:
getRoleId
)
.
innerJoin
(
ChatgptRoleType
.
class
,
ChatgptRoleType:
:
getId
,
ChatgptRoleDesc:
:
getRoleTypeId
);
List
<
ChatgptRoleDescDto
>
list
=
chatgptRoleDescMapper
.
selectJoinList
(
ChatgptRoleDescDto
.
class
,
mpjLambdaWrapper
);
Map
<
String
,
List
<
ChatgptRoleDescDto
>>
collect
=
list
.
stream
().
collect
(
Collectors
.
groupingBy
(
ChatgptRoleDescDto:
:
getRoleTypeName
));
List
<
Map
<
String
,
Object
>>
result
=
new
ArrayList
<>();
Map
<
String
,
Object
>
all
=
new
HashMap
<>();
all
.
put
(
"name"
,
"全部"
);
all
.
put
(
"value"
,
list
);
result
.
add
(
all
);
for
(
Map
.
Entry
<
String
,
List
<
ChatgptRoleDescDto
>>
map
:
collect
.
entrySet
()){
String
key
=
map
.
getKey
();
List
<
ChatgptRoleDescDto
>
value
=
map
.
getValue
();
Map
<
String
,
Object
>
tempMap
=
new
HashMap
<>();
tempMap
.
put
(
"name"
,
key
);
tempMap
.
put
(
"value"
,
value
);
result
.
add
(
tempMap
);
}
return
result
;
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
int
removeById
(
Integer
id
){
Set
<
Integer
>
set
=
new
HashSet
<>(
1
);
set
.
add
(
id
);
return
this
.
removeByIds
(
set
);
}
/*
private void delCaches(Integer id) {
redisUtils.delByKey(CACHE_KEY + "::id:", id);
}
private void delCaches(Set<Integer> ids) {
for (Integer id: ids) {
delCaches(id);
}
}*/
/*
@Override
public void download(List<ChatgptRoleDescDto> all, HttpServletResponse response) throws IOException {
List<Map<String, Object>> list = new ArrayList<>();
for (ChatgptRoleDescDto chatgptRoleDesc : all) {
Map<String,Object> map = new LinkedHashMap<>();
map.put("标题", chatgptRoleDesc.getTitle());
map.put("内容", chatgptRoleDesc.getDescription());
map.put("进入聊天提示内容", chatgptRoleDesc.getChat());
map.put("图片", chatgptRoleDesc.getImage());
map.put("角色id", chatgptRoleDesc.getRoleId());
map.put("排序序号", chatgptRoleDesc.getSortNum());
map.put("上线状态", chatgptRoleDesc.getPostStatus());
map.put("创建时间", chatgptRoleDesc.getCreateDate());
map.put("更新时间", chatgptRoleDesc.getUpdateDate());
map.put("角色类型", chatgptRoleDesc.getRoleTypeId());
list.add(map);
}
FileUtil.downloadExcel(list, response);
}*/
}
src/main/java/admin/modules/chatgpt/service/impl/ChatgptRoleRecordsServiceImpl.java
0 → 100644
View file @
8b435801
package
admin
.
modules
.
chatgpt
.
service
.
impl
;
import
admin.base.PageInfo
;
import
admin.base.QueryHelpMybatisPlus
;
import
admin.base.impl.CommonServiceImpl
;
import
admin.modules.chatgpt.domain.ChatgptRoleRecords
;
import
admin.modules.chatgpt.service.ChatgptRoleRecordsService
;
import
admin.modules.chatgpt.service.dto.ChatgptRoleRecordsDto
;
import
admin.modules.chatgpt.service.dto.ChatgptRoleRecordsQueryCriteria
;
import
admin.modules.chatgpt.service.mapper.ChatgptRoleRecordsMapper
;
import
admin.util.ConvertUtil
;
import
admin.util.PageUtil
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
lombok.AllArgsConstructor
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.Comparator
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Set
;
/**
* @author wk
* @date 2023-11-27
*/
@Service
@AllArgsConstructor
// @CacheConfig(cacheNames = ChatgptRoleRecordsService.CACHE_KEY)
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
public
class
ChatgptRoleRecordsServiceImpl
extends
CommonServiceImpl
<
ChatgptRoleRecordsMapper
,
ChatgptRoleRecords
>
implements
ChatgptRoleRecordsService
{
// private final RedisUtils redisUtils;
private
final
ChatgptRoleRecordsMapper
chatgptRoleRecordsMapper
;
@Override
public
PageInfo
<
ChatgptRoleRecordsDto
>
queryAll
(
ChatgptRoleRecordsQueryCriteria
query
,
Pageable
pageable
)
{
IPage
<
ChatgptRoleRecords
>
queryPage
=
PageUtil
.
toMybatisPage
(
pageable
);
IPage
<
ChatgptRoleRecords
>
page
=
chatgptRoleRecordsMapper
.
selectPage
(
queryPage
,
QueryHelpMybatisPlus
.
getPredicate
(
query
));
return
ConvertUtil
.
convertPage
(
page
,
ChatgptRoleRecordsDto
.
class
);
}
@Override
public
List
<
ChatgptRoleRecordsDto
>
queryAll
(
ChatgptRoleRecordsQueryCriteria
query
){
return
ConvertUtil
.
convertList
(
chatgptRoleRecordsMapper
.
selectList
(
QueryHelpMybatisPlus
.
getPredicate
(
query
)),
ChatgptRoleRecordsDto
.
class
);
}
@Override
public
ChatgptRoleRecords
getById
(
Integer
id
)
{
return
chatgptRoleRecordsMapper
.
selectById
(
id
);
}
@Override
// @Cacheable(key = "'id:' + #p0")
public
ChatgptRoleRecordsDto
findById
(
Integer
id
)
{
return
ConvertUtil
.
convert
(
getById
(
id
),
ChatgptRoleRecordsDto
.
class
);
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
Integer
insert
(
ChatgptRoleRecordsDto
resources
)
{
ChatgptRoleRecords
entity
=
ConvertUtil
.
convert
(
resources
,
ChatgptRoleRecords
.
class
);
return
chatgptRoleRecordsMapper
.
insert
(
entity
);
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
Integer
updateById
(
ChatgptRoleRecordsDto
resources
){
ChatgptRoleRecords
entity
=
ConvertUtil
.
convert
(
resources
,
ChatgptRoleRecords
.
class
);
int
ret
=
chatgptRoleRecordsMapper
.
updateById
(
entity
);
// delCaches(resources.id);
return
ret
;
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
Integer
removeByIds
(
Set
<
Integer
>
ids
){
// delCaches(ids);
return
chatgptRoleRecordsMapper
.
deleteBatchIds
(
ids
);
}
@Override
public
PageInfo
<
ChatgptRoleRecordsDto
>
queryRoleSessionListPage
(
Pageable
pageable
,
Long
userId
,
Integer
roleDescId
)
{
IPage
<
ChatgptRoleRecords
>
page
=
PageUtil
.
toMybatisPage
(
pageable
);
List
<
ChatgptRoleRecords
>
chatgptRoleRecords
=
chatgptRoleRecordsMapper
.
queryRoleSessionListPage
(
page
,
userId
,
roleDescId
);
page
.
setRecords
(
chatgptRoleRecords
);
return
ConvertUtil
.
convertPage
(
page
,
ChatgptRoleRecordsDto
.
class
);
}
@Override
public
Integer
findByTextCount
(
Long
memberId
)
{
return
this
.
baseMapper
.
findByTextCount
(
memberId
);
}
@Override
public
Integer
findBySessionCount
(
Long
memberId
)
{
return
this
.
baseMapper
.
findBySessionCount
(
memberId
);
}
@Override
public
Integer
findByDialogueCount
(
Long
memberId
)
{
return
this
.
baseMapper
.
findByDialogueCount
(
memberId
);
}
@Override
public
String
queryMaxSessionId
()
{
List
<
ChatgptRoleRecords
>
list
=
this
.
baseMapper
.
lambdaQuery
().
isNotNull
(
ChatgptRoleRecords:
:
getSessionId
).
select
(
ChatgptRoleRecords:
:
getSessionId
).
list
();
Integer
i
=
list
.
stream
().
map
(
ChatgptRoleRecords:
:
getSessionId
).
max
(
Integer:
:
compareTo
).
get
();
return
String
.
valueOf
(
i
+
1
);
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
Integer
removeById
(
Integer
id
){
Set
<
Integer
>
set
=
new
HashSet
<>(
1
);
set
.
add
(
id
);
return
this
.
removeByIds
(
set
);
}
/*
private void delCaches(Integer id) {
redisUtils.delByKey(CACHE_KEY + "::id:", id);
}
private void delCaches(Set<Integer> ids) {
for (Integer id: ids) {
delCaches(id);
}
}*/
/*
@Override
public void download(List<ChatgptRoleRecordsDto> all, HttpServletResponse response) throws IOException {
List<Map<String, Object>> list = new ArrayList<>();
for (ChatgptRoleRecordsDto chatgptRoleRecords : all) {
Map<String,Object> map = new LinkedHashMap<>();
map.put("发送者id", chatgptRoleRecords.getSenderId());
map.put("接收者id", chatgptRoleRecords.getReceiverId());
map.put("聊天消息的内容", chatgptRoleRecords.getMessage());
map.put("创建时间", chatgptRoleRecords.getCreateTime());
list.add(map);
}
FileUtil.downloadExcel(list, response);
}*/
}
src/main/java/admin/modules/chatgpt/service/impl/ChatgptRoleServiceImpl.java
0 → 100644
View file @
8b435801
package
admin
.
modules
.
chatgpt
.
service
.
impl
;
import
admin.base.PageInfo
;
import
admin.base.QueryHelpMybatisPlus
;
import
admin.base.impl.CommonServiceImpl
;
import
admin.modules.chatgpt.domain.ChatgptRole
;
import
admin.modules.chatgpt.service.ChatgptRoleService
;
import
admin.modules.chatgpt.service.dto.ChatgptRoleDto
;
import
admin.modules.chatgpt.service.dto.ChatgptRoleQueryCriteria
;
import
admin.modules.chatgpt.service.mapper.ChatgptRoleMapper
;
import
admin.util.ConvertUtil
;
import
admin.util.PageUtil
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
lombok.AllArgsConstructor
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Set
;
/**
* @author wk
* @date 2023-11-27
*/
@Service
@AllArgsConstructor
// @CacheConfig(cacheNames = ChatgptRoleService.CACHE_KEY)
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
public
class
ChatgptRoleServiceImpl
extends
CommonServiceImpl
<
ChatgptRoleMapper
,
ChatgptRole
>
implements
ChatgptRoleService
{
// private final RedisUtils redisUtils;
private
final
ChatgptRoleMapper
chatgptRoleMapper
;
@Override
public
PageInfo
<
ChatgptRoleDto
>
queryAll
(
ChatgptRoleQueryCriteria
query
,
Pageable
pageable
)
{
IPage
<
ChatgptRole
>
queryPage
=
PageUtil
.
toMybatisPage
(
pageable
);
IPage
<
ChatgptRole
>
page
=
chatgptRoleMapper
.
selectPage
(
queryPage
,
QueryHelpMybatisPlus
.
getPredicate
(
query
));
return
ConvertUtil
.
convertPage
(
page
,
ChatgptRoleDto
.
class
);
}
@Override
public
List
<
ChatgptRoleDto
>
queryAll
(
ChatgptRoleQueryCriteria
query
){
return
ConvertUtil
.
convertList
(
chatgptRoleMapper
.
selectList
(
QueryHelpMybatisPlus
.
getPredicate
(
query
)),
ChatgptRoleDto
.
class
);
}
@Override
public
ChatgptRole
getById
(
Integer
id
)
{
return
chatgptRoleMapper
.
selectById
(
id
);
}
@Override
// @Cacheable(key = "'id:' + #p0")
public
ChatgptRoleDto
findById
(
Integer
id
)
{
return
ConvertUtil
.
convert
(
getById
(
id
),
ChatgptRoleDto
.
class
);
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
int
insert
(
ChatgptRoleDto
resources
)
{
ChatgptRole
entity
=
ConvertUtil
.
convert
(
resources
,
ChatgptRole
.
class
);
return
chatgptRoleMapper
.
insert
(
entity
);
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
int
updateById
(
ChatgptRoleDto
resources
){
ChatgptRole
entity
=
ConvertUtil
.
convert
(
resources
,
ChatgptRole
.
class
);
int
ret
=
chatgptRoleMapper
.
updateById
(
entity
);
// delCaches(resources.id);
return
ret
;
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
int
removeByIds
(
Set
<
Integer
>
ids
){
// delCaches(ids);
return
chatgptRoleMapper
.
deleteBatchIds
(
ids
);
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
int
removeById
(
Integer
id
){
Set
<
Integer
>
set
=
new
HashSet
<>(
1
);
set
.
add
(
id
);
return
this
.
removeByIds
(
set
);
}
/*
private void delCaches(Integer id) {
redisUtils.delByKey(CACHE_KEY + "::id:", id);
}
private void delCaches(Set<Integer> ids) {
for (Integer id: ids) {
delCaches(id);
}
}*/
/*
@Override
public void download(List<ChatgptRoleDto> all, HttpServletResponse response) throws IOException {
List<Map<String, Object>> list = new ArrayList<>();
for (ChatgptRoleDto chatgptRole : all) {
Map<String,Object> map = new LinkedHashMap<>();
map.put("角色名称", chatgptRole.getRoleName());
map.put("角色prompt", chatgptRole.getRoleMessage());
map.put("模型", chatgptRole.getModel());
map.put("创建时间", chatgptRole.getCreateTime());
map.put("内容创意 该值越大,输出内容更加随机,推荐值:1", chatgptRole.getTemperature());
map.put("最大token", chatgptRole.getMaxTokens());
map.put("质量概率 核心采样,指选用前多少概率质量的内容,推荐值:1", chatgptRole.getTopP());
map.put("重复词汇 输出文本同一个词汇出现情况,默认为0,值越大,重复性越小,推荐值:0", chatgptRole.getPresencePenalty());
map.put("罕见词汇 输出文本罕见词汇出现情况,默认为0,值越大,罕见词汇越多,推荐值:0", chatgptRole.getFrequencyPenalty());
map.put("回答数量 为每个问题回答的内容数量,当多个时,会消耗大量Token,推荐值:1", chatgptRole.getN());
list.add(map);
}
FileUtil.downloadExcel(list, response);
}*/
}
src/main/java/admin/modules/chatgpt/service/impl/ChatgptRoleSessionServiceImpl.java
0 → 100644
View file @
8b435801
package
admin
.
modules
.
chatgpt
.
service
.
impl
;
import
admin.base.PageInfo
;
import
admin.base.QueryHelpMybatisPlus
;
import
admin.base.impl.CommonServiceImpl
;
import
admin.modules.chatgpt.domain.ChatgptRoleSession
;
import
admin.modules.chatgpt.service.ChatgptRoleSessionService
;
import
admin.modules.chatgpt.service.dto.ChatgptRoleSessionDto
;
import
admin.modules.chatgpt.service.dto.ChatgptRoleSessionQueryCriteria
;
import
admin.modules.chatgpt.service.mapper.ChatgptRoleSessionMapper
;
import
admin.util.ConvertUtil
;
import
admin.util.PageUtil
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
lombok.AllArgsConstructor
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Set
;
/**
* @author wk
* @date 2023-11-28
*/
@Service
@AllArgsConstructor
// @CacheConfig(cacheNames = ChatgptRoleSessionService.CACHE_KEY)
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
public
class
ChatgptRoleSessionServiceImpl
extends
CommonServiceImpl
<
ChatgptRoleSessionMapper
,
ChatgptRoleSession
>
implements
ChatgptRoleSessionService
{
// private final RedisUtils redisUtils;
private
final
ChatgptRoleSessionMapper
chatgptRoleSessionMapper
;
@Override
public
PageInfo
<
ChatgptRoleSessionDto
>
queryAll
(
ChatgptRoleSessionQueryCriteria
query
,
Pageable
pageable
)
{
IPage
<
ChatgptRoleSession
>
queryPage
=
PageUtil
.
toMybatisPage
(
pageable
);
IPage
<
ChatgptRoleSession
>
page
=
chatgptRoleSessionMapper
.
selectPage
(
queryPage
,
QueryHelpMybatisPlus
.
getPredicate
(
query
));
return
ConvertUtil
.
convertPage
(
page
,
ChatgptRoleSessionDto
.
class
);
}
@Override
public
List
<
ChatgptRoleSessionDto
>
queryAll
(
ChatgptRoleSessionQueryCriteria
query
){
return
ConvertUtil
.
convertList
(
chatgptRoleSessionMapper
.
selectList
(
QueryHelpMybatisPlus
.
getPredicate
(
query
)),
ChatgptRoleSessionDto
.
class
);
}
@Override
public
ChatgptRoleSession
getById
(
Integer
id
)
{
return
chatgptRoleSessionMapper
.
selectById
(
id
);
}
@Override
// @Cacheable(key = "'id:' + #p0")
public
ChatgptRoleSessionDto
findById
(
Integer
id
)
{
return
ConvertUtil
.
convert
(
getById
(
id
),
ChatgptRoleSessionDto
.
class
);
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
ChatgptRoleSession
insert
(
ChatgptRoleSessionDto
resources
)
{
ChatgptRoleSession
entity
=
ConvertUtil
.
convert
(
resources
,
ChatgptRoleSession
.
class
);
chatgptRoleSessionMapper
.
insert
(
entity
);
return
entity
;
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
int
updateById
(
ChatgptRoleSessionDto
resources
){
ChatgptRoleSession
entity
=
ConvertUtil
.
convert
(
resources
,
ChatgptRoleSession
.
class
);
int
ret
=
chatgptRoleSessionMapper
.
updateById
(
entity
);
// delCaches(resources.id);
return
ret
;
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
int
removeByIds
(
Set
<
Integer
>
ids
){
// delCaches(ids);
return
chatgptRoleSessionMapper
.
deleteBatchIds
(
ids
);
}
@Override
public
Integer
updateUpdateTime
(
Integer
id
)
{
return
chatgptRoleSessionMapper
.
updateUpdateTime
(
id
);
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
int
removeById
(
Integer
id
){
Set
<
Integer
>
set
=
new
HashSet
<>(
1
);
set
.
add
(
id
);
return
this
.
removeByIds
(
set
);
}
/*
private void delCaches(Integer id) {
redisUtils.delByKey(CACHE_KEY + "::id:", id);
}
private void delCaches(Set<Integer> ids) {
for (Integer id: ids) {
delCaches(id);
}
}*/
/*
@Override
public void download(List<ChatgptRoleSessionDto> all, HttpServletResponse response) throws IOException {
List<Map<String, Object>> list = new ArrayList<>();
for (ChatgptRoleSessionDto chatgptRoleSession : all) {
Map<String,Object> map = new LinkedHashMap<>();
map.put("名称", chatgptRoleSession.getName());
map.put("角色描述id", chatgptRoleSession.getRoleDescId());
map.put("用户id", chatgptRoleSession.getUserId());
map.put("创建时间", chatgptRoleSession.getCreateTime());
list.add(map);
}
FileUtil.downloadExcel(list, response);
}*/
}
src/main/java/admin/modules/chatgpt/service/impl/ChatgptRoleTypeServiceImpl.java
0 → 100644
View file @
8b435801
package
admin
.
modules
.
chatgpt
.
service
.
impl
;
import
admin.base.PageInfo
;
import
admin.base.QueryHelpMybatisPlus
;
import
admin.base.impl.CommonServiceImpl
;
import
admin.modules.chatgpt.domain.ChatgptRoleType
;
import
admin.modules.chatgpt.service.ChatgptRoleTypeService
;
import
admin.modules.chatgpt.service.dto.ChatgptRoleTypeDto
;
import
admin.modules.chatgpt.service.dto.ChatgptRoleTypeQueryCriteria
;
import
admin.modules.chatgpt.service.mapper.ChatgptRoleTypeMapper
;
import
admin.util.ConvertUtil
;
import
admin.util.PageUtil
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
lombok.AllArgsConstructor
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Set
;
/**
* @author wk
* @date 2023-11-27
*/
@Service
@AllArgsConstructor
// @CacheConfig(cacheNames = ChatgptRoleTypeService.CACHE_KEY)
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
public
class
ChatgptRoleTypeServiceImpl
extends
CommonServiceImpl
<
ChatgptRoleTypeMapper
,
ChatgptRoleType
>
implements
ChatgptRoleTypeService
{
// private final RedisUtils redisUtils;
private
final
ChatgptRoleTypeMapper
chatgptRoleTypeMapper
;
@Override
public
PageInfo
<
ChatgptRoleTypeDto
>
queryAll
(
ChatgptRoleTypeQueryCriteria
query
,
Pageable
pageable
)
{
IPage
<
ChatgptRoleType
>
queryPage
=
PageUtil
.
toMybatisPage
(
pageable
);
IPage
<
ChatgptRoleType
>
page
=
chatgptRoleTypeMapper
.
selectPage
(
queryPage
,
QueryHelpMybatisPlus
.
getPredicate
(
query
));
return
ConvertUtil
.
convertPage
(
page
,
ChatgptRoleTypeDto
.
class
);
}
@Override
public
List
<
ChatgptRoleTypeDto
>
queryAll
(
ChatgptRoleTypeQueryCriteria
query
){
return
ConvertUtil
.
convertList
(
chatgptRoleTypeMapper
.
selectList
(
QueryHelpMybatisPlus
.
getPredicate
(
query
)),
ChatgptRoleTypeDto
.
class
);
}
@Override
public
ChatgptRoleType
getById
(
String
id
)
{
return
chatgptRoleTypeMapper
.
selectById
(
id
);
}
@Override
// @Cacheable(key = "'id:' + #p0")
public
ChatgptRoleTypeDto
findById
(
String
id
)
{
return
ConvertUtil
.
convert
(
getById
(
id
),
ChatgptRoleTypeDto
.
class
);
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
int
insert
(
ChatgptRoleTypeDto
resources
)
{
ChatgptRoleType
entity
=
ConvertUtil
.
convert
(
resources
,
ChatgptRoleType
.
class
);
return
chatgptRoleTypeMapper
.
insert
(
entity
);
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
int
updateById
(
ChatgptRoleTypeDto
resources
){
ChatgptRoleType
entity
=
ConvertUtil
.
convert
(
resources
,
ChatgptRoleType
.
class
);
int
ret
=
chatgptRoleTypeMapper
.
updateById
(
entity
);
// delCaches(resources.id);
return
ret
;
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
int
removeByIds
(
Set
<
String
>
ids
){
// delCaches(ids);
return
chatgptRoleTypeMapper
.
deleteBatchIds
(
ids
);
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
int
removeById
(
String
id
){
Set
<
String
>
set
=
new
HashSet
<>(
1
);
set
.
add
(
id
);
return
this
.
removeByIds
(
set
);
}
/*
private void delCaches(String id) {
redisUtils.delByKey(CACHE_KEY + "::id:", id);
}
private void delCaches(Set<String> ids) {
for (String id: ids) {
delCaches(id);
}
}*/
/*
@Override
public void download(List<ChatgptRoleTypeDto> all, HttpServletResponse response) throws IOException {
List<Map<String, Object>> list = new ArrayList<>();
for (ChatgptRoleTypeDto chatgptRoleType : all) {
Map<String,Object> map = new LinkedHashMap<>();
map.put("类别名称", chatgptRoleType.getRoleTypeName());
map.put("排序序号", chatgptRoleType.getSortNum());
list.add(map);
}
FileUtil.downloadExcel(list, response);
}*/
}
src/main/java/admin/modules/chatgpt/service/impl/RiskControlWordsServiceImpl.java
0 → 100644
View file @
8b435801
package
admin
.
modules
.
chatgpt
.
service
.
impl
;
import
admin.base.PageInfo
;
import
admin.base.QueryHelpMybatisPlus
;
import
admin.base.impl.CommonServiceImpl
;
import
admin.modules.chatgpt.domain.RiskControlWords
;
import
admin.modules.chatgpt.service.RiskControlWordsService
;
import
admin.modules.chatgpt.service.dto.RiskControlWordsDto
;
import
admin.modules.chatgpt.service.dto.RiskControlWordsQueryCriteria
;
import
admin.modules.chatgpt.service.mapper.RiskControlWordsMapper
;
import
admin.util.ConvertUtil
;
import
admin.util.PageUtil
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
lombok.AllArgsConstructor
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Set
;
/**
* @author yan
* @date 2024-02-27
*/
@Service
@AllArgsConstructor
// @CacheConfig(cacheNames = RiskControlWordsService.CACHE_KEY)
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
public
class
RiskControlWordsServiceImpl
extends
CommonServiceImpl
<
RiskControlWordsMapper
,
RiskControlWords
>
implements
RiskControlWordsService
{
// private final RedisUtils redisUtils;
private
final
RiskControlWordsMapper
riskControlWordsMapper
;
@Override
public
PageInfo
<
RiskControlWordsDto
>
queryAll
(
RiskControlWordsQueryCriteria
query
,
Pageable
pageable
)
{
IPage
<
RiskControlWords
>
queryPage
=
PageUtil
.
toMybatisPage
(
pageable
);
IPage
<
RiskControlWords
>
page
=
riskControlWordsMapper
.
selectPage
(
queryPage
,
QueryHelpMybatisPlus
.
getPredicate
(
query
));
return
ConvertUtil
.
convertPage
(
page
,
RiskControlWordsDto
.
class
);
}
@Override
public
List
<
RiskControlWordsDto
>
queryAll
(
RiskControlWordsQueryCriteria
query
){
return
ConvertUtil
.
convertList
(
riskControlWordsMapper
.
selectList
(
QueryHelpMybatisPlus
.
getPredicate
(
query
)),
RiskControlWordsDto
.
class
);
}
@Override
public
RiskControlWords
getById
(
Long
id
)
{
return
riskControlWordsMapper
.
selectById
(
id
);
}
@Override
// @Cacheable(key = "'id:' + #p0")
public
RiskControlWordsDto
findById
(
Long
id
)
{
return
ConvertUtil
.
convert
(
getById
(
id
),
RiskControlWordsDto
.
class
);
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
int
insert
(
RiskControlWordsDto
resources
)
{
RiskControlWords
entity
=
ConvertUtil
.
convert
(
resources
,
RiskControlWords
.
class
);
return
riskControlWordsMapper
.
insert
(
entity
);
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
int
updateById
(
RiskControlWordsDto
resources
){
RiskControlWords
entity
=
ConvertUtil
.
convert
(
resources
,
RiskControlWords
.
class
);
int
ret
=
riskControlWordsMapper
.
updateById
(
entity
);
// delCaches(resources.id);
return
ret
;
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
int
removeByIds
(
Set
<
Long
>
ids
){
// delCaches(ids);
return
riskControlWordsMapper
.
deleteBatchIds
(
ids
);
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
addAll
(
String
words
)
{
String
[]
wordArray
=
words
.
split
(
";"
);
RiskControlWords
riskControlWords
=
new
RiskControlWords
();
for
(
String
word
:
wordArray
){
riskControlWords
.
setId
(
null
);
riskControlWords
.
setName
(
word
);
riskControlWordsMapper
.
insert
(
riskControlWords
);
}
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
int
removeById
(
Long
id
){
Set
<
Long
>
set
=
new
HashSet
<>(
1
);
set
.
add
(
id
);
return
this
.
removeByIds
(
set
);
}
/*
private void delCaches(Long id) {
redisUtils.delByKey(CACHE_KEY + "::id:", id);
}
private void delCaches(Set<Long> ids) {
for (Long id: ids) {
delCaches(id);
}
}*/
/*
@Override
public void download(List<RiskControlWordsDto> all, HttpServletResponse response) throws IOException {
List<Map<String, Object>> list = new ArrayList<>();
for (RiskControlWordsDto riskControlWords : all) {
Map<String,Object> map = new LinkedHashMap<>();
map.put("风控词", riskControlWords.getName());
list.add(map);
}
FileUtil.downloadExcel(list, response);
}*/
}
src/main/java/admin/modules/chatgpt/service/mapper/ChatgptRoleDescMapper.java
0 → 100644
View file @
8b435801
package
admin
.
modules
.
chatgpt
.
service
.
mapper
;
import
admin.base.CommonMapper
;
import
admin.modules.chatgpt.domain.ChatgptRoleDesc
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.springframework.stereotype.Repository
;
/**
* @author wk
* @date 2023-11-27
*/
@Repository
@Mapper
public
interface
ChatgptRoleDescMapper
extends
CommonMapper
<
ChatgptRoleDesc
>
{
}
src/main/java/admin/modules/chatgpt/service/mapper/ChatgptRoleMapper.java
0 → 100644
View file @
8b435801
package
admin
.
modules
.
chatgpt
.
service
.
mapper
;
import
admin.base.CommonMapper
;
import
admin.modules.chatgpt.domain.ChatgptRole
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.springframework.stereotype.Repository
;
/**
* @author wk
* @date 2023-11-27
*/
@Repository
@Mapper
public
interface
ChatgptRoleMapper
extends
CommonMapper
<
ChatgptRole
>
{
}
src/main/java/admin/modules/chatgpt/service/mapper/ChatgptRoleRecordsMapper.java
0 → 100644
View file @
8b435801
package
admin
.
modules
.
chatgpt
.
service
.
mapper
;
import
admin.base.CommonMapper
;
import
admin.modules.chatgpt.domain.ChatgptRoleRecords
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Param
;
import
org.springframework.stereotype.Repository
;
import
java.util.List
;
/**
* @author wk
* @date 2023-11-27
*/
@Repository
@Mapper
public
interface
ChatgptRoleRecordsMapper
extends
CommonMapper
<
ChatgptRoleRecords
>
{
List
<
ChatgptRoleRecords
>
queryRoleSessionListPage
(
IPage
<
ChatgptRoleRecords
>
page
,
@Param
(
"userId"
)
Long
userId
,
@Param
(
"roleDescId"
)
Integer
roleDescId
);
Integer
findByTextCount
(
Long
memberId
);
Integer
findBySessionCount
(
Long
memberId
);
Integer
findByDialogueCount
(
Long
memberId
);
}
src/main/java/admin/modules/chatgpt/service/mapper/ChatgptRoleSessionMapper.java
0 → 100644
View file @
8b435801
package
admin
.
modules
.
chatgpt
.
service
.
mapper
;
import
admin.base.CommonMapper
;
import
admin.modules.chatgpt.domain.ChatgptRoleSession
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.springframework.stereotype.Repository
;
/**
* @author wk
* @date 2023-11-28
*/
@Repository
@Mapper
public
interface
ChatgptRoleSessionMapper
extends
CommonMapper
<
ChatgptRoleSession
>
{
int
updateUpdateTime
(
Integer
id
);
}
src/main/java/admin/modules/chatgpt/service/mapper/ChatgptRoleTypeMapper.java
0 → 100644
View file @
8b435801
package
admin
.
modules
.
chatgpt
.
service
.
mapper
;
import
admin.base.CommonMapper
;
import
admin.modules.chatgpt.domain.ChatgptRoleType
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.springframework.stereotype.Repository
;
/**
* @author wk
* @date 2023-11-27
*/
@Repository
@Mapper
public
interface
ChatgptRoleTypeMapper
extends
CommonMapper
<
ChatgptRoleType
>
{
}
src/main/java/admin/modules/chatgpt/service/mapper/RiskControlWordsMapper.java
0 → 100644
View file @
8b435801
package
admin
.
modules
.
chatgpt
.
service
.
mapper
;
import
admin.base.CommonMapper
;
import
admin.modules.chatgpt.domain.RiskControlWords
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.springframework.stereotype.Repository
;
/**
* @author yan
* @date 2024-02-27
*/
@Repository
@Mapper
public
interface
RiskControlWordsMapper
extends
CommonMapper
<
RiskControlWords
>
{
}
src/main/java/admin/rest/ChatgptRoleRecordsController.java
0 → 100644
View file @
8b435801
package
admin
.
rest
;
import
admin.base.PageInfo
;
import
admin.modules.chatgpt.service.ChatgptRoleRecordsService
;
import
admin.modules.chatgpt.service.ChatgptRoleSessionService
;
import
admin.modules.chatgpt.service.dto.ChatgptRoleRecordsDto
;
import
admin.modules.chatgpt.service.dto.ChatgptRoleRecordsQueryCriteria
;
import
admin.modules.chatgpt.service.dto.ChatgptRoleSessionQueryCriteria
;
import
admin.resp.ApiResponse
;
import
admin.util.ScreenEnum
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.concurrent.TimeUnit
;
/**
* @author wk
* @date 2023-11-27
**/
@Slf4j
@RestController
@RequiredArgsConstructor
@Api
(
tags
=
"微信小程序:对话记录"
)
@RequestMapping
(
value
=
"wx/chatgptRoleRecords/"
)
public
class
ChatgptRoleRecordsController
{
private
final
ChatgptRoleRecordsService
chatgptRoleRecordsService
;
private
final
ChatgptRoleSessionService
chatgptRoleSessionService
;
@ApiOperation
(
"会话查询对话记录"
)
@GetMapping
(
value
=
"sessionList"
)
public
ApiResponse
<
Object
>
querySessionList
(
ChatgptRoleRecordsQueryCriteria
query
,
Pageable
pageable
)
{
return
ApiResponse
.
buildSuccess
(
chatgptRoleRecordsService
.
queryAll
(
query
,
pageable
));
}
@ApiOperation
(
"查询会话"
)
@GetMapping
(
value
=
"list"
)
public
ApiResponse
<
Object
>
query
(
ChatgptRoleSessionQueryCriteria
query
,
Pageable
pageable
){
Integer
byUserName
=
ScreenEnum
.
getByUserName
(
query
.
getName
());
query
.
setUserId
(
byUserName
);
return
ApiResponse
.
buildSuccess
(
chatgptRoleSessionService
.
queryAll
(
query
,
pageable
));
}
}
src/main/java/admin/server/VoiceWebSocketServer.java
View file @
8b435801
package
admin
.
server
;
import
admin.config.SpeechToTextConfig
;
import
admin.model.WebSocketModel
;
import
admin.modules.chatgpt.domain.ChatgptRoleRecords
;
import
admin.modules.chatgpt.domain.ChatgptRoleSession
;
import
admin.modules.chatgpt.service.ChatgptRoleRecordsService
;
import
admin.modules.chatgpt.service.ChatgptRoleSessionService
;
import
admin.service.MaxkbOpenApiService
;
import
admin.util.DateUtil
;
import
admin.util.ScreenEnum
;
import
com.alibaba.fastjson.JSON
;
import
lombok.extern.slf4j.Slf4j
;
import
okhttp3.HttpUrl
;
...
...
@@ -37,12 +44,24 @@ public class VoiceWebSocketServer {
private
static
AtomicInteger
onlineNum
=
new
AtomicInteger
();
private
static
SpeechToTextConfig
voiceConfig
;
private
static
MaxkbOpenApiService
maxkbOpenApiService
;
private
static
ChatgptRoleRecordsService
chatgptRoleRecordsService
;
private
static
ChatgptRoleSessionService
chatgptRoleSessionService
;
@Resource
public
void
setVoiceConfig
(
SpeechToTextConfig
speechToTextConfig
){
voiceConfig
=
speechToTextConfig
;
}
@Resource
public
void
setChatgptRoleRecordsService
(
ChatgptRoleRecordsService
chatgptRoleRecordsService
){
this
.
chatgptRoleRecordsService
=
chatgptRoleRecordsService
;
}
@Resource
public
void
setChatgptRoleSessionService
(
ChatgptRoleSessionService
chatgptRoleSessionService
){
this
.
chatgptRoleSessionService
=
chatgptRoleSessionService
;
}
@Resource
public
void
setMaxkbOpenApiService
(
MaxkbOpenApiService
maxkbOpenApiService
){
...
...
@@ -56,6 +75,20 @@ public class VoiceWebSocketServer {
public
void
onOpen
(
Session
session
,
@PathParam
(
value
=
"memberId"
)
String
memberId
)
{
log
.
info
(
"{}已连接"
,
memberId
);
sessionPools
.
put
(
memberId
,
session
);
//1.获取最新的会话id
String
maxSessionId
=
chatgptRoleRecordsService
.
queryMaxSessionId
();
WebSocketModel
webSocketModel
=
new
WebSocketModel
();
webSocketModel
.
setType
(
"text"
);
webSocketModel
.
setAction
(
"replaySessionId"
);
webSocketModel
.
setContent
(
maxSessionId
);
webSocketModel
.
setSessionId
(
maxSessionId
);
//2.返回给前端最新的sessionId
String
msg
=
JSON
.
toJSONString
(
webSocketModel
);
try
{
session
.
getBasicRemote
().
sendText
(
msg
);
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
//关闭连接时调用
...
...
@@ -71,10 +104,27 @@ public class VoiceWebSocketServer {
public
void
onTextMessage
(
Session
session
,
String
message
)
throws
IOException
{
// session.setMaxBinaryMessageBufferSize(50 * 1024 * 1024);
log
.
info
(
"message:{}"
,
message
);
Map
<
String
,
Object
>
map
=
JSON
.
parseObject
(
message
,
Map
.
class
);
WebSocketModel
webSocketModel
=
JSON
.
parseObject
(
message
,
WebSocketModel
.
class
);
//1.如果问题不存在则创建问题
ChatgptRoleSession
byId
=
chatgptRoleSessionService
.
getById
(
webSocketModel
.
getSessionId
());
if
(
byId
==
null
&&
webSocketModel
.
getAction
().
equals
(
"text"
)){
ChatgptRoleSession
chatgptRoleSession
=
new
ChatgptRoleSession
();
chatgptRoleSession
.
setId
(
Integer
.
valueOf
(
webSocketModel
.
getSessionId
()));
chatgptRoleSession
.
setName
(
webSocketModel
.
getData
());
chatgptRoleSession
.
setRoleDescId
(
10001
);
chatgptRoleSession
.
setUserId
(
ScreenEnum
.
getByUserName
(
webSocketModel
.
getName
()));
chatgptRoleSessionService
.
save
(
chatgptRoleSession
);
}
else
if
(
byId
!=
null
&&
webSocketModel
.
getAction
().
equals
(
"text"
)){
ChatgptRoleRecords
chatgptRoleRecords
=
new
ChatgptRoleRecords
();
chatgptRoleRecords
.
setMessage
(
webSocketModel
.
getData
());
chatgptRoleRecords
.
setReceiverId
(
10001
);
chatgptRoleRecords
.
setSenderId
(
Integer
.
valueOf
(
webSocketModel
.
getSessionId
()));
chatgptRoleRecords
.
setCreateTime
(
DateUtil
.
getNowTimestamp
());
chatgptRoleRecordsService
.
save
(
chatgptRoleRecords
);
}
String
msg
=
""
;
if
(
"sendText"
.
equals
(
map
.
get
(
"action"
))){
msg
=
(
String
)
map
.
get
(
"data"
);
if
(
"sendText"
.
equals
(
webSocketModel
.
getAction
(
))){
msg
=
webSocketModel
.
getData
(
);
}
maxkbOpenApiService
.
talk
(
message
,
session
);
}
...
...
src/main/java/admin/service/impl/DeepSeekOpenApiServiceImpl.java
View file @
8b435801
...
...
@@ -43,7 +43,7 @@ public class DeepSeekOpenApiServiceImpl implements DeepSeekOpenApiService {
.
addHeader
(
"Accept"
,
"application/json"
)
.
addHeader
(
"Authorization"
,
"Bearer zkhjdpQ8"
)
.
build
();
DeepSeekAiListener
deepSeekAiListener
=
new
DeepSeekAiListener
(
null
);
DeepSeekAiListener
deepSeekAiListener
=
new
DeepSeekAiListener
(
null
,
null
);
// OkHttpClient okHttpClient = new OkHttpClient.Builder()
// .connectTimeout(1, TimeUnit.MINUTES)
// .readTimeout(1, TimeUnit.MINUTES)
...
...
src/main/java/admin/service/impl/MaxkbOpenApiServiceImpl.java
View file @
8b435801
package
admin
.
service
.
impl
;
import
admin.model.WebSocketModel
;
import
admin.model.maxdb.MaxdbScreenConfig
;
import
admin.model.maxdb.MaxdbZkhjConfig
;
import
admin.model.maxdb.req.MaxdbReq
;
import
admin.resp.ApiResponse
;
import
admin.service.MaxkbOpenApiService
;
import
admin.util.HttpUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
...
...
@@ -35,7 +37,8 @@ public class MaxkbOpenApiServiceImpl implements MaxkbOpenApiService {
public
void
chatCompletions
(
String
message
,
String
chatId
,
Session
session
)
{
MaxdbReq
maxdbReq
=
new
MaxdbReq
();
maxdbReq
.
setMessage
(
message
);
HttpUtil
.
postCallBackStream
(
String
.
format
(
maxdbScreenConfig
.
getTalkUrl
(),
chatId
),
maxdbReq
,
maxdbScreenConfig
.
getApiKey
(),
session
);
WebSocketModel
webSocketModel
=
JSONObject
.
parseObject
(
message
,
WebSocketModel
.
class
);
HttpUtil
.
postCallBackStream
(
String
.
format
(
maxdbScreenConfig
.
getTalkUrl
(),
chatId
),
maxdbReq
,
maxdbScreenConfig
.
getApiKey
(),
session
,
webSocketModel
.
getSessionId
());
}
@Override
...
...
src/main/java/admin/util/ConvertUtil.java
0 → 100644
View file @
8b435801
package
admin
.
util
;
import
admin.base.PageInfo
;
import
cn.hutool.core.bean.BeanUtil
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
/**
* 转换
* Created by jinjin on 2020-09-22.
*/
public
class
ConvertUtil
{
public
static
<
T
,
S
>
T
convert
(
final
S
s
,
Class
<
T
>
clz
)
{
return
s
==
null
?
null
:
BeanUtil
.
copyProperties
(
s
,
clz
);
}
public
static
<
T
,
S
>
List
<
T
>
convertList
(
List
<
S
>
s
,
Class
<
T
>
clz
)
{
return
s
==
null
?
null
:
s
.
stream
().
map
(
vs
->
BeanUtil
.
copyProperties
(
vs
,
clz
)).
collect
(
Collectors
.
toList
());
}
public
static
<
T
,
S
>
Set
<
T
>
convertSet
(
Set
<
S
>
s
,
Class
<
T
>
clz
)
{
return
s
==
null
?
null
:
s
.
stream
().
map
(
vs
->
BeanUtil
.
copyProperties
(
vs
,
clz
)).
collect
(
Collectors
.
toSet
());
}
public
static
<
T
,
S
>
PageInfo
<
T
>
convertPage
(
IPage
<
S
>
page
,
Class
<
T
>
clz
)
{
if
(
page
==
null
)
{
return
null
;
}
PageInfo
<
T
>
pageInfo
=
new
PageInfo
<>();
pageInfo
.
setTotalElements
(
page
.
getTotal
());
pageInfo
.
setContent
(
convertList
(
page
.
getRecords
(),
clz
));
return
pageInfo
;
}
}
src/main/java/admin/util/DateUtil.java
0 → 100644
View file @
8b435801
/*
* Copyright 2019-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
admin
.
util
;
import
cn.hutool.core.date.DatePattern
;
import
cn.hutool.core.date.DateTime
;
import
lombok.extern.slf4j.Slf4j
;
import
java.sql.Timestamp
;
import
java.text.DateFormat
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.time.*
;
import
java.time.format.DateTimeFormatter
;
import
java.util.*
;
/**
* @date: 2020/6/11 16:28
* @apiNote: JDK 8 新日期类 格式化与字符串转换 工具类
*/
@Slf4j
public
class
DateUtil
{
public
static
final
DateTimeFormatter
DFY_MD_HMS
=
DateTimeFormatter
.
ofPattern
(
DatePattern
.
NORM_DATETIME_PATTERN
);
public
static
final
DateTimeFormatter
DFY_MD
=
DateTimeFormatter
.
ofPattern
(
DatePattern
.
NORM_DATE_PATTERN
);
public
static
final
String
rfcFormatter
=
"yyyy-MM-dd'T'HH:mm:ssXXX"
;
public
static
final
String
FULL_TIME_PATTERN
=
"yyyyMMddHHmmss"
;
public
static
final
String
FULL_TIME_SPLIT_PATTERN
=
"yyyy-MM-dd HH:mm:ss"
;
public
static
final
String
CST_TIME_PATTERN
=
"EEE MMM dd HH:mm:ss zzz yyyy"
;
public
static
String
formatFullTime
(
LocalDateTime
localDateTime
)
{
return
formatFullTime
(
localDateTime
,
FULL_TIME_PATTERN
);
}
public
static
String
formatFullTime
(
LocalDateTime
localDateTime
,
String
pattern
)
{
DateTimeFormatter
dateTimeFormatter
=
DateTimeFormatter
.
ofPattern
(
pattern
);
return
localDateTime
.
format
(
dateTimeFormatter
);
}
/**
* LocalDateTime 转时间戳
*
* @param localDateTime /
* @return /
*/
public
static
Long
getTimeStamp
(
LocalDateTime
localDateTime
)
{
return
localDateTime
.
atZone
(
ZoneId
.
systemDefault
()).
toEpochSecond
();
}
public
static
Timestamp
getNowTimestamp
(){
return
new
Timestamp
(
System
.
currentTimeMillis
());
}
/**艾佳地磁奇怪的时间方式转化*/
public
static
Timestamp
parseTimeByTimeString
(
String
yyyyMMddHHmmss
){
if
(
yyyyMMddHHmmss
.
length
()==
14
)
{
StringBuilder
stringBuilder
=
new
StringBuilder
(
yyyyMMddHHmmss
);
return
Timestamp
.
valueOf
(
stringBuilder
.
insert
(
4
,
"-"
).
insert
(
7
,
"-"
).
insert
(
10
,
" "
).
insert
(
13
,
":"
).
insert
(
16
,
":"
).
toString
());
}
return
getNowTimestamp
();
}
public
static
boolean
isWeekDay
(){
int
weekday
=
DateUtil
.
getWeekOfDate
(
new
Date
());
return
weekday
>=
6
;
}
/**
* 是否在时间段内,按起始时间和结束时间按具体时间算
* */
public
static
boolean
isBetweenTimeNow
(
Timestamp
compareTime
,
Timestamp
startTime
,
Timestamp
endTime
){
return
(
startTime
).
getTime
()<=
compareTime
.
getTime
()&&(
endTime
).
getTime
()>=
compareTime
.
getTime
();
}
/** String转时间戳 */
public
static
long
dateToMs
(
String
zhDate
,
String
pattern
)
{
SimpleDateFormat
format
=
new
SimpleDateFormat
(
pattern
,
Locale
.
getDefault
());
try
{
Date
date
=
format
.
parse
(
zhDate
);
return
date
.
getTime
();
}
catch
(
Exception
e
)
{
return
0
;
}
}
/**
* 遵循rfc3339标准格式,格式为YYYY-MM-DDTHH:mm:ss+TIMEZONE
* 例如:2015-05-20T13:29:35+08:00表示,北京时间2015年5月20日 13点29分35秒。
* @param timestamp
* @return
*/
public
static
String
timestampFormatRfc
(
Timestamp
timestamp
)
{
if
(
timestamp
==
null
)
return
""
;
DateFormat
sdf
=
new
SimpleDateFormat
(
rfcFormatter
);
return
sdf
.
format
(
timestamp
);
}
public
static
Timestamp
getMonthOneDay
(
Timestamp
timestamp
)
{
Calendar
calendar1
=
Calendar
.
getInstance
();
calendar1
.
setTimeInMillis
(
timestamp
.
getTime
());
calendar1
.
set
(
calendar1
.
get
(
1
),
calendar1
.
get
(
2
),
1
,
0
,
0
,
0
);
Date
beginOfDate
=
calendar1
.
getTime
();
return
new
Timestamp
(
calendar1
.
getTimeInMillis
());
}
public
static
Timestamp
getYearOneDay
(
Timestamp
timestamp
)
{
Calendar
calendar1
=
Calendar
.
getInstance
();
calendar1
.
setTimeInMillis
(
timestamp
.
getTime
());
calendar1
.
set
(
calendar1
.
get
(
1
),
0
,
1
,
0
,
0
,
0
);
return
new
Timestamp
(
calendar1
.
getTimeInMillis
());
}
/**加一天*/
public
static
Timestamp
addTimeMonth
(
Timestamp
timestamp
,
Integer
t
){
Calendar
c
=
Calendar
.
getInstance
();
c
.
setTime
(
timestamp
);
c
.
add
(
Calendar
.
MONTH
,
t
);
// 加一 月
return
new
Timestamp
(
c
.
getTimeInMillis
());
}
/**加一天*/
public
static
Timestamp
addTimeDay
(
Timestamp
timestamp
,
Integer
t
){
Calendar
c
=
Calendar
.
getInstance
();
c
.
setTime
(
timestamp
);
c
.
add
(
Calendar
.
DATE
,
t
);
// 加一 天
return
new
Timestamp
(
c
.
getTimeInMillis
());
}
/**加n分钟*/
public
static
Timestamp
addTimeMinute
(
Timestamp
timestamp
,
Integer
t
){
Calendar
c
=
Calendar
.
getInstance
();
c
.
setTime
(
timestamp
);
c
.
add
(
Calendar
.
MINUTE
,
t
);
// 加 t 分钟
return
new
Timestamp
(
c
.
getTimeInMillis
());
}
/**
* 是否推送时间,8点后,21点前为推送时间,地磁警告
* */
public
static
boolean
isPushTime8
(){
if
(
DateUtil
.
getNowTimestamp
().
compareTo
(
DateUtil
.
getNowDayDawnHMS
(
DateUtil
.
getNowTimestamp
(),
8
,
0
,
0
))
<
0
)
{
return
false
;
}
return
DateUtil
.
getNowTimestamp
().
compareTo
(
DateUtil
.
getNowDayDawnHMS
(
DateUtil
.
getNowTimestamp
(),
21
,
0
,
0
))
<=
0
;
}
/**
* 当天起始时间
* */
public
static
Timestamp
getNowDayBeforeDawn
(){
Calendar
calendar1
=
Calendar
.
getInstance
();
calendar1
.
set
(
calendar1
.
get
(
Calendar
.
YEAR
),
calendar1
.
get
(
Calendar
.
MONTH
),
calendar1
.
get
(
Calendar
.
DAY_OF_MONTH
),
0
,
0
,
0
);
Date
beginOfDate
=
calendar1
.
getTime
();
return
new
Timestamp
(
calendar1
.
getTimeInMillis
());
}
/**转化为当天起始时间*/
public
static
Timestamp
convertToNowDayBeforeDawn
(
Timestamp
timestamp
){
Calendar
calendar1
=
Calendar
.
getInstance
();
calendar1
.
setTimeInMillis
(
timestamp
.
getTime
());
calendar1
.
set
(
calendar1
.
get
(
Calendar
.
YEAR
),
calendar1
.
get
(
Calendar
.
MONTH
),
calendar1
.
get
(
Calendar
.
DAY_OF_MONTH
),
0
,
0
,
0
);
Date
beginOfDate
=
calendar1
.
getTime
();
return
new
Timestamp
(
calendar1
.
getTimeInMillis
());
}
public
static
Timestamp
getNowDayDawnHMS
(
Timestamp
timestamp
,
Integer
h
,
Integer
m
,
Integer
s
){
String
t
=
timestampFormat
(
timestamp
,
DatePattern
.
NORM_DATE_PATTERN
)+
" "
+
h
+
":"
+
m
+
":"
+
s
;
DateTime
dateTime
=
DateTime
.
of
(
t
,
DatePattern
.
NORM_DATETIME_PATTERN
);
return
new
Timestamp
(
dateTime
.
getTime
());
}
public
static
Timestamp
getNowDayMDHMS
(
Timestamp
timestamp
,
Integer
month
,
Integer
day
,
Integer
h
,
Integer
m
,
Integer
s
){
String
t
=
timestampFormat
(
timestamp
,
"yyyy"
)+
"-"
+
month
+
"-"
+
day
+
" "
+
h
+
":"
+
m
+
":"
+
s
;
DateTime
dateTime
=
DateTime
.
of
(
t
,
DatePattern
.
NORM_DATETIME_PATTERN
);
return
new
Timestamp
(
dateTime
.
getTime
());
}
/**
* 是否推送时间,7点后,21点前为推送时间
* */
public
static
boolean
isPushTime
(){
if
(
DateUtil
.
getNowTimestamp
().
compareTo
(
DateUtil
.
getNowDayDawnHMS
(
DateUtil
.
getNowTimestamp
(),
7
,
0
,
0
))
<
0
)
{
return
false
;
}
return
DateUtil
.
getNowTimestamp
().
compareTo
(
DateUtil
.
getNowDayDawnHMS
(
DateUtil
.
getNowTimestamp
(),
21
,
0
,
0
))
<=
0
;
}
/**加秒数*/
public
static
Timestamp
addTimeSecond
(
Timestamp
timestamp
,
Integer
t
){
Calendar
c
=
Calendar
.
getInstance
();
c
.
setTime
(
timestamp
);
c
.
add
(
Calendar
.
SECOND
,
t
);
// 加 t 分钟
return
new
Timestamp
(
c
.
getTimeInMillis
());
}
/**
* 结束时间
* */
public
static
Timestamp
getNowDayAfterDawn
(){
Calendar
calendar1
=
Calendar
.
getInstance
();
calendar1
.
set
(
calendar1
.
get
(
Calendar
.
YEAR
),
calendar1
.
get
(
Calendar
.
MONTH
),
calendar1
.
get
(
Calendar
.
DAY_OF_MONTH
),
23
,
59
,
59
);
Date
beginOfDate
=
calendar1
.
getTime
();
return
new
Timestamp
(
calendar1
.
getTimeInMillis
());
}
/**转化为参数时间的最晚时间*/
public
static
Timestamp
convertToNowDayAfterDawn
(
Timestamp
timestamp
){
Calendar
calendar1
=
Calendar
.
getInstance
();
calendar1
.
setTimeInMillis
(
timestamp
.
getTime
());
calendar1
.
set
(
calendar1
.
get
(
Calendar
.
YEAR
),
calendar1
.
get
(
Calendar
.
MONTH
),
calendar1
.
get
(
Calendar
.
DAY_OF_MONTH
),
23
,
59
,
59
);
Date
beginOfDate
=
calendar1
.
getTime
();
return
new
Timestamp
(
calendar1
.
getTimeInMillis
());
}
/**
* 时间戳转LocalDateTime
*
* @param timeStamp /
* @return /
*/
public
static
LocalDateTime
fromTimeStamp
(
Long
timeStamp
)
{
return
LocalDateTime
.
ofEpochSecond
(
timeStamp
,
0
,
OffsetDateTime
.
now
().
getOffset
());
}
/**
* LocalDateTime 转 Date
* Jdk8 后 不推荐使用 {@link Date} Date
*
* @param localDateTime /
* @return /
*/
public
static
Date
toDate
(
LocalDateTime
localDateTime
)
{
return
Date
.
from
(
localDateTime
.
atZone
(
ZoneId
.
systemDefault
()).
toInstant
());
}
/**
* LocalDate 转 Date
* Jdk8 后 不推荐使用 {@link Date} Date
*
* @param localDate /
* @return /
*/
public
static
Date
toDate
(
LocalDate
localDate
)
{
return
toDate
(
localDate
.
atTime
(
LocalTime
.
now
(
ZoneId
.
systemDefault
())));
}
/**
* Date转 LocalDateTime
* Jdk8 后 不推荐使用 {@link Date} Date
*
* @param date /
* @return /
*/
public
static
LocalDateTime
toLocalDateTime
(
Date
date
)
{
return
LocalDateTime
.
ofInstant
(
date
.
toInstant
(),
ZoneId
.
systemDefault
());
}
/**
* 日期 格式化
*
* @param localDateTime /
* @param patten /
* @return /
*/
public
static
String
localDateTimeFormat
(
LocalDateTime
localDateTime
,
String
patten
)
{
DateTimeFormatter
df
=
DateTimeFormatter
.
ofPattern
(
patten
);
return
df
.
format
(
localDateTime
);
}
/**
* 日期 格式化
*
* @param timestamp /
* @param patten /
* @return /
*/
public
static
String
timestampFormat
(
Timestamp
timestamp
,
String
patten
)
{
if
(
timestamp
==
null
)
return
""
;
DateFormat
sdf
=
new
SimpleDateFormat
(
patten
);
return
sdf
.
format
(
timestamp
);
}
/**
* 获取停车时长
* */
public
static
String
getTimeDuration
(
Timestamp
endTime
,
Timestamp
startTime
){
if
(
endTime
==
null
||
startTime
==
null
)
return
""
;
long
t1
=
endTime
.
getTime
();
long
t2
=
startTime
.
getTime
();
int
hours
=(
int
)
((
t1
-
t2
)/(
1000
*
60
*
60
));
int
minutes
=(
int
)
(((
t1
-
t2
)/
1000
-
hours
*(
60
*
60
))/
60
);
int
second
=(
int
)
((
t1
-
t2
)/
1000
-
hours
*(
60
*
60
)-
minutes
*
60
);
return
(
hours
>
0
?(
""
+
hours
+
"小时"
):
""
)+(
minutes
>
0
?(
minutes
+
"分"
):
""
)+
second
+
"秒"
;
}
/**
* 时间相差秒数
* */
public
static
Integer
getTimeSeconds
(
Timestamp
endTime
,
Timestamp
startTime
){
if
(
endTime
==
null
||
startTime
==
null
)
return
0
;
long
t1
=
endTime
.
getTime
();
long
t2
=
startTime
.
getTime
();
return
(
int
)
((
t1
-
t2
)/
1000
);
}
/**
* 日期 格式化
*
* @param localDateTime /
* @param df /
* @return /
*/
public
static
String
localDateTimeFormat
(
LocalDateTime
localDateTime
,
DateTimeFormatter
df
)
{
return
df
.
format
(
localDateTime
);
}
/**
* 日期格式化 yyyy-MM-dd HH:mm:ss
*
* @param localDateTime /
* @return /
*/
public
static
String
localDateTimeFormatyMdHms
(
LocalDateTime
localDateTime
)
{
return
DFY_MD_HMS
.
format
(
localDateTime
);
}
public
static
List
<
Timestamp
>
getAreaTimeDay
(
Timestamp
bTime
,
int
day
)
{
List
<
Timestamp
>
timestamps
=
new
ArrayList
();
bTime
=
bTime
==
null
?
getNowTimestamp
()
:
bTime
;
Timestamp
eTime
=
addTimeDay
(
bTime
,
day
);
if
(
day
>
0
)
{
timestamps
.
add
(
bTime
);
timestamps
.
add
(
eTime
);
}
else
{
timestamps
.
add
(
eTime
);
timestamps
.
add
(
bTime
);
}
return
timestamps
;
}
public
static
boolean
isBetweenJumpAreaAfterOneMin
(
long
second
)
{
long
s
=
second
%
3600L
;
return
s
>=
60L
&&
s
<
120L
;
}
/**
* 日期格式化 yyyy-MM-dd
*
* @param localDateTime /
* @return /
*/
public
String
localDateTimeFormatyMd
(
LocalDateTime
localDateTime
)
{
return
DFY_MD
.
format
(
localDateTime
);
}
/**
* 字符串转 LocalDateTime ,字符串格式 yyyy-MM-dd
*
* @param localDateTime /
* @return /
*/
public
static
LocalDateTime
parseLocalDateTimeFormat
(
String
localDateTime
,
String
pattern
)
{
DateTimeFormatter
dateTimeFormatter
=
DateTimeFormatter
.
ofPattern
(
pattern
);
return
LocalDateTime
.
from
(
dateTimeFormatter
.
parse
(
localDateTime
));
}
/**
* 字符串转 LocalDateTime ,字符串格式 yyyy-MM-dd
*
* @param localDateTime /
* @return /
*/
public
static
LocalDateTime
parseLocalDateTimeFormat
(
String
localDateTime
,
DateTimeFormatter
dateTimeFormatter
)
{
return
LocalDateTime
.
from
(
dateTimeFormatter
.
parse
(
localDateTime
));
}
/**
* 字符串转 LocalDateTime ,字符串格式 yyyy-MM-dd HH:mm:ss
*
* @param localDateTime /
* @return /
*/
public
static
LocalDateTime
parseLocalDateTimeFormatyMdHms
(
String
localDateTime
)
{
return
LocalDateTime
.
from
(
DFY_MD_HMS
.
parse
(
localDateTime
));
}
public
static
int
getWeekOfDate
(
Date
dt
)
{
Calendar
cal
=
Calendar
.
getInstance
();
cal
.
setTime
(
dt
);
int
w
=
cal
.
get
(
Calendar
.
DAY_OF_WEEK
)
-
1
;
return
w
==
0
?
7
:
w
;
}
/**
* 两个时间戳是否是同一天
* @param millis1
* @param millis2
* @return
*/
public
static
boolean
isSameDay
(
long
millis1
,
long
millis2
){
long
interval
=
millis1
-
millis2
;
return
interval
<
86400000
&&
interval
>
-
86400000
&&
millis2Days
(
millis1
,
TimeZone
.
getDefault
())
==
millis2Days
(
millis2
,
TimeZone
.
getDefault
());
}
private
static
long
millis2Days
(
long
millis
,
TimeZone
timeZone
)
{
return
(((
long
)
timeZone
.
getOffset
(
millis
))
+
millis
)
/
86400000
;
}
/**
* 相差分钟数
* @param endTime
* @param startTime
* @return
*/
public
static
Integer
getDifferMinute
(
Timestamp
endTime
,
Timestamp
startTime
)
{
Integer
parkTimeSeconds
=
DateUtil
.
getTimeSeconds
(
endTime
,
startTime
);
return
parkTimeSeconds
/
60
;
}
/**
* 获取计费小时,分开算比较清晰
* */
public
static
Map
<
String
,
Integer
>
getMoneyHour
(
Timestamp
entTime
,
Timestamp
startTime
){
Map
<
String
,
Integer
>
map
=
new
HashMap
<>();
//跨越的整天数
map
.
put
(
"days"
,(
int
)
((
getFreeTime
(
entTime
,
7
,
0
).
getTime
()
-
getFreeTime
(
startTime
,
7
,
0
).
getTime
())
/
(
1000
*
60
*
60
*
24
)));
//第一天:晚9点到起始点,负数取0,最后一天从早7点到结束点,负数取0
int
bTime
=
compareTimeMin
(
getFreeTime
(
startTime
,
21
,
0
),
startTime
);
//起始时间在8点40至9点间,不计费
if
(
isBetweenTimeReal
(
startTime
,
DateUtil
.
getNowDayDawnHMS
(
startTime
,
20
,
40
,
0
),
DateUtil
.
getNowDayDawnHMS
(
startTime
,
21
,
0
,
0
)))
bTime
=
0
;
int
eTime
=
compareTimeMin
(
entTime
,
getFreeTime
(
entTime
,
7
,
0
));
if
(
isBetweenTimeReal
(
entTime
,
DateUtil
.
getNowDayDawnHMS
(
entTime
,
7
,
0
,
0
),
DateUtil
.
getNowDayDawnHMS
(
entTime
,
7
,
20
,
0
)))
eTime
=
0
;
map
.
put
(
"bMin"
,
Math
.
max
(
bTime
,
0
));
map
.
put
(
"eMin"
,
Math
.
max
(
eTime
,
0
));
return
map
;
}
/**
* 获取免费时间段
* */
public
static
Timestamp
getFreeTime
(
Timestamp
time
,
Integer
hour
,
Integer
min
){
return
getNowDayDawnHMS
(
time
,
hour
,
min
,
0
);
}
/**
* 计算费用时,抛弃7点前,9点后的时候段 时间差分钟数
* */
public
static
Integer
compareTimeMin
(
Timestamp
entTime
,
Timestamp
startTime
){
try
{
//7点前取7点,21点后取21点
if
(
startTime
.
compareTo
(
DateUtil
.
getNowDayDawnHMS
(
startTime
,
7
,
0
,
0
))
<
0
)
{
startTime
=
DateUtil
.
getNowDayDawnHMS
(
startTime
,
7
,
0
,
0
);
}
if
(
entTime
.
compareTo
(
DateUtil
.
getNowDayDawnHMS
(
entTime
,
21
,
0
,
0
))
>
0
)
{
entTime
=
DateUtil
.
getNowDayDawnHMS
(
entTime
,
21
,
0
,
0
);
}
long
t1
=
entTime
.
getTime
();
long
t2
=
startTime
.
getTime
();
return
(
int
)
(((
t1
-
t2
)
/
1000
)
/
60
);
}
catch
(
Exception
ex
){
log
.
error
(
"获取停车耗时compareTimeMin异常,{},{}"
,
entTime
,
startTime
,
ex
);
}
return
0
;
}
/**
* 是否在时间段内
* */
public
static
boolean
isBetweenTime
(
Timestamp
compareTime
,
Timestamp
startTime
,
Timestamp
endTime
){
return
(
convertToNowDayBeforeDawn
(
startTime
)).
getTime
()<=
compareTime
.
getTime
()&&(
convertToNowDayAfterDawn
(
endTime
)).
getTime
()>=
compareTime
.
getTime
();
}
public
static
boolean
isBetweenTimeReal
(
Timestamp
compareTime
,
Timestamp
startTime
,
Timestamp
endTime
){
return
(
startTime
).
getTime
()<=
compareTime
.
getTime
()&&(
endTime
).
getTime
()>=
compareTime
.
getTime
();
}
/**
* 获取某一天的初始时刻 yyyy-MM-dd HH:mm:ss
* @param time 任意格式的时间
* @return
*/
public
static
String
getBeginDayTime
(
String
time
){
Date
useDate
=
new
Date
();
try
{
useDate
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
).
parse
(
time
);
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
}
// 设置查询当天初始时刻
Calendar
firstCa
=
Calendar
.
getInstance
();
firstCa
.
setTime
(
useDate
);
firstCa
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
firstCa
.
set
(
Calendar
.
MINUTE
,
0
);
firstCa
.
set
(
Calendar
.
SECOND
,
0
);
firstCa
.
set
(
Calendar
.
MILLISECOND
,
1
);
return
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
).
format
(
firstCa
.
getTime
());
}
/**
* 获取某一天的最后时刻 yyyy-MM-dd HH:mm:ss
* @param time 任意格式的时间
* @return
*/
public
static
String
getEndDayTime
(
String
time
){
Date
useDate
=
new
Date
();
try
{
useDate
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
).
parse
(
time
);
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
}
// 设置查询当天初始时刻
Calendar
firstCa
=
Calendar
.
getInstance
();
firstCa
.
setTime
(
useDate
);
firstCa
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
firstCa
.
set
(
Calendar
.
MINUTE
,
0
);
firstCa
.
set
(
Calendar
.
SECOND
,
0
);
firstCa
.
set
(
Calendar
.
MILLISECOND
,
1
);
Calendar
lastCa
=
Calendar
.
getInstance
();
lastCa
.
setTime
(
firstCa
.
getTime
());
lastCa
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
lastCa
.
set
(
Calendar
.
MINUTE
,
0
);
lastCa
.
set
(
Calendar
.
SECOND
,
0
);
lastCa
.
set
(
Calendar
.
MILLISECOND
,
0
);
lastCa
.
add
(
Calendar
.
DATE
,
1
);
lastCa
.
add
(
Calendar
.
MILLISECOND
,
-
1
);
return
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
).
format
(
lastCa
.
getTime
());
}
/**
* 获取某个月的初始时刻 yyyy-MM-dd HH:mm:ss
* @param time 任意格式的时间
* @return
*/
public
static
String
getBeginMonthTime
(
String
time
){
Date
useDate
=
new
Date
();
try
{
useDate
=
new
SimpleDateFormat
(
"yyyy-MM"
).
parse
(
time
);
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
}
// 设置查询月第一天初始时刻
Calendar
firstCa
=
Calendar
.
getInstance
();
firstCa
.
setTime
(
useDate
);
firstCa
.
set
(
Calendar
.
DAY_OF_MONTH
,
1
);
firstCa
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
firstCa
.
set
(
Calendar
.
MINUTE
,
0
);
firstCa
.
set
(
Calendar
.
SECOND
,
0
);
firstCa
.
set
(
Calendar
.
MILLISECOND
,
1
);
return
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
).
format
(
firstCa
.
getTime
());
}
/**
* 获取某个月的最后时刻 yyyy-MM-dd HH:mm:ss
* @param time 任意格式的时间
* @return
*/
public
static
String
getEndMonthTime
(
String
time
){
Date
useDate
=
new
Date
();
try
{
useDate
=
new
SimpleDateFormat
(
"yyyy-MM"
).
parse
(
time
);
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
}
// 设置查询月第一天初始时刻
Calendar
firstCa
=
Calendar
.
getInstance
();
firstCa
.
setTime
(
useDate
);
firstCa
.
set
(
Calendar
.
DAY_OF_MONTH
,
1
);
firstCa
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
firstCa
.
set
(
Calendar
.
MINUTE
,
0
);
firstCa
.
set
(
Calendar
.
SECOND
,
0
);
firstCa
.
set
(
Calendar
.
MILLISECOND
,
1
);
Calendar
lastCa
=
Calendar
.
getInstance
();
lastCa
.
setTime
(
firstCa
.
getTime
());
lastCa
.
set
(
Calendar
.
DAY_OF_MONTH
,
1
);
lastCa
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
lastCa
.
set
(
Calendar
.
MINUTE
,
0
);
lastCa
.
set
(
Calendar
.
SECOND
,
0
);
lastCa
.
set
(
Calendar
.
MILLISECOND
,
0
);
lastCa
.
add
(
Calendar
.
MONTH
,
1
);
lastCa
.
add
(
Calendar
.
MILLISECOND
,
-
1
);
return
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
).
format
(
lastCa
.
getTime
());
}
/**
* 获取某年的初始时刻 yyyy-MM-dd HH:mm:ss
* @param time 任意格式的时间
* @return
*/
public
static
String
getBeginYearTime
(
String
time
){
Date
useDate
=
new
Date
();
try
{
useDate
=
new
SimpleDateFormat
(
"yyyy"
).
parse
(
time
);
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
}
//设置查询年第一天
Calendar
firstCa
=
Calendar
.
getInstance
();
firstCa
.
setTime
(
useDate
);
firstCa
.
set
(
Calendar
.
MONTH
,
0
);
firstCa
.
set
(
Calendar
.
DAY_OF_MONTH
,
1
);
firstCa
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
firstCa
.
set
(
Calendar
.
MINUTE
,
0
);
firstCa
.
set
(
Calendar
.
SECOND
,
0
);
firstCa
.
set
(
Calendar
.
MILLISECOND
,
0
);
return
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
).
format
(
firstCa
.
getTime
());
}
/**
* 获取某年的最后时刻 yyyy-MM-dd HH:mm:ss
* @param time 任意格式的时间
* @return
*/
public
static
String
getEndYearTime
(
String
time
){
Date
useDate
=
new
Date
();
try
{
useDate
=
new
SimpleDateFormat
(
"yyyy"
).
parse
(
time
);
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
}
//设置查询年第一天
Calendar
firstCa
=
Calendar
.
getInstance
();
firstCa
.
setTime
(
useDate
);
firstCa
.
set
(
Calendar
.
MONTH
,
0
);
firstCa
.
set
(
Calendar
.
DAY_OF_MONTH
,
1
);
firstCa
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
firstCa
.
set
(
Calendar
.
MINUTE
,
0
);
firstCa
.
set
(
Calendar
.
SECOND
,
0
);
firstCa
.
set
(
Calendar
.
MILLISECOND
,
0
);
Calendar
lastCa
=
Calendar
.
getInstance
();
lastCa
.
setTime
(
firstCa
.
getTime
());
lastCa
.
set
(
Calendar
.
MONTH
,
0
);
lastCa
.
set
(
Calendar
.
DAY_OF_MONTH
,
1
);
lastCa
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
lastCa
.
set
(
Calendar
.
MINUTE
,
0
);
lastCa
.
set
(
Calendar
.
SECOND
,
0
);
lastCa
.
set
(
Calendar
.
MILLISECOND
,
0
);
lastCa
.
add
(
Calendar
.
YEAR
,
1
);
lastCa
.
add
(
Calendar
.
MILLISECOND
,
-
1
);
return
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
).
format
(
lastCa
.
getTime
());
}
public
static
String
timestampFormatyMdHms
(
Integer
day
)
{
SimpleDateFormat
df
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
return
df
.
format
(
addTimeDay
(
getNowTimestamp
(),
day
));
}
public
static
boolean
isBetweenJumpAreaBeforeTenMin
(
long
second
)
{
//20-31分钟之间
if
(
second
>=
1200L
&&
second
<
1860L
)
{
return
true
;
}
else
{
long
s
=
second
%
3600L
;
return
(
s
>=
3000L
&&
s
<=
3600L
)
||
s
<=
60
;
}
}
public
static
boolean
isBetweenJumpAreaAfterFiveMin
(
long
second
)
{
if
(
second
>=
1800L
&&
second
<=
2400L
)
{
return
true
;
}
else
{
long
s
=
second
%
3600L
;
return
s
>=
0L
&&
s
<=
600L
;
}
}
public
static
Timestamp
addTimeHour
(
Timestamp
timestamp
,
Integer
t
)
{
Calendar
c
=
Calendar
.
getInstance
();
c
.
setTime
(
timestamp
);
c
.
add
(
10
,
t
);
return
new
Timestamp
(
c
.
getTimeInMillis
());
}
public
static
String
getNextQuarterArea
(
Timestamp
now
)
{
int
month
=
now
.
getMonth
()
+
1
;
int
lastDay
;
if
(
month
<
4
)
{
lastDay
=
addTimeDay
(
getNowDayMDHMS
(
now
,
7
,
1
,
0
,
0
,
0
),
-
1
).
getDate
();
return
timestampFormat
(
getNowDayMDHMS
(
now
,
4
,
1
,
0
,
0
,
0
),
"MM月dd日"
)
+
"~"
+
timestampFormat
(
getNowDayMDHMS
(
now
,
6
,
lastDay
,
0
,
0
,
0
),
"MM月dd日"
);
}
else
if
(
month
<
7
)
{
lastDay
=
addTimeDay
(
getNowDayMDHMS
(
now
,
10
,
1
,
0
,
0
,
0
),
-
1
).
getDate
();
return
timestampFormat
(
getNowDayMDHMS
(
now
,
7
,
1
,
0
,
0
,
0
),
"MM月dd日"
)
+
"~"
+
timestampFormat
(
getNowDayMDHMS
(
now
,
9
,
lastDay
,
0
,
0
,
0
),
"MM月dd日"
);
}
else
if
(
month
<
10
)
{
lastDay
=
addTimeDay
(
getNowDayMDHMS
(
now
,
1
,
1
,
0
,
0
,
0
),
-
1
).
getDate
();
return
timestampFormat
(
getNowDayMDHMS
(
now
,
10
,
1
,
0
,
0
,
0
),
"MM月dd日"
)
+
"~"
+
timestampFormat
(
getNowDayMDHMS
(
now
,
12
,
lastDay
,
0
,
0
,
0
),
"MM月dd日"
);
}
else
{
lastDay
=
addTimeDay
(
getNowDayMDHMS
(
now
,
4
,
1
,
0
,
0
,
0
),
-
1
).
getDate
();
return
timestampFormat
(
getNowDayMDHMS
(
now
,
1
,
1
,
0
,
0
,
0
),
"MM月dd日"
)
+
"~"
+
timestampFormat
(
getNowDayMDHMS
(
now
,
3
,
lastDay
,
0
,
0
,
0
),
"MM月dd日"
);
}
}
public
static
Timestamp
getNextQuarterDay
()
{
Timestamp
now
=
getNowTimestamp
();
int
month
=
now
.
getMonth
();
if
(
month
<
4
)
{
return
getNowDayMDHMS
(
now
,
4
,
1
,
0
,
0
,
0
);
}
else
if
(
month
<
7
)
{
return
getNowDayMDHMS
(
now
,
7
,
1
,
0
,
0
,
0
);
}
else
{
return
month
<
10
?
getNowDayMDHMS
(
now
,
10
,
1
,
0
,
0
,
0
)
:
getNowDayMDHMS
(
now
,
1
,
1
,
0
,
0
,
0
);
}
}
}
src/main/java/admin/util/HttpUtil.java
View file @
8b435801
...
...
@@ -34,7 +34,7 @@ public class HttpUtil {
}
public
static
void
postCallBackStream
(
String
url
,
Object
data
,
String
apiKey
,
Session
session
){
public
static
void
postCallBackStream
(
String
url
,
Object
data
,
String
apiKey
,
Session
session
,
String
sessionId
){
OkHttpClient
okHttpClient
=
new
OkHttpClient
().
newBuilder
().
build
();
// RequestBody body = RequestBody.create(MediaType.parse("application/json"), data);
Request
request
=
null
;
...
...
@@ -51,6 +51,6 @@ public class HttpUtil {
throw
new
RuntimeException
(
e
);
}
EventSource
.
Factory
factory
=
EventSources
.
createFactory
(
okHttpClient
);
factory
.
newEventSource
(
request
,
new
DeepSeekAiListener
(
session
));
factory
.
newEventSource
(
request
,
new
DeepSeekAiListener
(
session
,
sessionId
));
}
}
src/main/java/admin/util/PageUtil.java
0 → 100644
View file @
8b435801
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
admin
.
util
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.core.metadata.OrderItem
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.data.domain.Sort
;
import
java.util.ArrayList
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
* 分页工具
* @date 2018-12-10
*/
public
class
PageUtil
extends
cn
.
hutool
.
core
.
util
.
PageUtil
{
/**
* List 分页
*/
public
static
List
toPage
(
int
page
,
int
size
,
List
list
)
{
int
fromIndex
=
page
*
size
;
int
toIndex
=
page
*
size
+
size
;
if
(
fromIndex
>
list
.
size
()){
return
new
ArrayList
();
}
else
if
(
toIndex
>=
list
.
size
())
{
return
list
.
subList
(
fromIndex
,
list
.
size
());
}
else
{
return
list
.
subList
(
fromIndex
,
toIndex
);
}
}
/**
* Page 数据处理,预防redis反序列化报错
*/
public
static
Map
<
String
,
Object
>
toPage
(
Page
page
)
{
Map
<
String
,
Object
>
map
=
new
LinkedHashMap
<>(
2
);
map
.
put
(
"content"
,
page
.
getContent
());
map
.
put
(
"totalElements"
,
page
.
getTotalElements
());
return
map
;
}
/**
* 自定义分页
*/
public
static
Map
<
String
,
Object
>
toPage
(
Object
object
,
Object
totalElements
)
{
Map
<
String
,
Object
>
map
=
new
LinkedHashMap
<>(
2
);
map
.
put
(
"content"
,
object
);
map
.
put
(
"totalElements"
,
totalElements
);
return
map
;
}
public
static
<
T
>
IPage
<
T
>
toMybatisPage
(
Pageable
pageable
)
{
return
toMybatisPage
(
pageable
,
false
);
}
public
static
<
T
>
IPage
<
T
>
toMybatisPage
(
Pageable
pageable
,
boolean
ignoreOrderBy
)
{
com
.
baomidou
.
mybatisplus
.
extension
.
plugins
.
pagination
.
Page
<
T
>
page
=
new
com
.
baomidou
.
mybatisplus
.
extension
.
plugins
.
pagination
.
Page
<>(
pageable
.
getPageNumber
()
+
1
,
pageable
.
getPageSize
());
if
(!
ignoreOrderBy
)
{
for
(
Sort
.
Order
order
:
pageable
.
getSort
())
{
OrderItem
orderItem
=
new
OrderItem
();
orderItem
.
setAsc
(
order
.
isAscending
());
orderItem
.
setColumn
(
com
.
baomidou
.
mybatisplus
.
core
.
toolkit
.
StringUtils
.
camelToUnderline
(
order
.
getProperty
()));
page
.
addOrder
(
orderItem
);
}
}
return
page
;
}
}
src/main/java/admin/util/ScreenEnum.java
0 → 100644
View file @
8b435801
package
admin
.
util
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.Getter
;
/**
* @author lj
* @date 2025/2/27 18:14
*/
@Getter
@AllArgsConstructor
public
enum
ScreenEnum
{
PH_ADMIN
(
"ph"
,
1
),
PH_LC_ADMIN
(
"ph_lc"
,
2
),
PH_SCREEN
(
"phscreen"
,
3
),
PH_TEST
(
"test"
,
4
),
PH_PYT
(
"pyt"
,
5
),
PH_PYT_LS
(
"pytls"
,
6
),
ZP_GQ
(
"zp_gq"
,
7
),
ADMIN
(
"admin"
,
8
),
ALL_PARK
(
"all"
,
9
),
BLT_ADMIN
(
"blt"
,
10
),
BLT_LC_ADMIN
(
"blt_lc"
,
11
),
BLT_SCREEN
(
"screen"
,
12
),
JS_ADMIN
(
"js"
,
13
),
JS_LC_ADMIN
(
"js_lc"
,
14
),
JS_SCREEN
(
"jsscreen"
,
15
),
HK_ADMIN
(
"hk"
,
16
),
HK_LC_ADMIN
(
"hk_lc"
,
17
),
HK_SCREEN
(
"hkscreen"
,
18
),
JGS_ADMIN
(
"jgs"
,
19
),
JGS_LC_ADMIN
(
"jgs_lc"
,
20
),
JGS_SCREEN
(
"jgsscreen"
,
21
),
BJ_ADMIN
(
"bj"
,
22
),
HZ_ADMIN
(
"hz"
,
23
),
QY_ADMIN
(
"qy"
,
24
),
QYT_ADMIN
(
"qyt"
,
25
),
NC_ADMIN
(
"nc"
,
26
),
YZ_ADMIN
(
"yz"
,
27
),
NK_ADMIN
(
"nk"
,
28
);
private
String
name
;
private
Integer
userId
;
public
static
Integer
getByUserName
(
String
userName
){
for
(
ScreenEnum
value:
ScreenEnum
.
values
()){
if
(
value
.
name
.
equals
(
userName
)){
return
value
.
userId
;
}
}
return
ScreenEnum
.
ALL_PARK
.
userId
;
}
}
src/main/resources/config/application.yml
View file @
8b435801
...
...
@@ -10,6 +10,74 @@ maxdb:
chat-url
:
http://192.168.0.122:8080/api/application/%s/chat/open
talk-url
:
http://192.168.0.122:8080/api/application/chat_message/%s
spring
:
redis
:
#数据库索引
database
:
9
host
:
120.24.176.53
port
:
6580
password
:
Hzzy891212
#连接超时时间
timeout
:
5000
datasource
:
druid
:
db-type
:
com.alibaba.druid.pool.DruidDataSource
driverClassName
:
net.sf.log4jdbc.sql.jdbcapi.DriverSpy
url
:
jdbc:log4jdbc:mysql://36.138.204.4:3306/chatgpt?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&rewriteBatchedStatements=true
username
:
chatgpt_rw
password
:
Chatgpt@20231211
# 初始连接数
initial-size
:
5
# 最小连接数
min-idle
:
10
# 最大连接数
max-active
:
20
# 获取连接超时时间
max-wait
:
5000
# 连接有效性检测时间
time-between-eviction-runs-millis
:
60000
# 连接在池中最小生存的时间
min-evictable-idle-time-millis
:
300000
# 连接在池中最大生存的时间
max-evictable-idle-time-millis
:
900000
test-while-idle
:
true
test-on-borrow
:
true
test-on-return
:
false
# 检测连接是否有效
validation-query
:
select 1
# 配置监控统计
webStatFilter
:
enabled
:
true
stat-view-servlet
:
enabled
:
true
url-pattern
:
/druid/*
reset-enable
:
false
filter
:
stat
:
enabled
:
true
# 记录慢SQL
log-slow-sql
:
true
slow-sql-millis
:
1000
merge-sql
:
true
wall
:
config
:
multi-statement-allow
:
true
jpa
:
properties
:
hibernate
:
ddl-auto
:
none
dialect
:
org.hibernate.dialect.MySQL5InnoDBDialect
open-in-view
:
true
mybatis-plus
:
check-config-location
:
true
configuration
:
map-underscore-to-camel-case
:
true
global-config
:
db-config
:
id-type
:
auto
logic-delete-value
:
1
logic-not-delete-value
:
0
mapper-locations
:
classpath:mapper/*.xml
server
:
port
:
8888
...
...
src/main/resources/log4jdbc.log4j2.properties
0 → 100644
View file @
8b435801
# If you use SLF4J. First, you need to tell log4jdbc-log4j2 that you want to use the SLF4J logger
log4jdbc.spylogdelegator.name
=
net.sf.log4jdbc.log.slf4j.Slf4jSpyLogDelegator
log4jdbc.auto.load.popular.drivers
=
false
log4jdbc.drivers
=
com.mysql.cj.jdbc.Driver
\ No newline at end of file
src/main/resources/logback.xml
0 → 100644
View file @
8b435801
<?xml version="1.0" encoding="UTF-8"?>
<configuration
scan=
"true"
scanPeriod=
"30 seconds"
debug=
"false"
>
<contextName>
btl-admin
</contextName>
<property
name=
"log.charset"
value=
"utf-8"
/>
<property
name=
"log.pattern"
value=
"%(%d{yyyy-MM-dd HH:mm:ss}) %(%-5level) - %(%msg%n)"
/>
<!--输出到控制台-->
<appender
name=
"console"
class=
"ch.qos.logback.core.ConsoleAppender"
>
<encoder>
<pattern>
${log.pattern}
</pattern>
<charset>
${log.charset}
</charset>
</encoder>
</appender>
<!--普通日志输出到控制台-->
<root
level=
"info"
>
<appender-ref
ref=
"console"
/>
</root>
<!--监控sql日志输出 -->
<logger
name=
"jdbc.sqlonly"
level=
"INFO"
additivity=
"false"
>
<appender-ref
ref=
"console"
/>
</logger>
<logger
name=
"jdbc.resultset"
level=
"ERROR"
additivity=
"false"
>
<appender-ref
ref=
"console"
/>
</logger>
<!-- 如想看到表格数据,将OFF改为INFO -->
<logger
name=
"jdbc.resultsettable"
level=
"OFF"
additivity=
"false"
>
<appender-ref
ref=
"console"
/>
</logger>
<logger
name=
"jdbc.connection"
level=
"OFF"
additivity=
"false"
>
<appender-ref
ref=
"console"
/>
</logger>
<logger
name=
"jdbc.sqltiming"
level=
"OFF"
additivity=
"false"
>
<appender-ref
ref=
"console"
/>
</logger>
<logger
name=
"jdbc.audit"
level=
"OFF"
additivity=
"false"
>
<appender-ref
ref=
"console"
/>
</logger>
</configuration>
\ No newline at end of file
src/main/resources/mapper/ChatgptRoleDescMapper.xml
0 → 100644
View file @
8b435801
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"admin.modules.chatgpt.service.mapper.ChatgptRoleDescMapper"
>
<!-- 通用查询结果列 -->
<!--
<sql id="Base_Column_List">
a.id, a.title, a.description, a.chat, a.image, a.role_id, a.sort_num, a.post_status, a.create_date, a.update_date, a.role_type_id, a.classify
</sql>
-->
</mapper>
src/main/resources/mapper/ChatgptRoleMapper.xml
0 → 100644
View file @
8b435801
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"admin.modules.chatgpt.service.mapper.ChatgptRoleMapper"
>
<!-- 通用查询结果列 -->
<!--
<sql id="Base_Column_List">
a.id, a.role_name, a.role_message, a.model, a.create_time, a.temperature, a.max_tokens, a.top_p, a.presence_penalty, a.frequency_penalty, a.n
</sql>
-->
</mapper>
src/main/resources/mapper/ChatgptRoleRecordsMapper.xml
0 → 100644
View file @
8b435801
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"admin.modules.chatgpt.service.mapper.ChatgptRoleRecordsMapper"
>
<!-- 通用查询结果列 -->
<!--
<sql id="Base_Column_List">
a.id, a.sender_id, a.receiver_id, a.message, a.create_time
</sql>
-->
<select
id=
"queryRoleSessionListPage"
resultType=
"admin.modules.chatgpt.domain.ChatgptRoleRecords"
>
select *
from (select *
from chatgpt_role_records
where sender_id = #{userId}
and receiver_id = #{roleDescId}
and session_id is null
union all
select *
from chatgpt_role_records
where sender_id = #{roleDescId}
and receiver_id = #{userId}
and session_id is null) as a
</select>
<select
id=
"findByTextCount"
resultType=
"Integer"
>
SELECT SUM(LENGTH(message))
FROM `chatgpt_role_records`
WHERE receiver_id = #{memberId} or sender_id = #{memberId}
</select>
<select
id=
"findBySessionCount"
resultType=
"Integer"
>
SELECT COUNT(DISTINCT session_id)
FROM `chatgpt_role_records`
WHERE (receiver_id = #{memberId} or sender_id = #{memberId})
AND session_id is not NULL
</select>
<select
id=
"findByDialogueCount"
resultType=
"Integer"
>
SELECT count(*)
FROM `chatgpt_role_records`
WHERE sender_id = #{memberId}
</select>
</mapper>
src/main/resources/mapper/ChatgptRoleSessionMapper.xml
0 → 100644
View file @
8b435801
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"admin.modules.chatgpt.service.mapper.ChatgptRoleSessionMapper"
>
<!-- 通用查询结果列 -->
<!--
<sql id="Base_Column_List">
a.id, a.name, a.role_desc_id, a.user_id, a.create_time
</sql>
-->
<update
id=
"updateUpdateTime"
>
update chatgpt_role_session set update_time = now() where id = #{id}
</update>
</mapper>
src/main/resources/mapper/ChatgptRoleTypeMapper.xml
0 → 100644
View file @
8b435801
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"admin.modules.chatgpt.service.mapper.ChatgptRoleTypeMapper"
>
<!-- 通用查询结果列 -->
<!--
<sql id="Base_Column_List">
a.id, a.role_type_name, a.sort_num
</sql>
-->
</mapper>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment