From 9a55dd2315602ab802ee7fcbad46cef17ffe23d8 Mon Sep 17 00:00:00 2001 From: liujiandao <274878379@qq.com> Date: 星期四, 18 四月 2024 16:50:29 +0800 Subject: [PATCH] swag提交 --- controllers/salary_plan_controller.go | 78 ++++++++++++++++++++++++++++++++++++++ 1 files changed, 77 insertions(+), 1 deletions(-) diff --git a/controllers/salary_plan_controller.go b/controllers/salary_plan_controller.go index 1aa74b4..9934ca0 100644 --- a/controllers/salary_plan_controller.go +++ b/controllers/salary_plan_controller.go @@ -2,6 +2,8 @@ import ( "github.com/gin-gonic/gin" + "gorm.io/gorm" + "silkserver/constvar" "silkserver/controllers/request" "silkserver/extend/code" "silkserver/extend/util" @@ -20,7 +22,7 @@ // @Tags 鍛樺伐钖祫/钖叕鏂规 // @Summary 淇濆瓨钖叕鏂规 // @Produce application/json -// @Param object body models.SaveSalaryPlan true "鍙傛暟" +// @Param object body models.SalaryPlan true "鍙傛暟" // @Param Authorization header string true "token" // @Success 200 {object} util.Response "鎴愬姛" // @Router /api-jl/v1/salary/saveSalaryPlan [post] @@ -104,3 +106,77 @@ } util.ResponseFormat(c, code.Success, "鍒犻櫎鎴愬姛") } + +// SaveSalaryType +// +// @Tags 鍛樺伐钖祫/钖叕鏂规 +// @Summary 淇濆瓨钖祫绫诲瀷 +// @Produce application/json +// @Param object body request.SalaryType true "鍙傛暟" +// @Param Authorization header string true "token" +// @Success 200 {object} util.Response "鎴愬姛" +// @Router /api-jl/v1/salary/saveSalaryType [post] +func (slf SalaryPlanController) SaveSalaryType(c *gin.Context) { + var params request.SalaryType + err := c.BindJSON(¶ms) + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�") + return + } + if params.Type == 0 { + util.ResponseFormat(c, code.RequestParamError, "绫诲瀷涓嶈兘涓虹┖") + return + } + types := make([]*models.MiniDict, 0) + for _, value := range params.Values { + var dict models.MiniDict + dict.Name = value.Name + dict.IsDefault = value.IsDefault + dict.Type = params.Type + types = append(types, &dict) + } + err = models.WithTransaction(func(db *gorm.DB) error { + err = models.NewMiniDictSearch().SetOrm(db).SetType(params.Type).Delete() + if err != nil { + return err + } + err = models.NewMiniDictSearch().SetOrm(db).CreateBatch(types) + if err != nil { + return err + } + return nil + }) + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "淇濆瓨澶辫触") + return + } + util.ResponseFormat(c, code.Success, "淇濆瓨鎴愬姛") +} + +// GetSalaryTypeList +// +// @Tags 鍛樺伐钖祫/钖叕鏂规 +// @Summary 鑾峰彇钖祫绫诲瀷鍒楄〃 +// @Produce application/json +// @Param number path string true "type" "鍙傛暟" +// @Param Authorization header string true "token" +// @Success 200 {object} util.ResponseList{data=[]models.MiniDict} "鎴愬姛" +// @Router /api-jl/v1/salary/getSalaryTypeList/{type} [get] +func (slf SalaryPlanController) GetSalaryTypeList(c *gin.Context) { + tp := c.Param("type") + if tp == "" { + util.ResponseFormat(c, code.RequestParamError, "鏃犳晥鐨勭被鍨�") + return + } + atoi, _ := strconv.Atoi(tp) + if atoi == 0 { + util.ResponseFormat(c, code.RequestParamError, "鏃犳晥鐨勭被鍨�") + return + } + dicts, err := models.NewMiniDictSearch().SetType(constvar.MiniDictType(atoi)).FindNotTotal() + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "鏌ヨ澶辫触") + return + } + util.ResponseFormat(c, code.Success, dicts) +} -- Gitblit v1.8.0