You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.5 KiB
62 lines
1.5 KiB
package allhelp
|
|
|
|
import (
|
|
"yunyan/comm"
|
|
"yunyan/pb"
|
|
)
|
|
|
|
// CancelTask 取消任务
|
|
// @Summary 取消任务
|
|
// @Description 取消指定任务
|
|
// @Tags Allhelp
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Security BearerAuth
|
|
// @Param user body pb.AllhelpCancelTaskReq true "请求数据"
|
|
// @Success 200 {object} comm.HttpResult{data=pb.AllhelpCancelTaskResp} "响应数据"
|
|
// @Router /api/home/allhelp_canceltask [post]
|
|
func (this *apiComp) CancelTask(session comm.IUserSession, req *pb.AllhelpCancelTaskReq) (resp *pb.AllhelpCancelTaskResp, errdata *pb.ErrorData) {
|
|
uid := session.GetUserId()
|
|
if uid == "" {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Message: "用户未登录",
|
|
}
|
|
return
|
|
}
|
|
if req.TaskId == 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Message: "任务ID无效",
|
|
}
|
|
return
|
|
}
|
|
|
|
task, err := this.module.model.getTaskById(req.TaskId)
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Message: "任务不存在",
|
|
}
|
|
return
|
|
}
|
|
if task.Uid != uid {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Message: "无权操作该任务",
|
|
}
|
|
return
|
|
}
|
|
|
|
if err := this.module.model.updateTaskStatus(req.TaskId, pb.TaskStatus_TaskStatus_Cancelled); err != nil {
|
|
this.module.Errorln("CancelTask error:", err)
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Message: "取消任务失败",
|
|
}
|
|
return
|
|
}
|
|
|
|
resp = &pb.AllhelpCancelTaskResp{}
|
|
return
|
|
}
|
|
|