| | |
| | | import ( |
| | | "github.com/gin-gonic/gin" |
| | | "github.com/spf13/cast" |
| | | "gorm.io/gorm" |
| | | "silkserver/controllers/request" |
| | | "silkserver/extend/code" |
| | | "silkserver/extend/util" |
| | |
| | | } |
| | | |
| | | //查询是否重复 |
| | | _, err = models.NewWorkerPositionSearch().SetWorkerID(params.WorkerId).First() |
| | | if err != gorm.ErrRecordNotFound { |
| | | util.ResponseFormat(c, code.RequestParamError, "请勿重复添加") |
| | | _, err = models.NewWorkerPositionSearch().SetWorkerID(params.WorkerId).SetOverlappingDate(params.StartDate, params.EndDate).First() |
| | | if err == nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "时间范围和该工人以往添加记录有重复,请检查") |
| | | return |
| | | } |
| | | |
| | |
| | | return |
| | | } |
| | | |
| | | //查询是否重复 |
| | | old, err := models.NewWorkerPositionSearch().SetWorkerID(params.WorkerId).First() |
| | | if err == nil { |
| | | if old.ID != params.Id { |
| | | util.ResponseFormat(c, code.RequestParamError, "时间范围和该工人以往添加记录有重复,请检查") |
| | | return |
| | | } |
| | | } |
| | | |
| | | record := &models.WorkerPosition{ |
| | | StartDate: params.StartDate, |
| | | EndDate: params.EndDate, |
| | |
| | | util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | return |
| | | } |
| | | WorkerPositions, total, err := models.NewWorkerPositionSearch().SetPage(params.Page, params.PageSize).SetKeyword(params.Keyword).SetPreload().Find() |
| | | WorkerPositions, total, err := models.NewWorkerPositionSearch().SetPage(params.Page, params.PageSize).SetKeyword(params.Keyword).SetPreload().SetOrder("id desc").Find() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "查询失败") |
| | | return |