From 690dd891f8ee47b6036eb87c239275490ee02b7f Mon Sep 17 00:00:00 2001
From: wanjianli <1061428287@qq.com>
Date: 星期一, 18 九月 2023 19:52:58 +0800
Subject: [PATCH] 出入库一部分代码
---
constvar/const.go | 9 ++
pkg/timex/timex.go | 28 -------
controllers/operation.go | 86 +++++++++++++++++++++
models/operation.go | 34 +++++---
request/operation.go | 26 ++++++
models/operation_details.go | 2
router/router.go | 10 ++
7 files changed, 152 insertions(+), 43 deletions(-)
diff --git a/constvar/const.go b/constvar/const.go
index dff496d..8e45297 100644
--- a/constvar/const.go
+++ b/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 //姝e湪绛夊緟
+ OperationStatus_Ready //灏辩华
+ OperationStatus_Finish //瀹屾垚
+)
diff --git a/controllers/operation.go b/controllers/operation.go
new file mode 100644
index 0000000..18a26f7
--- /dev/null
+++ b/controllers/operation.go
@@ -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, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�")
+ }
+ 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
+}
diff --git a/models/operation.go b/models/operation.go
index b1b3355..450bd27 100644
--- a/models/operation.go
+++ b/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:婧愪綅缃甶d"` //婧愪綅缃甶d
- 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:婧愪綅缃甶d"` //婧愪綅缃甶d
+ 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:鎵胯繍鍟咺D"`
+ 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:鑱旂郴浜篒D"`
+ 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 {
diff --git a/models/operation_details.go b/models/operation_details.go
index 742d651..8595052 100644
--- a/models/operation_details.go
+++ b/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"
)
diff --git a/pkg/timex/timex.go b/pkg/timex/timex.go
index c443050..68f63c9 100644
--- a/pkg/timex/timex.go
+++ b/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
}
diff --git a/request/operation.go b/request/operation.go
new file mode 100644
index 0000000..63639fc
--- /dev/null
+++ b/request/operation.go
@@ -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:婧愪綅缃甶d"` //婧愪綅缃甶d
+ 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:鏁伴噺"` //瀹屾垚鏁伴噺
+}
diff --git a/router/router.go b/router/router.go
index ac1f0c5..6da897f 100644
--- a/router/router.go
+++ b/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
}
--
Gitblit v1.8.0