package roadshow import ( "fmt" "hongze/hz_crm_api/models/company" "hongze/hz_crm_api/models/overseas_custom" "hongze/hz_crm_api/models/roadshow" "hongze/hz_crm_api/utils" "time" ) // GetWeekData 周度数据 func GetWeekData(adminType, dimensionType string) (adminDataList []AdminDataMap, firstDate time.Time, err error) { nowWeekMonday := utils.GetNowWeekMonday() //本周周一 //fmt.Println(nowWeekMonday) nowWeekSunday := nowWeekMonday.AddDate(0, 0, 7).Add(-1 * time.Second) //本周周日 //fmt.Println(nowWeekSunday) //nowWeekMonday = nowWeekMonday.AddDate(0, 0, -30) //上周周一 //nowWeekSunday = nowWeekSunday.AddDate(0, 0, -30) //上周周日 //adminDataMap, err := getSectionData(nowWeekMonday, nowWeekSunday) //if err != nil { // fmt.Println(err) // return //} //fmt.Println(adminDataMap) lastWeekMonday := nowWeekMonday.AddDate(0, 0, -7) //上周周一 //fmt.Println(lastWeekMonday) //最早的一天 firstDate = lastWeekMonday lastWeekSunday := nowWeekSunday.AddDate(0, 0, -7) //上周周日 //fmt.Println(lastWeekSunday) nextWeekMonday := nowWeekMonday.AddDate(0, 0, 7) //下周周一 //fmt.Println(nextWeekMonday) nextWeekSunday := nowWeekSunday.AddDate(0, 0, 7) //下周周日 //fmt.Println(nextWeekSunday) ch1 := make(chan AdminDataMap, 0) ch2 := make(chan AdminDataMap, 0) ch3 := make(chan AdminDataMap, 0) go getSectionData(lastWeekMonday, lastWeekSunday, adminType, dimensionType, ch1) go getSectionData(nowWeekMonday, nowWeekSunday, adminType, dimensionType, ch2) go getSectionData(nextWeekMonday, nextWeekSunday, adminType, dimensionType, ch3) var nowWeekAdminDataMap, lastWeekAdminDataMap, nextWeekAdminDataMap AdminDataMap lastWeekAdminDataMap = <-ch1 close(ch1) nowWeekAdminDataMap = <-ch2 close(ch2) nextWeekAdminDataMap = <-ch3 close(ch3) adminDataList = make([]AdminDataMap, 0) adminDataList = append(adminDataList, lastWeekAdminDataMap, nowWeekAdminDataMap, nextWeekAdminDataMap) return } // GetWeekDataV2 周度数据 func GetWeekDataV2(adminType, dimensionType string, weekNum int) (adminDataList []AdminDataMap, firstDate time.Time, err error) { nowWeekMonday := utils.GetNowWeekMonday() //本周周一 //fmt.Println(nowWeekMonday) nowWeekSunday := nowWeekMonday.AddDate(0, 0, 7).Add(-1 * time.Second) //本周周日 chanList := make([]chan AdminDataMap, 0) for i := 0; i < weekNum; i++ { tmpCh := make(chan AdminDataMap, 0) chanList = append(chanList, tmpCh) lastWeekMonday := nowWeekMonday.AddDate(0, 0, -7*i) lastWeekSunday := nowWeekSunday.AddDate(0, 0, -7*i) // 第一个开始日期 firstDate = lastWeekMonday go getSectionData(lastWeekMonday, lastWeekSunday, adminType, dimensionType, tmpCh) } adminDataList = make([]AdminDataMap, 0) for _, vChan := range chanList { var weekAdminDataMap AdminDataMap weekAdminDataMap = <-vChan close(vChan) adminDataList = append(adminDataList, weekAdminDataMap) } return } // GetMonthData 月度数据 func GetMonthData(adminType, dimensionType string) (adminDataMapList []AdminDataMap, firstDate time.Time, err error) { //三个协程返回 nowMonthFirstDay := utils.GetNowMonthFirstDay() //本月第一天 nowMonthLastDay := nowMonthFirstDay.AddDate(0, 1, 0).Add(-1 * time.Second) //本月最后一天 lastMonthFirstDay1 := nowMonthFirstDay.AddDate(0, -1, 0) //上个月第一天 lastMonthLastDay1 := lastMonthFirstDay1.AddDate(0, 1, 0).Add(-1 * time.Second) //上个月最后一天 lastMonthFirstDay2 := nowMonthFirstDay.AddDate(0, -2, 0) //上上个月第一天 lastMonthLastDay2 := lastMonthFirstDay2.AddDate(0, 1, 0).Add(-1 * time.Second) //上上个月最后一天 lastMonthFirstDay3 := nowMonthFirstDay.AddDate(0, -3, 0) //上上上个月第一天 lastMonthLastDay3 := lastMonthFirstDay3.AddDate(0, 1, 0).Add(-1 * time.Second) //上上上个月最后一天 //最早的一天 firstDate = lastMonthFirstDay3 ch1 := make(chan AdminDataMap, 0) ch2 := make(chan AdminDataMap, 0) ch3 := make(chan AdminDataMap, 0) ch4 := make(chan AdminDataMap, 0) go getSectionData(nowMonthFirstDay, nowMonthLastDay, adminType, dimensionType, ch1) go getSectionData(lastMonthFirstDay1, lastMonthLastDay1, adminType, dimensionType, ch2) go getSectionData(lastMonthFirstDay2, lastMonthLastDay2, adminType, dimensionType, ch3) go getSectionData(lastMonthFirstDay3, lastMonthLastDay3, adminType, dimensionType, ch4) var nowMonthAdminDataMap, lastMonthAdminDataMap1, lastMonthAdminDataMap2, lastMonthAdminDataMap3 AdminDataMap nowMonthAdminDataMap = <-ch1 close(ch1) lastMonthAdminDataMap1 = <-ch2 close(ch2) lastMonthAdminDataMap2 = <-ch3 close(ch3) lastMonthAdminDataMap3 = <-ch4 close(ch4) adminDataMapList = make([]AdminDataMap, 0) adminDataMapList = append(adminDataMapList, nowMonthAdminDataMap, lastMonthAdminDataMap1, lastMonthAdminDataMap2, lastMonthAdminDataMap3) return } // GetMonthDataV2 月度数据 func GetMonthDataV2(adminType, dimensionType string, dataNum int) (adminDataMapList []AdminDataMap, firstDate time.Time, err error) { //三个协程返回 nowMonthFirstDay := utils.GetNowMonthFirstDay() //本月第一天 //nowMonthLastDay := nowMonthFirstDay.AddDate(0, 1, 0).Add(-1 * time.Second) //本月最后一天 chanList := make([]chan AdminDataMap, 0) for i := 0; i < dataNum; i++ { tmpCh := make(chan AdminDataMap, 0) chanList = append(chanList, tmpCh) lastMonthFirstDay := nowMonthFirstDay.AddDate(0, -1*i, 0) //上个月第一天 lastMonthLastDay := nowMonthFirstDay.AddDate(0, -1*(i-1), 0).Add(-1 * time.Second) //上个月最后一天 // 第一个开始日期 firstDate = lastMonthFirstDay go getSectionData(lastMonthFirstDay, lastMonthLastDay, adminType, dimensionType, tmpCh) } adminDataMapList = make([]AdminDataMap, 0) for _, vChan := range chanList { var monthAdminDataMap AdminDataMap monthAdminDataMap = <-vChan close(vChan) adminDataMapList = append(adminDataMapList, monthAdminDataMap) } return } // GetTimeIntervalData 区间数据 func GetTimeIntervalData(startDate, endDate, adminType, dimensionType string) (adminDataMapList []AdminDataMap, firstDate time.Time, err error) { //三个协程返回 startDateTimer, _ := time.ParseInLocation(utils.FormatDate, startDate, time.Local) endDateTimer, _ := time.ParseInLocation(utils.FormatDate, endDate, time.Local) endDateTimer = endDateTimer.AddDate(0, 0, 1).Add(-1 * time.Second) //本月最后一天 //最早的一天 firstDate = startDateTimer ch1 := make(chan AdminDataMap, 0) go getSectionData(startDateTimer, endDateTimer, adminType, dimensionType, ch1) var adminDataMap AdminDataMap adminDataMap = <-ch1 close(ch1) adminDataMapList = make([]AdminDataMap, 0) adminDataMapList = append(adminDataMapList, adminDataMap) return } type AdminDataMap struct { TryOutMap map[int]int `description:"试用路演次数"` FormalMap map[int]int `description:"正式路演次数"` MeetingMap map[int]int `description:"会议次数"` OnlineMap map[int]int `description:"线上路演次数"` OfflineMap map[int]int `description:"线上路演次数"` RoadShowMap map[int]int `description:"路演总次数"` SalonMap map[int]int `description:"沙龙路演次数"` StartDate string `description:"开始日期"` EndDate string `description:"开始日期"` } // getSectionData 获取周期数据 func getSectionData(startDate, endDate time.Time, adminType, dimensionType string, ch chan AdminDataMap) (adminDataMap AdminDataMap, err error) { defer func() { ch <- adminDataMap }() //adminType := `seller` switch adminType { case "researcher": adminDataMap, err = getResearcherSectionData(startDate, endDate) case "seller": adminDataMap, err = getSellerSectionData(startDate, endDate, dimensionType) } return } // getResearcherSectionData 获取研究员周期数据 func getResearcherSectionData(startDate, endDate time.Time) (adminDataMap AdminDataMap, err error) { tryOutMap := make(map[int]int) formalMap := make(map[int]int) meetingMap := make(map[int]int) roadShowMap := make(map[int]int) // 路演总次数 salonMap := make(map[int]int) //沙龙路演次数 //正式客户 { var condition string var pars []interface{} condition = ` and start_date >= ? and end_date <= ? and company_status = ? ` pars = append(pars, startDate, endDate, "正式") data, tmpErr := roadshow.GetGroupResearcherRecordList(condition, pars) if tmpErr != nil { err = tmpErr return } for _, v := range data { formalMap[v.AdminId] = v.Num } } //试用客户 { var condition string var pars []interface{} condition = ` and start_date >= ? and end_date <= ? and company_status = ? ` pars = append(pars, startDate, endDate, "试用") data, tmpErr := roadshow.GetGroupResearcherRecordList(condition, pars) if tmpErr != nil { err = tmpErr return } for _, v := range data { //fmt.Println(v) tryOutMap[v.AdminId] = v.Num } } //试用客户 { var condition string var pars []interface{} condition = ` and start_date >= ? and end_date <= ? and activity_type = ? ` pars = append(pars, startDate, endDate, "公开会议") data, tmpErr := roadshow.GetGroupResearcherRecordList(condition, pars) if tmpErr != nil { err = tmpErr return } for _, v := range data { //fmt.Println(v) meetingMap[v.AdminId] = v.Num } } //路演总次数 { var condition string var pars []interface{} condition = ` and start_date >= ? and end_date <= ? and activity_type = ? ` pars = append(pars, startDate, endDate, "路演") data, tmpErr := roadshow.GetGroupResearcherRecordList(condition, pars) if tmpErr != nil { err = tmpErr return } for _, v := range data { //fmt.Println(v) roadShowMap[v.AdminId] = v.Num } } //沙龙路演次数 { var condition string var pars []interface{} condition = ` and start_date >= ? and end_date <= ? and activity_type = ? ` pars = append(pars, startDate, endDate, "沙龙") data, tmpErr := roadshow.GetGroupResearcherRecordList(condition, pars) if tmpErr != nil { err = tmpErr return } for _, v := range data { //fmt.Println(v) salonMap[v.AdminId] = v.Num } } adminDataMap = AdminDataMap{ TryOutMap: tryOutMap, FormalMap: formalMap, MeetingMap: meetingMap, RoadShowMap: roadShowMap, SalonMap: salonMap, StartDate: startDate.Format(utils.FormatDate), EndDate: endDate.Format(utils.FormatDate), } return } // getSellerSectionData 获取销售周期数据 func getSellerSectionData(startDate, endDate time.Time, dimensionType string) (adminDataMap AdminDataMap, err error) { tryOutMap := make(map[int]int) formalMap := make(map[int]int) meetingMap := make(map[int]int) onlineMap := make(map[int]int) offlineMap := make(map[int]int) roadShowMap := make(map[int]int) // 路演总次数 salonMap := make(map[int]int) //沙龙路演次数 //fmt.Println() //客户状态维度 if dimensionType == "company_status" { //正式客户 { var condition string var pars []interface{} condition = ` and start_date >= ? and end_date <= ? and company_status = ? ` pars = append(pars, startDate, endDate, "正式") data, tmpErr := roadshow.GetGroupSellerRecordList(condition, pars) if tmpErr != nil { err = tmpErr return } for _, v := range data { formalMap[v.AdminId] = v.Num } } //试用客户 { var condition string var pars []interface{} condition = ` and start_date >= ? and end_date <= ? and company_status = ? ` pars = append(pars, startDate, endDate, "试用") data, tmpErr := roadshow.GetGroupSellerRecordList(condition, pars) if tmpErr != nil { err = tmpErr return } for _, v := range data { //fmt.Println(v) tryOutMap[v.AdminId] = v.Num } } } //路演形式维度 if dimensionType == "roadshow_type" { //线上路演 { var condition string var pars []interface{} condition = ` and start_date >= ? and end_date <= ? and roadshow_type = ? ` pars = append(pars, startDate, endDate, "线上") data, tmpErr := roadshow.GetGroupSellerRecordList(condition, pars) if tmpErr != nil { err = tmpErr return } for _, v := range data { //fmt.Println(v) onlineMap[v.AdminId] = v.Num } } //线下路演 { var condition string var pars []interface{} condition = ` and start_date >= ? and end_date <= ? and roadshow_type = ? ` pars = append(pars, startDate, endDate, "线下") data, tmpErr := roadshow.GetGroupSellerRecordList(condition, pars) if tmpErr != nil { err = tmpErr return } for _, v := range data { //fmt.Println(v) offlineMap[v.AdminId] = v.Num } } } //销售专项路演统计 if dimensionType == "seller_special" { detail, errdetail := company.GetConfigDetailByCode("choice_researcher_adminid") if errdetail != nil { err = errdetail return } //正式客户 { var condition string var pars []interface{} condition = ` and start_date >= ? and end_date <= ? and company_status = ? ` + ` and researcher_id IN (` + detail.ConfigValue + `) ` pars = append(pars, startDate, endDate, "正式") data, tmpErr := roadshow.GetGroupSellerRecordList(condition, pars) if tmpErr != nil { err = tmpErr return } for _, v := range data { formalMap[v.AdminId] = v.Num } } //试用客户 { var condition string var pars []interface{} condition = ` and start_date >= ? and end_date <= ? and company_status = ? ` + ` and researcher_id IN (` + detail.ConfigValue + `) ` pars = append(pars, startDate, endDate, "试用") data, tmpErr := roadshow.GetGroupSellerRecordList(condition, pars) if tmpErr != nil { err = tmpErr return } for _, v := range data { //fmt.Println(v) tryOutMap[v.AdminId] = v.Num } } //公开会议 { var condition string var pars []interface{} condition = ` and start_date >= ? and end_date <= ? and activity_type = ? ` + ` and researcher_id IN (` + detail.ConfigValue + `) ` pars = append(pars, startDate, endDate, "公开会议") data, tmpErr := roadshow.GetGroupSellerRecordList(condition, pars) if tmpErr != nil { err = tmpErr return } for _, v := range data { //fmt.Println(v) meetingMap[v.AdminId] = v.Num } } } else { //公开会议 { var condition string var pars []interface{} condition = ` and start_date >= ? and end_date <= ? and activity_type = ? ` pars = append(pars, startDate, endDate, "公开会议") data, tmpErr := roadshow.GetGroupSellerRecordList(condition, pars) if tmpErr != nil { err = tmpErr return } for _, v := range data { //fmt.Println(v) meetingMap[v.AdminId] = v.Num } } } //权益路演 if dimensionType == "roadshow_rai" { //路演总次数 { var condition string var pars []interface{} condition = ` and start_date >= ? and end_date <= ? and activity_type = ? ` pars = append(pars, startDate, endDate, "路演") data, tmpErr := roadshow.GetGroupSellerRecordList(condition, pars) if tmpErr != nil { err = tmpErr return } for _, v := range data { //fmt.Println(v) roadShowMap[v.AdminId] = v.Num } } //沙龙路演次数 { var condition string var pars []interface{} condition = ` and start_date >= ? and end_date <= ? and activity_type = ? ` pars = append(pars, startDate, endDate, "沙龙") data, tmpErr := roadshow.GetGroupSellerRecordList(condition, pars) if tmpErr != nil { err = tmpErr return } for _, v := range data { //fmt.Println(v) salonMap[v.AdminId] = v.Num } } } adminDataMap = AdminDataMap{ TryOutMap: tryOutMap, FormalMap: formalMap, MeetingMap: meetingMap, OfflineMap: offlineMap, OnlineMap: onlineMap, RoadShowMap: roadShowMap, SalonMap: salonMap, StartDate: startDate.Format(utils.FormatDate), EndDate: endDate.Format(utils.FormatDate), } return } type OverseasAdminDataMap struct { TryOutMap map[int]int `description:"试用路演次数"` FormalMap map[int]int `description:"正式路演次数"` CloseMap map[int]int `description:"关闭客户次数"` OnlineMap map[int]int `description:"线上路演次数"` OfflineMap map[int]int `description:"线上路演次数"` StartDate string `description:"开始日期"` EndDate string `description:"开始日期"` } // GetOverseasWeekDataV2 周度数据 func GetOverseasWeekDataV2(adminType, dimensionType string, weekNum int) (adminDataList []OverseasAdminDataMap, firstDate time.Time, err error) { nowWeekMonday := utils.GetNowWeekMonday() //本周周一 //fmt.Println(nowWeekMonday) nowWeekSunday := nowWeekMonday.AddDate(0, 0, 7).Add(-1 * time.Second) //本周周日 chanList := make([]chan OverseasAdminDataMap, 0) for i := 0; i < weekNum; i++ { tmpCh := make(chan OverseasAdminDataMap, 0) chanList = append(chanList, tmpCh) lastWeekMonday := nowWeekMonday.AddDate(0, 0, -7*i) lastWeekSunday := nowWeekSunday.AddDate(0, 0, -7*i) // 第一个开始日期 firstDate = lastWeekMonday go getOverseasSectionData(lastWeekMonday, lastWeekSunday, adminType, dimensionType, tmpCh) } adminDataList = make([]OverseasAdminDataMap, 0) for _, vChan := range chanList { var weekAdminDataMap OverseasAdminDataMap weekAdminDataMap = <-vChan close(vChan) adminDataList = append(adminDataList, weekAdminDataMap) } return } // getOverseasSectionData 获取周期数据 func getOverseasSectionData(startDate, endDate time.Time, adminType, dimensionType string, ch chan OverseasAdminDataMap) (adminDataMap OverseasAdminDataMap, err error) { defer func() { ch <- adminDataMap }() //adminType := `seller` switch adminType { case "researcher": adminDataMap, err = getOverseasResearcherSectionData(startDate, endDate) case "seller": adminDataMap, err = getOverseasSellerSectionData(startDate, endDate, dimensionType) } return } // getOverseasSellerSectionData 获取销售周期数据 func getOverseasSellerSectionData(startDate, endDate time.Time, dimensionType string) (adminDataMap OverseasAdminDataMap, err error) { tryOutMap := make(map[int]int) formalMap := make(map[int]int) closeMap := make(map[int]int) onlineMap := make(map[int]int) offlineMap := make(map[int]int) //fmt.Println() //客户状态维度 companylist, err := overseas_custom.GetOverseasCustomList("", nil) if err != nil { return } formalIdsArr := make([]int, 0) tryoutIdsArr := make([]int, 0) closeIdsArr := make([]int, 0) for _, v := range companylist { if v.OverseasStatus == "正式" { formalIdsArr = append(formalIdsArr, v.CompanyId) } else if v.OverseasStatus == "试用" { tryoutIdsArr = append(tryoutIdsArr, v.CompanyId) } else if v.OverseasStatus == "关闭" { closeIdsArr = append(closeIdsArr, v.CompanyId) } } if dimensionType == "company_status" { //正式客户 { //var condition string //var pars []interface{} //condition = ` and start_date >= ? and end_date <= ? and company_status = ? and company_id IN (` + utils.GetOrmInReplace(len(formalIdsArr)) + `)` //pars = append(pars, startDate, endDate, "正式", formalIdsArr) data, tmpErr := roadshow.GetOverseasGroupSellerRecordList(startDate.Format(utils.FormatDate), endDate.Format(utils.FormatDate), "正式") if tmpErr != nil { err = tmpErr return } for _, v := range data { fmt.Println(v) formalMap[v.AdminId] = v.Num } } //试用客户 { //var condition string //var pars []interface{} //condition = ` and start_date >= ? and end_date <= ? and company_status = ? and company_id IN (` + utils.GetOrmInReplace(len(tryoutIdsArr)) + `)` //pars = append(pars, startDate, endDate, "试用", tryoutIdsArr) data, tmpErr := roadshow.GetOverseasGroupSellerRecordList(startDate.Format(utils.FormatDate), endDate.Format(utils.FormatDate), "试用") if tmpErr != nil { err = tmpErr return } for _, v := range data { //fmt.Println(v) tryOutMap[v.AdminId] = v.Num } } //关闭客户 { //var condition string //var pars []interface{} //condition = ` and start_date >= ? and end_date <= ? and company_status = ? and company_id IN (` + utils.GetOrmInReplace(len(closeIdsArr)) + `)` //pars = append(pars, startDate, endDate, "关闭", closeIdsArr) data, tmpErr := roadshow.GetOverseasGroupSellerRecordList(startDate.Format(utils.FormatDate), endDate.Format(utils.FormatDate), "关闭") if tmpErr != nil { err = tmpErr return } for _, v := range data { //fmt.Println(v) closeMap[v.AdminId] = v.Num } } } //路演形式维度 //if dimensionType == "roadshow_type" { // //线上路演 // { // var condition string // var pars []interface{} // condition = ` and start_date >= ? and end_date <= ? and roadshow_type = ? and company_id IN (` + utils.GetOrmInReplace(len(idsArr)) + `)` // pars = append(pars, startDate, endDate, "线上", idsArr) // data, tmpErr := roadshow.GetOverseasGroupSellerRecordList(condition, pars) // if tmpErr != nil { // err = tmpErr // return // } // for _, v := range data { // //fmt.Println(v) // onlineMap[v.AdminId] = v.Num // } // } // // //线下路演 // { // var condition string // var pars []interface{} // condition = ` and start_date >= ? and end_date <= ? and roadshow_type = ? and company_id IN (` + utils.GetOrmInReplace(len(idsArr)) + `)` // pars = append(pars, startDate, endDate, "线下", idsArr) // data, tmpErr := roadshow.GetOverseasGroupSellerRecordList(condition, pars) // if tmpErr != nil { // err = tmpErr // return // } // for _, v := range data { // //fmt.Println(v) // offlineMap[v.AdminId] = v.Num // } // } //} ////销售专项路演统计 //if dimensionType == "seller_special" { // // detail, errdetail := company.GetConfigDetailByCode("choice_researcher_adminid") // if errdetail != nil { // err = errdetail // return // } // //正式客户 // { // var condition string // var pars []interface{} // condition = ` and start_date >= ? and end_date <= ? and company_status = ? ` + ` and researcher_id IN (` + detail.ConfigValue + `) ` // pars = append(pars, startDate, endDate, "正式") // data, tmpErr := roadshow.GetOverseasGroupSellerRecordList(condition, pars) // if tmpErr != nil { // err = tmpErr // return // } // for _, v := range data { // formalMap[v.AdminId] = v.Num // } // } // // //试用客户 // { // var condition string // var pars []interface{} // condition = ` and start_date >= ? and end_date <= ? and company_status = ? ` + ` and researcher_id IN (` + detail.ConfigValue + `) ` // pars = append(pars, startDate, endDate, "试用") // data, tmpErr := roadshow.GetOverseasGroupSellerRecordList(condition, pars) // // if tmpErr != nil { // err = tmpErr // return // } // for _, v := range data { // //fmt.Println(v) // tryOutMap[v.AdminId] = v.Num // } // } // // //公开会议 // { // var condition string // var pars []interface{} // condition = ` and start_date >= ? and end_date <= ? and activity_type = ? ` + ` and researcher_id IN (` + detail.ConfigValue + `) ` // pars = append(pars, startDate, endDate, "公开会议") // data, tmpErr := roadshow.GetOverseasGroupSellerRecordList(condition, pars) // if tmpErr != nil { // err = tmpErr // return // } // for _, v := range data { // //fmt.Println(v) // meetingMap[v.AdminId] = v.Num // } // } //} else { // //公开会议 // { // var condition string // var pars []interface{} // condition = ` and start_date >= ? and end_date <= ? and activity_type = ? ` // pars = append(pars, startDate, endDate, "公开会议") // data, tmpErr := roadshow.GetOverseasGroupSellerRecordList(condition, pars) // if tmpErr != nil { // err = tmpErr // return // } // for _, v := range data { // //fmt.Println(v) // meetingMap[v.AdminId] = v.Num // } // } //} adminDataMap = OverseasAdminDataMap{ TryOutMap: tryOutMap, FormalMap: formalMap, CloseMap: closeMap, OfflineMap: offlineMap, OnlineMap: onlineMap, StartDate: startDate.Format(utils.FormatDate), EndDate: endDate.Format(utils.FormatDate), } return } // getOverseasResearcherSectionData 获取研究员周期数据 func getOverseasResearcherSectionData(startDate, endDate time.Time) (adminDataMap OverseasAdminDataMap, err error) { tryOutMap := make(map[int]int) formalMap := make(map[int]int) closemap := make(map[int]int) //companylist, err := overseas_custom.GetOverseasCustomList("", nil) //if err != nil { // return //} //formalIdsArr := make([]int, 0) //tryoutIdsArr := make([]int, 0) //closeIdsArr := make([]int, 0) //for _, v := range companylist { // if v.OverseasStatus == "正式" { // formalIdsArr = append(formalIdsArr, v.CompanyId) // } else if v.OverseasStatus == "试用" { // tryoutIdsArr = append(tryoutIdsArr, v.CompanyId) // } else if v.OverseasStatus == "关闭" { // closeIdsArr = append(closeIdsArr, v.CompanyId) // } //} //正式客户 { //var condition string //var pars []interface{} //condition = ` and start_date >= ? and end_date <= ? and company_status = ? and company_id IN (` + utils.GetOrmInReplace(len(formalIdsArr)) + `)` //pars = append(pars, startDate, endDate, "正式", formalIdsArr) data, tmpErr := roadshow.GetOverseasGroupResearcherRecordList(startDate.Format(utils.FormatDate), endDate.Format(utils.FormatDate), "正式") if tmpErr != nil { err = tmpErr return } for _, v := range data { formalMap[v.AdminId] = v.Num } } //试用客户 { //var condition string //var pars []interface{} //condition = ` and start_date >= ? and end_date <= ? and company_status = ? and company_id IN (` + utils.GetOrmInReplace(len(tryoutIdsArr)) + `)` //pars = append(pars, startDate, endDate, "试用", tryoutIdsArr) data, tmpErr := roadshow.GetOverseasGroupResearcherRecordList(startDate.Format(utils.FormatDate), endDate.Format(utils.FormatDate), "试用") if tmpErr != nil { err = tmpErr return } for _, v := range data { //fmt.Println(v) tryOutMap[v.AdminId] = v.Num } } //试用客户 { //var condition string //var pars []interface{} //condition = ` and start_date >= ? and end_date <= ? and company_status = ? and company_id IN (` + utils.GetOrmInReplace(len(closeIdsArr)) + `)` //pars = append(pars, startDate, endDate, "关闭", closeIdsArr) data, tmpErr := roadshow.GetOverseasGroupResearcherRecordList(startDate.Format(utils.FormatDate), endDate.Format(utils.FormatDate), "关闭") if tmpErr != nil { err = tmpErr return } for _, v := range data { //fmt.Println(v) closemap[v.AdminId] = v.Num } } adminDataMap = OverseasAdminDataMap{ TryOutMap: tryOutMap, FormalMap: formalMap, CloseMap: closemap, StartDate: startDate.Format(utils.FormatDate), EndDate: endDate.Format(utils.FormatDate), } return } // GetOverseasMonthDataV2 月度数据 func GetOverseasMonthDataV2(adminType, dimensionType string, dataNum int) (adminDataMapList []OverseasAdminDataMap, firstDate time.Time, err error) { //三个协程返回 nowMonthFirstDay := utils.GetNowMonthFirstDay() //本月第一天 //nowMonthLastDay := nowMonthFirstDay.AddDate(0, 1, 0).Add(-1 * time.Second) //本月最后一天 chanList := make([]chan OverseasAdminDataMap, 0) for i := 0; i < dataNum; i++ { tmpCh := make(chan OverseasAdminDataMap, 0) chanList = append(chanList, tmpCh) lastMonthFirstDay := nowMonthFirstDay.AddDate(0, -1*i, 0) //上个月第一天 lastMonthLastDay := nowMonthFirstDay.AddDate(0, -1*(i-1), 0).Add(-1 * time.Second) //上个月最后一天 // 第一个开始日期 firstDate = lastMonthFirstDay go getOverseasSectionData(lastMonthFirstDay, lastMonthLastDay, adminType, dimensionType, tmpCh) } adminDataMapList = make([]OverseasAdminDataMap, 0) for _, vChan := range chanList { var monthAdminDataMap OverseasAdminDataMap monthAdminDataMap = <-vChan close(vChan) adminDataMapList = append(adminDataMapList, monthAdminDataMap) } return } // GetOverseasTimeIntervalData 区间数据 func GetOverseasTimeIntervalData(startDate, endDate, adminType, dimensionType string) (adminDataMapList []OverseasAdminDataMap, firstDate time.Time, err error) { //三个协程返回 startDateTimer, _ := time.ParseInLocation(utils.FormatDate, startDate, time.Local) endDateTimer, _ := time.ParseInLocation(utils.FormatDate, endDate, time.Local) endDateTimer = endDateTimer.AddDate(0, 0, 1).Add(-1 * time.Second) //本月最后一天 //最早的一天 firstDate = startDateTimer ch1 := make(chan OverseasAdminDataMap, 0) go getOverseasSectionData(startDateTimer, endDateTimer, adminType, dimensionType, ch1) var adminDataMap OverseasAdminDataMap adminDataMap = <-ch1 close(ch1) adminDataMapList = make([]OverseasAdminDataMap, 0) adminDataMapList = append(adminDataMapList, adminDataMap) return } // GetOverseasWeekData 周度数据 func GetOverseasWeekData(adminType, dimensionType string) (adminDataList []OverseasAdminDataMap, firstDate time.Time, err error) { nowWeekMonday := utils.GetNowWeekMonday() //本周周一 //fmt.Println(nowWeekMonday) nowWeekSunday := nowWeekMonday.AddDate(0, 0, 7).Add(-1 * time.Second) //本周周日 //fmt.Println(nowWeekSunday) //nowWeekMonday = nowWeekMonday.AddDate(0, 0, -30) //上周周一 //nowWeekSunday = nowWeekSunday.AddDate(0, 0, -30) //上周周日 //adminDataMap, err := getSectionData(nowWeekMonday, nowWeekSunday) //if err != nil { // fmt.Println(err) // return //} //fmt.Println(adminDataMap) lastWeekMonday := nowWeekMonday.AddDate(0, 0, -7) //上周周一 //fmt.Println(lastWeekMonday) //最早的一天 firstDate = lastWeekMonday lastWeekSunday := nowWeekSunday.AddDate(0, 0, -7) //上周周日 //fmt.Println(lastWeekSunday) nextWeekMonday := nowWeekMonday.AddDate(0, 0, 7) //下周周一 //fmt.Println(nextWeekMonday) nextWeekSunday := nowWeekSunday.AddDate(0, 0, 7) //下周周日 //fmt.Println(nextWeekSunday) ch1 := make(chan OverseasAdminDataMap, 0) ch2 := make(chan OverseasAdminDataMap, 0) ch3 := make(chan OverseasAdminDataMap, 0) go getOverseasSectionData(lastWeekMonday, lastWeekSunday, adminType, dimensionType, ch1) go getOverseasSectionData(nowWeekMonday, nowWeekSunday, adminType, dimensionType, ch2) go getOverseasSectionData(nextWeekMonday, nextWeekSunday, adminType, dimensionType, ch3) var nowWeekAdminDataMap, lastWeekAdminDataMap, nextWeekAdminDataMap OverseasAdminDataMap lastWeekAdminDataMap = <-ch1 close(ch1) nowWeekAdminDataMap = <-ch2 close(ch2) nextWeekAdminDataMap = <-ch3 close(ch3) adminDataList = make([]OverseasAdminDataMap, 0) adminDataList = append(adminDataList, lastWeekAdminDataMap, nowWeekAdminDataMap, nextWeekAdminDataMap) return } // GetOverseasMonthData 月度数据 func GetOverseasMonthData(adminType, dimensionType string) (adminDataMapList []OverseasAdminDataMap, firstDate time.Time, err error) { //三个协程返回 nowMonthFirstDay := utils.GetNowMonthFirstDay() //本月第一天 nowMonthLastDay := nowMonthFirstDay.AddDate(0, 1, 0).Add(-1 * time.Second) //本月最后一天 lastMonthFirstDay1 := nowMonthFirstDay.AddDate(0, -1, 0) //上个月第一天 lastMonthLastDay1 := lastMonthFirstDay1.AddDate(0, 1, 0).Add(-1 * time.Second) //上个月最后一天 lastMonthFirstDay2 := nowMonthFirstDay.AddDate(0, -2, 0) //上上个月第一天 lastMonthLastDay2 := lastMonthFirstDay2.AddDate(0, 1, 0).Add(-1 * time.Second) //上上个月最后一天 lastMonthFirstDay3 := nowMonthFirstDay.AddDate(0, -3, 0) //上上上个月第一天 lastMonthLastDay3 := lastMonthFirstDay3.AddDate(0, 1, 0).Add(-1 * time.Second) //上上上个月最后一天 //最早的一天 firstDate = lastMonthFirstDay3 ch1 := make(chan OverseasAdminDataMap, 0) ch2 := make(chan OverseasAdminDataMap, 0) ch3 := make(chan OverseasAdminDataMap, 0) ch4 := make(chan OverseasAdminDataMap, 0) go getOverseasSectionData(nowMonthFirstDay, nowMonthLastDay, adminType, dimensionType, ch1) go getOverseasSectionData(lastMonthFirstDay1, lastMonthLastDay1, adminType, dimensionType, ch2) go getOverseasSectionData(lastMonthFirstDay2, lastMonthLastDay2, adminType, dimensionType, ch3) go getOverseasSectionData(lastMonthFirstDay3, lastMonthLastDay3, adminType, dimensionType, ch4) var nowMonthAdminDataMap, lastMonthAdminDataMap1, lastMonthAdminDataMap2, lastMonthAdminDataMap3 OverseasAdminDataMap nowMonthAdminDataMap = <-ch1 close(ch1) lastMonthAdminDataMap1 = <-ch2 close(ch2) lastMonthAdminDataMap2 = <-ch3 close(ch3) lastMonthAdminDataMap3 = <-ch4 close(ch4) adminDataMapList = make([]OverseasAdminDataMap, 0) adminDataMapList = append(adminDataMapList, nowMonthAdminDataMap, lastMonthAdminDataMap1, lastMonthAdminDataMap2, lastMonthAdminDataMap3) return }