rai_serve.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. package cygx
  2. import (
  3. "errors"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "hongze/hz_crm_api/controllers"
  7. "hongze/hz_crm_api/models"
  8. "hongze/hz_crm_api/models/cygx"
  9. "hongze/hz_crm_api/models/roadshow"
  10. "hongze/hz_crm_api/utils"
  11. "strconv"
  12. "strings"
  13. "time"
  14. )
  15. // 权益服务类型
  16. type RaiServeCoAntroller struct {
  17. controllers.BaseAuthController
  18. }
  19. // @Title 服务类型列表
  20. // @Description 服务类型列表接口
  21. // @Success 200 {object} cygx.RaiServeTypeListResp
  22. // @router /rai_serve/type_list [get]
  23. func (this *RaiServeCoAntroller) TypeList() {
  24. br := new(models.BaseResponse).Init()
  25. defer func() {
  26. this.Data["json"] = br
  27. this.ServeJSON()
  28. }()
  29. sysUser := this.SysUser
  30. if sysUser == nil {
  31. br.Msg = "请登录"
  32. br.ErrMsg = "请登录,SysUser Is Empty"
  33. br.Ret = 408
  34. return
  35. }
  36. resp := new(cygx.RaiServeTypeListResp)
  37. var condition string
  38. list, err := cygx.GetRaiServeTypeRespList(condition)
  39. if err != nil {
  40. br.Msg = "获取失败"
  41. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  42. return
  43. }
  44. resp.List = list
  45. br.Ret = 200
  46. br.Success = true
  47. br.Msg = "获取成功"
  48. br.Data = resp
  49. }
  50. // @Title 标签搜索
  51. // @Description 标签搜索接口
  52. // @Param KeyWord query string false "搜索关键词"
  53. // @Success 200 {object} cygx.RaiServeTagListResp
  54. // @router /rai_serve/search_tag [get]
  55. func (this *RaiServeCoAntroller) SearchTag() {
  56. br := new(models.BaseResponse).Init()
  57. defer func() {
  58. this.Data["json"] = br
  59. this.ServeJSON()
  60. }()
  61. sysUser := this.SysUser
  62. if sysUser == nil {
  63. br.Msg = "请登录"
  64. br.ErrMsg = "请登录,SysUser Is Empty"
  65. br.Ret = 408
  66. return
  67. }
  68. keyWord := this.GetString("KeyWord")
  69. if keyWord == "" {
  70. br.Msg = "请输入搜索关键词"
  71. return
  72. }
  73. //keyWordSlice := strings.Split(keyWord, ",")
  74. //var conditionindustrial string
  75. //var conditionsubject string
  76. //for _, v := range keyWordSlice {
  77. // conditionindustrial += ` OR i.industry_name LIKE '%` + v + `%' `
  78. // conditionsubject += ` OR s.subject_name LIKE '%` + v + `%' `
  79. //}
  80. resp := new(cygx.RaiServeTagListResp)
  81. list, err := cygx.GetRaiServeSearchTagRespList(keyWord)
  82. if err != nil {
  83. br.Msg = "获取失败"
  84. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  85. return
  86. }
  87. //如果有固收或者策略就去查询行业表
  88. if strings.Contains("固收", keyWord) || strings.Contains("策略", keyWord) {
  89. var condition string
  90. var pars []interface{}
  91. keyWord = "%" + keyWord + "%"
  92. condition = ` AND product_id = 2 AND permission_name IN ('策略','固收') AND permission_name LIKE ? `
  93. pars = append(pars, keyWord)
  94. listChartPermission, err := models.GetChartPermissionListByCondition(condition, pars)
  95. if err != nil {
  96. br.Msg = "获取失败"
  97. br.ErrMsg = "获取数据失败,GetChartPermissionListByCondition Err:" + err.Error()
  98. return
  99. }
  100. for _, v := range listChartPermission {
  101. item := new(cygx.RaiServeTagResp)
  102. item.TagType = 3
  103. item.TagId = v.ChartPermissionId
  104. item.TagName = v.PermissionName
  105. list = append(list, item)
  106. }
  107. }
  108. if len(list) == 0 {
  109. list = make([]*cygx.RaiServeTagResp, 0)
  110. } else {
  111. for _, v := range list {
  112. v.Md5Key = utils.MD5(fmt.Sprintf("K_", v.TagType, "V_", v.TagId))
  113. }
  114. }
  115. resp.List = list
  116. br.Ret = 200
  117. br.Success = true
  118. br.Msg = "获取成功"
  119. br.Data = resp
  120. }
  121. // @Title 标签搜索(研究员日历添加到会信息)
  122. // @Description 标签搜索接口
  123. // @Param KeyWord query string false "搜索关键词"
  124. // @Param ResearcherId query int false "研究员ID"
  125. // @Success 200 {object} cygx.RaiServeTagListResp
  126. // @router /rai_serve/search_tag_by_calendar [get]
  127. func (this *RaiServeCoAntroller) SearchTagCalendar() {
  128. br := new(models.BaseResponse).Init()
  129. defer func() {
  130. this.Data["json"] = br
  131. this.ServeJSON()
  132. }()
  133. sysUser := this.SysUser
  134. if sysUser == nil {
  135. br.Msg = "请登录"
  136. br.ErrMsg = "请登录,SysUser Is Empty"
  137. br.Ret = 408
  138. return
  139. }
  140. keyWord := this.GetString("KeyWord")
  141. researcherId := this.GetString("ResearcherId")
  142. askEmailList, err := cygx.GetAskEmailListByAdminIds(researcherId)
  143. if err != nil {
  144. br.Msg = "获取失败"
  145. br.ErrMsg = "GetAskEmailCountByCelue,Err:" + err.Error()
  146. return
  147. }
  148. var hasCelue bool
  149. var permissionName []string
  150. for _, v := range askEmailList {
  151. permissionName = append(permissionName, v.ChartPermissionName)
  152. if v.ChartPermissionName == "策略" || v.ChartPermissionName == "固收" {
  153. hasCelue = true
  154. }
  155. }
  156. var permissionNameSql []string
  157. for _, v := range permissionName {
  158. permissionNameSql = append(permissionNameSql, "'"+v+"'")
  159. }
  160. chartList, err := models.GetChartPermissionByNamesByRai(permissionNameSql)
  161. if err != nil {
  162. br.Msg = "获取失败"
  163. br.ErrMsg = "获取数据失败,GetChartPermissionByNames Err:" + err.Error()
  164. return
  165. }
  166. var list []*cygx.RaiServeTagResp
  167. resp := new(cygx.RaiServeTagListResp)
  168. if hasCelue {
  169. for _, v := range chartList {
  170. item := new(cygx.RaiServeTagResp)
  171. item.TagType = 3
  172. item.TagId = v.ChartPermissionId
  173. item.TagName = v.PermissionName
  174. list = append(list, item)
  175. }
  176. } else {
  177. if keyWord == "" {
  178. br.Msg = "请输入搜索关键词"
  179. return
  180. }
  181. keyWordSlice := strings.Split(keyWord, ",")
  182. var conditionindustrial string
  183. var conditionsubject string
  184. for _, v := range keyWordSlice {
  185. conditionindustrial += ` OR i.industry_name LIKE '%` + v + `%' `
  186. conditionsubject += ` OR s.subject_name LIKE '%` + v + `%' `
  187. }
  188. var permissionId []string
  189. for _, v := range chartList {
  190. permissionId = append(permissionId, strconv.Itoa(v.ChartPermissionId))
  191. }
  192. list, err = cygx.GetRaiServeSearchTagRespListBycharId(keyWord, strings.Join(permissionId, ","), conditionindustrial, conditionsubject)
  193. if err != nil {
  194. br.Msg = "获取失败"
  195. br.ErrMsg = "获取数据失败,GetRaiServeSearchTagRespListBycharId Err:" + err.Error()
  196. return
  197. }
  198. }
  199. if len(list) == 0 {
  200. list = make([]*cygx.RaiServeTagResp, 0)
  201. } else {
  202. for _, v := range list {
  203. v.Md5Key = utils.MD5(fmt.Sprintf("K_", v.TagType, "V_", v.TagId))
  204. }
  205. }
  206. resp.List = list
  207. br.Ret = 200
  208. br.Success = true
  209. br.Msg = "获取成功"
  210. br.Data = resp
  211. }
  212. // @Title 校验是否属于策略固收
  213. // @Description 校验是否属于策略固收接口
  214. // @Param ResearcherId query int false "研究员ID"
  215. // @Success 200 {object} cygx.RaiServeTagListResp
  216. // @router /rai_serve/chcck_PermissionName [get]
  217. func (this *RaiServeCoAntroller) ChcckPermissionName() {
  218. br := new(models.BaseResponse).Init()
  219. defer func() {
  220. this.Data["json"] = br
  221. this.ServeJSON()
  222. }()
  223. sysUser := this.SysUser
  224. if sysUser == nil {
  225. br.Msg = "请登录"
  226. br.ErrMsg = "请登录,SysUser Is Empty"
  227. br.Ret = 408
  228. return
  229. }
  230. researcherId := this.GetString("ResearcherId")
  231. askEmailList, err := cygx.GetAskEmailListByAdminIds(researcherId)
  232. if err != nil {
  233. br.Msg = "获取失败"
  234. br.ErrMsg = "GetAskEmailCountByCelue,Err:" + err.Error()
  235. return
  236. }
  237. var belong bool
  238. var permissionNameResp []string
  239. var permissionNames []string
  240. for _, v := range askEmailList {
  241. permissionNames = append(permissionNames, v.ChartPermissionName)
  242. if v.ChartPermissionName == "策略" || v.ChartPermissionName == "固收" {
  243. belong = true
  244. permissionNameResp = append(permissionNameResp, v.ChartPermissionName)
  245. }
  246. }
  247. resp := new(cygx.ChekChartPermissionNameResp)
  248. resp.Belong = belong
  249. resp.ChartPermissionName = strings.Join(permissionNameResp, ",")
  250. br.Ret = 200
  251. br.Success = true
  252. br.Msg = "获取成功"
  253. br.Data = resp
  254. }
  255. // @Title 权益服务统计列表
  256. // @Description 权益服务统计列表接口
  257. // @Param PageSize query int true "每页数据条数"
  258. // @Param CurrentIndex query int true "当前页页码,从1开始"
  259. // @Param SellerId query string false "销售id"
  260. // @Param ShareSellerId query string false "共享销售ID"
  261. // @Param ServeTypeId int int false "服务类型ID"
  262. // @Param TagType int string false "标签类型"
  263. // @Param TagId int string false "标签ID"
  264. // @Param Status query string false "客户状态,正式、未续约(除了正式之外的所有)"
  265. // @Param SortType query string true "如何排序,是正序还是倒序,枚举值:`asc 正序`,`desc 倒叙`"
  266. // @Param IsExport query bool false "是否导出excel,默认是false"
  267. // @Success 200 {object} cygx.RaiServeTagListResp
  268. // @router /rai_serve/list [get]
  269. func (this *RaiServeCoAntroller) List() {
  270. br := new(models.BaseResponse).Init()
  271. defer func() {
  272. this.Data["json"] = br
  273. this.ServeJSON()
  274. }()
  275. sysUser := this.SysUser
  276. if sysUser == nil {
  277. br.Msg = "请登录"
  278. br.ErrMsg = "请登录,SysUser Is Empty"
  279. br.Ret = 408
  280. return
  281. }
  282. pageSize, _ := this.GetInt("PageSize")
  283. currentIndex, _ := this.GetInt("CurrentIndex")
  284. status := this.GetString("Status")
  285. sellerId := this.GetString("SellerId")
  286. shareSellerId := this.GetString("ShareSellerId")
  287. sortType := this.GetString("SortType")
  288. tagType, _ := this.GetInt("TagType")
  289. tagId, _ := this.GetInt("TagId")
  290. serveTypeId, _ := this.GetInt("ServeTypeId")
  291. isExport, _ := this.GetBool("IsExport")
  292. resp := new(cygx.CygxRaiServeCompanyListResp)
  293. var startSize int
  294. if pageSize <= 0 {
  295. pageSize = utils.PageSize20
  296. }
  297. if currentIndex <= 0 {
  298. currentIndex = 1
  299. }
  300. startSize = utils.StartIndex(currentIndex, pageSize)
  301. var condition string
  302. var sortStr string
  303. var pars []interface{}
  304. if status != "" {
  305. if status == "正式" {
  306. condition = " AND status = '正式' "
  307. } else {
  308. condition = " AND status != '正式' "
  309. }
  310. }
  311. if sellerId != "" {
  312. condition = " AND seller_id IN (?) "
  313. pars = append(pars, sellerId)
  314. }
  315. if shareSellerId != "" {
  316. condition = " AND share_seller_id IN (?) "
  317. pars = append(pars, shareSellerId)
  318. }
  319. if sortType != "" {
  320. if sortType == "asc" {
  321. sortStr = " ORDER BY money ASC "
  322. } else if sortType == "desc" {
  323. sortStr = " ORDER BY money DESC "
  324. }
  325. } else {
  326. sortStr = " ORDER BY end_date DESC "
  327. }
  328. //如果不是权益管理员和admin、财务,就做可见权限限制
  329. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_RAI_ADMIN && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_RAI_RESEARCHR {
  330. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER {
  331. condition = " AND (seller_id = ? OR share_seller_id = ? ) "
  332. pars = append(pars, sysUser.AdminId, sysUser.AdminId)
  333. }
  334. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  335. condition = " AND ( seller_id = ? OR share_seller_id = ? OR group_id = ? OR share_group_id = ? ) "
  336. pars = append(pars, sysUser.AdminId, sysUser.AdminId, sysUser.GroupId, sysUser.GroupId)
  337. }
  338. }
  339. total, err := cygx.GetCygxRaiServeCompanyCount(condition, pars)
  340. if err != nil {
  341. br.Msg = "获取失败"
  342. br.ErrMsg = "获取失败,GetCygxRaiServeCompanyCountErr:" + err.Error()
  343. return
  344. }
  345. listRaiServeCompany, err := cygx.GetCygxRaiServeCompanyList(condition+sortStr, pars, startSize, pageSize)
  346. if err != nil {
  347. br.Msg = "获取失败"
  348. br.ErrMsg = "获取失败,Err:" + err.Error()
  349. return
  350. }
  351. var companyIds []int
  352. for _, v := range listRaiServeCompany {
  353. companyIds = append(companyIds, v.CompanyId)
  354. }
  355. mapWeekAmount := make(map[string]float64) //周度服务量
  356. lencompanyIds := len(companyIds)
  357. if lencompanyIds > 0 {
  358. var conditionBill string
  359. var parsBill []interface{}
  360. conditionBill, parsBill, err = getServeBillTag(tagType, tagId) // 标签ID搜索语句处理
  361. if err != nil {
  362. br.Msg = "获取信息失败!"
  363. br.ErrMsg = "获取用户信息失败-getServeBillTag!Err:" + err.Error()
  364. return
  365. }
  366. //服务类型筛选
  367. if serveTypeId > 0 {
  368. conditionBill += ` AND serve_type_id = ? `
  369. parsBill = append(parsBill, serveTypeId)
  370. }
  371. conditionBill += " AND company_id IN (" + utils.GetOrmInReplace(lencompanyIds) + ") "
  372. parsBill = append(parsBill, companyIds)
  373. listBill, err := cygx.GetCygxRaiServeBillListAll(conditionBill, parsBill)
  374. if err != nil {
  375. br.Msg = "获取信息失败!"
  376. br.ErrMsg = "获取用户信息失败-GetCygxRaiServeBillListAll!Err:" + err.Error()
  377. return
  378. }
  379. now := time.Now()
  380. weeks := 4
  381. for _, v := range listBill {
  382. for i := 0; i < weeks; i++ {
  383. // 计算当前周的周一
  384. monday := now.AddDate(0, 0, -int(now.Weekday()-time.Monday)-i*7)
  385. weekmonday := monday.Format(utils.FormatDate)
  386. if v.WeekStartDate == weekmonday {
  387. mapWeekAmount[fmt.Sprintf("CID_", v.CompanyId, "WEEK_", i)] += v.ServeCount
  388. }
  389. }
  390. }
  391. }
  392. if isExport {
  393. }
  394. for _, v := range listRaiServeCompany {
  395. item := new(cygx.CygxRaiServeCompanyResp)
  396. item.CompanyId = v.CompanyId
  397. item.CompanyName = v.CompanyName
  398. item.Money = v.Money
  399. item.ServeCoverageRate = v.ServeCoverageRate + "%"
  400. item.SellerId = v.SellerId
  401. item.SellerName = v.SellerName
  402. item.StartDate = v.StartDate
  403. item.StartDate = v.StartDate
  404. item.EndDate = v.EndDate
  405. item.ShareSeller = v.ShareSeller
  406. item.ShareSellerId = v.ShareSellerId
  407. item.Status = v.Status
  408. item.PermissionName = v.PermissionName
  409. item.ThisWeekAmount = mapWeekAmount[fmt.Sprintf("CID_", v.CompanyId, "WEEK_", 0)]
  410. item.LastWeekAmount = mapWeekAmount[fmt.Sprintf("CID_", v.CompanyId, "WEEK_", 1)]
  411. item.TwoWeekAmount = mapWeekAmount[fmt.Sprintf("CID_", v.CompanyId, "WEEK_", 2)]
  412. item.ThreeWeekAmount = mapWeekAmount[fmt.Sprintf("CID_", v.CompanyId, "WEEK_", 3)]
  413. resp.List = append(resp.List, item)
  414. }
  415. page := paging.GetPaging(currentIndex, pageSize, total)
  416. resp.Paging = page
  417. br.Ret = 200
  418. br.Success = true
  419. br.Msg = "获取成功"
  420. br.Data = resp
  421. }
  422. // 标签搜索语句筛选
  423. func getServeBillTag(tagType, tagId int) (conditionBill string, parsBill []interface{}, err error) {
  424. var activityIds []int
  425. var activitySpecialIds []int
  426. var articleIds []int
  427. var rsCalendarIds []int
  428. switch tagType {
  429. case 1:
  430. listGroupActivity, e := cygx.GetIndustrialActivityGroupManagementListByIndustriaId(tagId, 1) // 关联的活动
  431. if e != nil {
  432. err = errors.New("GetIndustrialActivityGroupManagementListByIndustriaId, Err: " + e.Error())
  433. return
  434. }
  435. for _, v := range listGroupActivity {
  436. activityIds = append(activityIds, v.ActivityId)
  437. }
  438. listGroupActivitySpecial, e := cygx.GetIndustrialActivityGroupManagementListByIndustriaId(tagId, 2) // 关联的产业
  439. if e != nil {
  440. err = errors.New("GetIndustrialActivityGroupManagementListByIndustriaId, Err: " + e.Error())
  441. return
  442. }
  443. for _, v := range listGroupActivitySpecial {
  444. activitySpecialIds = append(activitySpecialIds, v.ActivityId)
  445. }
  446. listGroupArticle, e := cygx.GetIndustrialArticleGroupManagementListByindustrialId(tagId) // 关联的产业
  447. if e != nil {
  448. err = errors.New("GetIndustrialArticleGroupManagementListByindustrialId, Err: " + e.Error())
  449. return
  450. }
  451. for _, v := range listGroupArticle {
  452. articleIds = append(articleIds, v.ArticleId)
  453. }
  454. listGroupRsCalendar, e := roadshow.GetRsCalendarMeetingLabelGroupDetailByTag(tagType, tagId)
  455. if e != nil {
  456. err = errors.New("GetRsCalendarMeetingLabelGroupDetailByTag, Err: " + e.Error())
  457. return
  458. }
  459. for _, v := range listGroupRsCalendar {
  460. rsCalendarIds = append(rsCalendarIds, v.RsCalendarId)
  461. }
  462. case 2:
  463. listGroupActivity, e := cygx.GetSubjectActivityGroupManagementListBySubjectId(tagId, 1) // 关联的活动
  464. if e != nil {
  465. err = errors.New("GetSubjectActivityGroupManagementListBySubjectId, Err: " + e.Error())
  466. return
  467. }
  468. for _, v := range listGroupActivity {
  469. activityIds = append(activityIds, v.ActivityId)
  470. }
  471. listGroupActivitySpecial, e := cygx.GetSubjectActivityGroupManagementListBySubjectId(tagId, 2) // 关联的产业
  472. if e != nil {
  473. err = errors.New("GetSubjectActivityGroupManagementListBySubjectId, Err: " + e.Error())
  474. return
  475. }
  476. for _, v := range listGroupActivitySpecial {
  477. activitySpecialIds = append(activitySpecialIds, v.ActivityId)
  478. }
  479. listGroupArticle, e := cygx.GetSubjectArticleGroupManagementListBysubjectId(tagId) // 关联的产业
  480. if e != nil {
  481. err = errors.New("GetSubjectArticleGroupManagementListBysubjectId, Err: " + e.Error())
  482. return
  483. }
  484. for _, v := range listGroupArticle {
  485. articleIds = append(articleIds, v.ArticleId)
  486. }
  487. listGroupRsCalendar, e := roadshow.GetRsCalendarMeetingLabelGroupDetailByTag(tagType, tagId)
  488. if e != nil {
  489. err = errors.New("GetRsCalendarMeetingLabelGroupDetailByTag, Err: " + e.Error())
  490. return
  491. }
  492. for _, v := range listGroupRsCalendar {
  493. rsCalendarIds = append(rsCalendarIds, v.RsCalendarId)
  494. }
  495. case 3:
  496. conditionBill += " AND chart_permission_id = ? "
  497. parsBill = append(parsBill, tagId)
  498. }
  499. lenactivityIds := len(activityIds)
  500. if lenactivityIds > 0 {
  501. conditionBill += ` AND IF ( source = 'activity', source_id IN (` + utils.GetOrmInReplace(lenactivityIds) + `) , 1 = 1 ) `
  502. parsBill = append(parsBill, activityIds)
  503. }
  504. lenactivitySpecialIds := len(activitySpecialIds)
  505. if lenactivitySpecialIds > 0 {
  506. conditionBill += ` AND IF ( source = 'activityspecial', source_id IN (` + utils.GetOrmInReplace(lenactivitySpecialIds) + `) , 1 = 1 ) `
  507. parsBill = append(parsBill, activitySpecialIds)
  508. }
  509. lenarticleIds := len(articleIds)
  510. if lenarticleIds > 0 {
  511. conditionBill += ` AND IF ( source = 'article', source_id IN (` + utils.GetOrmInReplace(lenarticleIds) + `) , 1 = 1 ) `
  512. parsBill = append(parsBill, articleIds)
  513. }
  514. lenrsCalendarIds := len(rsCalendarIds)
  515. if lenrsCalendarIds > 0 {
  516. conditionBill += ` AND IF ( source = 'rscalendar', source_id IN (` + utils.GetOrmInReplace(lenrsCalendarIds) + `) , 1 = 1 ) `
  517. parsBill = append(parsBill, rsCalendarIds)
  518. }
  519. return
  520. }
  521. // @Title 近四周覆盖率
  522. // @Description 近四周覆盖率接口
  523. // @Param CompanyId query int false "公司ID"
  524. // @Success 200 {object} cygx.RaiServeTagListResp
  525. // @router /rai_serve/coverage_rate [get]
  526. func (this *RaiServeCoAntroller) CoverageRate() {
  527. br := new(models.BaseResponse).Init()
  528. defer func() {
  529. this.Data["json"] = br
  530. this.ServeJSON()
  531. }()
  532. sysUser := this.SysUser
  533. if sysUser == nil {
  534. br.Msg = "请登录"
  535. br.ErrMsg = "请登录,SysUser Is Empty"
  536. br.Ret = 408
  537. return
  538. }
  539. companyId, _ := this.GetInt("CompanyId")
  540. listWeekBill, err := cygx.GetCygxRaiServeBillListWeek4(companyId)
  541. if err != nil {
  542. br.Msg = "获取信息失败!"
  543. br.ErrMsg = "获取用户信息失败-GetCygxRaiServeBillListWeek4!Err:" + err.Error()
  544. return
  545. }
  546. mapWeek := make(map[int]float64)
  547. for k, v := range listWeekBill {
  548. mapWeek[k] = v.ServeCount
  549. }
  550. resp := new(cygx.RaiServeCoverageRateResp)
  551. resp.ThisWeekAmount = strconv.Itoa(int(mapWeek[0])) + "%"
  552. resp.LastWeekAmount = strconv.Itoa(int(mapWeek[1])) + "%"
  553. resp.TwoWeekAmount = strconv.Itoa(int(mapWeek[2])) + "%"
  554. resp.ThreeWeekAmount = strconv.Itoa(int(mapWeek[3])) + "%"
  555. br.Ret = 200
  556. br.Success = true
  557. br.Msg = "获取成功"
  558. br.Data = resp
  559. }
  560. // @Title 明细列表
  561. // @Description 明细列表接口
  562. // @Param PageSize query int true "每页数据条数"
  563. // @Param CurrentIndex query int true "当前页页码,从1开始"
  564. // @Param CompanyId query int false "公司ID"
  565. // @Param TagType query int false "标签类型"
  566. // @Param TagId query int false "标签ID"
  567. // @Param ServeTypeId int int false "服务类型ID"
  568. // @Param WhatWeek query int false "哪一周 ,1:本周、2:上周、3:上上周、4上三周"
  569. // @Success 200 {object} cygx.RaiServeTagListResp
  570. // @router /rai_serve/bill_list [get]
  571. func (this *RaiServeCoAntroller) BillList() {
  572. br := new(models.BaseResponse).Init()
  573. defer func() {
  574. this.Data["json"] = br
  575. this.ServeJSON()
  576. }()
  577. sysUser := this.SysUser
  578. if sysUser == nil {
  579. br.Msg = "请登录"
  580. br.ErrMsg = "请登录,SysUser Is Empty"
  581. br.Ret = 408
  582. return
  583. }
  584. pageSize, _ := this.GetInt("PageSize")
  585. currentIndex, _ := this.GetInt("CurrentIndex")
  586. companyId, _ := this.GetInt("CompanyId")
  587. tagType, _ := this.GetInt("TagType")
  588. tagId, _ := this.GetInt("TagId")
  589. serveTypeId, _ := this.GetInt("ServeTypeId")
  590. var startSize int
  591. if pageSize <= 0 {
  592. pageSize = utils.PageSize20
  593. }
  594. if currentIndex <= 0 {
  595. currentIndex = 1
  596. }
  597. startSize = utils.StartIndex(currentIndex, pageSize)
  598. if companyId == 0 {
  599. br.Msg = "请选择对应公司ID"
  600. return
  601. }
  602. var condition string
  603. var pars []interface{}
  604. var err error
  605. condition, pars, err = getServeBillTag(tagType, tagId) // 标签ID搜索语句处理
  606. if err != nil {
  607. br.Msg = "获取信息失败!"
  608. br.ErrMsg = "获取用户信息失败-getServeBillTag!Err:" + err.Error()
  609. return
  610. }
  611. condition += " AND company_id = ? "
  612. pars = append(pars, companyId)
  613. if serveTypeId > 0 {
  614. condition += " AND serve_type_id = ? "
  615. pars = append(pars, serveTypeId)
  616. }
  617. total, err := cygx.GetCygxRaiServeBillCount(condition, pars)
  618. if err != nil {
  619. br.Msg = "获取失败"
  620. br.ErrMsg = "获取失败,GetCygxRaiServeBillCount:" + err.Error()
  621. return
  622. }
  623. list, err := cygx.GetCygxRaiServeBillRespList(condition, pars, startSize, pageSize)
  624. if err != nil {
  625. br.Msg = "获取失败"
  626. br.ErrMsg = "获取失败,GetCygxRaiServeBillRespList:" + err.Error()
  627. return
  628. }
  629. page := paging.GetPaging(currentIndex, pageSize, total)
  630. resp := new(cygx.CygxRaiServeBillListResp)
  631. resp.Paging = page
  632. if len(list) == 0 {
  633. resp.List = make([]*cygx.CygxRaiServeBillResp, 0)
  634. } else {
  635. for _, v := range list {
  636. v.Tag = "云计算,阿里云,华为云,移动&联通"
  637. }
  638. resp.List = list
  639. }
  640. br.Ret = 200
  641. br.Success = true
  642. br.Msg = "获取成功"
  643. br.Data = resp
  644. }