Browse Source

no message

xingzai 9 months ago
parent
commit
128fa55dba

+ 9 - 2
models/admin.go

@@ -2,6 +2,7 @@ package models
 
 import (
 	"github.com/beego/beego/v2/client/orm"
+	"hongze/hongze_task/models/system"
 	"hongze/hongze_task/utils"
 )
 
@@ -33,12 +34,18 @@ func GetAdminByAdminIds(adminIds []int) (items []*Admin, err error) {
 	return
 }
 
-func GetAdminByAdminMobiles(mobiles []string) (items []*Admin, err error) {
-	sql := `SELECT * FROM admin WHERE admin_id in (` + utils.GetOrmInReplace(len(mobiles)) + `) `
+func GetAdminByAdminMobiles(mobiles []string) (items []*system.AdminItem, err error) {
+	sql := `SELECT * FROM admin WHERE mobile in (` + utils.GetOrmInReplace(len(mobiles)) + `) `
 	_, err = orm.NewOrm().Raw(sql, mobiles).QueryRows(&items)
 	return
 }
 
+func GetAdminByAdminAllList() (items []*system.AdminItem, err error) {
+	sql := `SELECT * FROM admin WHERE mobile != '' `
+	_, err = orm.NewOrm().Raw(sql).QueryRows(&items)
+	return
+}
+
 type AdminView struct {
 	AdminId      int
 	AdminName    string `description:"系统用户名称"`

+ 15 - 1
models/db.go

@@ -88,7 +88,6 @@ func init() {
 		new(ReportSendThsDetail),
 		new(Report),
 		new(UserViewStatistics),
-		new(roadshow.RsReportRecord), //路演记录
 		new(CompanyReportRecord),
 		new(ChartPermission), // 权限表
 		new(ComeinWhiteUser), // 进门财经白名单
@@ -120,6 +119,9 @@ func init() {
 
 	// ETA商家配置表
 	initEtaBusinessConf()
+
+	// 路演记录 数据表
+	initRoadShow()
 }
 
 // initCompany 注册客户信息 数据表
@@ -254,3 +256,15 @@ func initEnglishReport() {
 		new(EnglishReport),
 	)
 }
+
+// 路演记录 数据表
+func initRoadShow() {
+	//注册对象
+	orm.RegisterModel(
+		new(roadshow.RsCalendar),           //路演主表
+		new(roadshow.RsCalendarResearcher), //路演研究员信息表
+		new(roadshow.RsMatters),            //公开会议表
+		new(roadshow.RsCalendarRelation),   //路演关系表(与上海的路演日历关系)
+		new(roadshow.RsReportRecord),       //路演统计表
+	)
+}

+ 54 - 3
models/roadshow/calendar.go

@@ -24,6 +24,7 @@ type RsCalendarResearcher struct {
 	RefuseTime             time.Time `description:"拒绝时间"`
 	DeleteReason           string    `description:"删除理由"`
 	UnionCode              string    `description:"公开会议联合编码"`
+	IsSynced               int       `description:"是否与上海同步 0:未同步 1:已同步"`
 }
 
 func GetRsCalendarResearcher(endDate, endTime string) (list []*RsCalendarResearcher, err error) {
@@ -102,6 +103,17 @@ func GetRsCalendarById(rsCalendarId int) (item *RsCalendar, err error) {
 	return
 }
 
+func GetRsCalendarByIds(rsCalendarIds []int) (items []*RsCalendar, err error) {
+	lenArr := len(rsCalendarIds)
+	if lenArr == 0 {
+		return
+	}
+	o := orm.NewOrm()
+	sql := `SELECT * FROM rs_calendar WHERE rs_calendar_id  IN  (` + utils.GetOrmInReplace(lenArr) + `) `
+	_, err = o.Raw(sql, rsCalendarIds).QueryRows(&items)
+	return
+}
+
 func GetRsCalendarResearcherById(rsCalendarId int) (item *RsCalendarResearcher, err error) {
 	sql := `SELECT * FROM rs_calendar_researcher WHERE rs_calendar_researcher_id=? `
 	o := orm.NewOrm()
@@ -109,11 +121,14 @@ func GetRsCalendarResearcherById(rsCalendarId int) (item *RsCalendarResearcher,
 	return
 }
 
-func GetRsCalendarResearcherByIds(rsCalendarIds []int) (items []*RsCalendarResearcher, err error) {
-	lenArr := len(rsCalendarIds)
+func GetRsCalendarResearcherByIds(rsCalendarResearcherId []int) (items []*RsCalendarResearcher, err error) {
+	lenArr := len(rsCalendarResearcherId)
+	if lenArr == 0 {
+		return
+	}
 	sql := `SELECT * FROM rs_calendar_researcher WHERE rs_calendar_researcher_id  IN  (` + utils.GetOrmInReplace(lenArr) + `) `
 	o := orm.NewOrm()
-	_, err = o.Raw(sql).QueryRows(&items)
+	_, err = o.Raw(sql, rsCalendarResearcherId).QueryRows(&items)
 	return
 }
 
@@ -135,3 +150,39 @@ func GetResearcher() (list []*ResearcherGroup, err error) {
 	_, err = o.Raw(sql).QueryRows(&list)
 	return
 }
+
+// GetRsCalendarResearcherListByRsCalendarIds 根据路演id获取路演研究员列表
+func GetRsCalendarResearcherListByRsCalendarIds(rsCalendarIds []int) (items []*RsCalendarResearcher, err error) {
+	lenArr := len(rsCalendarIds)
+	if lenArr == 0 {
+		return
+	}
+	o := orm.NewOrm()
+	sql := `SELECT * FROM rs_calendar_researcher WHERE rs_calendar_id  IN  (` + utils.GetOrmInReplace(lenArr) + `) `
+	_, err = o.Raw(sql, rsCalendarIds).QueryRows(&items)
+	return
+}
+
+// 更新
+func UpdateCalendarResearcher(where, updateParams map[string]interface{}) error {
+	o := orm.NewOrm()
+	ptrStructOrTableName := "rs_calendar_researcher"
+	qs := o.QueryTable(ptrStructOrTableName)
+	for expr, exprV := range where {
+		qs = qs.Filter(expr, exprV)
+	}
+	_, err := qs.Update(updateParams)
+	return err
+}
+
+// 软删除
+func ModifyRsCalendarResearcherStatusDel(rsCalendarResearcherIds []int) (err error) {
+	lenArr := len(rsCalendarResearcherIds)
+	if lenArr == 0 {
+		return
+	}
+	sql := ` UPDATE rs_calendar_researcher SET status=4,modify_time=NOW() WHERE rs_calendar_researcher_id IN (` + utils.GetOrmInReplace(lenArr) + `) `
+	o := orm.NewOrm()
+	_, err = o.Raw(sql, rsCalendarResearcherIds).Exec()
+	return
+}

+ 240 - 0
models/roadshow/rs_calendar_relation.go

@@ -2,7 +2,9 @@ package roadshow
 
 import (
 	"github.com/beego/beego/v2/client/orm"
+	"hongze/hongze_task/models/system"
 	"hongze/hongze_task/utils"
+	"strconv"
 	"time"
 )
 
@@ -82,3 +84,241 @@ WHERE a.status=2 and c.calendar_type=1  and start_date>=? and end_date <= ? `
 	_, err = o.Raw(sql, startDate, endDate).QueryRows(&items)
 	return
 }
+
+// UpdateSyncRsCalendarRelation 同步自系统路演与第三方路演关系
+func UpdateSyncRsCalendarRelation(thirdUserCalendar UserCalendar, rsCalendar *RsCalendar, rsCalendarRelation *RsCalendarRelation, updateRsCalendarResearcherList []*RsCalendarResearcher, delResearcherIdList []int, addResearcherList []*system.AdminItem) (err error) {
+	currentStartTimer := time.Unix(int64(thirdUserCalendar.StartTime), 0)
+	currentEndTimer := time.Unix(int64(thirdUserCalendar.EndTime), 0)
+
+	//新增研究员
+	//删除研究员
+	//更新研究员
+	o := orm.NewOrm()
+	to, err := o.Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err != nil {
+			_ = to.Rollback()
+		} else {
+			_ = to.Commit()
+		}
+	}()
+
+	// 路演活动表修改
+	rsCalendar.Title = thirdUserCalendar.Title
+	rsCalendar.ModifyTime = time.Now()
+	_, err = to.Update(rsCalendar, "Title", "ModifyTime")
+	if err != nil {
+		return
+	}
+
+	// 删除路演研究员
+	if len(delResearcherIdList) > 0 {
+		delResearcherIdStr := utils.Implode(delResearcherIdList)
+		sql := `DELETE FROM rs_calendar_researcher WHERE rs_calendar_researcher_id in (` + delResearcherIdStr + `) `
+		_, tmpErr := to.Raw(sql).Exec()
+		if tmpErr != nil {
+			err = tmpErr
+			return
+		}
+	}
+
+	// 修改路演研究员
+	for _, rsCalendarResearcher := range updateRsCalendarResearcherList {
+		rsCalendarResearcher.StartDate = currentStartTimer.Format(utils.FormatDate)
+		rsCalendarResearcher.EndDate = currentEndTimer.Format(utils.FormatDate)
+		rsCalendarResearcher.StartTime = currentStartTimer.Format(utils.FormatTime)
+		rsCalendarResearcher.EndTime = currentEndTimer.Format(utils.FormatTime)
+		rsCalendarResearcher.StartWeek = utils.EnWeekToCnWeek(currentStartTimer.Weekday().String())
+		rsCalendarResearcher.EndWeek = utils.EnWeekToCnWeek(currentEndTimer.Weekday().String())
+		rsCalendarResearcher.Status = 2 // 已接受
+		rsCalendarResearcher.ModifyTime = time.Now()
+		rsCalendarResearcher.IsSynced = 1
+		_, tmpErr := to.Update(rsCalendarResearcher, "StartDate", "EndDate", "StartTime", "EndTime", "StartWeek", "EndWeek", "Status", "ModifyTime", "IsSynced")
+		if tmpErr != nil {
+			err = tmpErr
+			return
+		}
+	}
+
+	// 路演研究员入库
+	rsCalendarResearcherList := make([]*RsCalendarResearcher, 0)
+	for _, researcheInfo := range addResearcherList {
+		rsCalendarResearcher := &RsCalendarResearcher{
+			RsCalendarResearcherId: 0,
+			RsCalendarId:           rsCalendar.RsCalendarId,
+			ResearcherId:           researcheInfo.AdminId,
+			ResearcherName:         researcheInfo.RealName,
+			StartDate:              currentStartTimer.Format(utils.FormatDate),
+			EndDate:                currentEndTimer.Format(utils.FormatDate),
+			StartTime:              currentStartTimer.Format(utils.FormatTime),
+			EndTime:                currentEndTimer.Format(utils.FormatTime),
+			StartWeek:              utils.EnWeekToCnWeek(currentStartTimer.Weekday().String()),
+			EndWeek:                utils.EnWeekToCnWeek(currentEndTimer.Weekday().String()),
+			CreateTime:             time.Now(),
+			ModifyTime:             time.Now(),
+			Status:                 2, //1:待接受,2:已接受,3:已拒绝,4:已删除,5:已撤回,6:已结束
+			RefuseReason:           "",
+			//RefuseTime:             time.Time{},
+			DeleteReason: "",
+			IsSynced:     1,
+		}
+		rsCalendarResearcherId, tmpErr := to.Insert(rsCalendarResearcher)
+		if tmpErr != nil {
+			err = tmpErr
+			return
+		}
+		rsCalendarResearcher.RsCalendarResearcherId = int(rsCalendarResearcherId)
+		rsCalendarResearcherList = append(rsCalendarResearcherList, rsCalendarResearcher)
+	}
+
+	// 关系表变更
+	selfCalendarId := rsCalendarRelation.SelfCalendarId
+	if len(updateRsCalendarResearcherList) > 0 {
+		selfCalendarId = updateRsCalendarResearcherList[0].RsCalendarResearcherId //更新的研究员关系表id
+	} else if len(rsCalendarResearcherList) > 0 {
+		selfCalendarId = rsCalendarResearcherList[0].RsCalendarResearcherId //新增的研究员关系表id
+	}
+
+	//关系入库
+	customerId, _ := strconv.Atoi(thirdUserCalendar.CustomerId)
+	rsCalendarRelation.SelfCalendarId = selfCalendarId
+	rsCalendarRelation.UserId = thirdUserCalendar.UserId
+	rsCalendarRelation.UserPhone = thirdUserCalendar.UserPhone
+	rsCalendarRelation.UserName = thirdUserCalendar.UserName
+	rsCalendarRelation.ProjectName = thirdUserCalendar.ProjectName
+	rsCalendarRelation.ProjectId = thirdUserCalendar.ProjectId
+	rsCalendarRelation.CustomerId = customerId
+	rsCalendarRelation.CustomerName = thirdUserCalendar.CustomerName
+	rsCalendarRelation.CustomerSocial = thirdUserCalendar.CustomerSocial
+	rsCalendarRelation.ProjectType = thirdUserCalendar.ProjectType
+	rsCalendarRelation.ProjectFormType = thirdUserCalendar.ProjectType
+	rsCalendarRelation.Room = thirdUserCalendar.Room
+	rsCalendarRelation.StartTime = thirdUserCalendar.StartTime
+	rsCalendarRelation.EndTime = thirdUserCalendar.EndTime
+	rsCalendarRelation.Content = thirdUserCalendar.Content
+	rsCalendarRelation.FeedExpert = thirdUserCalendar.FeedExpert
+	rsCalendarRelation.Title = thirdUserCalendar.Title
+	rsCalendarRelation.ResearcherMobile = thirdUserCalendar.ResearcherMobile
+	rsCalendarRelation.ModifyTime = time.Now()
+	_, err = to.Update(rsCalendarRelation, "SelfCalendarId", "UserId", "UserPhone", "UserName", "ProjectName", "ProjectId", "CustomerId", "CustomerName", "CustomerSocial", "ProjectType", "ProjectFormType", "Room", "StartTime", "EndTime", "Content", "FeedExpert", "Title", "ResearcherMobile", "ModifyTime")
+	return
+}
+
+func SyncRsCalendarRelation(thirdUserCalendar UserCalendar, createUser *system.AdminItem, researcherList []*system.AdminItem) (err error) {
+	currentStartTimer := time.Unix(int64(thirdUserCalendar.StartTime), 0)
+	currentEndTimer := time.Unix(int64(thirdUserCalendar.EndTime), 0)
+
+	o := orm.NewOrm()
+	to, err := o.Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err != nil {
+			_ = to.Rollback()
+		} else {
+			_ = to.Commit()
+		}
+	}()
+
+	//路演活动表入库
+	rsCalendar := &RsCalendar{
+		SysUserId:        createUser.AdminId,
+		SysUserRealName:  createUser.RealName,
+		ActivityType:     "路演",
+		RoadshowType:     "",
+		RoadshowPlatform: "",
+		CompanyId:        0,
+		CompanyName:      thirdUserCalendar.CustomerName,
+		Province:         "",
+		ProvinceCode:     "",
+		City:             "",
+		CityCode:         "",
+		Theme:            "",
+		CooperationName:  "",
+		Title:            thirdUserCalendar.Title,
+		Source:           1, //来源,0:自系统,1:上海方的
+		CreateTime:       time.Now(),
+		ModifyTime:       time.Now(),
+		ActivityCategory: "",
+		IsSynced:         1,
+	}
+	rsCalendarId, err := to.Insert(rsCalendar)
+	if err != nil {
+		return
+	}
+	rsCalendar.RsCalendarId = int(rsCalendarId)
+
+	// 路演研究员入库
+	rsCalendarResearcherList := make([]*RsCalendarResearcher, 0)
+	for _, researcheInfo := range researcherList {
+		rsCalendarResearcher := &RsCalendarResearcher{
+			RsCalendarResearcherId: 0,
+			RsCalendarId:           rsCalendar.RsCalendarId,
+			ResearcherId:           researcheInfo.AdminId,
+			ResearcherName:         researcheInfo.RealName,
+			StartDate:              currentStartTimer.Format(utils.FormatDate),
+			EndDate:                currentEndTimer.Format(utils.FormatDate),
+			StartTime:              currentStartTimer.Format(utils.FormatTime),
+			EndTime:                currentEndTimer.Format(utils.FormatTime),
+			StartWeek:              utils.EnWeekToCnWeek(currentStartTimer.Weekday().String()),
+			EndWeek:                utils.EnWeekToCnWeek(currentEndTimer.Weekday().String()),
+			CreateTime:             time.Now(),
+			ModifyTime:             time.Now(),
+			Status:                 2, //1:待接受,2:已接受,3:已拒绝,4:已删除,5:已撤回,6:已结束
+			RefuseReason:           "",
+			//RefuseTime:             time.Time{},
+			DeleteReason: "",
+			IsSynced:     1,
+		}
+		rsCalendarResearcherId, tmpErr := to.Insert(rsCalendarResearcher)
+		if tmpErr != nil {
+			err = tmpErr
+			return
+		}
+		rsCalendarResearcher.RsCalendarResearcherId = int(rsCalendarResearcherId)
+		rsCalendarResearcherList = append(rsCalendarResearcherList, rsCalendarResearcher)
+	}
+
+	selfCalendarId := 0
+	if len(rsCalendarResearcherList) > 0 {
+		selfCalendarId = rsCalendarResearcherList[0].RsCalendarResearcherId
+	}
+	//关系入库
+	customerId, _ := strconv.Atoi(thirdUserCalendar.CustomerId)
+	rsCalendarRelation := &RsCalendarRelation{
+		//RelationId:       0,
+		CalendarType:     1,              //日历类型;1:路演;2:事项
+		SelfCalendarId:   selfCalendarId, //研究员与路演关系id;
+		ThirdCalendarId:  thirdUserCalendar.ID,
+		UserId:           thirdUserCalendar.UserId,
+		UserPhone:        thirdUserCalendar.UserPhone,
+		UserName:         thirdUserCalendar.UserName,
+		ProjectName:      thirdUserCalendar.ProjectName,
+		ProjectId:        thirdUserCalendar.ProjectId,
+		CustomerId:       customerId,
+		CustomerName:     thirdUserCalendar.CustomerName,
+		CustomerSocial:   thirdUserCalendar.CustomerSocial,
+		ProjectType:      thirdUserCalendar.ProjectType,
+		ProjectFormType:  thirdUserCalendar.ProjectType,
+		Room:             thirdUserCalendar.Room,
+		StartTime:        thirdUserCalendar.StartTime,
+		EndTime:          thirdUserCalendar.EndTime,
+		Content:          thirdUserCalendar.Content,
+		FeedExpert:       thirdUserCalendar.FeedExpert,
+		Title:            thirdUserCalendar.Title,
+		ResearcherMobile: thirdUserCalendar.ResearcherMobile,
+		ModifyTime:       time.Now(),
+		CreateTime:       time.Now(),
+	}
+	rsCalendarRelationId, err := to.Insert(rsCalendarRelation)
+	if err != nil {
+		return
+	}
+	rsCalendarRelation.RelationId = int(rsCalendarRelationId)
+
+	return
+}

+ 38 - 0
models/system/sys_admin.go

@@ -0,0 +1,38 @@
+package system
+
+import "time"
+
+type AdminItem struct {
+	AdminId                 int    `description:"系统用户id"`
+	AdminName               string `description:"系统用户名称"`
+	RealName                string `description:"系统用户姓名"`
+	Password                string
+	LastUpdatedPasswordTime string `json:"-"`
+	Enabled                 int    `description:"1:有效,0:禁用"`
+	Email                   string `description:"系统用户邮箱"`
+	LastLoginTime           string
+	CreatedTime             time.Time
+	LastUpdatedTime         string
+	Role                    string `description:"系统用户角色"`
+	Mobile                  string `description:"手机号"`
+	RoleType                int    `description:"角色类型:1需要录入指标,0:不需要"`
+	RoleId                  int    `description:"角色id"`
+	RoleName                string `description:"角色名称"`
+	RoleTypeCode            string `description:"角色编码"`
+	DepartmentId            int    `description:"部门id"`
+	DepartmentName          string `json:"-" description:"部门名称"`
+	TeamId                  int    `description:"三级id"`
+	GroupId                 int    `description:"分组id"`
+	GroupName               string `json:"-" description:"分组名称"`
+	Authority               int    `description:"管理权限,0:无,1:部门负责人,2:小组负责人,或者ficc销售主管,4:ficc销售组长"`
+	Position                string `description:"职位"`
+	DepartmentGroup         string `description:"部门分组"`
+	LabelVal                int    `description:"标签:1:超级管理员,2:管理员,3:部门经理,4:组长,5:ficc销售主管"`
+	ResearchGroupName       string `description:"研究方向分组名称"`
+	Province                string `description:"省"`
+	ProvinceCode            string `description:"省编码"`
+	City                    string `description:"市"`
+	CityCode                string `description:"市编码"`
+	EmployeeId              string `description:"员工工号(钉钉/每刻报销)"`
+	TelAreaCode             string `description:"手机区号"`
+}

+ 89 - 93
services/roadshow/calendar.go

@@ -9,6 +9,7 @@ import (
 	"hongze/hongze_task/models"
 	"hongze/hongze_task/models/cygx"
 	"hongze/hongze_task/models/roadshow"
+	"hongze/hongze_task/models/system"
 	"hongze/hongze_task/services/alarm_msg"
 	"hongze/hongze_task/utils"
 	"io/ioutil"
@@ -260,6 +261,10 @@ func getCalendarFrom(userPhone, startDate, endDate string) (list []roadshow.User
 	return
 }
 
+//func init() {
+//	SyncCalendarFromShanghai77()
+//}
+
 // SyncCalendarFromShanghai 上海路演数据同步到自系统
 func SyncCalendarFromShanghai77() (err error) {
 	errMsgList := make([]string, 0)
@@ -270,18 +275,17 @@ func SyncCalendarFromShanghai77() (err error) {
 				errMsgList = append(errMsgList, fmt.Sprint("ERR:"+err.Error(), ";"))
 			}
 			go alarm_msg.SendAlarmMsg("上海路演数据同步到自系统失败;errMsg:"+strings.Join(errMsgList, "\n"), 3)
-			//go utils.SendEmail(utils.APPNAME+"上海路演数据同步到自系统失败:"+time.Now().Format("2006-01-02 15:04:05"), errMsg, utils.EmailSendToUsers)
 		}
 	}()
 
 	var mobiles []string
 	mobilesMap := make(map[string]bool)
-	researcherList, err := roadshow.GetResearcher()
-	if err != nil {
-		fmt.Println(err)
+	researcherListAdmin, tmpErr := roadshow.GetResearcher() // ficc研究员
+	if tmpErr != nil {
+		errMsgList = append(errMsgList, fmt.Sprint("获取研究员信息失败:GetResearcher", ";err:"+tmpErr.Error(), ";"))
 		return
 	}
-	for _, v := range researcherList {
+	for _, v := range researcherListAdmin {
 		if v.Mobile == "" {
 			continue
 		}
@@ -291,9 +295,9 @@ func SyncCalendarFromShanghai77() (err error) {
 		mobiles = append(mobiles, v.Mobile)
 		mobilesMap[v.Mobile] = true
 	}
-	askUserList, err := cygx.GetAskEmailList()
-	if err != nil {
-		fmt.Println(err)
+	askUserList, tmpErr := cygx.GetAskEmailList() //权益研究员
+	if tmpErr != nil {
+		errMsgList = append(errMsgList, fmt.Sprint("获取研究员信息失败:GetAskEmailList", ";err:"+tmpErr.Error(), ";"))
 		return
 	}
 	for _, v := range askUserList {
@@ -307,58 +311,42 @@ func SyncCalendarFromShanghai77() (err error) {
 		mobilesMap[v.Mobile] = true
 	}
 
-	//查询管理员信息列表
-	adminList, e := models.GetAdminByAdminMobiles(mobiles)
-	if e != nil {
-		err = fmt.Errorf("查询管理员信息列表失败 Err:%s\n", e)
-
+	adminList, tmpErr := models.GetAdminByAdminAllList() //查询管理员信息列表
+	if tmpErr != nil {
+		errMsgList = append(errMsgList, fmt.Sprint("查询管理员信息列表 失败:GetAdminByAdminAllList", ";err:"+tmpErr.Error(), ";"))
 		return
 	}
-	mapUserInfo := make(map[string]*models.Admin)
-
+	mapUserInfo := make(map[string]*system.AdminItem)
 	for _, v := range adminList {
 		mapUserInfo[v.Mobile] = v
 	}
-
-	fmt.Println(len(mobiles))
-	//return
-	//userPhone := v
+	//获取前后三十天的信息
 	startDate := time.Now().AddDate(0, 0, -30).Format(utils.FormatDate)
 	endDate := time.Now().AddDate(0, 0, 30).Format(utils.FormatDate)
 	var userPhone string
-
 	var list []roadshow.UserCalendar
-	for k, v := range mobiles {
+	//获取指定日期内所有研究员的路演信息
+	for _, v := range mobiles {
 		if v == "" {
 			continue
 		}
-		fmt.Println(k, "___", v)
-
-		//return
 		userPhone = v
 		//以当前日期作为起始日期去同步
-		listSh, err := getCalendarFrom(userPhone, startDate, endDate)
-		if err != nil {
-			errMsgList = append(errMsgList, fmt.Sprint("获取第三方路演日历数据失败,", "userPhone:", userPhone, ";currDay:", startDate, ";endDate:", endDate, ";err:"+err.Error()))
-			return
-		}
+		listSh, tmpErr := getCalendarFrom(userPhone, startDate, endDate)
 
+		if tmpErr != nil && tmpErr.Error() != "NewRequest Err:该用户不存在" {
+			errMsgList = append(errMsgList, fmt.Sprint("获取第三方路演日历数据失败,", "userPhone:", userPhone, ";currDay:", startDate, ";endDate:", endDate, ";err:"+tmpErr.Error()))
+			continue
+		}
 		for _, vSh := range listSh {
 			list = append(list, vSh)
 		}
 	}
 
-	////获取当前研究员信息
-	//userPhoneInfo, err := roadshowService.GetAdminInfo(userPhone)
-	//if err != nil {
-	//	errMsgList = append(errMsgList, fmt.Sprint("获取手机号信息失败:手机号:", userPhone, ";err:"+err.Error(), ";"))
-	//	return
-	//}
-
 	//根据研究员和开始/结束日期获取上海的活动路演
-	rsCalendarResearcherList, err := roadshow.GetRsCalendarResearcherInfoIByResearcherIdAndDate(startDate, endDate)
-	if err != nil {
-		errMsgList = append(errMsgList, fmt.Sprint("获取研究员日程信息失败:手机号:", userPhone, ";err:"+err.Error(), ";"))
+	rsCalendarResearcherList, tmpErr := roadshow.GetRsCalendarResearcherInfoIByResearcherIdAndDate(startDate, endDate)
+	if tmpErr != nil {
+		errMsgList = append(errMsgList, fmt.Sprint("获取研究员日程信息失败:手机号:", userPhone, ";err:"+tmpErr.Error(), ";"))
 		return
 	}
 	//待删除的活动路演
@@ -386,9 +374,8 @@ func SyncCalendarFromShanghai77() (err error) {
 			errMsgList = append(errMsgList, "获取关联列表失败,err:"+tmpErr.Error())
 			return
 		}
-
+		//已存在的三方日历信息,做对比使用
 		rsCalendarRelationMap := make(map[int]*roadshow.RsCalendarRelation)
-
 		var selfCalendarIds []int
 		for _, rsCalendarRelation := range rsCalendarRelationList {
 			rsCalendarRelationMap[rsCalendarRelation.ThirdCalendarId] = rsCalendarRelation
@@ -406,6 +393,28 @@ func SyncCalendarFromShanghai77() (err error) {
 			maprsCalendarResearcherInfo[v.RsCalendarResearcherId] = v
 			rsCalendarIds = append(rsCalendarIds, v.RsCalendarId)
 		}
+
+		//获取研究员map数据信息
+		rsCalendarResearcherListDate, tmpErr := roadshow.GetRsCalendarResearcherListByRsCalendarIds(rsCalendarIds)
+		if tmpErr != nil {
+			errMsgList = append(errMsgList, fmt.Sprint("获取路演活动中的研究员列表失败,路演活动ID:", rsCalendarIds, ";err:"+tmpErr.Error(), ";"))
+			return
+		}
+		maprsCalendarResearcherList := make(map[int][]*roadshow.RsCalendarResearcher)
+		for _, v := range rsCalendarResearcherListDate {
+			maprsCalendarResearcherList[v.RsCalendarId] = append(maprsCalendarResearcherList[v.RsCalendarId], v)
+		}
+
+		//获取路演map信息
+		rsCalendarInfoList, tmpErr := roadshow.GetRsCalendarByIds(rsCalendarIds)
+		if tmpErr != nil {
+			errMsgList = append(errMsgList, fmt.Sprint("日历ID:", rsCalendarIds, "获取路演信息失败;err:"+tmpErr.Error(), ";"))
+			return
+		}
+		mapRsCalendar := make(map[int]*roadshow.RsCalendar)
+		for _, v := range rsCalendarInfoList {
+			mapRsCalendar[v.RsCalendarId] = v
+		}
 		for _, v := range list {
 			//展示优先级:1、customer_name 2、project_name 3、title 需求池953
 			if v.CustomerName != "" {
@@ -416,17 +425,14 @@ func SyncCalendarFromShanghai77() (err error) {
 			if rsCalendarRelation, ok := rsCalendarRelationMap[v.ID]; ok {
 				//存在的话,那么就去查找对应的信息
 				if rsCalendarRelation.CalendarType == 1 {
-					//路演
-					rsCalendarResearcherInfo, tmpErr := roadshow.GetRsCalendarResearcherById(rsCalendarRelation.SelfCalendarId)
-					if tmpErr != nil {
-						errMsgList = append(errMsgList, fmt.Sprint("第三方日历ID:", v.ID, "获取路演研究员信息失败;err:"+tmpErr.Error(), ";"))
+					if maprsCalendarResearcherInfo[rsCalendarRelation.SelfCalendarId] == nil {
 						continue
 					}
-					rsCalendarInfo, tmpErr := roadshow.GetRsCalendarById(rsCalendarResearcherInfo.RsCalendarId)
-					if tmpErr != nil {
-						errMsgList = append(errMsgList, fmt.Sprint("第三方日历ID:", v.ID, "获取路演信息失败;err:"+tmpErr.Error(), ";"))
+					rsCalendarResearcherInfo := maprsCalendarResearcherInfo[rsCalendarRelation.SelfCalendarId]
+					if mapRsCalendar[rsCalendarResearcherInfo.RsCalendarId] == nil {
 						continue
 					}
+					rsCalendarInfo := mapRsCalendar[rsCalendarResearcherInfo.RsCalendarId]
 					if rsCalendarInfo.Source == 0 { //自系统创建的路演活动,不需要依靠上海方来修改
 						continue
 					}
@@ -449,25 +455,23 @@ func SyncCalendarFromShanghai77() (err error) {
 						isUpdate = true
 					}
 
-					researcherList := make([]system.AdminItem, 0)
-					researcherMap := make(map[int]system.AdminItem)
+					researcherList := make([]*system.AdminItem, 0)
+					researcherMap := make(map[int]*system.AdminItem)
 
-					addResearcherList := make([]system.AdminItem, 0)                  // 需要新增的研究员
+					addResearcherList := make([]*system.AdminItem, 0)                 // 需要新增的研究员
 					delResearcherIdList := make([]int, 0)                             //需要删除的路演活动与研究员的关系id
 					updateResearcherList := make([]*roadshow.RsCalendarResearcher, 0) //待更新的路演活动中研究员信息
 
 					if v.ResearcherMobile != rsCalendarRelation.ResearcherMobile {
 						//研究员变更了,需要去改表
 						isUpdateSync = true
-
 						researcherMobileList := strings.Split(v.ResearcherMobile, ",")
 						if len(researcherMobileList) > 0 {
 							for _, mobile := range researcherMobileList {
-								researcherInfo, tmpErr := mapUserInfo[mobile]
-								if tmpErr != nil {
-									errMsgList = append(errMsgList, fmt.Sprint("第三方日历ID:", v.ID, "获取研究员失败,研究员手机号:", mobile, ";err:"+tmpErr.Error(), ";"))
+								if mapUserInfo[mobile] == nil {
 									continue
 								}
+								researcherInfo := mapUserInfo[mobile]
 								if researcherInfo.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_RESEARCHR ||
 									researcherInfo.RoleTypeCode == utils.ROLE_TYPE_CODE_RESEARCHR ||
 									researcherInfo.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_RESEARCHR ||
@@ -475,7 +479,6 @@ func SyncCalendarFromShanghai77() (err error) {
 									researcherInfo.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT ||
 									researcherInfo.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
 									researcherInfo.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
-
 									researcherList = append(researcherList, researcherInfo)
 									researcherMap[researcherInfo.AdminId] = researcherInfo
 								}
@@ -487,16 +490,14 @@ func SyncCalendarFromShanghai77() (err error) {
 							errMsgList = append(errMsgList, fmt.Sprint("第三方日历ID:", v.ID, ";对方研究员信息失败;"))
 							continue
 						}
-
-						rsCalendarResearcherList, tmpErr := roadshow.GetRsCalendarResearcherListByRsCalendarId(rsCalendarInfo.RsCalendarId)
-						if tmpErr != nil {
-							errMsgList = append(errMsgList, fmt.Sprint("第三方日历ID:", v.ID, "获取路演活动中的研究员列表失败,路演活动ID:", rsCalendarInfo.RsCalendarId, ";err:"+tmpErr.Error(), ";"))
+						if len(maprsCalendarResearcherList[rsCalendarInfo.RsCalendarId]) == 0 {
 							continue
 						}
+						rsCalendarResearcherListAdd := maprsCalendarResearcherList[rsCalendarInfo.RsCalendarId]
 
 						//现有活动中的研究员
 						rsCalendarResearcherMap := make(map[int]*roadshow.RsCalendarResearcher)
-						for _, rsCalendarResearcher := range rsCalendarResearcherList {
+						for _, rsCalendarResearcher := range rsCalendarResearcherListAdd {
 							if _, ok := researcherMap[rsCalendarResearcher.ResearcherId]; ok {
 								if isUpdate {
 									updateResearcherList = append(updateResearcherList, rsCalendarResearcher)
@@ -517,18 +518,17 @@ func SyncCalendarFromShanghai77() (err error) {
 						}
 					} else if isUpdate { //如果有字段更新,那么需要将所有的研究员信息更新
 						isUpdateSync = true
-
-						rsCalendarResearcherList, tmpErr := roadshow.GetRsCalendarResearcherListByRsCalendarId(rsCalendarInfo.RsCalendarId)
-						if tmpErr != nil {
-							errMsgList = append(errMsgList, fmt.Sprint("第三方日历ID:", v.ID, "获取路演活动中的研究员列表失败,路演活动ID:", rsCalendarInfo.RsCalendarId, ";err:"+tmpErr.Error(), ";"))
+						if len(maprsCalendarResearcherList[rsCalendarInfo.RsCalendarId]) == 0 {
 							continue
 						}
-						for _, rsCalendarResearcher := range rsCalendarResearcherList {
+						rsCalendarResearcherListUpdate := maprsCalendarResearcherList[rsCalendarInfo.RsCalendarId]
+						for _, rsCalendarResearcher := range rsCalendarResearcherListUpdate {
 							updateResearcherList = append(updateResearcherList, rsCalendarResearcher)
 						}
 					}
 
 					if isUpdateSync {
+						time.Sleep(200 * time.Millisecond) // 加一个延迟0.2秒
 						tmpErr = roadshow.UpdateSyncRsCalendarRelation(v, rsCalendarInfo, rsCalendarRelation, updateResearcherList, delResearcherIdList, addResearcherList)
 						if tmpErr != nil {
 							err = tmpErr
@@ -541,23 +541,20 @@ func SyncCalendarFromShanghai77() (err error) {
 					//事项都是由自系统创建的,不需要依靠上海方来修改
 				}
 			} else {
-				//数据不存在
-				createUser, tmpErr := roadshowService.GetAdminInfo(v.UserPhone)
-				if tmpErr != nil {
-					errMsgList = append(errMsgList, fmt.Sprint("第三方日历ID:", v.ID, "获取创建人失败,创建人手机号:", v.UserPhone, ";err:"+tmpErr.Error(), ";"))
+				//fmt.Println("add")
+				if mapUserInfo[v.UserPhone] == nil {
 					continue
 				}
-
+				createUser := mapUserInfo[v.UserPhone]
 				//研究员列表
-				researcherList := make([]system.AdminItem, 0)
+				researcherList := make([]*system.AdminItem, 0)
 				researcherMobileList := strings.Split(v.ResearcherMobile, ",")
 				if len(researcherMobileList) > 0 {
 					for _, mobile := range researcherMobileList {
-						researcherInfo, tmpErr := roadshowService.GetAdminInfo(mobile)
-						if tmpErr != nil {
-							errMsgList = append(errMsgList, fmt.Sprint("第三方日历ID:", v.ID, "获取研究员失败,研究员手机号:", mobile, ";err:"+tmpErr.Error(), ";"))
+						if mapUserInfo[mobile] == nil {
 							continue
 						}
+						researcherInfo := mapUserInfo[mobile]
 						if researcherInfo.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_RESEARCHR ||
 							researcherInfo.RoleTypeCode == utils.ROLE_TYPE_CODE_RESEARCHR ||
 							researcherInfo.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_RESEARCHR ||
@@ -576,34 +573,33 @@ func SyncCalendarFromShanghai77() (err error) {
 					continue
 				}
 				//数据入库
+				time.Sleep(200 * time.Millisecond) // 加一个延迟0.2秒
 				tmpErr = roadshow.SyncRsCalendarRelation(v, createUser, researcherList)
 				if tmpErr != nil {
 					err = tmpErr
 					errMsgList = append(errMsgList, fmt.Sprint("第三方日历ID:", v.ID, "绑定关联关系失败;err:"+tmpErr.Error(), ";"))
 					continue
 				}
-				//fmt.Println("createUser:", createUser)
 			}
-
 		}
 	}
 
+	var delRsCalendarResearcherIds []int
 	////上海那边已经删除了路演,这边也要同步删除
-	//for _, deleteRsCalendarResearcherList := range deleteRsCalendarResearcherMap {
-	//	for _, deleteRsCalendarResearcher := range deleteRsCalendarResearcherList {
-	//		// 更新路演与研究员关系表的状态字段
-	//		whereParams := make(map[string]interface{})
-	//		updateParams := make(map[string]interface{})
-	//		whereParams["rs_calendar_researcher_id"] = deleteRsCalendarResearcher.RsCalendarResearcherId
-	//		updateParams["status"] = 4
-	//		updateParams["modify_time"] = time.Now()
-	//		tmpErr := roadshow.UpdateCalendarResearcher(whereParams, updateParams)
-	//		if tmpErr != nil {
-	//			err = tmpErr
-	//			errMsgList = append(errMsgList, fmt.Sprint("第三方日历ID:", deleteRsCalendarResearcher.ThirdCalendarId, "删除关联关系失败;err:"+tmpErr.Error(), ";"))
-	//			continue
-	//		}
-	//	}
-	//}
+	for _, deleteRsCalendarResearcherList := range deleteRsCalendarResearcherMap {
+		for _, deleteRsCalendarResearcher := range deleteRsCalendarResearcherList {
+			delRsCalendarResearcherIds = append(delRsCalendarResearcherIds, deleteRsCalendarResearcher.RsCalendarResearcherId)
+		}
+	}
+
+	if len(delRsCalendarResearcherIds) > 0 {
+		tmpErr := roadshow.ModifyRsCalendarResearcherStatusDel(delRsCalendarResearcherIds)
+		if tmpErr != nil {
+			err = tmpErr
+			errMsgList = append(errMsgList, fmt.Sprint("删除第三方日历ID:", delRsCalendarResearcherIds, "删除关联关系失败;err:"+tmpErr.Error(), ";"))
+			return
+		}
+	}
+
 	return
 }

+ 18 - 0
utils/common.go

@@ -925,3 +925,21 @@ func Implode(idIntList []int) (str string) {
 	str = str[:len(str)-1]
 	return
 }
+
+// EnWeekToCnWeek 英文周几转中文周几
+func EnWeekToCnWeek(enWeekStr string) string {
+	var WeekDayMap = map[string]string{
+		"Monday":    "周一",
+		"Tuesday":   "周二",
+		"Wednesday": "周三",
+		"Thursday":  "周四",
+		"Friday":    "周五",
+		"Saturday":  "周六",
+		"Sunday":    "周日",
+	}
+	cnWeekStr, ok := WeekDayMap[enWeekStr]
+	if !ok {
+		cnWeekStr = `周一`
+	}
+	return cnWeekStr
+}

+ 16 - 0
utils/config.go

@@ -268,6 +268,9 @@ ZwIDAQAB
 
 	// 进门财经开放api配置
 	ComeinOpenApiConfig()
+
+	//上海crm开放api配置
+	CrmOpenApiConfig()
 }
 
 // ComeinOpenApiConfig 进门开放api配置
@@ -287,5 +290,18 @@ func ComeinOpenApiConfig() {
 	}
 }
 
+// CrmOpenApiConfig 上海crm开放api配置
+func CrmOpenApiConfig() {
+	if RunMode == "release" {
+		CRM_OPEN_API_URL = "http://crm.hzinsights.com/openapi"
+		CRM_OPEN_API_APP_KEY = "26945134"
+		CRM_OPEN_API_APP_SECRET = "b99cb2bdec70d20156000f664ec5ac30"
+	} else {
+		CRM_OPEN_API_URL = "http://106.15.192.100:8100/openapi"
+		CRM_OPEN_API_APP_KEY = "26945134"
+		CRM_OPEN_API_APP_SECRET = "b99cb2bdec70d20156000f664ec5ac30"
+	}
+}
+
 //http://entryapi.brilliantstart.cn
 //http://entryapi.brilliantstart.cn/swagger/

+ 38 - 0
utils/constants.go

@@ -185,3 +185,41 @@ const (
 const (
 	EnCompanyIdStep = 10000000
 )
+
+// 管理员,ficc管理员,ficc销售,权益管理员,权益销售。
+// 角色类型/类型编码
+const (
+	ROLE_TYPE_ADMIN       = "管理员"
+	ROLE_TYPE_FICC_ADMIN  = "ficc管理员"
+	ROLE_TYPE_FICC_SELLER = "ficc销售"
+	ROLE_TYPE_RAI_ADMIN   = "权益管理员"
+	ROLE_TYPE_RAI_SELLER  = "权益销售"
+	ROLE_TYPE_RAI_PRODUCT = "权益产品"
+
+	ROLE_TYPE_FICC_GROUP      = "ficc销售组长"
+	ROLE_TYPE_FICC_MANAGER    = "ficc销售主管"
+	ROLE_TYPE_RAI_GROUP       = "权益销售组长"
+	ROLE_TYPE_FICC_DEPARTMENT = "ficc部门经理"
+	ROLE_TYPE_RAI_DEPARTMENT  = "权益部门经理"
+	ROLE_TYPE_FICC_RESEARCHR  = "ficc研究员"
+	ROLE_TYPE_RAI_RESEARCHR   = "权益研究员"
+	ROLE_NAME_FICC_DIRECTOR   = "ficc销售经理" // 实际角色类型为ficc销售主管
+
+	ROLE_TYPE_CODE_ADMIN           = "admin"           //管理员
+	ROLE_TYPE_CODE_FICC_ADMIN      = "ficc_admin"      //ficc管理员
+	ROLE_TYPE_CODE_FICC_SELLER     = "ficc_seller"     //ficc销售
+	ROLE_TYPE_CODE_RAI_ADMIN       = "rai_admin"       //权益管理员
+	ROLE_TYPE_CODE_RAI_SELLER      = "rai_seller"      //权益销售
+	ROLE_TYPE_CODE_FICC_GROUP      = "ficc_group"      //ficc销售主管
+	ROLE_TYPE_CODE_RAI_GROUP       = "rai_group"       //ficc组长
+	ROLE_TYPE_CODE_FICC_DEPARTMENT = "ficc_department" //ficc部门经理
+	ROLE_TYPE_CODE_RAI_DEPARTMENT  = "rai_department"  //权益部门经理
+	ROLE_TYPE_CODE_FICC_RESEARCHR  = "ficc_researcher" //ficc研究员
+	ROLE_TYPE_CODE_RESEARCHR       = "researcher"      //ficc研究员(最早定义的)
+	ROLE_TYPE_CODE_RAI_RESEARCHR   = "rai_researcher"  //权益研究员
+	ROLE_TYPE_CODE_COMPLIANCE      = "compliance"      //合规角色
+	ROLE_TYPE_CODE_FINANCE         = "finance"         //财务角色
+	ROLE_TYPE_CODE_FICC_TEAM       = "ficc_team"       //ficc销售组长
+
+	ROLE_TYPE_SELLERS = "'ficc_admin','ficc_seller','ficc_team','rai_admin','rai_seller','ficc_group','rai_group','ficc_department','rai_department','compliance','finance'"
+)