| | |
| | | BaseOperationTypeIncoming BaseOperationType = iota + 1 //收货 |
| | | BaseOperationTypeOutgoing //交货 |
| | | BaseOperationTypeInternal //内部调拨 |
| | | BaseOperationTypeDisuse //报废 |
| | | BaseOperationTypeAdjust //库存盘点 |
| | | ) |
| | | |
| | | func (slf BaseOperationType) IsValid() bool { |
New file |
| | |
| | | package controllers |
| | | |
| | | import ( |
| | | "github.com/gin-gonic/gin" |
| | | "strconv" |
| | | "wms/extend/code" |
| | | "wms/extend/util" |
| | | "wms/models" |
| | | "wms/pkg/logx" |
| | | "wms/pkg/structx" |
| | | "wms/request" |
| | | ) |
| | | |
| | | type LocationProductController struct { |
| | | } |
| | | |
| | | // Add |
| | | // @Tags 上架规则 |
| | | // @Summary 添加上架规则 |
| | | // @Produce application/json |
| | | // @Param object body request.AddLocationProduct true "新增上架规则" |
| | | // @Success 200 {object} util.Response "成功" |
| | | // @Router /api-wms/v1/locationProduct/add [post] |
| | | func (slf LocationProductController) Add(c *gin.Context) { |
| | | var reqParams request.AddLocationProduct |
| | | var params models.LocationProduct |
| | | if err := c.BindJSON(&reqParams); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | return |
| | | } |
| | | if err := structx.AssignTo(reqParams, ¶ms); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "数据转换错误"+err.Error()) |
| | | return |
| | | } |
| | | if params.AreaId == 0 { |
| | | util.ResponseFormat(c, code.RequestParamError, "请选择区域") |
| | | return |
| | | } |
| | | if params.LocationId == 0 { |
| | | util.ResponseFormat(c, code.RequestParamError, "请选择位置") |
| | | return |
| | | } |
| | | if params.ProductId == "" { |
| | | util.ResponseFormat(c, code.RequestParamError, "请选择产品") |
| | | return |
| | | } |
| | | if params.ProductCategoryID == 0 { |
| | | util.ResponseFormat(c, code.RequestParamError, "请选择产品类别") |
| | | return |
| | | } |
| | | if err := models.NewLocationProductSearch().Create(¶ms); err != nil { |
| | | logx.Errorf("Operation create err: %v", err) |
| | | util.ResponseFormat(c, code.SaveFail, "添加失败:"+err.Error()) |
| | | return |
| | | } |
| | | util.ResponseFormat(c, code.Success, "添加成功") |
| | | } |
| | | |
| | | // List |
| | | // @Tags 上架规则 |
| | | // @Summary 上架规则列表 |
| | | // @Produce application/json |
| | | // @Param object body request.PageInfo true "查询参数" |
| | | // @Success 200 {object} util.Response "成功" |
| | | // @Router /api-wms/v1/locationProduct/list [post] |
| | | func (slf LocationProductController) List(c *gin.Context) { |
| | | var params request.PageInfo |
| | | if err := c.BindJSON(¶ms); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误:"+err.Error()) |
| | | return |
| | | } |
| | | if params.Check() { |
| | | util.ResponseFormat(c, code.RequestParamError, "参数异常") |
| | | return |
| | | } |
| | | |
| | | search := models.NewLocationProductSearch() |
| | | search.SetPage(params.Page, params.PageSize) |
| | | list, total, err := search.SetPreload(true).SetOrder("created_at desc").FindByPage() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestError, "查找失败:"+err.Error()) |
| | | return |
| | | } |
| | | |
| | | util.ResponseFormatListWithPage(c, code.Success, list, int(total), params.Page, params.PageSize) |
| | | } |
| | | |
| | | // Update |
| | | // @Tags 上架规则 |
| | | // @Summary 修改上架规则 |
| | | // @Produce application/json |
| | | // @Param object body request.UpdateLocationProduct true "入库信息" |
| | | // @Success 200 {object} util.Response "成功" |
| | | // @Router /api-wms/v1/locationProduct/update [post] |
| | | func (slf LocationProductController) Update(c *gin.Context) { |
| | | var reqParams request.UpdateLocationProduct |
| | | var params models.LocationProduct |
| | | if err := c.BindJSON(&reqParams); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误:"+err.Error()) |
| | | return |
| | | } |
| | | if reqParams.Id == 0 { |
| | | util.ResponseFormat(c, code.RequestParamError, "id为0") |
| | | return |
| | | } |
| | | if err := structx.AssignTo(reqParams, ¶ms); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "数据转换错误"+err.Error()) |
| | | return |
| | | } |
| | | if params.AreaId == 0 { |
| | | util.ResponseFormat(c, code.RequestParamError, "请选择区域") |
| | | return |
| | | } |
| | | if params.LocationId == 0 { |
| | | util.ResponseFormat(c, code.RequestParamError, "请选择位置") |
| | | return |
| | | } |
| | | if params.ProductId == "" { |
| | | util.ResponseFormat(c, code.RequestParamError, "请选择产品") |
| | | return |
| | | } |
| | | if params.ProductCategoryID == 0 { |
| | | util.ResponseFormat(c, code.RequestParamError, "请选择产品类别") |
| | | return |
| | | } |
| | | if err := models.NewLocationProductSearch().SetID(params.Id).Update(¶ms); err != nil { |
| | | logx.Errorf("LocationProduct update err: %v", err) |
| | | util.ResponseFormat(c, code.SaveFail, "修改失败:"+err.Error()) |
| | | return |
| | | } |
| | | |
| | | util.ResponseFormat(c, code.Success, "修改成功") |
| | | } |
| | | |
| | | // Delete |
| | | // |
| | | // @Tags 上架规则 |
| | | // @Summary 删除上架规则 |
| | | // @Produce application/json |
| | | // @Param id path int true "id" |
| | | // @Success 200 {object} util.Response "成功" |
| | | // @Router /api-wms/v1/locationProduct/delete/{id} [delete] |
| | | func (slf LocationProductController) Delete(c *gin.Context) { |
| | | id, err := strconv.Atoi(c.Param("id")) |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "错误的id值") |
| | | return |
| | | } |
| | | if id == 0 { |
| | | util.ResponseFormat(c, code.RequestParamError, "id为0") |
| | | return |
| | | } |
| | | //TODO:此处可能需要增加限制,如果该上架规则如果已经产生了库存数量,删除会造成库存查不到的影响 |
| | | if err := models.NewLocationProductSearch().SetID(id).Delete(); err != nil { |
| | | logx.Errorf("LocationProduct delete err: %v", err) |
| | | util.ResponseFormat(c, code.SaveFail, "删除失败:"+err.Error()) |
| | | return |
| | | } |
| | | util.ResponseFormat(c, code.Success, "删除成功") |
| | | } |
New file |
| | |
| | | package controllers |
| | | |
| | | import ( |
| | | "fmt" |
| | | "github.com/gin-gonic/gin" |
| | | "wms/constvar" |
| | | "wms/extend/code" |
| | | "wms/extend/util" |
| | | "wms/models" |
| | | "wms/request" |
| | | ) |
| | | |
| | | type LocationProductAmountController struct { |
| | | } |
| | | |
| | | // List |
| | | // @Tags 库存盘点 |
| | | // @Summary 库存盘点列表 |
| | | // @Produce application/json |
| | | // @Param object body request.PageInfo true "查询参数" |
| | | // @Success 200 {object} util.Response "成功" |
| | | // @Router /api-wms/v1/locationProduct/list [post] |
| | | func (slf LocationProductAmountController) List(c *gin.Context) { |
| | | var params request.PageInfo |
| | | if err := c.BindJSON(¶ms); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误:"+err.Error()) |
| | | return |
| | | } |
| | | if params.Check() { |
| | | util.ResponseFormat(c, code.RequestParamError, "参数异常") |
| | | return |
| | | } |
| | | |
| | | search := models.NewLocationProductAmountSearch() |
| | | search.SetPage(params.Page, params.PageSize) |
| | | |
| | | search.Orm = search.Orm.Model(&models.LocationProductAmountWithOperation{}).Table("wms_location_product_amount").Select("wms_location_product_amount.*,wms_operation.amount as adjust_amount").InnerJoins("inner join wms_location_product on wms_location_product.id=wms_location_product_amount.location_product_id").InnerJoins("inner join wms_operation_details on wms_operation_details.product_id=wms_location_product.product_id").InnerJoins("inner join wms_operation on wms_operation.id=wms_operation_details.operation_id").Where("wms_operation.base_operation_type=?", constvar.BaseOperationTypeAdjust) |
| | | |
| | | var ( |
| | | records = make([]*models.ResponseDisuseList, 0) |
| | | total int64 |
| | | ) |
| | | |
| | | if err := search.Orm.Count(&total).Error; err != nil { |
| | | util.ResponseFormat(c, code.RequestError, fmt.Errorf("find count err: %v", err)) |
| | | return |
| | | } |
| | | search.Orm = search.Orm.Preload("LocationProduct").Preload("LocationProduct.Location").Preload("LocationProduct.Product") |
| | | if params.Page*params.PageSize > 0 { |
| | | search.Orm = search.Orm.Offset((params.Page - 1) * params.PageSize).Limit(params.PageSize) |
| | | } |
| | | if err := search.Orm.Find(&records).Error; err != nil { |
| | | util.ResponseFormat(c, code.RequestError, fmt.Errorf("find count err: %v", err)) |
| | | return |
| | | } |
| | | |
| | | util.ResponseFormatListWithPage(c, code.Success, records, int(total), params.Page, params.PageSize) |
| | | } |
| | | |
| | | // Add |
| | | // @Tags 库存盘点 |
| | | // @Summary 添加库存盘点信息 |
| | | // @Produce application/json |
| | | // @Param object body request.AddLocationProductAmount true "入库/出库信息" |
| | | // @Success 200 {object} util.Response "成功" |
| | | // @Router /api-wms/v1/operation/operation [post] |
| | | //func (slf LocationProductAmountController) Add(c *gin.Context) { |
| | | // var reqParams request.AddLocationProductAmount |
| | | // if err := c.BindJSON(&reqParams); err != nil { |
| | | // util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | // return |
| | | // } |
| | | // if reqParams.LocationProductAmountId==0 { |
| | | // util.ResponseFormat(c, code.RequestParamError, "参数异常,locationProductAmountId为0") |
| | | // return |
| | | // } |
| | | // locAmount:=models.LocationProductAmount{ |
| | | // LocationProductId: reqParams.LocationProductAmountId |
| | | // } |
| | | // operationType, err := models.NewOperationTypeSearch().SetID(uint(params.OperationTypeId)).First() |
| | | // if err != nil { |
| | | // util.ResponseFormat(c, code.RequestParamError, err.Error()) |
| | | // return |
| | | // } |
| | | // ////// |
| | | // if location, err := models.NewLocationSearch().SetType(int(constvar.LocationTypeCustomer)).First(); err != nil { |
| | | // return err |
| | | // } else { |
| | | // params.ToLocationID = location.Id |
| | | // } |
| | | // |
| | | // |
| | | // params.Status = constvar.OperationStatus_Ready |
| | | // params.Number = strconv.FormatInt(time.Now().Unix(), 10) |
| | | // params.BaseOperationType = operationType.BaseOperationType |
| | | // if err := models.NewOperationSearch().Create(¶ms); err != nil { |
| | | // logx.Errorf("Operation create err: %v", err) |
| | | // util.ResponseFormat(c, code.SaveFail, "添加失败:"+err.Error()) |
| | | // return |
| | | // } |
| | | // util.ResponseFormat(c, code.Success, "添加成功") |
| | | //} |
| | |
| | | util.ResponseFormat(c, code.RequestParamError, err.Error()) |
| | | return |
| | | } |
| | | operationType, err := models.NewOperationTypeSearch().SetID(uint(params.OperationTypeId)).First() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, err.Error()) |
| | | return |
| | | } |
| | | |
| | | params.Status = constvar.OperationStatus_Ready |
| | | params.Number = strconv.FormatInt(time.Now().Unix(), 10) |
| | | params.BaseOperationType = operationType.BaseOperationType |
| | | if err := models.NewOperationSearch().Create(¶ms); err != nil { |
| | | logx.Errorf("Operation create err: %v", err) |
| | | util.ResponseFormat(c, code.SaveFail, "添加失败:"+err.Error()) |
| | |
| | | if err := tx.Save(listProdt[k]).Error; err != nil { |
| | | return err |
| | | } |
| | | //TODO:出入库的finish和报废的finish都要增加对location_product_amount表数量的更新,因为此表有ProductCategory字段,所以operation_details表中要增加ProductCategoryId字段 |
| | | //var locAmount models.LocationProductAmount |
| | | //if err := models.NewLocationProductAmountSearch().Orm.Table("wms_location_produt_amount").Joins("inner join wms_location_product on wms_location_produt.id=wms_location_produt_amount.location_product_id").Where("wms_location_produt.product_id=? and wms_location_produt.location_id=?",operation.ToLocationID,v.ID).First(&locAmount).Error;err!=nil { |
| | | // return err |
| | | //} |
| | | } |
| | | } |
| | | |
| | | } |
| | | if operationType.BaseOperationType == constvar.BaseOperationTypeOutgoing { |
| | | for k, v := range listProdt { |
| | |
| | | } |
| | | detail := &models.OperationDetails{ |
| | | ProductId: params.ProductId, |
| | | //ProductName: params.ProductName, |
| | | Amount: params.Amount, |
| | | //Unit: params.Unit, |
| | | } |
| | | operation := models.Operation{ |
| | | Number: strconv.FormatInt(time.Now().Unix(), 10), |
| | |
| | | ToLocationID: params.ToLocationId, |
| | | OperationDate: time.Now().Format("2006-01-02 15:04:05"), |
| | | Details: []*models.OperationDetails{detail}, |
| | | BaseOperationType: constvar.BaseOperationTypeDisuse, |
| | | } |
| | | if err := models.NewOperationSearch().Create(&operation); err != nil { |
| | | logx.Errorf("Operation create err: %v", err) |
New file |
| | |
| | | package models |
| | | |
| | | import ( |
| | | "fmt" |
| | | "gorm.io/gorm" |
| | | "wms/pkg/mysqlx" |
| | | ) |
| | | |
| | | type ( |
| | | LocationProduct struct { |
| | | WmsModel |
| | | Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` |
| | | LocationId int `json:"locationId" gorm:"type:int;not null;comment:位置id"` //位置id |
| | | Location Location `json:"location" gorm:"foreignKey:LocationId;references:id"` |
| | | AreaId int `json:"areaId" grom:"type:int;not null;comment:区域id"` //区域id |
| | | Area Location `json:"area" gorm:"foreignKey:AreaId;references:id"` |
| | | ProductCategoryID int `json:"productCategoryId" gorm:"type:int;not null;comment:产品种类id"` //产品种类id |
| | | ProductCategory ProductCategory `json:"productCategory"` |
| | | ProductId string `json:"productId" gorm:"type:varchar(191);not null;comment:产品id"` //产品id |
| | | Product Material `json:"product" gorm:"foreignKey:ProductId;references:ID"` |
| | | } |
| | | |
| | | LocationProductSearch struct { |
| | | LocationProduct |
| | | Order string |
| | | PageNum int |
| | | PageSize int |
| | | Keyword string |
| | | Orm *gorm.DB |
| | | Preload bool |
| | | } |
| | | ) |
| | | |
| | | func (slf *LocationProduct) TableName() string { |
| | | return "wms_location_product" |
| | | } |
| | | |
| | | func NewLocationProductSearch() *LocationProductSearch { |
| | | return &LocationProductSearch{Orm: mysqlx.GetDB()} |
| | | } |
| | | |
| | | func (slf *LocationProductSearch) SetOrm(tx *gorm.DB) *LocationProductSearch { |
| | | slf.Orm = tx |
| | | return slf |
| | | } |
| | | |
| | | func (slf *LocationProductSearch) SetPage(page, size int) *LocationProductSearch { |
| | | slf.PageNum, slf.PageSize = page, size |
| | | return slf |
| | | } |
| | | |
| | | func (slf *LocationProductSearch) SetOrder(order string) *LocationProductSearch { |
| | | slf.Order = order |
| | | return slf |
| | | } |
| | | |
| | | func (slf *LocationProductSearch) SetID(id int) *LocationProductSearch { |
| | | slf.Id = id |
| | | return slf |
| | | } |
| | | |
| | | func (slf *LocationProductSearch) SetKeyword(keyword string) *LocationProductSearch { |
| | | slf.Keyword = keyword |
| | | return slf |
| | | } |
| | | |
| | | func (slf *LocationProductSearch) SetPreload(preload bool) *LocationProductSearch { |
| | | slf.Preload = preload |
| | | return slf |
| | | } |
| | | |
| | | func (slf *LocationProductSearch) build() *gorm.DB { |
| | | var db = slf.Orm.Model(&LocationProduct{}) |
| | | |
| | | if slf.Id != 0 { |
| | | db = db.Where("id = ?", slf.Id) |
| | | } |
| | | if slf.Order != "" { |
| | | db = db.Order(slf.Order) |
| | | } |
| | | |
| | | if slf.Keyword != "" { |
| | | db = db.Where("product_name like ?", fmt.Sprintf("%%%v%%", slf.Keyword)) |
| | | } |
| | | |
| | | if slf.Preload { |
| | | db = db.Model(&LocationProduct{}).Preload("Location").Preload("Area").Preload("ProductCategory").Preload("Product") |
| | | } |
| | | |
| | | return db |
| | | } |
| | | |
| | | // Create 单条插入 |
| | | func (slf *LocationProductSearch) Create(record *LocationProduct) error { |
| | | var db = slf.build() |
| | | |
| | | if err := db.Create(record).Error; err != nil { |
| | | return err |
| | | } |
| | | |
| | | return nil |
| | | } |
| | | |
| | | // CreateBatch 批量插入 |
| | | func (slf *LocationProductSearch) CreateBatch(records []*LocationProduct) error { |
| | | var db = slf.build() |
| | | |
| | | if err := db.Create(&records).Error; err != nil { |
| | | return fmt.Errorf("create batch err: %v, records: %+v", err, records) |
| | | } |
| | | |
| | | return nil |
| | | } |
| | | |
| | | func (slf *LocationProductSearch) Update(record *LocationProduct) error { |
| | | var db = slf.build() |
| | | |
| | | if err := db.Omit("CreatedAt").Updates(record).Error; err != nil { |
| | | return fmt.Errorf("save err: %v, record: %+v", err, record) |
| | | } |
| | | |
| | | return nil |
| | | } |
| | | |
| | | func (slf *LocationProductSearch) Delete() error { |
| | | var db = slf.build() |
| | | return db.Unscoped().Delete(&LocationProduct{}).Error |
| | | } |
| | | |
| | | func (slf *LocationProductSearch) First() (*LocationProduct, error) { |
| | | var ( |
| | | record = new(LocationProduct) |
| | | db = slf.build() |
| | | ) |
| | | |
| | | if err := db.First(record).Error; err != nil { |
| | | return record, err |
| | | } |
| | | |
| | | return record, nil |
| | | } |
| | | |
| | | func (slf *LocationProductSearch) FindByPage() ([]*LocationProduct, int64, error) { |
| | | var ( |
| | | records = make([]*LocationProduct, 0) |
| | | total int64 |
| | | db = slf.build() |
| | | ) |
| | | |
| | | if err := db.Count(&total).Error; err != nil { |
| | | return records, total, fmt.Errorf("find count err: %v", err) |
| | | } |
| | | if slf.PageNum*slf.PageSize > 0 { |
| | | db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize) |
| | | } |
| | | if err := db.Find(&records).Error; err != nil { |
| | | return records, total, fmt.Errorf("find records err: %v", err) |
| | | } |
| | | |
| | | return records, total, nil |
| | | } |
| | | |
| | | func (slf *LocationProductSearch) Find() ([]*LocationProduct, error) { |
| | | var ( |
| | | records = make([]*LocationProduct, 0) |
| | | db = slf.build() |
| | | ) |
| | | |
| | | if err := db.Find(&records).Error; err != nil { |
| | | return records, fmt.Errorf("find records err: %v", err) |
| | | } |
| | | |
| | | return records, nil |
| | | } |
New file |
| | |
| | | package models |
| | | |
| | | import ( |
| | | "fmt" |
| | | "github.com/shopspring/decimal" |
| | | "gorm.io/gorm" |
| | | "wms/pkg/mysqlx" |
| | | ) |
| | | |
| | | type ( |
| | | LocationProductAmount struct { |
| | | WmsModel |
| | | Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` |
| | | LocationProductId int `json:"locationProductId" gorm:"type:int;not null;comment:上架规则id"` //上架规则id |
| | | LocationProduct LocationProduct `json:"locationProduct" gorm:"foreignKey:LocationProductId;references:Id"` |
| | | Amount decimal.Decimal `json:"amount" gorm:"type:decimal(20,2);not null;comment:库存数量"` //库存数量 |
| | | } |
| | | |
| | | LocationProductAmountSearch struct { |
| | | LocationProductAmount |
| | | Order string |
| | | PageNum int |
| | | PageSize int |
| | | Keyword string |
| | | Orm *gorm.DB |
| | | Preload bool |
| | | } |
| | | |
| | | LocationProductAmountWithOperation struct { |
| | | LocationProductAmount LocationProductAmount `json:"locationProductAmount"` |
| | | AdjustAmount decimal.Decimal `json:"adjustAmount" gorm:"column:adjust_amount"` |
| | | DifferenceAmount decimal.Decimal `json:"difference_amount"` |
| | | } |
| | | ) |
| | | |
| | | func (slf *LocationProductAmount) TableName() string { |
| | | return "wms_location_product_amount" |
| | | } |
| | | |
| | | func NewLocationProductAmountSearch() *LocationProductAmountSearch { |
| | | return &LocationProductAmountSearch{Orm: mysqlx.GetDB()} |
| | | } |
| | | |
| | | func (slf *LocationProductAmountSearch) SetOrm(tx *gorm.DB) *LocationProductAmountSearch { |
| | | slf.Orm = tx |
| | | return slf |
| | | } |
| | | |
| | | func (slf *LocationProductAmountSearch) SetPage(page, size int) *LocationProductAmountSearch { |
| | | slf.PageNum, slf.PageSize = page, size |
| | | return slf |
| | | } |
| | | |
| | | func (slf *LocationProductAmountSearch) SetOrder(order string) *LocationProductAmountSearch { |
| | | slf.Order = order |
| | | return slf |
| | | } |
| | | |
| | | func (slf *LocationProductAmountSearch) SetID(id int) *LocationProductAmountSearch { |
| | | slf.Id = id |
| | | return slf |
| | | } |
| | | |
| | | func (slf *LocationProductAmountSearch) SetKeyword(keyword string) *LocationProductAmountSearch { |
| | | slf.Keyword = keyword |
| | | return slf |
| | | } |
| | | |
| | | func (slf *LocationProductAmountSearch) SetPreload(preload bool) *LocationProductAmountSearch { |
| | | slf.Preload = preload |
| | | return slf |
| | | } |
| | | |
| | | func (slf *LocationProductAmountSearch) build() *gorm.DB { |
| | | var db = slf.Orm.Model(&LocationProductAmount{}) |
| | | |
| | | if slf.Id != 0 { |
| | | db = db.Where("id = ?", slf.Id) |
| | | } |
| | | if slf.Order != "" { |
| | | db = db.Order(slf.Order) |
| | | } |
| | | |
| | | if slf.Keyword != "" { |
| | | db = db.Where("product_name like ?", fmt.Sprintf("%%%v%%", slf.Keyword)) |
| | | } |
| | | |
| | | if slf.Preload { |
| | | db = db.Model(&LocationProductAmount{}).Preload("LocationProduct").Preload("LocationProduct.Location").Preload("LocationProduct.Product") |
| | | } |
| | | |
| | | return db |
| | | } |
| | | |
| | | // Create 单条插入 |
| | | func (slf *LocationProductAmountSearch) Create(record *LocationProductAmount) error { |
| | | var db = slf.build() |
| | | |
| | | if err := db.Create(record).Error; err != nil { |
| | | return err |
| | | } |
| | | |
| | | return nil |
| | | } |
| | | |
| | | // CreateBatch 批量插入 |
| | | func (slf *LocationProductAmountSearch) CreateBatch(records []*LocationProductAmount) error { |
| | | var db = slf.build() |
| | | |
| | | if err := db.Create(&records).Error; err != nil { |
| | | return fmt.Errorf("create batch err: %v, records: %+v", err, records) |
| | | } |
| | | |
| | | return nil |
| | | } |
| | | |
| | | func (slf *LocationProductAmountSearch) Update(record *LocationProductAmount) error { |
| | | var db = slf.build() |
| | | |
| | | if err := db.Omit("CreatedAt").Updates(record).Error; err != nil { |
| | | return fmt.Errorf("save err: %v, record: %+v", err, record) |
| | | } |
| | | |
| | | return nil |
| | | } |
| | | |
| | | func (slf *LocationProductAmountSearch) Delete() error { |
| | | var db = slf.build() |
| | | return db.Unscoped().Delete(&LocationProductAmount{}).Error |
| | | } |
| | | |
| | | func (slf *LocationProductAmountSearch) First() (*LocationProductAmount, error) { |
| | | var ( |
| | | record = new(LocationProductAmount) |
| | | db = slf.build() |
| | | ) |
| | | |
| | | if err := db.First(record).Error; err != nil { |
| | | return record, err |
| | | } |
| | | |
| | | return record, nil |
| | | } |
| | | |
| | | func (slf *LocationProductAmountSearch) FindByPage() ([]*LocationProductAmount, int64, error) { |
| | | var ( |
| | | records = make([]*LocationProductAmount, 0) |
| | | total int64 |
| | | db = slf.build() |
| | | ) |
| | | |
| | | if err := db.Count(&total).Error; err != nil { |
| | | return records, total, fmt.Errorf("find count err: %v", err) |
| | | } |
| | | if slf.PageNum*slf.PageSize > 0 { |
| | | db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize) |
| | | } |
| | | if err := db.Find(&records).Error; err != nil { |
| | | return records, total, fmt.Errorf("find records err: %v", err) |
| | | } |
| | | |
| | | return records, total, nil |
| | | } |
| | | |
| | | func (slf *LocationProductAmountSearch) Find() ([]*LocationProductAmount, error) { |
| | | var ( |
| | | records = make([]*LocationProductAmount, 0) |
| | | db = slf.build() |
| | | ) |
| | | |
| | | if err := db.Find(&records).Error; err != nil { |
| | | return records, fmt.Errorf("find records err: %v", err) |
| | | } |
| | | |
| | | return records, nil |
| | | } |
| | |
| | | Comment string `json:"comment" gorm:"type:text;comment:备注"` |
| | | |
| | | Details []*OperationDetails `json:"details" gorm:"foreignKey:OperationID;references:Id"` |
| | | |
| | | //Weight decimal.Decimal `json:"weight" gorm:"type:decimal(20,2);comment:重量(kg)"` |
| | | //TransferWeight decimal.Decimal `json:"transferWeight" gorm:"type:decimal(20,2);comment:物流重量(kg)"` |
| | | //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:追踪参考"` |
| | | BaseOperationType constvar.BaseOperationType `json:"baseOperationType" gorm:"type:tinyint;not null;comment:基础作业类型"` //基础作业类型 |
| | | } |
| | | |
| | | OperationSearch struct { |
New file |
| | |
| | | package request |
| | | |
| | | type AddLocationProduct struct { |
| | | LocationId int `json:"locationId"` //位置id |
| | | ProductId string `json:"productId"` //产品id |
| | | ProductCategoryId int `json:"productCategoryId"` //产品种类id |
| | | AreaId int `json:"areaId"` //区域id |
| | | } |
| | | |
| | | type UpdateLocationProduct struct { |
| | | Id int `json:"id"` |
| | | LocationId int `json:"locationId"` //位置id |
| | | ProductId string `json:"productId"` //产品id |
| | | ProductCategoryId int `json:"productCategoryId"` //产品种类id |
| | | AreaId int `json:"areaId"` //区域id |
| | | } |
New file |
| | |
| | | package request |
| | | |
| | | import "github.com/shopspring/decimal" |
| | | |
| | | type AddLocationProductAmount struct { |
| | | LocationProductAmountId int `json:"locationProductAmountId"` //库存盘点id |
| | | AdjustAmount decimal.Decimal `json:"adjustAmount" ` //差值 |
| | | DifferenceAmount decimal.Decimal `json:"difference_amount"` //计数数量 |
| | | } |
| | | |
| | | type UpdateLocationProductAmount struct { |
| | | LocationProductAmountId int `json:"locationProductAmountId"` //库存盘点id |
| | | AdjustAmount decimal.Decimal `json:"adjustAmount" ` //差值 |
| | | DifferenceAmount decimal.Decimal `json:"difference_amount"` //计数数量 |
| | | } |
| | |
| | | CompanyID int `json:"companyID" gorm:"type:int;comment:公司ID"` //公司ID-客户 |
| | | CompanyName string `json:"companyName" gorm:"type:varchar(127);comment:公司名称"` //公司名称-客户名称 |
| | | Comment string `json:"comment" gorm:"type:text;comment:备注"` //备注 |
| | | |
| | | //CarrierID int `json:"carrierID" gorm:"type:int;comment:承运商ID"` //承运商ID-非必填 |
| | | //CarrierName string `json:"carrierName" gorm:"type:varchar(63);comment:承运商名称"` //承运商名称-非必填 |
| | | //Tracking string `json:"tracking" gorm:"type:varchar(127);comment:追踪参考"` //追踪参考-非必填 |
| | | //Weight decimal.Decimal `json:"weight" gorm:"type:decimal(20,2);comment:重量(kg)"` //重量(kg)-非必填 |
| | | //TransferWeight decimal.Decimal `json:"transferWeight" gorm:"type:decimal(20,2);comment:物流重量(kg)"` //物流重量(kg)-非必填 |
| | | BaseOperationType constvar.BaseOperationType `json:"baseOperationType"` //基础作业类型 |
| | | } |
| | | |
| | | type OperationAllList struct { |
| | |
| | | type UpdateDisuse struct { |
| | | Id int `json:"id"` |
| | | ProductId string `json:"productId"` |
| | | //ProductName string `json:"productName"` |
| | | Amount decimal.Decimal `json:"amount"` |
| | | FromLocationId int `json:"fromLocationId"` |
| | | ToLocationId int `json:"toLocationId"` |
| | | SourceNumber string `json:"sourceNumber"` |
| | | //Unit string `json:"unit"` |
| | | Number string `json:"number"` |
| | | Status constvar.OperationStatus `json:"status"` |
| | | OperationDate string `json:"operationDate"` |
| | | BaseOperationType constvar.BaseOperationType `json:"baseOperationType"` |
| | | } |
| | |
| | | productAPI.POST("listDisuse", productController.ListDisuse) //查看产品的历史出入库信息 |
| | | productAPI.PUT("finishDisuse/:id", productController.FinishDisuse) //报废验证 |
| | | productAPI.POST("updateDisuse", productController.UpdateDisuse) //修改报废信息 |
| | | } |
| | | |
| | | // 上架规则 |
| | | locationProductController := new(controllers.LocationProductController) |
| | | locationProductAPI := r.Group(urlPrefix + "/locationProduct") |
| | | { |
| | | locationProductAPI.GET("operationType", locationProductController.List) // 获取上架规则列表 |
| | | locationProductAPI.POST("operationType", locationProductController.Add) // 新增上架规则 |
| | | locationProductAPI.PUT("operationType/:id", locationProductController.Update) // 修改上架规则 |
| | | locationProductAPI.DELETE("operationType/:id", locationProductController.Delete) // 删除上架规则 |
| | | } |
| | | |
| | | return r |