product_material_group_dao.go
1.1 KB
package dao
import (
"fmt"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/models"
)
type ProductMaterialGroupDao struct {
transactionContext *pgTransaction.TransactionContext
}
func (dao *ProductMaterialGroupDao) CurrentGroupLatestNumber(companyId int, productMaterialGroupId int) (string, int, error) {
m := new(models.ProductMaterialGroup)
var result string
var total int
query := dao.transactionContext.PgTx.Model(m).Where("company_id = ?", companyId)
query.Where("pid = ?", productMaterialGroupId)
query.ColumnExpr("max(material_group_number) number")
query.ColumnExpr("count(material_group_number) total")
query.AllWithDeleted()
err := query.Select(&result, &total)
return result, total, err
}
func NewProductMaterialGroupDao(transactionContext *pgTransaction.TransactionContext) (*ProductMaterialGroupDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &ProductMaterialGroupDao{
transactionContext: transactionContext,
}, nil
}
}