package twi

import (
	"courseSign/server/global"
    "courseSign/server/model/twi"
    "courseSign/server/model/common/request"
    twiReq "courseSign/server/model/twi/request"
    "courseSign/server/model/common/response"
    "courseSign/server/service"
    "github.com/gin-gonic/gin"
    "go.uber.org/zap"
)

type TwiActFinishApi struct {
}

var twiActFinishService = service.ServiceGroupApp.TwiServiceGroup.TwiActFinishService


// CreateTwiActFinish 创建TwiActFinish
// @Tags TwiActFinish
// @Summary 创建TwiActFinish
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body twi.TwiActFinish true "创建TwiActFinish"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /twiActFinish/createTwiActFinish [post]
func (twiActFinishApi *TwiActFinishApi) CreateTwiActFinish(c *gin.Context) {
	var twiActFinish twi.TwiActFinish
	err := c.ShouldBindJSON(&twiActFinish)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := twiActFinishService.CreateTwiActFinish(twiActFinish); err != nil {
        global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败", c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}

// DeleteTwiActFinish 删除TwiActFinish
// @Tags TwiActFinish
// @Summary 删除TwiActFinish
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body twi.TwiActFinish true "删除TwiActFinish"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /twiActFinish/deleteTwiActFinish [delete]
func (twiActFinishApi *TwiActFinishApi) DeleteTwiActFinish(c *gin.Context) {
	var twiActFinish twi.TwiActFinish
	err := c.ShouldBindJSON(&twiActFinish)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := twiActFinishService.DeleteTwiActFinish(twiActFinish); err != nil {
        global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

// DeleteTwiActFinishByIds 批量删除TwiActFinish
// @Tags TwiActFinish
// @Summary 批量删除TwiActFinish
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除TwiActFinish"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
// @Router /twiActFinish/deleteTwiActFinishByIds [delete]
func (twiActFinishApi *TwiActFinishApi) DeleteTwiActFinishByIds(c *gin.Context) {
	var IDS request.IdsReq
    err := c.ShouldBindJSON(&IDS)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := twiActFinishService.DeleteTwiActFinishByIds(IDS); err != nil {
        global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败", c)
	} else {
		response.OkWithMessage("批量删除成功", c)
	}
}

// UpdateTwiActFinish 更新TwiActFinish
// @Tags TwiActFinish
// @Summary 更新TwiActFinish
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body twi.TwiActFinish true "更新TwiActFinish"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /twiActFinish/updateTwiActFinish [put]
func (twiActFinishApi *TwiActFinishApi) UpdateTwiActFinish(c *gin.Context) {
	var twiActFinish twi.TwiActFinish
	err := c.ShouldBindJSON(&twiActFinish)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := twiActFinishService.UpdateTwiActFinish(twiActFinish); err != nil {
        global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// FindTwiActFinish 用id查询TwiActFinish
// @Tags TwiActFinish
// @Summary 用id查询TwiActFinish
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query twi.TwiActFinish true "用id查询TwiActFinish"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /twiActFinish/findTwiActFinish [get]
func (twiActFinishApi *TwiActFinishApi) FindTwiActFinish(c *gin.Context) {
	var twiActFinish twi.TwiActFinish
	err := c.ShouldBindQuery(&twiActFinish)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if retwiActFinish, err := twiActFinishService.GetTwiActFinish(twiActFinish.ID); err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"retwiActFinish": retwiActFinish}, c)
	}
}

// GetTwiActFinishList 分页获取TwiActFinish列表
// @Tags TwiActFinish
// @Summary 分页获取TwiActFinish列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query twiReq.TwiActFinishSearch true "分页获取TwiActFinish列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /twiActFinish/getTwiActFinishList [get]
func (twiActFinishApi *TwiActFinishApi) GetTwiActFinishList(c *gin.Context) {
	var pageInfo twiReq.TwiActFinishSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if list, total, err := twiActFinishService.GetTwiActFinishInfoList(pageInfo); err != nil {
	    global.GVA_LOG.Error("获取失败!", zap.Error(err))
        response.FailWithMessage("获取失败", c)
    } else {
        response.OkWithDetailed(response.PageResult{
            List:     list,
            Total:    total,
            Page:     pageInfo.Page,
            PageSize: pageInfo.PageSize,
        }, "获取成功", c)
    }
}
