252 lines
7.4 KiB
Go
252 lines
7.4 KiB
Go
package controller
|
|
|
|
import (
|
|
"SciencesServer/app/api/website/model"
|
|
config2 "SciencesServer/app/basic/config"
|
|
model2 "SciencesServer/app/common/model"
|
|
"SciencesServer/app/service"
|
|
"SciencesServer/config"
|
|
"SciencesServer/utils"
|
|
"strings"
|
|
)
|
|
|
|
type Index struct {
|
|
*service.Session
|
|
local string
|
|
}
|
|
|
|
type IndexHandle func(session *service.Session, local string) *Index
|
|
|
|
type (
|
|
// InstanceInfo 首页信息
|
|
InstanceInfo struct {
|
|
*InstanceStaticInfo
|
|
Distribution *InstanceDistributionInfo `json:"distribution"`
|
|
}
|
|
// InstanceStaticInfo 统计信息
|
|
InstanceStaticInfo struct {
|
|
ExpertCount int64 `json:"expert_count"` // 专家数量
|
|
CompanyCount int64 `json:"company_count"` // 公司数量
|
|
PatentCount int64 `json:"patent_count"` // 专利数量
|
|
AchievementCount int64 `json:"achievement_count"` // 成果数量
|
|
DemandCount int64 `json:"demand_count"` // 需求数量
|
|
DockingCount int64 `json:"docking_count"` // 对接数量
|
|
}
|
|
// InstanceDistributionInfo 分布信息
|
|
InstanceDistributionInfo struct {
|
|
Expert map[string]*InstanceDistributionDetailInfo `json:"expert"` // 专家信息
|
|
Laboratory map[string]*InstanceDistributionDetailInfo `json:"laboratory"` // 公司信息
|
|
Demand map[string]*InstanceDistributionDetailInfo `json:"demand"` // 专利信息
|
|
Patent map[string]*InstanceDistributionDetailInfo `json:"patent"` // 成果信息
|
|
Achievement map[string]*InstanceDistributionDetailInfo `json:"achievement"` // 需求信息
|
|
}
|
|
// InstanceDistributionDetailInfo 分布区域信息
|
|
InstanceDistributionDetailInfo struct {
|
|
Code string `json:"code"` // 区域编码
|
|
Name string `json:"name"` // 区域名称
|
|
Count int `json:"count"` // 数量
|
|
Industry map[string]int `json:"industry"` // 行业领域
|
|
Children map[string]*InstanceDistributionDetailInfo `json:"children"` // 子集信息
|
|
}
|
|
)
|
|
|
|
// industry 所属行业信息
|
|
func (c *Index) industry(src, sep string) map[string]int {
|
|
values := strings.Split(src, sep)
|
|
|
|
out := make(map[string]int, 0)
|
|
|
|
for _, value := range values {
|
|
_values := make([]string, 0)
|
|
_ = utils.FromJSON(value, &_values)
|
|
|
|
for _, v := range _values {
|
|
if _, has := out[v]; has {
|
|
out[v]++
|
|
continue
|
|
}
|
|
out[v] = 1
|
|
}
|
|
}
|
|
return out
|
|
}
|
|
|
|
// distribution 分布统计
|
|
func (c *Index) distribution(src []*model.DataAreaDistributionInfo) map[string]*InstanceDistributionDetailInfo {
|
|
out := make(map[string]*InstanceDistributionDetailInfo, 0)
|
|
|
|
for _, v := range src {
|
|
industrys := c.industry(v.Industry, "&")
|
|
|
|
_, has := out[v.Province]
|
|
|
|
if !has {
|
|
out[v.Province] = &InstanceDistributionDetailInfo{
|
|
Code: v.Province,
|
|
Name: config2.MemoryForAreaInfo[config.DefaultChinaAreaCode][v.Province],
|
|
Industry: nil,
|
|
Count: 1,
|
|
Children: make(map[string]*InstanceDistributionDetailInfo, 0),
|
|
}
|
|
goto NEXT
|
|
}
|
|
out[v.Province].Count++
|
|
NEXT:
|
|
if _, has = out[v.Province].Children[v.City]; !has {
|
|
out[v.Province].Children[v.City] = &InstanceDistributionDetailInfo{
|
|
Code: v.City,
|
|
Count: 1,
|
|
Name: config2.MemoryForAreaInfo[v.Province][v.City],
|
|
Industry: industrys,
|
|
}
|
|
continue
|
|
}
|
|
out[v.Province].Children[v.City].Count++
|
|
}
|
|
return out
|
|
}
|
|
|
|
// static 数量统计
|
|
func (c *Index) static() (*InstanceStaticInfo, error) {
|
|
out := new(InstanceStaticInfo)
|
|
var err error
|
|
// 专家信息
|
|
mManageExpert := model.NewManageExpert()
|
|
|
|
if err = model2.Count(mManageExpert.ManageExpert, &out.ExpertCount, model2.NewWhere("examine_status", model2.ExamineStatusForAgree)); err != nil {
|
|
return nil, err
|
|
}
|
|
// 专利信息
|
|
mSysPatent := model.NewSysPatent()
|
|
|
|
if err = model2.Count(mSysPatent.SysPatent, &out.PatentCount, model2.NewWhere("shelf_status", model2.ShelfStatusForUp)); err != nil {
|
|
return nil, err
|
|
}
|
|
//成果信息
|
|
mTechnologyAchievement := model.NewTechnologyAchievement()
|
|
|
|
if err = model2.Count(mTechnologyAchievement.TechnologyAchievement, &out.AchievementCount, model2.NewWhere("shelf_status", model2.ShelfStatusForUp),
|
|
model2.NewWhere("status", model2.TechnologyAchievementStatusForAgree)); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// 公司信息
|
|
mManageCompany := model.NewManageCompany()
|
|
|
|
if err = model2.Count(mManageCompany.ManageCompany, &out.CompanyCount, model2.NewWhere("examine_status", model2.ExamineStatusForAgree)); err != nil {
|
|
return nil, err
|
|
}
|
|
// 需求信息
|
|
mTechnologyDemand := model.NewTechnologyDemand()
|
|
|
|
if err = model2.Count(mTechnologyDemand.TechnologyDemand, &out.DemandCount,
|
|
model2.NewWhere("status", model2.TechnologyDemandStatusForAgree)); err != nil {
|
|
return nil, err
|
|
}
|
|
// 对接信息
|
|
mServiceDocking := model.NewServiceDocking()
|
|
|
|
if err = model2.Count(mServiceDocking.ServiceDocking, &out.DockingCount); err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
// distributionExpert 专家分布
|
|
func (c *Index) distributionExpert() (map[string]*InstanceDistributionDetailInfo, error) {
|
|
mManageExpert := model.NewManageExpert()
|
|
out, err := mManageExpert.Distribution()
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return c.distribution(out), nil
|
|
}
|
|
|
|
// distributionLaboratory 实验室分布
|
|
func (c *Index) distributionLaboratory() (map[string]*InstanceDistributionDetailInfo, error) {
|
|
mManageLaboratory := model.NewManageLaboratory()
|
|
out, err := mManageLaboratory.Distribution()
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return c.distribution(out), nil
|
|
}
|
|
|
|
// distributionDemand 需求信息
|
|
func (c *Index) distributionDemand() (map[string]*InstanceDistributionDetailInfo, error) {
|
|
mTechnologyDemand := model.NewTechnologyDemand()
|
|
out, err := mTechnologyDemand.Distribution()
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return c.distribution(out), nil
|
|
}
|
|
|
|
// distributionPatent 专利信息
|
|
func (c *Index) distributionPatent() (map[string]*InstanceDistributionDetailInfo, error) {
|
|
mSysPatent := model.NewSysPatent()
|
|
out, err := mSysPatent.Distribution()
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return c.distribution(out), nil
|
|
}
|
|
|
|
// distributionAchievement 技术成果信息
|
|
func (c *Index) distributionAchievement() (map[string]*InstanceDistributionDetailInfo, error) {
|
|
mSysPatent := model.NewSysPatent()
|
|
out, err := mSysPatent.Distribution()
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return c.distribution(out), nil
|
|
}
|
|
|
|
// Instance 首页信息
|
|
func (c *Index) Instance() (*InstanceInfo, error) {
|
|
out := &InstanceInfo{
|
|
InstanceStaticInfo: new(InstanceStaticInfo),
|
|
Distribution: new(InstanceDistributionInfo),
|
|
}
|
|
var err error
|
|
// 数量统计信息
|
|
if out.InstanceStaticInfo, err = c.static(); err != nil {
|
|
return nil, err
|
|
}
|
|
// 专家区域分布信息
|
|
if out.Distribution.Expert, err = c.distributionExpert(); err != nil {
|
|
return nil, err
|
|
}
|
|
// 实验室区域分布信息
|
|
if out.Distribution.Laboratory, err = c.distributionLaboratory(); err != nil {
|
|
return nil, err
|
|
}
|
|
// 需求信息区域分布信息
|
|
if out.Distribution.Demand, err = c.distributionDemand(); err != nil {
|
|
return nil, err
|
|
}
|
|
// 专利信息区域分布信息
|
|
if out.Distribution.Patent, err = c.distributionPatent(); err != nil {
|
|
return nil, err
|
|
}
|
|
// 成果信息区域分布信息
|
|
if out.Distribution.Achievement, err = c.distributionAchievement(); err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func NewIndex() IndexHandle {
|
|
return func(session *service.Session, local string) *Index {
|
|
return &Index{
|
|
Session: session,
|
|
local: local,
|
|
}
|
|
}
|
|
}
|