feat:优化专家导入接口
This commit is contained in:
@ -72,6 +72,7 @@ type (
|
|||||||
Education string `json:"education" xlsx:"最高学历"`
|
Education string `json:"education" xlsx:"最高学历"`
|
||||||
Major string `json:"major" xlsx:"主修专业"`
|
Major string `json:"major" xlsx:"主修专业"`
|
||||||
Job string `json:"job" xlsx:"职务"`
|
Job string `json:"job" xlsx:"职务"`
|
||||||
|
Title string `json:"title" xlsx:"职称"`
|
||||||
WorkAt string `json:"work_at" xlsx:"从业时间"`
|
WorkAt string `json:"work_at" xlsx:"从业时间"`
|
||||||
Gender string `json:"gender" xlsx:"性别"`
|
Gender string `json:"gender" xlsx:"性别"`
|
||||||
ResearchWhere string `json:"research_where" xlsx:"研究方向"`
|
ResearchWhere string `json:"research_where" xlsx:"研究方向"`
|
||||||
@ -80,12 +81,8 @@ type (
|
|||||||
Technology string `json:"technology" xlsx:"核心技术及产品"`
|
Technology string `json:"technology" xlsx:"核心技术及产品"`
|
||||||
Scene string `json:"scene" xlsx:"应用场景"`
|
Scene string `json:"scene" xlsx:"应用场景"`
|
||||||
Tag1 string `json:"tag_1" xlsx:"代表成果及合作模式"`
|
Tag1 string `json:"tag_1" xlsx:"代表成果及合作模式"`
|
||||||
Tag2 string `json:"tag_2" xlsx:"承担科研项目"`
|
Tag2 string `json:"tag_2" xlsx:"已合作企业"`
|
||||||
Tag3 string `json:"tag_3" xlsx:"代表专利"`
|
Tag3 string `json:"tag_3" xlsx:"想合作企业"`
|
||||||
Tag4 string `json:"tag_4" xlsx:"代表论文"`
|
|
||||||
Tag5 string `json:"tag_5" xlsx:"已合作企业"`
|
|
||||||
Tag6 string `json:"tag_6" xlsx:"想合作企业"`
|
|
||||||
Tag7 string `json:"tag_7" xlsx:"我的需求"`
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -351,17 +348,191 @@ func (c *Expert) Import(file string) error {
|
|||||||
}
|
}
|
||||||
data := excel.Analysis(&ExpertExcel{})
|
data := excel.Analysis(&ExpertExcel{})
|
||||||
|
|
||||||
//now := time.Now()
|
rows := make([]*model2.ManageExpert, 0, len(data))
|
||||||
|
|
||||||
|
now := time.Now()
|
||||||
|
|
||||||
for _, v := range data {
|
for _, v := range data {
|
||||||
_data := v.(*ExpertExcel)
|
_data := v.(*ExpertExcel)
|
||||||
// 所属领域
|
|
||||||
//industrys := strings.Split(_data.Industry, "\n")
|
row := new(model2.ManageExpert)
|
||||||
fmt.Println(_data)
|
|
||||||
|
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
|
||||||
|
rows = append(rows, row)
|
||||||
|
}
|
||||||
|
if len(rows) > 0 {
|
||||||
|
mManageExpert := model2.NewManageExpert()
|
||||||
|
|
||||||
|
if err = model2.Creates(mManageExpert, rows); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
manage := service.NewESManage()
|
||||||
|
|
||||||
|
for _, row := range rows {
|
||||||
|
_industrys := make([]string, 0)
|
||||||
|
|
||||||
|
for _, v := range row.GetIndustryAttribute() {
|
||||||
|
_industrys = append(_industrys, config.GetIndustryInfo(v, "-", "-").Value)
|
||||||
|
}
|
||||||
|
service.WithManageID(row.ID)(manage)
|
||||||
|
service.WithManageTitle(row.Name)(manage)
|
||||||
|
service.WithManageIdentity(config.TenantUserIdentityForExpert)(manage)
|
||||||
|
service.WithManageIndustry(strings.Join(_industrys, ";"))(manage)
|
||||||
|
service.WithManageKeyword(strings.Join(row.GetKeywordAttribute(), ";"))(manage)
|
||||||
|
}
|
||||||
|
if err = manage.Create(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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")
|
||||||
|
}
|
||||||
|
|
||||||
func NewExpert() ExpertHandle {
|
func NewExpert() ExpertHandle {
|
||||||
return func(session *session.Admin) *Expert {
|
return func(session *session.Admin) *Expert {
|
||||||
return &Expert{session}
|
return &Expert{session}
|
||||||
|
Reference in New Issue
Block a user