package controllers import ( "github.com/gin-gonic/gin" "gorm.io/gorm" "silkserver/controllers/request" "silkserver/extend/code" "silkserver/extend/util" "silkserver/middleware" "silkserver/models" ) type WorkerController struct { } // CreateWorkerInfo // // @Tags 员工管理/员工信息 // @Summary 创建人员信息 // @Produce application/json // @Param object body models.Worker true "参数" // @Param Authorization header string true "token" // @Success 200 {object} util.Response "成功" // @Router /api-jl/v1/worker/createWorkerInfo [post] func (slf WorkerController) CreateWorkerInfo(c *gin.Context) { var params models.Worker err := c.BindJSON(¶ms) if err != nil { util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") return } if params.ID == "" { util.ResponseFormat(c, code.RequestParamError, "ID为空") return } if params.Name == "" { util.ResponseFormat(c, code.RequestParamError, "名称为空") return } _, err = models.NewWorkerSearch().SetID(params.ID).First() if err != gorm.ErrRecordNotFound { util.ResponseFormat(c, code.RequestParamError, "编码已存在") return } info := middleware.GetUserInfo(c) params.AddPeople = info.NickName err = models.NewWorkerSearch().Create(¶ms) if err != nil { util.ResponseFormat(c, code.RequestParamError, "创建失败") return } util.ResponseFormat(c, code.Success, "创建成功") } // UpdateWorkerInfo // // @Tags 员工管理/员工信息 // @Summary 更新人员信息 // @Produce application/json // @Param object body models.Worker true "参数" // @Param Authorization header string true "token" // @Success 200 {object} util.Response "成功" // @Router /api-jl/v1/worker/updateWorkerInfo [post] func (slf WorkerController) UpdateWorkerInfo(c *gin.Context) { var params models.Worker err := c.BindJSON(¶ms) if err != nil { util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") return } if params.ID == "" { util.ResponseFormat(c, code.RequestParamError, "ID为空") return } if params.Name == "" { util.ResponseFormat(c, code.RequestParamError, "名称为空") return } err = models.NewWorkerSearch().Save(¶ms) if err != nil { util.ResponseFormat(c, code.RequestParamError, "更新失败") return } util.ResponseFormat(c, code.Success, "更新成功") } // GetWorkerList // // @Tags 员工管理/员工信息 // @Summary 获取人员信息列表 // @Produce application/json // @Param object body request.GetWorkerList true "参数" // @Param Authorization header string true "token" // @Success 200 {object} util.ResponseList{data=[]models.Worker} "成功" // @Router /api-jl/v1/worker/getWorkerList [post] func (slf WorkerController) GetWorkerList(c *gin.Context) { var params request.GetWorkerList err := c.BindJSON(¶ms) if err != nil { util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") return } workers, total, err := models.NewWorkerSearch().SetPage(params.Page, params.PageSize).SetKeyword(params.Keyword).SetOrder("updated_at desc").Find() if err != nil { util.ResponseFormat(c, code.RequestParamError, "查询失败") return } util.ResponseFormatList(c, code.Success, workers, total) } // DeleteWorkerInfo // // @Tags 员工管理/员工信息 // @Summary 删除人员信息 // @Produce application/json // @Param id path string true "id" // @Param Authorization header string true "token" // @Success 200 {object} util.Response "成功" // @Router /api-jl/v1/worker/deleteWorkerInfo/{id} [delete] func (slf WorkerController) DeleteWorkerInfo(c *gin.Context) { id := c.Param("id") if id == "" { util.ResponseFormat(c, code.RequestParamError, "无效的id") return } err := models.NewWorkerSearch().SetID(id).Delete() if err != nil { util.ResponseFormat(c, code.RequestParamError, "删除失败") return } util.ResponseFormat(c, code.Success, "删除成功") }