实现关闭计划

This commit is contained in:
2025-09-22 15:17:54 +08:00
parent bd2d1c6b63
commit 4096499d28
5 changed files with 138 additions and 3 deletions

View File

@@ -405,7 +405,21 @@ func (c *Controller) StartPlan(ctx *gin.Context) {
// @Success 200 {object} controller.Response "业务码为200代表成功停止计划"
// @Router /api/v1/plans/{id}/stop [post]
func (c *Controller) StopPlan(ctx *gin.Context) {
// 占位符:此处应调用服务层或仓库层来停止计划
c.logger.Infof("收到停止计划请求 (占位符)")
controller.SendResponse(ctx, controller.CodeSuccess, "停止计划接口占位符", nil)
// 1. 从 URL 路径中获取 ID
idStr := ctx.Param("id")
id, err := strconv.ParseUint(idStr, 10, 32)
if err != nil {
controller.SendErrorResponse(ctx, controller.CodeBadRequest, "无效的计划ID格式")
return
}
// 2. 调用仓库层方法,该方法内部处理事务
if err := c.planRepo.StopPlanTransactionally(uint(id)); err != nil {
c.logger.Errorf("停止计划 #%d 失败: %v", id, err)
controller.SendErrorResponse(ctx, controller.CodeInternalError, "停止计划时发生内部错误: "+err.Error())
return
}
// 3. 发送成功响应
controller.SendResponse(ctx, controller.CodeSuccess, "计划已成功停止", nil)
}