From cc7c2094568ea8f9d1697da5ed0a2c759ca81abd Mon Sep 17 00:00:00 2001 From: yinbentan <yinbentan@live.com> Date: 星期五, 30 八月 2024 17:18:30 +0800 Subject: [PATCH] 方法修改,修改薪资列表,添加分页查询 --- models/payroll_constitute.go | 66 +++++++++++++++++++++++---------- 1 files changed, 46 insertions(+), 20 deletions(-) diff --git a/models/payroll_constitute.go b/models/payroll_constitute.go index 4c1d179..38cf0fa 100644 --- a/models/payroll_constitute.go +++ b/models/payroll_constitute.go @@ -29,8 +29,9 @@ PayrollConstituteSearch struct { PayrollConstitute - Monthly string - Keyword string + Monthly string + WorkerIDs []string + Keyword string Order string PageNum int @@ -99,6 +100,11 @@ return slf } +func (slf *PayrollConstituteSearch) SetWorkerIDs(workerIds []string) *PayrollConstituteSearch { + slf.WorkerIDs = workerIds + return slf +} + func (slf *PayrollConstituteSearch) SetCreatedBy(createdBy string) *PayrollConstituteSearch { slf.CreatedBy = createdBy return slf @@ -108,7 +114,7 @@ var db = slf.Orm.Table(slf.TableName()) if slf.Preload { - db = db.Model(&PayrollConstitute{}).Preload("Worker").Preload("WorkType").Preload("WorkType.SalaryPlan") + db = db.Model(&PayrollConstitute{}).Preload("Worker").Preload("WorkType.SalaryPlan") } if slf.ID > 0 { @@ -121,6 +127,10 @@ if slf.Monthly != "" { db = db.Where("cycle like ?", slf.Monthly+"%") + } + + if len(slf.WorkerIDs) > 0 { + db = db.Where("Worker_id in ?", slf.WorkerIDs) } if slf.WorkTypeID > 0 { @@ -327,31 +337,47 @@ 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 -} +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) { + ConstituteGroupSearch struct { + ConstituteGroup + + WorkerIDs []string `json:"workerIds"` + PageNum int `json:"pageNum"` + PageSize int `json:"pageSize"` + } +) + +// ConstituteGroup 姣忔湀缁熻宸ヨ祫鐨勫憳宸� +func (slf *PayrollConstituteSearch) ConstituteGroup(cg *ConstituteGroupSearch) ([]*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) + db = db.Select("cycle,worker_id,work_type_code,salary_plan_id") + db = db.Where("cycle = ?", cg.Cycle) if cg.WorkerID != "" { - db.Where("worker_id = ?", cg.WorkerID) + db = db.Where("worker_id = ?", cg.WorkerID) + } + if len(cg.WorkerIDs) > 0 { + db = db.Where("worker_id in ?", cg.WorkerIDs) } if cg.WorkTypeCode != "" { - db.Where("work_type_code = ?", cg.WorkTypeCode) + db = db.Where("work_type_code = ?", cg.WorkTypeCode) } if cg.SalaryPlanId > 0 { - db.Where("salary_plan_id = ?", cg.SalaryPlanId) + db = db.Where("salary_plan_id = ?", cg.SalaryPlanId) } - db.Group("cycle,worker_id,work_type_code,salary_plan_id") + db = db.Group("cycle,worker_id,work_type_code,salary_plan_id").Order("salary_plan_id,worker_id") + /* if cg.PageNum*cg.PageSize > 0 { + db = db.Offset((cg.PageNum - 1) * cg.PageSize).Limit(cg.PageSize) + }*/ return records, db.Find(&records).Error } @@ -362,8 +388,8 @@ db = slf.Orm.Table(slf.TableName()) total int64 = 0 ) - date := "2024-06" - if err := db.Where("cycle = ?", date).Count(&total).Error; err != nil { + date := "2024-07" + if err := db.Where("cycle = ? and salary_plan_id = 5", date).Count(&total).Error; err != nil { return err } if total != 0 { @@ -379,7 +405,7 @@ WorkTypeID: uint(r + 1), WorkTypeCode: constvar.JobTypeArr[r], WorkTypeName: constvar.JobTypeMap[constvar.JobTypeArr[r]], - SalaryPlanId: 7, + SalaryPlanId: 5, Amount: decimal.NewFromInt32(int32(r * 100)), CreatedBy: "auto", }) -- Gitblit v1.8.0