constvar/const.go | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
controllers/operation.go | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
models/operation.go | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
models/operation_details.go | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
pkg/timex/timex.go | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
request/operation.go | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
router/router.go | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
constvar/const.go
@@ -127,3 +127,12 @@ func (t InventoryValuation) Valid() bool { return t >= InventoryValuationManual && t <= InventoryValuationAuto } type OperationStatus int const ( OperationStatus_Draft OperationStatus = iota + 1 //草稿 OperationStatus_Waiting //正在等待 OperationStatus_Ready //就绪 OperationStatus_Finish //完成 ) controllers/operation.go
New file @@ -0,0 +1,86 @@ package controllers import ( "errors" "github.com/gin-gonic/gin" "wms/extend/code" "wms/extend/util" "wms/models" "wms/pkg/logx" "wms/pkg/structx" "wms/request" ) type OperationController struct { } // Add // @Tags 入库/出库 // @Summary 添加入库/出库 // @Produce application/json // @Param object body request.AddOperation true "入库/出库信息" // @Success 200 {object} util.Response "成功" // @Router /api-wms/v1/operation/operation [post] func (slf OperationController) Add(c *gin.Context) { var reqParams request.AddOperation var params models.Operation if err := c.BindJSON(&reqParams); err != nil { util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") } if err := structx.AssignTo(reqParams, params); err != nil { util.ResponseFormat(c, code.RequestParamError, "数据转换错误") } if err := slf.CheckParams(params); err != nil { util.ResponseFormat(c, code.RequestParamError, err.Error()) } if err := models.NewOperationSearch().Create(¶ms); err != nil { logx.Errorf("Operation create err: %v", err) util.ResponseFormat(c, code.SaveFail, "添加失败:"+err.Error()) } util.ResponseFormat(c, code.Success, "添加成功") } func (slf OperationController) CheckParams(params models.Operation) error { if params.SourceNumber == "" { return errors.New("请填入源单号") } if params.OperationTypeId == 0 { return errors.New("operationTypeId为0") } if params.FromLocationId == 0 { return errors.New("请选择源位置") } if params.ToLocationId == 0 { return errors.New("请选择目标位置") } if params.OperationDate.IsZero() { return errors.New("请选择安排日期") } if len(params.Details) <= 0 { return errors.New("请添加明细信息") } //检查明细部分 for _, v := range params.Details { if v.ProductId == 0 { return errors.New("productID为0") } if v.ProductName == "" { return errors.New("产品名称异常") } if v.Quantity.IsNegative() { return errors.New("产品数量出错") } if v.FinishQuantity.IsNegative() { return errors.New("产品数量出错") } } return nil } models/operation.go
@@ -4,6 +4,7 @@ "fmt" "gorm.io/gorm" "wms/constvar" "wms/extend/util" "wms/pkg/mysqlx" ) @@ -11,19 +12,26 @@ // Operation 操作表 Operation struct { WmsModel Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` Number string `json:"number" gorm:"column:number;type:varchar(255)"` //单号 SourceNumber string `json:"sourceNumber" gorm:"type:varchar(255)"` //源单号 BaseOperationType constvar.BaseOperationType `json:"baseOperationType" gorm:"type:tinyint;not null;comment:基础作业类型"` //基础作业类型 OperationTypeId int `json:"operationTypeId" gorm:"type:int;not null;comment:作业类型id"` //作业类型id Status int `json:"status" gorm:"type:tinyint;not null;comment:状态"` //状态 FromLocationId int `json:"fromLocationId" gorm:"type:int;not null;comment:源位置id"` //源位置id FromLocation Location `json:"fromLocation" gorm:"foreignKey:FromLocationId"` //源位置 ToLocationId int `json:"toLocationId" gorm:"type:int;not null;comment:目标位置id"` //目标位置id ToLocation Location `json:"toLocation" gorm:"foreignKey:ToLocationId"` //目标位置 Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` Number string `json:"number" gorm:"column:number;type:varchar(255)"` //单号 SourceNumber string `json:"sourceNumber" gorm:"type:varchar(255)"` //源单号 OperationTypeId int `json:"operationTypeId" gorm:"type:int;not null;comment:作业类型id"` //作业类型id Status constvar.OperationStatus `json:"status" gorm:"type:int(11);not null;comment:状态"` //状态 FromLocationId int `json:"fromLocationId" gorm:"type:int;not null;comment:源位置id"` //源位置id FromLocation Location `json:"fromLocation" gorm:"foreignKey:FromLocationId"` //源位置 ToLocationId int `json:"toLocationId" gorm:"type:int;not null;comment:目标位置id"` //目标位置id ToLocation Location `json:"toLocation" gorm:"foreignKey:ToLocationId"` //目标位置 OperationDate util.JSONTime `json:"operationDate" gorm:"comment:安排日期"` CarrierID int `json:"carrierID" gorm:"type:int;comment:承运商ID"` CarrierName string `json:"carrierName" gorm:"type:varchar(63);comment:承运商名称"` Tracking string `json:"tracking" gorm:"type:varchar(127);comment:追踪参考"` ContacterID int `json:"contacterID" gorm:"type:int;comment:联系人ID"` ContacterName string `json:"contacterName" gorm:"type:varchar(63);comment:联系人姓名"` Weight float64 `json:"weight" gorm:"type:decimal;comment:重量(kg)"` TransferWeight float64 `json:"transferWeight" gorm:"type:decimal;comment:物流重量(kg)"` CompanyID int `json:"companyID" gorm:"type:int;comment:公司ID"` CompanyName string `json:"companyName" gorm:"type:varchar(127);comment:公司名称(kg)"` Details []*OperationDetails `json:"details"` } OperationSearch struct { models/operation_details.go
@@ -2,7 +2,7 @@ import ( "fmt" "google.golang.org/genproto/googleapis/type/decimal" "github.com/shopspring/decimal" "gorm.io/gorm" "wms/pkg/mysqlx" ) pkg/timex/timex.go
@@ -2,7 +2,6 @@ import ( "time" "wms/constvar" ) func StringToTime(timeStr string) (time.Time, error) { @@ -56,31 +55,4 @@ func GetCurrentTime() string { return time.Now().Format(timeLayout) } func NextDateTimestamp(base time.Time, unit constvar.InspectCycleUnit, cycle int) time.Time { var t time.Time switch unit { case constvar.InspectCycleUnitWeek: t = base.AddDate(0, 0, cycle*7) case constvar.InspectCycleUnitMonth: t = base.AddDate(0, cycle, 0) case constvar.InspectCycleUnitDay: t = base.AddDate(0, 0, cycle) } return time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, t.Location()) } // Cycle2Seconds 周期换算成秒数 func Cycle2Seconds(unit constvar.InspectCycleUnit, cycle int) int { var s int switch unit { case constvar.InspectCycleUnitWeek: s = cycle * 86400 * 7 case constvar.InspectCycleUnitMonth: s = cycle * 86400 * 30 case constvar.InspectCycleUnitDay: s = cycle * 86400 } return s } request/operation.go
New file @@ -0,0 +1,26 @@ package request import ( "google.golang.org/genproto/googleapis/type/decimal" "wms/constvar" "wms/extend/util" ) type AddOperation struct { Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` Number string `json:"number" gorm:"column:number;type:varchar(255)"` //单号 SourceNumber string `json:"sourceNumber" gorm:"type:varchar(255)"` //源单号 OperationTypeId int `json:"operationTypeId" gorm:"type:int;not null;comment:作业类型id"` //作业类型id Status constvar.OperationStatus `json:"status" gorm:"type:int(11);not null;comment:状态"` //状态 FromLocationId int `json:"fromLocationId" gorm:"type:int;not null;comment:源位置id"` //源位置id ToLocationId int `json:"toLocationId" gorm:"type:int;not null;comment:目标位置id"` //目标位置id OperationDate util.JSONTime `json:"operationDate" gorm:"comment:安排日期"` Details []*OperationDetails `json:"details"` } type OperationDetails struct { ProductId int `json:"productId" gorm:"type:int;not null;comment:产品id"` //产品id ProductName string `json:"productName" gorm:"type:varchar(255);not null;comment:产品名称"` //产品名称 Quantity decimal.Decimal `json:"quantity" gorm:"type:decimal(20,2);not null;comment:数量"` //数量 FinishQuantity decimal.Decimal `json:"finishQuantity" gorm:"type:decimal(20,2);not null;comment:数量"` //完成数量 } router/router.go
@@ -53,7 +53,7 @@ // 作业类型 operationTypeController := new(controllers.OperationTypeController) operationTypeAPI := r.Group(urlPrefix + "/warehouse") operationTypeAPI := r.Group(urlPrefix + "/operationType") { operationTypeAPI.GET("operationType", operationTypeController.List) // 获取作业类型列表 operationTypeAPI.POST("operationType", operationTypeController.Add) // 新增作业类型 @@ -61,5 +61,13 @@ operationTypeAPI.DELETE("operationType/:id", operationTypeController.Delete) // 删除作业类型 } // 入库/出库 operationController := new(controllers.OperationController) operationAPI := r.Group(urlPrefix + "/operation") { //operationAPI.GET() operationAPI.POST("operation", operationController.Add) } return r }