feat:增加科技产品数据模型管理
This commit is contained in:
@ -113,7 +113,7 @@ func (c *Demand) Form(params *DemandParams) error {
|
||||
if params.ID > 0 {
|
||||
mTechnologyDemand.ID = params.ID
|
||||
|
||||
isExist, err := model2.FirstField(mTechnologyDemand.TechnologyDemand, []string{"id", "uid", "status"})
|
||||
isExist, err := model2.FirstField(mTechnologyDemand.TechnologyDemand, []string{"id", "m_uid", "status"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
@ -166,7 +166,7 @@ func (c *Demand) Delete(id uint64) error {
|
||||
mTechnologyDemand := model.NewTechnologyDemand()
|
||||
mTechnologyDemand.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mTechnologyDemand.TechnologyDemand, []string{"id", "uid", "status"})
|
||||
isExist, err := model2.FirstField(mTechnologyDemand.TechnologyDemand, []string{"id", "m_uid", "status"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
// Equipment 技术设备
|
||||
type Equipment struct {
|
||||
*session.Enterprise
|
||||
local string
|
||||
|
@ -3,6 +3,7 @@ package technology
|
||||
import (
|
||||
"SciencesServer/app/api/enterprise/model"
|
||||
"SciencesServer/app/api/manage/controller"
|
||||
"SciencesServer/app/basic/config"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
"errors"
|
||||
@ -29,8 +30,9 @@ type (
|
||||
InstanceParams struct {
|
||||
ID, PatentID, Territory uint64
|
||||
Title, Company, Images, ProveImages, Introduce, Purpose, Remark string
|
||||
Maturity, Prototype, Source, Transaction, Status int
|
||||
Maturity, Prototype, Source, Transaction int
|
||||
Products, Keywords []string
|
||||
IsSubmit int
|
||||
}
|
||||
)
|
||||
|
||||
@ -66,7 +68,7 @@ func (c *Instance) Form(params *InstanceParams) error {
|
||||
if params.ID > 0 {
|
||||
mTechnologyInstance.ID = params.ID
|
||||
|
||||
isExist, err := model2.FirstField(mTechnologyInstance.TechnologyInstance, []string{"id", "uid",
|
||||
isExist, err := model2.FirstField(mTechnologyInstance.TechnologyInstance, []string{"id", "m_uid",
|
||||
"status", "created_at", "updated_at"})
|
||||
|
||||
if err != nil {
|
||||
@ -83,7 +85,7 @@ func (c *Instance) Form(params *InstanceParams) error {
|
||||
mTechnologyInstance.PatentID = params.PatentID
|
||||
mTechnologyInstance.Title = params.Title
|
||||
mTechnologyInstance.Company = params.Company
|
||||
mTechnologyInstance.Maturity = model2.TechnologyInstanceMaturity(params.Maturity)
|
||||
mTechnologyInstance.Maturity = config.TechnologyMaturity(params.Maturity)
|
||||
mTechnologyInstance.Prototype = params.Prototype
|
||||
mTechnologyInstance.SetProductAttribute(params.Products)
|
||||
mTechnologyInstance.Source = model2.TechnologyInstanceSource(params.Source)
|
||||
@ -95,20 +97,22 @@ func (c *Instance) Form(params *InstanceParams) error {
|
||||
mTechnologyInstance.Introduce = params.Introduce
|
||||
mTechnologyInstance.Purpose = params.Purpose
|
||||
mTechnologyInstance.Remark = params.Remark
|
||||
mTechnologyInstance.Status = model2.TechnologyInstanceStatus(params.Status)
|
||||
|
||||
if mTechnologyInstance.Status != model2.TechnologyInstanceStatusForDraft &&
|
||||
mTechnologyInstance.Status != model2.TechnologyInstanceStatusForExamining {
|
||||
return errors.New("操作错误,状态参数错误")
|
||||
}
|
||||
if params.ID > 0 {
|
||||
mTechnologyInstance.UpdatedAt = time.Now()
|
||||
mTechnologyInstance.Status = model2.TechnologyInstanceStatusForExamining
|
||||
return model2.Updates(mTechnologyInstance.TechnologyInstance, mTechnologyInstance.TechnologyInstance)
|
||||
}
|
||||
mTechnologyInstance.MUid = c.ManageUID
|
||||
mTechnologyInstance.Local.Local = c.local
|
||||
mTechnologyInstance.TenantID = c.TenantID
|
||||
|
||||
if params.IsSubmit > 0 {
|
||||
mTechnologyInstance.Status = model2.TechnologyInstanceStatusForExamining
|
||||
}
|
||||
return model2.Create(mTechnologyInstance.TechnologyInstance)
|
||||
}
|
||||
|
||||
@ -116,7 +120,7 @@ func (c *Instance) Form(params *InstanceParams) error {
|
||||
func (c *Instance) Shelf(id uint64, status int) error {
|
||||
mTechnologyInstance := model.NewTechnologyInstance()
|
||||
mTechnologyInstance.ID = id
|
||||
isExist, err := model2.FirstField(mTechnologyInstance.TechnologyInstance, []string{"id", "uid", "shelf_status", "status"})
|
||||
isExist, err := model2.FirstField(mTechnologyInstance.TechnologyInstance, []string{"id", "m_uid", "shelf_status", "status"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
@ -141,7 +145,7 @@ func (c *Instance) Shelf(id uint64, status int) error {
|
||||
func (c *Instance) Delete(id uint64) error {
|
||||
mTechnologyInstance := model.NewTechnologyInstance()
|
||||
mTechnologyInstance.ID = id
|
||||
isExist, err := model2.FirstField(mTechnologyInstance.TechnologyInstance, []string{"id", "uid"})
|
||||
isExist, err := model2.FirstField(mTechnologyInstance.TechnologyInstance, []string{"id", "m_uid"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -97,7 +97,7 @@ func (c *Patent) Form(params *PatentParams) error {
|
||||
if params.ID > 0 {
|
||||
mTechnologyPatent.ID = params.ID
|
||||
|
||||
isExist, err := model2.FirstField(mTechnologyPatent.TechnologyPatent, []string{"id", "uid"})
|
||||
isExist, err := model2.FirstField(mTechnologyPatent.TechnologyPatent, []string{"id", "m_uid"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
193
app/api/enterprise/controller/technology/product.go
Normal file
193
app/api/enterprise/controller/technology/product.go
Normal file
@ -0,0 +1,193 @@
|
||||
package technology
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/enterprise/model"
|
||||
"SciencesServer/app/basic/config"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Product 产品信息
|
||||
type Product struct {
|
||||
*session.Enterprise
|
||||
local string
|
||||
}
|
||||
|
||||
type ProductHandle func(session *session.Enterprise, local string) *Product
|
||||
|
||||
type (
|
||||
// ProductInfo 产品信息
|
||||
ProductInfo struct {
|
||||
ID string `json:"id"`
|
||||
*model2.TechnologyProduct
|
||||
}
|
||||
ProductDetailInfo struct {
|
||||
ID string `json:"id"`
|
||||
*model2.TechnologyProduct
|
||||
Customers []string `json:"customers"`
|
||||
Keywords []string `json:"keywords"`
|
||||
}
|
||||
// ProductParams 产品参数信息
|
||||
ProductParams struct {
|
||||
ID uint64
|
||||
Title, Image, Video, Material, Introduce string
|
||||
Maturity, LeadStandard, CooperationMode int // 技术成熟度 领先标准 合作模式
|
||||
Industrys, Customers, Keywords []string // 所属客户 关键词
|
||||
IsSubmit int // 是否提交审核
|
||||
}
|
||||
)
|
||||
|
||||
// List 列表信息
|
||||
func (c *Product) List(title string, status, page, pageSize int) ([]*ProductInfo, error) {
|
||||
mTechnologyProduct := model.NewTechnologyProduct()
|
||||
|
||||
where := []*model2.ModelWhereOrder{
|
||||
&model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("local", c.local),
|
||||
Order: model2.NewOrder("id", model2.OrderModeToDesc),
|
||||
},
|
||||
&model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("m_uid", c.ManageUID),
|
||||
},
|
||||
&model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("status", status),
|
||||
},
|
||||
}
|
||||
if title != "" {
|
||||
where = append(where, &model2.ModelWhereOrder{
|
||||
Where: model2.NewWhereLike("title", title),
|
||||
})
|
||||
}
|
||||
out := make([]*model2.TechnologyProduct, 0)
|
||||
|
||||
var count int64
|
||||
|
||||
if err := model2.PagesFields(mTechnologyProduct.TechnologyProduct, &out, []string{},
|
||||
page, pageSize, &count, where...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*ProductInfo, 0)
|
||||
|
||||
for _, v := range out {
|
||||
list = append(list, &ProductInfo{
|
||||
ID: v.GetEncodeID(),
|
||||
TechnologyProduct: v,
|
||||
})
|
||||
}
|
||||
return list, nil
|
||||
}
|
||||
|
||||
// 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(),
|
||||
TechnologyProduct: mTechnologyProduct.TechnologyProduct,
|
||||
Customers: mTechnologyProduct.GetCustomerAttribute(),
|
||||
Keywords: mTechnologyProduct.GetKeywordAttribute(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Form 数据操作
|
||||
func (c *Product) Form(params *ProductParams) error {
|
||||
mTechnologyProduct := model.NewTechnologyProduct()
|
||||
|
||||
if params.ID > 0 {
|
||||
mTechnologyProduct.ID = params.ID
|
||||
|
||||
isExist, err := model2.FirstField(mTechnologyProduct.TechnologyProduct, []string{"id", "m_uid", "status", "created_at", "updated_at"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,产品信息不存在或已被删除")
|
||||
} else if mTechnologyProduct.MUid != c.ManageUID {
|
||||
return errors.New("无权限操作")
|
||||
} else if mTechnologyProduct.Status != model2.TechnologyProductStatusForRefuse &&
|
||||
mTechnologyProduct.Status != model2.TechnologyProductStatusForDraft {
|
||||
return errors.New("操作错误,当前状态不允许修改")
|
||||
}
|
||||
}
|
||||
mTechnologyProduct.Title = params.Title
|
||||
mTechnologyProduct.Image.Image = params.Image
|
||||
mTechnologyProduct.Video = params.Video
|
||||
mTechnologyProduct.Material = params.Material
|
||||
mTechnologyProduct.SetIndustryAttribute(params.Industrys)
|
||||
mTechnologyProduct.SetCustomerAttribute(params.Customers)
|
||||
mTechnologyProduct.Maturity = config.TechnologyMaturity(params.Maturity)
|
||||
mTechnologyProduct.LeadStandard = model2.TechnologyProductLeadStandard(params.LeadStandard)
|
||||
mTechnologyProduct.CooperationMode = config.TechnologyCooperationMode(params.CooperationMode)
|
||||
mTechnologyProduct.SetKeywordAttribute(params.Keywords)
|
||||
mTechnologyProduct.Introduce = params.Introduce
|
||||
|
||||
if mTechnologyProduct.ID > 0 {
|
||||
mTechnologyProduct.Status = model2.TechnologyProductStatusForExamining
|
||||
return model2.Updates(mTechnologyProduct.TechnologyProduct, mTechnologyProduct.TechnologyProduct)
|
||||
}
|
||||
mTechnologyProduct.TenantID = c.TenantID
|
||||
mTechnologyProduct.Local.Local = c.local
|
||||
mTechnologyProduct.MUid = c.UID
|
||||
|
||||
if params.IsSubmit > 0 {
|
||||
mTechnologyProduct.Status = model2.TechnologyProductStatusForExamining
|
||||
}
|
||||
return model2.Create(mTechnologyProduct.TechnologyProduct)
|
||||
}
|
||||
|
||||
// Shelf 上下架
|
||||
func (c *Product) Shelf(id uint64, status int) error {
|
||||
mTechnologyProduct := model.NewTechnologyProduct()
|
||||
mTechnologyProduct.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mTechnologyProduct.TechnologyProduct, []string{"id", "m_uid", "status"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,产品信息不存在或已被删除")
|
||||
} else if mTechnologyProduct.MUid != c.ManageUID {
|
||||
return errors.New("无权限操作")
|
||||
} else if mTechnologyProduct.ShelfStatus.ShelfStatus == model2.ShelfStatusKind(status) {
|
||||
return errors.New("操作错误,无需变更上下架状态")
|
||||
}
|
||||
return model2.Updates(mTechnologyProduct.TechnologyProduct, map[string]interface{}{
|
||||
"shelf_status": status, "updated_at": time.Now(),
|
||||
})
|
||||
}
|
||||
|
||||
// Delete 删除操作
|
||||
func (c *Product) Delete(id uint64) error {
|
||||
mTechnologyProduct := model.NewTechnologyProduct()
|
||||
mTechnologyProduct.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mTechnologyProduct.TechnologyProduct, []string{"id", "m_uid"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,产品信息不存在或已被删除")
|
||||
} else if mTechnologyProduct.MUid != c.ManageUID {
|
||||
return errors.New("无权限操作")
|
||||
}
|
||||
return model2.Delete(mTechnologyProduct.TechnologyProduct)
|
||||
}
|
||||
|
||||
func NewProduct() ProductHandle {
|
||||
return func(session *session.Enterprise, local string) *Product {
|
||||
return &Product{
|
||||
Enterprise: session,
|
||||
local: local,
|
||||
}
|
||||
}
|
||||
}
|
@ -94,7 +94,7 @@ func (c *Topic) Form(params *TopicParams) error {
|
||||
|
||||
if params.ID > 0 {
|
||||
mTechnologyTopic.ID = params.ID
|
||||
isExist, err := model2.FirstField(mTechnologyTopic.TechnologyTopic, []string{"id", "uid", "status"})
|
||||
isExist, err := model2.FirstField(mTechnologyTopic.TechnologyTopic, []string{"id", "m_uid", "status"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
@ -133,7 +133,7 @@ func (c *Topic) Delete(id uint64) error {
|
||||
mTechnologyTopic := model.NewTechnologyTopic()
|
||||
mTechnologyTopic.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mTechnologyTopic.TechnologyTopic, []string{"id", "uid", "status"})
|
||||
isExist, err := model2.FirstField(mTechnologyTopic.TechnologyTopic, []string{"id", "m_uid", "status"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
Reference in New Issue
Block a user