zhangqian
2024-04-28 d6aea9913510936bde157e22a1f7042a0eb33ac3
时间范围和该工人以往添加记录重复性校验
1个文件已添加
3个文件已修改
44 ■■■■ 已修改文件
controllers/mentor_controller.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/request/fineness.go 12 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/worker_position_controller.go 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
utils/timex.go 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/mentor_controller.go
@@ -116,7 +116,7 @@
        util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误")
        return
    }
    mentors, total, err := models.NewMentorSearch().SetPage(params.Page, params.PageSize).SetKeyword(params.Keyword).SetPreload(true).Find()
    mentors, total, err := models.NewMentorSearch().SetPage(params.Page, params.PageSize).SetKeyword(params.Keyword).SetPreload(true).SetOrder("id desc").Find()
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "查询失败")
        return
controllers/request/fineness.go
@@ -5,18 +5,18 @@
)
type AddFinenessRegister struct {
    ID            uint            `json:"id"`                                                                //id 添加时传0
    ID            uint            `json:"id"`                                                              //id 添加时传0
    Number        string          `gorm:"type:varchar(255);not null;comment:编号" json:"number"`             //编号
    FinishDate    string          `gorm:"type:varchar(255);not null;comment:落丝时间" json:"finishDate"`     //落丝时间
    FinishDate    string          `gorm:"type:varchar(255);not null;comment:落丝时间" json:"finishDate"`       //落丝时间
    Workshop      string          `gorm:"type:varchar(255);not null;comment:车间" json:"name"`               //车间
    WorkshopGroup int             `gorm:"type:int(11);not null;default:0;comment:车组" json:"workshopGroup"` //车组
    Market        string          `gorm:"type:varchar(255);not null;comment:庄口" json:"market"`             //庄口
    Spec          string          `gorm:"type:varchar(255);not null;comment:规格" json:"spec"`               //规格
    Circle        uint8           `gorm:"not null;comment:回数" json:"circle"`                               //回数
    TotalCircle   uint8           `gorm:"not null;comment:总回数" json:"totalCircle"`                        //总回数
    FinenessList  []FinenessItem  `json:"finenessList"`                                                      //纤度数组
    SumFineness   decimal.Decimal `gorm:"type:decimal(12,2);not null;comment:合计纤度" json:"sumFineness"`   //合计纤度
    SumQuantity   decimal.Decimal `gorm:"type:decimal(12,2);not null;comment:合计数量" json:"sumQuantity"`   //合计数量
    TotalCircle   uint8           `gorm:"not null;comment:总回数" json:"totalCircle"`                         //总回数
    FinenessList  []FinenessItem  `json:"finenessList"`                                                    //纤度数组
    SumFineness   decimal.Decimal `gorm:"type:decimal(12,2);not null;comment:合计纤度" json:"sumFineness"`     //合计纤度
    SumQuantity   decimal.Decimal `gorm:"type:decimal(12,2);not null;comment:合计数量" json:"sumQuantity"`     //合计数量
    Position      int             `gorm:"not null;default:0;comment:车号" json:"position"`                   //最后一个车号
}
controllers/worker_position_controller.go
@@ -3,12 +3,12 @@
import (
    "github.com/gin-gonic/gin"
    "github.com/spf13/cast"
    "gorm.io/gorm"
    "silkserver/controllers/request"
    "silkserver/extend/code"
    "silkserver/extend/util"
    "silkserver/middleware"
    "silkserver/models"
    "silkserver/utils"
)
type WorkerPositionController struct {
@@ -31,10 +31,12 @@
    }
    //查询是否重复
    _, err = models.NewWorkerPositionSearch().SetWorkerID(params.WorkerId).First()
    if err != gorm.ErrRecordNotFound {
        util.ResponseFormat(c, code.RequestParamError, "请勿重复添加")
        return
    old, err := models.NewWorkerPositionSearch().SetWorkerID(params.WorkerId).First()
    if err == nil {
        if utils.IsOverlap(params.StartDate, params.EndDate, old.StartDate, old.EndDate) {
            util.ResponseFormat(c, code.RequestParamError, "请勿重复添加")
            return
        }
    }
    record := &models.WorkerPosition{
utils/timex.go
New file
@@ -0,0 +1,18 @@
package utils
import "time"
// IsOverlap 判断两个时间段是否有重叠
func IsOverlap(start1, end1, start2, end2 string) bool {
    layout := "2006-01-02"
    startTime1, _ := time.Parse(layout, start1)
    endTime1, _ := time.Parse(layout, end1)
    startTime2, _ := time.Parse(layout, start2)
    endTime2, _ := time.Parse(layout, end2)
    // 如果一个时间段的开始时间在另一个时间段之后,或结束时间在另一个时间段之前,则无重叠
    if startTime1.After(endTime2) || endTime1.Before(startTime2) {
        return false
    }
    return true
}