report.go 60 KB

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