春松客服数据库表及管理 | 春松客服

1.对象关系映射(OR Mapping)

对象-关系映射(Object/Relation Mapping,简称ORM),是一种程序设计技术,用于实现面向对象编程语言里不同类型系统的数据之间的转换。面向对象的开发方法是当今企业级应用开发环境中的主流开发方法,关系数据库是企业级应用环境中永久存放数据的主流数据存储系统。对象和关系数据是业务实体的两种表现形式,业务实体在内存中表现为对象,在数据库中表现为关系数据。内存中的对象之间存在关联和继承关系,而在数据库中,关系数据无法直接表达多对多关联和继承关系。因此,对象-关系映射(ORM)系统一般以中间件的形式存在,主要实现程序对象到关系数据库数据的映射。

2.SQL表结构初始化

  • 初始化脚本
    contact-center/config/sql/cosinee-MySQL-slim.sql
    cosinee-MySQL-slim.sql文件主要用来创建数据库表和初始化数据。

    如果需要更方便的查看数据库,可以查看
    春松客服数据词典
  • 查看Hibernate数据库脚本执行
Properties: spring.jpa.show-sql=true 
OR
环境变量:SPRING_JPA_SHOW_SQL=true

3.源码导读

Blob:存储文件

spring data jpa 创建方法名进行查询

spring data jpa 可以通过在接口中按照规定语法创建一个方法进行查询,在项目中也使用这种方法。

支持的规范表达式

关键字 方法命名 sql where字句
And findByNameAndPwd where name= ? and pwd =?
Or findByNameOrSex where name= ? or sex=?
Is,Equals findById,findByIdEquals where id= ?
Between findByIdBetween where id between ? and ?
LessThan findByIdLessThan where id < ?
LessThanEqual findByIdLessThanEqual where id <= ?
GreaterThan findByIdGreaterThan where id > ?
GreaterThanEqual findByIdGreaterThanEqual where id > = ?
After findByIdAfter where id > ?
Before findByIdBefore where id < ?
IsNull findByNameIsNull where name is null
isNotNull,NotNull findByNameNotNull where name is not null
Like findByNameLike where name like ?
NotLike findByNameNotLike where name not like ?
StartingWith findByNameStartingWit where name like ‘?%’
EndingWith findByNameEndingWithwhere name like ‘%?’
Containing findByNameContainingwhere name like ‘%?%’
OrderBy findByIdOrderByXDesc where id=? order by x desc
Not findByNameNot where name <> ?
In findByIdIn(Collection<?> c) where id in (?)
NotIn findByIdNotIn(Collection<?> c) where id not in (?)
True findByAaaTue where aaa = true
False findByAaaFalse where aaa = false
IgnoreCase findByNameIgnoreCase where UPPER(name)=UPPER(?)

@Query注解的用法

@Query注解查询适用于所查询的数据无法通过关键字查询得到结果的查询。这种查询可以摆脱像关键字查询那样的约束,将查询直接在相应的接口方法中声明,结构更为清晰,这是Spring Data的特有实现。

  1. 一个使用@Query注解的简单例子
    @Query(value = "select c from Chatbot c")
    Page<Chatbot> findWithPagination(Pageable pageRequest);
  1. Like表达式
 @Query(value = "select u from ChatMessage u where u.usession = ?1 and u.message like %?2% and u.islabel = true")
    Page<ChatMessage> findByislabel(String usession, String message, Pageable page);
  1. 使用Native SQL Query(nativeQuery=true则使用原生SQL默认HQL)
    所谓本地查询,就是使用原生的sql语句(根据数据库的不同,在sql的语法或结构方面可能有所区别)进行查询数据库的操作。
@Query(value = "SELECT * FROM uk_agentuser WHERE userid = ?1 LIMIT 1", nativeQuery = true)
    AgentUser findOneByUserid(final String userid);
  1. 使用@Param注解注入参数
 @Query(value = "SELECT a FROM AgentUser a WHERE a.userid in(:userids)")
    List<AgentUser> findAllByUserids(@Param("userids") List<String> userids)

4. 延伸阅读

春松客服部署方案
春松客服数据词典
春松客服开发环境

开源智能客服系统

春松客服是 Chatopera 自主研发的,Apache2.0开源协议授权的智能客服系统,春松客服会不断增强客服系统的智能化,这包括利用自然语言处理、机器学习和语音识别等技术让客服工作更有效率、客服满意度更高、成本更低。

开源力量 社区共建

猜你喜欢

转载自blog.csdn.net/watson243671/article/details/105807088