report.go 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287
  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. }