12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217 |
- package controllers
- import (
- "encoding/json"
- "hongze/hz_crm_api/models"
- "hongze/hz_crm_api/models/roadshow"
- "hongze/hz_crm_api/models/system"
- "hongze/hz_crm_api/models/yb"
- "hongze/hz_crm_api/services"
- "hongze/hz_crm_api/services/statistic_report"
- "hongze/hz_crm_api/utils"
- "strings"
- "time"
- )
- type StatisticYbLogController struct {
- BaseAuthController
- }
- // SellerYbLog
- // @Title 分产品阅读统计
- // @Description 分产品阅读统计
- // @Param DataType query string true "枚举值:week、month、time_interval"
- // @Param ProductType query int true "产品类型"
- // @Param ProductId query int true "产品id"
- // @Success 200 {object} statistic_report.CompanyReportRecordResp
- // @router /report/seller_yb_log [get]
- func (s *StatisticYbLogController) SellerYbLog() {
- br := new(models.BaseResponse).Init()
- defer func() {
- s.Data["json"] = br
- s.ServeJSON()
- }()
- sysUser := s.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- dataType := s.GetString("DataType")
- productType, _ := s.GetInt("ProductType")
- productId, _ := s.GetInt("ProductId")
- if dataType == "" {
- br.Msg = "请输入时间类型"
- return
- }
- if productType == 0 {
- br.Msg = "请输入产品类型"
- return
- }
- var companyReportDataMapList []statistic_report.SellerYbLogDataMap
- var err error
- var firstDate time.Time
- switch dataType {
- //获取列表
- case "week":
- nowWeekMonday := utils.GetNowWeekMonday() //本周周一
- //companyReportDataMapList, firstDate, err = statistic_report.GetWeekData()
- companyReportDataMapList, firstDate, err = statistic_report.GetYbLogWeekDataNum(nowWeekMonday, productId, productType, 6)
- if err != nil {
- br.Msg = "数据异常"
- br.ErrMsg = "数据异常,Err:" + err.Error()
- return
- }
- case "month":
- nowMonthFirstDay := utils.GetNowMonthFirstDay() //本月第一天
- companyReportDataMapList, firstDate, err = statistic_report.GetYbLogMonthDataNum(nowMonthFirstDay, productId, productType, 6)
- if err != nil {
- br.Msg = "数据异常"
- br.ErrMsg = "数据异常,Err:" + err.Error()
- return
- }
- }
- //获取销售人员分组数据
- var group []services.AdminGroup
- var groupIdRelationMap map[int]int
- var groupMap map[int][]*roadshow.Researcher
- group, groupIdRelationMap, err = services.GetFiccSystemGroup()
- if err != nil {
- br.Msg = "获取信息失败!"
- br.ErrMsg = "获取分组信息失败!Err:" + err.Error()
- return
- }
- researcherList, tmpErr := services.GetFiccSeller(firstDate, groupIdRelationMap)
- if tmpErr != nil {
- err = tmpErr
- }
- 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([]statistic_report.GroupYbLogRecord, 0)
- allCompanyReportRecordNum := make([]statistic_report.SellerYbLogRecordNum, 0)
- companyReportRecordResp := statistic_report.SellerYbLogRecordResp{
- List: groupReportRecordList,
- SellerYbLogRecordNumList: allCompanyReportRecordNum,
- }
- startDateIndexList := make(map[int]string) //开始时间间隔map
- endDateIndexList := make(map[int]string) //结束时间间隔map
- //客户数汇总
- tmpAllTryOutNumMap := make(map[int]int)
- tmpAllFormalNumMap := make(map[int]int)
- tmpAllAllNumMap := make(map[int]int)
- //id集合汇总
- tmpAllTryOutIdMap := make(map[int]string)
- tmpAllFormalIdMap := make(map[int]string)
- tmpAllAllIdMap := make(map[int]string)
- for _, v := range group {
- v.ResearcherList = groupMap[v.GroupId]
- tmpGroupAdminReportRecord := make([]statistic_report.AdminYbLogRecord, 0)
- tmpGroupCompanyReportRecordNumList := make([]statistic_report.SellerYbLogRecordNum, 0)
- //数量统计
- tmpGroupTryOutNumMap := make(map[int]int)
- tmpGroupFormalNumMap := make(map[int]int)
- tmpGroupAllNumMap := make(map[int]int)
- //id集合
- tmpGroupTryOutIdSliceMap := make(map[int][]string)
- tmpGroupFormalIdSliceMap := make(map[int][]string)
- tmpGroupAllIdSliceMap := make(map[int][]string)
- //id集合
- tmpGroupTryOutIdMap := make(map[int]string)
- tmpGroupFormalIdMap := make(map[int]string)
- tmpGroupAllIdMap := make(map[int]string)
- for _, researcher := range groupMap[v.GroupId] {
- //组内研究员数据
- //每个区间的数据
- tmpCompanyReportRecordNumList := make([]statistic_report.SellerYbLogRecordNum, 0)
- for index, adminData := range companyReportDataMapList {
- startDateIndexList[index] = adminData.StartDate
- endDateIndexList[index] = adminData.EndDate
- var tmpTryOutNum, tmpFormalNum, tmpAllNum int
- var tmpTryOutIdSlice, tmpFormalIdSlice, tmpAllIdSlice []string
- var tmpTryOutId, tmpFormalId, tmpAllId string
- if num, ok := adminData.TryOutMap[researcher.AdminId]; ok {
- tmpTryOutNum = num
- tmpTryOutIdSlice = append(tmpTryOutIdSlice, adminData.TryOutIdMap[researcher.AdminId])
- tmpTryOutId = strings.Join(tmpTryOutIdSlice, ",")
- }
- if num, ok := adminData.FormalMap[researcher.AdminId]; ok {
- tmpFormalNum = num
- tmpFormalIdSlice = append(tmpFormalIdSlice, adminData.FormalIdMap[researcher.AdminId])
- tmpFormalId = strings.Join(tmpFormalIdSlice, ",")
- }
- if num, ok := adminData.AllMap[researcher.AdminId]; ok {
- tmpAllNum = num
- tmpAllIdSlice = append(tmpAllIdSlice, adminData.AllIdMap[researcher.AdminId])
- tmpAllId = strings.Join(tmpAllIdSlice, ",")
- }
- tmpAdminRsReportRecordNum := statistic_report.SellerYbLogRecordNum{
- TryOutNum: tmpTryOutNum,
- TryOutIds: tmpTryOutId,
- FormalNum: tmpFormalNum,
- FormalIds: tmpFormalId,
- AllNum: tmpAllNum,
- AllIds: tmpAllId,
- StartDate: adminData.StartDate,
- EndDate: adminData.EndDate,
- }
- tmpCompanyReportRecordNumList = append(tmpCompanyReportRecordNumList, tmpAdminRsReportRecordNum)
- //组内数据汇总
- if _, ok := tmpGroupTryOutNumMap[index]; !ok {
- tmpGroupTryOutNumMap[index] = 0
- }
- if _, ok := tmpGroupFormalNumMap[index]; !ok {
- tmpGroupFormalNumMap[index] = 0
- }
- if _, ok := tmpGroupAllNumMap[index]; !ok {
- tmpGroupAllNumMap[index] = 0
- }
- tmpGroupTryOutNumMap[index] += tmpTryOutNum
- tmpGroupFormalNumMap[index] += tmpFormalNum
- tmpGroupAllNumMap[index] += tmpAllNum
- //组内数据汇总
- if tmpTryOutId != "" {
- tmpGroupTryOutIdSliceMap[index] = append(tmpGroupTryOutIdSliceMap[index], tmpTryOutId)
- }
- if tmpFormalId != "" {
- tmpGroupFormalIdSliceMap[index] = append(tmpGroupFormalIdSliceMap[index], tmpFormalId)
- }
- if tmpAllId != "" {
- tmpGroupAllIdSliceMap[index] = append(tmpGroupAllIdSliceMap[index], tmpAllId)
- }
- //总数据汇总
- /* if _, ok := tmpAllTryOutNumMap[index]; !ok {
- tmpAllTryOutNumMap[index] = 0
- }
- if _, ok := tmpAllFormalNumMap[index]; !ok {
- tmpAllFormalNumMap[index] = 0
- }
- if _, ok := tmpAllAllNumMap[index]; !ok {
- tmpAllAllNumMap[index] = 0
- }*/
- tmpAllTryOutNumMap[index] += tmpTryOutNum
- tmpAllFormalNumMap[index] += tmpFormalNum
- tmpAllAllNumMap[index] += tmpAllNum
- tmpAllTryOutIdMap[index] += tmpTryOutId
- tmpAllFormalIdMap[index] += tmpFormalId
- tmpAllAllIdMap[index] += tmpAllId
- }
- tmpAdminReportRecord := statistic_report.AdminYbLogRecord{
- Name: researcher.RealName,
- AdminId: researcher.AdminId,
- SellerYbLogRecordNumList: tmpCompanyReportRecordNumList,
- }
- tmpGroupAdminReportRecord = append(tmpGroupAdminReportRecord, tmpAdminReportRecord)
- }
- for i := 0; i < len(tmpGroupAllNumMap); i++ {
- tmpGroupTryOutIdMap[i] = strings.Join(tmpGroupTryOutIdSliceMap[i], ",")
- tmpGroupFormalIdMap[i] = strings.Join(tmpGroupFormalIdSliceMap[i], ",")
- tmpGroupAllIdMap[i] = strings.Join(tmpGroupAllIdSliceMap[i], ",")
- tmpGroupCompanyReportRecordNum := statistic_report.SellerYbLogRecordNum{
- TryOutNum: tmpGroupTryOutNumMap[i],
- TryOutIds: tmpGroupTryOutIdMap[i],
- FormalNum: tmpGroupFormalNumMap[i],
- FormalIds: tmpGroupFormalIdMap[i],
- AllNum: tmpGroupAllNumMap[i],
- AllIds: tmpGroupAllIdMap[i],
- StartDate: startDateIndexList[i],
- EndDate: endDateIndexList[i],
- }
- tmpGroupCompanyReportRecordNumList = append(tmpGroupCompanyReportRecordNumList, tmpGroupCompanyReportRecordNum)
- }
- groupReportRecord := statistic_report.GroupYbLogRecord{
- Item: tmpGroupAdminReportRecord,
- Name: v.GroupName,
- GroupId: v.GroupId,
- SellerYbLogRecordNumList: tmpGroupCompanyReportRecordNumList,
- }
- groupReportRecordList = append(groupReportRecordList, groupReportRecord)
- }
- //总体汇总数据
- for i := 0; i < len(tmpAllFormalNumMap); i++ {
- tmpGroupCompanyReportRecordNum := statistic_report.SellerYbLogRecordNum{
- TryOutNum: tmpAllTryOutNumMap[i],
- TryOutIds: "",
- FormalNum: tmpAllFormalNumMap[i],
- FormalIds: "",
- AllNum: tmpAllAllNumMap[i],
- AllIds: "",
- StartDate: startDateIndexList[i],
- EndDate: endDateIndexList[i],
- }
- allCompanyReportRecordNum = append(allCompanyReportRecordNum, tmpGroupCompanyReportRecordNum)
- }
- companyReportRecordResp.SellerYbLogRecordNumList = allCompanyReportRecordNum
- 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.GroupId != adminGroupId {
- tmpList[index].Item = make([]statistic_report.AdminYbLogRecord, 0)
- } else {
- tmpList[index], tmpList[0] = tmpList[0], tmpList[index]
- }
- }
- companyReportRecordResp.List = tmpList
- case utils.ROLE_TYPE_CODE_RAI_GROUP:
- for index, v := range tmpList {
- //如果不是同一个分组,那么就移除该分组下的人员数据
- if v.GroupId != adminGroupId {
- tmpList[index].Item = make([]statistic_report.AdminYbLogRecord, 0)
- } else {
- tmpList[index], tmpList[0] = tmpList[0], tmpList[index]
- }
- }
- companyReportRecordResp.List = tmpList
- case utils.ROLE_TYPE_CODE_FICC_ADMIN, utils.ROLE_TYPE_CODE_ADMIN, utils.ROLE_TYPE_CODE_RAI_ADMIN:
- //管理员、超管看全部数据
- companyReportRecordResp.List = tmpList
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = companyReportRecordResp
- }
- // SellerYbUserLog
- // @Title 分产品阅读统计用户详情
- // @Description 分产品阅读统计用户详情
- // @Param request body statisticModels.SellerYbUserLogReq true "type json string"
- // @Success 200 {object} statistic_report.CompanyListResp
- // @router /report/seller_yb_log/user [post]
- func (s *StatisticYbLogController) SellerYbUserLog() {
- br := new(models.BaseResponse).Init()
- defer func() {
- s.Data["json"] = br
- s.ServeJSON()
- }()
- sysUser := s.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req yb.SellerYbUserLogReq
- err := json.Unmarshal(s.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- //todo 校验入参
- if req.SellerIds == "" {
- br.Msg = "请输入销售ID"
- return
- }
- if req.StartDate == "" {
- br.Msg = "请输入开始时间"
- return
- }
- if req.EndDate == "" {
- br.Msg = "请输入截止时间"
- return
- }
- if req.ProductType == 0 {
- br.Msg = "请输入产品类型"
- return
- }
- if req.CompanyStatus == "" {
- br.Msg = "请输入产品状态"
- return
- }
- resp, err, errMsg := statistic_report.YbProductUserList(sysUser, req)
- if err != nil {
- br.Msg = err.Error()
- br.ErrMsg = errMsg
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // SellerCollectLog
- // @Title 收藏统计
- // @Description 收藏统计
- // @Param DataType query string true "枚举值:week、month、time_interval"
- // @Success 200 {object} statistic_report.CompanyReportRecordResp
- // @router /report/seller_collect_log [get]
- func (s *StatisticYbLogController) SellerCollectLog() {
- br := new(models.BaseResponse).Init()
- defer func() {
- s.Data["json"] = br
- s.ServeJSON()
- }()
- sysUser := s.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- dataType := s.GetString("DataType")
- if dataType == "" {
- br.Msg = "请输入时间类型"
- return
- }
- var companyReportDataMapList []statistic_report.SellerYbLogDataMap
- var err error
- var firstDate time.Time
- switch dataType {
- //获取列表
- case "week":
- nowWeekMonday := utils.GetNowWeekMonday() //本周周一
- companyReportDataMapList, firstDate, err = statistic_report.GetCollectLogWeekDataNum(nowWeekMonday, 6)
- if err != nil {
- br.Msg = "数据异常"
- br.ErrMsg = "数据异常,Err:" + err.Error()
- return
- }
- case "month":
- nowMonthFirstDay := utils.GetNowMonthFirstDay() //本月第一天
- companyReportDataMapList, firstDate, err = statistic_report.GetCollectLogMonthDataNum(nowMonthFirstDay, 6)
- if err != nil {
- br.Msg = "数据异常"
- br.ErrMsg = "数据异常,Err:" + err.Error()
- return
- }
- }
- //获取销售人员分组数据
- var group []services.AdminGroup
- var groupIdRelationMap map[int]int
- var groupMap map[int][]*roadshow.Researcher
- group, groupIdRelationMap, err = services.GetFiccSystemGroup()
- if err != nil {
- br.Msg = "获取信息失败!"
- br.ErrMsg = "获取分组信息失败!Err:" + err.Error()
- return
- }
- researcherList, tmpErr := services.GetFiccSeller(firstDate, groupIdRelationMap)
- if tmpErr != nil {
- err = tmpErr
- }
- 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([]statistic_report.GroupYbLogRecord, 0)
- allCompanyReportRecordNum := make([]statistic_report.SellerYbLogRecordNum, 0)
- companyReportRecordResp := statistic_report.SellerYbLogRecordResp{
- List: groupReportRecordList,
- SellerYbLogRecordNumList: allCompanyReportRecordNum,
- }
- startDateIndexList := make(map[int]string) //开始时间间隔map
- endDateIndexList := make(map[int]string) //结束时间间隔map
- //客户数汇总
- tmpAllTryOutNumMap := make(map[int]int)
- tmpAllFormalNumMap := make(map[int]int)
- tmpAllAllNumMap := make(map[int]int)
- //id集合汇总
- tmpAllTryOutIdMap := make(map[int]string)
- tmpAllFormalIdMap := make(map[int]string)
- tmpAllAllIdMap := make(map[int]string)
- for _, v := range group {
- v.ResearcherList = groupMap[v.GroupId]
- tmpGroupAdminReportRecord := make([]statistic_report.AdminYbLogRecord, 0)
- tmpGroupCompanyReportRecordNumList := make([]statistic_report.SellerYbLogRecordNum, 0)
- //数量统计
- tmpGroupTryOutNumMap := make(map[int]int)
- tmpGroupFormalNumMap := make(map[int]int)
- tmpGroupAllNumMap := make(map[int]int)
- //id集合
- tmpGroupTryOutIdSliceMap := make(map[int][]string)
- tmpGroupFormalIdSliceMap := make(map[int][]string)
- tmpGroupAllIdSliceMap := make(map[int][]string)
- //id集合
- tmpGroupTryOutIdMap := make(map[int]string)
- tmpGroupFormalIdMap := make(map[int]string)
- tmpGroupAllIdMap := make(map[int]string)
- for _, researcher := range groupMap[v.GroupId] {
- //组内研究员数据
- //每个区间的数据
- tmpCompanyReportRecordNumList := make([]statistic_report.SellerYbLogRecordNum, 0)
- for index, adminData := range companyReportDataMapList {
- startDateIndexList[index] = adminData.StartDate
- endDateIndexList[index] = adminData.EndDate
- var tmpTryOutNum, tmpFormalNum, tmpAllNum int
- var tmpTryOutIdSlice, tmpFormalIdSlice, tmpAllIdSlice []string
- var tmpTryOutId, tmpFormalId, tmpAllId string
- if num, ok := adminData.TryOutMap[researcher.AdminId]; ok {
- tmpTryOutNum = num
- tmpTryOutIdSlice = append(tmpTryOutIdSlice, adminData.TryOutIdMap[researcher.AdminId])
- tmpTryOutId = strings.Join(tmpTryOutIdSlice, ",")
- }
- if num, ok := adminData.FormalMap[researcher.AdminId]; ok {
- tmpFormalNum = num
- tmpFormalIdSlice = append(tmpFormalIdSlice, adminData.FormalIdMap[researcher.AdminId])
- tmpFormalId = strings.Join(tmpFormalIdSlice, ",")
- }
- if num, ok := adminData.AllMap[researcher.AdminId]; ok {
- tmpAllNum = num
- tmpAllIdSlice = append(tmpAllIdSlice, adminData.AllIdMap[researcher.AdminId])
- tmpAllId = strings.Join(tmpAllIdSlice, ",")
- }
- tmpAdminRsReportRecordNum := statistic_report.SellerYbLogRecordNum{
- TryOutNum: tmpTryOutNum,
- TryOutIds: tmpTryOutId,
- FormalNum: tmpFormalNum,
- FormalIds: tmpFormalId,
- AllNum: tmpAllNum,
- AllIds: tmpAllId,
- StartDate: adminData.StartDate,
- EndDate: adminData.EndDate,
- }
- tmpCompanyReportRecordNumList = append(tmpCompanyReportRecordNumList, tmpAdminRsReportRecordNum)
- //组内数据汇总
- if _, ok := tmpGroupTryOutNumMap[index]; !ok {
- tmpGroupTryOutNumMap[index] = 0
- }
- if _, ok := tmpGroupFormalNumMap[index]; !ok {
- tmpGroupFormalNumMap[index] = 0
- }
- if _, ok := tmpGroupAllNumMap[index]; !ok {
- tmpGroupAllNumMap[index] = 0
- }
- tmpGroupTryOutNumMap[index] += tmpTryOutNum
- tmpGroupFormalNumMap[index] += tmpFormalNum
- tmpGroupAllNumMap[index] += tmpAllNum
- //组内数据汇总
- if tmpTryOutId != "" {
- tmpGroupTryOutIdSliceMap[index] = append(tmpGroupTryOutIdSliceMap[index], tmpTryOutId)
- }
- if tmpFormalId != "" {
- tmpGroupFormalIdSliceMap[index] = append(tmpGroupFormalIdSliceMap[index], tmpFormalId)
- }
- if tmpAllId != "" {
- tmpGroupAllIdSliceMap[index] = append(tmpGroupAllIdSliceMap[index], tmpAllId)
- }
- tmpAllTryOutNumMap[index] += tmpTryOutNum
- tmpAllFormalNumMap[index] += tmpFormalNum
- tmpAllAllNumMap[index] += tmpAllNum
- tmpAllTryOutIdMap[index] += tmpTryOutId
- tmpAllFormalIdMap[index] += tmpFormalId
- tmpAllAllIdMap[index] += tmpAllId
- }
- tmpAdminReportRecord := statistic_report.AdminYbLogRecord{
- Name: researcher.RealName,
- AdminId: researcher.AdminId,
- SellerYbLogRecordNumList: tmpCompanyReportRecordNumList,
- }
- tmpGroupAdminReportRecord = append(tmpGroupAdminReportRecord, tmpAdminReportRecord)
- }
- for i := 0; i < len(tmpGroupAllNumMap); i++ {
- tmpGroupTryOutIdMap[i] = strings.Join(tmpGroupTryOutIdSliceMap[i], ",")
- tmpGroupFormalIdMap[i] = strings.Join(tmpGroupFormalIdSliceMap[i], ",")
- tmpGroupAllIdMap[i] = strings.Join(tmpGroupAllIdSliceMap[i], ",")
- tmpGroupCompanyReportRecordNum := statistic_report.SellerYbLogRecordNum{
- TryOutNum: tmpGroupTryOutNumMap[i],
- TryOutIds: tmpGroupTryOutIdMap[i],
- FormalNum: tmpGroupFormalNumMap[i],
- FormalIds: tmpGroupFormalIdMap[i],
- AllNum: tmpGroupAllNumMap[i],
- AllIds: tmpGroupAllIdMap[i],
- StartDate: startDateIndexList[i],
- EndDate: endDateIndexList[i],
- }
- tmpGroupCompanyReportRecordNumList = append(tmpGroupCompanyReportRecordNumList, tmpGroupCompanyReportRecordNum)
- }
- groupReportRecord := statistic_report.GroupYbLogRecord{
- Item: tmpGroupAdminReportRecord,
- Name: v.GroupName,
- GroupId: v.GroupId,
- SellerYbLogRecordNumList: tmpGroupCompanyReportRecordNumList,
- }
- groupReportRecordList = append(groupReportRecordList, groupReportRecord)
- }
- //总体汇总数据
- for i := 0; i < len(tmpAllFormalNumMap); i++ {
- tmpGroupCompanyReportRecordNum := statistic_report.SellerYbLogRecordNum{
- TryOutNum: tmpAllTryOutNumMap[i],
- TryOutIds: "",
- FormalNum: tmpAllFormalNumMap[i],
- FormalIds: "",
- AllNum: tmpAllAllNumMap[i],
- AllIds: "",
- StartDate: startDateIndexList[i],
- EndDate: endDateIndexList[i],
- }
- allCompanyReportRecordNum = append(allCompanyReportRecordNum, tmpGroupCompanyReportRecordNum)
- }
- companyReportRecordResp.SellerYbLogRecordNumList = allCompanyReportRecordNum
- 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.GroupId != adminGroupId {
- tmpList[index].Item = make([]statistic_report.AdminYbLogRecord, 0)
- } else {
- tmpList[index], tmpList[0] = tmpList[0], tmpList[index]
- }
- }
- companyReportRecordResp.List = tmpList
- case utils.ROLE_TYPE_CODE_RAI_GROUP:
- for index, v := range tmpList {
- //如果不是同一个分组,那么就移除该分组下的人员数据
- if v.GroupId != adminGroupId {
- tmpList[index].Item = make([]statistic_report.AdminYbLogRecord, 0)
- } else {
- tmpList[index], tmpList[0] = tmpList[0], tmpList[index]
- }
- }
- companyReportRecordResp.List = tmpList
- case utils.ROLE_TYPE_CODE_FICC_ADMIN, utils.ROLE_TYPE_CODE_ADMIN, utils.ROLE_TYPE_CODE_RAI_ADMIN:
- //管理员、超管看全部数据
- companyReportRecordResp.List = tmpList
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = companyReportRecordResp
- }
- // SellerYbUserLog
- // @Title 收藏统计用户详情
- // @Description 分产品阅读统计用户详情
- // @Param request body statisticModels.SellerYbUserLogReq true "type json string"
- // @Success 200 {object} statistic_report.CompanyListResp
- // @router /report/seller_collect_log/user [post]
- func (s *StatisticYbLogController) SellerCollectUserLog() {
- br := new(models.BaseResponse).Init()
- defer func() {
- s.Data["json"] = br
- s.ServeJSON()
- }()
- sysUser := s.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req yb.SellerCollectUserLogReq
- err := json.Unmarshal(s.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- //todo 校验入参
- if req.SellerIds == "" {
- br.Msg = "请输入销售ID"
- return
- }
- if req.StartDate == "" {
- br.Msg = "请输入开始时间"
- return
- }
- if req.EndDate == "" {
- br.Msg = "请输入截止时间"
- return
- }
- if req.CompanyStatus == "" {
- br.Msg = "请输入产品状态"
- return
- }
- resp, err, errMsg := statistic_report.YbCollectUserList(sysUser, req)
- if err != nil {
- br.Msg = err.Error()
- br.ErrMsg = errMsg
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // CollectDetailList
- // @Title 收藏详情
- // @Description 收藏详情
- // @Param request body statisticModels.SellerYbUserLogReq true "type json string"
- // @Success 200 {object} statistic_report.CompanyListResp
- // @router /report/seller_collect_log/detail [post]
- func (s *StatisticYbLogController) CollectList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- s.Data["json"] = br
- s.ServeJSON()
- }()
- sysUser := s.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req yb.CollectListReq
- err := json.Unmarshal(s.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- //todo 校验入参
- if req.UserId == 0 {
- br.Msg = "请输入联系人ID"
- return
- }
- if req.SellerIds == "" {
- br.Msg = "请输入销售ID"
- return
- }
- if req.StartDate == "" {
- br.Msg = "请输入开始时间"
- return
- }
- if req.EndDate == "" {
- br.Msg = "请输入截止时间"
- return
- }
- if req.CompanyStatus == "" {
- br.Msg = "请输入产品状态"
- return
- }
- resp, err, errMsg := statistic_report.YbCollectList(sysUser, req)
- if err != nil {
- br.Msg = err.Error()
- br.ErrMsg = errMsg
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // SellerYbChartCollectLog
- // @Title 图收藏统计
- // @Description 图收藏统计
- // @Param DataType query string true "枚举值:week、month、time_interval"
- // @Success 200 {object} statistic_report.CompanyReportRecordResp
- // @router /report/seller_chart_collect_log [get]
- func (s *StatisticYbLogController) SellerYbChartCollectLog() {
- br := new(models.BaseResponse).Init()
- defer func() {
- s.Data["json"] = br
- s.ServeJSON()
- }()
- sysUser := s.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- dataType := s.GetString("DataType")
- if dataType == "" {
- br.Msg = "请输入时间类型"
- return
- }
- var companyReportDataMapList []statistic_report.SellerYbLogDataMap
- var err error
- var firstDate time.Time
- switch dataType {
- //获取列表
- case "week":
- nowWeekMonday := utils.GetNowWeekMonday() //本周周一
- companyReportDataMapList, firstDate, err = statistic_report.GetYbChartCollectLogWeekDataNum(nowWeekMonday, 6)
- if err != nil {
- br.Msg = "数据异常"
- br.ErrMsg = "数据异常,Err:" + err.Error()
- return
- }
- case "month":
- nowMonthFirstDay := utils.GetNowMonthFirstDay() //本月第一天
- companyReportDataMapList, firstDate, err = statistic_report.GetYbChartCollectLogMonthDataNum(nowMonthFirstDay, 6)
- if err != nil {
- br.Msg = "数据异常"
- br.ErrMsg = "数据异常,Err:" + err.Error()
- return
- }
- }
- //获取销售人员分组数据
- var group []services.AdminGroup
- var groupIdRelationMap map[int]int
- var groupMap map[int][]*roadshow.Researcher
- group, groupIdRelationMap, err = services.GetFiccSystemGroup()
- if err != nil {
- br.Msg = "获取信息失败!"
- br.ErrMsg = "获取分组信息失败!Err:" + err.Error()
- return
- }
- researcherList, tmpErr := services.GetFiccSeller(firstDate, groupIdRelationMap)
- if tmpErr != nil {
- err = tmpErr
- }
- 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([]statistic_report.GroupYbLogRecord, 0)
- allCompanyReportRecordNum := make([]statistic_report.SellerYbLogRecordNum, 0)
- companyReportRecordResp := statistic_report.SellerYbLogRecordResp{
- List: groupReportRecordList,
- SellerYbLogRecordNumList: allCompanyReportRecordNum,
- }
- startDateIndexList := make(map[int]string) //开始时间间隔map
- endDateIndexList := make(map[int]string) //结束时间间隔map
- //客户数汇总
- tmpAllTryOutNumMap := make(map[int]int)
- tmpAllFormalNumMap := make(map[int]int)
- tmpAllAllNumMap := make(map[int]int)
- //id集合汇总
- tmpAllTryOutIdMap := make(map[int]string)
- tmpAllFormalIdMap := make(map[int]string)
- tmpAllAllIdMap := make(map[int]string)
- for _, v := range group {
- v.ResearcherList = groupMap[v.GroupId]
- tmpGroupAdminReportRecord := make([]statistic_report.AdminYbLogRecord, 0)
- tmpGroupCompanyReportRecordNumList := make([]statistic_report.SellerYbLogRecordNum, 0)
- //数量统计
- tmpGroupTryOutNumMap := make(map[int]int)
- tmpGroupFormalNumMap := make(map[int]int)
- tmpGroupAllNumMap := make(map[int]int)
- //id集合
- tmpGroupTryOutIdSliceMap := make(map[int][]string)
- tmpGroupFormalIdSliceMap := make(map[int][]string)
- tmpGroupAllIdSliceMap := make(map[int][]string)
- //id集合
- tmpGroupTryOutIdMap := make(map[int]string)
- tmpGroupFormalIdMap := make(map[int]string)
- tmpGroupAllIdMap := make(map[int]string)
- for _, researcher := range groupMap[v.GroupId] {
- //组内研究员数据
- //每个区间的数据
- tmpCompanyReportRecordNumList := make([]statistic_report.SellerYbLogRecordNum, 0)
- for index, adminData := range companyReportDataMapList {
- startDateIndexList[index] = adminData.StartDate
- endDateIndexList[index] = adminData.EndDate
- var tmpTryOutNum, tmpFormalNum, tmpAllNum int
- var tmpTryOutIdSlice, tmpFormalIdSlice, tmpAllIdSlice []string
- var tmpTryOutId, tmpFormalId, tmpAllId string
- if num, ok := adminData.TryOutMap[researcher.AdminId]; ok {
- tmpTryOutNum = num
- tmpTryOutIdSlice = append(tmpTryOutIdSlice, adminData.TryOutIdMap[researcher.AdminId])
- tmpTryOutId = strings.Join(tmpTryOutIdSlice, ",")
- }
- if num, ok := adminData.FormalMap[researcher.AdminId]; ok {
- tmpFormalNum = num
- tmpFormalIdSlice = append(tmpFormalIdSlice, adminData.FormalIdMap[researcher.AdminId])
- tmpFormalId = strings.Join(tmpFormalIdSlice, ",")
- }
- if num, ok := adminData.AllMap[researcher.AdminId]; ok {
- tmpAllNum = num
- tmpAllIdSlice = append(tmpAllIdSlice, adminData.AllIdMap[researcher.AdminId])
- tmpAllId = strings.Join(tmpAllIdSlice, ",")
- }
- tmpAdminRsReportRecordNum := statistic_report.SellerYbLogRecordNum{
- TryOutNum: tmpTryOutNum,
- TryOutIds: tmpTryOutId,
- FormalNum: tmpFormalNum,
- FormalIds: tmpFormalId,
- AllNum: tmpAllNum,
- AllIds: tmpAllId,
- StartDate: adminData.StartDate,
- EndDate: adminData.EndDate,
- }
- tmpCompanyReportRecordNumList = append(tmpCompanyReportRecordNumList, tmpAdminRsReportRecordNum)
- //组内数据汇总
- if _, ok := tmpGroupTryOutNumMap[index]; !ok {
- tmpGroupTryOutNumMap[index] = 0
- }
- if _, ok := tmpGroupFormalNumMap[index]; !ok {
- tmpGroupFormalNumMap[index] = 0
- }
- if _, ok := tmpGroupAllNumMap[index]; !ok {
- tmpGroupAllNumMap[index] = 0
- }
- tmpGroupTryOutNumMap[index] += tmpTryOutNum
- tmpGroupFormalNumMap[index] += tmpFormalNum
- tmpGroupAllNumMap[index] += tmpAllNum
- //组内数据汇总
- if tmpTryOutId != "" {
- tmpGroupTryOutIdSliceMap[index] = append(tmpGroupTryOutIdSliceMap[index], tmpTryOutId)
- }
- if tmpFormalId != "" {
- tmpGroupFormalIdSliceMap[index] = append(tmpGroupFormalIdSliceMap[index], tmpFormalId)
- }
- if tmpAllId != "" {
- tmpGroupAllIdSliceMap[index] = append(tmpGroupAllIdSliceMap[index], tmpAllId)
- }
- tmpAllTryOutNumMap[index] += tmpTryOutNum
- tmpAllFormalNumMap[index] += tmpFormalNum
- tmpAllAllNumMap[index] += tmpAllNum
- tmpAllTryOutIdMap[index] += tmpTryOutId
- tmpAllFormalIdMap[index] += tmpFormalId
- tmpAllAllIdMap[index] += tmpAllId
- }
- tmpAdminReportRecord := statistic_report.AdminYbLogRecord{
- Name: researcher.RealName,
- AdminId: researcher.AdminId,
- SellerYbLogRecordNumList: tmpCompanyReportRecordNumList,
- }
- tmpGroupAdminReportRecord = append(tmpGroupAdminReportRecord, tmpAdminReportRecord)
- }
- for i := 0; i < len(tmpGroupAllNumMap); i++ {
- tmpGroupTryOutIdMap[i] = strings.Join(tmpGroupTryOutIdSliceMap[i], ",")
- tmpGroupFormalIdMap[i] = strings.Join(tmpGroupFormalIdSliceMap[i], ",")
- tmpGroupAllIdMap[i] = strings.Join(tmpGroupAllIdSliceMap[i], ",")
- tmpGroupCompanyReportRecordNum := statistic_report.SellerYbLogRecordNum{
- TryOutNum: tmpGroupTryOutNumMap[i],
- TryOutIds: tmpGroupTryOutIdMap[i],
- FormalNum: tmpGroupFormalNumMap[i],
- FormalIds: tmpGroupFormalIdMap[i],
- AllNum: tmpGroupAllNumMap[i],
- AllIds: tmpGroupAllIdMap[i],
- StartDate: startDateIndexList[i],
- EndDate: endDateIndexList[i],
- }
- tmpGroupCompanyReportRecordNumList = append(tmpGroupCompanyReportRecordNumList, tmpGroupCompanyReportRecordNum)
- }
- groupReportRecord := statistic_report.GroupYbLogRecord{
- Item: tmpGroupAdminReportRecord,
- Name: v.GroupName,
- GroupId: v.GroupId,
- SellerYbLogRecordNumList: tmpGroupCompanyReportRecordNumList,
- }
- groupReportRecordList = append(groupReportRecordList, groupReportRecord)
- }
- //总体汇总数据
- for i := 0; i < len(tmpAllFormalNumMap); i++ {
- tmpGroupCompanyReportRecordNum := statistic_report.SellerYbLogRecordNum{
- TryOutNum: tmpAllTryOutNumMap[i],
- TryOutIds: "",
- FormalNum: tmpAllFormalNumMap[i],
- FormalIds: "",
- AllNum: tmpAllAllNumMap[i],
- AllIds: "",
- StartDate: startDateIndexList[i],
- EndDate: endDateIndexList[i],
- }
- allCompanyReportRecordNum = append(allCompanyReportRecordNum, tmpGroupCompanyReportRecordNum)
- }
- companyReportRecordResp.SellerYbLogRecordNumList = allCompanyReportRecordNum
- 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.GroupId != adminGroupId {
- tmpList[index].Item = make([]statistic_report.AdminYbLogRecord, 0)
- } else {
- tmpList[index], tmpList[0] = tmpList[0], tmpList[index]
- }
- }
- companyReportRecordResp.List = tmpList
- case utils.ROLE_TYPE_CODE_RAI_GROUP:
- for index, v := range tmpList {
- //如果不是同一个分组,那么就移除该分组下的人员数据
- if v.GroupId != adminGroupId {
- tmpList[index].Item = make([]statistic_report.AdminYbLogRecord, 0)
- } else {
- tmpList[index], tmpList[0] = tmpList[0], tmpList[index]
- }
- }
- companyReportRecordResp.List = tmpList
- case utils.ROLE_TYPE_CODE_FICC_ADMIN, utils.ROLE_TYPE_CODE_ADMIN, utils.ROLE_TYPE_CODE_RAI_ADMIN:
- //管理员、超管看全部数据
- companyReportRecordResp.List = tmpList
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = companyReportRecordResp
- }
- // SellerChartCollectUserLog
- // @Title 图收藏统计用户详情
- // @Description 图收藏统计用户详情
- // @Param request body statisticModels.SellerYbUserLogReq true "type json string"
- // @Success 200 {object} statistic_report.CompanyListResp
- // @router /report/seller_chart_collect_log/user [post]
- func (s *StatisticYbLogController) SellerChartCollectUserLog() {
- br := new(models.BaseResponse).Init()
- defer func() {
- s.Data["json"] = br
- s.ServeJSON()
- }()
- sysUser := s.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req yb.SellerChartCollectUserLogReq
- err := json.Unmarshal(s.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- //todo 校验入参
- if req.SellerIds == "" {
- br.Msg = "请输入销售ID"
- return
- }
- if req.StartDate == "" {
- br.Msg = "请输入开始时间"
- return
- }
- if req.EndDate == "" {
- br.Msg = "请输入截止时间"
- return
- }
- if req.CompanyStatus == "" {
- br.Msg = "请输入产品状态"
- return
- }
- resp, err, errMsg := statistic_report.YbChartCollectUserList(sysUser, req)
- if err != nil {
- br.Msg = err.Error()
- br.ErrMsg = errMsg
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // CollectDetailList
- // @Title 图收藏详情
- // @Description 图收藏详情
- // @Param request body statisticModels.SellerYbUserLogReq true "type json string"
- // @Success 200 {object} statistic_report.CompanyListResp
- // @router /report/seller_chart_collect_log/detail [post]
- func (s *StatisticYbLogController) ChartCollectList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- s.Data["json"] = br
- s.ServeJSON()
- }()
- sysUser := s.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req yb.ChartCollectListReq
- err := json.Unmarshal(s.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- //todo 校验入参
- if req.UserId == 0 {
- br.Msg = "请输入联系人ID"
- return
- }
- if req.SellerIds == "" {
- br.Msg = "请输入销售ID"
- return
- }
- if req.StartDate == "" {
- br.Msg = "请输入开始时间"
- return
- }
- if req.EndDate == "" {
- br.Msg = "请输入截止时间"
- return
- }
- if req.CompanyStatus == "" {
- br.Msg = "请输入产品状态"
- return
- }
- resp, err, errMsg := statistic_report.YbChartCollectList(sysUser, req)
- if err != nil {
- br.Msg = err.Error()
- br.ErrMsg = errMsg
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
|