report.go 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765
  1. package roadshow
  2. import (
  3. "encoding/json"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hz_crm_api/models"
  6. "hongze/hz_crm_api/models/company"
  7. "hongze/hz_crm_api/models/roadshow"
  8. "hongze/hz_crm_api/models/system"
  9. "hongze/hz_crm_api/services"
  10. roadshowService "hongze/hz_crm_api/services/roadshow"
  11. "hongze/hz_crm_api/utils"
  12. "strconv"
  13. "strings"
  14. "time"
  15. )
  16. // ResearcherReportList
  17. // @Title 研究员路演统计
  18. // @Description 研究员路演统计接口
  19. // @Param DataType query string true "枚举值:week、month、time_interval"
  20. // @Param StartDate query string true "开始日期,格式:2022-04-06"
  21. // @Param EndDate query string true "结束日期,格式:2022-04-06"
  22. // @Success 200 {object} roadshow.RsReportRecordResp
  23. // @router /report/researcher/list [get]
  24. func (this *CalendarController) ResearcherReportList() {
  25. br := new(models.BaseResponse).Init()
  26. defer func() {
  27. this.Data["json"] = br
  28. this.ServeJSON()
  29. }()
  30. sysUser := this.SysUser
  31. if sysUser == nil {
  32. br.Msg = "请登录"
  33. br.ErrMsg = "请登录,SysUser Is Empty"
  34. br.Ret = 408
  35. return
  36. }
  37. dataType := this.GetString("DataType")
  38. startDate := this.GetString("StartDate")
  39. endDate := this.GetString("EndDate")
  40. var adminDataList []roadshowService.AdminDataMap
  41. var err error
  42. //var firstDate time.Time
  43. //获取列表
  44. switch dataType {
  45. case "week":
  46. adminDataList, _, err = roadshowService.GetWeekData("researcher", "company_status")
  47. if err != nil {
  48. br.Msg = "数据异常"
  49. br.ErrMsg = "数据异常,Err:" + err.Error()
  50. return
  51. }
  52. case "month":
  53. adminDataList, _, err = roadshowService.GetMonthData("researcher", "company_status")
  54. if err != nil {
  55. br.Msg = "数据异常"
  56. br.ErrMsg = "数据异常,Err:" + err.Error()
  57. return
  58. }
  59. case "time_interval":
  60. if startDate == `` || endDate == `` {
  61. br.Msg = "开始日期或结束日期不能为空"
  62. br.ErrMsg = "开始日期或结束日期不能为空,Err:" + err.Error()
  63. return
  64. }
  65. adminDataList, _, err = roadshowService.GetTimeIntervalData(startDate, endDate, "researcher", "company_status")
  66. if err != nil {
  67. br.Msg = "数据异常"
  68. br.ErrMsg = "数据异常,Err:" + err.Error()
  69. return
  70. }
  71. }
  72. group, err := roadshow.GetResearcherGroup()
  73. if err != nil {
  74. br.Msg = "获取信息失败!"
  75. br.ErrMsg = "获取分组信息失败!Err:" + err.Error()
  76. return
  77. }
  78. researcherList, err := roadshow.GetResearcherV2()
  79. if err != nil {
  80. br.Msg = "获取信息失败!"
  81. br.ErrMsg = "获取分组信息失败!,GetResearcherV2 Err:" + err.Error()
  82. return
  83. }
  84. groupMap := make(map[int][]*roadshow.ResearcherGroup)
  85. for _, v := range researcherList {
  86. item := &roadshow.ResearcherGroup{
  87. GroupId: v.GroupId,
  88. GroupName: v.GroupName,
  89. AdminId: v.AdminId,
  90. RealName: v.RealName,
  91. RoleTypeCode: v.RoleTypeCode,
  92. }
  93. if findItems, ok := groupMap[v.GroupId]; ok {
  94. findItems = append(findItems, item)
  95. groupMap[v.GroupId] = findItems
  96. } else {
  97. findItems = append(findItems, item)
  98. groupMap[v.GroupId] = findItems
  99. }
  100. //}
  101. }
  102. for _, v := range group {
  103. v.ResearcherList = groupMap[v.GroupId]
  104. }
  105. groupReportRecordList := make([]roadshow.GroupReportRecord, 0)
  106. rsAllReportRecordNumList := make([]roadshow.RsReportRecordNum, 0)
  107. RsReportRecordResp := roadshow.RsReportRecordResp{
  108. List: groupReportRecordList,
  109. RsReportRecordNumList: rsAllReportRecordNumList,
  110. }
  111. startDateIndexList := make(map[int]string) //开始时间间隔map
  112. endDateIndexList := make(map[int]string) //结束时间间隔map
  113. tmpAllTryOutNumMap := make(map[int]int)
  114. tmpAllFormalNumMap := make(map[int]int)
  115. tmpAllMeetingNumMap := make(map[int]int)
  116. for _, v := range group {
  117. v.ResearcherList = groupMap[v.GroupId]
  118. tmpGroupAdminReportRecord := make([]roadshow.AdminReportRecord, 0)
  119. tmpGroupRsReportRecordNumList := make([]roadshow.RsReportRecordNum, 0)
  120. tmpGroupTryOutNumMap := make(map[int]int)
  121. tmpGroupFormalNumMap := make(map[int]int)
  122. tmpGroupMeetingNumMap := make(map[int]int)
  123. for _, researcher := range groupMap[v.GroupId] {
  124. //组内研究员数据
  125. //每个区间的数据
  126. tmpAdminRsReportRecordNumList := make([]roadshow.RsReportRecordNum, 0)
  127. for index, adminData := range adminDataList {
  128. startDateIndexList[index] = adminData.StartDate
  129. endDateIndexList[index] = adminData.EndDate
  130. var tmpTryOutNum, tmpFormalNum, tmpMeetingNum int
  131. if num, ok := adminData.TryOutMap[researcher.AdminId]; ok {
  132. tmpTryOutNum = num
  133. }
  134. if num, ok := adminData.FormalMap[researcher.AdminId]; ok {
  135. tmpFormalNum = num
  136. }
  137. if num, ok := adminData.MeetingMap[researcher.AdminId]; ok {
  138. tmpMeetingNum = num
  139. }
  140. tmpAdminRsReportRecordNum := roadshow.RsReportRecordNum{
  141. TryOutNum: tmpTryOutNum,
  142. FormalNum: tmpFormalNum,
  143. MeetingNum: tmpMeetingNum,
  144. StartDate: adminData.StartDate,
  145. EndDate: adminData.EndDate,
  146. }
  147. tmpAdminRsReportRecordNumList = append(tmpAdminRsReportRecordNumList, tmpAdminRsReportRecordNum)
  148. //组内数据汇总
  149. if _, ok := tmpGroupTryOutNumMap[index]; !ok {
  150. tmpGroupTryOutNumMap[index] = 0
  151. }
  152. if _, ok := tmpGroupFormalNumMap[index]; !ok {
  153. tmpGroupFormalNumMap[index] = 0
  154. }
  155. if _, ok := tmpGroupMeetingNumMap[index]; !ok {
  156. tmpGroupMeetingNumMap[index] = 0
  157. }
  158. tmpGroupTryOutNumMap[index] += tmpTryOutNum
  159. tmpGroupFormalNumMap[index] += tmpFormalNum
  160. tmpGroupMeetingNumMap[index] += tmpMeetingNum
  161. //总数据汇总
  162. if _, ok := tmpAllTryOutNumMap[index]; !ok {
  163. tmpAllTryOutNumMap[index] = 0
  164. }
  165. if _, ok := tmpAllFormalNumMap[index]; !ok {
  166. tmpAllFormalNumMap[index] = 0
  167. }
  168. if _, ok := tmpAllMeetingNumMap[index]; !ok {
  169. tmpAllMeetingNumMap[index] = 0
  170. }
  171. tmpAllTryOutNumMap[index] += tmpTryOutNum
  172. tmpAllFormalNumMap[index] += tmpFormalNum
  173. tmpAllMeetingNumMap[index] += tmpMeetingNum
  174. }
  175. tmpAdminReportRecord := roadshow.AdminReportRecord{
  176. Name: researcher.RealName,
  177. AdminId: researcher.AdminId,
  178. RsReportRecordNumList: tmpAdminRsReportRecordNumList,
  179. }
  180. tmpGroupAdminReportRecord = append(tmpGroupAdminReportRecord, tmpAdminReportRecord)
  181. }
  182. for i := 0; i < len(tmpGroupMeetingNumMap); i++ {
  183. tmpGroupRsReportRecordNum := roadshow.RsReportRecordNum{
  184. TryOutNum: tmpGroupTryOutNumMap[i],
  185. FormalNum: tmpGroupFormalNumMap[i],
  186. MeetingNum: tmpGroupMeetingNumMap[i],
  187. StartDate: startDateIndexList[i],
  188. EndDate: endDateIndexList[i],
  189. }
  190. tmpGroupRsReportRecordNumList = append(tmpGroupRsReportRecordNumList, tmpGroupRsReportRecordNum)
  191. }
  192. groupReportRecord := roadshow.GroupReportRecord{
  193. Item: tmpGroupAdminReportRecord,
  194. Name: v.GroupName,
  195. RsReportRecordNumList: tmpGroupRsReportRecordNumList,
  196. }
  197. RsReportRecordResp.List = append(RsReportRecordResp.List, groupReportRecord)
  198. }
  199. //总体汇总数据
  200. for i := 0; i < len(tmpAllFormalNumMap); i++ {
  201. tmpGroupRsReportRecordNum := roadshow.RsReportRecordNum{
  202. TryOutNum: tmpAllTryOutNumMap[i],
  203. FormalNum: tmpAllFormalNumMap[i],
  204. MeetingNum: tmpAllMeetingNumMap[i],
  205. StartDate: startDateIndexList[i],
  206. EndDate: endDateIndexList[i],
  207. }
  208. rsAllReportRecordNumList = append(rsAllReportRecordNumList, tmpGroupRsReportRecordNum)
  209. }
  210. RsReportRecordResp.RsReportRecordNumList = rsAllReportRecordNumList
  211. br.Ret = 200
  212. br.Success = true
  213. br.Msg = "获取成功"
  214. br.Data = RsReportRecordResp
  215. return
  216. }
  217. // SellerReportList
  218. // @Title 销售路演统计
  219. // @Description 销售路演统计接口
  220. // @Param DataType query string true "枚举值:week、month、time_interval、online、offline"
  221. // @Param DimensionType query string true "维度枚举值:company_status、roadshow_type"
  222. // @Param StartDate query string true "开始日期,格式:2022-04-06"
  223. // @Param EndDate query string true "结束日期,格式:2022-04-06"
  224. // @Success 200 {object} roadshow.RsReportRecordResp
  225. // @router /report/seller/list [get]
  226. func (this *CalendarController) SellerReportList() {
  227. br := new(models.BaseResponse).Init()
  228. defer func() {
  229. this.Data["json"] = br
  230. this.ServeJSON()
  231. }()
  232. sysUser := this.SysUser
  233. if sysUser == nil {
  234. br.Msg = "请登录"
  235. br.ErrMsg = "请登录,SysUser Is Empty"
  236. br.Ret = 408
  237. return
  238. }
  239. dataType := this.GetString("DataType")
  240. dimensionType := this.GetString("DimensionType")
  241. startDate := this.GetString("StartDate")
  242. endDate := this.GetString("EndDate")
  243. if dimensionType == "" {
  244. dimensionType = "company_status"
  245. }
  246. var adminDataList []roadshowService.AdminDataMap
  247. var err error
  248. var firstDate time.Time
  249. //获取列表
  250. switch dataType {
  251. case "week":
  252. adminDataList, firstDate, err = roadshowService.GetWeekDataV2("seller", dimensionType, 6)
  253. if err != nil {
  254. br.Msg = "数据异常"
  255. br.ErrMsg = "数据异常,Err:" + err.Error()
  256. return
  257. }
  258. case "month":
  259. adminDataList, firstDate, err = roadshowService.GetMonthDataV2("seller", dimensionType, 6)
  260. if err != nil {
  261. br.Msg = "数据异常"
  262. br.ErrMsg = "数据异常,Err:" + err.Error()
  263. return
  264. }
  265. case "time_interval":
  266. if startDate == `` || endDate == `` {
  267. br.Msg = "开始日期或结束日期不能为空"
  268. br.ErrMsg = "开始日期或结束日期不能为空,Err:" + err.Error()
  269. return
  270. }
  271. adminDataList, firstDate, err = roadshowService.GetTimeIntervalData(startDate, endDate, "seller", dimensionType)
  272. if err != nil {
  273. br.Msg = "数据异常"
  274. br.ErrMsg = "数据异常,Err:" + err.Error()
  275. return
  276. }
  277. }
  278. group, groupIdRelationMap, err := services.GetFiccSystemGroup()
  279. if err != nil {
  280. br.Msg = "获取信息失败!"
  281. br.ErrMsg = "获取分组信息失败!Err:" + err.Error()
  282. return
  283. }
  284. researcherList, err := services.GetFiccSeller(firstDate, groupIdRelationMap)
  285. groupMap := make(map[int][]*roadshow.Researcher)
  286. for _, v := range researcherList {
  287. if v.RoleTypeCode == "ficc_admin" {
  288. findItems := groupMap[1]
  289. findItems = append(findItems, v)
  290. groupMap[1] = findItems
  291. } else {
  292. if findItems, ok := groupMap[v.GroupId]; ok {
  293. findItems = append(findItems, v)
  294. groupMap[v.GroupId] = findItems
  295. } else {
  296. findItems = append(findItems, v)
  297. groupMap[v.GroupId] = findItems
  298. }
  299. }
  300. }
  301. groupReportRecordList := make([]roadshow.GroupReportRecord, 0)
  302. rsAllReportRecordNumList := make([]roadshow.RsReportRecordNum, 0)
  303. RsReportRecordResp := roadshow.RsReportRecordResp{
  304. List: groupReportRecordList,
  305. RsReportRecordNumList: rsAllReportRecordNumList,
  306. }
  307. startDateIndexList := make(map[int]string) //开始时间间隔map
  308. endDateIndexList := make(map[int]string) //结束时间间隔map
  309. tmpAllTryOutNumMap := make(map[int]int)
  310. tmpAllFormalNumMap := make(map[int]int)
  311. tmpAllMeetingNumMap := make(map[int]int)
  312. tmpAllOnlineNumMap := make(map[int]int)
  313. tmpAllOfflineNumMap := make(map[int]int)
  314. for _, v := range group {
  315. v.ResearcherList = groupMap[v.GroupId]
  316. tmpGroupAdminReportRecord := make([]roadshow.AdminReportRecord, 0)
  317. tmpGroupRsReportRecordNumList := make([]roadshow.RsReportRecordNum, 0)
  318. tmpGroupTryOutNumMap := make(map[int]int)
  319. tmpGroupFormalNumMap := make(map[int]int)
  320. tmpGroupMeetingNumMap := make(map[int]int)
  321. tmpGroupOnlineNumMap := make(map[int]int)
  322. tmpGroupOfflineNumMap := make(map[int]int)
  323. for _, researcher := range groupMap[v.GroupId] {
  324. //组内研究员数据
  325. //每个区间的数据
  326. tmpAdminRsReportRecordNumList := make([]roadshow.RsReportRecordNum, 0)
  327. for index, adminData := range adminDataList {
  328. startDateIndexList[index] = adminData.StartDate
  329. endDateIndexList[index] = adminData.EndDate
  330. var tmpTryOutNum, tmpFormalNum, tmpMeetingNum, tmpOnlineNum, tmpOfflineNum int
  331. if num, ok := adminData.TryOutMap[researcher.AdminId]; ok {
  332. tmpTryOutNum = num
  333. }
  334. if num, ok := adminData.FormalMap[researcher.AdminId]; ok {
  335. tmpFormalNum = num
  336. }
  337. if num, ok := adminData.MeetingMap[researcher.AdminId]; ok {
  338. tmpMeetingNum = num
  339. }
  340. if num, ok := adminData.OnlineMap[researcher.AdminId]; ok {
  341. tmpOnlineNum = num
  342. }
  343. if num, ok := adminData.OfflineMap[researcher.AdminId]; ok {
  344. tmpOfflineNum = num
  345. }
  346. tmpAdminRsReportRecordNum := roadshow.RsReportRecordNum{
  347. TryOutNum: tmpTryOutNum,
  348. FormalNum: tmpFormalNum,
  349. MeetingNum: tmpMeetingNum,
  350. OnlineNum: tmpOnlineNum,
  351. OfflineNum: tmpOfflineNum,
  352. StartDate: adminData.StartDate,
  353. EndDate: adminData.EndDate,
  354. }
  355. tmpAdminRsReportRecordNumList = append(tmpAdminRsReportRecordNumList, tmpAdminRsReportRecordNum)
  356. //组内数据汇总
  357. if _, ok := tmpGroupTryOutNumMap[index]; !ok {
  358. tmpGroupTryOutNumMap[index] = 0
  359. }
  360. if _, ok := tmpGroupFormalNumMap[index]; !ok {
  361. tmpGroupFormalNumMap[index] = 0
  362. }
  363. if _, ok := tmpGroupMeetingNumMap[index]; !ok {
  364. tmpGroupMeetingNumMap[index] = 0
  365. }
  366. if _, ok := tmpGroupOnlineNumMap[index]; !ok {
  367. tmpGroupOnlineNumMap[index] = 0
  368. }
  369. if _, ok := tmpGroupOfflineNumMap[index]; !ok {
  370. tmpGroupOfflineNumMap[index] = 0
  371. }
  372. tmpGroupTryOutNumMap[index] += tmpTryOutNum
  373. tmpGroupFormalNumMap[index] += tmpFormalNum
  374. tmpGroupMeetingNumMap[index] += tmpMeetingNum
  375. tmpGroupOnlineNumMap[index] += tmpOnlineNum
  376. tmpGroupOfflineNumMap[index] += tmpOfflineNum
  377. //总数据汇总
  378. if _, ok := tmpAllTryOutNumMap[index]; !ok {
  379. tmpAllTryOutNumMap[index] = 0
  380. }
  381. if _, ok := tmpAllFormalNumMap[index]; !ok {
  382. tmpAllFormalNumMap[index] = 0
  383. }
  384. if _, ok := tmpAllMeetingNumMap[index]; !ok {
  385. tmpAllMeetingNumMap[index] = 0
  386. }
  387. if _, ok := tmpAllOnlineNumMap[index]; !ok {
  388. tmpAllOnlineNumMap[index] = 0
  389. }
  390. if _, ok := tmpAllOfflineNumMap[index]; !ok {
  391. tmpAllOfflineNumMap[index] = 0
  392. }
  393. tmpAllTryOutNumMap[index] += tmpTryOutNum
  394. tmpAllFormalNumMap[index] += tmpFormalNum
  395. tmpAllMeetingNumMap[index] += tmpMeetingNum
  396. tmpAllOnlineNumMap[index] += tmpOnlineNum
  397. tmpAllOfflineNumMap[index] += tmpOfflineNum
  398. }
  399. tmpAdminReportRecord := roadshow.AdminReportRecord{
  400. Name: researcher.RealName,
  401. AdminId: researcher.AdminId,
  402. RsReportRecordNumList: tmpAdminRsReportRecordNumList,
  403. }
  404. tmpGroupAdminReportRecord = append(tmpGroupAdminReportRecord, tmpAdminReportRecord)
  405. }
  406. for i := 0; i < len(tmpGroupMeetingNumMap); i++ {
  407. tmpGroupRsReportRecordNum := roadshow.RsReportRecordNum{
  408. TryOutNum: tmpGroupTryOutNumMap[i],
  409. FormalNum: tmpGroupFormalNumMap[i],
  410. MeetingNum: tmpGroupMeetingNumMap[i],
  411. OnlineNum: tmpGroupOnlineNumMap[i],
  412. OfflineNum: tmpGroupOfflineNumMap[i],
  413. StartDate: startDateIndexList[i],
  414. EndDate: endDateIndexList[i],
  415. }
  416. tmpGroupRsReportRecordNumList = append(tmpGroupRsReportRecordNumList, tmpGroupRsReportRecordNum)
  417. }
  418. groupReportRecord := roadshow.GroupReportRecord{
  419. Item: tmpGroupAdminReportRecord,
  420. Name: v.GroupName,
  421. GruopId: v.GroupId,
  422. RsReportRecordNumList: tmpGroupRsReportRecordNumList,
  423. }
  424. groupReportRecordList = append(groupReportRecordList, groupReportRecord)
  425. }
  426. //总体汇总数据
  427. for i := 0; i < len(tmpAllFormalNumMap); i++ {
  428. tmpGroupRsReportRecordNum := roadshow.RsReportRecordNum{
  429. TryOutNum: tmpAllTryOutNumMap[i],
  430. FormalNum: tmpAllFormalNumMap[i],
  431. MeetingNum: tmpAllMeetingNumMap[i],
  432. OnlineNum: tmpAllOnlineNumMap[i],
  433. OfflineNum: tmpAllOfflineNumMap[i],
  434. StartDate: startDateIndexList[i],
  435. EndDate: endDateIndexList[i],
  436. }
  437. rsAllReportRecordNumList = append(rsAllReportRecordNumList, tmpGroupRsReportRecordNum)
  438. }
  439. RsReportRecordResp.RsReportRecordNumList = rsAllReportRecordNumList
  440. //tmpList := groupReportRecordList
  441. //因为RoleTypeCode不一样,所以需要重新从数据库取数据
  442. //adminInfo, _ := system.GetSysAdminById(sysUser.AdminId)
  443. //adminGroupId := adminInfo.GroupId
  444. //if tmpGroupId, ok := groupIdRelationMap[adminGroupId]; ok {
  445. // adminGroupId = tmpGroupId
  446. //}
  447. //switch adminInfo.RoleTypeCode {
  448. //case utils.ROLE_TYPE_CODE_FICC_GROUP, utils.ROLE_TYPE_CODE_FICC_TEAM:
  449. // for index, v := range tmpList {
  450. // //如果不是同一个分组,那么就移除该分组下的人员数据
  451. // if v.GruopId != adminGroupId {
  452. // tmpList[index].Item = make([]roadshow.AdminReportRecord, 0)
  453. // }
  454. // }
  455. // RsReportRecordResp.List = tmpList
  456. //case utils.ROLE_TYPE_CODE_FICC_ADMIN, utils.ROLE_TYPE_CODE_ADMIN:
  457. // //管理员、超管看全部数据
  458. // RsReportRecordResp.List = groupReportRecordList
  459. //}
  460. // 20230529-有权限查看该页面的用户权限同admin
  461. RsReportRecordResp.List = groupReportRecordList
  462. br.Ret = 200
  463. br.Success = true
  464. br.Msg = "获取成功"
  465. br.Data = RsReportRecordResp
  466. return
  467. }
  468. // ReportCalendarList
  469. // @Title 路演详情列表
  470. // @Description 路演详情列表接口
  471. // @Param AdminType query string true "枚举值:researcher、seller、 special:专项路演"
  472. // @Param DataType query string true "枚举值:try_out、formal、meeting、online、offline"
  473. // @Param AdminId query int true "用户id"
  474. // @Param StartDate query string true "开始日期,格式:2022-04-06"
  475. // @Param EndDate query string true "结束日期,格式:2022-04-06"
  476. // @Success 200 {object} []roadshow.RsReportRecordList
  477. // @router /report/calendar/list [get]
  478. func (this *CalendarController) ReportCalendarList() {
  479. br := new(models.BaseResponse).Init()
  480. defer func() {
  481. this.Data["json"] = br
  482. this.ServeJSON()
  483. }()
  484. sysUser := this.SysUser
  485. if sysUser == nil {
  486. br.Msg = "请登录"
  487. br.ErrMsg = "请登录,SysUser Is Empty"
  488. br.Ret = 408
  489. return
  490. }
  491. adminType := this.GetString("AdminType")
  492. dataType := this.GetString("DataType")
  493. startDate := this.GetString("StartDate")
  494. endDate := this.GetString("EndDate")
  495. adminId, _ := this.GetInt("AdminId")
  496. if adminId <= 0 {
  497. br.Msg = "请传入对应的人员"
  498. return
  499. }
  500. //正式客户
  501. var condition string
  502. var pars []interface{}
  503. condition = ` and a.start_date >= ? and a.end_date <= ? `
  504. pars = append(pars, startDate, endDate)
  505. //选择的人员类型(发起人还是被发起人)
  506. if adminType == "seller" {
  507. condition += ` and a.seller_id = ? `
  508. } else if adminType == "special" {
  509. condition += ` and a.seller_id = ? `
  510. detail, err := company.GetConfigDetailByCode("choice_researcher_adminid")
  511. if err != nil {
  512. br.Msg = "获取研究员信息失败!"
  513. br.ErrMsg = "选择研究员失败,Err:" + err.Error()
  514. return
  515. }
  516. condition += ` and a.researcher_id IN (` + detail.ConfigValue + `) `
  517. } else {
  518. condition += ` and a.researcher_id = ? `
  519. }
  520. pars = append(pars, adminId)
  521. //获取列表
  522. switch dataType {
  523. case "try_out":
  524. condition += ` and a.company_status = ? `
  525. pars = append(pars, "试用")
  526. case "formal":
  527. condition += ` and a.company_status = ? `
  528. pars = append(pars, "正式")
  529. case "meeting":
  530. condition += ` and a.activity_type = ? `
  531. pars = append(pars, "公开会议")
  532. case "online":
  533. condition += ` and a.roadshow_type = ? `
  534. pars = append(pars, "线上")
  535. case "offline":
  536. condition += ` and a.roadshow_type = ? `
  537. pars = append(pars, "线下")
  538. default:
  539. br.Msg = "请传入类型"
  540. br.ErrMsg = "请传入类型DataType"
  541. return
  542. }
  543. list, err := roadshow.GetRsReportRecordList(condition, pars)
  544. if err != nil {
  545. br.Msg = "获取失败"
  546. br.ErrMsg = "获取失败,ERR:" + err.Error()
  547. return
  548. }
  549. br.Ret = 200
  550. br.Success = true
  551. br.Msg = "获取成功"
  552. br.Data = list
  553. return
  554. }
  555. // ChoiceResearcher
  556. // @Title 选择的研究员
  557. // @Description 选择的研究员接口
  558. // @Param AdminIds query string true "研究员ID ,多个用 , 隔开"
  559. // @Success 200 操作成功
  560. // @router /report/choice/researcher [post]
  561. func (this *CalendarController) ChoiceResearcher() {
  562. br := new(models.BaseResponse).Init()
  563. defer func() {
  564. this.Data["json"] = br
  565. this.ServeJSON()
  566. }()
  567. sysUser := this.SysUser
  568. if sysUser == nil {
  569. br.Msg = "请登录"
  570. br.ErrMsg = "请登录,SysUser Is Empty"
  571. br.Ret = 408
  572. return
  573. }
  574. var req roadshow.ResearcherIds
  575. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  576. if err != nil {
  577. br.Msg = "参数解析异常!"
  578. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  579. return
  580. }
  581. if req.AdminIds == "" {
  582. req.AdminIds = "0"
  583. }
  584. adminIdArr := strings.Split(req.AdminIds, ",")
  585. for _, v := range adminIdArr {
  586. _, err := strconv.Atoi(v)
  587. if err != nil {
  588. br.Msg = "选择研究员失败!"
  589. br.ErrMsg = "选择研究员失败,Err:" + err.Error()
  590. return
  591. }
  592. }
  593. err = company.CrmConfigUpdate(req.AdminIds, "choice_researcher_adminid")
  594. if err != nil {
  595. br.Msg = "操作失败"
  596. br.ErrMsg = "操作失败,Err:" + err.Error()
  597. return
  598. }
  599. br.Ret = 200
  600. br.Success = true
  601. br.Msg = "操作成功"
  602. return
  603. }
  604. // AdminList
  605. // @Title 选择的研究员列表
  606. // @Description 获取选择的研究员列表
  607. // @Success 200 {object} roadshow.Researcher
  608. // @Success 200 操作成功
  609. // @router /report/admin/list [get]
  610. func (this *CalendarController) AdminList() {
  611. br := new(models.BaseResponse).Init()
  612. defer func() {
  613. this.Data["json"] = br
  614. this.ServeJSON()
  615. }()
  616. sysUser := this.SysUser
  617. if sysUser == nil {
  618. br.Msg = "请登录"
  619. br.ErrMsg = "请登录,SysUser Is Empty"
  620. br.Ret = 408
  621. return
  622. }
  623. detail, err := company.GetConfigDetailByCode("choice_researcher_adminid")
  624. if err != nil {
  625. br.Msg = "获取研究员信息失败!"
  626. br.ErrMsg = "选择研究员失败,Err:" + err.Error()
  627. return
  628. }
  629. list, err := roadshow.GetChoiceResearcher(detail.ConfigValue)
  630. if err != nil {
  631. br.Msg = "操作失败"
  632. br.ErrMsg = "操作失败,Err:" + err.Error()
  633. return
  634. }
  635. br.Ret = 200
  636. br.Success = true
  637. br.Msg = "操作成功"
  638. br.Data = list
  639. return
  640. }
  641. // SellerReportList
  642. // @Title 专项路演统计
  643. // @Description 专项路演统计接口
  644. // @Success 200 {object} roadshow.RsReportRecordResp
  645. // @router /report/special/list [get]
  646. func (this *CalendarController) SpecialReportList() {
  647. br := new(models.BaseResponse).Init()
  648. defer func() {
  649. this.Data["json"] = br
  650. this.ServeJSON()
  651. }()
  652. sysUser := this.SysUser
  653. if sysUser == nil {
  654. br.Msg = "请登录"
  655. br.ErrMsg = "请登录,SysUser Is Empty"
  656. br.Ret = 408
  657. return
  658. }
  659. dimensionType := this.GetString("DimensionType")
  660. if dimensionType == "" {
  661. dimensionType = "seller_special"
  662. }
  663. var adminDataList []roadshowService.AdminDataMap
  664. var err error
  665. var firstDate time.Time
  666. //获取列表
  667. adminDataList, firstDate, err = roadshowService.GetWeekData("seller", dimensionType)
  668. if err != nil {
  669. br.Msg = "数据异常"
  670. br.ErrMsg = "数据异常,Err:" + err.Error()
  671. return
  672. }
  673. var haveData bool
  674. detail, err := company.GetConfigDetailByCode("choice_researcher_adminid")
  675. if err != nil {
  676. br.Msg = "获取信息失败!"
  677. br.ErrMsg = "获取选择研究员信息失败,Err:" + err.Error()
  678. return
  679. }
  680. adminMap := make(map[int]int)
  681. adminIdArr := strings.Split(detail.ConfigValue, ",")
  682. for _, v := range adminIdArr {
  683. adminId, err := strconv.Atoi(v)
  684. if err != nil {
  685. br.Msg = "获取信息失败!"
  686. br.ErrMsg = "获取选择研究员信息失败,Err:" + err.Error()
  687. return
  688. }
  689. adminMap[adminId] = adminId
  690. }
  691. group, groupIdRelationMap, err := services.GetFiccSystemGroup()
  692. if err != nil {
  693. br.Msg = "获取信息失败!"
  694. br.ErrMsg = "获取分组信息失败!Err:" + err.Error()
  695. return
  696. }
  697. researcherList, err := services.GetFiccSeller(firstDate, groupIdRelationMap)
  698. groupMap := make(map[int][]*roadshow.Researcher)
  699. for _, v := range researcherList {
  700. //if v.RoleTypeCode == "ficc_admin" {
  701. // findItems := groupMap[1]
  702. // findItems = append(findItems, v)
  703. // groupMap[1] = findItems
  704. //} else {
  705. if findItems, ok := groupMap[v.GroupId]; ok {
  706. findItems = append(findItems, v)
  707. groupMap[v.GroupId] = findItems
  708. } else {
  709. findItems = append(findItems, v)
  710. groupMap[v.GroupId] = findItems
  711. }
  712. //}
  713. }
  714. groupReportRecordList := make([]roadshow.GroupReportRecord, 0)
  715. rsAllReportRecordNumList := make([]roadshow.RsReportRecordNum, 0)
  716. RsReportRecordResp := roadshow.RsReportRecordResp{
  717. List: groupReportRecordList,
  718. RsReportRecordNumList: rsAllReportRecordNumList,
  719. }
  720. startDateIndexList := make(map[int]string) //开始时间间隔map
  721. endDateIndexList := make(map[int]string) //结束时间间隔map
  722. tmpAllTryOutNumMap := make(map[int]int)
  723. tmpAllFormalNumMap := make(map[int]int)
  724. tmpAllMeetingNumMap := make(map[int]int)
  725. tmpAllOnlineNumMap := make(map[int]int)
  726. tmpAllOfflineNumMap := make(map[int]int)
  727. for _, v := range group {
  728. v.ResearcherList = groupMap[v.GroupId]
  729. tmpGroupAdminReportRecord := make([]roadshow.AdminReportRecord, 0)
  730. tmpGroupRsReportRecordNumList := make([]roadshow.RsReportRecordNum, 0)
  731. tmpGroupTryOutNumMap := make(map[int]int)
  732. tmpGroupFormalNumMap := make(map[int]int)
  733. tmpGroupMeetingNumMap := make(map[int]int)
  734. tmpGroupOnlineNumMap := make(map[int]int)
  735. tmpGroupOfflineNumMap := make(map[int]int)
  736. for _, researcher := range groupMap[v.GroupId] {
  737. //组内研究员数据
  738. var isLook bool
  739. //如果是管理员或者本组的可以查看详情
  740. if sysUser.GroupId == v.GroupId || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  741. isLook = true
  742. }
  743. //每个区间的数据
  744. tmpAdminRsReportRecordNumList := make([]roadshow.RsReportRecordNum, 0)
  745. var isAppend bool
  746. for index, adminData := range adminDataList {
  747. startDateIndexList[index] = adminData.StartDate
  748. endDateIndexList[index] = adminData.EndDate
  749. var tmpTryOutNum, tmpFormalNum, tmpMeetingNum, tmpOnlineNum, tmpOfflineNum int
  750. if num, ok := adminData.TryOutMap[researcher.AdminId]; ok {
  751. tmpTryOutNum = num
  752. }
  753. if num, ok := adminData.FormalMap[researcher.AdminId]; ok {
  754. tmpFormalNum = num
  755. }
  756. if num, ok := adminData.MeetingMap[researcher.AdminId]; ok {
  757. tmpMeetingNum = num
  758. }
  759. if num, ok := adminData.OnlineMap[researcher.AdminId]; ok {
  760. tmpOnlineNum = num
  761. }
  762. if num, ok := adminData.OfflineMap[researcher.AdminId]; ok {
  763. tmpOfflineNum = num
  764. }
  765. tmpAdminRsReportRecordNum := roadshow.RsReportRecordNum{
  766. TryOutNum: tmpTryOutNum,
  767. FormalNum: tmpFormalNum,
  768. MeetingNum: tmpMeetingNum,
  769. OnlineNum: tmpOnlineNum,
  770. OfflineNum: tmpOfflineNum,
  771. StartDate: adminData.StartDate,
  772. EndDate: adminData.EndDate,
  773. IsLook: isLook,
  774. }
  775. if tmpTryOutNum > 0 || tmpFormalNum > 0 || tmpMeetingNum > 0 || tmpOnlineNum > 0 || tmpOfflineNum > 0 {
  776. isAppend = true
  777. haveData = true
  778. }
  779. tmpAdminRsReportRecordNumList = append(tmpAdminRsReportRecordNumList, tmpAdminRsReportRecordNum)
  780. //组内数据汇总
  781. if _, ok := tmpGroupTryOutNumMap[index]; !ok {
  782. tmpGroupTryOutNumMap[index] = 0
  783. }
  784. if _, ok := tmpGroupFormalNumMap[index]; !ok {
  785. tmpGroupFormalNumMap[index] = 0
  786. }
  787. if _, ok := tmpGroupMeetingNumMap[index]; !ok {
  788. tmpGroupMeetingNumMap[index] = 0
  789. }
  790. if _, ok := tmpGroupOnlineNumMap[index]; !ok {
  791. tmpGroupOnlineNumMap[index] = 0
  792. }
  793. if _, ok := tmpGroupOfflineNumMap[index]; !ok {
  794. tmpGroupOfflineNumMap[index] = 0
  795. }
  796. tmpGroupTryOutNumMap[index] += tmpTryOutNum
  797. tmpGroupFormalNumMap[index] += tmpFormalNum
  798. tmpGroupMeetingNumMap[index] += tmpMeetingNum
  799. tmpGroupOnlineNumMap[index] += tmpOnlineNum
  800. tmpGroupOfflineNumMap[index] += tmpOfflineNum
  801. //总数据汇总
  802. if _, ok := tmpAllTryOutNumMap[index]; !ok {
  803. tmpAllTryOutNumMap[index] = 0
  804. }
  805. if _, ok := tmpAllFormalNumMap[index]; !ok {
  806. tmpAllFormalNumMap[index] = 0
  807. }
  808. if _, ok := tmpAllMeetingNumMap[index]; !ok {
  809. tmpAllMeetingNumMap[index] = 0
  810. }
  811. if _, ok := tmpAllOnlineNumMap[index]; !ok {
  812. tmpAllOnlineNumMap[index] = 0
  813. }
  814. if _, ok := tmpAllOfflineNumMap[index]; !ok {
  815. tmpAllOfflineNumMap[index] = 0
  816. }
  817. tmpAllTryOutNumMap[index] += tmpTryOutNum
  818. tmpAllFormalNumMap[index] += tmpFormalNum
  819. tmpAllMeetingNumMap[index] += tmpMeetingNum
  820. tmpAllOnlineNumMap[index] += tmpOnlineNum
  821. tmpAllOfflineNumMap[index] += tmpOfflineNum
  822. }
  823. tmpAdminReportRecord := roadshow.AdminReportRecord{
  824. Name: researcher.RealName,
  825. AdminId: researcher.AdminId,
  826. RsReportRecordNumList: tmpAdminRsReportRecordNumList,
  827. }
  828. if isAppend {
  829. tmpGroupAdminReportRecord = append(tmpGroupAdminReportRecord, tmpAdminReportRecord)
  830. }
  831. }
  832. for i := 0; i < len(tmpGroupMeetingNumMap); i++ {
  833. tmpGroupRsReportRecordNum := roadshow.RsReportRecordNum{
  834. TryOutNum: tmpGroupTryOutNumMap[i],
  835. FormalNum: tmpGroupFormalNumMap[i],
  836. MeetingNum: tmpGroupMeetingNumMap[i],
  837. OnlineNum: tmpGroupOnlineNumMap[i],
  838. OfflineNum: tmpGroupOfflineNumMap[i],
  839. StartDate: startDateIndexList[i],
  840. EndDate: endDateIndexList[i],
  841. }
  842. tmpGroupRsReportRecordNumList = append(tmpGroupRsReportRecordNumList, tmpGroupRsReportRecordNum)
  843. }
  844. groupReportRecord := roadshow.GroupReportRecord{
  845. Item: tmpGroupAdminReportRecord,
  846. Name: v.GroupName,
  847. GruopId: v.GroupId,
  848. RsReportRecordNumList: tmpGroupRsReportRecordNumList,
  849. }
  850. if len(tmpGroupAdminReportRecord) > 0 {
  851. groupReportRecordList = append(groupReportRecordList, groupReportRecord)
  852. }
  853. }
  854. //总体汇总数据
  855. for i := 0; i < len(tmpAllFormalNumMap); i++ {
  856. tmpGroupRsReportRecordNum := roadshow.RsReportRecordNum{
  857. TryOutNum: tmpAllTryOutNumMap[i],
  858. FormalNum: tmpAllFormalNumMap[i],
  859. MeetingNum: tmpAllMeetingNumMap[i],
  860. OnlineNum: tmpAllOnlineNumMap[i],
  861. OfflineNum: tmpAllOfflineNumMap[i],
  862. StartDate: startDateIndexList[i],
  863. EndDate: endDateIndexList[i],
  864. }
  865. rsAllReportRecordNumList = append(rsAllReportRecordNumList, tmpGroupRsReportRecordNum)
  866. }
  867. RsReportRecordResp.RsReportRecordNumList = rsAllReportRecordNumList
  868. tmpList := groupReportRecordList
  869. //因为RoleTypeCode不一样,所以需要重新从数据库取数据
  870. adminInfo, _ := system.GetSysAdminById(sysUser.AdminId)
  871. adminGroupId := adminInfo.GroupId
  872. if tmpGroupId, ok := groupIdRelationMap[adminGroupId]; ok {
  873. adminGroupId = tmpGroupId
  874. }
  875. switch adminInfo.RoleTypeCode {
  876. case utils.ROLE_TYPE_CODE_FICC_GROUP, utils.ROLE_TYPE_CODE_FICC_TEAM:
  877. for index, v := range tmpList {
  878. //如果不是同一个分组,那么就移除该分组下的人员数据
  879. if v.GruopId != adminGroupId {
  880. tmpList[index].Item = make([]roadshow.AdminReportRecord, 0)
  881. }
  882. }
  883. RsReportRecordResp.List = tmpList
  884. case utils.ROLE_TYPE_CODE_FICC_ADMIN, utils.ROLE_TYPE_CODE_ADMIN:
  885. //管理员、超管看全部数据
  886. RsReportRecordResp.List = groupReportRecordList
  887. }
  888. //判断是否有数据如果没有,处理数据为空
  889. if !haveData {
  890. RsReportRecordResp = roadshow.RsReportRecordResp{
  891. List: make([]roadshow.GroupReportRecord, 0),
  892. RsReportRecordNumList: make([]roadshow.RsReportRecordNum, 0),
  893. }
  894. }
  895. br.Ret = 200
  896. br.Success = true
  897. br.Msg = "获取成功"
  898. br.Data = RsReportRecordResp
  899. return
  900. }
  901. // ResearcherReportList
  902. // @Title 研究员出差表
  903. // @Description 研究员出差表接口
  904. // @Param AdminId query int true "研究员id"
  905. // @Param WeekQuery query int false "周查询: 0-本期(本周及下周); 1-前两周; 2-后两周"
  906. // @Param BaseQueryDate query string false "周查询时的开始日期"
  907. // @Success 200 {object} roadshow.BusinessTripResp
  908. // @router /report/researcher/business_trip [get]
  909. func (this *CalendarController) ResearcherBusinessTrip() {
  910. br := new(models.BaseResponse).Init()
  911. defer func() {
  912. this.Data["json"] = br
  913. this.ServeJSON()
  914. }()
  915. sysUser := this.SysUser
  916. if sysUser == nil {
  917. br.Msg = "请登录"
  918. br.ErrMsg = "请登录,SysUser Is Empty"
  919. br.Ret = 408
  920. return
  921. }
  922. adminId, _ := this.GetInt("AdminId")
  923. weekQuery, _ := this.GetInt("WeekQuery")
  924. baseQueryDate := this.GetString("BaseQueryDate")
  925. //fmt.Println(adminId)
  926. group, err := roadshow.GetResearcherGroup()
  927. if err != nil {
  928. br.Msg = "获取信息失败!"
  929. br.ErrMsg = "获取分组信息失败!Err:" + err.Error()
  930. return
  931. }
  932. researcherList, err := roadshow.GetBusinessTripResearcher()
  933. if err != nil {
  934. br.Msg = "获取信息失败!"
  935. br.ErrMsg = "获取分组信息失败!,GetBusinessTripResearcher Err:" + err.Error()
  936. return
  937. }
  938. ////获取当天周日期
  939. //nowWeekStart := utils.GetNowWeekMonday().AddDate(0, 0, -2)
  940. ////nowWeekEnd := utils.GetNowWeekLastDay()
  941. ////获取下周日期
  942. //nextWeekStart := utils.GetNextWeekMonday().AddDate(0, 0, -2)
  943. //nextWeekEnd := utils.GetNextWeekLastDay().AddDate(0, 0, -2)
  944. var nowWeekStart time.Time
  945. if baseQueryDate == "" {
  946. now := time.Now()
  947. weekDay := int(now.Weekday())
  948. if weekDay == 6 {
  949. nowWeekStart, _ = time.ParseInLocation(utils.FormatDate, now.Format(utils.FormatDate), time.Local)
  950. } else {
  951. nowWeekStart, _ = time.ParseInLocation(utils.FormatDate, now.AddDate(0, 0, -(weekDay+1)).Format(utils.FormatDate), time.Local)
  952. }
  953. }
  954. // 查询需求是可以无限往前后两周查询, 以入参为本周开始日期
  955. if baseQueryDate != "" {
  956. t, e := time.ParseInLocation(utils.FormatDate, baseQueryDate, time.Local)
  957. if e != nil {
  958. br.Msg = "查询开始日期格式有误"
  959. return
  960. }
  961. nowWeekStart = t
  962. }
  963. // 前/后两周
  964. if weekQuery == 1 {
  965. nowWeekStart = nowWeekStart.AddDate(0, 0, -14)
  966. }
  967. if weekQuery == 2 {
  968. nowWeekStart = nowWeekStart.AddDate(0, 0, +14)
  969. }
  970. //nowWeekEnd := utils.GetNowWeekLastDay()
  971. //获取下周日期
  972. nextWeekStart := nowWeekStart.AddDate(0, 0, +7)
  973. nextWeekEnd := nowWeekStart.AddDate(0, 0, +13)
  974. //获取路演信息
  975. roadshowList, err := roadshow.GetBusinessTripList(adminId, nowWeekStart.Format(utils.FormatDate), nextWeekEnd.Format(utils.FormatDateTime))
  976. if err != nil {
  977. br.Msg = "获取信息失败!"
  978. br.ErrMsg = "获取路演信息失败!,GetBusinessTripList Err:" + err.Error()
  979. return
  980. }
  981. roadshowMap := make(map[int][]*roadshow.BusinessTripResearcherList)
  982. for _, v := range roadshowList {
  983. if findVals, ok := roadshowMap[v.ResearcherId]; ok {
  984. findVals = append(findVals, v)
  985. roadshowMap[v.ResearcherId] = findVals
  986. } else {
  987. roadsItems := make([]*roadshow.BusinessTripResearcherList, 0)
  988. roadsItems = append(roadsItems, v)
  989. roadshowMap[v.ResearcherId] = roadsItems
  990. }
  991. }
  992. //fmt.Println("roadshow json start")
  993. //jsonBody, err := json.Marshal(roadshowMap)
  994. //fmt.Println("json body:" + string(jsonBody))
  995. //fmt.Println("roadshow json end")
  996. groupMap := make(map[int][]*roadshow.BusinessTripResearcher)
  997. for _, v := range researcherList {
  998. if findRoadshowList, ok := roadshowMap[v.AdminId]; ok {
  999. tripList := make([]*roadshow.BusinessTrip, 0)
  1000. researcherMap := make(map[string]string)
  1001. for i := 0; i < 7; i++ {
  1002. newDay, _ := time.ParseInLocation(utils.FormatDate, nowWeekStart.AddDate(0, 0, i).Format(utils.FormatDate), time.Local)
  1003. weekDate := newDay.Format(utils.FormatDate)
  1004. tripItem := new(roadshow.BusinessTrip)
  1005. for _, r := range findRoadshowList {
  1006. startDateT, _ := time.ParseInLocation(utils.FormatDate, r.StartDate, time.Local)
  1007. endDateT, _ := time.ParseInLocation(utils.FormatDate, r.EndDate, time.Local)
  1008. if int(endDateT.Sub(startDateT)) <= 0 {
  1009. skey := strconv.Itoa(r.ResearcherId) + r.StartDate
  1010. if _, sok := researcherMap[skey]; !sok {
  1011. if r != nil && (newDay.Equal(startDateT) || (newDay.Equal(endDateT)) || (newDay.Before(endDateT) && newDay.After(startDateT))) {
  1012. tripItem.City = r.City
  1013. researcherMap[skey] = skey
  1014. }
  1015. }
  1016. } else {
  1017. if r != nil && (newDay.Equal(startDateT) || (newDay.Equal(endDateT)) || (newDay.Before(endDateT) && newDay.After(startDateT))) {
  1018. tripItem.City = r.City
  1019. //researcherMap[skey] = skey
  1020. }
  1021. }
  1022. }
  1023. tripItem.WeekDate = weekDate
  1024. tripItem.WeekType = "current"
  1025. tripItem.Week = newDay.Weekday().String()
  1026. tripList = append(tripList, tripItem)
  1027. }
  1028. for i := 0; i < 7; i++ {
  1029. newDay := nextWeekStart.AddDate(0, 0, i)
  1030. weekDate := newDay.Format(utils.FormatDate)
  1031. tripItem := new(roadshow.BusinessTrip)
  1032. for _, r := range findRoadshowList {
  1033. startDateT, _ := time.ParseInLocation(utils.FormatDate, r.StartDate, time.Local)
  1034. endDateT, _ := time.ParseInLocation(utils.FormatDate, r.EndDate, time.Local)
  1035. if int(endDateT.Sub(startDateT)) <= 0 {
  1036. skey := strconv.Itoa(r.ResearcherId) + r.StartDate
  1037. if _, sok := researcherMap[skey]; !sok {
  1038. if r != nil && (newDay.Equal(startDateT) || (newDay.Equal(endDateT)) || (newDay.Before(endDateT) && newDay.After(startDateT))) {
  1039. tripItem.City = r.City
  1040. researcherMap[skey] = skey
  1041. }
  1042. }
  1043. } else {
  1044. if r != nil && (newDay.Equal(startDateT) || (newDay.Equal(endDateT)) || (newDay.Before(endDateT) && newDay.After(startDateT))) {
  1045. tripItem.City = r.City
  1046. //researcherMap[skey] = skey
  1047. }
  1048. }
  1049. }
  1050. tripItem.WeekDate = weekDate
  1051. tripItem.WeekType = "next"
  1052. tripItem.Week = newDay.Weekday().String()
  1053. tripList = append(tripList, tripItem)
  1054. }
  1055. v.BusinessTripList = tripList
  1056. //if v.RoleTypeCode == "ficc_admin" {
  1057. // findItems := groupMap[1]
  1058. // findItems = append(findItems, v)
  1059. // groupMap[1] = findItems
  1060. //} else {
  1061. if findItems, ok := groupMap[v.GroupId]; ok {
  1062. findItems = append(findItems, v)
  1063. groupMap[v.GroupId] = findItems
  1064. } else {
  1065. findItems = append(findItems, v)
  1066. groupMap[v.GroupId] = findItems
  1067. }
  1068. //}
  1069. }
  1070. }
  1071. groupList := make([]*roadshow.BusinessTripGroup, 0)
  1072. for _, v := range group {
  1073. item := new(roadshow.BusinessTripGroup)
  1074. item.GroupName = v.GroupName
  1075. item.GroupId = v.GroupId
  1076. item.ResearcherList = groupMap[v.GroupId]
  1077. groupList = append(groupList, item)
  1078. }
  1079. resp := new(roadshow.BusinessTripResp)
  1080. resp.GroupList = groupList
  1081. resp.BaseDate = nowWeekStart.Format(utils.FormatDate)
  1082. br.Ret = 200
  1083. br.Success = true
  1084. br.Msg = "获取成功"
  1085. br.Data = resp
  1086. return
  1087. }
  1088. // OverseasCustomReportCalendarList
  1089. // @Title 路演详情列表
  1090. // @Description 路演详情列表接口
  1091. // @Param Keyword query string true "关键字:客户名称"
  1092. // @Param CompanyStatus query string true "客户状态,枚举值:正式、试用、关闭"
  1093. // @Param SellerId query int true "销售id列表;多个用英文,分割"
  1094. // @Param ResearcherId query int true "销售id列表;多个用英文,分割"
  1095. // @Param StartDate query string true "开始日期,格式:2022-04-06"
  1096. // @Param EndDate query string true "结束日期,格式:2022-04-06"
  1097. // @Param SortField query string false "排序字段:start_date"
  1098. // @Param SortDesc query int false "1:降序,默认,2:升序"
  1099. // @Success 200 {object} []roadshow.RsReportRecordList
  1100. // @router /overseas_custom/calendar/list [get]
  1101. func (this *CalendarController) OverseasCustomReportCalendarList() {
  1102. br := new(models.BaseResponse).Init()
  1103. defer func() {
  1104. this.Data["json"] = br
  1105. this.ServeJSON()
  1106. }()
  1107. sysUser := this.SysUser
  1108. if sysUser == nil {
  1109. br.Msg = "请登录"
  1110. br.ErrMsg = "请登录,SysUser Is Empty"
  1111. br.Ret = 408
  1112. return
  1113. }
  1114. keyword := this.GetString("Keyword")
  1115. companyStatus := this.GetString("CompanyStatus")
  1116. startDate := this.GetString("StartDate")
  1117. endDate := this.GetString("EndDate")
  1118. sellerId := this.GetString("SellerId")
  1119. researcherId := this.GetString("ResearcherId")
  1120. pageSize, _ := this.GetInt("PageSize")
  1121. currentIndex, _ := this.GetInt("CurrentIndex")
  1122. sortField := this.GetString("SortField")
  1123. sortDesc, _ := this.GetInt("SortDesc")
  1124. var startSize int
  1125. if pageSize <= 0 {
  1126. pageSize = utils.PageSize20
  1127. }
  1128. if currentIndex <= 0 {
  1129. currentIndex = 1
  1130. }
  1131. startSize = paging.StartIndex(currentIndex, pageSize)
  1132. switch sortField {
  1133. case "start_date":
  1134. default:
  1135. sortField = "start_date"
  1136. }
  1137. // "1:降序,默认,2:升序"
  1138. sortDesStr := ` desc `
  1139. switch sortDesc {
  1140. case 2:
  1141. sortDesStr = ` asc `
  1142. default:
  1143. sortDesStr = "desc"
  1144. }
  1145. total, list, err := roadshow.GetOverseaCustomCalendarList(keyword, sellerId, researcherId, startDate, endDate, companyStatus, sortField, sortDesStr, startSize, pageSize)
  1146. if err != nil {
  1147. br.Msg = "获取失败"
  1148. br.ErrMsg = "获取失败,ERR:" + err.Error()
  1149. return
  1150. }
  1151. page := paging.GetPaging(currentIndex, pageSize, total)
  1152. resp := new(roadshow.OverseaCustomRecordInfoResp)
  1153. resp.Paging = page
  1154. resp.List = list
  1155. br.Ret = 200
  1156. br.Success = true
  1157. br.Msg = "获取成功"
  1158. br.Data = resp
  1159. return
  1160. }
  1161. // OverseasCustomCalendarAdminList
  1162. // @Title 海外客户路演用户列表接口
  1163. // @Description 海外客户路演用户列表接口
  1164. // @Param AdminType query string true "枚举值:researcher、seller"
  1165. // @Success 200 {object} []roadshow.AdminInfo
  1166. // @router /overseas_custom/sys_user/list [get]
  1167. func (this *CalendarController) OverseasCustomCalendarAdminList() {
  1168. br := new(models.BaseResponse).Init()
  1169. defer func() {
  1170. this.Data["json"] = br
  1171. this.ServeJSON()
  1172. }()
  1173. sysUser := this.SysUser
  1174. if sysUser == nil {
  1175. br.Msg = "请登录"
  1176. br.ErrMsg = "请登录,SysUser Is Empty"
  1177. br.Ret = 408
  1178. return
  1179. }
  1180. adminType := this.GetString("AdminType")
  1181. var list []*roadshow.AdminInfo
  1182. var err error
  1183. //选择的人员类型(发起人还是被发起人)
  1184. if adminType == "seller" {
  1185. list, err = roadshow.GetOverseaCustomCalendarSellerList()
  1186. } else if adminType == "researcher" {
  1187. list, err = roadshow.GetOverseaCustomCalendarResearcherList()
  1188. } else {
  1189. br.Msg = "错误的类型"
  1190. br.IsSendEmail = false
  1191. }
  1192. if err != nil {
  1193. br.Msg = "获取失败"
  1194. br.ErrMsg = "获取失败,ERR:" + err.Error()
  1195. return
  1196. }
  1197. br.Ret = 200
  1198. br.Success = true
  1199. br.Msg = "获取成功"
  1200. br.Data = list
  1201. return
  1202. }
  1203. // OverseasSellerReportList
  1204. // @Title 海外客户销售路演统计
  1205. // @Description 海外客户销售路演统计接口
  1206. // @Param DataType query string true "枚举值:week、month、time_interval、online、offline"
  1207. // @Param DimensionType query string true "维度枚举值:company_status、roadshow_type"
  1208. // @Param StartDate query string true "开始日期,格式:2022-04-06"
  1209. // @Param EndDate query string true "结束日期,格式:2022-04-06"
  1210. // @Success 200 {object} roadshow.RsReportRecordResp
  1211. // @router /overseas_custom/seller/list [get]
  1212. func (this *CalendarController) OverseasSellerReportList() {
  1213. br := new(models.BaseResponse).Init()
  1214. defer func() {
  1215. this.Data["json"] = br
  1216. this.ServeJSON()
  1217. }()
  1218. sysUser := this.SysUser
  1219. if sysUser == nil {
  1220. br.Msg = "请登录"
  1221. br.ErrMsg = "请登录,SysUser Is Empty"
  1222. br.Ret = 408
  1223. return
  1224. }
  1225. dataType := this.GetString("DataType")
  1226. dimensionType := this.GetString("DimensionType")
  1227. startDate := this.GetString("StartDate")
  1228. endDate := this.GetString("EndDate")
  1229. if dimensionType == "" {
  1230. dimensionType = "company_status"
  1231. }
  1232. var adminDataList []roadshowService.OverseasAdminDataMap
  1233. var err error
  1234. var firstDate time.Time
  1235. //获取列表
  1236. switch dataType {
  1237. case "week":
  1238. adminDataList, firstDate, err = roadshowService.GetOverseasWeekDataV2("seller", dimensionType, 6)
  1239. if err != nil {
  1240. br.Msg = "数据异常"
  1241. br.ErrMsg = "数据异常,Err:" + err.Error()
  1242. return
  1243. }
  1244. case "month":
  1245. adminDataList, firstDate, err = roadshowService.GetOverseasMonthDataV2("seller", dimensionType, 6)
  1246. if err != nil {
  1247. br.Msg = "数据异常"
  1248. br.ErrMsg = "数据异常,Err:" + err.Error()
  1249. return
  1250. }
  1251. case "time_interval":
  1252. if startDate == `` || endDate == `` {
  1253. br.Msg = "开始日期或结束日期不能为空"
  1254. br.ErrMsg = "开始日期或结束日期不能为空,Err:" + err.Error()
  1255. return
  1256. }
  1257. adminDataList, firstDate, err = roadshowService.GetOverseasTimeIntervalData(startDate, endDate, "seller", dimensionType)
  1258. if err != nil {
  1259. br.Msg = "数据异常"
  1260. br.ErrMsg = "数据异常,Err:" + err.Error()
  1261. return
  1262. }
  1263. }
  1264. group, groupIdRelationMap, err := services.GetFiccSystemGroup()
  1265. if err != nil {
  1266. br.Msg = "获取信息失败!"
  1267. br.ErrMsg = "获取分组信息失败!Err:" + err.Error()
  1268. return
  1269. }
  1270. researcherList, err := services.GetFiccSeller(firstDate, groupIdRelationMap)
  1271. groupMap := make(map[int][]*roadshow.Researcher)
  1272. for _, v := range researcherList {
  1273. if v.RoleTypeCode == "ficc_admin" {
  1274. findItems := groupMap[1]
  1275. findItems = append(findItems, v)
  1276. groupMap[1] = findItems
  1277. } else {
  1278. if findItems, ok := groupMap[v.GroupId]; ok {
  1279. findItems = append(findItems, v)
  1280. groupMap[v.GroupId] = findItems
  1281. } else {
  1282. findItems = append(findItems, v)
  1283. groupMap[v.GroupId] = findItems
  1284. }
  1285. }
  1286. }
  1287. groupReportRecordList := make([]roadshow.OverseasGroupReportRecord, 0)
  1288. rsAllReportRecordNumList := make([]roadshow.RsOverseasReportRecordNum, 0)
  1289. RsReportRecordResp := roadshow.RsOverseasReportRecordResp{
  1290. List: groupReportRecordList,
  1291. RsReportRecordNumList: rsAllReportRecordNumList,
  1292. }
  1293. startDateIndexList := make(map[int]string) //开始时间间隔map
  1294. endDateIndexList := make(map[int]string) //结束时间间隔map
  1295. tmpAllTryOutNumMap := make(map[int]int)
  1296. tmpAllFormalNumMap := make(map[int]int)
  1297. tmpAllCloseNumMap := make(map[int]int)
  1298. tmpAllOnlineNumMap := make(map[int]int)
  1299. tmpAllOfflineNumMap := make(map[int]int)
  1300. for _, v := range group {
  1301. v.ResearcherList = groupMap[v.GroupId]
  1302. tmpGroupAdminReportRecord := make([]roadshow.OverseasAdminReportRecord, 0)
  1303. tmpGroupRsReportRecordNumList := make([]roadshow.RsOverseasReportRecordNum, 0)
  1304. tmpGroupTryOutNumMap := make(map[int]int)
  1305. tmpGroupFormalNumMap := make(map[int]int)
  1306. tmpGroupCloseNumMap := make(map[int]int)
  1307. tmpGroupOnlineNumMap := make(map[int]int)
  1308. tmpGroupOfflineNumMap := make(map[int]int)
  1309. for _, researcher := range groupMap[v.GroupId] {
  1310. //组内研究员数据
  1311. //每个区间的数据
  1312. tmpAdminRsReportRecordNumList := make([]roadshow.RsOverseasReportRecordNum, 0)
  1313. for index, adminData := range adminDataList {
  1314. startDateIndexList[index] = adminData.StartDate
  1315. endDateIndexList[index] = adminData.EndDate
  1316. var tmpTryOutNum, tmpFormalNum, tmpCloseNum, tmpOnlineNum, tmpOfflineNum int
  1317. if num, ok := adminData.TryOutMap[researcher.AdminId]; ok {
  1318. tmpTryOutNum = num
  1319. }
  1320. if num, ok := adminData.FormalMap[researcher.AdminId]; ok {
  1321. tmpFormalNum = num
  1322. }
  1323. if num, ok := adminData.CloseMap[researcher.AdminId]; ok {
  1324. tmpCloseNum = num
  1325. }
  1326. if num, ok := adminData.OnlineMap[researcher.AdminId]; ok {
  1327. tmpOnlineNum = num
  1328. }
  1329. if num, ok := adminData.OfflineMap[researcher.AdminId]; ok {
  1330. tmpOfflineNum = num
  1331. }
  1332. tmpAdminRsReportRecordNum := roadshow.RsOverseasReportRecordNum{
  1333. TryOutNum: tmpTryOutNum,
  1334. FormalNum: tmpFormalNum,
  1335. CloseNum: tmpCloseNum,
  1336. OnlineNum: tmpOnlineNum,
  1337. OfflineNum: tmpOfflineNum,
  1338. StartDate: adminData.StartDate,
  1339. EndDate: adminData.EndDate,
  1340. }
  1341. tmpAdminRsReportRecordNumList = append(tmpAdminRsReportRecordNumList, tmpAdminRsReportRecordNum)
  1342. //组内数据汇总
  1343. if _, ok := tmpGroupTryOutNumMap[index]; !ok {
  1344. tmpGroupTryOutNumMap[index] = 0
  1345. }
  1346. if _, ok := tmpGroupFormalNumMap[index]; !ok {
  1347. tmpGroupFormalNumMap[index] = 0
  1348. }
  1349. if _, ok := tmpGroupCloseNumMap[index]; !ok {
  1350. tmpGroupCloseNumMap[index] = 0
  1351. }
  1352. if _, ok := tmpGroupOnlineNumMap[index]; !ok {
  1353. tmpGroupOnlineNumMap[index] = 0
  1354. }
  1355. if _, ok := tmpGroupOfflineNumMap[index]; !ok {
  1356. tmpGroupOfflineNumMap[index] = 0
  1357. }
  1358. tmpGroupTryOutNumMap[index] += tmpTryOutNum
  1359. tmpGroupFormalNumMap[index] += tmpFormalNum
  1360. tmpGroupCloseNumMap[index] += tmpCloseNum
  1361. tmpGroupOnlineNumMap[index] += tmpOnlineNum
  1362. tmpGroupOfflineNumMap[index] += tmpOfflineNum
  1363. //总数据汇总
  1364. if _, ok := tmpAllTryOutNumMap[index]; !ok {
  1365. tmpAllTryOutNumMap[index] = 0
  1366. }
  1367. if _, ok := tmpAllFormalNumMap[index]; !ok {
  1368. tmpAllFormalNumMap[index] = 0
  1369. }
  1370. if _, ok := tmpAllCloseNumMap[index]; !ok {
  1371. tmpAllCloseNumMap[index] = 0
  1372. }
  1373. if _, ok := tmpAllOnlineNumMap[index]; !ok {
  1374. tmpAllOnlineNumMap[index] = 0
  1375. }
  1376. if _, ok := tmpAllOfflineNumMap[index]; !ok {
  1377. tmpAllOfflineNumMap[index] = 0
  1378. }
  1379. tmpAllTryOutNumMap[index] += tmpTryOutNum
  1380. tmpAllFormalNumMap[index] += tmpFormalNum
  1381. tmpAllCloseNumMap[index] += tmpCloseNum
  1382. tmpAllOnlineNumMap[index] += tmpOnlineNum
  1383. tmpAllOfflineNumMap[index] += tmpOfflineNum
  1384. }
  1385. tmpAdminReportRecord := roadshow.OverseasAdminReportRecord{
  1386. Name: researcher.RealName,
  1387. AdminId: researcher.AdminId,
  1388. RsReportRecordNumList: tmpAdminRsReportRecordNumList,
  1389. }
  1390. tmpGroupAdminReportRecord = append(tmpGroupAdminReportRecord, tmpAdminReportRecord)
  1391. }
  1392. for i := 0; i < len(tmpGroupCloseNumMap); i++ {
  1393. tmpGroupRsReportRecordNum := roadshow.RsOverseasReportRecordNum{
  1394. TryOutNum: tmpGroupTryOutNumMap[i],
  1395. FormalNum: tmpGroupFormalNumMap[i],
  1396. CloseNum: tmpGroupCloseNumMap[i],
  1397. OnlineNum: tmpGroupOnlineNumMap[i],
  1398. OfflineNum: tmpGroupOfflineNumMap[i],
  1399. StartDate: startDateIndexList[i],
  1400. EndDate: endDateIndexList[i],
  1401. }
  1402. tmpGroupRsReportRecordNumList = append(tmpGroupRsReportRecordNumList, tmpGroupRsReportRecordNum)
  1403. }
  1404. groupReportRecord := roadshow.OverseasGroupReportRecord{
  1405. Item: tmpGroupAdminReportRecord,
  1406. Name: v.GroupName,
  1407. GruopId: v.GroupId,
  1408. RsReportRecordNumList: tmpGroupRsReportRecordNumList,
  1409. }
  1410. groupReportRecordList = append(groupReportRecordList, groupReportRecord)
  1411. }
  1412. //总体汇总数据
  1413. for i := 0; i < len(tmpAllFormalNumMap); i++ {
  1414. tmpGroupRsReportRecordNum := roadshow.RsOverseasReportRecordNum{
  1415. TryOutNum: tmpAllTryOutNumMap[i],
  1416. FormalNum: tmpAllFormalNumMap[i],
  1417. CloseNum: tmpAllCloseNumMap[i],
  1418. OnlineNum: tmpAllOnlineNumMap[i],
  1419. OfflineNum: tmpAllOfflineNumMap[i],
  1420. StartDate: startDateIndexList[i],
  1421. EndDate: endDateIndexList[i],
  1422. }
  1423. rsAllReportRecordNumList = append(rsAllReportRecordNumList, tmpGroupRsReportRecordNum)
  1424. }
  1425. RsReportRecordResp.RsReportRecordNumList = rsAllReportRecordNumList
  1426. //tmpList := groupReportRecordList
  1427. //因为RoleTypeCode不一样,所以需要重新从数据库取数据
  1428. //adminInfo, _ := system.GetSysAdminById(sysUser.AdminId)
  1429. //adminGroupId := adminInfo.GroupId
  1430. //if tmpGroupId, ok := groupIdRelationMap[adminGroupId]; ok {
  1431. // adminGroupId = tmpGroupId
  1432. //}
  1433. //switch adminInfo.RoleTypeCode {
  1434. //case utils.ROLE_TYPE_CODE_FICC_GROUP, utils.ROLE_TYPE_CODE_FICC_TEAM:
  1435. // for index, v := range tmpList {
  1436. // //如果不是同一个分组,那么就移除该分组下的人员数据
  1437. // if v.GruopId != adminGroupId {
  1438. // tmpList[index].Item = make([]roadshow.AdminReportRecord, 0)
  1439. // }
  1440. // }
  1441. // RsReportRecordResp.List = tmpList
  1442. //case utils.ROLE_TYPE_CODE_FICC_ADMIN, utils.ROLE_TYPE_CODE_ADMIN:
  1443. // //管理员、超管看全部数据
  1444. // RsReportRecordResp.List = groupReportRecordList
  1445. //}
  1446. // 20230529-有权限查看该页面的用户权限同admin
  1447. RsReportRecordResp.List = groupReportRecordList
  1448. br.Ret = 200
  1449. br.Success = true
  1450. br.Msg = "获取成功"
  1451. br.Data = RsReportRecordResp
  1452. return
  1453. }
  1454. // OverseasResearcherReportList
  1455. // @Title 研究员路演统计
  1456. // @Description 研究员路演统计接口
  1457. // @Param DataType query string true "枚举值:week、month、time_interval"
  1458. // @Param StartDate query string true "开始日期,格式:2022-04-06"
  1459. // @Param EndDate query string true "结束日期,格式:2022-04-06"
  1460. // @Success 200 {object} roadshow.RsReportRecordResp
  1461. // @router /overseas_custom/researcher/list [get]
  1462. func (this *CalendarController) OverseasResearcherReportList() {
  1463. br := new(models.BaseResponse).Init()
  1464. defer func() {
  1465. this.Data["json"] = br
  1466. this.ServeJSON()
  1467. }()
  1468. sysUser := this.SysUser
  1469. if sysUser == nil {
  1470. br.Msg = "请登录"
  1471. br.ErrMsg = "请登录,SysUser Is Empty"
  1472. br.Ret = 408
  1473. return
  1474. }
  1475. dataType := this.GetString("DataType")
  1476. startDate := this.GetString("StartDate")
  1477. endDate := this.GetString("EndDate")
  1478. var adminDataList []roadshowService.OverseasAdminDataMap
  1479. var err error
  1480. //var firstDate time.Time
  1481. //获取列表
  1482. switch dataType {
  1483. case "week":
  1484. adminDataList, _, err = roadshowService.GetOverseasWeekData("researcher", "company_status")
  1485. if err != nil {
  1486. br.Msg = "数据异常"
  1487. br.ErrMsg = "数据异常,Err:" + err.Error()
  1488. return
  1489. }
  1490. case "month":
  1491. adminDataList, _, err = roadshowService.GetOverseasMonthData("researcher", "company_status")
  1492. if err != nil {
  1493. br.Msg = "数据异常"
  1494. br.ErrMsg = "数据异常,Err:" + err.Error()
  1495. return
  1496. }
  1497. case "time_interval":
  1498. if startDate == `` || endDate == `` {
  1499. br.Msg = "开始日期或结束日期不能为空"
  1500. br.ErrMsg = "开始日期或结束日期不能为空,Err:" + err.Error()
  1501. return
  1502. }
  1503. adminDataList, _, err = roadshowService.GetOverseasTimeIntervalData(startDate, endDate, "researcher", "company_status")
  1504. if err != nil {
  1505. br.Msg = "数据异常"
  1506. br.ErrMsg = "数据异常,Err:" + err.Error()
  1507. return
  1508. }
  1509. }
  1510. group, err := roadshow.GetResearcherGroup()
  1511. if err != nil {
  1512. br.Msg = "获取信息失败!"
  1513. br.ErrMsg = "获取分组信息失败!Err:" + err.Error()
  1514. return
  1515. }
  1516. researcherList, err := roadshow.GetResearcherV2()
  1517. if err != nil {
  1518. br.Msg = "获取信息失败!"
  1519. br.ErrMsg = "获取分组信息失败!,GetResearcherV2 Err:" + err.Error()
  1520. return
  1521. }
  1522. groupMap := make(map[int][]*roadshow.ResearcherGroup)
  1523. for _, v := range researcherList {
  1524. //if v.RoleTypeCode == "ficc_admin" {
  1525. // findItems := groupMap[1]
  1526. // findItems = append(findItems, v)
  1527. // groupMap[1] = findItems
  1528. //} else {
  1529. if findItems, ok := groupMap[v.GroupId]; ok {
  1530. findItems = append(findItems, v)
  1531. groupMap[v.GroupId] = findItems
  1532. } else {
  1533. findItems = append(findItems, v)
  1534. groupMap[v.GroupId] = findItems
  1535. }
  1536. //}
  1537. }
  1538. groupReportRecordList := make([]roadshow.OverseasGroupReportRecord, 0)
  1539. rsAllReportRecordNumList := make([]roadshow.RsOverseasReportRecordNum, 0)
  1540. RsReportRecordResp := roadshow.RsOverseasReportRecordResp{
  1541. List: groupReportRecordList,
  1542. RsReportRecordNumList: rsAllReportRecordNumList,
  1543. }
  1544. startDateIndexList := make(map[int]string) //开始时间间隔map
  1545. endDateIndexList := make(map[int]string) //结束时间间隔map
  1546. tmpAllTryOutNumMap := make(map[int]int)
  1547. tmpAllFormalNumMap := make(map[int]int)
  1548. tmpAllMeetingNumMap := make(map[int]int)
  1549. for _, v := range group {
  1550. v.ResearcherList = groupMap[v.GroupId]
  1551. tmpGroupAdminReportRecord := make([]roadshow.OverseasAdminReportRecord, 0)
  1552. tmpGroupRsReportRecordNumList := make([]roadshow.RsOverseasReportRecordNum, 0)
  1553. tmpGroupTryOutNumMap := make(map[int]int)
  1554. tmpGroupFormalNumMap := make(map[int]int)
  1555. tmpGroupCloseNumMap := make(map[int]int)
  1556. for _, researcher := range groupMap[v.GroupId] {
  1557. //组内研究员数据
  1558. //每个区间的数据
  1559. tmpAdminRsReportRecordNumList := make([]roadshow.RsOverseasReportRecordNum, 0)
  1560. for index, adminData := range adminDataList {
  1561. startDateIndexList[index] = adminData.StartDate
  1562. endDateIndexList[index] = adminData.EndDate
  1563. var tmpTryOutNum, tmpFormalNum, tmpCloseNum int
  1564. if num, ok := adminData.TryOutMap[researcher.AdminId]; ok {
  1565. tmpTryOutNum = num
  1566. }
  1567. if num, ok := adminData.FormalMap[researcher.AdminId]; ok {
  1568. tmpFormalNum = num
  1569. }
  1570. if num, ok := adminData.CloseMap[researcher.AdminId]; ok {
  1571. tmpCloseNum = num
  1572. }
  1573. tmpAdminRsReportRecordNum := roadshow.RsOverseasReportRecordNum{
  1574. TryOutNum: tmpTryOutNum,
  1575. FormalNum: tmpFormalNum,
  1576. CloseNum: tmpCloseNum,
  1577. StartDate: adminData.StartDate,
  1578. EndDate: adminData.EndDate,
  1579. }
  1580. tmpAdminRsReportRecordNumList = append(tmpAdminRsReportRecordNumList, tmpAdminRsReportRecordNum)
  1581. //组内数据汇总
  1582. if _, ok := tmpGroupTryOutNumMap[index]; !ok {
  1583. tmpGroupTryOutNumMap[index] = 0
  1584. }
  1585. if _, ok := tmpGroupFormalNumMap[index]; !ok {
  1586. tmpGroupFormalNumMap[index] = 0
  1587. }
  1588. if _, ok := tmpGroupCloseNumMap[index]; !ok {
  1589. tmpGroupCloseNumMap[index] = 0
  1590. }
  1591. tmpGroupTryOutNumMap[index] += tmpTryOutNum
  1592. tmpGroupFormalNumMap[index] += tmpFormalNum
  1593. tmpGroupCloseNumMap[index] += tmpCloseNum
  1594. //总数据汇总
  1595. if _, ok := tmpAllTryOutNumMap[index]; !ok {
  1596. tmpAllTryOutNumMap[index] = 0
  1597. }
  1598. if _, ok := tmpAllFormalNumMap[index]; !ok {
  1599. tmpAllFormalNumMap[index] = 0
  1600. }
  1601. if _, ok := tmpAllMeetingNumMap[index]; !ok {
  1602. tmpAllMeetingNumMap[index] = 0
  1603. }
  1604. tmpAllTryOutNumMap[index] += tmpTryOutNum
  1605. tmpAllFormalNumMap[index] += tmpFormalNum
  1606. tmpAllMeetingNumMap[index] += tmpCloseNum
  1607. }
  1608. tmpAdminReportRecord := roadshow.OverseasAdminReportRecord{
  1609. Name: researcher.RealName,
  1610. AdminId: researcher.AdminId,
  1611. RsReportRecordNumList: tmpAdminRsReportRecordNumList,
  1612. }
  1613. tmpGroupAdminReportRecord = append(tmpGroupAdminReportRecord, tmpAdminReportRecord)
  1614. }
  1615. for i := 0; i < len(tmpGroupCloseNumMap); i++ {
  1616. tmpGroupRsReportRecordNum := roadshow.RsOverseasReportRecordNum{
  1617. TryOutNum: tmpGroupTryOutNumMap[i],
  1618. FormalNum: tmpGroupFormalNumMap[i],
  1619. CloseNum: tmpGroupCloseNumMap[i],
  1620. StartDate: startDateIndexList[i],
  1621. EndDate: endDateIndexList[i],
  1622. }
  1623. tmpGroupRsReportRecordNumList = append(tmpGroupRsReportRecordNumList, tmpGroupRsReportRecordNum)
  1624. }
  1625. groupReportRecord := roadshow.OverseasGroupReportRecord{
  1626. Item: tmpGroupAdminReportRecord,
  1627. Name: v.GroupName,
  1628. RsReportRecordNumList: tmpGroupRsReportRecordNumList,
  1629. }
  1630. RsReportRecordResp.List = append(RsReportRecordResp.List, groupReportRecord)
  1631. }
  1632. //总体汇总数据
  1633. for i := 0; i < len(tmpAllFormalNumMap); i++ {
  1634. tmpGroupRsReportRecordNum := roadshow.RsOverseasReportRecordNum{
  1635. TryOutNum: tmpAllTryOutNumMap[i],
  1636. FormalNum: tmpAllFormalNumMap[i],
  1637. CloseNum: tmpAllMeetingNumMap[i],
  1638. StartDate: startDateIndexList[i],
  1639. EndDate: endDateIndexList[i],
  1640. }
  1641. rsAllReportRecordNumList = append(rsAllReportRecordNumList, tmpGroupRsReportRecordNum)
  1642. }
  1643. RsReportRecordResp.RsReportRecordNumList = rsAllReportRecordNumList
  1644. br.Ret = 200
  1645. br.Success = true
  1646. br.Msg = "获取成功"
  1647. br.Data = RsReportRecordResp
  1648. return
  1649. }