Commit 71524645 by 朱继来

调整脚本

parent ccae335b
......@@ -8,7 +8,7 @@ import (
// 获取指定任务类型的配置
func GetTaskSetup(task_type int) model.TaskSetup {
var task_setup model.TaskSetup
dao.GetDb().Get(&task_setup, "select * from lie_task_setup where task_type = ?", task_type)
dao.GetNewDb().Get(&task_setup, "select * from lie_task_setup where task_type = ?", task_type)
return task_setup
}
......@@ -16,7 +16,7 @@ func GetTaskSetup(task_type int) model.TaskSetup {
// 获取指定任务类型的配置
func GetTaskSetupDetails(task_id int) model.TaskSetupDetails {
var task_setup_details model.TaskSetupDetails
dao.GetDb().Get(&task_setup_details, "select * from lie_task_setup_details where task_id = ?", task_id)
dao.GetNewDb().Get(&task_setup_details, "select * from lie_task_setup_details where task_id = ?", task_id)
return task_setup_details
}
\ No newline at end of file
......@@ -68,8 +68,10 @@ func setFindGoods(status, task_id, task_type, task_display_degree int) {
return
}
db := dao.GetNewDb()
// 获取快速找料的用户
row, err := dao.GetDb().Queryx("select * from lie_feedback where type = ? and is_add_task = ? order by id desc limit 100", 7, 0)
row, err := db.Queryx("select * from lie_feedback where type = ? and is_add_task = ? order by id desc limit 100", 7, 0)
defer db.Close()
if err != nil {
logger.Info("获取快速找料用户失败: ", err.Error())
......@@ -82,7 +84,7 @@ func setFindGoods(status, task_id, task_type, task_display_degree int) {
// 判断该用户是否存在注册领取任务记录或快速找料任务,若存在则跳过
var task_info model.TaskInfo
dao.GetDb().Get(&task_info, "select * from lie_task_info where user_id = ? and status = ? and (task_type = ? or task_type = ?) limit 1", feedback.Outter_Uid, 1, 1, 4)
db.Get(&task_info, "select * from lie_task_info where user_id = ? and status = ? and (task_type = ? or task_type = ?) limit 1", feedback.Outter_Uid, 1, 1, 4)
if task_info.Id != 0 {
continue
......@@ -92,11 +94,11 @@ func setFindGoods(status, task_id, task_type, task_display_degree int) {
// 查看用户是否分配
var salesman model.Salesman
dao.GetDb().Get(&salesman, "select * from lie_salesman where user_id = ?", feedback.Outter_Uid)
db.Get(&salesman, "select * from lie_salesman where user_id = ?", feedback.Outter_Uid)
dao.GetDb().Exec("insert into lie_task_info (user_id, task_id, task_type, task_display_degree, sale_id, create_time, update_time) value (?, ?, ?, ?, " +
db.Exec("insert into lie_task_info (user_id, task_id, task_type, task_display_degree, sale_id, create_time, update_time) value (?, ?, ?, ?, " +
"?, ?, ?)", feedback.Outter_Uid, task_id, task_type, task_display_degree, salesman.Sale_Id, current_time, current_time)
dao.GetDb().Exec("update lie_feedback set is_add_task = ? where id = ?", 1, feedback.Id)
db.Exec("update lie_feedback set is_add_task = ? where id = ?", 1, feedback.Id)
service.DingAlert(configs.Ding_crm_task_token, "任务告警:快速找料任务脚本添加任务记录成功,CRM用户ID:"+strconv.Itoa(feedback.Outter_Uid), "")
}
......
......@@ -60,9 +60,11 @@ func setHaveOrderTask(status, task_id, task_type, task_display_degree int, task_
return
}
db := dao.GetNewDb()
// 获取未释放且未下单用户
row, err := dao.GetDb().Queryx("select u.user_id, u.copy_ctime from lie_user as u left join lie_user_extend as ue on u.user_id = ue.user_id where " +
row, err := db.Queryx("select u.user_id, u.copy_ctime from lie_user as u left join lie_user_extend as ue on u.user_id = ue.user_id where " +
"u.is_free = ? and u.is_add_task = ? and ue.no_create_order = ? order by user_id desc limit 1000", 0, 0, 2)
defer db.Close()
if err != nil {
logger.Info("获取未下单用户失败: ", err.Error())
......@@ -75,7 +77,7 @@ func setHaveOrderTask(status, task_id, task_type, task_display_degree int, task_
// 查看用户最后下单时间
var user_extend model.UserExtend
dao.GetDb().Get(&user_extend, "select * from lie_user_extend where user_id = ?", user.User_id)
db.Get(&user_extend, "select * from lie_user_extend where user_id = ?", user.User_id)
if user_extend.Latest_Order_Time == 0 {
logger.Info("未获取到最后下单时间,CRM用户ID:%d", user.User_id)
......@@ -91,15 +93,15 @@ func setHaveOrderTask(status, task_id, task_type, task_display_degree int, task_
// 查看用户是否分配
var salesman model.Salesman
dao.GetDb().Get(&salesman, "select * from lie_salesman where user_id = ?", user.User_id)
db.Get(&salesman, "select * from lie_salesman where user_id = ?", user.User_id)
// 大于150天,则添加到任务信息表
dao.GetDb().Exec("delete from lie_task_info where user_id = ? and task_type = ?", user.User_id, 3)
db.Exec("delete from lie_task_info where user_id = ? and task_type = ?", user.User_id, 3)
end_time := current_time + task_end_time * 60
dao.GetDb().Exec("insert into lie_task_info (user_id, task_id, task_type, task_display_degree, sale_id, end_time, create_time, update_time) value (?, ?, ?, ?, " +
db.Exec("insert into lie_task_info (user_id, task_id, task_type, task_display_degree, sale_id, end_time, create_time, update_time) value (?, ?, ?, ?, " +
"?, ?, ?, ?)", user.User_id, task_id, task_type, task_display_degree, salesman.Sale_Id, end_time, current_time, current_time)
dao.GetDb().Exec("update lie_user set is_add_task = ? where user_id = ?", 1, user.User_id)
db.Exec("update lie_user set is_add_task = ? where user_id = ?", 1, user.User_id)
service.DingAlert(configs.Ding_crm_task_token, "任务告警:已成交任务脚本添加任务记录成功,CRM用户ID:"+strconv.Itoa(int(user.User_id)), "")
}
......
......@@ -66,8 +66,10 @@ func setMultiSearch(status, task_id, task_type, task_display_degree int) {
return
}
db := dao.GetNewDb()
// 获取快速找料的用户
row, err := dao.GetDb().Queryx("select * from lie_feedback where type = ? and is_add_task = ? order by id desc limit 100", 6, 0)
row, err := db.Queryx("select * from lie_feedback where type = ? and is_add_task = ? order by id desc limit 100", 6, 0)
defer db.Close()
if err != nil {
logger.Info("获取多次搜索用户失败: ", err.Error())
......@@ -79,7 +81,7 @@ func setMultiSearch(status, task_id, task_type, task_display_degree int) {
row.StructScan(&feedback)
var task_info model.TaskInfo
dao.GetDb().Get(&task_info, "select * from lie_task_info where user_id = ? and status = ? and task_type = ? limit 1", feedback.Outter_Uid, 1, 5)
db.Get(&task_info, "select * from lie_task_info where user_id = ? and status = ? and task_type = ? limit 1", feedback.Outter_Uid, 1, 5)
if task_info.Id != 0 {
continue
......@@ -89,11 +91,11 @@ func setMultiSearch(status, task_id, task_type, task_display_degree int) {
// 查看用户是否分配
var salesman model.Salesman
dao.GetDb().Get(&salesman, "select * from lie_salesman where user_id = ?", feedback.Outter_Uid)
db.Get(&salesman, "select * from lie_salesman where user_id = ?", feedback.Outter_Uid)
dao.GetDb().Exec("insert into lie_task_info (user_id, task_id, task_type, task_display_degree, sale_id, create_time, update_time) value (?, ?, ?, ?, " +
db.Exec("insert into lie_task_info (user_id, task_id, task_type, task_display_degree, sale_id, create_time, update_time) value (?, ?, ?, ?, " +
"?, ?, ?)", feedback.Outter_Uid, task_id, task_type, task_display_degree, salesman.Sale_Id, current_time, current_time)
dao.GetDb().Exec("update lie_feedback set is_add_task = ? where id = ?", 1, feedback.Id)
db.Exec("update lie_feedback set is_add_task = ? where id = ?", 1, feedback.Id)
service.DingAlert(configs.Ding_crm_task_token, "任务告警:多次搜索任务脚本添加任务记录成功,CRM用户ID:"+strconv.Itoa(feedback.Outter_Uid), "")
}
......
......@@ -41,7 +41,7 @@ func main () {
task_exec_time, _ := strconv.Atoi(task_setup_details.TsakExecTime)
ticker := time.NewTicker(time.Minute * time.Duration(task_exec_time))
//ticker := time.NewTicker(time.Second * 5)
//ticker := time.NewTicker(time.Second * 3)
for {
select {
......@@ -60,9 +60,11 @@ func setNoOrderTask(status, task_id, task_type, task_display_degree int, task_en
return
}
db := dao.GetNewDb()
// 获取未释放且未下单用户
row, err := dao.GetDb().Queryx("select u.user_id, u.copy_ctime from lie_user as u left join lie_user_extend as ue on u.user_id = ue.user_id where " +
row, err := db.Queryx("select u.user_id, u.copy_ctime from lie_user as u left join lie_user_extend as ue on u.user_id = ue.user_id where " +
"u.is_free = ? and u.is_add_task = ? and ue.no_create_order = ? order by user_id desc limit 1000", 0, 0, 1)
defer db.Close()
if err != nil {
logger.Info("获取未下单用户失败: ", err.Error())
......@@ -75,7 +77,7 @@ func setNoOrderTask(status, task_id, task_type, task_display_degree int, task_en
// 查看用户是否分配
var salesman model.Salesman
dao.GetDb().Get(&salesman, "select * from lie_salesman where user_id = ?", user.User_id)
db.Get(&salesman, "select * from lie_salesman where user_id = ?", user.User_id)
var check_time int64 // 校验时间
if salesman.Sale_Id != 0 {
......@@ -99,12 +101,12 @@ func setNoOrderTask(status, task_id, task_type, task_display_degree int, task_en
}
// 大于23天,则添加到任务信息表
dao.GetDb().Exec("delete from lie_task_info where user_id = ? and task_type = ?", user.User_id, 2)
db.Exec("delete from lie_task_info where user_id = ? and task_type = ?", user.User_id, 2)
end_time := current_time + task_end_time * 60
dao.GetDb().Exec("insert into lie_task_info (user_id, task_id, task_type, task_display_degree, sale_id, end_time, create_time, update_time) value (?, ?, ?, ?, " +
db.Exec("insert into lie_task_info (user_id, task_id, task_type, task_display_degree, sale_id, end_time, create_time, update_time) value (?, ?, ?, ?, " +
"?, ?, ?, ?)", user.User_id, task_id, task_type, task_display_degree, salesman.Sale_Id, end_time, current_time, current_time)
dao.GetDb().Exec("update lie_user set is_add_task = ? where user_id = ?", 1, user.User_id)
db.Exec("update lie_user set is_add_task = ? where user_id = ?", 1, user.User_id)
service.DingAlert(configs.Ding_crm_task_token, "任务告警:未成交任务脚本添加任务记录成功,CRM用户ID:"+strconv.Itoa(int(user.User_id)), "")
}
......
......@@ -61,7 +61,8 @@ func main() {
}
func updateOverTime() {
row, err := dao.GetDb().Queryx("select * from lie_task_info where status = 1 limit 100")
db := dao.GetDb()
row, err := db.Queryx("select * from lie_task_info where status = 1 limit 100")
if err != nil {
logger.Info("获取待处理的任务记录失败: ", err.Error())
......@@ -81,7 +82,7 @@ func updateOverTime() {
// 获取任务配置详情
var task_setup_details model.TaskSetupDetails
err = dao.GetDb().Get(&task_setup_details, "select * from lie_task_setup_details where task_id = ?", task_info.TaskId)
err = db.Get(&task_setup_details, "select * from lie_task_setup_details where task_id = ?", task_info.TaskId)
if err != nil {
logger.Info("获取任务配置详情失败,任务Id:%d,错误原因:%v", task_info.TaskId, err.Error())
......@@ -91,29 +92,29 @@ func updateOverTime() {
// 设置上一任客服
var salesman model.Salesman
dao.GetDb().Get(&salesman, "select sale_id from lie_salesman where user_id = ?", task_info.UserId)
db.Get(&salesman, "select sale_id from lie_salesman where user_id = ?", task_info.UserId)
if salesman.Sale_Id != 0 {
dao.GetDb().Exec("update lie_user set last_sale_id = ? where user_id = ?", salesman.Sale_Id, task_info.UserId)
db.Exec("update lie_user set last_sale_id = ? where user_id = ?", salesman.Sale_Id, task_info.UserId)
}
// TaskResult: 1-释放客户至公共池,2-重新分配客服
var msg_txt string
if task_setup_details.TaskResult == 1 {
dao.GetDb().Exec("update lie_user set is_free = ?, free_time = ?, is_churn = ? where user_id = ?", 1, current_time, 0, task_info.UserId)
dao.GetDb().Exec("delete from lie_salesman where user_id = ?", task_info.UserId)
dao.GetDb().Exec("insert into lie_action_log (user_id, type, event, remark, create_time) values (?, ?, ?, ?, ?)", task_info.UserId, 2, "释放用户", "", current_time)
db.Exec("update lie_user set is_free = ?, free_time = ?, is_churn = ? where user_id = ?", 1, current_time, 0, task_info.UserId)
db.Exec("delete from lie_salesman where user_id = ?", task_info.UserId)
db.Exec("insert into lie_action_log (user_id, type, event, remark, create_time) values (?, ?, ?, ?, ?)", task_info.UserId, 2, "释放用户", "", current_time)
msg_txt = "任务告警:监听任务脚本释放用户成功,CRM用户ID:"+strconv.Itoa(task_info.UserId)
} else {
// 获取adtag、ptag
var user model.Users
dao.GetDb().Get(&user, "select user_id,outter_uid,adtag,ptag from lie_user where user_id = ?", task_info.UserId)
db.Get(&user, "select user_id,outter_uid,adtag,ptag from lie_user where user_id = ?", task_info.UserId)
if user.Adtag != "" || user.Ptag != "" {
// 获取自动分配表指定的客服
var sale_tag model.SaleTag
dao.GetDb().Get(&sale_tag, "select sale_id from lie_sale_tag where adtag = ? or ptag = ?", user.Adtag, user.Ptag)
db.Get(&sale_tag, "select sale_id from lie_sale_tag where adtag = ? or ptag = ?", user.Adtag, user.Ptag)
var sale_id int
......@@ -126,12 +127,12 @@ func updateOverTime() {
msg_txt = "任务告警:监听任务脚本随机分配客服成功,CRM用户ID:"+strconv.Itoa(task_info.UserId)+",指定客服ID:"+strconv.Itoa(sale_id)
}
dao.GetDb().Exec("update lie_salesman set sale_id = ?, create_time = ?, update_time = ? where user_id = ?", sale_id, current_time, current_time, task_info.UserId)
db.Exec("update lie_salesman set sale_id = ?, create_time = ?, update_time = ? where user_id = ?", sale_id, current_time, current_time, task_info.UserId)
}
}
// 标记已超时状态
dao.GetDb().Exec("update lie_task_info set status = ?, update_time = ? where id = ?", -1, current_time, task_info.Id)
db.Exec("update lie_task_info set status = ?, update_time = ? where id = ?", -1, current_time, task_info.Id)
service.DingAlert(configs.Ding_crm_task_token, msg_txt, "")
}
......
......@@ -18,6 +18,15 @@ var onceCms sync.Once
var onceLiexin sync.Once
var onceLiexinBom sync.Once
// 创建可释放的db连接
func GetNewDb()(*sqlx.DB) {
dbConfig := configs.GetDBOne()
db, err := sqlx.Open(dbConfig.Engine, fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8", dbConfig.User, dbConfig.Pass, dbConfig.Ip, dbConfig.Port, dbConfig.Table))
if err != nil {
log.Fatalln(err)
}
return db
}
func GetDb()(*sqlx.DB) {
once.Do(func() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment