2021-11-03 14:51:14 +08:00
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
|
|
|
"ArmedPolice/app/common/model"
|
|
|
|
"ArmedPolice/serve/orm"
|
2021-11-03 17:55:27 +08:00
|
|
|
"fmt"
|
2021-11-03 14:51:14 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type ManageMaterial struct {
|
|
|
|
*model.ManageMaterial
|
|
|
|
}
|
|
|
|
|
2021-11-04 11:10:51 +08:00
|
|
|
type (
|
|
|
|
// ManageMaterialBasic 基本信息
|
|
|
|
ManageMaterialBasic struct {
|
|
|
|
Code string `json:"code"`
|
|
|
|
Title string `json:"title"`
|
|
|
|
Unit int `json:"unit"`
|
|
|
|
ManufacturerName string `json:"manufacturer_name"`
|
|
|
|
}
|
|
|
|
ManageMaterialInfo struct {
|
|
|
|
*model.ManageMaterial
|
|
|
|
SupplierName string `json:"supplier_name"`
|
|
|
|
}
|
|
|
|
)
|
2021-11-03 14:51:14 +08:00
|
|
|
|
2021-11-03 17:55:27 +08:00
|
|
|
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
|
|
|
|
|
2021-11-03 14:51:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewManageMaterial() *ManageMaterial {
|
|
|
|
return &ManageMaterial{model.NewManageMaterial()}
|
|
|
|
}
|