feat:完善项目
This commit is contained in:
9
app/model/base.go
Normal file
9
app/model/base.go
Normal file
@ -0,0 +1,9 @@
|
||||
package model
|
||||
|
||||
import "ArmedPolice/app/common/model"
|
||||
|
||||
type PageParams struct {
|
||||
Page, PageSize int
|
||||
Count *int64
|
||||
Where []*model.ModelWhere
|
||||
}
|
@ -3,6 +3,7 @@ package model
|
||||
import (
|
||||
"ArmedPolice/app/common/model"
|
||||
"ArmedPolice/serve/orm"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type ManageMaterial struct {
|
||||
@ -10,11 +11,30 @@ type ManageMaterial struct {
|
||||
}
|
||||
|
||||
type ManageMaterialInfo struct {
|
||||
Title string `json:"title"`
|
||||
*model.ManageMaterial
|
||||
SupplierName string `json:"supplier_name"`
|
||||
}
|
||||
|
||||
func (m *ManageMaterial) Materials() {
|
||||
orm.GetDB().Table(m.TableName() + " AS m").Select("")
|
||||
func (m *ManageMaterial) Materials(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*ManageMaterialInfo, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS m").
|
||||
Select("m.*", "s.name AS supplier_name").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS s ON m.supplier_id = s.id", model.NewManageSupplier().TableName()))
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, wo := range where {
|
||||
db = db.Where(wo.Condition, wo.Value)
|
||||
}
|
||||
}
|
||||
out := make([]*ManageMaterialInfo, 0)
|
||||
|
||||
if err := db.Order("p.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := db.Count(count).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
|
||||
}
|
||||
|
||||
func NewManageMaterial() *ManageMaterial {
|
||||
|
47
app/model/manage_materiral_purchase.go
Normal file
47
app/model/manage_materiral_purchase.go
Normal file
@ -0,0 +1,47 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"ArmedPolice/app/common/model"
|
||||
"ArmedPolice/serve/orm"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type ManageMaterialPurchase struct {
|
||||
*model.ManageMaterialPurchase
|
||||
}
|
||||
|
||||
// ManageMaterialPurchaseInfo 器材采购信息
|
||||
type ManageMaterialPurchaseInfo struct {
|
||||
*model.ManageMaterialPurchase
|
||||
MaterialTitle string `json:"material_title"`
|
||||
SupplierName string `json:"supplier_name"`
|
||||
Username string `json:"username"`
|
||||
}
|
||||
|
||||
func (m *ManageMaterialPurchase) Purchases(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*ManageMaterialPurchaseInfo, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS p").
|
||||
Select("p.*", "m.title AS material_title", "s.name AS supplier_names", "u.name AS username").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS m ON p.material_id = m.id", model.NewManageMaterial().TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS s ON m.supplier_id = s.id", model.NewManageSupplier().TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS u ON p.uid = u.uuid", model.NewSysUser().TableName())).
|
||||
Where("p.is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, wo := range where {
|
||||
db = db.Where(wo.Condition, wo.Value)
|
||||
}
|
||||
}
|
||||
out := make([]*ManageMaterialPurchaseInfo, 0)
|
||||
|
||||
if err := db.Order("p.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := db.Count(count).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func NewManageMaterialPurchase() *ManageMaterialPurchase {
|
||||
return &ManageMaterialPurchase{}
|
||||
}
|
11
app/model/manage_materiral_warehouse.go
Normal file
11
app/model/manage_materiral_warehouse.go
Normal file
@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
import "ArmedPolice/app/common/model"
|
||||
|
||||
type ManageMaterialWarehouse struct {
|
||||
*model.ManageMaterialWarehouse
|
||||
}
|
||||
|
||||
func NewManageMaterialWarehouse() *ManageMaterialWarehouse {
|
||||
return &ManageMaterialWarehouse{}
|
||||
}
|
Reference in New Issue
Block a user