feat:完善项目

This commit is contained in:
henry
2022-01-17 11:34:39 +08:00
parent b50fdb0d44
commit 8fd5283b0e
6 changed files with 187 additions and 10 deletions

View File

@ -0,0 +1,101 @@
package technology
import (
"SciencesServer/app/api/admin/model"
"SciencesServer/app/basic/controller"
model2 "SciencesServer/app/common/model"
"SciencesServer/app/session"
"errors"
)
type Product struct {
*session.Admin
}
type ProductHandle func(session *session.Admin) *Product
type (
// ProductInfo 产品信息
ProductInfo struct {
ID string `json:"id"`
}
// ProductDetailInfo 产品详细信息
ProductDetailInfo struct {
ID string `json:"id"`
TenantID string `json:"tenant_id"`
*model2.TechnologyProduct
}
)
func (c *Product) Instance(tenantID uint64, title string, page, pageSize int) (*controller.ReturnPages, error) {
mTechnologyProduct := model.NewTechnologyProduct()
where := make([]*model2.ModelWhere, 0)
if c.TenantID > 0 {
where = append(where, model2.NewWhere("p.tenant_id", c.TenantID))
}
if tenantID > 0 {
where = append(where, model2.NewWhere("p.tenant_id", tenantID))
}
if title != "" {
where = append(where, model2.NewWhereLike("p.title", title))
}
var count int64
out, err := mTechnologyProduct.Product(page, pageSize, &count)
if err != nil {
return nil, err
}
list := make([]*ProductInfo, 0)
for _, v := range out {
list = append(list, &ProductInfo{ID: v.GetEncodeID()})
}
return &controller.ReturnPages{Data: list, Count: count}, err
}
// Detail 详细信息
func (c *Product) Detail(id uint64) (*ProductDetailInfo, error) {
mTechnologyProduct := model.NewTechnologyProduct()
mTechnologyProduct.ID = id
isExist, err := model2.First(mTechnologyProduct.TechnologyProduct)
if err != nil {
return nil, err
} else if !isExist {
return nil, errors.New("操作错误,产品信息不存在或已被删除")
}
return &ProductDetailInfo{
ID: mTechnologyProduct.GetEncodeID(),
TenantID: mTechnologyProduct.GetEncodeTenantID(),
TechnologyProduct: mTechnologyProduct.TechnologyProduct,
}, nil
}
func (c *Product) Form() {
}
// Delete 删除操作
func (c *Product) Delete(id uint64) error {
mTechnologyProduct := model.NewTechnologyProduct()
mTechnologyProduct.ID = id
isExist, err := model2.FirstField(mTechnologyProduct.TechnologyProduct, []string{"id", "tenant_id"})
if err != nil {
return err
} else if !isExist {
return errors.New("操作错误,产品信息不存在或已被删除")
}
return model2.Delete(mTechnologyProduct.TechnologyProduct)
}
func NewProduct() ProductHandle {
return func(session *session.Admin) *Product {
return &Product{session}
}
}