Commit 854e3fa0 by keith

增加工单超期定时关闭任务

parent 99b0cec3
......@@ -48,6 +48,9 @@ func messageList(c *MessageController, isHistory bool) {
// GetAdminAuthInfo
auth := c.GetAdminAuthInfo()
if messagePaginationDto.Service == 0 {
messagePaginationDto.Service = auth.UID
}
// Timestamp == 0
if messagePaginationDto.Timestamp == 0 {
......
......@@ -21,6 +21,8 @@ type WorkOrderRepositoryInterface interface {
Delete(id int64) (int64, error)
Close(id int64, cid int64, remark string) (int64, error)
GetCounts() (models.WorkOrderCountDto, error)
GetTimeOutWorkOrders(lastDateTime int64) []models.WorkOrder
ClearTimeOutWorkOrders(lastDateTime int64) int64
}
// WorkOrderRepository struct
......@@ -37,6 +39,27 @@ func GetWorkOrderRepositoryInstance() *WorkOrderRepository {
return instance
}
// GetTimeOutWorkOrders get TimeOut WorkOrders
func (r *WorkOrderRepository) GetTimeOutWorkOrders(lastDateTime int64) []models.WorkOrder {
var workOrders []models.WorkOrder
_, err := r.o.Raw("SELECT * FROM work_order WHERE `status` = 2 AND `update_at` < ?", lastDateTime).QueryRows(&workOrders)
if err != nil {
logs.Warn("GetTimeOutWorkOrders Clear TimeOut WorkOrders-----------", err)
}
return workOrders
}
// ClearTimeOutWorkOrders Clear TimeOut WorkOrders
func (r *WorkOrderRepository) ClearTimeOutWorkOrders(lastDateTime int64) int64 {
res, err := r.o.Raw("UPDATE work_order SET `status` = 3 WHERE `status` = 2 AND `update_at` < ?", lastDateTime).Exec()
if err != nil {
logs.Warn("ClearTimeOutWorkOrders Clear TimeOut WorkOrders-----------", err)
return 0
}
rows, _ := res.RowsAffected()
return rows
}
// Close close WorkOrder
func (r *WorkOrderRepository) Close(id int64, cid int64, remark string) (int64, error) {
row, err := r.q.Filter("id", id).Update(orm.Params{
......
package task
import (
"kf_server/models"
"kf_server/services"
"kf_server/utils"
"strconv"
"time"
"github.com/astaxie/beego"
"github.com/astaxie/beego/logs"
"github.com/astaxie/beego/toolbox"
)
// clearWorkorder tk
func clearWorkorder() {
// clearWorkorder day at 1 am
clearWorkorderTk := toolbox.NewTask("clearWorkorder", "0 0 01 * * *", func() error {
var dayTime int64 = time.Now().Unix() - 60*60*24*7
workOrderRepository := services.GetWorkOrderRepositoryInstance()
workOrders := workOrderRepository.GetTimeOutWorkOrders(dayTime)
for _, workOrder := range workOrders {
workOrderComment := models.WorkOrderComment{
UID: workOrder.UID,
AID: workOrder.LastReply,
WID: workOrder.ID,
Content: "由于您较长时间未反馈该问题,我们暂时先将该工单结束了, 如您的问题还未得到解决,您可以随时联系我们的在线客服,祝您生活愉快~",
CreateAt: time.Now().Unix(),
}
services.GetWorkOrderCommentRepositoryInstance().Add(workOrderComment)
// send email message
openWorkorderEmail, _ := beego.AppConfig.Bool("open_workorder_email")
if workOrder.Email != "" && openWorkorderEmail {
go func() {
mailTo := []string{
workOrder.Email,
}
subject := "您的工单:" + workOrder.Title + "已被回复"
kefuClientURL := beego.AppConfig.String("kefu_client_url")
body := "工单标题:" + workOrder.Title + "<br>回复:" + workOrderComment.Content + "<br>您可以点<a target='_blank' href='" + kefuClientURL + "?u=" + strconv.FormatInt(workOrder.UID, 10) + "'>此链接</a>去查看完整内容"
utils.SendMail(mailTo, subject, body)
}()
}
}
length := workOrderRepository.ClearTimeOutWorkOrders(dayTime)
logs.Error("tk--------定时清理了", length, "条超期工单~")
return nil
})
toolbox.AddTask("clearWorkorder", clearWorkorderTk)
}
......@@ -12,4 +12,7 @@ func Run() {
// moveMessage
moveMessage()
// clearWorkorder()
clearWorkorder()
}
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