12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718 |
- package roadshow
- import (
- "encoding/json"
- "github.com/rdlucklib/rdluck_tools/paging"
- "hongze/hz_crm_api/models"
- "hongze/hz_crm_api/models/company"
- "hongze/hz_crm_api/models/roadshow"
- "hongze/hz_crm_api/models/system"
- "hongze/hz_crm_api/services"
- roadshowService "hongze/hz_crm_api/services/roadshow"
- "hongze/hz_crm_api/utils"
- "strconv"
- "strings"
- "time"
- )
- // ResearcherReportList
- // @Title 研究员路演统计
- // @Description 研究员路演统计接口
- // @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} roadshow.RsReportRecordResp
- // @router /report/researcher/list [get]
- func (this *CalendarController) ResearcherReportList() {
- 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
- }
- dataType := this.GetString("DataType")
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- var adminDataList []roadshowService.AdminDataMap
- var err error
- //var firstDate time.Time
- //获取列表
- switch dataType {
- case "week":
- adminDataList, _, err = roadshowService.GetWeekData("researcher", "company_status")
- if err != nil {
- br.Msg = "数据异常"
- br.ErrMsg = "数据异常,Err:" + err.Error()
- return
- }
- case "month":
- adminDataList, _, err = roadshowService.GetMonthData("researcher", "company_status")
- 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
- }
- adminDataList, _, err = roadshowService.GetTimeIntervalData(startDate, endDate, "researcher", "company_status")
- if err != nil {
- br.Msg = "数据异常"
- br.ErrMsg = "数据异常,Err:" + err.Error()
- return
- }
- }
- group, err := roadshow.GetResearcherGroup()
- if err != nil {
- br.Msg = "获取信息失败!"
- br.ErrMsg = "获取分组信息失败!Err:" + err.Error()
- return
- }
- researcherList, err := roadshow.GetResearcherV2()
- if err != nil {
- br.Msg = "获取信息失败!"
- br.ErrMsg = "获取分组信息失败!,GetResearcherV2 Err:" + err.Error()
- return
- }
- groupMap := make(map[int][]*roadshow.ResearcherGroup)
- for _, v := range researcherList {
- item := &roadshow.ResearcherGroup{
- GroupId: v.GroupId,
- GroupName: v.GroupName,
- AdminId: v.AdminId,
- RealName: v.RealName,
- RoleTypeCode: v.RoleTypeCode,
- }
- if findItems, ok := groupMap[v.GroupId]; ok {
- findItems = append(findItems, item)
- groupMap[v.GroupId] = findItems
- } else {
- findItems = append(findItems, item)
- groupMap[v.GroupId] = findItems
- }
- //}
- }
- for _, v := range group {
- v.ResearcherList = groupMap[v.GroupId]
- }
- groupReportRecordList := make([]roadshow.GroupReportRecord, 0)
- rsAllReportRecordNumList := make([]roadshow.RsReportRecordNum, 0)
- RsReportRecordResp := roadshow.RsReportRecordResp{
- List: groupReportRecordList,
- RsReportRecordNumList: rsAllReportRecordNumList,
- }
- startDateIndexList := make(map[int]string) //开始时间间隔map
- endDateIndexList := make(map[int]string) //结束时间间隔map
- tmpAllTryOutNumMap := make(map[int]int)
- tmpAllFormalNumMap := make(map[int]int)
- tmpAllMeetingNumMap := make(map[int]int)
- for _, v := range group {
- v.ResearcherList = groupMap[v.GroupId]
- tmpGroupAdminReportRecord := make([]roadshow.AdminReportRecord, 0)
- tmpGroupRsReportRecordNumList := make([]roadshow.RsReportRecordNum, 0)
- tmpGroupTryOutNumMap := make(map[int]int)
- tmpGroupFormalNumMap := make(map[int]int)
- tmpGroupMeetingNumMap := make(map[int]int)
- for _, researcher := range groupMap[v.GroupId] {
- //组内研究员数据
- //每个区间的数据
- tmpAdminRsReportRecordNumList := make([]roadshow.RsReportRecordNum, 0)
- for index, adminData := range adminDataList {
- startDateIndexList[index] = adminData.StartDate
- endDateIndexList[index] = adminData.EndDate
- var tmpTryOutNum, tmpFormalNum, tmpMeetingNum int
- if num, ok := adminData.TryOutMap[researcher.AdminId]; ok {
- tmpTryOutNum = num
- }
- if num, ok := adminData.FormalMap[researcher.AdminId]; ok {
- tmpFormalNum = num
- }
- if num, ok := adminData.MeetingMap[researcher.AdminId]; ok {
- tmpMeetingNum = num
- }
- tmpAdminRsReportRecordNum := roadshow.RsReportRecordNum{
- TryOutNum: tmpTryOutNum,
- FormalNum: tmpFormalNum,
- MeetingNum: tmpMeetingNum,
- StartDate: adminData.StartDate,
- EndDate: adminData.EndDate,
- }
- tmpAdminRsReportRecordNumList = append(tmpAdminRsReportRecordNumList, tmpAdminRsReportRecordNum)
- //组内数据汇总
- if _, ok := tmpGroupTryOutNumMap[index]; !ok {
- tmpGroupTryOutNumMap[index] = 0
- }
- if _, ok := tmpGroupFormalNumMap[index]; !ok {
- tmpGroupFormalNumMap[index] = 0
- }
- if _, ok := tmpGroupMeetingNumMap[index]; !ok {
- tmpGroupMeetingNumMap[index] = 0
- }
- tmpGroupTryOutNumMap[index] += tmpTryOutNum
- tmpGroupFormalNumMap[index] += tmpFormalNum
- tmpGroupMeetingNumMap[index] += tmpMeetingNum
- //总数据汇总
- if _, ok := tmpAllTryOutNumMap[index]; !ok {
- tmpAllTryOutNumMap[index] = 0
- }
- if _, ok := tmpAllFormalNumMap[index]; !ok {
- tmpAllFormalNumMap[index] = 0
- }
- if _, ok := tmpAllMeetingNumMap[index]; !ok {
- tmpAllMeetingNumMap[index] = 0
- }
- tmpAllTryOutNumMap[index] += tmpTryOutNum
- tmpAllFormalNumMap[index] += tmpFormalNum
- tmpAllMeetingNumMap[index] += tmpMeetingNum
- }
- tmpAdminReportRecord := roadshow.AdminReportRecord{
- Name: researcher.RealName,
- AdminId: researcher.AdminId,
- RsReportRecordNumList: tmpAdminRsReportRecordNumList,
- }
- tmpGroupAdminReportRecord = append(tmpGroupAdminReportRecord, tmpAdminReportRecord)
- }
- for i := 0; i < len(tmpGroupMeetingNumMap); i++ {
- tmpGroupRsReportRecordNum := roadshow.RsReportRecordNum{
- TryOutNum: tmpGroupTryOutNumMap[i],
- FormalNum: tmpGroupFormalNumMap[i],
- MeetingNum: tmpGroupMeetingNumMap[i],
- StartDate: startDateIndexList[i],
- EndDate: endDateIndexList[i],
- }
- tmpGroupRsReportRecordNumList = append(tmpGroupRsReportRecordNumList, tmpGroupRsReportRecordNum)
- }
- groupReportRecord := roadshow.GroupReportRecord{
- Item: tmpGroupAdminReportRecord,
- Name: v.GroupName,
- RsReportRecordNumList: tmpGroupRsReportRecordNumList,
- }
- RsReportRecordResp.List = append(RsReportRecordResp.List, groupReportRecord)
- }
- //总体汇总数据
- for i := 0; i < len(tmpAllFormalNumMap); i++ {
- tmpGroupRsReportRecordNum := roadshow.RsReportRecordNum{
- TryOutNum: tmpAllTryOutNumMap[i],
- FormalNum: tmpAllFormalNumMap[i],
- MeetingNum: tmpAllMeetingNumMap[i],
- StartDate: startDateIndexList[i],
- EndDate: endDateIndexList[i],
- }
- rsAllReportRecordNumList = append(rsAllReportRecordNumList, tmpGroupRsReportRecordNum)
- }
- RsReportRecordResp.RsReportRecordNumList = rsAllReportRecordNumList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = RsReportRecordResp
- return
- }
- // SellerReportList
- // @Title 销售路演统计
- // @Description 销售路演统计接口
- // @Param DataType query string true "枚举值:week、month、time_interval、online、offline"
- // @Param DimensionType query string true "维度枚举值:company_status、roadshow_type"
- // @Param StartDate query string true "开始日期,格式:2022-04-06"
- // @Param EndDate query string true "结束日期,格式:2022-04-06"
- // @Success 200 {object} roadshow.RsReportRecordResp
- // @router /report/seller/list [get]
- func (this *CalendarController) SellerReportList() {
- 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
- }
- dataType := this.GetString("DataType")
- dimensionType := this.GetString("DimensionType")
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- if dimensionType == "" {
- dimensionType = "company_status"
- }
- var adminDataList []roadshowService.AdminDataMap
- var err error
- var firstDate time.Time
- //获取列表
- switch dataType {
- case "week":
- adminDataList, firstDate, err = roadshowService.GetWeekDataV2("seller", dimensionType, 6)
- if err != nil {
- br.Msg = "数据异常"
- br.ErrMsg = "数据异常,Err:" + err.Error()
- return
- }
- case "month":
- adminDataList, firstDate, err = roadshowService.GetMonthDataV2("seller", dimensionType, 6)
- 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
- }
- adminDataList, firstDate, err = roadshowService.GetTimeIntervalData(startDate, endDate, "seller", dimensionType)
- if err != nil {
- br.Msg = "数据异常"
- br.ErrMsg = "数据异常,Err:" + err.Error()
- return
- }
- }
- group, groupIdRelationMap, err := services.GetFiccSystemGroup()
- if err != nil {
- br.Msg = "获取信息失败!"
- br.ErrMsg = "获取分组信息失败!Err:" + err.Error()
- return
- }
- researcherList, err := services.GetFiccSeller(firstDate, groupIdRelationMap)
- groupMap := make(map[int][]*roadshow.Researcher)
- 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
- }
- }
- }
- groupReportRecordList := make([]roadshow.GroupReportRecord, 0)
- rsAllReportRecordNumList := make([]roadshow.RsReportRecordNum, 0)
- RsReportRecordResp := roadshow.RsReportRecordResp{
- List: groupReportRecordList,
- RsReportRecordNumList: rsAllReportRecordNumList,
- }
- startDateIndexList := make(map[int]string) //开始时间间隔map
- endDateIndexList := make(map[int]string) //结束时间间隔map
- tmpAllTryOutNumMap := make(map[int]int)
- tmpAllFormalNumMap := make(map[int]int)
- tmpAllMeetingNumMap := make(map[int]int)
- tmpAllOnlineNumMap := make(map[int]int)
- tmpAllOfflineNumMap := make(map[int]int)
- for _, v := range group {
- v.ResearcherList = groupMap[v.GroupId]
- tmpGroupAdminReportRecord := make([]roadshow.AdminReportRecord, 0)
- tmpGroupRsReportRecordNumList := make([]roadshow.RsReportRecordNum, 0)
- tmpGroupTryOutNumMap := make(map[int]int)
- tmpGroupFormalNumMap := make(map[int]int)
- tmpGroupMeetingNumMap := make(map[int]int)
- tmpGroupOnlineNumMap := make(map[int]int)
- tmpGroupOfflineNumMap := make(map[int]int)
- for _, researcher := range groupMap[v.GroupId] {
- //组内研究员数据
- //每个区间的数据
- tmpAdminRsReportRecordNumList := make([]roadshow.RsReportRecordNum, 0)
- for index, adminData := range adminDataList {
- startDateIndexList[index] = adminData.StartDate
- endDateIndexList[index] = adminData.EndDate
- var tmpTryOutNum, tmpFormalNum, tmpMeetingNum, tmpOnlineNum, tmpOfflineNum int
- if num, ok := adminData.TryOutMap[researcher.AdminId]; ok {
- tmpTryOutNum = num
- }
- if num, ok := adminData.FormalMap[researcher.AdminId]; ok {
- tmpFormalNum = num
- }
- if num, ok := adminData.MeetingMap[researcher.AdminId]; ok {
- tmpMeetingNum = num
- }
- if num, ok := adminData.OnlineMap[researcher.AdminId]; ok {
- tmpOnlineNum = num
- }
- if num, ok := adminData.OfflineMap[researcher.AdminId]; ok {
- tmpOfflineNum = num
- }
- tmpAdminRsReportRecordNum := roadshow.RsReportRecordNum{
- TryOutNum: tmpTryOutNum,
- FormalNum: tmpFormalNum,
- MeetingNum: tmpMeetingNum,
- OnlineNum: tmpOnlineNum,
- OfflineNum: tmpOfflineNum,
- StartDate: adminData.StartDate,
- EndDate: adminData.EndDate,
- }
- tmpAdminRsReportRecordNumList = append(tmpAdminRsReportRecordNumList, tmpAdminRsReportRecordNum)
- //组内数据汇总
- if _, ok := tmpGroupTryOutNumMap[index]; !ok {
- tmpGroupTryOutNumMap[index] = 0
- }
- if _, ok := tmpGroupFormalNumMap[index]; !ok {
- tmpGroupFormalNumMap[index] = 0
- }
- if _, ok := tmpGroupMeetingNumMap[index]; !ok {
- tmpGroupMeetingNumMap[index] = 0
- }
- if _, ok := tmpGroupOnlineNumMap[index]; !ok {
- tmpGroupOnlineNumMap[index] = 0
- }
- if _, ok := tmpGroupOfflineNumMap[index]; !ok {
- tmpGroupOfflineNumMap[index] = 0
- }
- tmpGroupTryOutNumMap[index] += tmpTryOutNum
- tmpGroupFormalNumMap[index] += tmpFormalNum
- tmpGroupMeetingNumMap[index] += tmpMeetingNum
- tmpGroupOnlineNumMap[index] += tmpOnlineNum
- tmpGroupOfflineNumMap[index] += tmpOfflineNum
- //总数据汇总
- if _, ok := tmpAllTryOutNumMap[index]; !ok {
- tmpAllTryOutNumMap[index] = 0
- }
- if _, ok := tmpAllFormalNumMap[index]; !ok {
- tmpAllFormalNumMap[index] = 0
- }
- if _, ok := tmpAllMeetingNumMap[index]; !ok {
- tmpAllMeetingNumMap[index] = 0
- }
- if _, ok := tmpAllOnlineNumMap[index]; !ok {
- tmpAllOnlineNumMap[index] = 0
- }
- if _, ok := tmpAllOfflineNumMap[index]; !ok {
- tmpAllOfflineNumMap[index] = 0
- }
- tmpAllTryOutNumMap[index] += tmpTryOutNum
- tmpAllFormalNumMap[index] += tmpFormalNum
- tmpAllMeetingNumMap[index] += tmpMeetingNum
- tmpAllOnlineNumMap[index] += tmpOnlineNum
- tmpAllOfflineNumMap[index] += tmpOfflineNum
- }
- tmpAdminReportRecord := roadshow.AdminReportRecord{
- Name: researcher.RealName,
- AdminId: researcher.AdminId,
- RsReportRecordNumList: tmpAdminRsReportRecordNumList,
- }
- tmpGroupAdminReportRecord = append(tmpGroupAdminReportRecord, tmpAdminReportRecord)
- }
- for i := 0; i < len(tmpGroupMeetingNumMap); i++ {
- tmpGroupRsReportRecordNum := roadshow.RsReportRecordNum{
- TryOutNum: tmpGroupTryOutNumMap[i],
- FormalNum: tmpGroupFormalNumMap[i],
- MeetingNum: tmpGroupMeetingNumMap[i],
- OnlineNum: tmpGroupOnlineNumMap[i],
- OfflineNum: tmpGroupOfflineNumMap[i],
- StartDate: startDateIndexList[i],
- EndDate: endDateIndexList[i],
- }
- tmpGroupRsReportRecordNumList = append(tmpGroupRsReportRecordNumList, tmpGroupRsReportRecordNum)
- }
- groupReportRecord := roadshow.GroupReportRecord{
- Item: tmpGroupAdminReportRecord,
- Name: v.GroupName,
- GruopId: v.GroupId,
- RsReportRecordNumList: tmpGroupRsReportRecordNumList,
- }
- groupReportRecordList = append(groupReportRecordList, groupReportRecord)
- }
- //总体汇总数据
- for i := 0; i < len(tmpAllFormalNumMap); i++ {
- tmpGroupRsReportRecordNum := roadshow.RsReportRecordNum{
- TryOutNum: tmpAllTryOutNumMap[i],
- FormalNum: tmpAllFormalNumMap[i],
- MeetingNum: tmpAllMeetingNumMap[i],
- OnlineNum: tmpAllOnlineNumMap[i],
- OfflineNum: tmpAllOfflineNumMap[i],
- StartDate: startDateIndexList[i],
- EndDate: endDateIndexList[i],
- }
- rsAllReportRecordNumList = append(rsAllReportRecordNumList, tmpGroupRsReportRecordNum)
- }
- RsReportRecordResp.RsReportRecordNumList = rsAllReportRecordNumList
- //tmpList := groupReportRecordList
- //因为RoleTypeCode不一样,所以需要重新从数据库取数据
- //adminInfo, _ := system.GetSysAdminById(sysUser.AdminId)
- //adminGroupId := adminInfo.GroupId
- //if tmpGroupId, ok := groupIdRelationMap[adminGroupId]; ok {
- // adminGroupId = tmpGroupId
- //}
- //switch adminInfo.RoleTypeCode {
- //case utils.ROLE_TYPE_CODE_FICC_GROUP, utils.ROLE_TYPE_CODE_FICC_TEAM:
- // for index, v := range tmpList {
- // //如果不是同一个分组,那么就移除该分组下的人员数据
- // if v.GruopId != adminGroupId {
- // tmpList[index].Item = make([]roadshow.AdminReportRecord, 0)
- // }
- // }
- // RsReportRecordResp.List = tmpList
- //case utils.ROLE_TYPE_CODE_FICC_ADMIN, utils.ROLE_TYPE_CODE_ADMIN:
- // //管理员、超管看全部数据
- // RsReportRecordResp.List = groupReportRecordList
- //}
- // 20230529-有权限查看该页面的用户权限同admin
- RsReportRecordResp.List = groupReportRecordList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = RsReportRecordResp
- return
- }
- // ReportCalendarList
- // @Title 路演详情列表
- // @Description 路演详情列表接口
- // @Param AdminType query string true "枚举值:researcher、seller、 special:专项路演"
- // @Param DataType query string true "枚举值:try_out、formal、meeting、online、offline"
- // @Param AdminId query int true "用户id"
- // @Param StartDate query string true "开始日期,格式:2022-04-06"
- // @Param EndDate query string true "结束日期,格式:2022-04-06"
- // @Success 200 {object} []roadshow.RsReportRecordList
- // @router /report/calendar/list [get]
- func (this *CalendarController) ReportCalendarList() {
- 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
- }
- adminType := this.GetString("AdminType")
- dataType := this.GetString("DataType")
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- adminId, _ := this.GetInt("AdminId")
- if adminId <= 0 {
- br.Msg = "请传入对应的人员"
- return
- }
- //正式客户
- var condition string
- var pars []interface{}
- condition = ` and a.start_date >= ? and a.end_date <= ? `
- pars = append(pars, startDate, endDate)
- //选择的人员类型(发起人还是被发起人)
- if adminType == "seller" {
- condition += ` and a.seller_id = ? `
- } else if adminType == "special" {
- condition += ` and a.seller_id = ? `
- detail, err := company.GetConfigDetailByCode("choice_researcher_adminid")
- if err != nil {
- br.Msg = "获取研究员信息失败!"
- br.ErrMsg = "选择研究员失败,Err:" + err.Error()
- return
- }
- condition += ` and a.researcher_id IN (` + detail.ConfigValue + `) `
- } else {
- condition += ` and a.researcher_id = ? `
- }
- pars = append(pars, adminId)
- //获取列表
- switch dataType {
- case "try_out":
- condition += ` and a.company_status = ? `
- pars = append(pars, "试用")
- case "formal":
- condition += ` and a.company_status = ? `
- pars = append(pars, "正式")
- case "meeting":
- condition += ` and a.activity_type = ? `
- pars = append(pars, "公开会议")
- case "online":
- condition += ` and a.roadshow_type = ? `
- pars = append(pars, "线上")
- case "offline":
- condition += ` and a.roadshow_type = ? `
- pars = append(pars, "线下")
- default:
- br.Msg = "请传入类型"
- br.ErrMsg = "请传入类型DataType"
- return
- }
- list, err := roadshow.GetRsReportRecordList(condition, pars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,ERR:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = list
- return
- }
- // ChoiceResearcher
- // @Title 选择的研究员
- // @Description 选择的研究员接口
- // @Param AdminIds query string true "研究员ID ,多个用 , 隔开"
- // @Success 200 操作成功
- // @router /report/choice/researcher [post]
- func (this *CalendarController) ChoiceResearcher() {
- 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
- }
- var req roadshow.ResearcherIds
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.AdminIds == "" {
- req.AdminIds = "0"
- }
- adminIdArr := strings.Split(req.AdminIds, ",")
- for _, v := range adminIdArr {
- _, err := strconv.Atoi(v)
- if err != nil {
- br.Msg = "选择研究员失败!"
- br.ErrMsg = "选择研究员失败,Err:" + err.Error()
- return
- }
- }
- err = company.CrmConfigUpdate(req.AdminIds, "choice_researcher_adminid")
- if err != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "操作失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- return
- }
- // AdminList
- // @Title 选择的研究员列表
- // @Description 获取选择的研究员列表
- // @Success 200 {object} roadshow.Researcher
- // @Success 200 操作成功
- // @router /report/admin/list [get]
- func (this *CalendarController) AdminList() {
- 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
- }
- detail, err := company.GetConfigDetailByCode("choice_researcher_adminid")
- if err != nil {
- br.Msg = "获取研究员信息失败!"
- br.ErrMsg = "选择研究员失败,Err:" + err.Error()
- return
- }
- list, err := roadshow.GetChoiceResearcher(detail.ConfigValue)
- if err != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "操作失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- br.Data = list
- return
- }
- // SellerReportList
- // @Title 专项路演统计
- // @Description 专项路演统计接口
- // @Success 200 {object} roadshow.RsReportRecordResp
- // @router /report/special/list [get]
- func (this *CalendarController) SpecialReportList() {
- 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
- }
- dimensionType := this.GetString("DimensionType")
- if dimensionType == "" {
- dimensionType = "seller_special"
- }
- var adminDataList []roadshowService.AdminDataMap
- var err error
- var firstDate time.Time
- //获取列表
- adminDataList, firstDate, err = roadshowService.GetWeekData("seller", dimensionType)
- if err != nil {
- br.Msg = "数据异常"
- br.ErrMsg = "数据异常,Err:" + err.Error()
- return
- }
- var haveData bool
- detail, err := company.GetConfigDetailByCode("choice_researcher_adminid")
- if err != nil {
- br.Msg = "获取信息失败!"
- br.ErrMsg = "获取选择研究员信息失败,Err:" + err.Error()
- return
- }
- adminMap := make(map[int]int)
- adminIdArr := strings.Split(detail.ConfigValue, ",")
- for _, v := range adminIdArr {
- adminId, err := strconv.Atoi(v)
- if err != nil {
- br.Msg = "获取信息失败!"
- br.ErrMsg = "获取选择研究员信息失败,Err:" + err.Error()
- return
- }
- adminMap[adminId] = adminId
- }
- group, groupIdRelationMap, err := services.GetFiccSystemGroup()
- if err != nil {
- br.Msg = "获取信息失败!"
- br.ErrMsg = "获取分组信息失败!Err:" + err.Error()
- return
- }
- researcherList, err := services.GetFiccSeller(firstDate, groupIdRelationMap)
- groupMap := make(map[int][]*roadshow.Researcher)
- 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
- }
- //}
- }
- groupReportRecordList := make([]roadshow.GroupReportRecord, 0)
- rsAllReportRecordNumList := make([]roadshow.RsReportRecordNum, 0)
- RsReportRecordResp := roadshow.RsReportRecordResp{
- List: groupReportRecordList,
- RsReportRecordNumList: rsAllReportRecordNumList,
- }
- startDateIndexList := make(map[int]string) //开始时间间隔map
- endDateIndexList := make(map[int]string) //结束时间间隔map
- tmpAllTryOutNumMap := make(map[int]int)
- tmpAllFormalNumMap := make(map[int]int)
- tmpAllMeetingNumMap := make(map[int]int)
- tmpAllOnlineNumMap := make(map[int]int)
- tmpAllOfflineNumMap := make(map[int]int)
- for _, v := range group {
- v.ResearcherList = groupMap[v.GroupId]
- tmpGroupAdminReportRecord := make([]roadshow.AdminReportRecord, 0)
- tmpGroupRsReportRecordNumList := make([]roadshow.RsReportRecordNum, 0)
- tmpGroupTryOutNumMap := make(map[int]int)
- tmpGroupFormalNumMap := make(map[int]int)
- tmpGroupMeetingNumMap := make(map[int]int)
- tmpGroupOnlineNumMap := make(map[int]int)
- tmpGroupOfflineNumMap := make(map[int]int)
- for _, researcher := range groupMap[v.GroupId] {
- //组内研究员数据
- var isLook bool
- //如果是管理员或者本组的可以查看详情
- if sysUser.GroupId == v.GroupId || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- isLook = true
- }
- //每个区间的数据
- tmpAdminRsReportRecordNumList := make([]roadshow.RsReportRecordNum, 0)
- var isAppend bool
- for index, adminData := range adminDataList {
- startDateIndexList[index] = adminData.StartDate
- endDateIndexList[index] = adminData.EndDate
- var tmpTryOutNum, tmpFormalNum, tmpMeetingNum, tmpOnlineNum, tmpOfflineNum int
- if num, ok := adminData.TryOutMap[researcher.AdminId]; ok {
- tmpTryOutNum = num
- }
- if num, ok := adminData.FormalMap[researcher.AdminId]; ok {
- tmpFormalNum = num
- }
- if num, ok := adminData.MeetingMap[researcher.AdminId]; ok {
- tmpMeetingNum = num
- }
- if num, ok := adminData.OnlineMap[researcher.AdminId]; ok {
- tmpOnlineNum = num
- }
- if num, ok := adminData.OfflineMap[researcher.AdminId]; ok {
- tmpOfflineNum = num
- }
- tmpAdminRsReportRecordNum := roadshow.RsReportRecordNum{
- TryOutNum: tmpTryOutNum,
- FormalNum: tmpFormalNum,
- MeetingNum: tmpMeetingNum,
- OnlineNum: tmpOnlineNum,
- OfflineNum: tmpOfflineNum,
- StartDate: adminData.StartDate,
- EndDate: adminData.EndDate,
- IsLook: isLook,
- }
- if tmpTryOutNum > 0 || tmpFormalNum > 0 || tmpMeetingNum > 0 || tmpOnlineNum > 0 || tmpOfflineNum > 0 {
- isAppend = true
- haveData = true
- }
- tmpAdminRsReportRecordNumList = append(tmpAdminRsReportRecordNumList, tmpAdminRsReportRecordNum)
- //组内数据汇总
- if _, ok := tmpGroupTryOutNumMap[index]; !ok {
- tmpGroupTryOutNumMap[index] = 0
- }
- if _, ok := tmpGroupFormalNumMap[index]; !ok {
- tmpGroupFormalNumMap[index] = 0
- }
- if _, ok := tmpGroupMeetingNumMap[index]; !ok {
- tmpGroupMeetingNumMap[index] = 0
- }
- if _, ok := tmpGroupOnlineNumMap[index]; !ok {
- tmpGroupOnlineNumMap[index] = 0
- }
- if _, ok := tmpGroupOfflineNumMap[index]; !ok {
- tmpGroupOfflineNumMap[index] = 0
- }
- tmpGroupTryOutNumMap[index] += tmpTryOutNum
- tmpGroupFormalNumMap[index] += tmpFormalNum
- tmpGroupMeetingNumMap[index] += tmpMeetingNum
- tmpGroupOnlineNumMap[index] += tmpOnlineNum
- tmpGroupOfflineNumMap[index] += tmpOfflineNum
- //总数据汇总
- if _, ok := tmpAllTryOutNumMap[index]; !ok {
- tmpAllTryOutNumMap[index] = 0
- }
- if _, ok := tmpAllFormalNumMap[index]; !ok {
- tmpAllFormalNumMap[index] = 0
- }
- if _, ok := tmpAllMeetingNumMap[index]; !ok {
- tmpAllMeetingNumMap[index] = 0
- }
- if _, ok := tmpAllOnlineNumMap[index]; !ok {
- tmpAllOnlineNumMap[index] = 0
- }
- if _, ok := tmpAllOfflineNumMap[index]; !ok {
- tmpAllOfflineNumMap[index] = 0
- }
- tmpAllTryOutNumMap[index] += tmpTryOutNum
- tmpAllFormalNumMap[index] += tmpFormalNum
- tmpAllMeetingNumMap[index] += tmpMeetingNum
- tmpAllOnlineNumMap[index] += tmpOnlineNum
- tmpAllOfflineNumMap[index] += tmpOfflineNum
- }
- tmpAdminReportRecord := roadshow.AdminReportRecord{
- Name: researcher.RealName,
- AdminId: researcher.AdminId,
- RsReportRecordNumList: tmpAdminRsReportRecordNumList,
- }
- if isAppend {
- tmpGroupAdminReportRecord = append(tmpGroupAdminReportRecord, tmpAdminReportRecord)
- }
- }
- for i := 0; i < len(tmpGroupMeetingNumMap); i++ {
- tmpGroupRsReportRecordNum := roadshow.RsReportRecordNum{
- TryOutNum: tmpGroupTryOutNumMap[i],
- FormalNum: tmpGroupFormalNumMap[i],
- MeetingNum: tmpGroupMeetingNumMap[i],
- OnlineNum: tmpGroupOnlineNumMap[i],
- OfflineNum: tmpGroupOfflineNumMap[i],
- StartDate: startDateIndexList[i],
- EndDate: endDateIndexList[i],
- }
- tmpGroupRsReportRecordNumList = append(tmpGroupRsReportRecordNumList, tmpGroupRsReportRecordNum)
- }
- groupReportRecord := roadshow.GroupReportRecord{
- Item: tmpGroupAdminReportRecord,
- Name: v.GroupName,
- GruopId: v.GroupId,
- RsReportRecordNumList: tmpGroupRsReportRecordNumList,
- }
- if len(tmpGroupAdminReportRecord) > 0 {
- groupReportRecordList = append(groupReportRecordList, groupReportRecord)
- }
- }
- //总体汇总数据
- for i := 0; i < len(tmpAllFormalNumMap); i++ {
- tmpGroupRsReportRecordNum := roadshow.RsReportRecordNum{
- TryOutNum: tmpAllTryOutNumMap[i],
- FormalNum: tmpAllFormalNumMap[i],
- MeetingNum: tmpAllMeetingNumMap[i],
- OnlineNum: tmpAllOnlineNumMap[i],
- OfflineNum: tmpAllOfflineNumMap[i],
- StartDate: startDateIndexList[i],
- EndDate: endDateIndexList[i],
- }
- rsAllReportRecordNumList = append(rsAllReportRecordNumList, tmpGroupRsReportRecordNum)
- }
- RsReportRecordResp.RsReportRecordNumList = rsAllReportRecordNumList
- tmpList := groupReportRecordList
- //因为RoleTypeCode不一样,所以需要重新从数据库取数据
- adminInfo, _ := system.GetSysAdminById(sysUser.AdminId)
- adminGroupId := adminInfo.GroupId
- if tmpGroupId, ok := groupIdRelationMap[adminGroupId]; ok {
- adminGroupId = tmpGroupId
- }
- switch adminInfo.RoleTypeCode {
- case utils.ROLE_TYPE_CODE_FICC_GROUP, utils.ROLE_TYPE_CODE_FICC_TEAM:
- for index, v := range tmpList {
- //如果不是同一个分组,那么就移除该分组下的人员数据
- if v.GruopId != adminGroupId {
- tmpList[index].Item = make([]roadshow.AdminReportRecord, 0)
- }
- }
- RsReportRecordResp.List = tmpList
- case utils.ROLE_TYPE_CODE_FICC_ADMIN, utils.ROLE_TYPE_CODE_ADMIN:
- //管理员、超管看全部数据
- RsReportRecordResp.List = groupReportRecordList
- }
- //判断是否有数据如果没有,处理数据为空
- if !haveData {
- RsReportRecordResp = roadshow.RsReportRecordResp{
- List: make([]roadshow.GroupReportRecord, 0),
- RsReportRecordNumList: make([]roadshow.RsReportRecordNum, 0),
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = RsReportRecordResp
- return
- }
- // ResearcherReportList
- // @Title 研究员出差表
- // @Description 研究员出差表接口
- // @Param AdminId query int true "研究员id"
- // @Param WeekQuery query int false "周查询: 0-本期(本周及下周); 1-前两周; 2-后两周"
- // @Param BaseQueryDate query string false "周查询时的开始日期"
- // @Success 200 {object} roadshow.BusinessTripResp
- // @router /report/researcher/business_trip [get]
- func (this *CalendarController) ResearcherBusinessTrip() {
- 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
- }
- adminId, _ := this.GetInt("AdminId")
- weekQuery, _ := this.GetInt("WeekQuery")
- baseQueryDate := this.GetString("BaseQueryDate")
- //fmt.Println(adminId)
- group, err := roadshow.GetResearcherGroup()
- if err != nil {
- br.Msg = "获取信息失败!"
- br.ErrMsg = "获取分组信息失败!Err:" + err.Error()
- return
- }
- researcherList, err := roadshow.GetBusinessTripResearcher()
- if err != nil {
- br.Msg = "获取信息失败!"
- br.ErrMsg = "获取分组信息失败!,GetBusinessTripResearcher Err:" + err.Error()
- return
- }
- ////获取当天周日期
- //nowWeekStart := utils.GetNowWeekMonday().AddDate(0, 0, -2)
- ////nowWeekEnd := utils.GetNowWeekLastDay()
- ////获取下周日期
- //nextWeekStart := utils.GetNextWeekMonday().AddDate(0, 0, -2)
- //nextWeekEnd := utils.GetNextWeekLastDay().AddDate(0, 0, -2)
- var nowWeekStart time.Time
- if baseQueryDate == "" {
- now := time.Now()
- weekDay := int(now.Weekday())
- if weekDay == 6 {
- nowWeekStart, _ = time.ParseInLocation(utils.FormatDate, now.Format(utils.FormatDate), time.Local)
- } else {
- nowWeekStart, _ = time.ParseInLocation(utils.FormatDate, now.AddDate(0, 0, -(weekDay+1)).Format(utils.FormatDate), time.Local)
- }
- }
- // 查询需求是可以无限往前后两周查询, 以入参为本周开始日期
- if baseQueryDate != "" {
- t, e := time.ParseInLocation(utils.FormatDate, baseQueryDate, time.Local)
- if e != nil {
- br.Msg = "查询开始日期格式有误"
- return
- }
- nowWeekStart = t
- }
- // 前/后两周
- if weekQuery == 1 {
- nowWeekStart = nowWeekStart.AddDate(0, 0, -14)
- }
- if weekQuery == 2 {
- nowWeekStart = nowWeekStart.AddDate(0, 0, +14)
- }
- //nowWeekEnd := utils.GetNowWeekLastDay()
- //获取下周日期
- nextWeekStart := nowWeekStart.AddDate(0, 0, +7)
- nextWeekEnd := nowWeekStart.AddDate(0, 0, +13)
- //获取路演信息
- roadshowList, err := roadshow.GetBusinessTripList(adminId, nowWeekStart.Format(utils.FormatDate), nextWeekEnd.Format(utils.FormatDateTime))
- if err != nil {
- br.Msg = "获取信息失败!"
- br.ErrMsg = "获取路演信息失败!,GetBusinessTripList Err:" + err.Error()
- return
- }
- roadshowMap := make(map[int][]*roadshow.BusinessTripResearcherList)
- for _, v := range roadshowList {
- if findVals, ok := roadshowMap[v.ResearcherId]; ok {
- findVals = append(findVals, v)
- roadshowMap[v.ResearcherId] = findVals
- } else {
- roadsItems := make([]*roadshow.BusinessTripResearcherList, 0)
- roadsItems = append(roadsItems, v)
- roadshowMap[v.ResearcherId] = roadsItems
- }
- }
- //fmt.Println("roadshow json start")
- //jsonBody, err := json.Marshal(roadshowMap)
- //fmt.Println("json body:" + string(jsonBody))
- //fmt.Println("roadshow json end")
- groupMap := make(map[int][]*roadshow.BusinessTripResearcher)
- for _, v := range researcherList {
- if findRoadshowList, ok := roadshowMap[v.AdminId]; ok {
- tripList := make([]*roadshow.BusinessTrip, 0)
- researcherMap := make(map[string]string)
- for i := 0; i < 7; i++ {
- newDay, _ := time.ParseInLocation(utils.FormatDate, nowWeekStart.AddDate(0, 0, i).Format(utils.FormatDate), time.Local)
- weekDate := newDay.Format(utils.FormatDate)
- tripItem := new(roadshow.BusinessTrip)
- for _, r := range findRoadshowList {
- startDateT, _ := time.ParseInLocation(utils.FormatDate, r.StartDate, time.Local)
- endDateT, _ := time.ParseInLocation(utils.FormatDate, r.EndDate, time.Local)
- if int(endDateT.Sub(startDateT)) <= 0 {
- skey := strconv.Itoa(r.ResearcherId) + r.StartDate
- if _, sok := researcherMap[skey]; !sok {
- if r != nil && (newDay.Equal(startDateT) || (newDay.Equal(endDateT)) || (newDay.Before(endDateT) && newDay.After(startDateT))) {
- tripItem.City = r.City
- researcherMap[skey] = skey
- }
- }
- } else {
- if r != nil && (newDay.Equal(startDateT) || (newDay.Equal(endDateT)) || (newDay.Before(endDateT) && newDay.After(startDateT))) {
- tripItem.City = r.City
- //researcherMap[skey] = skey
- }
- }
- }
- tripItem.WeekDate = weekDate
- tripItem.WeekType = "current"
- tripItem.Week = newDay.Weekday().String()
- tripList = append(tripList, tripItem)
- }
- for i := 0; i < 7; i++ {
- newDay := nextWeekStart.AddDate(0, 0, i)
- weekDate := newDay.Format(utils.FormatDate)
- tripItem := new(roadshow.BusinessTrip)
- for _, r := range findRoadshowList {
- startDateT, _ := time.ParseInLocation(utils.FormatDate, r.StartDate, time.Local)
- endDateT, _ := time.ParseInLocation(utils.FormatDate, r.EndDate, time.Local)
- if int(endDateT.Sub(startDateT)) <= 0 {
- skey := strconv.Itoa(r.ResearcherId) + r.StartDate
- if _, sok := researcherMap[skey]; !sok {
- if r != nil && (newDay.Equal(startDateT) || (newDay.Equal(endDateT)) || (newDay.Before(endDateT) && newDay.After(startDateT))) {
- tripItem.City = r.City
- researcherMap[skey] = skey
- }
- }
- } else {
- if r != nil && (newDay.Equal(startDateT) || (newDay.Equal(endDateT)) || (newDay.Before(endDateT) && newDay.After(startDateT))) {
- tripItem.City = r.City
- //researcherMap[skey] = skey
- }
- }
- }
- tripItem.WeekDate = weekDate
- tripItem.WeekType = "next"
- tripItem.Week = newDay.Weekday().String()
- tripList = append(tripList, tripItem)
- }
- v.BusinessTripList = tripList
- //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
- }
- //}
- }
- }
- groupList := make([]*roadshow.BusinessTripGroup, 0)
- for _, v := range group {
- item := new(roadshow.BusinessTripGroup)
- item.GroupName = v.GroupName
- item.GroupId = v.GroupId
- item.ResearcherList = groupMap[v.GroupId]
- groupList = append(groupList, item)
- }
- resp := new(roadshow.BusinessTripResp)
- resp.GroupList = groupList
- resp.BaseDate = nowWeekStart.Format(utils.FormatDate)
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- return
- }
- // OverseasCustomReportCalendarList
- // @Title 路演详情列表
- // @Description 路演详情列表接口
- // @Param Keyword query string true "关键字:客户名称"
- // @Param CompanyStatus query string true "客户状态,枚举值:正式、试用、关闭"
- // @Param SellerId query int true "销售id列表;多个用英文,分割"
- // @Param ResearcherId query int true "销售id列表;多个用英文,分割"
- // @Param StartDate query string true "开始日期,格式:2022-04-06"
- // @Param EndDate query string true "结束日期,格式:2022-04-06"
- // @Param SortField query string false "排序字段:start_date"
- // @Param SortDesc query int false "1:降序,默认,2:升序"
- // @Success 200 {object} []roadshow.RsReportRecordList
- // @router /overseas_custom/calendar/list [get]
- func (this *CalendarController) OverseasCustomReportCalendarList() {
- 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
- }
- keyword := this.GetString("Keyword")
- companyStatus := this.GetString("CompanyStatus")
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- sellerId := this.GetString("SellerId")
- researcherId := this.GetString("ResearcherId")
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- sortField := this.GetString("SortField")
- sortDesc, _ := this.GetInt("SortDesc")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- switch sortField {
- case "start_date":
- default:
- sortField = "start_date"
- }
- // "1:降序,默认,2:升序"
- sortDesStr := ` desc `
- switch sortDesc {
- case 2:
- sortDesStr = ` asc `
- default:
- sortDesStr = "desc"
- }
- total, list, err := roadshow.GetOverseaCustomCalendarList(keyword, sellerId, researcherId, startDate, endDate, companyStatus, sortField, sortDesStr, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,ERR:" + err.Error()
- return
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := new(roadshow.OverseaCustomRecordInfoResp)
- resp.Paging = page
- resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- return
- }
- // OverseasCustomCalendarAdminList
- // @Title 海外客户路演用户列表接口
- // @Description 海外客户路演用户列表接口
- // @Param AdminType query string true "枚举值:researcher、seller"
- // @Success 200 {object} []roadshow.AdminInfo
- // @router /overseas_custom/sys_user/list [get]
- func (this *CalendarController) OverseasCustomCalendarAdminList() {
- 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
- }
- adminType := this.GetString("AdminType")
- var list []*roadshow.AdminInfo
- var err error
- //选择的人员类型(发起人还是被发起人)
- if adminType == "seller" {
- list, err = roadshow.GetOverseaCustomCalendarSellerList()
- } else if adminType == "researcher" {
- list, err = roadshow.GetOverseaCustomCalendarResearcherList()
- } else {
- br.Msg = "错误的类型"
- br.IsSendEmail = false
- }
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,ERR:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = list
- return
- }
- // OverseasSellerReportList
- // @Title 海外客户销售路演统计
- // @Description 海外客户销售路演统计接口
- // @Param DataType query string true "枚举值:week、month、time_interval、online、offline"
- // @Param DimensionType query string true "维度枚举值:company_status、roadshow_type"
- // @Param StartDate query string true "开始日期,格式:2022-04-06"
- // @Param EndDate query string true "结束日期,格式:2022-04-06"
- // @Success 200 {object} roadshow.RsReportRecordResp
- // @router /overseas_custom/seller/list [get]
- func (this *CalendarController) OverseasSellerReportList() {
- 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
- }
- dataType := this.GetString("DataType")
- dimensionType := this.GetString("DimensionType")
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- if dimensionType == "" {
- dimensionType = "company_status"
- }
- var adminDataList []roadshowService.OverseasAdminDataMap
- var err error
- //获取列表
- switch dataType {
- case "week":
- adminDataList, _, err = roadshowService.GetOverseasWeekDataV2("seller", dimensionType, 6)
- if err != nil {
- br.Msg = "数据异常"
- br.ErrMsg = "数据异常,Err:" + err.Error()
- return
- }
- case "month":
- adminDataList, _, err = roadshowService.GetOverseasMonthDataV2("seller", dimensionType, 6)
- 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
- }
- adminDataList, _, err = roadshowService.GetOverseasTimeIntervalData(startDate, endDate, "seller", dimensionType)
- if err != nil {
- br.Msg = "数据异常"
- br.ErrMsg = "数据异常,Err:" + err.Error()
- return
- }
- }
- sellerList, err := roadshow.GetOverseaCustomCalendarSellerList()
- adminReportRecordList := make([]roadshow.OverseasAdminReportRecord, 0)
- rsAllReportRecordNumList := make([]roadshow.RsOverseasReportRecordNum, 0)
- RsReportRecordResp := roadshow.RsOverseasReportRecordResp{
- List: adminReportRecordList,
- RsReportRecordNumList: rsAllReportRecordNumList,
- }
- startDateIndexList := make(map[int]string) //开始时间间隔map
- endDateIndexList := make(map[int]string) //结束时间间隔map
- tmpAllTryOutNumMap := make(map[int]int)
- tmpAllFormalNumMap := make(map[int]int)
- tmpAllCloseNumMap := make(map[int]int)
- tmpAllOnlineNumMap := make(map[int]int)
- tmpAllOfflineNumMap := make(map[int]int)
- for _, researcher := range sellerList {
- //每个区间的数据
- tmpAdminRsReportRecordNumList := make([]roadshow.RsOverseasReportRecordNum, 0)
- for index, adminData := range adminDataList {
- startDateIndexList[index] = adminData.StartDate
- endDateIndexList[index] = adminData.EndDate
- var tmpTryOutNum, tmpFormalNum, tmpCloseNum, tmpOnlineNum, tmpOfflineNum int
- if num, ok := adminData.TryOutMap[researcher.AdminId]; ok {
- tmpTryOutNum = num
- }
- if num, ok := adminData.FormalMap[researcher.AdminId]; ok {
- tmpFormalNum = num
- }
- if num, ok := adminData.CloseMap[researcher.AdminId]; ok {
- tmpCloseNum = num
- }
- if num, ok := adminData.OnlineMap[researcher.AdminId]; ok {
- tmpOnlineNum = num
- }
- if num, ok := adminData.OfflineMap[researcher.AdminId]; ok {
- tmpOfflineNum = num
- }
- tmpAdminRsReportRecordNum := roadshow.RsOverseasReportRecordNum{
- TryOutNum: tmpTryOutNum,
- FormalNum: tmpFormalNum,
- CloseNum: tmpCloseNum,
- OnlineNum: tmpOnlineNum,
- OfflineNum: tmpOfflineNum,
- StartDate: adminData.StartDate,
- EndDate: adminData.EndDate,
- }
- tmpAdminRsReportRecordNumList = append(tmpAdminRsReportRecordNumList, tmpAdminRsReportRecordNum)
- //总数据汇总
- if _, ok := tmpAllTryOutNumMap[index]; !ok {
- tmpAllTryOutNumMap[index] = 0
- }
- if _, ok := tmpAllFormalNumMap[index]; !ok {
- tmpAllFormalNumMap[index] = 0
- }
- if _, ok := tmpAllCloseNumMap[index]; !ok {
- tmpAllCloseNumMap[index] = 0
- }
- if _, ok := tmpAllOnlineNumMap[index]; !ok {
- tmpAllOnlineNumMap[index] = 0
- }
- if _, ok := tmpAllOfflineNumMap[index]; !ok {
- tmpAllOfflineNumMap[index] = 0
- }
- tmpAllTryOutNumMap[index] += tmpTryOutNum
- tmpAllFormalNumMap[index] += tmpFormalNum
- tmpAllCloseNumMap[index] += tmpCloseNum
- tmpAllOnlineNumMap[index] += tmpOnlineNum
- tmpAllOfflineNumMap[index] += tmpOfflineNum
- }
- // 数据都为0的时候不显示
- adminTotalNum := 0
- for _, v := range tmpAdminRsReportRecordNumList {
- adminTotalNum += v.TryOutNum + v.CloseNum + v.FormalNum
- }
- if adminTotalNum > 0 {
- tmpAdminReportRecord := roadshow.OverseasAdminReportRecord{
- Name: researcher.RealName,
- AdminId: researcher.AdminId,
- RsReportRecordNumList: tmpAdminRsReportRecordNumList,
- }
- RsReportRecordResp.List = append(RsReportRecordResp.List, tmpAdminReportRecord)
- }
- }
- //总体汇总数据
- for i := 0; i < len(tmpAllFormalNumMap); i++ {
- tmpGroupRsReportRecordNum := roadshow.RsOverseasReportRecordNum{
- TryOutNum: tmpAllTryOutNumMap[i],
- FormalNum: tmpAllFormalNumMap[i],
- CloseNum: tmpAllCloseNumMap[i],
- OnlineNum: tmpAllOnlineNumMap[i],
- OfflineNum: tmpAllOfflineNumMap[i],
- StartDate: startDateIndexList[i],
- EndDate: endDateIndexList[i],
- }
- rsAllReportRecordNumList = append(rsAllReportRecordNumList, tmpGroupRsReportRecordNum)
- }
- RsReportRecordResp.RsReportRecordNumList = rsAllReportRecordNumList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = RsReportRecordResp
- return
- }
- // OverseasResearcherReportList
- // @Title 研究员路演统计
- // @Description 研究员路演统计接口
- // @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} roadshow.RsReportRecordResp
- // @router /overseas_custom/researcher/list [get]
- func (this *CalendarController) OverseasResearcherReportList() {
- 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
- }
- dataType := this.GetString("DataType")
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- var adminDataList []roadshowService.OverseasAdminDataMap
- var err error
- //var firstDate time.Time
- //获取列表
- switch dataType {
- case "week":
- adminDataList, _, err = roadshowService.GetOverseasWeekData("researcher", "company_status")
- if err != nil {
- br.Msg = "数据异常"
- br.ErrMsg = "数据异常,Err:" + err.Error()
- return
- }
- case "month":
- adminDataList, _, err = roadshowService.GetOverseasMonthData("researcher", "company_status")
- 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
- }
- adminDataList, _, err = roadshowService.GetOverseasTimeIntervalData(startDate, endDate, "researcher", "company_status")
- if err != nil {
- br.Msg = "数据异常"
- br.ErrMsg = "数据异常,Err:" + err.Error()
- return
- }
- }
- researcherList, err := roadshow.GetOverseaCustomCalendarResearcherList()
- if err != nil {
- br.Msg = "获取信息失败!"
- br.ErrMsg = "获取分组信息失败!,GetResearcherV2 Err:" + err.Error()
- return
- }
- adminReportRecordList := make([]roadshow.OverseasAdminReportRecord, 0)
- rsAllReportRecordNumList := make([]roadshow.RsOverseasReportRecordNum, 0)
- RsReportRecordResp := roadshow.RsOverseasReportRecordResp{
- List: adminReportRecordList,
- RsReportRecordNumList: rsAllReportRecordNumList,
- }
- startDateIndexList := make(map[int]string) //开始时间间隔map
- endDateIndexList := make(map[int]string) //结束时间间隔map
- tmpAllTryOutNumMap := make(map[int]int)
- tmpAllFormalNumMap := make(map[int]int)
- tmpAllMeetingNumMap := make(map[int]int)
- for _, researcher := range researcherList {
- //组内研究员数据
- //每个区间的数据
- tmpAdminRsReportRecordNumList := make([]roadshow.RsOverseasReportRecordNum, 0)
- for index, adminData := range adminDataList {
- startDateIndexList[index] = adminData.StartDate
- endDateIndexList[index] = adminData.EndDate
- var tmpTryOutNum, tmpFormalNum, tmpCloseNum int
- if num, ok := adminData.TryOutMap[researcher.AdminId]; ok {
- tmpTryOutNum = num
- }
- if num, ok := adminData.FormalMap[researcher.AdminId]; ok {
- tmpFormalNum = num
- }
- if num, ok := adminData.CloseMap[researcher.AdminId]; ok {
- tmpCloseNum = num
- }
- tmpAdminRsReportRecordNum := roadshow.RsOverseasReportRecordNum{
- TryOutNum: tmpTryOutNum,
- FormalNum: tmpFormalNum,
- CloseNum: tmpCloseNum,
- StartDate: adminData.StartDate,
- EndDate: adminData.EndDate,
- }
- tmpAdminRsReportRecordNumList = append(tmpAdminRsReportRecordNumList, tmpAdminRsReportRecordNum)
- //总数据汇总
- if _, ok := tmpAllTryOutNumMap[index]; !ok {
- tmpAllTryOutNumMap[index] = 0
- }
- if _, ok := tmpAllFormalNumMap[index]; !ok {
- tmpAllFormalNumMap[index] = 0
- }
- if _, ok := tmpAllMeetingNumMap[index]; !ok {
- tmpAllMeetingNumMap[index] = 0
- }
- tmpAllTryOutNumMap[index] += tmpTryOutNum
- tmpAllFormalNumMap[index] += tmpFormalNum
- tmpAllMeetingNumMap[index] += tmpCloseNum
- }
- // 数据都为0的时候不显示
- adminTotalNum := 0
- for _, v := range tmpAdminRsReportRecordNumList {
- adminTotalNum += v.TryOutNum + v.CloseNum + v.FormalNum
- }
- if adminTotalNum > 0 {
- tmpAdminReportRecord := roadshow.OverseasAdminReportRecord{
- Name: researcher.RealName,
- AdminId: researcher.AdminId,
- RsReportRecordNumList: tmpAdminRsReportRecordNumList,
- }
- RsReportRecordResp.List = append(RsReportRecordResp.List, tmpAdminReportRecord)
- }
- }
- //总体汇总数据
- for i := 0; i < len(tmpAllFormalNumMap); i++ {
- tmpGroupRsReportRecordNum := roadshow.RsOverseasReportRecordNum{
- TryOutNum: tmpAllTryOutNumMap[i],
- FormalNum: tmpAllFormalNumMap[i],
- CloseNum: tmpAllMeetingNumMap[i],
- StartDate: startDateIndexList[i],
- EndDate: endDateIndexList[i],
- }
- rsAllReportRecordNumList = append(rsAllReportRecordNumList, tmpGroupRsReportRecordNum)
- }
- RsReportRecordResp.RsReportRecordNumList = rsAllReportRecordNumList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = RsReportRecordResp
- return
- }
- // OverseasCalendarList
- // @Title 海外客户路演详情列表
- // @Description 海外客户路演详情列表接口
- // @Param AdminType query string true "枚举值:researcher、seller、 special:专项路演"
- // @Param DataType query string true "枚举值:try_out、formal、close、online、offline"
- // @Param AdminIds query string true "用户ids"
- // @Param StartDate query string true "开始日期,格式:2022-04-06"
- // @Param EndDate query string true "结束日期,格式:2022-04-06"
- // @Success 200 {object} []roadshow.RsReportRecordList
- // @router /overseas/calendar/list [get]
- func (this *CalendarController) OverseasCalendarList() {
- 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
- }
- adminType := this.GetString("AdminType")
- dataType := this.GetString("DataType")
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- adminIds := this.GetString("AdminIds")
- if adminIds == "" {
- br.Msg = "请传入对应的人员"
- return
- }
- //adminIdsArr := make([]int, 0)
- //adminIdSlice := strings.Split(adminIds, ",")
- //for _, v := range adminIdSlice {
- // id,_ := strconv.Atoi(v)
- // adminIdsArr = append(adminIdsArr, id)
- //}
- //正式客户
- //var condition string
- //var pars []interface{}
- //condition = ` and a.start_date >= ? and a.end_date <= ? `
- //pars = append(pars, startDate, endDate)
- var sellerIds, researcherIds string
- //选择的人员类型(发起人还是被发起人)
- if adminType == "seller" {
- //condition += ` and a.seller_id IN (` + utils.GetOrmInReplace(len(adminIdsArr)) + `)`
- sellerIds = adminIds
- } else {
- //condition += ` and a.researcher_id IN (` + utils.GetOrmInReplace(len(adminIdsArr)) + `)`
- researcherIds = adminIds
- }
- //pars = append(pars, adminIdsArr)
- var status string
- //获取列表
- switch dataType {
- case "try_out":
- //condition += ` and a.company_status = ? )`
- //pars = append(pars, "试用")
- status = "试用"
- case "formal":
- //condition += ` and a.company_status = ? )`
- //pars = append(pars, "正式")
- status = "正式"
- case "close":
- //condition += ` and a.company_status = ? )`
- //pars = append(pars, "关闭")
- status = "关闭"
- //case "online":
- // condition += ` and a.roadshow_type = ? `
- // pars = append(pars, "线上")
- //case "offline":
- // condition += ` and a.roadshow_type = ? `
- // pars = append(pars, "线下")
- default:
- br.Msg = "请传入类型"
- br.ErrMsg = "请传入类型DataType"
- return
- }
- list, err := roadshow.GetOverseaCustomCalendarList2(sellerIds, researcherIds, startDate, endDate, status)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,ERR:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = list
- return
- }
|