| | |
| | | |
| | | import ( |
| | | "github.com/gin-gonic/gin" |
| | | "gorm.io/gorm" |
| | | "silkserver/constvar" |
| | | "silkserver/controllers/request" |
| | | "silkserver/extend/code" |
| | | "silkserver/extend/util" |
| | |
| | | // @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] |
| | |
| | | } |
| | | 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, "参数解析失败,数据类型错误") |
| | | 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) |
| | | } |