35 lines
1.4 KiB
Go
35 lines
1.4 KiB
Go
package excel
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/tiger1103/gfast/v3/internal/app/system/dao"
|
|
)
|
|
|
|
// EquipmentMaterials 设备和材料
|
|
type EquipmentMaterials struct {
|
|
EquipmentMaterialsName string `json:"equipment_materials_name"`
|
|
TotalNumber int `json:"total_number"`
|
|
TotalQuantityCount int `json:"total_quantity_count"`
|
|
CumulativeArrivalQuantity int `json:"cumulative_arrival_quantity"`
|
|
}
|
|
|
|
// 传入项目ID,开始时间,结束时间返回 EquipmentMaterials 列表
|
|
func GetEquipmentMaterials(projectID string, startAt, endAt string) ([]EquipmentMaterials, error) {
|
|
var list []EquipmentMaterials
|
|
|
|
if err := dao.BusEquipmentMaterialsInventory.Ctx(context.Background()).As("bmi").
|
|
Fields("bem.equipment_materials_name, SUM(bmi.number) AS total_number, SUM(bem.quantity_count) AS total_quantity_count, (SELECT SUM(bi.number) FROM `bus_equipment_materials_inventory` bi WHERE bi.equipment_materials_id = bmi.equipment_materials_id AND bi.deleted_at IS NULL AND bi.out_put = 2) AS cumulative_arrival_quantity").
|
|
LeftJoin("bus_equipment_materials bem", "bmi.equipment_materials_id = bem.equipment_materials_id").
|
|
Where("bem.project_id = ?", projectID).
|
|
Where("bmi.out_put = ?", 2).
|
|
Where("bmi.created_at >= ?", startAt).
|
|
Where("bmi.created_at <= ?", endAt).
|
|
Group("bem.equipment_materials_name").
|
|
Scan(&list); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return list, nil
|
|
}
|