feat:完善项目
This commit is contained in:
@ -4,14 +4,12 @@ package model
|
||||
type ManageMaterial struct {
|
||||
Model
|
||||
ModelTenant
|
||||
SupplierID uint64 `gorm:"column:supplier_id;type:int;default:0;comment:供应商ID" json:""`
|
||||
Code string `gorm:"column:code;type:varchar(35);default:null;comment:编号" json:"code"`
|
||||
Title string `gorm:"column:title;type:varchar(100);default:null;comment:名称" json:"title"`
|
||||
ManufacturerID uint64 `gorm:"column:manufacturer_id;type:int;default:0;comment:制造商ID" json:"-"`
|
||||
Code string `gorm:"column:code;type:varchar(35);default:null;comment:编号" json:"code"`
|
||||
Title string `gorm:"column:title;type:varchar(100);default:null;comment:名称" json:"title"`
|
||||
Image
|
||||
Stock int `gorm:"column:stock;type:int(8);default:0;comment:库存数" json:"stock"`
|
||||
FrozenStock int `gorm:"column:frozen_stock;type:int(8);default:0;comment:冻结的库存数" json:"-"`
|
||||
Unit ManageMaterialUnit `gorm:"column:unit;type:tinyint(1);default:0;comment:单位" json:"unit"`
|
||||
Remark string `gorm:"column:remark;type:varchar(255);default:null;comment:备注" json:"remark"`
|
||||
Unit ManageMaterialUnit `gorm:"column:unit;type:tinyint(1);default:0;comment:单位" json:"unit"`
|
||||
Remark string `gorm:"column:remark;type:varchar(255);default:null;comment:备注" json:"remark"`
|
||||
ModelDeleted
|
||||
ModelAt
|
||||
}
|
||||
|
@ -3,12 +3,12 @@ package model
|
||||
// ManageMaterialPurchase 维修器材采购数据明细
|
||||
type ManageMaterialPurchase struct {
|
||||
Model
|
||||
UID uint64 `gorm:"column:uid;type:int;default:0;comment:用户uuid" json:"-"`
|
||||
OrderNo string `gorm:"column:order_no;type:varchar(30);default:null;comment:采购单号" json:"order_no"`
|
||||
MaterialID uint64 `gorm:"column:material_id;type:int(6);default:0;comment:器材ID" json:"-"`
|
||||
Price float64 `gorm:"column:price;type:decimal(10,2);default:0;comment:采购单价" json:"price"`
|
||||
Number int `gorm:"column:number;type:int(8);default:0;comment:采购数量" json:"number"`
|
||||
Remark string `gorm:"column:remark;type:varchar(255);default:null;comment:采购备注" json:"remark"`
|
||||
UID uint64 `gorm:"column:uid;type:int;default:0;comment:用户uuid" json:"-"`
|
||||
OrderNo string `gorm:"column:order_no;type:varchar(30);default:null;comment:采购单号" json:"order_no"`
|
||||
MaterialSupplierID uint64 `gorm:"column:material_supplier_id;type:int(6);default:0;comment:器材ID" json:"-"`
|
||||
Price float64 `gorm:"column:price;type:decimal(10,2);default:0;comment:采购单价" json:"price"`
|
||||
Number int `gorm:"column:number;type:int(8);default:0;comment:采购数量" json:"number"`
|
||||
Remark string `gorm:"column:remark;type:varchar(255);default:null;comment:采购备注" json:"remark"`
|
||||
ModelDeleted
|
||||
ModelAt
|
||||
}
|
||||
|
@ -17,9 +17,11 @@ type ManageSupplier struct {
|
||||
type ManageSupplierKind int
|
||||
|
||||
const (
|
||||
// ManageSupplierKindForMaterial 材料供应商
|
||||
ManageSupplierKindForMaterial ManageSupplierKind = iota + 101
|
||||
// ManageSupplierKindForRepair 维修供应商
|
||||
// ManageSupplierKindForManufacturer 制造商
|
||||
ManageSupplierKindForManufacturer ManageSupplierKind = iota + 101
|
||||
// ManageSupplierKindForMaterial 材料合作供应商
|
||||
ManageSupplierKindForMaterial
|
||||
// ManageSupplierKindForRepair 维修合作供应商
|
||||
ManageSupplierKindForRepair
|
||||
)
|
||||
|
||||
|
@ -6,10 +6,7 @@ import (
|
||||
"ArmedPolice/app/model"
|
||||
"ArmedPolice/app/service"
|
||||
"ArmedPolice/config"
|
||||
"ArmedPolice/lib"
|
||||
"ArmedPolice/serve/orm"
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -25,32 +22,16 @@ type (
|
||||
}
|
||||
// MaterialParams 基本参数
|
||||
MaterialParams struct {
|
||||
ID, SupplierID uint64
|
||||
ID, ManufacturerID uint64
|
||||
Code, Title, Image, Remark string
|
||||
Unit int
|
||||
}
|
||||
// MaterialPurchaseInfo 采购信息
|
||||
MaterialPurchaseInfo struct {
|
||||
basic.CommonIDString
|
||||
*model.ManageMaterialPurchaseInfo
|
||||
}
|
||||
)
|
||||
|
||||
func (c *MaterialParams) isExistForCode(iModel model2.IModel) (bool, error) {
|
||||
func (c *MaterialParams) isExistForCode(iModel model2.IModel, tenantID uint64) (bool, error) {
|
||||
var count int64
|
||||
|
||||
if err := model2.Count(iModel, &count, model2.NewWhere("code", c.Code),
|
||||
model2.NewWhere("supplier_id", c.SupplierID)); err != nil {
|
||||
return false, err
|
||||
}
|
||||
return count > 0, nil
|
||||
}
|
||||
|
||||
func (c *MaterialParams) isExistForTitle(iModel model2.IModel) (bool, error) {
|
||||
var count int64
|
||||
|
||||
if err := model2.Count(iModel, &count, model2.NewWhere("title", c.Title),
|
||||
model2.NewWhere("supplier_id", c.SupplierID)); err != nil {
|
||||
if err := model2.Count(iModel, &count, model2.NewWhere("tenant_id", tenantID), model2.NewWhere("code", c.Code)); err != nil {
|
||||
return false, err
|
||||
}
|
||||
return count > 0, nil
|
||||
@ -90,6 +71,7 @@ func (c *Material) List(supplierID uint64, code, title string, page, pageSize in
|
||||
return &basic.PageDataResponse{Data: list, Count: count}, nil
|
||||
}
|
||||
|
||||
// Form 数据操作
|
||||
func (c *Material) Form(params *MaterialParams) error {
|
||||
mManageMaterial := model.NewManageMaterial()
|
||||
|
||||
@ -102,26 +84,16 @@ func (c *Material) Form(params *MaterialParams) error {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,器材信息不存在")
|
||||
}
|
||||
if mManageMaterial.SupplierID != params.SupplierID {
|
||||
|
||||
}
|
||||
if mManageMaterial.Code != params.Code {
|
||||
if isExist, err = params.isExistForCode(mManageMaterial); err != nil {
|
||||
if isExist, err = params.isExistForCode(mManageMaterial, c.TenantID); err != nil {
|
||||
return err
|
||||
} else if isExist {
|
||||
return errors.New("操作错误,当前供应商下已存在此编码")
|
||||
}
|
||||
}
|
||||
if mManageMaterial.Title != params.Title {
|
||||
if isExist, err = params.isExistForTitle(mManageMaterial); err != nil {
|
||||
return err
|
||||
} else if isExist {
|
||||
return errors.New("操作错误,当前供应商下已存在此名称")
|
||||
return errors.New("操作错误,已存在此对应的器材编码")
|
||||
}
|
||||
}
|
||||
}
|
||||
mManageMaterial.SupplierID = params.SupplierID
|
||||
mManageMaterial.ManufacturerID = params.ManufacturerID
|
||||
mManageMaterial.Code = params.Code
|
||||
mManageMaterial.Title = params.Title
|
||||
mManageMaterial.Unit = model2.ManageMaterialUnit(params.Unit)
|
||||
@ -131,17 +103,12 @@ func (c *Material) Form(params *MaterialParams) error {
|
||||
mManageMaterial.UpdatedAt = time.Now()
|
||||
return model2.Updates(mManageMaterial.ManageMaterial, mManageMaterial.ManageMaterial)
|
||||
}
|
||||
isExist, err := params.isExistForCode(mManageMaterial)
|
||||
isExist, err := params.isExistForCode(mManageMaterial, c.TenantID)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if isExist {
|
||||
return errors.New("操作错误,当前供应商下已存在此编码")
|
||||
}
|
||||
if isExist, err = params.isExistForTitle(mManageMaterial); err != nil {
|
||||
return err
|
||||
} else if isExist {
|
||||
return errors.New("操作错误,当前供应商下已存在此名称")
|
||||
return errors.New("操作错误,已存在此对应的器材编码")
|
||||
}
|
||||
mManageMaterial.TenantID = c.TenantID
|
||||
return model2.Create(mManageMaterial.ManageMaterial)
|
||||
@ -154,101 +121,8 @@ func (c *Material) Delete(id uint64) error {
|
||||
return model2.Delete(mManageMaterial.ManageMaterial)
|
||||
}
|
||||
|
||||
// Purchase 采购信息
|
||||
func (c *Material) Purchase(orderNo, supplierName, materialTitle string, page, pageSize int) (*basic.PageDataResponse, error) {
|
||||
mManageMaterialPurchase := model.NewManageMaterialPurchase()
|
||||
func (c *Material) Supplier() {
|
||||
|
||||
where := make([]*model2.ModelWhere, 0)
|
||||
|
||||
if orderNo != "" {
|
||||
where = append(where, model2.NewWhereLike("p.order_no", orderNo))
|
||||
}
|
||||
if supplierName != "" {
|
||||
where = append(where, model2.NewWhereLike("s.name", supplierName))
|
||||
}
|
||||
if materialTitle != "" {
|
||||
where = append(where, model2.NewWhereLike("m.title", materialTitle))
|
||||
}
|
||||
var count int64
|
||||
|
||||
out, err := mManageMaterialPurchase.Purchases(page, pageSize, &count, where...)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*MaterialPurchaseInfo, 0)
|
||||
|
||||
for _, v := range out {
|
||||
list = append(list, &MaterialPurchaseInfo{
|
||||
CommonIDString: basic.CommonIDString{ID: v.GetEncodeID()},
|
||||
ManageMaterialPurchaseInfo: v,
|
||||
})
|
||||
}
|
||||
return &basic.PageDataResponse{Data: list, Count: count}, nil
|
||||
}
|
||||
|
||||
// PurchaseLaunch 采购发起
|
||||
func (c *Material) PurchaseLaunch(materialID uint64, price float64, number int, remark string) error {
|
||||
mManageMaterialPurchase := model.NewManageMaterialPurchase()
|
||||
mManageMaterialPurchase.UID = c.UID
|
||||
mManageMaterialPurchase.OrderNo = lib.OrderNo()
|
||||
mManageMaterialPurchase.MaterialID = materialID
|
||||
mManageMaterialPurchase.Price = price
|
||||
mManageMaterialPurchase.Number = number
|
||||
mManageMaterialPurchase.Remark = remark
|
||||
return model2.Create(mManageMaterialPurchase.ManageMaterialPurchase)
|
||||
}
|
||||
|
||||
// PurchaseDelete 采购删除
|
||||
func (c *Material) PurchaseDelete(id uint64) error {
|
||||
mManageMaterialPurchase := model.NewManageMaterialPurchase()
|
||||
mManageMaterialPurchase.ID = id
|
||||
return model2.Delete(mManageMaterialPurchase.ManageMaterialPurchase)
|
||||
}
|
||||
|
||||
func (c *Material) Warehouse() {
|
||||
|
||||
}
|
||||
|
||||
// WarehouseLaunch 入库发起
|
||||
func (c *Material) WarehouseLaunch(materialPurchaseID uint64, number int, remark string) error {
|
||||
mManageMaterialPurchase := model.NewManageMaterialPurchase()
|
||||
mManageMaterialPurchase.ID = materialPurchaseID
|
||||
|
||||
isExist, err := model2.FirstWhere(mManageMaterialPurchase.ManageMaterialPurchase)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,未找到相应的采购单")
|
||||
}
|
||||
mManageMaterialWarehouse := model.NewManageMaterialWarehouse()
|
||||
mManageMaterialWarehouse.UID = c.UID
|
||||
mManageMaterialWarehouse.MaterialPurchaseID = materialPurchaseID
|
||||
mManageMaterialWarehouse.Number = number
|
||||
mManageMaterialWarehouse.Remark = remark
|
||||
|
||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
if err = model2.Create(mManageMaterialWarehouse.ManageMaterialWarehouse); err != nil {
|
||||
return err
|
||||
}
|
||||
// 同步库存
|
||||
mManageMaterial := model.NewManageMaterial()
|
||||
|
||||
if err = model2.Updates(mManageMaterial.ManageMaterial, map[string]interface{}{
|
||||
"stock": gorm.Expr("stock + ?", number),
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// WarehouseDelete 入库删除
|
||||
func (c *Material) WarehouseDelete(id uint64) error {
|
||||
mManageMaterialWarehouse := model.NewManageMaterialWarehouse()
|
||||
mManageMaterialWarehouse.ID = id
|
||||
return model2.Delete(mManageMaterialWarehouse.ManageMaterialWarehouse)
|
||||
}
|
||||
|
||||
func NewMaterial() MaterialHandle {
|
||||
|
@ -72,6 +72,14 @@ func (c *Supplier) List(name, mobile string, kind model2.ManageSupplierKind, pag
|
||||
return &basic.PageDataResponse{Data: list, Count: count}, nil
|
||||
}
|
||||
|
||||
func (c *Supplier) Manufacturer() {
|
||||
|
||||
}
|
||||
|
||||
func (c *Supplier) Partner() {
|
||||
|
||||
}
|
||||
|
||||
// Form 数据处理
|
||||
func (c *Supplier) Form(params *SupplierParams) error {
|
||||
mManageSupplier := model.NewManageSupplier()
|
||||
|
@ -19,10 +19,11 @@ func (c *Instance) List() (*basic.PageDataResponse, error) {
|
||||
//if {
|
||||
//
|
||||
//}
|
||||
|
||||
out := make([]*model2.SysRole, 0)
|
||||
|
||||
model2.Find(mSysRole.SysRole, &out, where...)
|
||||
if err := model2.Find(mSysRole.SysRole, &out, where...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &basic.PageDataResponse{Data: nil, Count: 0}, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user