Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
kefu_server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
854e3fa0
authored
Apr 14, 2020
by
keith
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
增加工单超期定时关闭任务
parent
99b0cec3
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
81 additions
and
0 deletions
controllers/message_controller.go
services/workorder_service.go
task/clear_workorder.go
task/index.go
controllers/message_controller.go
View file @
854e3fa0
...
...
@@ -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
{
...
...
services/workorder_service.go
View file @
854e3fa0
...
...
@@ -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
{
...
...
task/clear_workorder.go
0 → 100644
View file @
854e3fa0
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
)
}
task/index.go
View file @
854e3fa0
...
...
@@ -12,4 +12,7 @@ func Run() {
// moveMessage
moveMessage
()
// clearWorkorder()
clearWorkorder
()
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment