|
@@ -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
|
|
|
}
|