From 3032034d254fc15f06a1d4260f35c49f0ef1e12f Mon Sep 17 00:00:00 2001 From: yinbentan <yinbentan@live.com> Date: 星期五, 02 八月 2024 11:57:33 +0800 Subject: [PATCH] 添加接口,添加新的薪资查询和修改接口 --- controllers/request/salary_plan.go | 32 ++ controllers/response/salary_plan.go | 6 controllers/salary_plan_controller.go | 162 +++++++++++ docs/swagger.yaml | 124 ++++++++ docs/docs.go | 197 +++++++++++++ docs/swagger.json | 197 +++++++++++++ models/payroll_constitute.go | 103 ++++++ router/router.go | 2 service/salary_plan.go | 5 9 files changed, 789 insertions(+), 39 deletions(-) diff --git a/controllers/request/salary_plan.go b/controllers/request/salary_plan.go index 20c927e..52929ae 100644 --- a/controllers/request/salary_plan.go +++ b/controllers/request/salary_plan.go @@ -1,5 +1,10 @@ package request +import ( + "github.com/shopspring/decimal" + "silkserver/constvar" +) + type PayrollProductionCar struct { PageInfo Cycle string `json:"cycle" form:"cycle"` // 缁熻鍛ㄦ湡锛堝勾-鏈�-鏃ワ級 @@ -28,3 +33,30 @@ WorkTypeCode string `json:"workTypeCode" form:"workTypeCode"` // 宸ョ缂栫爜 Keyword string `json:"keyword" form:"keyword"` // 鍏抽敭瀛� } + +type UpdatePayrollConstitute struct { + Cycle string `json:"cycle" ` //鏈堜唤 + WorkerID string `json:"workerID" ` //鍛樺伐ID + WorkTypeID uint `json:"workTypeID" ` //宸ョID + WorkTypeCode constvar.JobType `json:"workTypeCode" ` //宸ョ浠g爜 + Amount decimal.Decimal `json:"amount" ` //閲戦 +} + +type PayrollConstitute struct { + PageInfo + Cycle string `json:"cycle" form:"cycle"` // 缁熻鍛ㄦ湡鎸夋湀鏌ヨ锛堝勾-鏈堬級 + WorkerID string `json:"workerID" form:"workerID"` // 鍛樺伐ID + WorkTypeID int `json:"workTypeID" form:"workTypeID"` // 宸ョID + WorkTypeCode string `json:"workTypeCode" form:"workTypeCode"` // 宸ョ缂栫爜 + Keyword string `json:"keyword" form:"keyword"` // 鍏抽敭瀛� +} + +type SavePayrollConstitute struct { + Cycle string `json:"cycle" from:"cycle"` //鍛ㄦ湡锛堟湀浠斤級 + WorkerID string `json:"workerId" from:"workerId"` //鍛樺伐ID + WorkTypeID uint `json:"workTypeID" from:"workTypeID"` //宸ョID + WorkTypeCode constvar.JobType `json:"workTypeCode" from:"workTypeCode"` //宸ョ浠g爜 + WorkTypeName string `json:"workTypeName" from:"workTypeName"` //宸ョ鍚嶇О + SalaryPlanId uint `json:"salaryPlanId" from:"salaryPlanId"` //钖祫鏂规ID + Amount decimal.Decimal `json:"amount" from:"amount"` // 閲戦 +} diff --git a/controllers/response/salary_plan.go b/controllers/response/salary_plan.go new file mode 100644 index 0000000..cc4f11d --- /dev/null +++ b/controllers/response/salary_plan.go @@ -0,0 +1,6 @@ +package response + +type PayrollSalaryPlan struct { + // 浜哄憳淇℃伅 + // +} diff --git a/controllers/salary_plan_controller.go b/controllers/salary_plan_controller.go index 461b326..17fa659 100644 --- a/controllers/salary_plan_controller.go +++ b/controllers/salary_plan_controller.go @@ -1,7 +1,9 @@ package controllers import ( + "fmt" "github.com/gin-gonic/gin" + "github.com/shopspring/decimal" "gorm.io/gorm" "silkserver/constvar" "silkserver/controllers/request" @@ -9,6 +11,7 @@ "silkserver/extend/util" "silkserver/middleware" "silkserver/models" + "silkserver/pkg/structx" "silkserver/pkg/timex" "strconv" "time" @@ -335,3 +338,162 @@ util.ResponseFormatList(c, code.Success, list, total) } + +// SavePayrollConstitute +// +// @Tags 鍛樺伐钖祫/钖叕鏂规 +// @Summary 钖叕鏁伴璋冩暣 +// @Produce application/json +// @Param object body request.SavePayrollConstitute true "鍙傛暟" +// @Param Authorization header string true "token" +// @Success 200 {object} util.Response "鎴愬姛" +// @Router /api-jl/v1/salary/savePayrollConstitute [post] +func (slf SalaryPlanController) SavePayrollConstitute(c *gin.Context) { + var params request.SavePayrollConstitute + var constitute models.PayrollConstitute + err := c.BindJSON(¶ms) + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�") + return + } + err = structx.AssignTo(params, &constitute) + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "鏁版嵁杞崲澶辫触") + return + } + if len(constitute.Cycle) < 7 { + util.ResponseFormat(c, code.RequestParamError, "鍛ㄦ湡鍙傛暟涓虹┖鎴栨牸寮忛敊璇�") + } + if len(constitute.WorkerID) == 0 { + util.ResponseFormat(c, code.RequestParamError, "鍛樺伐ID鍙傛暟涓虹┖") + } + if constitute.SalaryPlanId == 0 { + util.ResponseFormat(c, code.RequestParamError, "钖祫鏂规ID鍙傛暟涓虹┖") + } + + info := middleware.GetUserInfo(c) + if info == nil || info.NickName == "" { + util.ResponseFormat(c, code.RequestParamError, "鐢ㄦ埛鏈櫥褰�") + } + constitute.CreatedBy = info.NickName + + if payrollConstitute, err := models.NewPayrollConstituteSearch().SetCycle(params.Cycle).SetWorkerID(params.WorkerID).SetSalaryPlanId(params.SalaryPlanId).First(); err != nil && payrollConstitute != nil { + constitute.ID = payrollConstitute.ID + constitute.CreatedAt = payrollConstitute.CreatedAt + } + + if constitute.ID > 0 { + err = models.NewPayrollConstituteSearch().Save(&constitute) + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "淇濆瓨澶辫触") + return + } + } else { + err = models.NewPayrollConstituteSearch().Create(&constitute) + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "淇濆瓨澶辫触") + return + } + } + + util.ResponseFormat(c, code.Success, "淇濆瓨鎴愬姛") +} + +// GetPayrollConstituteList +// +// @Tags 鍛樺伐钖祫/钖叕鏂规 +// @Summary 鑾峰彇浜哄憳姣忔湀鐨勮柂璧勫垪琛� +// @Produce application/json +// @Param Authorization header string true "token" +// @Param object query request.PayrollConstitute true "鏌ヨ鍙傛暟" +// @Success 200 {object} util.ResponseList{data=map[string]interface{}} "鎴愬姛" +// @Router /api-jl/v1/salary/getPayrollConstituteList [get] +func (slf SalaryPlanController) GetPayrollConstituteList(c *gin.Context) { + + var params request.PayrollConstitute + if err := c.ShouldBindQuery(¶ms); err != nil { + util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�") + return + } + if len(params.Cycle) == 0 { + util.ResponseFormat(c, code.RequestParamError, "璇锋鏌ユ煡璇㈠懆鏈熴�傛牸寮忥細Cycle锛坹yyy-MM-dd锛�") + return + } + + groupList, err := models.NewPayrollConstituteSearch().ConstituteGroup(&models.ConstituteGroup{Cycle: params.Cycle}) + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "鏌ユ壘宸ヨ祫鍒嗙被澶辫触") + return + } + groupMap := make(map[string][]*models.ConstituteGroup, 0) + for _, group := range groupList { + if _, ok := groupMap[group.WorkerID]; ok { + groupMap[group.WorkerID] = append(groupMap[group.WorkerID], group) + } else { + groupMap[group.WorkerID] = []*models.ConstituteGroup{group} + } + } + + // 鍛樺伐淇℃伅 + workers, err := models.NewWorkerSearch().FindNotTotal() + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "鏌ユ壘鐢ㄦ埛澶辫触") + } + workerMap := make(map[string]*models.Worker) + for _, worker := range workers { + workerMap[worker.ID] = worker + } + + // 宸ヨ祫鏂规 + salaryPlans, err := models.NewSalaryPlanSearch().FindNotTotal() + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "鏌ユ壘钖祫鏂规澶辫触") + } + salaryPlanMap := make(map[uint]*models.SalaryPlan) + for _, plan := range salaryPlans { + salaryPlanMap[plan.ID] = plan + } + + // 宸ヨ祫鍗曢」 + constituteList, err := models.NewPayrollConstituteSearch().SetCycle(params.Cycle).SetWorkerID(params.WorkerID).SetWorkTypeID(uint(params.WorkTypeID)).SetWorkTypeCode(params.WorkTypeCode).FindNotTotal() + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "鏌ユ壘宸ヨ祫鍗曢」澶辫触") + return + } + constituteMap := make(map[string]*models.PayrollConstitute) + for _, v := range constituteList { + key := fmt.Sprintf("%v%v%v", v.Cycle, v.WorkerID, v.SalaryPlanId) + constituteMap[key] = v + } + + var list []map[string]interface{} + for workerId, group := range groupMap { + result := make(map[string]interface{}) + result["cycle"] = params.Cycle + if _, ok := workerMap[workerId]; ok { // 浜哄憳淇℃伅 + result["worker"] = workerMap[workerId] + } + amount := decimal.NewFromInt(0) + constituteList := make([]map[string]interface{}, 0) + for _, v := range group { + temp := make(map[string]interface{}) + if _, ok := salaryPlanMap[v.SalaryPlanId]; ok { + temp["salaryPlan"] = salaryPlanMap[v.SalaryPlanId] + } + + key := fmt.Sprintf("%v%v%v", v.Cycle, v.WorkerID, v.SalaryPlanId) + if _, ok := constituteMap[key]; ok { + temp["amount"] = constituteMap[key].Amount + amount = amount.Add(constituteMap[key].Amount) + } + constituteList = append(constituteList, temp) + } + result["amount"] = amount // 搴斿彂宸ヨ祫 + result["list"] = constituteList // 宸ヨ祫璇︽儏 + + list = append(list, result) + } + + util.ResponseFormat(c, code.Success, list) + +} diff --git a/docs/docs.go b/docs/docs.go index 14b0afe..3f8e9e3 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -1136,6 +1136,89 @@ } } }, + "/api-jl/v1/salary/getPayrollConstituteList": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "鍛樺伐钖祫/钖叕鏂规" + ], + "summary": "鑾峰彇浜哄憳姣忔湀鐨勮柂璧勫垪琛�", + "parameters": [ + { + "type": "string", + "description": "token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "type": "string", + "description": "缁熻鍛ㄦ湡鎸夋湀鏌ヨ锛堝勾-鏈堬級", + "name": "cycle", + "in": "query" + }, + { + "type": "string", + "description": "鍏抽敭瀛�", + "name": "keyword", + "in": "query" + }, + { + "type": "integer", + "description": "椤电爜", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "description": "姣忛〉澶у皬", + "name": "pageSize", + "in": "query" + }, + { + "type": "string", + "description": "宸ョ缂栫爜", + "name": "workTypeCode", + "in": "query" + }, + { + "type": "integer", + "description": "宸ョID", + "name": "workTypeID", + "in": "query" + }, + { + "type": "string", + "description": "鍛樺伐ID", + "name": "workerID", + "in": "query" + } + ], + "responses": { + "200": { + "description": "鎴愬姛", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/util.ResponseList" + }, + { + "type": "object", + "properties": { + "data": { + "type": "object", + "additionalProperties": true + } + } + } + ] + } + } + } + } + }, "/api-jl/v1/salary/getPayrollProductionCarList": { "get": { "produces": [ @@ -1505,6 +1588,43 @@ } } }, + "/api-jl/v1/salary/savePayrollConstitute": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "鍛樺伐钖祫/钖叕鏂规" + ], + "summary": "钖叕鏁伴璋冩暣", + "parameters": [ + { + "description": "鍙傛暟", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.SavePayrollConstitute" + } + }, + { + "type": "string", + "description": "token", + "name": "Authorization", + "in": "header", + "required": true + } + ], + "responses": { + "200": { + "description": "鎴愬姛", + "schema": { + "$ref": "#/definitions/util.Response" + } + } + } + } + }, "/api-jl/v1/salary/saveSalaryPlan": { "post": { "produces": [ @@ -1650,23 +1770,20 @@ 1, 2, 3, - 4, - 5 + 4 ], "type": "integer", "x-enum-comments": { "DictTypeColor": "棰滆壊", "DictTypeMarket": "搴勫彛", "DictTypeSpec": "瑙勬牸", - "DictTypeSubsidy": "琛ヨ创", "DictTypeWorkshop": "杞﹂棿" }, "x-enum-varnames": [ "DictTypeMarket", "DictTypeWorkshop", "DictTypeColor", - "DictTypeSpec", - "DictTypeSubsidy" + "DictTypeSpec" ], "description": "瀛楀吀绫诲瀷", "name": "dictType", @@ -2790,22 +2907,19 @@ 1, 2, 3, - 4, - 5 + 4 ], "x-enum-comments": { "DictTypeColor": "棰滆壊", "DictTypeMarket": "搴勫彛", "DictTypeSpec": "瑙勬牸", - "DictTypeSubsidy": "琛ヨ创", "DictTypeWorkshop": "杞﹂棿" }, "x-enum-varnames": [ "DictTypeMarket", "DictTypeWorkshop", "DictTypeColor", - "DictTypeSpec", - "DictTypeSubsidy" + "DictTypeSpec" ] }, "constvar.FileTemplateCategory": { @@ -2835,7 +2949,9 @@ "cleaner", "machine_cleaner", "all-powerful", - "monitor" + "monitor", + "test", + "other" ], "x-enum-comments": { "JobTypeAllPowerful": "鍏ㄨ兘鏈哄姩", @@ -2845,7 +2961,9 @@ "JobTypeMachineCleaner": "鎰熺煡鍣ㄦ竻娲楀伐", "JobTypeMaintenance": "淇濆叏宸�", "JobTypeMonitor": "鐝暱", + "JobTypeOther": "鍏跺畠", "JobTypeScoop": "鑸�鑼у伐", + "JobTypeTest": "娴嬭瘯", "JobTypeTransport": "閫佽導宸�", "JobTypeWeavers": "鎸¤溅宸�" }, @@ -2859,7 +2977,9 @@ "JobTypeCleaner", "JobTypeMachineCleaner", "JobTypeAllPowerful", - "JobTypeMonitor" + "JobTypeMonitor", + "JobTypeTest", + "JobTypeOther" ] }, "constvar.MiniDictType": { @@ -3404,6 +3524,10 @@ "models.PayrollProductionCar": { "type": "object", "properties": { + "badSilkAvgQuantity": { + "description": "閲庣氦骞冲潎鏁伴噺", + "type": "number" + }, "badSilkQuantity": { "description": "閲庣氦鏁伴噺", "type": "number" @@ -3503,6 +3627,9 @@ "description": "瑙勬牸", "type": "string" }, + "workshopId": { + "type": "integer" + }, "workshopNumber": { "description": "杞﹂棿缂栧彿", "type": "string" @@ -3561,6 +3688,9 @@ "silkTotalAvgAmount": { "description": "涓濋噺浜哄钩鍧囨�讳环", "type": "number" + }, + "workshopId": { + "type": "integer" }, "workshopName": { "description": "杞﹂棿鍚嶇О", @@ -3836,6 +3966,9 @@ "shopName": { "type": "string" }, + "shopNumber": { + "type": "string" + }, "status": { "$ref": "#/definitions/constvar.WorkerStatus" }, @@ -4080,6 +4213,9 @@ }, "vehicleSpeed": { "type": "number" + }, + "workshopId": { + "type": "integer" }, "workshopName": { "description": "杞﹂棿鍚�", @@ -4711,6 +4847,43 @@ } } }, + "request.SavePayrollConstitute": { + "type": "object", + "properties": { + "amount": { + "description": "閲戦", + "type": "number" + }, + "cycle": { + "description": "鍛ㄦ湡锛堟湀浠斤級", + "type": "string" + }, + "salaryPlanId": { + "description": "钖祫鏂规ID", + "type": "integer" + }, + "workTypeCode": { + "description": "宸ョ浠g爜", + "allOf": [ + { + "$ref": "#/definitions/constvar.JobType" + } + ] + }, + "workTypeID": { + "description": "宸ョID", + "type": "integer" + }, + "workTypeName": { + "description": "宸ョ鍚嶇О", + "type": "string" + }, + "workerId": { + "description": "鍛樺伐ID", + "type": "string" + } + } + }, "request.SaveRankStandard": { "type": "object", "properties": { diff --git a/docs/swagger.json b/docs/swagger.json index 71bc2ef..401d42b 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -1125,6 +1125,89 @@ } } }, + "/api-jl/v1/salary/getPayrollConstituteList": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "鍛樺伐钖祫/钖叕鏂规" + ], + "summary": "鑾峰彇浜哄憳姣忔湀鐨勮柂璧勫垪琛�", + "parameters": [ + { + "type": "string", + "description": "token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "type": "string", + "description": "缁熻鍛ㄦ湡鎸夋湀鏌ヨ锛堝勾-鏈堬級", + "name": "cycle", + "in": "query" + }, + { + "type": "string", + "description": "鍏抽敭瀛�", + "name": "keyword", + "in": "query" + }, + { + "type": "integer", + "description": "椤电爜", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "description": "姣忛〉澶у皬", + "name": "pageSize", + "in": "query" + }, + { + "type": "string", + "description": "宸ョ缂栫爜", + "name": "workTypeCode", + "in": "query" + }, + { + "type": "integer", + "description": "宸ョID", + "name": "workTypeID", + "in": "query" + }, + { + "type": "string", + "description": "鍛樺伐ID", + "name": "workerID", + "in": "query" + } + ], + "responses": { + "200": { + "description": "鎴愬姛", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/util.ResponseList" + }, + { + "type": "object", + "properties": { + "data": { + "type": "object", + "additionalProperties": true + } + } + } + ] + } + } + } + } + }, "/api-jl/v1/salary/getPayrollProductionCarList": { "get": { "produces": [ @@ -1494,6 +1577,43 @@ } } }, + "/api-jl/v1/salary/savePayrollConstitute": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "鍛樺伐钖祫/钖叕鏂规" + ], + "summary": "钖叕鏁伴璋冩暣", + "parameters": [ + { + "description": "鍙傛暟", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.SavePayrollConstitute" + } + }, + { + "type": "string", + "description": "token", + "name": "Authorization", + "in": "header", + "required": true + } + ], + "responses": { + "200": { + "description": "鎴愬姛", + "schema": { + "$ref": "#/definitions/util.Response" + } + } + } + } + }, "/api-jl/v1/salary/saveSalaryPlan": { "post": { "produces": [ @@ -1639,23 +1759,20 @@ 1, 2, 3, - 4, - 5 + 4 ], "type": "integer", "x-enum-comments": { "DictTypeColor": "棰滆壊", "DictTypeMarket": "搴勫彛", "DictTypeSpec": "瑙勬牸", - "DictTypeSubsidy": "琛ヨ创", "DictTypeWorkshop": "杞﹂棿" }, "x-enum-varnames": [ "DictTypeMarket", "DictTypeWorkshop", "DictTypeColor", - "DictTypeSpec", - "DictTypeSubsidy" + "DictTypeSpec" ], "description": "瀛楀吀绫诲瀷", "name": "dictType", @@ -2779,22 +2896,19 @@ 1, 2, 3, - 4, - 5 + 4 ], "x-enum-comments": { "DictTypeColor": "棰滆壊", "DictTypeMarket": "搴勫彛", "DictTypeSpec": "瑙勬牸", - "DictTypeSubsidy": "琛ヨ创", "DictTypeWorkshop": "杞﹂棿" }, "x-enum-varnames": [ "DictTypeMarket", "DictTypeWorkshop", "DictTypeColor", - "DictTypeSpec", - "DictTypeSubsidy" + "DictTypeSpec" ] }, "constvar.FileTemplateCategory": { @@ -2824,7 +2938,9 @@ "cleaner", "machine_cleaner", "all-powerful", - "monitor" + "monitor", + "test", + "other" ], "x-enum-comments": { "JobTypeAllPowerful": "鍏ㄨ兘鏈哄姩", @@ -2834,7 +2950,9 @@ "JobTypeMachineCleaner": "鎰熺煡鍣ㄦ竻娲楀伐", "JobTypeMaintenance": "淇濆叏宸�", "JobTypeMonitor": "鐝暱", + "JobTypeOther": "鍏跺畠", "JobTypeScoop": "鑸�鑼у伐", + "JobTypeTest": "娴嬭瘯", "JobTypeTransport": "閫佽導宸�", "JobTypeWeavers": "鎸¤溅宸�" }, @@ -2848,7 +2966,9 @@ "JobTypeCleaner", "JobTypeMachineCleaner", "JobTypeAllPowerful", - "JobTypeMonitor" + "JobTypeMonitor", + "JobTypeTest", + "JobTypeOther" ] }, "constvar.MiniDictType": { @@ -3393,6 +3513,10 @@ "models.PayrollProductionCar": { "type": "object", "properties": { + "badSilkAvgQuantity": { + "description": "閲庣氦骞冲潎鏁伴噺", + "type": "number" + }, "badSilkQuantity": { "description": "閲庣氦鏁伴噺", "type": "number" @@ -3492,6 +3616,9 @@ "description": "瑙勬牸", "type": "string" }, + "workshopId": { + "type": "integer" + }, "workshopNumber": { "description": "杞﹂棿缂栧彿", "type": "string" @@ -3550,6 +3677,9 @@ "silkTotalAvgAmount": { "description": "涓濋噺浜哄钩鍧囨�讳环", "type": "number" + }, + "workshopId": { + "type": "integer" }, "workshopName": { "description": "杞﹂棿鍚嶇О", @@ -3825,6 +3955,9 @@ "shopName": { "type": "string" }, + "shopNumber": { + "type": "string" + }, "status": { "$ref": "#/definitions/constvar.WorkerStatus" }, @@ -4069,6 +4202,9 @@ }, "vehicleSpeed": { "type": "number" + }, + "workshopId": { + "type": "integer" }, "workshopName": { "description": "杞﹂棿鍚�", @@ -4700,6 +4836,43 @@ } } }, + "request.SavePayrollConstitute": { + "type": "object", + "properties": { + "amount": { + "description": "閲戦", + "type": "number" + }, + "cycle": { + "description": "鍛ㄦ湡锛堟湀浠斤級", + "type": "string" + }, + "salaryPlanId": { + "description": "钖祫鏂规ID", + "type": "integer" + }, + "workTypeCode": { + "description": "宸ョ浠g爜", + "allOf": [ + { + "$ref": "#/definitions/constvar.JobType" + } + ] + }, + "workTypeID": { + "description": "宸ョID", + "type": "integer" + }, + "workTypeName": { + "description": "宸ョ鍚嶇О", + "type": "string" + }, + "workerId": { + "description": "鍛樺伐ID", + "type": "string" + } + } + }, "request.SaveRankStandard": { "type": "object", "properties": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 5c36380..a3cc964 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -53,20 +53,17 @@ - 2 - 3 - 4 - - 5 type: integer x-enum-comments: DictTypeColor: 棰滆壊 DictTypeMarket: 搴勫彛 DictTypeSpec: 瑙勬牸 - DictTypeSubsidy: 琛ヨ创 DictTypeWorkshop: 杞﹂棿 x-enum-varnames: - DictTypeMarket - DictTypeWorkshop - DictTypeColor - DictTypeSpec - - DictTypeSubsidy constvar.FileTemplateCategory: enum: - 1 @@ -90,6 +87,8 @@ - machine_cleaner - all-powerful - monitor + - test + - other type: string x-enum-comments: JobTypeAllPowerful: 鍏ㄨ兘鏈哄姩 @@ -99,7 +98,9 @@ JobTypeMachineCleaner: 鎰熺煡鍣ㄦ竻娲楀伐 JobTypeMaintenance: 淇濆叏宸� JobTypeMonitor: 鐝暱 + JobTypeOther: 鍏跺畠 JobTypeScoop: 鑸�鑼у伐 + JobTypeTest: 娴嬭瘯 JobTypeTransport: 閫佽導宸� JobTypeWeavers: 鎸¤溅宸� x-enum-varnames: @@ -113,6 +114,8 @@ - JobTypeMachineCleaner - JobTypeAllPowerful - JobTypeMonitor + - JobTypeTest + - JobTypeOther constvar.MiniDictType: enum: - 1 @@ -496,6 +499,9 @@ type: object models.PayrollProductionCar: properties: + badSilkAvgQuantity: + description: 閲庣氦骞冲潎鏁伴噺 + type: number badSilkQuantity: description: 閲庣氦鏁伴噺 type: number @@ -570,6 +576,8 @@ spec: description: 瑙勬牸 type: string + workshopId: + type: integer workshopNumber: description: 杞﹂棿缂栧彿 type: string @@ -613,6 +621,8 @@ silkTotalAvgAmount: description: 涓濋噺浜哄钩鍧囨�讳环 type: number + workshopId: + type: integer workshopName: description: 杞﹂棿鍚嶇О type: string @@ -801,6 +811,8 @@ type: string shopName: type: string + shopNumber: + type: string status: $ref: '#/definitions/constvar.WorkerStatus' workType: @@ -964,6 +976,8 @@ type: string vehicleSpeed: type: number + workshopId: + type: integer workshopName: description: 杞﹂棿鍚� type: string @@ -1394,6 +1408,31 @@ type: boolean name: description: 鍚嶇О + type: string + type: object + request.SavePayrollConstitute: + properties: + amount: + description: 閲戦 + type: number + cycle: + description: 鍛ㄦ湡锛堟湀浠斤級 + type: string + salaryPlanId: + description: 钖祫鏂规ID + type: integer + workTypeCode: + allOf: + - $ref: '#/definitions/constvar.JobType' + description: 宸ョ浠g爜 + workTypeID: + description: 宸ョID + type: integer + workTypeName: + description: 宸ョ鍚嶇О + type: string + workerId: + description: 鍛樺伐ID type: string type: object request.SaveRankStandard: @@ -2593,6 +2632,58 @@ summary: 鍒犻櫎钖叕鏂规 tags: - 鍛樺伐钖祫/钖叕鏂规 + /api-jl/v1/salary/getPayrollConstituteList: + get: + parameters: + - description: token + in: header + name: Authorization + required: true + type: string + - description: 缁熻鍛ㄦ湡鎸夋湀鏌ヨ锛堝勾-鏈堬級 + in: query + name: cycle + type: string + - description: 鍏抽敭瀛� + in: query + name: keyword + type: string + - description: 椤电爜 + in: query + name: page + type: integer + - description: 姣忛〉澶у皬 + in: query + name: pageSize + type: integer + - description: 宸ョ缂栫爜 + in: query + name: workTypeCode + type: string + - description: 宸ョID + in: query + name: workTypeID + type: integer + - description: 鍛樺伐ID + in: query + name: workerID + type: string + produces: + - application/json + responses: + "200": + description: 鎴愬姛 + schema: + allOf: + - $ref: '#/definitions/util.ResponseList' + - properties: + data: + additionalProperties: true + type: object + type: object + summary: 鑾峰彇浜哄憳姣忔湀鐨勮柂璧勫垪琛� + tags: + - 鍛樺伐钖祫/钖叕鏂规 /api-jl/v1/salary/getPayrollProductionCarList: get: parameters: @@ -2821,6 +2912,30 @@ summary: 鑾峰彇钖祫绫诲瀷鍒楄〃 tags: - 鍛樺伐钖祫/钖叕鏂规 + /api-jl/v1/salary/savePayrollConstitute: + post: + parameters: + - description: 鍙傛暟 + in: body + name: object + required: true + schema: + $ref: '#/definitions/request.SavePayrollConstitute' + - description: token + in: header + name: Authorization + required: true + type: string + produces: + - application/json + responses: + "200": + description: 鎴愬姛 + schema: + $ref: '#/definitions/util.Response' + summary: 钖叕鏁伴璋冩暣 + tags: + - 鍛樺伐钖祫/钖叕鏂规 /api-jl/v1/salary/saveSalaryPlan: post: parameters: @@ -2914,7 +3029,6 @@ - 2 - 3 - 4 - - 5 in: query name: dictType type: integer @@ -2922,14 +3036,12 @@ DictTypeColor: 棰滆壊 DictTypeMarket: 搴勫彛 DictTypeSpec: 瑙勬牸 - DictTypeSubsidy: 琛ヨ创 DictTypeWorkshop: 杞﹂棿 x-enum-varnames: - DictTypeMarket - DictTypeWorkshop - DictTypeColor - DictTypeSpec - - DictTypeSubsidy - description: 鎼滅储鍏抽敭瀛� in: query name: keyword diff --git a/models/payroll_constitute.go b/models/payroll_constitute.go index b920aec..4c1d179 100644 --- a/models/payroll_constitute.go +++ b/models/payroll_constitute.go @@ -4,12 +4,13 @@ "fmt" "github.com/shopspring/decimal" "gorm.io/gorm" + "math/rand" "silkserver/constvar" "silkserver/pkg/mysqlx" ) type ( - // PayrollConstitute 鍏跺畠琛ヨ创銆佸鎯� + // PayrollConstitute 钖祫鍒嗙被椤� PayrollConstitute struct { BaseModelInt Cycle string `json:"cycle" gorm:"index;size:20;not null;comment:缁熻鍛ㄦ湡(yyyy-MM)"` //鏈堜唤 @@ -18,17 +19,19 @@ WorkTypeID uint `json:"workTypeID" gorm:"type:bigint(20);not null;comment:宸ョID"` //宸ョID WorkType WorkTypeManage `json:"workType" gorm:"foreignKey:WorkTypeID;references:ID"` //宸ョID WorkTypeCode constvar.JobType `json:"workTypeCode" gorm:"size:255;not null;comment:宸ョ浠g爜"` //宸ョ浠g爜 - WorkTypeName string `json:"workTypeName" gorm:"size:255;not null;comment:宸ョ鍚嶇О"` //宸ョ鍚嶇О + WorkTypeName string `json:"workTypeName" gorm:"size:255;comment:宸ョ鍚嶇О"` //宸ョ鍚嶇О SalaryPlanId uint `json:"salaryPlanId" gorm:"type:bigint(20);not null;comment:钖祫鏂规ID"` //钖祫鏂规ID SalaryPlan SalaryPlan `json:"subsidyTypeName" gorm:"foreignKey:SalaryPlanId;references:ID"` //钖祫鏂规 - SalaryFormula string `json:"salaryFormula" gorm:"size:255;not null;comment:钖祫鏂规(缈昏瘧)"` //钖祫鏂规 + SalaryFormula string `json:"salaryFormula" gorm:"size:255;comment:钖祫鏂规(缈昏瘧)"` //钖祫鏂规 Amount decimal.Decimal `json:"amount" gorm:"type:decimal(12,4);comment:閲戦"` // 閲戦 CreatedBy string `json:"createdBy" gorm:"size:255;not null;comment:娣诲姞鑰�"` // 娣诲姞鑰�(auto,鐢ㄦ埛id) } PayrollConstituteSearch struct { PayrollConstitute - Monthly string + Monthly string + Keyword string + Order string PageNum int PageSize int @@ -41,7 +44,7 @@ return "silk_payroll_constitute" } -// NewPayrollConstituteSearch 鍏跺畠琛ヨ创 +// NewPayrollConstituteSearch 钖祫鍒嗙被椤� func NewPayrollConstituteSearch() *PayrollConstituteSearch { return &PayrollConstituteSearch{Orm: mysqlx.GetDB()} } @@ -81,6 +84,16 @@ return slf } +func (slf *PayrollConstituteSearch) SetWorkTypeCode(workTypeCode string) *PayrollConstituteSearch { + slf.WorkTypeCode = constvar.JobType(workTypeCode) + return slf +} + +func (slf *PayrollConstituteSearch) SetSalaryPlanId(salaryPlanId uint) *PayrollConstituteSearch { + slf.SalaryPlanId = salaryPlanId + return slf +} + func (slf *PayrollConstituteSearch) SetWorkerID(workerID string) *PayrollConstituteSearch { slf.WorkerID = workerID return slf @@ -114,16 +127,25 @@ db = db.Where("work_type_id = ?", slf.WorkTypeID) } - if slf.WorkerID != "" { - db = db.Where("worker_id = ?", slf.WorkerID) + if slf.WorkTypeCode != "" { + db = db.Where("work_type_code = ?", slf.WorkTypeCode) } if slf.WorkerID != "" { db = db.Where("worker_id = ?", slf.WorkerID) + } + + if slf.SalaryPlanId > 0 { + db = db.Where("salary_plan_id = ?", slf.SalaryPlanId) } if slf.CreatedBy != "" { - db = db.Where("created_by = ?", slf.SalaryPlanId) + db = db.Where("created_by = ?", slf.CreatedBy) + } + + if slf.Keyword != "" { + key := "%" + slf.Keyword + "%" + db = db.Where("work_type_name like ?", key) } db.Where("1 = 1") @@ -304,3 +326,68 @@ return records, nil } + +type ConstituteGroup struct { + Cycle string `json:"cycle"` //鏈堜唤 + WorkerID string `json:"workerId"` //鍛樺伐ID + WorkTypeCode constvar.JobType `json:"workTypeCode"` //宸ョ浠g爜 + SalaryPlanId uint `json:"salaryPlanId"` //钖祫鏂规ID +} + +// ConstituteGroup 鏈湀缁熻浜嗗伐璧勭殑浜哄憳 +func (slf *PayrollConstituteSearch) ConstituteGroup(cg *ConstituteGroup) ([]*ConstituteGroup, error) { + var ( + records = make([]*ConstituteGroup, 0) + db = slf.Orm.Table(slf.TableName()) + ) + db.Select("cycle,worker_id,work_type_code,salary_plan_id") + db.Where("cycle = ?", cg.Cycle) + if cg.WorkerID != "" { + db.Where("worker_id = ?", cg.WorkerID) + } + if cg.WorkTypeCode != "" { + db.Where("work_type_code = ?", cg.WorkTypeCode) + } + if cg.SalaryPlanId > 0 { + db.Where("salary_plan_id = ?", cg.SalaryPlanId) + } + db.Group("cycle,worker_id,work_type_code,salary_plan_id") + + return records, db.Find(&records).Error +} + +// InitDefaultData 鍒濆鍖栨暟鎹� +func (slf *PayrollConstituteSearch) InitDefaultData() error { + var ( + db = slf.Orm.Table(slf.TableName()) + total int64 = 0 + ) + date := "2024-06" + if err := db.Where("cycle = ?", date).Count(&total).Error; err != nil { + return err + } + if total != 0 { + return nil + } + data := make([]*PayrollConstitute, 0) + workers, _ := NewWorkerSearch().FindNotTotal() + for _, record := range workers { + r := rand.Intn(10) + data = append(data, &PayrollConstitute{ + Cycle: date, + WorkerID: record.ID, + WorkTypeID: uint(r + 1), + WorkTypeCode: constvar.JobTypeArr[r], + WorkTypeName: constvar.JobTypeMap[constvar.JobTypeArr[r]], + SalaryPlanId: 7, + Amount: decimal.NewFromInt32(int32(r * 100)), + CreatedBy: "auto", + }) + } + err := slf.CreateBatch(data) + if err != nil { + return err + } + + return nil +} diff --git a/router/router.go b/router/router.go index b4fa13b..16117c4 100644 --- a/router/router.go +++ b/router/router.go @@ -104,6 +104,8 @@ salaryApi.GET("getPayrollProductionCarList", salaryPlanController.GetPayrollProductionCarList) //鑾峰彇杞﹀彴姣忓ぉ鐨勪骇閲忓垪琛� salaryApi.GET("getPayrollProductionGroupList", salaryPlanController.GetPayrollProductionGroupList) //鑾峰彇灏忕粍姣忓ぉ鐨勪骇閲忓垪琛� salaryApi.GET("getPayrollSalaryPlanList", salaryPlanController.GetPayrollSalaryPlanList) //鑾峰彇浜哄憳姣忔湀鐨勮柂璧勫垪琛� + salaryApi.POST("savePayrollConstitute", salaryPlanController.SavePayrollConstitute) //钖叕鏁伴璋冩暣 + salaryApi.GET("getPayrollConstituteList", salaryPlanController.GetPayrollConstituteList) //鑾峰彇浜哄憳姣忔湀鐨勮柂璧勫垪琛� } //鑰冨嫟绠$悊 diff --git a/service/salary_plan.go b/service/salary_plan.go index 399be70..d93c850 100644 --- a/service/salary_plan.go +++ b/service/salary_plan.go @@ -696,7 +696,8 @@ // 鏍规嵁鏂规璁$畻鍚勫伐绉嶈柂璧� func salaryCalculate(parameter *SalaryParameter, salaryPlan *models.SalaryPlan) (string, decimal.Decimal) { - formula := strings.ReplaceAll(salaryPlan.SalaryFormula, " ", "") + formula := strings.ReplaceAll(salaryPlan.SalaryFormula, ",", "") + formula = strings.ReplaceAll(salaryPlan.SalaryFormula, " ", "") //var SplitFixedField = []string{"鏃ヤ骇涓濋噺", "鐢熶笣鍗曚环", "妗舵暟", "閲庣氦鏁伴噺", "閲庣氦鍗曚环", "鍚岀粍鎸¤溅宸ユ湀骞冲潎宸ヨ祫", "鍚岀粍杞﹀ご宸ュ伐璧�", "鍑哄嫟澶╂暟"} formula = strings.Replace(formula, "鏃ヤ骇涓濋噺*鐢熶笣鍗曚环", parameter.SilkTotalAmount.String(), -1) formula = strings.Replace(formula, "閲庣氦鏁伴噺*閲庣氦鍗曚环", parameter.BadSilkTotalAmount.String(), -1) @@ -709,6 +710,8 @@ formula = strings.Replace(formula, "鍚岀粍杞﹀ご宸ュ伐璧�", parameter.GroupCarHeadAvgAmount.String(), -1) formula = strings.Replace(formula, "鍑哄嫟澶╂暟", parameter.JobDays.String(), -1) + logx.Debugf("salary formula: %v", formula) + result, err := calculator.ParseAndExec(formula) if err != nil { logx.Errorf("%s : %v", formula, err) -- Gitblit v1.8.0