report.go 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718
  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. //获取列表
  1235. switch dataType {
  1236. case "week":
  1237. adminDataList, _, err = roadshowService.GetOverseasWeekDataV2("seller", dimensionType, 6)
  1238. if err != nil {
  1239. br.Msg = "数据异常"
  1240. br.ErrMsg = "数据异常,Err:" + err.Error()
  1241. return
  1242. }
  1243. case "month":
  1244. adminDataList, _, err = roadshowService.GetOverseasMonthDataV2("seller", dimensionType, 6)
  1245. if err != nil {
  1246. br.Msg = "数据异常"
  1247. br.ErrMsg = "数据异常,Err:" + err.Error()
  1248. return
  1249. }
  1250. case "time_interval":
  1251. if startDate == `` || endDate == `` {
  1252. br.Msg = "开始日期或结束日期不能为空"
  1253. br.ErrMsg = "开始日期或结束日期不能为空,Err:" + err.Error()
  1254. return
  1255. }
  1256. adminDataList, _, err = roadshowService.GetOverseasTimeIntervalData(startDate, endDate, "seller", dimensionType)
  1257. if err != nil {
  1258. br.Msg = "数据异常"
  1259. br.ErrMsg = "数据异常,Err:" + err.Error()
  1260. return
  1261. }
  1262. }
  1263. sellerList, err := roadshow.GetOverseaCustomCalendarSellerList()
  1264. adminReportRecordList := make([]roadshow.OverseasAdminReportRecord, 0)
  1265. rsAllReportRecordNumList := make([]roadshow.RsOverseasReportRecordNum, 0)
  1266. RsReportRecordResp := roadshow.RsOverseasReportRecordResp{
  1267. List: adminReportRecordList,
  1268. RsReportRecordNumList: rsAllReportRecordNumList,
  1269. }
  1270. startDateIndexList := make(map[int]string) //开始时间间隔map
  1271. endDateIndexList := make(map[int]string) //结束时间间隔map
  1272. tmpAllTryOutNumMap := make(map[int]int)
  1273. tmpAllFormalNumMap := make(map[int]int)
  1274. tmpAllCloseNumMap := make(map[int]int)
  1275. tmpAllOnlineNumMap := make(map[int]int)
  1276. tmpAllOfflineNumMap := make(map[int]int)
  1277. for _, researcher := range sellerList {
  1278. //每个区间的数据
  1279. tmpAdminRsReportRecordNumList := make([]roadshow.RsOverseasReportRecordNum, 0)
  1280. for index, adminData := range adminDataList {
  1281. startDateIndexList[index] = adminData.StartDate
  1282. endDateIndexList[index] = adminData.EndDate
  1283. var tmpTryOutNum, tmpFormalNum, tmpCloseNum, tmpOnlineNum, tmpOfflineNum int
  1284. if num, ok := adminData.TryOutMap[researcher.AdminId]; ok {
  1285. tmpTryOutNum = num
  1286. }
  1287. if num, ok := adminData.FormalMap[researcher.AdminId]; ok {
  1288. tmpFormalNum = num
  1289. }
  1290. if num, ok := adminData.CloseMap[researcher.AdminId]; ok {
  1291. tmpCloseNum = num
  1292. }
  1293. if num, ok := adminData.OnlineMap[researcher.AdminId]; ok {
  1294. tmpOnlineNum = num
  1295. }
  1296. if num, ok := adminData.OfflineMap[researcher.AdminId]; ok {
  1297. tmpOfflineNum = num
  1298. }
  1299. tmpAdminRsReportRecordNum := roadshow.RsOverseasReportRecordNum{
  1300. TryOutNum: tmpTryOutNum,
  1301. FormalNum: tmpFormalNum,
  1302. CloseNum: tmpCloseNum,
  1303. OnlineNum: tmpOnlineNum,
  1304. OfflineNum: tmpOfflineNum,
  1305. StartDate: adminData.StartDate,
  1306. EndDate: adminData.EndDate,
  1307. }
  1308. tmpAdminRsReportRecordNumList = append(tmpAdminRsReportRecordNumList, tmpAdminRsReportRecordNum)
  1309. //总数据汇总
  1310. if _, ok := tmpAllTryOutNumMap[index]; !ok {
  1311. tmpAllTryOutNumMap[index] = 0
  1312. }
  1313. if _, ok := tmpAllFormalNumMap[index]; !ok {
  1314. tmpAllFormalNumMap[index] = 0
  1315. }
  1316. if _, ok := tmpAllCloseNumMap[index]; !ok {
  1317. tmpAllCloseNumMap[index] = 0
  1318. }
  1319. if _, ok := tmpAllOnlineNumMap[index]; !ok {
  1320. tmpAllOnlineNumMap[index] = 0
  1321. }
  1322. if _, ok := tmpAllOfflineNumMap[index]; !ok {
  1323. tmpAllOfflineNumMap[index] = 0
  1324. }
  1325. tmpAllTryOutNumMap[index] += tmpTryOutNum
  1326. tmpAllFormalNumMap[index] += tmpFormalNum
  1327. tmpAllCloseNumMap[index] += tmpCloseNum
  1328. tmpAllOnlineNumMap[index] += tmpOnlineNum
  1329. tmpAllOfflineNumMap[index] += tmpOfflineNum
  1330. }
  1331. // 数据都为0的时候不显示
  1332. adminTotalNum := 0
  1333. for _, v := range tmpAdminRsReportRecordNumList {
  1334. adminTotalNum += v.TryOutNum + v.CloseNum + v.FormalNum
  1335. }
  1336. if adminTotalNum > 0 {
  1337. tmpAdminReportRecord := roadshow.OverseasAdminReportRecord{
  1338. Name: researcher.RealName,
  1339. AdminId: researcher.AdminId,
  1340. RsReportRecordNumList: tmpAdminRsReportRecordNumList,
  1341. }
  1342. RsReportRecordResp.List = append(RsReportRecordResp.List, tmpAdminReportRecord)
  1343. }
  1344. }
  1345. //总体汇总数据
  1346. for i := 0; i < len(tmpAllFormalNumMap); i++ {
  1347. tmpGroupRsReportRecordNum := roadshow.RsOverseasReportRecordNum{
  1348. TryOutNum: tmpAllTryOutNumMap[i],
  1349. FormalNum: tmpAllFormalNumMap[i],
  1350. CloseNum: tmpAllCloseNumMap[i],
  1351. OnlineNum: tmpAllOnlineNumMap[i],
  1352. OfflineNum: tmpAllOfflineNumMap[i],
  1353. StartDate: startDateIndexList[i],
  1354. EndDate: endDateIndexList[i],
  1355. }
  1356. rsAllReportRecordNumList = append(rsAllReportRecordNumList, tmpGroupRsReportRecordNum)
  1357. }
  1358. RsReportRecordResp.RsReportRecordNumList = rsAllReportRecordNumList
  1359. br.Ret = 200
  1360. br.Success = true
  1361. br.Msg = "获取成功"
  1362. br.Data = RsReportRecordResp
  1363. return
  1364. }
  1365. // OverseasResearcherReportList
  1366. // @Title 研究员路演统计
  1367. // @Description 研究员路演统计接口
  1368. // @Param DataType query string true "枚举值:week、month、time_interval"
  1369. // @Param StartDate query string true "开始日期,格式:2022-04-06"
  1370. // @Param EndDate query string true "结束日期,格式:2022-04-06"
  1371. // @Success 200 {object} roadshow.RsReportRecordResp
  1372. // @router /overseas_custom/researcher/list [get]
  1373. func (this *CalendarController) OverseasResearcherReportList() {
  1374. br := new(models.BaseResponse).Init()
  1375. defer func() {
  1376. this.Data["json"] = br
  1377. this.ServeJSON()
  1378. }()
  1379. sysUser := this.SysUser
  1380. if sysUser == nil {
  1381. br.Msg = "请登录"
  1382. br.ErrMsg = "请登录,SysUser Is Empty"
  1383. br.Ret = 408
  1384. return
  1385. }
  1386. dataType := this.GetString("DataType")
  1387. startDate := this.GetString("StartDate")
  1388. endDate := this.GetString("EndDate")
  1389. var adminDataList []roadshowService.OverseasAdminDataMap
  1390. var err error
  1391. //var firstDate time.Time
  1392. //获取列表
  1393. switch dataType {
  1394. case "week":
  1395. adminDataList, _, err = roadshowService.GetOverseasWeekData("researcher", "company_status")
  1396. if err != nil {
  1397. br.Msg = "数据异常"
  1398. br.ErrMsg = "数据异常,Err:" + err.Error()
  1399. return
  1400. }
  1401. case "month":
  1402. adminDataList, _, err = roadshowService.GetOverseasMonthData("researcher", "company_status")
  1403. if err != nil {
  1404. br.Msg = "数据异常"
  1405. br.ErrMsg = "数据异常,Err:" + err.Error()
  1406. return
  1407. }
  1408. case "time_interval":
  1409. if startDate == `` || endDate == `` {
  1410. br.Msg = "开始日期或结束日期不能为空"
  1411. br.ErrMsg = "开始日期或结束日期不能为空,Err:" + err.Error()
  1412. return
  1413. }
  1414. adminDataList, _, err = roadshowService.GetOverseasTimeIntervalData(startDate, endDate, "researcher", "company_status")
  1415. if err != nil {
  1416. br.Msg = "数据异常"
  1417. br.ErrMsg = "数据异常,Err:" + err.Error()
  1418. return
  1419. }
  1420. }
  1421. researcherList, err := roadshow.GetOverseaCustomCalendarResearcherList()
  1422. if err != nil {
  1423. br.Msg = "获取信息失败!"
  1424. br.ErrMsg = "获取分组信息失败!,GetResearcherV2 Err:" + err.Error()
  1425. return
  1426. }
  1427. adminReportRecordList := make([]roadshow.OverseasAdminReportRecord, 0)
  1428. rsAllReportRecordNumList := make([]roadshow.RsOverseasReportRecordNum, 0)
  1429. RsReportRecordResp := roadshow.RsOverseasReportRecordResp{
  1430. List: adminReportRecordList,
  1431. RsReportRecordNumList: rsAllReportRecordNumList,
  1432. }
  1433. startDateIndexList := make(map[int]string) //开始时间间隔map
  1434. endDateIndexList := make(map[int]string) //结束时间间隔map
  1435. tmpAllTryOutNumMap := make(map[int]int)
  1436. tmpAllFormalNumMap := make(map[int]int)
  1437. tmpAllMeetingNumMap := make(map[int]int)
  1438. for _, researcher := range researcherList {
  1439. //组内研究员数据
  1440. //每个区间的数据
  1441. tmpAdminRsReportRecordNumList := make([]roadshow.RsOverseasReportRecordNum, 0)
  1442. for index, adminData := range adminDataList {
  1443. startDateIndexList[index] = adminData.StartDate
  1444. endDateIndexList[index] = adminData.EndDate
  1445. var tmpTryOutNum, tmpFormalNum, tmpCloseNum int
  1446. if num, ok := adminData.TryOutMap[researcher.AdminId]; ok {
  1447. tmpTryOutNum = num
  1448. }
  1449. if num, ok := adminData.FormalMap[researcher.AdminId]; ok {
  1450. tmpFormalNum = num
  1451. }
  1452. if num, ok := adminData.CloseMap[researcher.AdminId]; ok {
  1453. tmpCloseNum = num
  1454. }
  1455. tmpAdminRsReportRecordNum := roadshow.RsOverseasReportRecordNum{
  1456. TryOutNum: tmpTryOutNum,
  1457. FormalNum: tmpFormalNum,
  1458. CloseNum: tmpCloseNum,
  1459. StartDate: adminData.StartDate,
  1460. EndDate: adminData.EndDate,
  1461. }
  1462. tmpAdminRsReportRecordNumList = append(tmpAdminRsReportRecordNumList, tmpAdminRsReportRecordNum)
  1463. //总数据汇总
  1464. if _, ok := tmpAllTryOutNumMap[index]; !ok {
  1465. tmpAllTryOutNumMap[index] = 0
  1466. }
  1467. if _, ok := tmpAllFormalNumMap[index]; !ok {
  1468. tmpAllFormalNumMap[index] = 0
  1469. }
  1470. if _, ok := tmpAllMeetingNumMap[index]; !ok {
  1471. tmpAllMeetingNumMap[index] = 0
  1472. }
  1473. tmpAllTryOutNumMap[index] += tmpTryOutNum
  1474. tmpAllFormalNumMap[index] += tmpFormalNum
  1475. tmpAllMeetingNumMap[index] += tmpCloseNum
  1476. }
  1477. // 数据都为0的时候不显示
  1478. adminTotalNum := 0
  1479. for _, v := range tmpAdminRsReportRecordNumList {
  1480. adminTotalNum += v.TryOutNum + v.CloseNum + v.FormalNum
  1481. }
  1482. if adminTotalNum > 0 {
  1483. tmpAdminReportRecord := roadshow.OverseasAdminReportRecord{
  1484. Name: researcher.RealName,
  1485. AdminId: researcher.AdminId,
  1486. RsReportRecordNumList: tmpAdminRsReportRecordNumList,
  1487. }
  1488. RsReportRecordResp.List = append(RsReportRecordResp.List, tmpAdminReportRecord)
  1489. }
  1490. }
  1491. //总体汇总数据
  1492. for i := 0; i < len(tmpAllFormalNumMap); i++ {
  1493. tmpGroupRsReportRecordNum := roadshow.RsOverseasReportRecordNum{
  1494. TryOutNum: tmpAllTryOutNumMap[i],
  1495. FormalNum: tmpAllFormalNumMap[i],
  1496. CloseNum: tmpAllMeetingNumMap[i],
  1497. StartDate: startDateIndexList[i],
  1498. EndDate: endDateIndexList[i],
  1499. }
  1500. rsAllReportRecordNumList = append(rsAllReportRecordNumList, tmpGroupRsReportRecordNum)
  1501. }
  1502. RsReportRecordResp.RsReportRecordNumList = rsAllReportRecordNumList
  1503. br.Ret = 200
  1504. br.Success = true
  1505. br.Msg = "获取成功"
  1506. br.Data = RsReportRecordResp
  1507. return
  1508. }
  1509. // OverseasCalendarList
  1510. // @Title 海外客户路演详情列表
  1511. // @Description 海外客户路演详情列表接口
  1512. // @Param AdminType query string true "枚举值:researcher、seller、 special:专项路演"
  1513. // @Param DataType query string true "枚举值:try_out、formal、close、online、offline"
  1514. // @Param AdminIds query string true "用户ids"
  1515. // @Param StartDate query string true "开始日期,格式:2022-04-06"
  1516. // @Param EndDate query string true "结束日期,格式:2022-04-06"
  1517. // @Success 200 {object} []roadshow.RsReportRecordList
  1518. // @router /overseas/calendar/list [get]
  1519. func (this *CalendarController) OverseasCalendarList() {
  1520. br := new(models.BaseResponse).Init()
  1521. defer func() {
  1522. this.Data["json"] = br
  1523. this.ServeJSON()
  1524. }()
  1525. sysUser := this.SysUser
  1526. if sysUser == nil {
  1527. br.Msg = "请登录"
  1528. br.ErrMsg = "请登录,SysUser Is Empty"
  1529. br.Ret = 408
  1530. return
  1531. }
  1532. adminType := this.GetString("AdminType")
  1533. dataType := this.GetString("DataType")
  1534. startDate := this.GetString("StartDate")
  1535. endDate := this.GetString("EndDate")
  1536. adminIds := this.GetString("AdminIds")
  1537. if adminIds == "" {
  1538. br.Msg = "请传入对应的人员"
  1539. return
  1540. }
  1541. //adminIdsArr := make([]int, 0)
  1542. //adminIdSlice := strings.Split(adminIds, ",")
  1543. //for _, v := range adminIdSlice {
  1544. // id,_ := strconv.Atoi(v)
  1545. // adminIdsArr = append(adminIdsArr, id)
  1546. //}
  1547. //正式客户
  1548. //var condition string
  1549. //var pars []interface{}
  1550. //condition = ` and a.start_date >= ? and a.end_date <= ? `
  1551. //pars = append(pars, startDate, endDate)
  1552. var sellerIds, researcherIds string
  1553. //选择的人员类型(发起人还是被发起人)
  1554. if adminType == "seller" {
  1555. //condition += ` and a.seller_id IN (` + utils.GetOrmInReplace(len(adminIdsArr)) + `)`
  1556. sellerIds = adminIds
  1557. } else {
  1558. //condition += ` and a.researcher_id IN (` + utils.GetOrmInReplace(len(adminIdsArr)) + `)`
  1559. researcherIds = adminIds
  1560. }
  1561. //pars = append(pars, adminIdsArr)
  1562. var status string
  1563. //获取列表
  1564. switch dataType {
  1565. case "try_out":
  1566. //condition += ` and a.company_status = ? )`
  1567. //pars = append(pars, "试用")
  1568. status = "试用"
  1569. case "formal":
  1570. //condition += ` and a.company_status = ? )`
  1571. //pars = append(pars, "正式")
  1572. status = "正式"
  1573. case "close":
  1574. //condition += ` and a.company_status = ? )`
  1575. //pars = append(pars, "关闭")
  1576. status = "关闭"
  1577. //case "online":
  1578. // condition += ` and a.roadshow_type = ? `
  1579. // pars = append(pars, "线上")
  1580. //case "offline":
  1581. // condition += ` and a.roadshow_type = ? `
  1582. // pars = append(pars, "线下")
  1583. default:
  1584. br.Msg = "请传入类型"
  1585. br.ErrMsg = "请传入类型DataType"
  1586. return
  1587. }
  1588. list, err := roadshow.GetOverseaCustomCalendarList2(sellerIds, researcherIds, startDate, endDate, status)
  1589. if err != nil {
  1590. br.Msg = "获取失败"
  1591. br.ErrMsg = "获取失败,ERR:" + err.Error()
  1592. return
  1593. }
  1594. br.Ret = 200
  1595. br.Success = true
  1596. br.Msg = "获取成功"
  1597. br.Data = list
  1598. return
  1599. }