dao.py 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. #!/usr/bin/env python3
  2. # encoding:utf-8
  3. import json
  4. from . import db
  5. from datetime import datetime
  6. class Bucket(db.Model):
  7. __tablename__ = 'c_bucket'
  8. __table_args__ = {
  9. 'comment': '流量分桶表',
  10. 'mysql_engine': 'InnoDB',
  11. 'mysql_charset': 'utf8mb4'
  12. }
  13. id = db.Column(db.BigInteger, primary_key=True, autoincrement=True, comment='主键')
  14. name = db.Column(db.String(32), nullable=False, default='', comment='名称')
  15. eid = db.Column(db.String(16), nullable=False, default='', comment='实验id')
  16. lower = db.Column(db.String(32), nullable=False, default='', comment='下限')
  17. upper = db.Column(db.String(64), nullable=False, default='', comment='上限')
  18. config = db.Column(db.String(100), nullable=False, default='', comment='拓展配置')
  19. update_time = db.Column(db.TIMESTAMP, nullable=False, default=datetime.now, onupdate=datetime.now, comment='更新时间')
  20. create_time = db.Column(db.TIMESTAMP, nullable=False, default=datetime.now, comment='创建时间' )
  21. __table_args__ = (
  22. db.Index('idx_eid', 'eid', mysql_using='BTREE'),
  23. )
  24. def __repr__(self):
  25. return json.dumps(self.to_dict())
  26. def to_dict(self):
  27. return {
  28. 'id': self.id,
  29. 'name': self.name,
  30. 'eid': self.eid,
  31. 'lower': self.lower,
  32. 'upper': self.upper,
  33. 'config': self.config,
  34. 'update_time': self.update_time.isoformat() if self.update_time else None,
  35. 'create_time': self.create_time.isoformat() if self.create_time else None,
  36. }
  37. class Agent(db.Model):
  38. __tablename__ = 'c_agent'
  39. __table_args__ = {
  40. 'comment': '坐席信息表',
  41. 'mysql_engine': 'InnoDB',
  42. 'mysql_charset': 'utf8mb4'
  43. }
  44. id = db.Column(db.BigInteger, primary_key=True, autoincrement=True, comment='主键')
  45. saas_id = db.Column(db.String(16), nullable=False, default='', comment='租户隔离')
  46. agent_num = db.Column(db.String(32), nullable=False, default='', comment='坐席工号')
  47. agent_name = db.Column(db.String(32), nullable=False, default='', comment='坐席姓名')
  48. out_id = db.Column(db.String(32), nullable=False, default='', comment='外部id')
  49. agent_pwd = db.Column(db.String(64), nullable=False, default='', comment='坐席密码')
  50. agent_type = db.Column(db.SmallInteger, nullable=False, default=0, comment='坐席类型 0:普通坐席; 1:组长; 2:主管')
  51. phone_num = db.Column(db.String(32), nullable=False, default='0', comment='分机号')
  52. distribute = db.Column(db.SmallInteger, nullable=False, default=1, comment='分配标志 0:不参与排队; 1:参与排队')
  53. agent_state = db.Column(db.SmallInteger, nullable=False, default=0, comment='账号状态 0:可用; 1:禁用')
  54. identity_type = db.Column(db.SmallInteger, nullable=False, default=0, comment='身份标识')
  55. is_delete = db.Column(db.SmallInteger, nullable=False, default=0, comment='删除标识')
  56. update_time = db.Column(db.TIMESTAMP, nullable=False, default=datetime.now, onupdate=datetime.now, comment='更新时间')
  57. create_time = db.Column(db.TIMESTAMP, nullable=False, default=datetime.now, comment='创建时间')
  58. user_id= db.Column(db.BigInteger, nullable=False, default='', comment='用户id')
  59. __table_args__ = (
  60. db.UniqueConstraint('saas_id', 'agent_num', name='uniq_vcc_id_agent_num'),
  61. db.Index('idx_saas_id_out_id', 'saas_id', 'out_id'),
  62. db.Index('idx_saas_id_phone_num', 'saas_id', 'phone_num')
  63. )
  64. def __repr__(self):
  65. return json.dumps(self.to_dict())
  66. def to_dict(self):
  67. return {
  68. 'id': self.id,
  69. 'saas_id': self.saas_id,
  70. 'agent_num': self.agent_num,
  71. 'agent_name': self.agent_name,
  72. 'out_id': self.out_id,
  73. 'agent_pwd': self.agent_pwd,
  74. 'agent_type': self.agent_type,
  75. 'phone_num': self.phone_num,
  76. 'distribute': self.distribute,
  77. 'agent_state': self.agent_state,
  78. 'identity_type': self.identity_type,
  79. 'is_delete': self.is_delete,
  80. 'update_time': self.update_time.isoformat() if self.update_time else None,
  81. 'create_time': self.create_time.isoformat() if self.create_time else None,
  82. 'user_id': self.user_id
  83. }
  84. class AgentActionLog(db.Model):
  85. __tablename__ = 'c_agent_action_log'
  86. __table_args__ = {
  87. 'comment': '坐席行为日志表',
  88. 'mysql_engine': 'InnoDB',
  89. 'mysql_charset': 'utf8mb4'
  90. }
  91. id = db.Column(db.BigInteger, primary_key=True, autoincrement=True, comment='主键')
  92. saas_id = db.Column(db.String(16), nullable=False, default='', comment='租户隔离')
  93. agent_num = db.Column(db.String(32), nullable=False, default='', comment='坐席工号')
  94. out_id = db.Column(db.String(32), nullable=False, default='', comment='外部id')
  95. action_type = db.Column(db.SmallInteger, nullable=False, default=0, comment='行为类型')
  96. check_state = db.Column(db.SmallInteger, nullable=False, default=-1, comment='签入或签出')
  97. pre_check_state = db.Column(db.SmallInteger, nullable=False, default=-1, comment='上一次签入或签出')
  98. service_state = db.Column(db.SmallInteger, nullable=False, default=-1, comment='坐席状态')
  99. pre_service_state = db.Column(db.SmallInteger, nullable=False, default=-1, comment='上一次坐席状态')
  100. check_state_time = db.Column(db.TIMESTAMP, nullable=False, default=datetime.now, comment='签入或签出时间')
  101. pre_check_state_time = db.Column(db.TIMESTAMP, nullable=False, default=datetime.now, comment='上一次签入或签出时间')
  102. service_state_time = db.Column(db.TIMESTAMP, nullable=False, default=datetime.now, comment='坐席状态变更时间')
  103. pre_service_state_time = db.Column(db.TIMESTAMP, nullable=False, default=datetime.now, comment='上一次坐席状态变更时间')
  104. check_state_duration = db.Column(db.BigInteger, nullable=False, default=0, comment='行为持续时间')
  105. service_state_duration = db.Column(db.BigInteger, nullable=False, default=0, comment='状态持续时间')
  106. task_id = db.Column(db.String(32), nullable=False, default='', comment='任务Id')
  107. service_id = db.Column(db.String(32), nullable=False, default='', comment='人工组id')
  108. event_type = db.Column(db.Integer, nullable=False, default=0, comment='日志事件类型')
  109. event_desc = db.Column(db.String(100), nullable=False, default='', comment='日志事件描述')
  110. is_delete = db.Column(db.SmallInteger, nullable=False, default=0, comment='删除标识')
  111. update_time = db.Column(db.TIMESTAMP, nullable=False, default=datetime.now, onupdate=datetime.now, comment='更新时间')
  112. create_time = db.Column(db.TIMESTAMP, nullable=False, default=datetime.now, comment='创建时间')
  113. __table_args__ = (
  114. db.Index('idx_create_time', 'create_time'),
  115. db.Index('idx_saas_id_agent_num', 'saas_id', 'agent_num'),
  116. db.Index('idx_saas_id_out_id', 'saas_id', 'out_id'),
  117. db.Index('idx_saas_id_task_id', 'saas_id', 'task_id'),
  118. db.Index('idx_update_time', 'update_time'),
  119. )
  120. def __repr__(self):
  121. return json.dumps(self.to_dict())
  122. def to_dict(self):
  123. return {
  124. 'id': self.id,
  125. 'saas_id': self.saas_id,
  126. 'agent_num': self.agent_num,
  127. 'out_id': self.out_id,
  128. 'action_type': self.action_type,
  129. 'check_state': self.check_state,
  130. 'pre_check_state': self.pre_check_state,
  131. 'service_state': self.service_state,
  132. 'pre_service_state': self.pre_service_state,
  133. 'check_state_time': self.check_state_time.isoformat() if self.check_state_time else None,
  134. 'pre_check_state_time': self.pre_check_state_time.isoformat() if self.pre_check_state_time else None,
  135. 'service_state_time': self.service_state_time.isoformat() if self.service_state_time else None,
  136. 'pre_service_state_time': self.pre_service_state_time.isoformat() if self.pre_service_state_time else None,
  137. 'check_state_duration': self.check_state_duration,
  138. 'service_state_duration': self.service_state_duration,
  139. 'task_id': self.task_id,
  140. 'service_id': self.service_id,
  141. 'event_type': self.event_type,
  142. 'event_desc': self.event_desc,
  143. 'is_delete': self.is_delete,
  144. 'update_time': self.update_time.isoformat() if self.update_time else None,
  145. 'create_time': self.create_time.isoformat() if self.create_time else None,
  146. }
  147. class AgentLog(db.Model):
  148. __tablename__ = 'c_agent_log'
  149. __table_args__ = {
  150. 'comment': '坐席日志表',
  151. 'mysql_engine': 'InnoDB',
  152. 'mysql_charset': 'utf8mb4'
  153. }
  154. id = db.Column(db.BigInteger, primary_key=True, autoincrement=True, comment='主键')
  155. saas_id = db.Column(db.String(16), nullable=False, default='', comment='租户隔离')
  156. flow_id = db.Column(db.String(64), nullable=False, default='', comment='人工外呼流程ID')
  157. agent_num = db.Column(db.String(32), nullable=False, default='', comment='坐席工号')
  158. out_id = db.Column(db.String(32), nullable=False, default='', comment='外部id')
  159. event_type = db.Column(db.SmallInteger, nullable=False, default=0, comment='事件类型')
  160. event = db.Column(db.String(32), nullable=False, default='0', comment='事件')
  161. content = db.Column(db.String(64), nullable=False, default='', comment='描述')
  162. is_delete = db.Column(db.SmallInteger, nullable=False, default=0, comment='删除标识')
  163. update_time = db.Column(db.TIMESTAMP, nullable=False, default=datetime.now, onupdate=datetime.now, comment='更新时间')
  164. create_time = db.Column(db.TIMESTAMP, nullable=False, default=datetime.now, comment='创建时间')
  165. __table_args__ = (
  166. db.Index('idx_saas_id_agent_num', 'saas_id', 'agent_num'),
  167. db.Index('idx_saas_id_out_id', 'saas_id', 'out_id')
  168. )
  169. def __repr__(self):
  170. return json.dumps(self.to_dict())
  171. def to_dict(self):
  172. return {
  173. 'id': self.id,
  174. 'saas_id': self.saas_id,
  175. 'flow_id': self.flow_id,
  176. 'agent_num': self.agent_num,
  177. 'out_id': self.out_id,
  178. 'event_type': self.event_type,
  179. 'event': self.event,
  180. 'content': self.content,
  181. 'is_delete': self.is_delete,
  182. 'update_time': self.update_time.isoformat() if self.update_time else None,
  183. 'create_time': self.create_time.isoformat() if self.create_time else None,
  184. }
  185. class AgentMonitor(db.Model):
  186. __tablename__ = 'c_agent_monitor'
  187. __table_args__ = {
  188. 'comment': '坐席监控表',
  189. 'mysql_engine': 'InnoDB',
  190. 'mysql_charset': 'utf8mb4'
  191. }
  192. id = db.Column(db.BigInteger, primary_key=True, autoincrement=True, comment='主键')
  193. saas_id = db.Column(db.String(16), nullable=False, default='', comment='租户隔离')
  194. agent_num = db.Column(db.String(32), nullable=False, default='', comment='坐席工号')
  195. out_id = db.Column(db.String(32), nullable=False, default='', comment='外部id')
  196. identity_type = db.Column(db.SmallInteger, nullable=False, default=0, comment='身份标识')
  197. check_state = db.Column(db.SmallInteger, nullable=False, default=1, comment='是否签入 0:是 1:否 默认未签入')
  198. check_scene = db.Column(db.String(16), nullable=False, default='', comment='迁入场景')
  199. check_in_time = db.Column(db.TIMESTAMP, nullable=False, default=datetime.now, comment='签入时间')
  200. check_out_time = db.Column(db.TIMESTAMP, nullable=False, default=datetime.now, comment='签出时间')
  201. service_state = db.Column(db.SmallInteger, nullable=False, default=0, comment='坐席服务状态 0: 未登录(签出) 1: 置忙 2: 置闲 3: 通话中 4: 后处理 5: 拨号中')
  202. busy_time = db.Column(db.TIMESTAMP, nullable=False, default=datetime.now, comment='置忙时间')
  203. idle_time = db.Column(db.TIMESTAMP, nullable=False, default=datetime.now, comment='置闲时间')
  204. call_time = db.Column(db.TIMESTAMP, nullable=False, default=datetime.now, comment='接通时间')
  205. hang_time = db.Column(db.TIMESTAMP, nullable=False, default=datetime.now, comment='挂断时间')
  206. heart_state = db.Column(db.SmallInteger, nullable=False, default=0, comment='心跳状态 0: 默认 1:正常 2: 异常')
  207. heart_time = db.Column(db.TIMESTAMP, nullable=False, default=datetime.now, comment='正常心跳时间')
  208. session_id = db.Column(db.String(64), nullable=False, default='', comment='sessionId')
  209. is_delete = db.Column(db.SmallInteger, nullable=False, default=0, comment='删除标识')
  210. update_time = db.Column(db.TIMESTAMP, nullable=False, default=datetime.now, onupdate=datetime.now, comment='更新时间')
  211. create_time = db.Column(db.TIMESTAMP, nullable=False, default=datetime.now, comment='创建时间')
  212. __table_args__ = (
  213. db.UniqueConstraint('saas_id', 'agent_num', name='uniq_saas_id_agent_num'),
  214. db.Index('idx_saas_id_out_id', 'saas_id', 'out_id')
  215. )
  216. def __repr__(self):
  217. return json.dumps(self.to_dict())
  218. def to_dict(self):
  219. return {
  220. 'id': self.id,
  221. 'saas_id': self.saas_id,
  222. 'agent_num': self.agent_num,
  223. 'out_id': self.out_id,
  224. 'identity_type': self.identity_type,
  225. 'check_state': self.check_state,
  226. 'check_scene': self.check_scene,
  227. 'check_in_time': self.check_in_time.isoformat() if self.check_in_time else None,
  228. 'check_out_time': self.check_out_time.isoformat() if self.check_out_time else None,
  229. 'service_state': self.service_state,
  230. 'busy_time': self.busy_time.isoformat() if self.busy_time else None,
  231. 'idle_time': self.idle_time.isoformat() if self.idle_time else None,
  232. 'call_time': self.call_time.isoformat() if self.call_time else None,
  233. 'hang_time': self.hang_time.isoformat() if self.hang_time else None,
  234. 'heart_state': self.heart_state,
  235. 'heart_time': self.heart_time.isoformat() if self.heart_time else None,
  236. 'session_id': self.session_id,
  237. 'is_delete': self.is_delete,
  238. 'update_time': self.update_time.isoformat() if self.update_time else None,
  239. 'create_time': self.create_time.isoformat() if self.create_time else None,
  240. }
  241. class Phone(db.Model):
  242. __tablename__ = 'c_phone'
  243. __table_args__ = {
  244. 'comment': '分机信息表',
  245. 'mysql_engine': 'InnoDB',
  246. 'mysql_charset': 'utf8mb4'
  247. }
  248. id = db.Column(db.BigInteger, primary_key=True, autoincrement=True, comment='主键')
  249. saas_id = db.Column(db.String(16), nullable=False, default='', comment='租户隔离')
  250. phone_num = db.Column(db.String(32), nullable=False, default='0', comment='分机号')
  251. phone_pwd = db.Column(db.String(32), nullable=False, default='', comment='分机密码')
  252. sip_server = db.Column(db.String(64), nullable=False, default='', comment='SIP服务器')
  253. wss_server = db.Column(db.String(64), nullable=False, default='', comment='WSS服务器')
  254. ice_server = db.Column(db.String(64), nullable=False, default='', comment='ICE服务器')
  255. is_delete = db.Column(db.SmallInteger, nullable=False, default=0, comment='删除标识')
  256. update_time = db.Column(db.TIMESTAMP, nullable=False, default=datetime.now, onupdate=datetime.now, comment='更新时间')
  257. create_time = db.Column(db.TIMESTAMP, nullable=False, default=datetime.now, comment='创建时间')
  258. __table_args__ = (
  259. db.Index('idx_vcc_id_phone_num', 'saas_id', 'phone_num'),
  260. )
  261. def __repr__(self):
  262. return json.dumps(self.to_dict())
  263. def to_dict(self):
  264. return {
  265. 'id': self.id,
  266. 'saas_id': self.saas_id,
  267. 'phone_num': self.phone_num,
  268. 'phone_pwd': self.phone_pwd,
  269. 'sip_server': self.sip_server,
  270. 'wss_server': self.wss_server,
  271. 'ice_server': self.ice_server,
  272. 'is_delete': self.is_delete,
  273. 'update_time': self.update_time.isoformat() if self.update_time else None,
  274. 'create_time': self.create_time.isoformat() if self.create_time else None,
  275. }
  276. class HumanService(db.Model):
  277. __tablename__ = 'c_human_service'
  278. __table_args__ = {'comment': '人工服务组信息'}
  279. id = db.Column(db.BigInteger, primary_key=True, autoincrement=True, comment='主键')
  280. saas_id = db.Column(db.String(16), nullable=False, default='', comment='租户隔离')
  281. service_id = db.Column(db.String(32), nullable=False, default='', comment='人工组编号')
  282. service_name = db.Column(db.String(32), nullable=False, default='', comment='人工组名称')
  283. schedule_key = db.Column(db.String(32), nullable=False, default='', comment='日程编号')
  284. effective = db.Column(db.String(32), nullable=False, default='0', comment='状态 0:启用(可以或正在进行外呼)1:暂停')
  285. service_start = db.Column(db.String(32), nullable=False, default='', comment='任务开始时间 yyyyMMddHHmmss')
  286. service_end = db.Column(db.String(32), nullable=False, default='22200101000000', comment='任务结束时间 yyyyMMddHHmmss')
  287. distribute = db.Column(db.String(32), nullable=False, default='3', comment='分配策略')
  288. call_in_limit = db.Column(db.String(32), nullable=False, default='0', comment='呼入线数 限制 固定值0')
  289. record_type = db.Column(db.String(32), nullable=False, default='1', comment='录音方式 默认0 0:服务器不录 1:服务器录 4:按间隔抽样录 5:按百分比抽样录 固定值 1')
  290. queue_length = db.Column(db.String(32), nullable=False, default='100', comment='排队长度 固定值 100')
  291. queue_warning = db.Column(db.String(32), nullable=False, default='100', comment='排队告警 长度 固定值 100')
  292. queue_timeout = db.Column(db.String(32), nullable=False, default='60', comment='排队超时 时间 固定值 60')
  293. sum_queue_time = db.Column(db.String(32), nullable=False, default='90', comment='所有排队 时间 单位:秒;默认300: 固定值 90')
  294. connect_type = db.Column(db.String(32), nullable=False, default='0', comment='连接坐席 类型 默认0 0盲转连接 1桥接连接并超时重排 固定值 0')
  295. queue_music = db.Column(db.String(32), nullable=False, default='', comment='排队音 全局配置')
  296. direct_queue_type = db.Column(db.String(32), nullable=False, default='', comment='直接连接 媒体类型 默认1 接入码直接转人工服务能听到排队音 0:直接排队不连接媒体; 1:直接排队连接媒体 全局配置')
  297. is_delete = db.Column(db.Boolean, nullable=False, default=False, comment='删除标识')
  298. update_time = db.Column(db.TIMESTAMP, nullable=False, default=datetime.now, onupdate=datetime.now, comment='更新时间')
  299. create_time = db.Column(db.TIMESTAMP, nullable=False, default=datetime.now, comment='创建时间')
  300. # Indexes
  301. __table_args__ = (
  302. db.Index('idx_create_time', 'create_time'),
  303. db.Index('idx_update_time', 'update_time'),
  304. db.Index('idx_saas_id_service_id', 'saas_id', 'service_id'),
  305. )
  306. def to_dict(self):
  307. return {
  308. 'id': self.id,
  309. 'saas_id': self.saas_id,
  310. 'service_id': self.service_id,
  311. 'service_name': self.service_name,
  312. 'schedule_key': self.schedule_key,
  313. 'effective': self.effective,
  314. 'service_start': self.service_start,
  315. 'service_end': self.service_end,
  316. 'distribute': self.distribute,
  317. 'call_in_limit': self.call_in_limit,
  318. 'record_type': self.record_type,
  319. 'queue_length': self.queue_length,
  320. 'queue_warning': self.queue_warning,
  321. 'queue_timeout': self.queue_timeout,
  322. 'sum_queue_time': self.sum_queue_time,
  323. 'connect_type': self.connect_type,
  324. 'queue_music': self.queue_music,
  325. 'direct_queue_type': self.direct_queue_type,
  326. 'is_delete': self.is_delete,
  327. 'update_time': self.update_time.isoformat() if self.update_time else None,
  328. 'create_time': self.create_time.isoformat() if self.create_time else None,
  329. }
  330. class HumanServiceMap(db.Model):
  331. __tablename__ = 'c_human_service_map'
  332. __table_args__ = {'comment': '人工服务组与坐席关系'}
  333. id = db.Column(db.BigInteger, primary_key=True, autoincrement=True, comment='主键')
  334. saas_id = db.Column(db.String(16), nullable=False, default='', comment='租户隔离')
  335. service_id = db.Column(db.String(32), nullable=False, default='', comment='人工组编号')
  336. service_type = db.Column(db.String(32), nullable=False, default='0', comment='服务类型')
  337. agent_id = db.Column(db.String(32), nullable=False, default='', comment='坐席工号')
  338. state = db.Column(db.Boolean, nullable=False, default=0, comment='状态 1激活(签入)')
  339. is_delete = db.Column(db.Boolean, nullable=False, default=0, comment='删除标识')
  340. update_time = db.Column(db.TIMESTAMP, nullable=False, default=datetime.now, onupdate=datetime.now, comment='更新时间')
  341. create_time = db.Column(db.TIMESTAMP, nullable=False, default=datetime.now, comment='创建时间')
  342. # Indexes
  343. __table_args__ = (
  344. db.Index('idx_create_time', 'create_time'),
  345. db.Index('idx_update_time', 'update_time'),
  346. db.Index('idx_saas_id_service_id_agent_id', 'saas_id', 'service_id', 'agent_id'),
  347. )
  348. def to_dict(self):
  349. return {
  350. 'id': self.id,
  351. 'saas_id': self.vcc_id,
  352. 'service_id': self.service_id,
  353. 'service_type': self.service_type,
  354. 'agent_id': self.agent_id,
  355. 'state': self.state,
  356. 'is_delete': self.is_delete,
  357. 'update_time': self.update_time.isoformat() if self.update_time else None,
  358. 'create_time': self.create_time.isoformat() if self.create_time else None,
  359. }
  360. class Whitelist(db.Model):
  361. __tablename__ = 't_whitelist'
  362. __table_args__ = {'comment': '白名单配置表'}
  363. id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='主键')
  364. phone = db.Column(db.String(20), nullable=False, comment='电话号码')
  365. description = db.Column(db.String(255), nullable=True, comment='描述说明(备注)')
  366. type = db.Column(db.SmallInteger, nullable=False, default='0', comment='类型(0人工白名单 1机器人白名单)')
  367. del_flag = db.Column(db.SmallInteger, nullable=False, default=False, comment='删除标志(0代表存在 2代表删除)')
  368. revision = db.Column(db.Integer, nullable=True, comment='乐观锁')
  369. create_by = db.Column(db.String(32), nullable=True, comment='创建人')
  370. create_time = db.Column(db.DateTime, nullable=True, default=datetime.now, comment='创建时间')
  371. update_by = db.Column(db.String(32), nullable=True, comment='更新人')
  372. update_time = db.Column(db.DateTime, nullable=True, onupdate=datetime.now, comment='更新时间')
  373. remark = db.Column(db.String(500), nullable=True, comment='备注')
  374. def to_dict(self):
  375. return {
  376. 'id': self.id,
  377. 'phone': self.phone,
  378. 'description': self.description,
  379. 'type': self.type,
  380. 'del_flag': self.del_flag,
  381. 'revision': self.revision,
  382. 'create_by': self.create_by,
  383. 'create_time': self.create_time.isoformat() if self.create_time else None,
  384. 'update_by': self.update_by,
  385. 'update_time': self.update_time.isoformat() if self.update_time else None,
  386. 'remark': self.remark,
  387. }
  388. class CallRecord(db.Model):
  389. __tablename__ = 't_call_record'
  390. __table_args__ = {'comment': '通话记录表'}
  391. id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='主键')
  392. session_id = db.Column(db.String(30), nullable=True, comment='sessionId')
  393. type = db.Column(db.SmallInteger, nullable=True,comment='呼入分类(0白名单 1AI服务 2传统服务)')
  394. user_id = db.Column(db.BigInteger, nullable=True, comment='客服ID')
  395. user_name = db.Column(db.String(255), nullable=True, comment='客服名字')
  396. service_category = db.Column(db.SmallInteger, nullable=False,default=0, comment='服务类型(0人工坐席 1机器人坐席 2机器人转人工)')
  397. time_begin = db.Column(db.DateTime, nullable=True, comment='通话发起时间')
  398. time_end = db.Column(db.DateTime, nullable=True, comment='通话结束时间')
  399. times = db.Column(db.String(30), nullable=True, comment='通话时长(暂时按字符串接收)')
  400. category = db.Column(db.SmallInteger, nullable=True, comment='通话类型(0呼入 1呼出)')
  401. status = db.Column(db.SmallInteger, nullable=True, comment='通话状态(0未接听 1已接通)')
  402. sip_status = db.Column(db.String(32), nullable=True, comment='sip码')
  403. sip_hangup_cause = db.Column(db.String(32), nullable=True, comment='sip挂机描述')
  404. hangup_dir = db.Column(db.SmallInteger, nullable=True, comment='挂机方向:1 主叫 2 被叫 3 机器人')
  405. hangup_reason = db.Column(db.String(255), nullable=True, comment='挂机原因')
  406. phone = db.Column(db.String(20), nullable=True, comment='电话号码')
  407. bussiness_type = db.Column(db.String(50), nullable=True, comment='业务类型(创个返回字符串)')
  408. url = db.Column(db.String(255), nullable=True, comment='录音的地址')
  409. remark = db.Column(db.String(500), nullable=True, comment='备注')
  410. has_parsed = db.Column(db.SmallInteger, nullable=False, default=0, comment='是否已转录音(0否 1是)')
  411. parsed_voice_content = db.Column(db.Text, nullable=True, comment='通话录音内容')
  412. del_flag = db.Column(db.SmallInteger, nullable=False, default=0, comment='删除标志(0代表存在 2代表删除)')
  413. revision = db.Column(db.Integer, nullable=True, comment='乐观锁')
  414. create_by = db.Column(db.String(32), nullable=True, default="admin", comment='创建人')
  415. create_time = db.Column(db.DateTime, nullable=True, default=datetime.now, comment='创建时间')
  416. update_by = db.Column(db.String(32), nullable=True, default="admin", comment='更新人')
  417. update_time = db.Column(db.DateTime, nullable=True, onupdate=datetime.now, comment='更新时间')
  418. transfer_user_id = db.Column(db.BigInteger, nullable=True, comment='转接客服ID')
  419. transfer_user_name = db.Column(db.String(255), nullable=True, comment='转接客服名字')
  420. def __repr__(self):
  421. return json.dumps(self.to_dict())
  422. def to_dict(self):
  423. return {
  424. 'id': self.id,
  425. 'session_id': self.session_id,
  426. 'type': self.type,
  427. 'user_id': self.user_id,
  428. 'user_name': self.user_name,
  429. 'service_category': self.service_category,
  430. 'time_begin': self.time_begin.isoformat() if self.time_begin else None,
  431. 'time_end': self.time_end.isoformat() if self.time_end else None,
  432. 'times': self.times,
  433. 'category': self.category,
  434. 'status': self.status,
  435. 'phone': self.phone,
  436. 'bussiness_type': self.bussiness_type,
  437. 'url': self.url,
  438. 'remark': self.remark,
  439. 'has_parsed': self.has_parsed,
  440. 'parsed_voice_content': self.parsed_voice_content,
  441. 'del_flag': self.del_flag,
  442. 'revision': self.revision,
  443. 'create_by': self.create_by,
  444. 'create_time': self.create_time.isoformat() if self.create_time else None,
  445. 'update_by': self.update_by,
  446. 'update_time': self.update_time.isoformat() if self.update_time else None,
  447. 'transfer_user_id': self.transfer_user_id,
  448. 'transfer_user_name': self.transfer_user_name,
  449. }
  450. class BotRecords(db.Model):
  451. __tablename__ = 'botrecords'
  452. __table_args__ = {'comment': '记录机器人会话信息'}
  453. id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='主键')
  454. session = db.Column(db.String(50), nullable=False, unique=True, comment='请求ID')
  455. req_time = db.Column(db.DateTime, nullable=True, comment='来电时间')
  456. uid = db.Column(db.String(20), nullable=True, comment='来电手机号')
  457. bid = db.Column(db.String(20), nullable=True, comment='话术ID')
  458. intent = db.Column(db.String(20), nullable=True, comment='意图')
  459. contents = db.Column(db.Text, nullable=True, comment='内容')
  460. dialog = db.Column(db.Text, nullable=True, comment='对话')
  461. def __repr__(self):
  462. return json.dumps(self.to_dict())
  463. def to_dict(self):
  464. return {
  465. 'id': self.id,
  466. 'session': self.session,
  467. 'req_time': self.req_time.isoformat() if self.req_time else None,
  468. 'uid': self.uid,
  469. 'bid': self.bid,
  470. 'intent': self.intent,
  471. 'contents': self.contents,
  472. 'dialog': self.dialog,
  473. }
  474. class WarningRecord(db.Model):
  475. __tablename__ = 't_warning_record'
  476. __table_args__ = {'comment': '告警记录表'}
  477. id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='主键')
  478. type = db.Column(db.SmallInteger, nullable=True, comment='类型(0:连续5个未接 1:10分钟空岗报警 2:连续3个5s内挂断)')
  479. desc = db.Column(db.String(500), nullable=True, comment='报警描述')
  480. read = db.Column(db.SmallInteger, nullable=False, default=0, comment='是否已读(0否 1是)')
  481. del_flag = db.Column(db.SmallInteger, nullable=False, default=0, comment='删除标志(0代表存在 2代表删除)')
  482. revision = db.Column(db.Integer, nullable=True, comment='乐观锁')
  483. create_by = db.Column(db.String(100), nullable=True, comment='创建人')
  484. create_time = db.Column(db.DateTime, nullable=True, comment='创建时间')
  485. update_by = db.Column(db.String(100), nullable=True, comment='更新人')
  486. update_time = db.Column(db.DateTime, nullable=True, comment='更新时间')
  487. remark = db.Column(db.String(500), nullable=True, comment='备注')
  488. def __repr__(self):
  489. return json.dumps(self.to_dict())
  490. def to_dict(self):
  491. return {
  492. 'id': self.id,
  493. 'type': self.type,
  494. 'desc': self.desc,
  495. 'read': self.read,
  496. 'del_flag': self.del_flag,
  497. 'revision': self.revision,
  498. 'create_by': self.create_by,
  499. 'create_time': self.create_time.isoformat() if self.create_time else None,
  500. 'update_by': self.update_by,
  501. 'update_time': self.update_time.isoformat() if self.update_time else None,
  502. 'remark': self.remark,
  503. }