From d6aea9913510936bde157e22a1f7042a0eb33ac3 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期日, 28 四月 2024 10:36:50 +0800
Subject: [PATCH] 时间范围和该工人以往添加记录重复性校验

---
 controllers/salary_plan_controller.go |   82 +++++++++++++++++++++++++++++++++++++++-
 1 files changed, 79 insertions(+), 3 deletions(-)

diff --git a/controllers/salary_plan_controller.go b/controllers/salary_plan_controller.go
index 1aa74b4..fb8d9aa 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]
@@ -69,7 +71,7 @@
 		util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�")
 		return
 	}
-	find, total, err := models.NewSalaryPlanSearch().SetPage(params.Page, params.PageSize).Find()
+	find, total, err := models.NewSalaryPlanSearch().SetPage(params.Page, params.PageSize).SetPreload(true).Find()
 	if err != nil {
 		util.ResponseFormat(c, code.RequestParamError, "鏌ユ壘澶辫触")
 		return
@@ -82,7 +84,7 @@
 //	@Tags		鍛樺伐钖祫/钖叕鏂规
 //	@Summary	鍒犻櫎钖叕鏂规
 //	@Produce	application/json
-//	@Param		number	path		string			true	"id"
+//	@Param		id	path		string			true	"id"
 //	@Param     	Authorization	header string true "token"
 //	@Success	200		{object}	util.Response		"鎴愬姛"
 //	@Router		/api-jl/v1/salary/deleteSalaryPlanInfo/{id} [delete]
@@ -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(&params)
+	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