2022-01-19 13:23:07 +08:00
|
|
|
|
package manage
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"SciencesServer/app/api/admin/model"
|
|
|
|
|
"SciencesServer/app/basic/config"
|
|
|
|
|
"SciencesServer/app/basic/controller"
|
|
|
|
|
model2 "SciencesServer/app/common/model"
|
2022-02-15 17:19:23 +08:00
|
|
|
|
"SciencesServer/app/service"
|
2022-01-19 13:23:07 +08:00
|
|
|
|
"SciencesServer/app/session"
|
2022-01-20 09:43:26 +08:00
|
|
|
|
config2 "SciencesServer/config"
|
2022-05-03 23:21:04 +08:00
|
|
|
|
"SciencesServer/lib"
|
2022-05-11 22:30:18 +08:00
|
|
|
|
"SciencesServer/serve/orm"
|
2022-01-19 13:23:07 +08:00
|
|
|
|
"SciencesServer/utils"
|
|
|
|
|
"errors"
|
2022-05-03 23:21:04 +08:00
|
|
|
|
"fmt"
|
2022-05-11 22:30:18 +08:00
|
|
|
|
"gorm.io/gorm"
|
2022-02-15 17:19:23 +08:00
|
|
|
|
"strings"
|
2022-01-19 13:23:07 +08:00
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Expert struct {
|
|
|
|
|
*session.Admin
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type ExpertHandle func(session *session.Admin) *Expert
|
|
|
|
|
|
|
|
|
|
type (
|
|
|
|
|
// ExpertInstance 专家信息
|
|
|
|
|
ExpertInstance struct {
|
2022-01-20 11:09:29 +08:00
|
|
|
|
ID string `json:"id"`
|
|
|
|
|
Name string `json:"name"`
|
|
|
|
|
Industrys []string `json:"industrys"`
|
|
|
|
|
ResearchName string `json:"research_name"`
|
|
|
|
|
LaboratoryName string `json:"laboratory_name"`
|
|
|
|
|
AchievementCount int `json:"achievement_count"`
|
|
|
|
|
PatentCount int `json:"patent_count"`
|
|
|
|
|
Address string `json:"address"`
|
2022-01-20 10:03:38 +08:00
|
|
|
|
model2.Examine
|
|
|
|
|
CreatedAt time.Time `json:"created_at"`
|
|
|
|
|
Area string `json:"area"`
|
2022-01-19 13:23:07 +08:00
|
|
|
|
}
|
|
|
|
|
// ExpertDetail 专家详细信息
|
|
|
|
|
ExpertDetail struct {
|
2022-01-26 16:14:16 +08:00
|
|
|
|
ID string `json:"id"`
|
|
|
|
|
TenantID string `json:"tenant_id"`
|
|
|
|
|
ResearchID string `json:"research_id"`
|
|
|
|
|
LaboratoryID string `json:"laboratory_id"`
|
2022-01-19 13:23:07 +08:00
|
|
|
|
*model2.ManageExpert
|
2022-01-20 09:43:26 +08:00
|
|
|
|
Industrys []*config.Industry `json:"industrys"`
|
|
|
|
|
Keywords []string `json:"keywords"`
|
|
|
|
|
Researchs []string `json:"researchs"`
|
|
|
|
|
Area string `json:"area"`
|
2022-01-19 13:23:07 +08:00
|
|
|
|
}
|
2022-02-09 17:35:31 +08:00
|
|
|
|
// ExpertPatent 专家专利信息
|
|
|
|
|
ExpertPatent struct {
|
|
|
|
|
ID string `json:"id"`
|
|
|
|
|
*model.ManageExpertPatent
|
|
|
|
|
IsBind bool `json:"is_bind"`
|
|
|
|
|
}
|
2022-05-03 23:21:04 +08:00
|
|
|
|
|
|
|
|
|
// ExpertExcel 专家表格数据
|
|
|
|
|
ExpertExcel struct {
|
|
|
|
|
Name string `json:"name" xlsx:"专家姓名"`
|
|
|
|
|
Province string `json:"province" xlsx:"所在省"`
|
|
|
|
|
City string `json:"city" xlsx:"所在市"`
|
|
|
|
|
District string `json:"district" xlsx:"所在区"`
|
|
|
|
|
Address string `json:"address" xlsx:"详细地址"`
|
|
|
|
|
Site string `json:"site" form:"所属站点"`
|
|
|
|
|
Industry string `json:"industry" xlsx:"所属领域"`
|
|
|
|
|
Research string `json:"research" xlsx:"所属单位"`
|
|
|
|
|
Laboratory string `json:"laboratory" xlsx:"所属实验室"`
|
|
|
|
|
School string `json:"school" xlsx:"毕业院校"`
|
|
|
|
|
Keyword string `json:"keyword" xlsx:"关键词"`
|
|
|
|
|
Education string `json:"education" xlsx:"最高学历"`
|
|
|
|
|
Major string `json:"major" xlsx:"主修专业"`
|
|
|
|
|
Job string `json:"job" xlsx:"职务"`
|
2022-05-11 22:15:30 +08:00
|
|
|
|
Title string `json:"title" xlsx:"职称"`
|
2022-05-03 23:21:04 +08:00
|
|
|
|
WorkAt string `json:"work_at" xlsx:"从业时间"`
|
|
|
|
|
Gender string `json:"gender" xlsx:"性别"`
|
|
|
|
|
ResearchWhere string `json:"research_where" xlsx:"研究方向"`
|
|
|
|
|
Mobile string `json:"mobile" xlsx:"手机号"`
|
|
|
|
|
Introduce string `json:"introduce" xlsx:"个人简介"`
|
|
|
|
|
Technology string `json:"technology" xlsx:"核心技术及产品"`
|
|
|
|
|
Scene string `json:"scene" xlsx:"应用场景"`
|
|
|
|
|
Tag1 string `json:"tag_1" xlsx:"代表成果及合作模式"`
|
2022-05-11 22:15:30 +08:00
|
|
|
|
Tag2 string `json:"tag_2" xlsx:"已合作企业"`
|
|
|
|
|
Tag3 string `json:"tag_3" xlsx:"想合作企业"`
|
2022-05-03 23:21:04 +08:00
|
|
|
|
}
|
2022-05-11 22:30:18 +08:00
|
|
|
|
// ExpertExcelInfo 表格详细信息
|
|
|
|
|
ExpertExcelInfo struct {
|
|
|
|
|
*model2.ManageExpert
|
|
|
|
|
Tag2 string `json:"tag_2" xlsx:"已合作企业"`
|
|
|
|
|
Tag3 string `json:"tag_3" xlsx:"想合作企业"`
|
|
|
|
|
}
|
2022-01-19 13:23:07 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Instance 首页信息
|
|
|
|
|
func (c *Expert) Instance(tenantID uint64, name string, examineStatus int, page, pageSize int) (*controller.ReturnPages, error) {
|
|
|
|
|
mManageExpert := model.NewManageExpert()
|
|
|
|
|
|
|
|
|
|
where := make([]*model2.ModelWhere, 0)
|
|
|
|
|
|
|
|
|
|
if c.TenantID > 0 {
|
|
|
|
|
where = append(where, model2.NewWhere("e.tenant_id", c.TenantID))
|
|
|
|
|
}
|
|
|
|
|
if tenantID > 0 {
|
|
|
|
|
where = append(where, model2.NewWhere("e.tenant_id", tenantID))
|
|
|
|
|
}
|
|
|
|
|
if name != "" {
|
|
|
|
|
where = append(where, model2.NewWhereLike("e.name", name))
|
|
|
|
|
}
|
|
|
|
|
if examineStatus > 0 {
|
|
|
|
|
where = append(where, model2.NewWhere("e.examine_status", examineStatus))
|
|
|
|
|
}
|
|
|
|
|
var count int64
|
|
|
|
|
|
|
|
|
|
out, err := mManageExpert.Experts(page, pageSize, &count, where...)
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
list := make([]*ExpertInstance, 0)
|
|
|
|
|
|
|
|
|
|
for _, v := range out {
|
|
|
|
|
_industrys := make([]string, 0)
|
|
|
|
|
|
2022-01-20 10:03:38 +08:00
|
|
|
|
for _, v := range v.GetIndustryAttribute() {
|
2022-01-20 09:43:26 +08:00
|
|
|
|
_industrys = append(_industrys, config.GetIndustryInfo(v, "-", "/").Value)
|
2022-01-19 13:23:07 +08:00
|
|
|
|
}
|
|
|
|
|
// 研究机构,实验室
|
|
|
|
|
list = append(list, &ExpertInstance{ID: v.GetEncodeID(), Name: v.Name, Industrys: _industrys,
|
2022-01-20 11:09:29 +08:00
|
|
|
|
AchievementCount: v.AchievementCount, PatentCount: v.PatentCount,
|
2022-01-20 10:03:38 +08:00
|
|
|
|
ResearchName: v.ResearchName, LaboratoryName: v.LaboratoryName, Examine: v.Examine,
|
2022-01-19 16:03:47 +08:00
|
|
|
|
Address: v.FormatBasic(), CreatedAt: v.CreatedAt, Area: (&model2.Area{
|
|
|
|
|
Province: v.TenantProvince,
|
|
|
|
|
City: v.TenantCity,
|
|
|
|
|
}).FormatBasic(),
|
2022-01-19 13:23:07 +08:00
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
return &controller.ReturnPages{Data: list, Count: count}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Detail 详细信息
|
2022-01-19 14:22:44 +08:00
|
|
|
|
func (c *Expert) Detail(id uint64) (*ExpertDetail, error) {
|
2022-01-19 13:23:07 +08:00
|
|
|
|
mManageExpert := model.NewManageExpert()
|
|
|
|
|
|
|
|
|
|
out, err := mManageExpert.Expert(id)
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
} else if out.ManageExpert == nil {
|
|
|
|
|
return nil, errors.New("操作错误,专家信息不存在或已被删除")
|
|
|
|
|
}
|
2022-01-20 09:43:26 +08:00
|
|
|
|
_industrys := make([]*config.Industry, 0)
|
|
|
|
|
|
|
|
|
|
for _, v := range out.GetIndustryAttribute() {
|
|
|
|
|
_industrys = append(_industrys, config.GetIndustryInfo(v, "-", ">"))
|
|
|
|
|
}
|
|
|
|
|
out.Image.Image = out.Image.Analysis(config2.SystemConfig[config2.SysImageDomain])
|
|
|
|
|
|
2022-01-19 13:23:07 +08:00
|
|
|
|
return &ExpertDetail{
|
|
|
|
|
ID: out.GetEncodeID(),
|
2022-01-20 09:43:26 +08:00
|
|
|
|
TenantID: out.GetEncodeTenantID(),
|
2022-01-26 16:14:16 +08:00
|
|
|
|
ResearchID: (&model2.Model{ID: out.ResearchID}).GetEncodeID(),
|
|
|
|
|
LaboratoryID: (&model2.Model{ID: out.LaboratoryID}).GetEncodeID(),
|
2022-01-19 13:23:07 +08:00
|
|
|
|
ManageExpert: out.ManageExpert,
|
2022-01-20 09:43:26 +08:00
|
|
|
|
Industrys: _industrys,
|
2022-01-19 13:23:07 +08:00
|
|
|
|
Keywords: out.GetKeywordAttribute(),
|
|
|
|
|
Researchs: out.GetResearchAttribute(),
|
|
|
|
|
}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Form 数据操作
|
2022-01-19 14:22:44 +08:00
|
|
|
|
func (c *Expert) Form(params *BasicParams, other *config.IdentityForExpert) error {
|
2022-01-19 13:23:07 +08:00
|
|
|
|
mManageExpert := model.NewManageExpert()
|
|
|
|
|
|
|
|
|
|
if params.ID > 0 {
|
|
|
|
|
mManageExpert.ID = params.ID
|
|
|
|
|
|
2022-02-15 17:19:23 +08:00
|
|
|
|
isExist, err := model2.FirstField(mManageExpert.ManageExpert, []string{"id", "name", "mobile", "tenant_id", "examine_status", "created_at"})
|
2022-01-19 13:23:07 +08:00
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
} else if !isExist {
|
|
|
|
|
return errors.New("操作错误,专家信息不存在或已被删除")
|
|
|
|
|
}
|
2022-01-19 14:22:44 +08:00
|
|
|
|
if c.TenantID > 0 {
|
|
|
|
|
if mManageExpert.TenantID != c.TenantID {
|
|
|
|
|
return errors.New("操作错误,无权限操作")
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2022-01-28 16:59:15 +08:00
|
|
|
|
if mManageExpert.Mobile != params.Mobile {
|
|
|
|
|
if isExist, err = params.isExist(mManageExpert.ManageExpert, model2.NewWhere("mobile", params.Mobile)); err != nil {
|
2022-01-19 14:22:44 +08:00
|
|
|
|
return err
|
|
|
|
|
} else if isExist {
|
|
|
|
|
return errors.New("操作错误,当前站点下已存在相同手机号码")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-19 13:23:07 +08:00
|
|
|
|
}
|
2022-01-19 14:22:44 +08:00
|
|
|
|
mManageExpert.TenantID = c.TenantID
|
2022-02-15 17:19:23 +08:00
|
|
|
|
mManageExpert.Name = params.Name
|
2022-01-19 13:23:07 +08:00
|
|
|
|
mManageExpert.ResearchID = other.ConvertResearch()
|
|
|
|
|
mManageExpert.LaboratoryID = other.ConvertLaboratory()
|
|
|
|
|
mManageExpert.Image.Image = params.Image
|
|
|
|
|
mManageExpert.Area = model2.Area{
|
|
|
|
|
Province: params.Area.Province, City: params.Area.City, District: params.Area.District, Address: params.Area.Address,
|
|
|
|
|
}
|
2022-01-19 14:22:44 +08:00
|
|
|
|
mManageExpert.Education = other.Education
|
2022-01-19 13:23:07 +08:00
|
|
|
|
mManageExpert.School = other.School
|
|
|
|
|
mManageExpert.Major = other.Major
|
|
|
|
|
mManageExpert.Job = other.Job
|
|
|
|
|
mManageExpert.Title = other.Title
|
|
|
|
|
mManageExpert.Gender = model2.Gender{Gender: model2.GenderKind(other.Gender)}
|
|
|
|
|
mManageExpert.WorkAt = utils.DataTimeToDate(other.WorkAt)
|
|
|
|
|
mManageExpert.SetIndustryAttribute(params.Industrys)
|
|
|
|
|
mManageExpert.SetKeywordAttribute(params.Keywords)
|
|
|
|
|
mManageExpert.SetResearchAttribute(other.Researchs)
|
|
|
|
|
mManageExpert.Introduce = params.Introduce
|
|
|
|
|
|
2022-01-19 14:22:44 +08:00
|
|
|
|
if c.TenantID <= 0 {
|
|
|
|
|
mManageExpert.TenantID = params.TenantID
|
|
|
|
|
}
|
2022-02-15 17:19:23 +08:00
|
|
|
|
_industrys := make([]string, 0)
|
|
|
|
|
|
|
|
|
|
for _, v := range params.Industrys {
|
|
|
|
|
_industrys = append(_industrys, config.GetIndustryInfo(v, "-", "-").Value)
|
|
|
|
|
}
|
|
|
|
|
manage := service.NewESManage(
|
|
|
|
|
service.WithManageIdentity(config.TenantUserIdentityForExpert),
|
|
|
|
|
service.WithManageIndustry(strings.Join(_industrys, ";")),
|
|
|
|
|
service.WithManageKeyword(strings.Join(params.Keywords, ";")),
|
|
|
|
|
)
|
2022-01-19 13:23:07 +08:00
|
|
|
|
if mManageExpert.ID > 0 {
|
2022-02-15 17:19:23 +08:00
|
|
|
|
if err := model2.Updates(mManageExpert.ManageExpert, mManageExpert.ManageExpert); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if mManageExpert.ExamineStatus == model2.ExamineStatusForAgree {
|
|
|
|
|
_ = manage.Update()
|
|
|
|
|
}
|
|
|
|
|
return nil
|
2022-01-19 13:23:07 +08:00
|
|
|
|
}
|
2022-01-19 14:22:44 +08:00
|
|
|
|
// 查询手机号码是否在当前租户下是否已经注册了
|
2022-01-19 13:23:07 +08:00
|
|
|
|
mManageExpert.Mobile = params.Mobile
|
2022-01-20 11:09:29 +08:00
|
|
|
|
mManageExpert.ExamineStatus = model2.ExamineStatusForAgree
|
|
|
|
|
mManageExpert.ExamineRemark = "主动创建,无需审核"
|
2022-01-19 13:23:07 +08:00
|
|
|
|
|
2022-01-28 16:59:15 +08:00
|
|
|
|
if isExist, err := params.isExist(mManageExpert.ManageExpert,
|
2022-01-19 14:22:44 +08:00
|
|
|
|
model2.NewWhere("mobile", params.Mobile)); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
} else if isExist {
|
2022-01-28 16:59:15 +08:00
|
|
|
|
return errors.New("操作错误,已存在相同手机号码")
|
2022-01-19 14:22:44 +08:00
|
|
|
|
}
|
2022-02-15 17:19:23 +08:00
|
|
|
|
if err := model2.Create(mManageExpert.ManageExpert); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
service.WithManageID(mManageExpert.ID)(manage)
|
|
|
|
|
service.WithManageTitle(params.Name)(manage)
|
|
|
|
|
|
|
|
|
|
return manage.Create()
|
2022-01-19 13:23:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-02-09 17:35:31 +08:00
|
|
|
|
// Patent 专利信息
|
|
|
|
|
func (c *Expert) Patent(id uint64, title, applyName string) ([]*ExpertPatent, error) {
|
|
|
|
|
mManageExpert := model.NewManageExpert()
|
|
|
|
|
|
|
|
|
|
out, err := mManageExpert.Basic(id)
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
} else if out == nil || out.ID <= 0 {
|
|
|
|
|
return nil, errors.New("操作错误,未找到对应的专家信息")
|
|
|
|
|
}
|
|
|
|
|
// 查看专利信息
|
|
|
|
|
patents := make([]*model.ManageExpertPatent, 0)
|
|
|
|
|
|
|
|
|
|
where := []*model2.ModelWhere{
|
|
|
|
|
//model2.NewWhereFindInSet("p.apply_name", out.ResearchName),
|
|
|
|
|
model2.NewWhereFindInSet("p.inventor", out.Name),
|
|
|
|
|
}
|
|
|
|
|
if title != "" {
|
|
|
|
|
where = append(where, model2.NewWhereLike("p.title", title))
|
|
|
|
|
}
|
|
|
|
|
if applyName != "" {
|
|
|
|
|
where = append(where, model2.NewWhereFindInSet("p.apply_name", applyName))
|
|
|
|
|
}
|
|
|
|
|
if patents, err = mManageExpert.Patents(where...); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
list := make([]*ExpertPatent, 0)
|
|
|
|
|
|
|
|
|
|
for _, v := range patents {
|
|
|
|
|
list = append(list, &ExpertPatent{
|
|
|
|
|
ID: v.GetEncodeID(),
|
|
|
|
|
ManageExpertPatent: v,
|
|
|
|
|
IsBind: v.UserPatentCount > 0,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
return list, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// PatentBind 专利认领绑定
|
2022-02-09 18:38:32 +08:00
|
|
|
|
func (c *Expert) PatentBind(id uint64, patentIDs []uint64) error {
|
|
|
|
|
mManageExpert := model.NewManageExpert()
|
|
|
|
|
mManageExpert.ID = id
|
2022-02-09 17:35:31 +08:00
|
|
|
|
|
2022-02-09 18:38:32 +08:00
|
|
|
|
isExist, err := model2.FirstField(mManageExpert.ManageExpert, []string{"id", "tenant_id"})
|
2022-02-09 17:35:31 +08:00
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
2022-02-09 18:38:32 +08:00
|
|
|
|
} else if !isExist {
|
|
|
|
|
return errors.New("操作错误,专家信息不存在或已被删除")
|
|
|
|
|
} else if c.TenantID > 0 && c.TenantID != mManageExpert.TenantID {
|
|
|
|
|
return errors.New("操作错误,无权限操作")
|
2022-02-09 17:35:31 +08:00
|
|
|
|
}
|
2022-02-09 18:38:32 +08:00
|
|
|
|
data := make([]*model2.TechnologyPatentExpert, 0)
|
|
|
|
|
|
|
|
|
|
for _, v := range patentIDs {
|
|
|
|
|
data = append(data, &model2.TechnologyPatentExpert{
|
|
|
|
|
ExpertID: mManageExpert.ID, PatentID: v,
|
|
|
|
|
})
|
2022-02-09 17:35:31 +08:00
|
|
|
|
}
|
|
|
|
|
if len(data) > 0 {
|
2022-02-09 18:38:32 +08:00
|
|
|
|
return model2.Creates(model.NewTechnologyPatentExpert().TechnologyPatentExpert, data)
|
2022-02-09 17:35:31 +08:00
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// PatentUnbind 专利认领解绑
|
|
|
|
|
func (c *Expert) PatentUnbind(id uint64, patentID []uint64) error {
|
2022-02-09 18:38:32 +08:00
|
|
|
|
mManageExpert := model.NewManageExpert()
|
|
|
|
|
mManageExpert.ID = id
|
2022-02-09 17:35:31 +08:00
|
|
|
|
|
2022-02-09 18:38:32 +08:00
|
|
|
|
isExist, err := model2.FirstField(mManageExpert.ManageExpert, []string{"id", "tenant_id"})
|
2022-02-09 17:35:31 +08:00
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
2022-02-09 18:38:32 +08:00
|
|
|
|
} else if !isExist {
|
|
|
|
|
return errors.New("操作错误,专家信息不存在或已被删除")
|
|
|
|
|
} else if c.TenantID > 0 && c.TenantID != mManageExpert.TenantID {
|
|
|
|
|
return errors.New("操作错误,无权限操作")
|
2022-02-09 17:35:31 +08:00
|
|
|
|
}
|
2022-02-09 18:38:32 +08:00
|
|
|
|
return model2.DeleteWhere(model.NewTechnologyPatentExpert().TechnologyPatentExpert, []*model2.ModelWhere{
|
|
|
|
|
model2.NewWhere("expert_id", mManageExpert.ID),
|
2022-02-09 17:35:31 +08:00
|
|
|
|
model2.NewWhereIn("patent_id", patentID),
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-03 23:21:04 +08:00
|
|
|
|
// Import 导入数据
|
|
|
|
|
func (c *Expert) Import(file string) error {
|
|
|
|
|
excel := lib.NewExcel()
|
|
|
|
|
err := excel.Import(strings.Replace(file, "/", "", 1), 1, 0)
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
data := excel.Analysis(&ExpertExcel{})
|
|
|
|
|
|
2022-05-11 22:30:18 +08:00
|
|
|
|
rows := make([]*ExpertExcelInfo, 0, len(data))
|
2022-05-11 22:15:30 +08:00
|
|
|
|
|
|
|
|
|
now := time.Now()
|
2022-05-03 23:21:04 +08:00
|
|
|
|
|
|
|
|
|
for _, v := range data {
|
|
|
|
|
_data := v.(*ExpertExcel)
|
2022-05-11 22:15:30 +08:00
|
|
|
|
|
|
|
|
|
row := new(model2.ManageExpert)
|
|
|
|
|
|
|
|
|
|
var count int64
|
|
|
|
|
// 查询手机号码是否存在
|
|
|
|
|
if err = model2.Count(row, &count, model2.NewWhere("mobile", _data.Mobile)); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if count > 0 {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
// 查询所属科研机构
|
|
|
|
|
mManageResearch := model.NewManageResearch()
|
|
|
|
|
mManageLaboratory := model.NewManageLaboratory()
|
|
|
|
|
|
|
|
|
|
isExist := false
|
|
|
|
|
|
|
|
|
|
if _data.Research != "" {
|
|
|
|
|
if isExist, err = model2.FirstField(mManageResearch.ManageResearch, []string{"id"},
|
|
|
|
|
model2.NewWhere("name", _data.Research)); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
} else if !isExist {
|
|
|
|
|
return errors.New("所属单位不存在")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if _data.Laboratory != "" {
|
|
|
|
|
if isExist, err = model2.FirstField(mManageLaboratory.ManageLaboratory, []string{"id"},
|
|
|
|
|
model2.NewWhere("name", _data.Laboratory)); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
} else if !isExist {
|
|
|
|
|
return errors.New("所属实验室不存在")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 查询所属实验室
|
|
|
|
|
|
|
|
|
|
industrys := make([]string, 0)
|
|
|
|
|
|
|
|
|
|
if industrys, err = _data.industry(); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
row.ModelTenant = model2.ModelTenant{TenantID: _data.tenant()}
|
|
|
|
|
row.ResearchID = mManageResearch.ID
|
|
|
|
|
row.LaboratoryID = mManageLaboratory.ID
|
|
|
|
|
row.Name = _data.Name
|
|
|
|
|
row.Mobile = _data.Mobile
|
|
|
|
|
row.Area = _data.area()
|
|
|
|
|
row.Education = _data.Education
|
|
|
|
|
row.School = _data.School
|
|
|
|
|
row.Major = _data.Major
|
|
|
|
|
row.Job = _data.Job
|
|
|
|
|
row.Title = _data.Title
|
|
|
|
|
row.Gender = model2.Gender{Gender: _data.gender()}
|
|
|
|
|
row.WorkAt = utils.DataTimeToDate(_data.WorkAt)
|
|
|
|
|
row.SetIndustryAttribute(industrys)
|
|
|
|
|
row.SetKeywordAttribute(_data.keyword())
|
|
|
|
|
row.Research = _data.ResearchWhere
|
|
|
|
|
row.Introduce = _data.Introduce
|
|
|
|
|
row.Examine = model2.Examine{
|
|
|
|
|
ExamineStatus: model2.ExamineStatusForAgree,
|
|
|
|
|
ExamineRemark: "主动上传,无需审核",
|
|
|
|
|
ExamineAt: now,
|
|
|
|
|
}
|
|
|
|
|
row.CreatedAt = now
|
|
|
|
|
row.UpdatedAt = now
|
2022-05-11 22:30:18 +08:00
|
|
|
|
rows = append(rows, &ExpertExcelInfo{
|
|
|
|
|
ManageExpert: row,
|
|
|
|
|
Tag2: _data.Tag2,
|
|
|
|
|
Tag3: _data.Tag3,
|
|
|
|
|
})
|
2022-05-11 22:15:30 +08:00
|
|
|
|
}
|
|
|
|
|
if len(rows) > 0 {
|
2022-05-11 22:30:18 +08:00
|
|
|
|
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
|
|
|
|
//mManageExpert := model2.NewManageExpert()
|
|
|
|
|
manage := service.NewESManage()
|
2022-05-11 22:15:30 +08:00
|
|
|
|
|
2022-05-11 22:30:18 +08:00
|
|
|
|
for _, v := range rows {
|
|
|
|
|
if err = model2.Create(v.ManageExpert, tx); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
enterprises := make([]*model2.ManageCooperateEnterprise, 0)
|
|
|
|
|
// 已合作的企业
|
|
|
|
|
if v.Tag2 != "" {
|
|
|
|
|
for _, val := range strings.Split(v.Tag2, "\n") {
|
|
|
|
|
enterprises = append(enterprises, &model2.ManageCooperateEnterprise{
|
|
|
|
|
ModelTenant: model2.ModelTenant{TenantID: v.TenantID},
|
|
|
|
|
Mode: model2.ManageCooperateEnterpriseModeForCooperateAlready,
|
|
|
|
|
Name: val,
|
|
|
|
|
ModelAt: model2.ModelAt{
|
|
|
|
|
CreatedAt: now, UpdatedAt: now,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 想合作的企业
|
|
|
|
|
if v.Tag3 != "" {
|
|
|
|
|
for _, val := range strings.Split(v.Tag2, "\n") {
|
|
|
|
|
enterprises = append(enterprises, &model2.ManageCooperateEnterprise{
|
|
|
|
|
ModelTenant: model2.ModelTenant{TenantID: v.TenantID},
|
|
|
|
|
Mode: model2.ManageCooperateEnterpriseModeForCooperateToWant,
|
|
|
|
|
Name: val,
|
|
|
|
|
ModelAt: model2.ModelAt{
|
|
|
|
|
CreatedAt: now, UpdatedAt: now,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if len(enterprises) > 0 {
|
|
|
|
|
mManageCooperateEnterprise := model.NewManageCooperateEnterprise()
|
2022-05-11 22:15:30 +08:00
|
|
|
|
|
2022-05-11 22:30:18 +08:00
|
|
|
|
if err = model2.Creates(mManageCooperateEnterprise.ManageCooperateEnterprise, &enterprises, tx); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_industrys := make([]string, 0)
|
2022-05-11 22:15:30 +08:00
|
|
|
|
|
2022-05-11 22:30:18 +08:00
|
|
|
|
for _, val := range v.GetIndustryAttribute() {
|
|
|
|
|
_industrys = append(_industrys, config.GetIndustryInfo(val, "-", "-").Value)
|
|
|
|
|
}
|
|
|
|
|
service.WithManageID(v.ID)(manage)
|
|
|
|
|
service.WithManageTitle(v.Name)(manage)
|
|
|
|
|
service.WithManageIdentity(config.TenantUserIdentityForExpert)(manage)
|
|
|
|
|
service.WithManageIndustry(strings.Join(_industrys, ";"))(manage)
|
|
|
|
|
service.WithManageKeyword(strings.Join(v.GetKeywordAttribute(), ";"))(manage)
|
2022-05-11 22:15:30 +08:00
|
|
|
|
}
|
2022-05-11 22:30:18 +08:00
|
|
|
|
if err = manage.Create(); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
})
|
2022-05-03 23:21:04 +08:00
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-11 22:15:30 +08:00
|
|
|
|
func (c *ExpertExcel) tenant() uint64 {
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *ExpertExcel) gender() model2.GenderKind {
|
|
|
|
|
if c.Gender == "男" {
|
|
|
|
|
return model2.GenderKindForMale
|
|
|
|
|
}
|
|
|
|
|
return model2.GenderKindForFemale
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *ExpertExcel) area() model2.Area {
|
|
|
|
|
area := model2.Area{
|
|
|
|
|
Address: c.Address,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
filter := func(key, value string) string {
|
|
|
|
|
areaInfo, has := config.MemoryForAreaInfo[key]
|
|
|
|
|
|
|
|
|
|
if !has {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
if value == "" {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
for k, v := range areaInfo {
|
|
|
|
|
if v == value {
|
|
|
|
|
return k
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
// 省
|
|
|
|
|
area.Province = filter(config2.DefaultChinaAreaCode, c.Province)
|
|
|
|
|
|
|
|
|
|
if area.Province != "" {
|
|
|
|
|
area.City = filter(area.Province, c.City)
|
|
|
|
|
|
|
|
|
|
if area.City != "" {
|
|
|
|
|
area.District = filter(area.District, c.City)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return area
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *ExpertExcel) industry() ([]string, error) {
|
|
|
|
|
// 存在多个
|
|
|
|
|
industrys := strings.Split(c.Industry, "\n")
|
|
|
|
|
|
|
|
|
|
out := make([]string, 0)
|
|
|
|
|
|
|
|
|
|
for _, v := range industrys {
|
|
|
|
|
_industrys := strings.Split(v, "/")
|
|
|
|
|
|
|
|
|
|
_out := make([]string, 0, len(_industrys))
|
|
|
|
|
|
|
|
|
|
for key, industry := range _industrys {
|
|
|
|
|
mSysIndustry := model.NewSysIndustry()
|
|
|
|
|
|
|
|
|
|
isExist, err := model2.FirstField(mSysIndustry.SysIndustry, []string{"id"}, model2.NewWhere("name", industry))
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
if !isExist {
|
|
|
|
|
if key > 0 {
|
|
|
|
|
mSysIndustry.ParentID = utils.StringToUnit64(_out[key-1])
|
|
|
|
|
}
|
|
|
|
|
mSysIndustry.Name = industry
|
|
|
|
|
|
|
|
|
|
if err = model2.Create(mSysIndustry.SysIndustry); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
_out = append(_out, fmt.Sprintf("%d", mSysIndustry.ID))
|
|
|
|
|
}
|
|
|
|
|
out = append(out, strings.Join(_out, "-"))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return out, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *ExpertExcel) keyword() []string {
|
|
|
|
|
return strings.Split(c.Keyword, "\n")
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-19 13:23:07 +08:00
|
|
|
|
func NewExpert() ExpertHandle {
|
|
|
|
|
return func(session *session.Admin) *Expert {
|
|
|
|
|
return &Expert{session}
|
|
|
|
|
}
|
|
|
|
|
}
|