|
|
@@ -35,6 +35,9 @@ class Mcp {
|
|
|
|
|
|
async bind_account({ sender, bind_code }) {
|
|
|
try {
|
|
|
+ if ([sender, bind_code].some(value => value === '' || value === null || value === undefined))
|
|
|
+ return '缺少参数'
|
|
|
+
|
|
|
this.logger.info(`MCP接收绑定账号请求:${sender},绑定码:${bind_code}`)
|
|
|
let sql = `
|
|
|
SELECT
|
|
|
@@ -55,7 +58,7 @@ class Mcp {
|
|
|
if (rows[0].bot_account !== sender) return '该账号已被他人绑定,请联系客服解绑'
|
|
|
return '该账号您已绑定'
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
let insertSql = `
|
|
|
UPDATE lepao_extra SET bot_account = ? WHERE bind_code = ?
|
|
|
`
|
|
|
@@ -71,6 +74,9 @@ class Mcp {
|
|
|
|
|
|
async get_account_info({ sender }) {
|
|
|
try {
|
|
|
+ if ([sender].some(value => value === '' || value === null || value === undefined))
|
|
|
+ return '缺少参数'
|
|
|
+
|
|
|
this.logger.info(`MCP接收获取账号信息请求:${sender}`)
|
|
|
let sql = `
|
|
|
SELECT
|
|
|
@@ -120,6 +126,7 @@ class Mcp {
|
|
|
if (data.grade_id) returnMsg += `年级:${data.grade_id}级;`
|
|
|
if (data.target_count) returnMsg += `目标乐跑次数:${data.target_count};`
|
|
|
if (data.total_num) returnMsg += `累计乐跑次数:${data.total_num};`
|
|
|
+ if (data.notice_type) returnMsg += `通知方式:${data.notice_type};`
|
|
|
|
|
|
return returnMsg
|
|
|
} catch (error) {
|
|
|
@@ -130,6 +137,9 @@ class Mcp {
|
|
|
|
|
|
async unbind_account({ sender }) {
|
|
|
try {
|
|
|
+ if ([sender].some(value => value === '' || value === null || value === undefined))
|
|
|
+ return '缺少参数'
|
|
|
+
|
|
|
this.logger.info(`MCP接收解绑账号请求:${sender}`)
|
|
|
let insertSql = `
|
|
|
UPDATE lepao_extra SET bot_account = NULL, bot_umo = NULL WHERE bot_account = ?
|
|
|
@@ -146,6 +156,9 @@ class Mcp {
|
|
|
|
|
|
async change_email({ sender, email }) {
|
|
|
try {
|
|
|
+ if ([sender, email].some(value => value === '' || value === null || value === undefined))
|
|
|
+ return '缺少参数'
|
|
|
+
|
|
|
this.logger.info(`MCP接收更换邮箱请求:${sender}`)
|
|
|
|
|
|
if (!this.emailRegex.test(email))
|
|
|
@@ -180,6 +193,9 @@ class Mcp {
|
|
|
|
|
|
async set_notification({ sender, mode }) {
|
|
|
try {
|
|
|
+ if ([sender, mode].some(value => value === '' || value === null || value === undefined))
|
|
|
+ return '缺少参数'
|
|
|
+
|
|
|
this.logger.info(`MCP接收设置通知请求:${sender},mode:${mode}`)
|
|
|
if (mode !== 'email' && mode !== 'bot' && mode !== 'none') return '通知type不合法,仅支持 email, bot, none三种模式'
|
|
|
|
|
|
@@ -205,7 +221,66 @@ class Mcp {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ async create_work_order({ sender, email, title, content }) {
|
|
|
+ try {
|
|
|
+ if ([sender, email, title, content].some(value => value === '' || value === null || value === undefined))
|
|
|
+ return '缺少参数'
|
|
|
+
|
|
|
+ this.logger.info(`MCP接收工单创建请求:${sender},Email:${email}`)
|
|
|
+ if (!this.emailRegex.test(email))
|
|
|
+ return '请检查邮箱格式是否正确'
|
|
|
+
|
|
|
+ const emailDomain = email.split('@')[1].toLowerCase()
|
|
|
+ if (this.banEmailList.includes(emailDomain))
|
|
|
+ return `暂不支持使用 ${emailDomain} 域名的邮箱,请更换其他邮箱后重试`
|
|
|
+
|
|
|
+ let selectSql = `
|
|
|
+ SELECT
|
|
|
+ l.create_user
|
|
|
+ FROM
|
|
|
+ lepao_account l
|
|
|
+ LEFT JOIN
|
|
|
+ lepao_extra e
|
|
|
+ ON
|
|
|
+ l.student_num = e.student_num
|
|
|
+ WHERE
|
|
|
+ e.bot_account = ?
|
|
|
+ `
|
|
|
+
|
|
|
+ let selectRows = await db.query(selectSql, [sender])
|
|
|
+ if (!selectRows || selectRows.length === 0) return '您还未绑定乐跑账号哦~请绑定后再试'
|
|
|
+
|
|
|
+ const time = new Date().getTime()
|
|
|
+ const uuid = selectRows[0].create_user
|
|
|
+
|
|
|
+ let msg = []
|
|
|
+ let message = {
|
|
|
+ time,
|
|
|
+ content,
|
|
|
+ files: [],
|
|
|
+ uuid,
|
|
|
+ type: 'user'
|
|
|
+ }
|
|
|
+ msg.push(message)
|
|
|
+ const systemMsg = {
|
|
|
+ time,
|
|
|
+ content: `该问题由用户${sender}通过智能小妍提交~我们会尽快处理,请耐心等待`,
|
|
|
+ uuid: 'e4fe0277-0b1a-41a1-b25f-8b6e4cec3281',
|
|
|
+ type: 'system'
|
|
|
+ }
|
|
|
+ msg.push(systemMsg)
|
|
|
+ let sql = 'INSERT INTO work_order (title, email, msg, create_user, create_time, update_time) VALUES (?, ?, ?, ?, ?, ?)'
|
|
|
+ let r = await db.query(sql, [title, email, msg, uuid, time, time])
|
|
|
+
|
|
|
+ if (!r || r.affectedRows !== 1)
|
|
|
+ return '系统出错,请稍后再试'
|
|
|
|
|
|
+ return `提交成功`
|
|
|
+ } catch (error) {
|
|
|
+ this.logger.error(`MCP工单创建出错:${e}`)
|
|
|
+ return '系统出错,请稍后再试'
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
const MCP = new Mcp()
|