1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432 |
- package controllers
- import (
- "hongze/hz_crm_api/models"
- "hongze/hz_crm_api/models/roadshow"
- "hongze/hz_crm_api/models/system"
- "hongze/hz_crm_api/services"
- "hongze/hz_crm_api/services/statistic_report"
- "hongze/hz_crm_api/utils"
- "strconv"
- "strings"
- "time"
- )
- // TodoCompanyReport
- // @Title 销售Todo任务统计统计数据
- // @Description 获取增销售Todo任务统计统计数据接口
- // @Param ProductId query string true "销售类型,ficc销售:1;权益销售:2"
- // @Param DataType query string true "枚举值:week、month、time_interval"
- // @Param StartDate query string true "开始日期,格式:2022-04-06"
- // @Param EndDate query string true "结束日期,格式:2022-04-06"
- // @Success 200 {object} statistic_report.companyTodoReportRecordResp
- // @router /report/seller_company_todo [get]
- func (this *StatisticReportController) TodoCompanyReport() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- productId, _ := this.GetInt("ProductId")
- dataType := this.GetString("DataType")
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- //数据处理
- groupTodoReportRecordList := make([]statistic_report.GroupTodoReportRecord, 0)
- allCompanyTodoReportRecordNum := make([]statistic_report.CompanyTodoReportRecordNum, 0)
- //返回参
- companyTodoReportRecordResp := statistic_report.CompanyTodoReportRecordResp{
- List: groupTodoReportRecordList,
- CompanyTodoReportRecordNumList: allCompanyTodoReportRecordNum,
- }
- groupId := -1
- dataNum := 6 //目前设置管理员可见页面为6周,销售主管和销售组长可见页面为七周
- switch sysUser.RoleTypeCode {
- case utils.ROLE_TYPE_CODE_ADMIN:
- case utils.ROLE_TYPE_CODE_FICC_ADMIN: //ficc管理员
- productId = 1
- case utils.ROLE_TYPE_CODE_RAI_ADMIN: //权益管理员
- productId = 2
- case utils.ROLE_TYPE_CODE_FICC_TEAM, utils.ROLE_TYPE_CODE_FICC_SELLER, utils.ROLE_TYPE_CODE_FICC_GROUP:
- productId = 1
- groupId = sysUser.GroupId
- //dataNum = 7
- case utils.ROLE_TYPE_CODE_RAI_SELLER, utils.ROLE_TYPE_CODE_RAI_GROUP:
- productId = 2
- groupId = sysUser.GroupId
- //dataNum = 7
- default:
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = companyTodoReportRecordResp
- return
- }
- if productId <= 0 {
- br.Msg = "请选择销售类型"
- return
- }
- if productId != 1 && productId != 2 {
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = companyTodoReportRecordResp
- return
- }
- nowWeekMonday := utils.GetNowWeekMonday() //本周周一
- firstDate := nowWeekMonday.AddDate(0, 0, -7) //上周周一
- var group []services.AdminGroup
- groupMap := make(map[int][]*roadshow.Researcher)
- var sellerIds string
- group, groupMap, sellerIds, brMsg, brErrMsg := getTodoCompanySallers(productId, groupId, sysUser, firstDate)
- if brMsg != "" {
- br.Msg = brMsg
- br.ErrMsg = brErrMsg
- return
- }
- if sellerIds == "" {
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = companyTodoReportRecordResp
- return
- }
- sellerIds = strings.Trim(sellerIds, ",")
- sellerIds = "(" + sellerIds + ")"
- var companyReportDataMapList []statistic_report.CompanyTodoReportDataMap
- var err error
- //获取列表
- switch dataType {
- case "week":
- companyReportDataMapList, err = statistic_report.GetCompanyTodoWeekDataByWeekNumV2(productId, nowWeekMonday, sellerIds, dataNum)
- if err != nil {
- br.Msg = "数据异常"
- br.ErrMsg = "数据异常,Err:" + err.Error()
- return
- }
- case "month":
- nowMonthFirstDay := utils.GetNowMonthFirstDay() //本月第一天
- companyReportDataMapList, err = statistic_report.GetCompanyTodoMonthDataByNum(productId, nowMonthFirstDay, sellerIds, dataNum)
- if err != nil {
- br.Msg = "数据异常"
- br.ErrMsg = "数据异常,Err:" + err.Error()
- return
- }
- case "time_interval":
- if startDate == `` || endDate == `` {
- br.Msg = "开始日期或结束日期不能为空"
- br.ErrMsg = "开始日期或结束日期不能为空,Err:" + err.Error()
- return
- }
- companyReportDataMapList, err = statistic_report.GetCompanyTodoTimeIntervalDataByNum(productId, startDate, endDate, sellerIds)
- if err != nil {
- br.Msg = "数据异常"
- br.ErrMsg = "数据异常,Err:" + err.Error()
- return
- }
- default:
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = companyTodoReportRecordResp
- return
- }
- // 统计截止日期小于等于当前时间的未完成的任务数
- doingExpiredDataMapList, doingExpiredIdDataMapList, err := statistic_report.GetDoingTodoExpiredNum(productId, sellerIds)
- if err != nil {
- br.Msg = "数据异常"
- br.ErrMsg = "数据异常,Err:" + err.Error()
- return
- }
- // 统计截止日期小于等于当前时间的已完成的任务数
- finishDataMapList, finishIdDataMapList, err := statistic_report.GetFinishTodoNum(productId, sellerIds)
- if err != nil {
- br.Msg = "数据异常"
- br.ErrMsg = "数据异常,Err:" + err.Error()
- return
- }
- // 进行中且未到截止日期的To Do任务统计的任务数
- doingDataMapList, doingIdDataMapList, err := statistic_report.GetDoingTodoNum(productId, sellerIds)
- if err != nil {
- br.Msg = "数据异常"
- br.ErrMsg = "数据异常,Err:" + err.Error()
- return
- }
- adminCompanyIdsMap, err := statistic_report.GetTryStatusCompanyBySellerIds(productId, sellerIds)
- startDateIndexList := make(map[int]string) //开始时间间隔map
- endDateIndexList := make(map[int]string) //结束时间间隔map
- //客户数汇总
- tmpAllAddMap := make(map[int]int)
- tmpAllApproveMap := make(map[int]int)
- //id集合汇总
- tmpAllDoingExpired := 0 //任务未完成数量(基于分组id)
- tmpAllFinish := 0 //任务已完成数量(基于分组id)
- tmpAllDoing := 0 //任务进行中数量(基于分组id)
- for _, v := range group {
- v.ResearcherList = groupMap[v.GroupId]
- tmpGroupAdminTodoReportRecord := make([]statistic_report.AdminTodoReportRecord, 0)
- tmpGroupCompanyTodoReportRecordNumList := make([]statistic_report.CompanyTodoReportRecordNum, 0)
- //数量统计
- tmpGroupAddMap := make(map[int]int)
- tmpGroupApproveMap := make(map[int]int)
- //数量统计(基于分组id)
- tmpGroupDoingExpiredMap := make(map[int]int)
- tmpGroupFinishMap := make(map[int]int)
- tmpGroupDoingMap := make(map[int]int)
- //id集合(不区分客户状态)
- tmpGroupAddIdSliceMap := make(map[int][]string)
- tmpGroupApproveIdSliceMap := make(map[int][]string)
- //id集合 string类型(不区分客户状态)
- tmpGroupAddIdMap := make(map[int]string)
- tmpGroupApproveIdMap := make(map[int]string)
- //id集合(基于分组id)
- tmpGroupDoingExpiredIdMap := make(map[int]string)
- tmpGroupFinishIdMap := make(map[int]string)
- tmpGroupDoingIdMap := make(map[int]string)
- for _, researcher := range groupMap[v.GroupId] {
- //每个区间的数据
- tmpCompanyTodoReportRecordNumList := make([]statistic_report.CompanyTodoReportRecordNum, 0)
- // 未完成任务统计
- tmpDoingExpiredNum := 0
- tmpDoingExpiredCompanyIds := ""
- {
- if num, ok := doingExpiredDataMapList[researcher.AdminId]; ok {
- tmpDoingExpiredNum = num
- if tmpCompanyIds, ok2 := doingExpiredIdDataMapList[researcher.AdminId]; ok2 {
- tmpDoingExpiredCompanyIds = tmpCompanyIds
- }
- }
- tmpGroupDoingExpiredMap[v.GroupId] += tmpDoingExpiredNum
- tmpAllDoingExpired += tmpDoingExpiredNum
- if tmpDoingExpiredCompanyIds != "" {
- if tmpGroupDoingExpiredIdMap[v.GroupId] != "" {
- tmpGroupDoingExpiredIdMap[v.GroupId] += "," + tmpDoingExpiredCompanyIds
- } else {
- tmpGroupDoingExpiredIdMap[v.GroupId] += tmpDoingExpiredCompanyIds
- }
- }
- }
- // 已完成任务统计
- tmpFinishNum := 0
- tmpFinishCompanyIds := ""
- {
- if finishNum, ok := finishDataMapList[researcher.AdminId]; ok {
- tmpFinishNum = finishNum
- if tmpCompanyIds, ok2 := finishIdDataMapList[researcher.AdminId]; ok2 {
- tmpFinishCompanyIds = tmpCompanyIds
- }
- }
- tmpGroupFinishMap[v.GroupId] += tmpFinishNum
- tmpAllFinish += tmpFinishNum
- if tmpFinishCompanyIds != "" {
- if tmpGroupFinishIdMap[v.GroupId] != "" {
- tmpGroupFinishIdMap[v.GroupId] += "," + tmpFinishCompanyIds
- } else {
- tmpGroupFinishIdMap[v.GroupId] += tmpFinishCompanyIds
- }
- }
- }
- // 进行中任务统计
- tmpDoingNum := 0
- tmpDoingCompanyIds := ""
- {
- if doingNum, ok := doingDataMapList[researcher.AdminId]; ok {
- tmpDoingNum = doingNum
- if tmpCompanyIds, ok2 := doingIdDataMapList[researcher.AdminId]; ok2 {
- tmpDoingCompanyIds = tmpCompanyIds
- }
- }
- tmpGroupDoingMap[v.GroupId] += tmpDoingNum
- tmpAllDoing += tmpDoingNum
- if tmpDoingCompanyIds != "" {
- if tmpGroupDoingIdMap[v.GroupId] != "" {
- tmpGroupDoingIdMap[v.GroupId] += "," + tmpDoingCompanyIds
- } else {
- tmpGroupDoingIdMap[v.GroupId] += tmpDoingCompanyIds
- }
- }
- }
- // 销售相关的试用客户ID
- tmpAdminCompanyIds := ""
- if ids, ok := adminCompanyIdsMap[researcher.AdminId]; ok {
- tmpAdminCompanyIds = ids
- }
- for index, adminData := range companyReportDataMapList {
- startDateIndexList[index] = adminData.StartDate
- endDateIndexList[index] = adminData.EndDate
- var tmpAddNum, tmpApproveNum int
- var tmpAddIdSlice, tmpApproveIdSlice []string
- var tmpAddId, tmpApproveId string
- tmpStat := adminData.Stat
- //试用数据
- if num, ok := tmpStat.AddMap[researcher.AdminId]; ok {
- tmpAddNum = num
- tmpAddIdSlice = append(tmpAddIdSlice, tmpStat.AddIdMap[researcher.AdminId])
- }
- if num, ok := tmpStat.ApproveMap[researcher.AdminId]; ok {
- tmpApproveNum = num
- tmpApproveIdSlice = append(tmpApproveIdSlice, tmpStat.ApproveIdMap[researcher.AdminId])
- }
- tmpAddId = strings.Join(tmpAddIdSlice, ",")
- tmpApproveId = strings.Join(tmpApproveIdSlice, ",")
- tmpAdminRsReportRecordNum := statistic_report.CompanyTodoReportRecordNum{
- AddMap: tmpAddNum,
- AddIdMap: tmpAddId,
- ApproveMap: tmpApproveNum,
- ApproveIdMap: tmpApproveId,
- StartDate: adminData.StartDate,
- EndDate: adminData.EndDate,
- }
- tmpCompanyTodoReportRecordNumList = append(tmpCompanyTodoReportRecordNumList, tmpAdminRsReportRecordNum)
- //组内数据汇总
- if _, ok := tmpGroupAddMap[index]; !ok {
- tmpGroupAddMap[index] = 0
- }
- if _, ok := tmpGroupApproveMap[index]; !ok {
- tmpGroupApproveMap[index] = 0
- }
- tmpGroupAddMap[index] += tmpAddNum
- tmpGroupApproveMap[index] += tmpApproveNum
- //组内数据汇总
- if tmpAddId != "" {
- tmpGroupAddIdSliceMap[index] = append(tmpGroupAddIdSliceMap[index], tmpAddId)
- }
- if tmpApproveId != "" {
- tmpGroupApproveIdSliceMap[index] = append(tmpGroupApproveIdSliceMap[index], tmpApproveId)
- }
- //总数据汇总
- if _, ok := tmpAllAddMap[index]; !ok {
- tmpAllAddMap[index] = 0
- }
- if _, ok := tmpAllApproveMap[index]; !ok {
- tmpAllApproveMap[index] = 0
- }
- tmpAllAddMap[index] += tmpAddNum
- tmpAllApproveMap[index] += tmpApproveNum
- }
- tmpAdminTodoReportRecord := statistic_report.AdminTodoReportRecord{
- Name: researcher.RealName,
- AdminId: researcher.AdminId,
- CompanyTodoReportRecordNumList: tmpCompanyTodoReportRecordNumList,
- DoingExpiredNum: tmpDoingExpiredNum,
- DoingExpiredCompanyIds: tmpDoingExpiredCompanyIds,
- FinishNum: tmpFinishNum,
- FinishCompanyIds: tmpFinishCompanyIds,
- DoingNum: tmpDoingNum,
- DoingCompanyIds: tmpDoingCompanyIds,
- AdminCompanyIds: tmpAdminCompanyIds,
- }
- tmpGroupAdminTodoReportRecord = append(tmpGroupAdminTodoReportRecord, tmpAdminTodoReportRecord)
- }
- for i := 0; i < len(tmpGroupAddMap); i++ {
- //id集合(不区分客户状态)
- tmpGroupAddIdMap[i] = strings.Join(tmpGroupAddIdSliceMap[i], ",")
- tmpGroupApproveIdMap[i] = strings.Join(tmpGroupApproveIdSliceMap[i], ",")
- //tmpAddIdMap := append(AddIdMap)
- tmpGroupCompanyTodoReportRecordNum := statistic_report.CompanyTodoReportRecordNum{
- AddMap: tmpGroupAddMap[i],
- AddIdMap: tmpGroupAddIdMap[i],
- ApproveMap: tmpGroupApproveMap[i],
- ApproveIdMap: tmpGroupApproveIdMap[i],
- StartDate: startDateIndexList[i],
- EndDate: endDateIndexList[i],
- }
- tmpGroupCompanyTodoReportRecordNumList = append(tmpGroupCompanyTodoReportRecordNumList, tmpGroupCompanyTodoReportRecordNum)
- }
- groupTodoReportRecord := statistic_report.GroupTodoReportRecord{
- Item: tmpGroupAdminTodoReportRecord,
- Name: v.GroupName,
- GroupId: v.GroupId,
- CompanyTodoReportRecordNumList: tmpGroupCompanyTodoReportRecordNumList,
- DoingExpiredGroupNum: tmpGroupDoingExpiredMap[v.GroupId],
- DoingExpiredGroupCompanyIds: tmpGroupDoingExpiredIdMap[v.GroupId],
- FinishNum: tmpGroupFinishMap[v.GroupId],
- FinishCompanyIds: tmpGroupFinishIdMap[v.GroupId],
- DoingNum: tmpGroupDoingMap[v.GroupId],
- DoingCompanyIds: tmpGroupDoingIdMap[v.GroupId],
- }
- groupTodoReportRecordList = append(groupTodoReportRecordList, groupTodoReportRecord)
- }
- //总体汇总数据
- for i := 0; i < len(tmpAllApproveMap); i++ {
- tmpGroupCompanyTodoReportRecordNum := statistic_report.CompanyTodoReportRecordNum{
- AddMap: tmpAllAddMap[i],
- //AddIdMap: tmpAllTryOutAddIdMap[i],
- ApproveMap: tmpAllApproveMap[i],
- //ApproveIdMap: tmpAllTryOutApproveIdMap[i],
- StartDate: startDateIndexList[i],
- EndDate: endDateIndexList[i],
- }
- allCompanyTodoReportRecordNum = append(allCompanyTodoReportRecordNum, tmpGroupCompanyTodoReportRecordNum)
- }
- companyTodoReportRecordResp.CompanyTodoReportRecordNumList = allCompanyTodoReportRecordNum
- companyTodoReportRecordResp.List = groupTodoReportRecordList
- companyTodoReportRecordResp.DoingExpiredAllNum = tmpAllDoingExpired
- companyTodoReportRecordResp.FinishAllNum = tmpAllFinish
- companyTodoReportRecordResp.DoingAllNum = tmpAllDoing
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = companyTodoReportRecordResp
- }
- func (this *StatisticReportController) TodoCompanyReportBak20220610174656() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- productId, _ := this.GetInt("ProductId")
- dataType := this.GetString("DataType")
- //startDate := this.GetString("StartDate")
- //endDate := this.GetString("EndDate")
- //数据处理
- groupTodoReportRecordList := make([]statistic_report.GroupTodoReportRecord, 0)
- allCompanyTodoReportRecordNum := make([]statistic_report.CompanyTodoReportRecordNum, 0)
- //返回参
- companyTodoReportRecordResp := statistic_report.CompanyTodoReportRecordResp{
- List: groupTodoReportRecordList,
- CompanyTodoReportRecordNumList: allCompanyTodoReportRecordNum,
- }
- groupId := -1
- weekNum := 6 //目前设置管理员可见页面为6周,销售主管和销售组长可见页面为七周
- switch sysUser.RoleTypeCode {
- case utils.ROLE_TYPE_CODE_ADMIN:
- case utils.ROLE_TYPE_CODE_FICC_ADMIN: //ficc管理员
- productId = 1
- case utils.ROLE_TYPE_CODE_RAI_ADMIN: //权益管理员
- productId = 2
- case utils.ROLE_TYPE_CODE_FICC_TEAM, utils.ROLE_TYPE_CODE_FICC_SELLER, utils.ROLE_TYPE_CODE_FICC_GROUP:
- productId = 1
- groupId = sysUser.GroupId
- weekNum = 7
- case utils.ROLE_TYPE_CODE_RAI_SELLER, utils.ROLE_TYPE_CODE_RAI_GROUP:
- productId = 2
- groupId = sysUser.GroupId
- weekNum = 7
- default:
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = companyTodoReportRecordResp
- return
- }
- if productId <= 0 {
- br.Msg = "请选择销售类型"
- return
- }
- if productId != 1 && productId != 2 {
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = companyTodoReportRecordResp
- return
- }
- nowWeekMonday := utils.GetNowWeekMonday() //本周周一
- firstDate := nowWeekMonday.AddDate(0, 0, -7) //上周周一
- var group []services.AdminGroup
- groupMap := make(map[int][]*roadshow.Researcher)
- var sellerIds string
- group, groupMap, sellerIds, brMsg, brErrMsg := getTodoCompanySallers(productId, groupId, sysUser, firstDate)
- if brMsg != "" {
- br.Msg = brMsg
- br.ErrMsg = brErrMsg
- return
- }
- if sellerIds == "" {
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = companyTodoReportRecordResp
- return
- }
- sellerIds = strings.Trim(sellerIds, ",")
- sellerIds = "(" + sellerIds + ")"
- var companyReportDataMapList []statistic_report.CompanyTodoReportDataMap
- var err error
- //获取列表
- switch dataType {
- case "week":
- companyReportDataMapList, err = statistic_report.GetCompanyTodoWeekDataByWeekNum(productId, nowWeekMonday, sellerIds, weekNum)
- if err != nil {
- br.Msg = "数据异常"
- br.ErrMsg = "数据异常,Err:" + err.Error()
- return
- }
- default:
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = companyTodoReportRecordResp
- return
- }
- // 统计截止日期小于等于当前时间的未完成的任务数
- doingExpiredDataMapList, doingExpiredIdDataMapList, err := statistic_report.GetDoingTodoExpiredNum(productId, sellerIds)
- if err != nil {
- br.Msg = "数据异常"
- br.ErrMsg = "数据异常,Err:" + err.Error()
- return
- }
- // 统计截止日期小于等于当前时间的已完成的任务数
- finishDataMapList, finishIdDataMapList, err := statistic_report.GetFinishTodoNum(productId, sellerIds)
- if err != nil {
- br.Msg = "数据异常"
- br.ErrMsg = "数据异常,Err:" + err.Error()
- return
- }
- adminCompanyIdsMap, err := statistic_report.GetTryStatusCompanyBySellerIds(productId, sellerIds)
- startDateIndexList := make(map[int]string) //开始时间间隔map
- endDateIndexList := make(map[int]string) //结束时间间隔map
- //客户数汇总
- tmpAllTryOutAddMap := make(map[int]int)
- tmpAllTryOutApproveMap := make(map[int]int)
- tmpAllFormalAddMap := make(map[int]int)
- tmpAllFormalApproveMap := make(map[int]int)
- //id集合汇总
- tmpAllTryOutAddIdMap := make(map[int]string)
- tmpAllTryOutApproveIdMap := make(map[int]string)
- tmpAllFormalAddIdMap := make(map[int]string)
- tmpAllFormalApproveIdMap := make(map[int]string)
- tmpAllDoingExpired := 0 //任务未完成数量(基于分组id)
- tmpAllFinish := 0 //任务已完成数量(基于分组id)
- for _, v := range group {
- v.ResearcherList = groupMap[v.GroupId]
- tmpGroupAdminTodoReportRecord := make([]statistic_report.AdminTodoReportRecord, 0)
- tmpGroupCompanyTodoReportRecordNumList := make([]statistic_report.CompanyTodoReportRecordNum, 0)
- //数量统计
- tmpGroupTryOutAddMap := make(map[int]int)
- tmpGroupTryOutApproveMap := make(map[int]int)
- tmpGroupFormalAddMap := make(map[int]int)
- tmpGroupFormalApproveMap := make(map[int]int)
- //数量统计(基于分组id)
- tmpGroupDoingExpiredMap := make(map[int]int)
- tmpGroupFinishMap := make(map[int]int)
- //id集合
- tmpGroupTryOutAddIdSliceMap := make(map[int][]string)
- tmpGroupTryOutApproveIdSliceMap := make(map[int][]string)
- tmpGroupFormalAddIdSliceMap := make(map[int][]string)
- tmpGroupFormalApproveIdSliceMap := make(map[int][]string)
- //id集合(不区分客户状态)
- tmpGroupAddIdSliceMap := make(map[int][]string)
- tmpGroupApproveIdSliceMap := make(map[int][]string)
- //id集合 string类型
- tmpGroupTryOutAddIdMap := make(map[int]string)
- tmpGroupTryOutApproveIdMap := make(map[int]string)
- tmpGroupFormalAddIdMap := make(map[int]string)
- tmpGroupFormalApproveIdMap := make(map[int]string)
- //id集合 string类型(不区分客户状态)
- tmpGroupAddIdMap := make(map[int]string)
- tmpGroupApproveIdMap := make(map[int]string)
- //id集合(基于分组id)
- tmpGroupDoingExpiredIdMap := make(map[int]string)
- tmpGroupFinishIdMap := make(map[int]string)
- for _, researcher := range groupMap[v.GroupId] {
- //每个区间的数据
- tmpCompanyTodoReportRecordNumList := make([]statistic_report.CompanyTodoReportRecordNum, 0)
- tmpDoingExpiredNum := 0
- tmpDoingExpiredCompanyIds := ""
- tmpAdminCompanyIds := ""
- // 未完成任务统计
- if num, ok := doingExpiredDataMapList[researcher.AdminId]; ok {
- tmpDoingExpiredNum = num
- if tmpCompanyIds, ok2 := doingExpiredIdDataMapList[researcher.AdminId]; ok2 {
- tmpDoingExpiredCompanyIds = tmpCompanyIds
- }
- }
- tmpGroupDoingExpiredMap[v.GroupId] += tmpDoingExpiredNum
- tmpAllDoingExpired += tmpDoingExpiredNum
- if tmpDoingExpiredCompanyIds != "" {
- if tmpGroupDoingExpiredIdMap[v.GroupId] != "" {
- tmpGroupDoingExpiredIdMap[v.GroupId] += "," + tmpDoingExpiredCompanyIds
- } else {
- tmpGroupDoingExpiredIdMap[v.GroupId] += tmpDoingExpiredCompanyIds
- }
- }
- // 已完成任务统计
- tmpFinishNum := 0
- tmpFinishCompanyIds := ""
- if finishNum, ok := finishDataMapList[researcher.AdminId]; ok {
- tmpFinishNum = finishNum
- if tmpCompanyIds, ok2 := finishIdDataMapList[researcher.AdminId]; ok2 {
- tmpFinishCompanyIds = tmpCompanyIds
- }
- }
- tmpGroupFinishMap[v.GroupId] += tmpFinishNum
- tmpAllFinish += tmpFinishNum
- if tmpFinishCompanyIds != "" {
- if tmpGroupFinishIdMap[v.GroupId] != "" {
- tmpGroupFinishIdMap[v.GroupId] += "," + tmpFinishCompanyIds
- } else {
- tmpGroupFinishIdMap[v.GroupId] += tmpFinishCompanyIds
- }
- }
- // 销售相关的试用客户ID
- if ids, ok := adminCompanyIdsMap[researcher.AdminId]; ok {
- tmpAdminCompanyIds = ids
- }
- for index, adminData := range companyReportDataMapList {
- startDateIndexList[index] = adminData.StartDate
- endDateIndexList[index] = adminData.EndDate
- var tmpTryOutAddNum, tmpTryOutApproveNum, tmpFormalAddNum, tmpFormalApproveNum int
- //var tmpTryOutAddIds, tmpTryOutApproveIds, tmpFormalAddIds string
- var tmpTryOutAddIdSlice, tmpTryOutApproveIdSlice, tmpFormalAddIdSlice, tmpFormalApproveIdSlice, tmpAddIdSlice, tmpApproveIdSlice []string
- var tmpTryOutAddId, tmpTryOutApproveId, tmpFormalAddId, tmpFormalApproveId, tmpAddId, tmpApproveId string
- tmpTryOutData := adminData.TryOut
- tmpFormalData := adminData.Formal
- //试用数据
- if num, ok := tmpTryOutData.AddMap[researcher.AdminId]; ok {
- tmpTryOutAddNum = num
- tmpTryOutAddIdSlice = append(tmpTryOutAddIdSlice, tmpTryOutData.AddIdMap[researcher.AdminId])
- tmpAddIdSlice = append(tmpAddIdSlice, tmpTryOutData.AddIdMap[researcher.AdminId])
- }
- if num, ok := tmpTryOutData.ApproveMap[researcher.AdminId]; ok {
- tmpTryOutApproveNum = num
- tmpTryOutApproveIdSlice = append(tmpTryOutApproveIdSlice, tmpTryOutData.ApproveIdMap[researcher.AdminId])
- tmpApproveIdSlice = append(tmpApproveIdSlice, tmpTryOutData.ApproveIdMap[researcher.AdminId])
- }
- if num, ok := tmpFormalData.AddMap[researcher.AdminId]; ok {
- tmpFormalAddNum = num
- tmpFormalAddIdSlice = append(tmpFormalAddIdSlice, tmpFormalData.AddIdMap[researcher.AdminId])
- tmpAddIdSlice = append(tmpAddIdSlice, tmpFormalData.AddIdMap[researcher.AdminId])
- }
- if num, ok := tmpFormalData.ApproveMap[researcher.AdminId]; ok {
- tmpFormalApproveNum = num
- tmpFormalApproveIdSlice = append(tmpFormalApproveIdSlice, tmpFormalData.ApproveIdMap[researcher.AdminId])
- tmpApproveIdSlice = append(tmpApproveIdSlice, tmpFormalData.ApproveIdMap[researcher.AdminId])
- }
- tmpTryOutAddId = strings.Join(tmpTryOutAddIdSlice, ",")
- tmpTryOutApproveId = strings.Join(tmpTryOutApproveIdSlice, ",")
- tmpFormalAddId = strings.Join(tmpFormalAddIdSlice, ",")
- tmpAddId = strings.Join(tmpAddIdSlice, ",")
- tmpApproveId = strings.Join(tmpApproveIdSlice, ",")
- tmpAdminRsReportRecordNum := statistic_report.CompanyTodoReportRecordNum{
- TryOutAddMap: tmpTryOutAddNum,
- TryOutAddIdMap: tmpTryOutAddId,
- TryOutApproveMap: tmpTryOutApproveNum,
- TryOutApproveIdMap: tmpTryOutApproveId,
- FormalAddMap: tmpFormalAddNum,
- FormalAddIdMap: tmpFormalAddId,
- FormalApproveMap: tmpFormalApproveNum,
- FormalApproveIdMap: tmpFormalApproveId,
- AddMap: tmpTryOutAddNum + tmpFormalAddNum,
- AddIdMap: tmpAddId,
- ApproveMap: tmpTryOutApproveNum + tmpFormalApproveNum,
- ApproveIdMap: tmpApproveId,
- StartDate: adminData.StartDate,
- EndDate: adminData.EndDate,
- }
- tmpCompanyTodoReportRecordNumList = append(tmpCompanyTodoReportRecordNumList, tmpAdminRsReportRecordNum)
- //组内数据汇总
- if _, ok := tmpGroupTryOutAddMap[index]; !ok {
- tmpGroupTryOutAddMap[index] = 0
- }
- if _, ok := tmpGroupTryOutApproveMap[index]; !ok {
- tmpGroupTryOutApproveMap[index] = 0
- }
- if _, ok := tmpGroupFormalAddMap[index]; !ok {
- tmpGroupFormalAddMap[index] = 0
- }
- if _, ok := tmpGroupFormalApproveMap[index]; !ok {
- tmpGroupFormalApproveMap[index] = 0
- }
- tmpGroupTryOutAddMap[index] += tmpTryOutAddNum
- tmpGroupTryOutApproveMap[index] += tmpTryOutApproveNum
- tmpGroupFormalAddMap[index] += tmpFormalAddNum
- tmpGroupFormalApproveMap[index] += tmpFormalApproveNum
- //组内数据汇总
- if _, ok := tmpGroupTryOutAddIdMap[index]; !ok {
- tmpGroupTryOutAddIdMap[index] = ""
- }
- if _, ok := tmpGroupTryOutApproveIdMap[index]; !ok {
- tmpGroupTryOutApproveIdMap[index] = ""
- }
- if _, ok := tmpGroupFormalAddIdMap[index]; !ok {
- tmpGroupFormalAddIdMap[index] = ""
- }
- if tmpTryOutAddId != "" {
- tmpGroupTryOutAddIdSliceMap[index] = append(tmpGroupTryOutAddIdSliceMap[index], tmpTryOutAddId)
- tmpGroupAddIdSliceMap[index] = append(tmpGroupAddIdSliceMap[index], tmpTryOutAddId)
- }
- if tmpTryOutApproveId != "" {
- tmpGroupTryOutApproveIdSliceMap[index] = append(tmpGroupTryOutApproveIdSliceMap[index], tmpTryOutApproveId)
- tmpGroupApproveIdSliceMap[index] = append(tmpGroupApproveIdSliceMap[index], tmpTryOutApproveId)
- }
- if tmpFormalAddId != "" {
- tmpGroupFormalAddIdSliceMap[index] = append(tmpGroupFormalAddIdSliceMap[index], tmpFormalAddId)
- tmpGroupAddIdSliceMap[index] = append(tmpGroupAddIdSliceMap[index], tmpFormalAddId)
- }
- if tmpFormalApproveId != "" {
- tmpGroupFormalApproveIdSliceMap[index] = append(tmpGroupFormalApproveIdSliceMap[index], tmpFormalApproveId)
- tmpGroupApproveIdSliceMap[index] = append(tmpGroupApproveIdSliceMap[index], tmpFormalApproveId)
- }
- //总数据汇总
- if _, ok := tmpAllTryOutAddMap[index]; !ok {
- tmpAllTryOutAddMap[index] = 0
- }
- if _, ok := tmpAllTryOutApproveMap[index]; !ok {
- tmpAllTryOutApproveMap[index] = 0
- }
- if _, ok := tmpAllFormalAddMap[index]; !ok {
- tmpAllFormalAddMap[index] = 0
- }
- if _, ok := tmpAllFormalApproveMap[index]; !ok {
- tmpAllFormalApproveMap[index] = 0
- }
- tmpAllTryOutAddMap[index] += tmpTryOutAddNum
- tmpAllTryOutApproveMap[index] += tmpTryOutApproveNum
- tmpAllFormalAddMap[index] += tmpFormalAddNum
- tmpAllFormalApproveMap[index] += tmpFormalApproveNum
- }
- tmpAdminTodoReportRecord := statistic_report.AdminTodoReportRecord{
- Name: researcher.RealName,
- AdminId: researcher.AdminId,
- CompanyTodoReportRecordNumList: tmpCompanyTodoReportRecordNumList,
- DoingExpiredNum: tmpDoingExpiredNum,
- DoingExpiredCompanyIds: tmpDoingExpiredCompanyIds,
- FinishNum: tmpFinishNum,
- FinishCompanyIds: tmpFinishCompanyIds,
- AdminCompanyIds: tmpAdminCompanyIds,
- }
- tmpGroupAdminTodoReportRecord = append(tmpGroupAdminTodoReportRecord, tmpAdminTodoReportRecord)
- }
- for i := 0; i < len(tmpGroupFormalAddMap); i++ {
- tmpGroupTryOutAddIdMap[i] = strings.Join(tmpGroupTryOutAddIdSliceMap[i], ",")
- tmpGroupTryOutApproveIdMap[i] = strings.Join(tmpGroupTryOutApproveIdSliceMap[i], ",")
- tmpGroupFormalAddIdMap[i] = strings.Join(tmpGroupFormalAddIdSliceMap[i], ",")
- tmpGroupFormalApproveIdMap[i] = strings.Join(tmpGroupFormalApproveIdSliceMap[i], ",")
- //id集合(不区分客户状态)
- tmpGroupAddIdMap[i] = strings.Join(tmpGroupAddIdSliceMap[i], ",")
- tmpGroupApproveIdMap[i] = strings.Join(tmpGroupApproveIdSliceMap[i], ",")
- //tmpAddIdMap := append(AddIdMap)
- tmpGroupCompanyTodoReportRecordNum := statistic_report.CompanyTodoReportRecordNum{
- TryOutAddMap: tmpGroupTryOutAddMap[i],
- TryOutAddIdMap: tmpGroupTryOutAddIdMap[i],
- TryOutApproveMap: tmpGroupTryOutApproveMap[i],
- TryOutApproveIdMap: tmpGroupTryOutApproveIdMap[i],
- FormalAddMap: tmpGroupFormalAddMap[i],
- FormalAddIdMap: tmpGroupFormalAddIdMap[i],
- FormalApproveMap: tmpGroupFormalApproveMap[i],
- FormalApproveIdMap: tmpGroupFormalApproveIdMap[i],
- AddMap: tmpGroupTryOutAddMap[i] + tmpGroupFormalAddMap[i],
- AddIdMap: tmpGroupAddIdMap[i],
- ApproveMap: tmpGroupTryOutApproveMap[i] + tmpGroupFormalApproveMap[i],
- ApproveIdMap: tmpGroupApproveIdMap[i],
- StartDate: startDateIndexList[i],
- EndDate: endDateIndexList[i],
- }
- tmpGroupCompanyTodoReportRecordNumList = append(tmpGroupCompanyTodoReportRecordNumList, tmpGroupCompanyTodoReportRecordNum)
- }
- groupTodoReportRecord := statistic_report.GroupTodoReportRecord{
- Item: tmpGroupAdminTodoReportRecord,
- Name: v.GroupName,
- GroupId: v.GroupId,
- CompanyTodoReportRecordNumList: tmpGroupCompanyTodoReportRecordNumList,
- DoingExpiredGroupNum: tmpGroupDoingExpiredMap[v.GroupId],
- DoingExpiredGroupCompanyIds: tmpGroupDoingExpiredIdMap[v.GroupId],
- FinishNum: tmpGroupFinishMap[v.GroupId],
- FinishCompanyIds: tmpGroupFinishIdMap[v.GroupId],
- }
- groupTodoReportRecordList = append(groupTodoReportRecordList, groupTodoReportRecord)
- }
- //总体汇总数据
- for i := 0; i < len(tmpAllTryOutApproveMap); i++ {
- tmpGroupCompanyTodoReportRecordNum := statistic_report.CompanyTodoReportRecordNum{
- TryOutAddMap: tmpAllTryOutAddMap[i],
- TryOutAddIdMap: tmpAllTryOutAddIdMap[i],
- TryOutApproveMap: tmpAllTryOutApproveMap[i],
- TryOutApproveIdMap: tmpAllTryOutApproveIdMap[i],
- FormalAddMap: tmpAllFormalAddMap[i],
- FormalAddIdMap: tmpAllFormalAddIdMap[i],
- FormalApproveMap: tmpAllFormalApproveMap[i],
- FormalApproveIdMap: tmpAllFormalApproveIdMap[i],
- AddMap: tmpAllTryOutAddMap[i] + tmpAllFormalAddMap[i],
- //AddIdMap: tmpAllTryOutAddIdMap[i],
- ApproveMap: tmpAllTryOutApproveMap[i] + tmpAllFormalApproveMap[i],
- //ApproveIdMap: tmpAllTryOutApproveIdMap[i],
- StartDate: startDateIndexList[i],
- EndDate: endDateIndexList[i],
- }
- allCompanyTodoReportRecordNum = append(allCompanyTodoReportRecordNum, tmpGroupCompanyTodoReportRecordNum)
- }
- companyTodoReportRecordResp.CompanyTodoReportRecordNumList = allCompanyTodoReportRecordNum
- companyTodoReportRecordResp.List = groupTodoReportRecordList
- companyTodoReportRecordResp.DoingExpiredAllNum = tmpAllDoingExpired
- companyTodoReportRecordResp.FinishAllNum = tmpAllFinish
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = companyTodoReportRecordResp
- }
- func (this *StatisticReportController) TodoCompanyReportBak() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- productId, _ := this.GetInt("ProductId")
- dataType := this.GetString("DataType")
- //startDate := this.GetString("StartDate")
- //endDate := this.GetString("EndDate")
- //数据处理
- groupTodoReportRecordList := make([]statistic_report.GroupTodoReportRecord, 0)
- allCompanyTodoReportRecordNum := make([]statistic_report.CompanyTodoReportRecordNum, 0)
- //返回参
- companyTodoReportRecordResp := statistic_report.CompanyTodoReportRecordResp{
- List: groupTodoReportRecordList,
- CompanyTodoReportRecordNumList: allCompanyTodoReportRecordNum,
- }
- groupId := -1
- switch sysUser.RoleTypeCode {
- case utils.ROLE_TYPE_CODE_ADMIN:
- case utils.ROLE_TYPE_CODE_FICC_ADMIN: //ficc管理员
- productId = 1
- case utils.ROLE_TYPE_CODE_RAI_ADMIN: //权益管理员
- productId = 2
- case utils.ROLE_TYPE_CODE_FICC_TEAM, utils.ROLE_TYPE_CODE_FICC_SELLER, utils.ROLE_TYPE_CODE_FICC_GROUP:
- productId = 1
- groupId = sysUser.GroupId
- case utils.ROLE_TYPE_CODE_RAI_SELLER, utils.ROLE_TYPE_CODE_RAI_GROUP:
- productId = 2
- groupId = sysUser.GroupId
- default:
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = companyTodoReportRecordResp
- return
- }
- if productId <= 0 {
- br.Msg = "请选择销售类型"
- return
- }
- if productId != 1 && productId != 2 {
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = companyTodoReportRecordResp
- return
- }
- nowWeekMonday := utils.GetNowWeekMonday() //本周周一
- firstDate := nowWeekMonday.AddDate(0, 0, -7) //上周周一
- var group []services.AdminGroup
- groupMap := make(map[int][]*roadshow.Researcher)
- var sellerIds string
- group, groupMap, sellerIds, brMsg, brErrMsg := getTodoCompanySallers(productId, groupId, sysUser, firstDate)
- if brMsg != "" {
- br.Msg = brMsg
- br.ErrMsg = brErrMsg
- return
- }
- if sellerIds == "" {
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = companyTodoReportRecordResp
- return
- }
- sellerIds = strings.Trim(sellerIds, ",")
- sellerIds = "(" + sellerIds + ")"
- var companyReportDataMapList []statistic_report.CompanyTodoReportDataMap
- var err error
- //获取列表
- switch dataType {
- case "week":
- companyReportDataMapList, err = statistic_report.GetCompanyTodoWeekData(productId, nowWeekMonday, sellerIds)
- if err != nil {
- br.Msg = "数据异常"
- br.ErrMsg = "数据异常,Err:" + err.Error()
- return
- }
- default:
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = companyTodoReportRecordResp
- return
- }
- // 统计截止日期小于等于当前时间的未完成的任务数
- doingExpiredDataMapList, doingExpiredIdDataMapList, err := statistic_report.GetDoingTodoExpiredNum(productId, sellerIds)
- if err != nil {
- br.Msg = "数据异常"
- br.ErrMsg = "数据异常,Err:" + err.Error()
- return
- }
- // 统计截止日期小于等于当前时间的未完成的任务数
- finishDataMapList, finishIdDataMapList, err := statistic_report.GetFinishTodoNum(productId, sellerIds)
- if err != nil {
- br.Msg = "数据异常"
- br.ErrMsg = "数据异常,Err:" + err.Error()
- return
- }
- adminCompanyIdsMap, err := statistic_report.GetTryStatusCompanyBySellerIds(productId, sellerIds)
- startDateIndexList := make(map[int]string) //开始时间间隔map
- endDateIndexList := make(map[int]string) //结束时间间隔map
- //客户数汇总
- tmpAllTryOutAddMap := make(map[int]int)
- tmpAllTryOutApproveMap := make(map[int]int)
- tmpAllFormalAddMap := make(map[int]int)
- tmpAllFormalApproveMap := make(map[int]int)
- //id集合汇总
- tmpAllTryOutAddIdMap := make(map[int]string)
- tmpAllTryOutApproveIdMap := make(map[int]string)
- tmpAllFormalAddIdMap := make(map[int]string)
- tmpAllFormalApproveIdMap := make(map[int]string)
- tmpAllDoingExpired := 0
- tmpAllFinish := 0
- for _, v := range group {
- v.ResearcherList = groupMap[v.GroupId]
- tmpGroupAdminTodoReportRecord := make([]statistic_report.AdminTodoReportRecord, 0)
- tmpGroupCompanyTodoReportRecordNumList := make([]statistic_report.CompanyTodoReportRecordNum, 0)
- //数量统计
- tmpGroupTryOutAddMap := make(map[int]int)
- tmpGroupTryOutApproveMap := make(map[int]int)
- tmpGroupFormalAddMap := make(map[int]int)
- tmpGroupFormalApproveMap := make(map[int]int)
- tmpGroupDoingExpiredMap := make(map[int]int)
- tmpGroupFinishMap := make(map[int]int)
- //id集合
- tmpGroupTryOutAddIdSliceMap := make(map[int][]string)
- tmpGroupTryOutApproveIdSliceMap := make(map[int][]string)
- tmpGroupFormalAddIdSliceMap := make(map[int][]string)
- tmpGroupFormalApproveIdSliceMap := make(map[int][]string)
- //id集合
- tmpGroupTryOutAddIdMap := make(map[int]string)
- tmpGroupTryOutApproveIdMap := make(map[int]string)
- tmpGroupFormalAddIdMap := make(map[int]string)
- tmpGroupFormalApproveIdMap := make(map[int]string)
- tmpGroupDoingExpiredIdMap := make(map[int]string)
- tmpGroupFinishIdMap := make(map[int]string)
- for _, researcher := range groupMap[v.GroupId] {
- //每个区间的数据
- tmpCompanyTodoReportRecordNumList := make([]statistic_report.CompanyTodoReportRecordNum, 0)
- tmpDoingExpiredNum := 0
- tmpDoingExpiredCompanyIds := ""
- tmpAdminCompanyIds := ""
- // 未完成任务统计
- if num, ok := doingExpiredDataMapList[researcher.AdminId]; ok {
- tmpDoingExpiredNum = num
- if tmpCompanyIds, ok2 := doingExpiredIdDataMapList[researcher.AdminId]; ok2 {
- tmpDoingExpiredCompanyIds = tmpCompanyIds
- }
- }
- tmpGroupDoingExpiredMap[v.GroupId] += tmpDoingExpiredNum
- tmpAllDoingExpired += tmpDoingExpiredNum
- if tmpDoingExpiredCompanyIds != "" {
- if tmpGroupDoingExpiredIdMap[v.GroupId] != "" {
- tmpGroupDoingExpiredIdMap[v.GroupId] += "," + tmpDoingExpiredCompanyIds
- } else {
- tmpGroupDoingExpiredIdMap[v.GroupId] += tmpDoingExpiredCompanyIds
- }
- }
- // 已完成任务统计
- tmpFinishNum := 0
- tmpFinishCompanyIds := ""
- if finishNum, ok := finishDataMapList[researcher.AdminId]; ok {
- tmpFinishNum = finishNum
- if tmpCompanyIds, ok2 := finishIdDataMapList[researcher.AdminId]; ok2 {
- tmpFinishCompanyIds = tmpCompanyIds
- }
- }
- tmpGroupFinishMap[v.GroupId] += tmpFinishNum
- tmpAllFinish += tmpFinishNum
- if tmpFinishCompanyIds != "" {
- if tmpGroupFinishIdMap[v.GroupId] != "" {
- tmpGroupFinishIdMap[v.GroupId] += "," + tmpFinishCompanyIds
- } else {
- tmpGroupFinishIdMap[v.GroupId] += tmpFinishCompanyIds
- }
- }
- // 销售相关的试用客户ID
- if ids, ok := adminCompanyIdsMap[researcher.AdminId]; ok {
- tmpAdminCompanyIds = ids
- }
- for index, adminData := range companyReportDataMapList {
- startDateIndexList[index] = adminData.StartDate
- endDateIndexList[index] = adminData.EndDate
- var tmpTryOutAddNum, tmpTryOutApproveNum, tmpFormalAddNum, tmpFormalApproveNum int
- //var tmpTryOutAddIds, tmpTryOutApproveIds, tmpFormalAddIds string
- var tmpTryOutAddIdSlice, tmpTryOutApproveIdSlice, tmpFormalAddIdSlice, tmpFormalApproveIdSlice []string
- var tmpTryOutAddId, tmpTryOutApproveId, tmpFormalAddId, tmpFormalApproveId string
- tmpTryOutData := adminData.TryOut
- tmpFormalData := adminData.Formal
- //试用数据
- if num, ok := tmpTryOutData.AddMap[researcher.AdminId]; ok {
- tmpTryOutAddNum = num
- tmpTryOutAddIdSlice = append(tmpTryOutAddIdSlice, tmpTryOutData.AddIdMap[researcher.AdminId])
- tmpTryOutAddId = strings.Join(tmpTryOutAddIdSlice, ",")
- }
- if num, ok := tmpTryOutData.ApproveMap[researcher.AdminId]; ok {
- tmpTryOutApproveNum = num
- tmpTryOutApproveIdSlice = append(tmpTryOutApproveIdSlice, tmpTryOutData.ApproveIdMap[researcher.AdminId])
- tmpTryOutApproveId = strings.Join(tmpTryOutApproveIdSlice, ",")
- }
- if num, ok := tmpFormalData.AddMap[researcher.AdminId]; ok {
- tmpFormalAddNum = num
- tmpFormalAddIdSlice = append(tmpFormalAddIdSlice, tmpFormalData.AddIdMap[researcher.AdminId])
- tmpFormalAddId = strings.Join(tmpFormalAddIdSlice, ",")
- }
- if num, ok := tmpFormalData.ApproveMap[researcher.AdminId]; ok {
- tmpFormalApproveNum = num
- tmpFormalApproveIdSlice = append(tmpFormalApproveIdSlice, tmpFormalData.ApproveIdMap[researcher.AdminId])
- tmpFormalApproveId = strings.Join(tmpFormalApproveIdSlice, ",")
- }
- tmpAdminRsReportRecordNum := statistic_report.CompanyTodoReportRecordNum{
- TryOutAddMap: tmpTryOutAddNum,
- TryOutAddIdMap: tmpTryOutAddId,
- TryOutApproveMap: tmpTryOutApproveNum,
- TryOutApproveIdMap: tmpTryOutApproveId,
- FormalAddMap: tmpFormalAddNum,
- FormalAddIdMap: tmpFormalAddId,
- FormalApproveMap: tmpFormalApproveNum,
- FormalApproveIdMap: tmpFormalApproveId,
- StartDate: adminData.StartDate,
- EndDate: adminData.EndDate,
- }
- tmpCompanyTodoReportRecordNumList = append(tmpCompanyTodoReportRecordNumList, tmpAdminRsReportRecordNum)
- //组内数据汇总
- if _, ok := tmpGroupTryOutAddMap[index]; !ok {
- tmpGroupTryOutAddMap[index] = 0
- }
- if _, ok := tmpGroupTryOutApproveMap[index]; !ok {
- tmpGroupTryOutApproveMap[index] = 0
- }
- if _, ok := tmpGroupFormalAddMap[index]; !ok {
- tmpGroupFormalAddMap[index] = 0
- }
- if _, ok := tmpGroupFormalApproveMap[index]; !ok {
- tmpGroupFormalApproveMap[index] = 0
- }
- tmpGroupTryOutAddMap[index] += tmpTryOutAddNum
- tmpGroupTryOutApproveMap[index] += tmpTryOutApproveNum
- tmpGroupFormalAddMap[index] += tmpFormalAddNum
- tmpGroupFormalApproveMap[index] += tmpFormalApproveNum
- //组内数据汇总
- if _, ok := tmpGroupTryOutAddIdMap[index]; !ok {
- tmpGroupTryOutAddIdMap[index] = ""
- }
- if _, ok := tmpGroupTryOutApproveIdMap[index]; !ok {
- tmpGroupTryOutApproveIdMap[index] = ""
- }
- if _, ok := tmpGroupFormalAddIdMap[index]; !ok {
- tmpGroupFormalAddIdMap[index] = ""
- }
- if tmpTryOutAddId != "" {
- tmpGroupTryOutAddIdSliceMap[index] = append(tmpGroupTryOutAddIdSliceMap[index], tmpTryOutAddId)
- }
- if tmpTryOutApproveId != "" {
- tmpGroupTryOutApproveIdSliceMap[index] = append(tmpGroupTryOutApproveIdSliceMap[index], tmpTryOutApproveId)
- }
- if tmpFormalAddId != "" {
- tmpGroupFormalAddIdSliceMap[index] = append(tmpGroupFormalAddIdSliceMap[index], tmpFormalAddId)
- }
- if tmpFormalApproveId != "" {
- tmpGroupFormalApproveIdSliceMap[index] = append(tmpGroupFormalApproveIdSliceMap[index], tmpFormalApproveId)
- }
- //总数据汇总
- if _, ok := tmpAllTryOutAddMap[index]; !ok {
- tmpAllTryOutAddMap[index] = 0
- }
- if _, ok := tmpAllTryOutApproveMap[index]; !ok {
- tmpAllTryOutApproveMap[index] = 0
- }
- if _, ok := tmpAllFormalAddMap[index]; !ok {
- tmpAllFormalAddMap[index] = 0
- }
- if _, ok := tmpAllFormalApproveMap[index]; !ok {
- tmpAllFormalApproveMap[index] = 0
- }
- tmpAllTryOutAddMap[index] += tmpTryOutAddNum
- tmpAllTryOutApproveMap[index] += tmpTryOutApproveNum
- tmpAllFormalAddMap[index] += tmpFormalAddNum
- tmpAllFormalApproveMap[index] += tmpFormalApproveNum
- }
- tmpAdminTodoReportRecord := statistic_report.AdminTodoReportRecord{
- Name: researcher.RealName,
- AdminId: researcher.AdminId,
- CompanyTodoReportRecordNumList: tmpCompanyTodoReportRecordNumList,
- DoingExpiredNum: tmpDoingExpiredNum,
- DoingExpiredCompanyIds: tmpDoingExpiredCompanyIds,
- FinishNum: tmpFinishNum,
- FinishCompanyIds: tmpFinishCompanyIds,
- AdminCompanyIds: tmpAdminCompanyIds,
- }
- tmpGroupAdminTodoReportRecord = append(tmpGroupAdminTodoReportRecord, tmpAdminTodoReportRecord)
- }
- for i := 0; i < len(tmpGroupFormalAddMap); i++ {
- tmpGroupTryOutAddIdMap[i] = strings.Join(tmpGroupTryOutAddIdSliceMap[i], ",")
- tmpGroupTryOutApproveIdMap[i] = strings.Join(tmpGroupTryOutApproveIdSliceMap[i], ",")
- tmpGroupFormalAddIdMap[i] = strings.Join(tmpGroupFormalAddIdSliceMap[i], ",")
- tmpGroupFormalApproveIdMap[i] = strings.Join(tmpGroupFormalApproveIdSliceMap[i], ",")
- tmpGroupCompanyTodoReportRecordNum := statistic_report.CompanyTodoReportRecordNum{
- TryOutAddMap: tmpGroupTryOutAddMap[i],
- TryOutAddIdMap: tmpGroupTryOutAddIdMap[i],
- TryOutApproveMap: tmpGroupTryOutApproveMap[i],
- TryOutApproveIdMap: tmpGroupTryOutApproveIdMap[i],
- FormalAddMap: tmpGroupFormalAddMap[i],
- FormalAddIdMap: tmpGroupFormalAddIdMap[i],
- FormalApproveMap: tmpGroupFormalApproveMap[i],
- FormalApproveIdMap: tmpGroupFormalApproveIdMap[i],
- StartDate: startDateIndexList[i],
- EndDate: endDateIndexList[i],
- }
- tmpGroupCompanyTodoReportRecordNumList = append(tmpGroupCompanyTodoReportRecordNumList, tmpGroupCompanyTodoReportRecordNum)
- }
- groupTodoReportRecord := statistic_report.GroupTodoReportRecord{
- Item: tmpGroupAdminTodoReportRecord,
- Name: v.GroupName,
- GroupId: v.GroupId,
- CompanyTodoReportRecordNumList: tmpGroupCompanyTodoReportRecordNumList,
- DoingExpiredGroupNum: tmpGroupDoingExpiredMap[v.GroupId],
- DoingExpiredGroupCompanyIds: tmpGroupDoingExpiredIdMap[v.GroupId],
- }
- groupTodoReportRecordList = append(groupTodoReportRecordList, groupTodoReportRecord)
- }
- //总体汇总数据
- for i := 0; i < len(tmpAllTryOutApproveMap); i++ {
- tmpGroupCompanyTodoReportRecordNum := statistic_report.CompanyTodoReportRecordNum{
- TryOutAddMap: tmpAllTryOutAddMap[i],
- TryOutAddIdMap: tmpAllTryOutAddIdMap[i],
- TryOutApproveMap: tmpAllTryOutApproveMap[i],
- TryOutApproveIdMap: tmpAllTryOutApproveIdMap[i],
- FormalAddMap: tmpAllFormalAddMap[i],
- FormalAddIdMap: tmpAllFormalAddIdMap[i],
- FormalApproveMap: tmpAllFormalApproveMap[i],
- FormalApproveIdMap: tmpAllFormalApproveIdMap[i],
- StartDate: startDateIndexList[i],
- EndDate: endDateIndexList[i],
- }
- allCompanyTodoReportRecordNum = append(allCompanyTodoReportRecordNum, tmpGroupCompanyTodoReportRecordNum)
- }
- companyTodoReportRecordResp.CompanyTodoReportRecordNumList = allCompanyTodoReportRecordNum
- companyTodoReportRecordResp.List = groupTodoReportRecordList
- companyTodoReportRecordResp.DoingExpiredAllNum = tmpAllDoingExpired
- companyTodoReportRecordResp.FinishAllNum = tmpAllFinish
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = companyTodoReportRecordResp
- }
- // 获取销售to-do统计的销售员
- func getTodoCompanySallers(productId int, groupId int, sysUser *system.Admin, firstDate time.Time) (group []services.AdminGroup, groupMap map[int][]*roadshow.Researcher, sellerIds string, brMsg, brErrMsg string) {
- var groupIdRelationMap map[int]int
- var researcherList []*roadshow.Researcher
- var err error
- groupMap = make(map[int][]*roadshow.Researcher)
- //获取销售人员分组数据
- if productId == 1 { //ficc
- if groupId > 0 { //ficc 只查某个组相关的销售
- findItem := &roadshow.Researcher{
- AdminId: sysUser.AdminId,
- RealName: sysUser.RealName,
- GroupId: sysUser.GroupId,
- GroupName: sysUser.GroupName,
- RoleTypeCode: sysUser.RoleTypeCode,
- }
- if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER { //销售,只查自己的客户
- var findItems []*roadshow.Researcher
- findItems = append(findItems, findItem)
- groupMap[sysUser.GroupId] = findItems
- sellerIds = strconv.Itoa(sysUser.AdminId)
- //处理group
- adminGroup := services.AdminGroup{
- GroupId: sysUser.GroupId,
- GroupName: sysUser.GroupName,
- ResearcherList: findItems,
- }
- group = append(group, adminGroup)
- } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM { //销售组长只查本组员和本人
- roleTypeCode := "('ficc_seller')"
- groupIds := "(" + strconv.Itoa(groupId) + ")"
- researcherList, err = roadshow.GetSellerList(roleTypeCode, groupIds)
- if err != nil {
- brMsg = "获取销售失败!"
- brErrMsg = "获取销售失败!Err:" + err.Error()
- return
- }
- researcherList = append(researcherList, findItem)
- for _, v := range researcherList {
- sellerIds += "," + strconv.Itoa(v.AdminId)
- }
- groupMap[sysUser.GroupId] = researcherList
- //处理group
- adminGroup := services.AdminGroup{
- GroupId: sysUser.GroupId,
- GroupName: sysUser.GroupName,
- ResearcherList: researcherList,
- }
- group = append(group, adminGroup)
- } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP { //如果主管在三级小组里,查找到归属的二级分组
- groupIds := ""
- groupIdsSlice, err := services.GetFiccSystemGroupIdsByGroupId(sysUser.GroupId)
- if err != nil {
- brMsg = "获取销售失败!"
- brErrMsg = "获取销售失败!Err:" + err.Error()
- return
- }
- for _, v := range groupIdsSlice {
- groupIds += "," + strconv.Itoa(v)
- }
- groupIds = strings.Trim(groupIds, ",")
- groupIds = "(" + groupIds + ")"
- roleTypeCode := "('ficc_seller','ficc_team')"
- researcherList, err = roadshow.GetSellerList(roleTypeCode, groupIds)
- if err != nil {
- brMsg = "获取销售失败!"
- brErrMsg = "获取销售失败!Err:" + err.Error()
- return
- }
- researcherList = append(researcherList, findItem)
- for _, v := range researcherList {
- sellerIds += "," + strconv.Itoa(v.AdminId)
- }
- groupMap[sysUser.GroupId] = researcherList
- //处理group
- adminGroup := services.AdminGroup{
- GroupId: sysUser.GroupId,
- GroupName: sysUser.GroupName,
- ResearcherList: researcherList,
- }
- group = append(group, adminGroup)
- }
- } else {
- group, groupIdRelationMap, err = services.GetFiccSystemGroup()
- if err != nil {
- brMsg = "获取信息失败!"
- brErrMsg = "获取分组信息失败!Err:" + err.Error()
- return
- }
- researcherList, err = services.GetFiccSeller(firstDate, groupIdRelationMap)
- for _, v := range researcherList {
- if v.RoleTypeCode == "ficc_admin" {
- findItems := groupMap[1]
- findItems = append(findItems, v)
- groupMap[1] = findItems
- } else {
- if findItems, ok := groupMap[v.GroupId]; ok {
- findItems = append(findItems, v)
- groupMap[v.GroupId] = findItems
- } else {
- findItems = append(findItems, v)
- groupMap[v.GroupId] = findItems
- }
- }
- sellerIds += "," + strconv.Itoa(v.AdminId)
- }
- }
- } else if productId == 2 { //权益
- if groupId > 0 {
- findItem := &roadshow.Researcher{
- AdminId: sysUser.AdminId,
- RealName: sysUser.RealName,
- GroupId: sysUser.GroupId,
- GroupName: sysUser.GroupName,
- RoleTypeCode: sysUser.RoleTypeCode,
- }
- if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER { //销售,只查自己的客户
- var findItems []*roadshow.Researcher
- findItems = append(findItems, findItem)
- groupMap[sysUser.GroupId] = findItems
- sellerIds = strconv.Itoa(sysUser.AdminId)
- //处理group
- adminGroup := services.AdminGroup{
- GroupId: sysUser.GroupId,
- GroupName: sysUser.GroupName,
- ResearcherList: findItems,
- }
- group = append(group, adminGroup)
- } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
- roleTypeCode := "('rai_seller')"
- groupIds := "(" + strconv.Itoa(groupId) + ")"
- researcherList, err = roadshow.GetRaiSellerList(roleTypeCode, groupIds)
- if err != nil {
- brMsg = "获取销售失败!"
- brErrMsg = "获取销售失败!Err:" + err.Error()
- return
- }
- researcherList = append(researcherList, findItem)
- for _, v := range researcherList {
- sellerIds += "," + strconv.Itoa(v.AdminId)
- }
- groupMap[sysUser.GroupId] = researcherList
- //处理group
- adminGroup := services.AdminGroup{
- GroupId: sysUser.GroupId,
- GroupName: sysUser.GroupName,
- ResearcherList: researcherList,
- }
- group = append(group, adminGroup)
- }
- } else {
- group, groupIdRelationMap, err = services.GetRaiSystemGroup()
- if err != nil {
- brMsg = "获取信息失败!"
- brErrMsg = "获取分组信息失败!Err:" + err.Error()
- return
- }
- researcherList, err = services.GetRaiSeller(groupIdRelationMap)
- for _, v := range researcherList {
- if v.RoleTypeCode == "rai_admin" {
- findItems := groupMap[1]
- findItems = append(findItems, v)
- groupMap[1] = findItems
- } else {
- if findItems, ok := groupMap[v.GroupId]; ok {
- findItems = append(findItems, v)
- groupMap[v.GroupId] = findItems
- } else {
- findItems = append(findItems, v)
- groupMap[v.GroupId] = findItems
- }
- }
- sellerIds += "," + strconv.Itoa(v.AdminId)
- }
- }
- }
- return
- }
|