diff --git a/app/api/enterprise/api/manage.go b/app/api/enterprise/api/manage.go index f33b125..5264196 100644 --- a/app/api/enterprise/api/manage.go +++ b/app/api/enterprise/api/manage.go @@ -10,7 +10,7 @@ import ( type Manage struct{} type ( - // enterpriseForm 企业信息 + // enterpriseForm 设备信息 enterpriseForm struct { Mode int `json:"mode" form:"mode" binding:"required"` Title string `json:"title" form:"title" binding:"required"` @@ -164,3 +164,29 @@ func (*Manage) EquipmentDelete(c *gin.Context) { Delete(form.Convert()) api.APIResponse(err)(c) } + +func (*Manage) CompanyDetail(c *gin.Context) { + form := new(api.IDStringForm) + + if err := api.Bind(form)(c); err != nil { + api.APIFailure(err.(error))(c) + return + } + data, err := manage.NewCompany()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)). + Detail(form.Convert()) + api.APIResponse(err, data)(c) +} + +func (*Manage) CompanyProduct(c *gin.Context) { + form := &struct { + api.IDStringForm + api.PageForm + }{} + if err := api.Bind(form)(c); err != nil { + api.APIFailure(err.(error))(c) + return + } + data, err := manage.NewCompany()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)). + Product(form.Convert(), form.Page, form.PageSize) + api.APIResponse(err, data)(c) +} diff --git a/app/api/enterprise/controller/manage/company.go b/app/api/enterprise/controller/manage/company.go new file mode 100644 index 0000000..7ba011e --- /dev/null +++ b/app/api/enterprise/controller/manage/company.go @@ -0,0 +1,98 @@ +package manage + +import ( + "SciencesServer/app/api/enterprise/model" + model2 "SciencesServer/app/common/model" + "SciencesServer/app/session" + "errors" +) + +// Company 公司信息 +type Company struct { + *session.Enterprise + local string +} + +type CompanyHandle func(session *session.Enterprise, local string) *Company + +type ( + // CompanyDetail 详细信息 + CompanyDetail struct { + ID string `json:"id"` + *model2.ManageCompany + Keywords []string `json:"keywords"` + } + // CompanyProductInfo 公司产品信息 + CompanyProductInfo struct { + ID string `json:"id"` + *model.TechnologyProductInfo + Industrys []string `json:"industrys"` + Keywords []string `json:"keywords"` + } +) + +// Detail 详细信息 +func (c *Company) Detail(id uint64) (*CompanyDetail, error) { + mManageCompany := model.NewManageCompany() + mManageCompany.ID = id + + isExist, err := model2.First(mManageCompany.ManageCompany) + + if err != nil { + return nil, err + } else if !isExist { + return nil, errors.New("操作错误,企业信息不存在或已被删除") + } + return &CompanyDetail{ + ID: mManageCompany.GetEncodeID(), + ManageCompany: mManageCompany.ManageCompany, + Keywords: mManageCompany.GetKeywordAttribute(), + }, nil +} + +// Product 产品信息 +func (c *Company) Product(id uint64, page, pageSize int) ([]*CompanyProductInfo, error) { + mUserCompany := model.NewUserCompany() + + uids := make([]uint64, 0) + + // 查询公司下所有的用户信息 + err := model2.Pluck(mUserCompany.UserCompany, "uid", &uids, model2.NewWhere("company_id", id), + model2.NewWhere("invalid_status", model2.InvalidStatusForNot)) + + if err != nil { + return nil, err + } + mTechnologyProduct := model.NewTechnologyProduct() + + var count int64 + + out := make([]*model.TechnologyProductInfo, 0) + + if out, err = mTechnologyProduct.Product(page, pageSize, &count, model2.NewWhereIn("uid", uids)); err != nil { + return nil, err + } + list := make([]*CompanyProductInfo, 0) + + for _, v := range out { + mTechnologyProduct.Industry = v.Industry + mTechnologyProduct.Keyword = v.Keyword + + list = append(list, &CompanyProductInfo{ + ID: v.GetEncodeID(), + TechnologyProductInfo: v, + Industrys: mTechnologyProduct.GetIndustryAttribute(), + Keywords: mTechnologyProduct.GetKeywordAttribute(), + }) + } + return list, nil +} + +func NewCompany() CompanyHandle { + return func(session *session.Enterprise, local string) *Company { + return &Company{ + Enterprise: session, + local: local, + } + } +} diff --git a/app/api/enterprise/controller/settled/company.go b/app/api/enterprise/controller/settled/company.go index 8154b46..a551d71 100644 --- a/app/api/enterprise/controller/settled/company.go +++ b/app/api/enterprise/controller/settled/company.go @@ -94,6 +94,7 @@ func (c *Company) Launch(params *BasicParams, inviterID uint64, other *config.Id mManageCompany.License = other.License mManageCompany.SetIndustryAttribute(params.Industrys) mManageCompany.SetKeywordAttribute(params.Keywords) + mManageCompany.SetDirectionAttribute(other.Directions) mManageCompany.Introduce = params.Introduce return orm.GetDB().Transaction(func(tx *gorm.DB) error { diff --git a/app/api/enterprise/controller/technology/product.go b/app/api/enterprise/controller/technology/product.go index f323a22..535aa00 100644 --- a/app/api/enterprise/controller/technology/product.go +++ b/app/api/enterprise/controller/technology/product.go @@ -36,6 +36,7 @@ type ( ProductVisitInfo struct { ID string `json:"id"` *model.TechnologyProductVisitInfo + CompanyID string `json:"company_id"` CompanyKeywords []string `json:"company_keywords"` } // ProductParams 产品参数信息 @@ -139,6 +140,7 @@ func (c *Product) Visit(id uint64, page, pageSize int) (*controller.ReturnPages, list = append(list, &ProductVisitInfo{ ID: v.GetEncodeID(), TechnologyProductVisitInfo: v, + CompanyID: (&model2.Model{ID: v.CompanyID}).GetEncodeID(), CompanyKeywords: mManageCompany.GetKeywordAttribute(), }) } diff --git a/app/api/enterprise/model/technology_product.go b/app/api/enterprise/model/technology_product.go index 82d3c1b..a7a2bdd 100644 --- a/app/api/enterprise/model/technology_product.go +++ b/app/api/enterprise/model/technology_product.go @@ -1,11 +1,57 @@ package model -import "SciencesServer/app/common/model" +import ( + "SciencesServer/app/basic/config" + "SciencesServer/app/common/model" + "SciencesServer/serve/orm" + "fmt" +) type TechnologyProduct struct { *model.TechnologyProduct } +// TechnologyProductInfo 产品信息 +type TechnologyProductInfo struct { + model.Model + Title string `json:"title"` + model.Image + Maturity config.TechnologyMaturity `json:"maturity"` + LeadStandard model.TechnologyProductLeadStandard `json:"lead_standard"` + CooperationMode config.TechnologyCooperationMode `json:"cooperation_mode"` + Industry string `json:"industry"` + Keyword string `json:"keyword"` + VisitCount int `json:"visit_count"` + CollectCount int `json:"collect_count"` +} + +// Product 产品信息 +func (m *TechnologyProduct) Product(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*TechnologyProductInfo, error) { + db := orm.GetDB().Table(m.TableName()+" AS p"). + Select("p.id", "p.title", "p.image", "p.maturity", "p.industry", "p.cooperation_mode", "p.keyword", + "v.count AS v visit_count", "c.count AS collect_count"). + Joins(fmt.Sprintf("(SELECT company_id, COUNT(id) AS count FROM %s WHERE is_deleted = %d GROUP BY company_id) AS v ON p.id = v.company_id", + model.NewTechnologyProductVisit().TableName(), model.DeleteStatusForNot)). + Joins(fmt.Sprintf("(SELECT company_id, COUNT(id) AS count FROM %s WHERE is_deleted = %d GROUP BY company_id) AS c ON p.id = c.company_id", + model.NewTechnologyProductCollect().TableName(), model.DeleteStatusForNot)) + + out := make([]*TechnologyProductInfo, 0) + + if len(where) > 0 { + for _, v := range where { + db = db.Where(v.Condition, v.Value) + } + } + if err := db.Count(count).Error; err != nil { + return nil, err + } + if err := db.Order("p.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil { + return nil, err + } + return out, nil + +} + func NewTechnologyProduct() *TechnologyProduct { return &TechnologyProduct{model.NewTechnologyProduct()} } diff --git a/app/api/enterprise/model/technology_product_collect.go b/app/api/enterprise/model/technology_product_collect.go new file mode 100644 index 0000000..c88dcdd --- /dev/null +++ b/app/api/enterprise/model/technology_product_collect.go @@ -0,0 +1,11 @@ +package model + +import "SciencesServer/app/common/model" + +type TechnologyProductCollect struct { + *model.TechnologyProductCollect +} + +func NewTechnologyProductCollect() *TechnologyProductCollect { + return &TechnologyProductCollect{model.NewTechnologyProductCollect()} +} diff --git a/app/basic/config/public.go b/app/basic/config/public.go index 64aeb7d..ba6a7e4 100644 --- a/app/basic/config/public.go +++ b/app/basic/config/public.go @@ -11,10 +11,11 @@ type Area struct { type ( // IdentityForCompany 公司附加信息 IdentityForCompany struct { - Kind int `json:"kind" form:"kind" binding:"required"` // 企业类型 - Product string `json:"product" form:"product" binding:"required"` // 企业产品 - Url string `json:"url" form:"url"` // 企业网站 - License string `json:"license" form:"license" binding:"required"` // 营业执照 + Kind int `json:"kind" form:"kind" binding:"required"` // 企业类型 + Product string `json:"product" form:"product" binding:"required"` // 企业产品 + Url string `json:"url" form:"url"` // 企业网站 + License string `json:"license" form:"license" binding:"required"` // 营业执照 + Directions []string `json:"direction" form:"direction"` // 产品方向 } // IdentityForExpert 专家附加信息 IdentityForExpert struct { diff --git a/app/common/init.go b/app/common/init.go index 57475ac..e2e6cce 100644 --- a/app/common/init.go +++ b/app/common/init.go @@ -124,6 +124,7 @@ func initModel() { &synchronized{iModel: model.NewManageCompany()}, &synchronized{iModel: model.NewManageExpert()}, &synchronized{iModel: model.NewManageLaboratory()}, &synchronized{iModel: model.NewManageResearch()}, &synchronized{iModel: model.NewManageAgent()}, + // 数据管理 ) } func initCacheMode() { diff --git a/app/common/model/manage_company.go b/app/common/model/manage_company.go index c531216..609ba33 100644 --- a/app/common/model/manage_company.go +++ b/app/common/model/manage_company.go @@ -17,6 +17,7 @@ type ManageCompany struct { License string `gorm:"column:license;type:varchar(255);default:'';comment:营业执照" json:"license"` Industry string `gorm:"column:industry;type:varchar(255);default:'';comment:行业领域" json:"-"` Keyword string `gorm:"column:keyword;type:varchar(255);default:'';comment:关键词" json:"-"` + Direction string `gorm:"column:direction;type:varchar(255);default:'';comment:生产方向" json:"-"` Introduce string `gorm:"column:introduce;type:text;comment:介绍描述" json:"introduce"` Examine ModelDeleted @@ -63,6 +64,16 @@ func (m *ManageCompany) SetKeywordAttribute(value []string) { m.Keyword = utils.AnyToJSON(value) } +func (m *ManageCompany) GetDirectionAttribute() []string { + out := make([]string, 0) + _ = utils.FromJSON(m.Direction, &out) + return out +} + +func (m *ManageCompany) SetDirectionAttribute(value []string) { + m.Direction = utils.AnyToJSON(value) +} + func NewManageCompany() *ManageCompany { return &ManageCompany{} } diff --git a/app/common/model/user_company_collect.go b/app/common/model/user_company_collect.go new file mode 100644 index 0000000..a638d8e --- /dev/null +++ b/app/common/model/user_company_collect.go @@ -0,0 +1,18 @@ +package model + +// TechnologyProductCollect 产品收藏数据模型 +type TechnologyProductCollect struct { + Model + UID uint64 `gorm:"column:uid;type:int;default:0;comment:用户uuid" json:"-"` + ProductID uint64 `gorm:"column:product_id;type:int(11);default:0;comment:产品ID" json:"-"` + ModelDeleted + ModelAt +} + +func (m *TechnologyProductCollect) TableName() string { + return "technology_product_collect" +} + +func NewTechnologyProductCollect() *TechnologyProductCollect { + return &TechnologyProductCollect{} +} diff --git a/router/address.go b/router/address.go index 27933ad..5ad5e5e 100644 --- a/router/address.go +++ b/router/address.go @@ -235,6 +235,8 @@ func registerEnterpriseAPI(app *gin.Engine) { manageV1.POST("/equipment/add", _api.EquipmentAdd) manageV1.POST("/equipment/edit", _api.EquipmentEdit) manageV1.POST("/equipment/delete", _api.EquipmentDelete) + manageV1.POST("/company/detail", _api.CompanyDetail) + manageV1.POST("/company/product", _api.CompanyProduct) } // Identity 身份信息 identityV1 := v1.Group("/config")