report.go 61 KB

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