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

---
 models/worker_position.go |   24 ++++++++++++++++++------
 1 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/models/worker_position.go b/models/worker_position.go
index 0c3653d..07a9861 100644
--- a/models/worker_position.go
+++ b/models/worker_position.go
@@ -23,12 +23,14 @@
 	}
 	WorkerPositionSearch struct {
 		WorkerPosition
-		Order    string
-		PageNum  int
-		PageSize int
-		Orm      *gorm.DB
-		Preload  bool
-		Keyword  string
+		Order                string
+		PageNum              int
+		PageSize             int
+		Orm                  *gorm.DB
+		Preload              bool
+		Keyword              string
+		OverlappingDateStart string
+		OverlappingDateEnd   string
 	}
 )
 
@@ -85,6 +87,12 @@
 	return slf
 }
 
+func (slf *WorkerPositionSearch) SetOverlappingDate(startDate string, endDate string) *WorkerPositionSearch {
+	slf.OverlappingDateStart = startDate
+	slf.OverlappingDateEnd = endDate
+	return slf
+}
+
 func (slf *WorkerPositionSearch) build() *gorm.DB {
 	var db = slf.Orm.Table(slf.TableName())
 
@@ -117,6 +125,10 @@
 		db = db.Model(&WorkerPosition{}).Preload("Worker")
 	}
 
+	if slf.OverlappingDateStart != "" && slf.OverlappingDateEnd != "" {
+		db = db.Where("start_date <=  ? and end_date >= ?", slf.OverlappingDateEnd, slf.OverlappingDateStart)
+	}
+
 	return db
 }
 

--
Gitblit v1.8.0