rai_serve.go 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966
  1. package cygx
  2. import (
  3. "errors"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "github.com/tealeg/xlsx"
  7. "hongze/hz_crm_api/controllers"
  8. "hongze/hz_crm_api/models"
  9. "hongze/hz_crm_api/models/cygx"
  10. "hongze/hz_crm_api/models/roadshow"
  11. cygxService "hongze/hz_crm_api/services/cygx"
  12. "hongze/hz_crm_api/utils"
  13. "os"
  14. "path/filepath"
  15. "strconv"
  16. "strings"
  17. "time"
  18. )
  19. // 权益服务类型
  20. type RaiServeCoAntroller struct {
  21. controllers.BaseAuthController
  22. }
  23. // @Title 服务类型列表
  24. // @Description 服务类型列表接口
  25. // @Success 200 {object} cygx.RaiServeTypeListResp
  26. // @router /rai_serve/type_list [get]
  27. func (this *RaiServeCoAntroller) TypeList() {
  28. br := new(models.BaseResponse).Init()
  29. defer func() {
  30. this.Data["json"] = br
  31. this.ServeJSON()
  32. }()
  33. sysUser := this.SysUser
  34. if sysUser == nil {
  35. br.Msg = "请登录"
  36. br.ErrMsg = "请登录,SysUser Is Empty"
  37. br.Ret = 408
  38. return
  39. }
  40. resp := new(cygx.RaiServeTypeListResp)
  41. var condition string
  42. list, err := cygx.GetRaiServeTypeRespList(condition)
  43. if err != nil {
  44. br.Msg = "获取失败"
  45. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  46. return
  47. }
  48. resp.List = list
  49. br.Ret = 200
  50. br.Success = true
  51. br.Msg = "获取成功"
  52. br.Data = resp
  53. }
  54. // @Title 标签搜索
  55. // @Description 标签搜索接口
  56. // @Param KeyWord query string false "搜索关键词"
  57. // @Success 200 {object} cygx.RaiServeTagListResp
  58. // @router /rai_serve/search_tag [get]
  59. func (this *RaiServeCoAntroller) SearchTag() {
  60. br := new(models.BaseResponse).Init()
  61. defer func() {
  62. this.Data["json"] = br
  63. this.ServeJSON()
  64. }()
  65. sysUser := this.SysUser
  66. if sysUser == nil {
  67. br.Msg = "请登录"
  68. br.ErrMsg = "请登录,SysUser Is Empty"
  69. br.Ret = 408
  70. return
  71. }
  72. keyWord := this.GetString("KeyWord")
  73. if keyWord == "" {
  74. br.Msg = "请输入搜索关键词"
  75. return
  76. }
  77. resp := new(cygx.RaiServeTagListResp)
  78. list, err := cygx.GetRaiServeSearchTagRespList(keyWord)
  79. if err != nil {
  80. br.Msg = "获取失败"
  81. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  82. return
  83. }
  84. //如果有固收或者策略就去查询行业表
  85. if strings.Contains("固收", keyWord) || strings.Contains("策略", keyWord) {
  86. var condition string
  87. var pars []interface{}
  88. keyWord = "%" + keyWord + "%"
  89. condition = ` AND product_id = 2 AND permission_name IN ('策略','固收') AND permission_name LIKE ? `
  90. pars = append(pars, keyWord)
  91. listChartPermission, err := models.GetChartPermissionListByCondition(condition, pars)
  92. if err != nil {
  93. br.Msg = "获取失败"
  94. br.ErrMsg = "获取数据失败,GetChartPermissionListByCondition Err:" + err.Error()
  95. return
  96. }
  97. for _, v := range listChartPermission {
  98. item := new(cygx.RaiServeTagResp)
  99. item.TagType = 3
  100. item.TagId = v.ChartPermissionId
  101. item.TagName = v.PermissionName
  102. list = append(list, item)
  103. }
  104. }
  105. if len(list) == 0 {
  106. list = make([]*cygx.RaiServeTagResp, 0)
  107. } else {
  108. for _, v := range list {
  109. v.Md5Key = utils.MD5(fmt.Sprintf("K_", v.TagType, "V_", v.TagId))
  110. }
  111. }
  112. resp.List = list
  113. br.Ret = 200
  114. br.Success = true
  115. br.Msg = "获取成功"
  116. br.Data = resp
  117. }
  118. // @Title 标签搜索(研究员日历添加到会信息)
  119. // @Description 标签搜索接口
  120. // @Param KeyWord query string false "搜索关键词"
  121. // @Param ResearcherId query int false "研究员ID"
  122. // @Success 200 {object} cygx.RaiServeTagListResp
  123. // @router /rai_serve/search_tag_by_calendar [get]
  124. func (this *RaiServeCoAntroller) SearchTagCalendar() {
  125. br := new(models.BaseResponse).Init()
  126. defer func() {
  127. this.Data["json"] = br
  128. this.ServeJSON()
  129. }()
  130. sysUser := this.SysUser
  131. if sysUser == nil {
  132. br.Msg = "请登录"
  133. br.ErrMsg = "请登录,SysUser Is Empty"
  134. br.Ret = 408
  135. return
  136. }
  137. keyWord := this.GetString("KeyWord")
  138. researcherId := this.GetString("ResearcherId")
  139. askEmailList, err := cygx.GetAskEmailListByAdminIds(researcherId)
  140. if err != nil {
  141. br.Msg = "获取失败"
  142. br.ErrMsg = "GetAskEmailCountByCelue,Err:" + err.Error()
  143. return
  144. }
  145. var hasCelue bool
  146. var permissionName []string
  147. for _, v := range askEmailList {
  148. permissionName = append(permissionName, v.ChartPermissionName)
  149. if v.ChartPermissionName == "策略" || v.ChartPermissionName == "固收" {
  150. hasCelue = true
  151. }
  152. }
  153. var permissionNameSql []string
  154. for _, v := range permissionName {
  155. permissionNameSql = append(permissionNameSql, "'"+v+"'")
  156. }
  157. chartList, err := models.GetChartPermissionByNamesByRai(permissionNameSql)
  158. if err != nil {
  159. br.Msg = "获取失败"
  160. br.ErrMsg = "获取数据失败,GetChartPermissionByNames Err:" + err.Error()
  161. return
  162. }
  163. var list []*cygx.RaiServeTagResp
  164. resp := new(cygx.RaiServeTagListResp)
  165. if hasCelue {
  166. for _, v := range chartList {
  167. item := new(cygx.RaiServeTagResp)
  168. item.TagType = 3
  169. item.TagId = v.ChartPermissionId
  170. item.TagName = v.PermissionName
  171. list = append(list, item)
  172. }
  173. } else {
  174. if keyWord == "" {
  175. br.Msg = "请输入搜索关键词"
  176. return
  177. }
  178. keyWordSlice := strings.Split(keyWord, ",")
  179. var conditionindustrial string
  180. var conditionsubject string
  181. for _, v := range keyWordSlice {
  182. conditionindustrial += ` OR i.industry_name LIKE '%` + v + `%' `
  183. conditionsubject += ` OR s.subject_name LIKE '%` + v + `%' `
  184. }
  185. var permissionId []string
  186. for _, v := range chartList {
  187. permissionId = append(permissionId, strconv.Itoa(v.ChartPermissionId))
  188. }
  189. list, err = cygx.GetRaiServeSearchTagRespListBycharId(keyWord, strings.Join(permissionId, ","), conditionindustrial, conditionsubject)
  190. if err != nil {
  191. br.Msg = "获取失败"
  192. br.ErrMsg = "获取数据失败,GetRaiServeSearchTagRespListBycharId Err:" + err.Error()
  193. return
  194. }
  195. }
  196. if len(list) == 0 {
  197. list = make([]*cygx.RaiServeTagResp, 0)
  198. } else {
  199. for _, v := range list {
  200. v.Md5Key = utils.MD5(fmt.Sprintf("K_", v.TagType, "V_", v.TagId))
  201. }
  202. }
  203. resp.List = list
  204. br.Ret = 200
  205. br.Success = true
  206. br.Msg = "获取成功"
  207. br.Data = resp
  208. }
  209. // @Title 校验是否属于策略固收
  210. // @Description 校验是否属于策略固收接口
  211. // @Param ResearcherId query int false "研究员ID"
  212. // @Success 200 {object} cygx.RaiServeTagListResp
  213. // @router /rai_serve/chcck_PermissionName [get]
  214. func (this *RaiServeCoAntroller) ChcckPermissionName() {
  215. br := new(models.BaseResponse).Init()
  216. defer func() {
  217. this.Data["json"] = br
  218. this.ServeJSON()
  219. }()
  220. sysUser := this.SysUser
  221. if sysUser == nil {
  222. br.Msg = "请登录"
  223. br.ErrMsg = "请登录,SysUser Is Empty"
  224. br.Ret = 408
  225. return
  226. }
  227. researcherId := this.GetString("ResearcherId")
  228. askEmailList, err := cygx.GetAskEmailListByAdminIds(researcherId)
  229. if err != nil {
  230. br.Msg = "获取失败"
  231. br.ErrMsg = "GetAskEmailCountByCelue,Err:" + err.Error()
  232. return
  233. }
  234. var belong bool
  235. var permissionNameResp []string
  236. var permissionNames []string
  237. for _, v := range askEmailList {
  238. permissionNames = append(permissionNames, v.ChartPermissionName)
  239. if v.ChartPermissionName == "策略" || v.ChartPermissionName == "固收" {
  240. belong = true
  241. permissionNameResp = append(permissionNameResp, v.ChartPermissionName)
  242. }
  243. }
  244. var list []*cygx.RaiServeTagResp
  245. if belong {
  246. var permissionNameSql []string
  247. for _, v := range permissionNameResp {
  248. permissionNameSql = append(permissionNameSql, "'"+v+"'")
  249. }
  250. chartList, err := models.GetChartPermissionByNamesByRai(permissionNameSql)
  251. if err != nil {
  252. br.Msg = "获取失败"
  253. br.ErrMsg = "获取数据失败,GetChartPermissionByNames Err:" + err.Error()
  254. return
  255. }
  256. for _, v := range chartList {
  257. item := new(cygx.RaiServeTagResp)
  258. item.TagType = 3
  259. item.TagId = v.ChartPermissionId
  260. item.TagName = v.PermissionName
  261. item.Md5Key = utils.MD5(fmt.Sprintf("K_", item.TagType, "V_", item.TagId))
  262. list = append(list, item)
  263. }
  264. }
  265. resp := new(cygx.ChekChartPermissionNameResp)
  266. if len(list) == 0 {
  267. list = make([]*cygx.RaiServeTagResp, 0)
  268. }
  269. resp.List = list
  270. resp.Belong = belong
  271. resp.ChartPermissionName = strings.Join(permissionNameResp, ",")
  272. br.Ret = 200
  273. br.Success = true
  274. br.Msg = "获取成功"
  275. br.Data = resp
  276. }
  277. // @Title 权益服务统计列表
  278. // @Description 权益服务统计列表接口
  279. // @Param PageSize query int true "每页数据条数"
  280. // @Param CurrentIndex query int true "当前页页码,从1开始"
  281. // @Param SellerId query string false "销售id"
  282. // @Param ShareSellerId query string false "共享销售ID"
  283. // @Param ServeTypeId int int false "服务类型ID"
  284. // @Param TagType int string false "标签类型"
  285. // @Param TagId int string false "标签ID"
  286. // @Param Status query string false "客户状态,正式、未续约(除了正式之外的所有)"
  287. // @Param SortType query string true "如何排序,是正序还是倒序,枚举值:`asc 正序`,`desc 倒叙`"
  288. // @Param IsExport query bool false "是否导出excel,默认是false"
  289. // @Success 200 {object} cygx.RaiServeTagListResp
  290. // @router /rai_serve/list [get]
  291. func (this *RaiServeCoAntroller) List() {
  292. br := new(models.BaseResponse).Init()
  293. defer func() {
  294. this.Data["json"] = br
  295. this.ServeJSON()
  296. }()
  297. sysUser := this.SysUser
  298. if sysUser == nil {
  299. br.Msg = "请登录"
  300. br.ErrMsg = "请登录,SysUser Is Empty"
  301. br.Ret = 408
  302. return
  303. }
  304. pageSize, _ := this.GetInt("PageSize")
  305. currentIndex, _ := this.GetInt("CurrentIndex")
  306. status := this.GetString("Status")
  307. sellerId := this.GetString("SellerId")
  308. shareSellerId := this.GetString("ShareSellerId")
  309. sortType := this.GetString("SortType")
  310. tagType, _ := this.GetInt("TagType")
  311. tagId, _ := this.GetInt("TagId")
  312. serveTypeId, _ := this.GetInt("ServeTypeId")
  313. isExport, _ := this.GetBool("IsExport")
  314. resp := new(cygx.CygxRaiServeCompanyListResp)
  315. var startSize int
  316. if pageSize <= 0 {
  317. pageSize = utils.PageSize20
  318. }
  319. if currentIndex <= 0 {
  320. currentIndex = 1
  321. }
  322. startSize = utils.StartIndex(currentIndex, pageSize)
  323. var condition string
  324. var sortStr string
  325. var pars []interface{}
  326. if status != "" {
  327. if status == "正式" {
  328. condition += " AND status = '正式' "
  329. } else {
  330. condition += " AND status != '正式' "
  331. }
  332. }
  333. if sellerId != "" {
  334. condition += " AND seller_id IN (?) "
  335. pars = append(pars, sellerId)
  336. }
  337. if shareSellerId != "" {
  338. condition += " AND share_seller_id IN (?) "
  339. pars = append(pars, shareSellerId)
  340. }
  341. if sortType != "" {
  342. if sortType == "asc" {
  343. sortStr = " ORDER BY money ASC "
  344. } else if sortType == "desc" {
  345. sortStr = " ORDER BY money DESC "
  346. }
  347. } else {
  348. sortStr = " ORDER BY end_date DESC "
  349. }
  350. //如果不是权益管理员和admin、财务,就做可见权限限制
  351. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_RAI_ADMIN && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_RAI_RESEARCHR {
  352. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER {
  353. condition += " AND (seller_id = ? OR share_seller_id = ? ) "
  354. pars = append(pars, sysUser.AdminId, sysUser.AdminId)
  355. }
  356. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  357. condition += " AND ( seller_id = ? OR share_seller_id = ? OR group_id = ? OR share_group_id = ? ) "
  358. pars = append(pars, sysUser.AdminId, sysUser.AdminId, sysUser.GroupId, sysUser.GroupId)
  359. }
  360. }
  361. total, err := cygx.GetCygxRaiServeCompanyCount(condition, pars)
  362. if err != nil {
  363. br.Msg = "获取失败"
  364. br.ErrMsg = "获取失败,GetCygxRaiServeCompanyCountErr:" + err.Error()
  365. return
  366. }
  367. listRaiServeCompany, err := cygx.GetCygxRaiServeCompanyList(condition+sortStr, pars, startSize, pageSize)
  368. if err != nil {
  369. br.Msg = "获取失败"
  370. br.ErrMsg = "获取失败,Err:" + err.Error()
  371. return
  372. }
  373. var companyIds []int
  374. for _, v := range listRaiServeCompany {
  375. companyIds = append(companyIds, v.CompanyId)
  376. }
  377. mapWeekAmount := make(map[string]float64) //周度服务量
  378. weeks := 4
  379. if isExport {
  380. weeks = 12 // 下载获取近12周的数据
  381. }
  382. lencompanyIds := len(companyIds)
  383. if lencompanyIds > 0 {
  384. var conditionBill string
  385. var parsBill []interface{}
  386. conditionBill, parsBill, err = getServeBillTag(tagType, tagId) // 标签ID搜索语句处理
  387. if err != nil {
  388. br.Msg = "获取信息失败!"
  389. br.ErrMsg = "获取用户信息失败-getServeBillTag!Err:" + err.Error()
  390. return
  391. }
  392. //服务类型筛选
  393. if serveTypeId > 0 {
  394. conditionBill += ` AND serve_type_id = ? `
  395. parsBill = append(parsBill, serveTypeId)
  396. }
  397. conditionBill += " AND company_id IN (" + utils.GetOrmInReplace(lencompanyIds) + ") "
  398. parsBill = append(parsBill, companyIds)
  399. listBill, err := cygx.GetCygxRaiServeBillListAll(conditionBill, parsBill)
  400. if err != nil {
  401. br.Msg = "获取信息失败!"
  402. br.ErrMsg = "获取用户信息失败-GetCygxRaiServeBillListAll!Err:" + err.Error()
  403. return
  404. }
  405. now := time.Now()
  406. for _, v := range listBill {
  407. for i := 0; i < weeks; i++ {
  408. // 计算当前周的周一
  409. monday := now.AddDate(0, 0, -int(now.Weekday()-time.Monday)-i*7)
  410. weekmonday := monday.Format(utils.FormatDate)
  411. if v.WeekStartDate == weekmonday {
  412. mapWeekAmount[fmt.Sprintf("CID_", v.CompanyId, "WEEK_", i)] += v.ServeCount
  413. }
  414. }
  415. }
  416. }
  417. for _, v := range listRaiServeCompany {
  418. item := new(cygx.CygxRaiServeCompanyResp)
  419. item.CompanyId = v.CompanyId
  420. item.CompanyName = v.CompanyName
  421. item.Money = v.Money
  422. item.ServeCoverageRate = v.ServeCoverageRate + "%"
  423. item.SellerId = v.SellerId
  424. item.SellerName = v.SellerName
  425. item.StartDate = v.StartDate
  426. item.StartDate = v.StartDate
  427. item.EndDate = v.EndDate
  428. item.ShareSeller = v.ShareSeller
  429. item.ShareSellerId = v.ShareSellerId
  430. item.Status = v.Status
  431. item.PermissionName = v.PermissionName
  432. if v.IsUserMaker == 0 {
  433. item.IsRed = true
  434. }
  435. item.ThisWeekAmount = mapWeekAmount[fmt.Sprintf("CID_", v.CompanyId, "WEEK_", 0)]
  436. item.LastWeekAmount = mapWeekAmount[fmt.Sprintf("CID_", v.CompanyId, "WEEK_", 1)]
  437. item.TwoWeekAmount = mapWeekAmount[fmt.Sprintf("CID_", v.CompanyId, "WEEK_", 2)]
  438. item.ThreeWeekAmount = mapWeekAmount[fmt.Sprintf("CID_", v.CompanyId, "WEEK_", 3)]
  439. resp.List = append(resp.List, item)
  440. }
  441. //导出excel
  442. if isExport {
  443. RaiServeListExport(this, resp, mapWeekAmount, br)
  444. return
  445. }
  446. page := paging.GetPaging(currentIndex, pageSize, total)
  447. resp.Paging = page
  448. br.Ret = 200
  449. br.Success = true
  450. br.Msg = "获取成功"
  451. br.Data = resp
  452. }
  453. // EnterScoreScoreListExport 导出Excel
  454. func RaiServeListExport(this *RaiServeCoAntroller, resp *cygx.CygxRaiServeCompanyListResp, mapWeekAmount map[string]float64, br *models.BaseResponse) {
  455. weeks := 12 // 下载获取近12周的数据
  456. mapWeekFormat := make(map[int]string)
  457. now := time.Now()
  458. for i := 0; i < weeks; i++ {
  459. // 计算当前周的周一
  460. monday := now.AddDate(0, 0, -int(now.Weekday()-time.Monday)-i*7)
  461. sunday := monday.AddDate(0, 0, 6)
  462. weekmonday := monday.Format(utils.FormatMonthDayUnSpace2)
  463. weeksunday := sunday.Format(utils.FormatMonthDayUnSpace2)
  464. mapWeekFormat[i] = weekmonday + "~" + weeksunday
  465. }
  466. dir, err := os.Executable()
  467. exPath := filepath.Dir(dir)
  468. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  469. xlsxFile := xlsx.NewFile()
  470. if err != nil {
  471. br.Msg = "生成文件失败"
  472. br.ErrMsg = "生成文件失败"
  473. return
  474. }
  475. style := xlsx.NewStyle()
  476. alignment := xlsx.Alignment{
  477. Horizontal: "center",
  478. Vertical: "center",
  479. WrapText: true,
  480. }
  481. style.Alignment = alignment
  482. style.ApplyAlignment = true
  483. sheel, err := xlsxFile.AddSheet("权益服务统计")
  484. if err != nil {
  485. br.Msg = "新增Sheet失败"
  486. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  487. return
  488. }
  489. sheel.SetColWidth(0, 0, 30)
  490. sheel.SetColWidth(1, 1, 15)
  491. sheel.SetColWidth(2, 2, 15)
  492. sheel.SetColWidth(3, 3, 18)
  493. titleRow := sheel.AddRow()
  494. cellA := titleRow.AddCell()
  495. cellA.SetStyle(style)
  496. cellA.SetValue("客户名称")
  497. cellB := titleRow.AddCell()
  498. cellB.SetStyle(style)
  499. cellB.SetValue("当前状态")
  500. cellC := titleRow.AddCell()
  501. cellC.SetStyle(style)
  502. cellC.SetValue("所属销售")
  503. cellD := titleRow.AddCell()
  504. cellD.SetStyle(style)
  505. cellD.SetValue("咨询销售")
  506. cellE := titleRow.AddCell()
  507. cellE.SetStyle(style)
  508. cellE.SetValue("合同期限")
  509. cellF := titleRow.AddCell()
  510. cellF.SetStyle(style)
  511. cellF.SetValue("合同金额")
  512. cellG := titleRow.AddCell()
  513. cellG.SetStyle(style)
  514. cellG.SetValue("签约套餐")
  515. cellWe1 := titleRow.AddCell()
  516. cellWe1.SetStyle(style)
  517. cellWe1.SetValue("本周服务量(" + mapWeekFormat[0] + ")")
  518. cellWe2 := titleRow.AddCell()
  519. cellWe2.SetStyle(style)
  520. cellWe2.SetValue("上周服务量(" + mapWeekFormat[1] + ")")
  521. cellWe3 := titleRow.AddCell()
  522. cellWe3.SetStyle(style)
  523. cellWe3.SetValue("上上周服务量(" + mapWeekFormat[2] + ")")
  524. cellWe4 := titleRow.AddCell()
  525. cellWe4.SetStyle(style)
  526. cellWe4.SetValue("上三周服务量(" + mapWeekFormat[3] + ")")
  527. for i := 0; i < weeks; i++ {
  528. if i < 4 {
  529. continue
  530. }
  531. // 计算当前周的周一
  532. cellWei := titleRow.AddCell()
  533. cellWei.SetStyle(style)
  534. cellWei.SetValue(mapWeekFormat[i])
  535. }
  536. for _, v := range resp.List {
  537. dataRow := sheel.AddRow()
  538. dataRow.SetHeight(20)
  539. cellA := dataRow.AddCell()
  540. cellA.SetStyle(style)
  541. cellA.SetValue(v.CompanyName)
  542. cellB := dataRow.AddCell()
  543. cellB.SetStyle(style)
  544. cellB.SetValue(v.Status)
  545. cellC := dataRow.AddCell()
  546. cellC.SetStyle(style)
  547. cellC.SetValue(v.SellerName)
  548. cellD := dataRow.AddCell()
  549. cellD.SetStyle(style)
  550. cellD.SetValue(v.ShareSeller)
  551. cellE := dataRow.AddCell()
  552. cellE.SetStyle(style)
  553. cellE.SetValue(v.StartDate + "~" + v.EndDate)
  554. cellF := dataRow.AddCell()
  555. cellF.SetStyle(style)
  556. cellF.SetValue(v.Money)
  557. cellG := dataRow.AddCell()
  558. cellG.SetStyle(style)
  559. cellG.SetValue(v.PermissionName)
  560. for i := 0; i < weeks; i++ {
  561. cellWei := dataRow.AddCell()
  562. cellWei.SetStyle(style)
  563. cellWei.SetValue(mapWeekAmount[fmt.Sprintf("CID_", v.CompanyId, "WEEK_", i)])
  564. }
  565. }
  566. err = xlsxFile.Save(downLoadnFilePath)
  567. if err != nil {
  568. br.Msg = "保存文件失败"
  569. br.ErrMsg = "保存文件失败"
  570. return
  571. }
  572. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  573. downloadFileName := "权益服务统计导出数据_" + randStr + ".xlsx"
  574. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  575. defer func() {
  576. os.Remove(downLoadnFilePath)
  577. }()
  578. br.Ret = 200
  579. br.Success = true
  580. br.Msg = "导出成功"
  581. }
  582. // 标签搜索语句筛选
  583. func getServeBillTag(tagType, tagId int) (conditionBill string, parsBill []interface{}, err error) {
  584. if tagType == 0 {
  585. return
  586. }
  587. var activityIds []int
  588. var activitySpecialIds []int
  589. var articleIds []int
  590. var rsCalendarIds []int
  591. switch tagType {
  592. case 1:
  593. listGroupActivity, e := cygx.GetIndustrialActivityGroupManagementListByIndustriaId(tagId, 1) // 关联的活动
  594. if e != nil {
  595. err = errors.New("GetIndustrialActivityGroupManagementListByIndustriaId, Err: " + e.Error())
  596. return
  597. }
  598. for _, v := range listGroupActivity {
  599. activityIds = append(activityIds, v.ActivityId)
  600. }
  601. listGroupActivitySpecial, e := cygx.GetIndustrialActivityGroupManagementListByIndustriaId(tagId, 2) // 关联的产业
  602. if e != nil {
  603. err = errors.New("GetIndustrialActivityGroupManagementListByIndustriaId, Err: " + e.Error())
  604. return
  605. }
  606. for _, v := range listGroupActivitySpecial {
  607. activitySpecialIds = append(activitySpecialIds, v.ActivityId)
  608. }
  609. listGroupArticle, e := cygx.GetIndustrialArticleGroupManagementListByindustrialId(tagId) // 关联的产业
  610. if e != nil {
  611. err = errors.New("GetIndustrialArticleGroupManagementListByindustrialId, Err: " + e.Error())
  612. return
  613. }
  614. for _, v := range listGroupArticle {
  615. articleIds = append(articleIds, v.ArticleId)
  616. }
  617. listGroupRsCalendar, e := roadshow.GetRsCalendarMeetingLabelGroupDetailByTag(tagType, tagId)
  618. if e != nil {
  619. err = errors.New("GetRsCalendarMeetingLabelGroupDetailByTag, Err: " + e.Error())
  620. return
  621. }
  622. for _, v := range listGroupRsCalendar {
  623. rsCalendarIds = append(rsCalendarIds, v.RsCalendarId)
  624. }
  625. case 2:
  626. listGroupActivity, e := cygx.GetSubjectActivityGroupManagementListBySubjectId(tagId, 1) // 关联的活动
  627. if e != nil {
  628. err = errors.New("GetSubjectActivityGroupManagementListBySubjectId, Err: " + e.Error())
  629. return
  630. }
  631. for _, v := range listGroupActivity {
  632. activityIds = append(activityIds, v.ActivityId)
  633. }
  634. listGroupActivitySpecial, e := cygx.GetSubjectActivityGroupManagementListBySubjectId(tagId, 2) // 关联的产业
  635. if e != nil {
  636. err = errors.New("GetSubjectActivityGroupManagementListBySubjectId, Err: " + e.Error())
  637. return
  638. }
  639. for _, v := range listGroupActivitySpecial {
  640. activitySpecialIds = append(activitySpecialIds, v.ActivityId)
  641. }
  642. listGroupArticle, e := cygx.GetSubjectArticleGroupManagementListBysubjectId(tagId) // 关联的产业
  643. if e != nil {
  644. err = errors.New("GetSubjectArticleGroupManagementListBysubjectId, Err: " + e.Error())
  645. return
  646. }
  647. for _, v := range listGroupArticle {
  648. articleIds = append(articleIds, v.ArticleId)
  649. }
  650. listGroupRsCalendar, e := roadshow.GetRsCalendarMeetingLabelGroupDetailByTag(tagType, tagId)
  651. if e != nil {
  652. err = errors.New("GetRsCalendarMeetingLabelGroupDetailByTag, Err: " + e.Error())
  653. return
  654. }
  655. for _, v := range listGroupRsCalendar {
  656. rsCalendarIds = append(rsCalendarIds, v.RsCalendarId)
  657. }
  658. activityIds = append(activityIds, 0)
  659. lenactivityIds := len(activityIds)
  660. //if lenactivityIds > 0 {
  661. conditionBill += ` AND IF ( source = 'activity', source_id IN (` + utils.GetOrmInReplace(lenactivityIds) + `) , 1 = 1 ) `
  662. parsBill = append(parsBill, activityIds)
  663. //}
  664. activitySpecialIds = append(activitySpecialIds, 0)
  665. lenactivitySpecialIds := len(activitySpecialIds)
  666. //if lenactivitySpecialIds > 0 {
  667. conditionBill += ` AND IF ( source = 'activityspecial', source_id IN (` + utils.GetOrmInReplace(lenactivitySpecialIds) + `) , 1 = 1 ) `
  668. parsBill = append(parsBill, activitySpecialIds)
  669. //}
  670. articleIds = append(articleIds, 0)
  671. lenarticleIds := len(articleIds)
  672. //if lenarticleIds > 0 {
  673. conditionBill += ` AND IF ( source = 'article', source_id IN (` + utils.GetOrmInReplace(lenarticleIds) + `) , 1 = 1 ) `
  674. parsBill = append(parsBill, articleIds)
  675. //}
  676. rsCalendarIds = append(rsCalendarIds, 0)
  677. lenrsCalendarIds := len(rsCalendarIds)
  678. //if lenrsCalendarIds > 0 {
  679. conditionBill += ` AND IF ( source = 'rscalendar', source_id IN (` + utils.GetOrmInReplace(lenrsCalendarIds) + `) , 1 = 1 ) `
  680. parsBill = append(parsBill, rsCalendarIds)
  681. case 3:
  682. conditionBill += " AND chart_permission_id = ? "
  683. parsBill = append(parsBill, tagId)
  684. }
  685. //}
  686. conditionBill += ` AND source != 'yanxuanspecial' AND source != 'userfeedback' `
  687. return
  688. }
  689. // @Title 近四周覆盖率
  690. // @Description 近四周覆盖率接口
  691. // @Param CompanyId query int false "公司ID"
  692. // @Success 200 {object} cygx.RaiServeTagListResp
  693. // @router /rai_serve/coverage_rate [get]
  694. func (this *RaiServeCoAntroller) CoverageRate() {
  695. br := new(models.BaseResponse).Init()
  696. defer func() {
  697. this.Data["json"] = br
  698. this.ServeJSON()
  699. }()
  700. sysUser := this.SysUser
  701. if sysUser == nil {
  702. br.Msg = "请登录"
  703. br.ErrMsg = "请登录,SysUser Is Empty"
  704. br.Ret = 408
  705. return
  706. }
  707. companyId, _ := this.GetInt("CompanyId")
  708. listWeekBill, err := cygx.GetCygxRaiServeBillListWeek4(companyId)
  709. if err != nil {
  710. br.Msg = "获取信息失败!"
  711. br.ErrMsg = "获取用户信息失败-GetCygxRaiServeBillListWeek4!Err:" + err.Error()
  712. return
  713. }
  714. mapWeek := make(map[int]string)
  715. for k, v := range listWeekBill {
  716. mapWeek[k] = utils.SubFloatToString(v.CoverageRate, 2)
  717. }
  718. resp := new(cygx.RaiServeCoverageRateResp)
  719. resp.ThisWeekAmount = mapWeek[0] + "%"
  720. resp.LastWeekAmount = mapWeek[1] + "%"
  721. resp.TwoWeekAmount = mapWeek[2] + "%"
  722. resp.ThreeWeekAmount = mapWeek[3] + "%"
  723. br.Ret = 200
  724. br.Success = true
  725. br.Msg = "获取成功"
  726. br.Data = resp
  727. }
  728. // @Title 明细列表
  729. // @Description 明细列表接口
  730. // @Param PageSize query int true "每页数据条数"
  731. // @Param CurrentIndex query int true "当前页页码,从1开始"
  732. // @Param CompanyId query int false "公司ID"
  733. // @Param TagType query int false "标签类型"
  734. // @Param TagId query int false "标签ID"
  735. // @Param ServeTypeId int int false "服务类型ID"
  736. // @Param WhatWeek query int false "哪一周 ,1:本周、2:上周、3:上上周、4上三周"
  737. // @Success 200 {object} cygx.RaiServeTagListResp
  738. // @router /rai_serve/bill_list [get]
  739. func (this *RaiServeCoAntroller) BillList() {
  740. br := new(models.BaseResponse).Init()
  741. defer func() {
  742. this.Data["json"] = br
  743. this.ServeJSON()
  744. }()
  745. sysUser := this.SysUser
  746. if sysUser == nil {
  747. br.Msg = "请登录"
  748. br.ErrMsg = "请登录,SysUser Is Empty"
  749. br.Ret = 408
  750. return
  751. }
  752. pageSize, _ := this.GetInt("PageSize")
  753. currentIndex, _ := this.GetInt("CurrentIndex")
  754. companyId, _ := this.GetInt("CompanyId")
  755. tagType, _ := this.GetInt("TagType")
  756. tagId, _ := this.GetInt("TagId")
  757. serveTypeId, _ := this.GetInt("ServeTypeId")
  758. whatWeek, _ := this.GetInt("WhatWeek")
  759. var startSize int
  760. if pageSize <= 0 {
  761. pageSize = utils.PageSize20
  762. }
  763. if currentIndex <= 0 {
  764. currentIndex = 1
  765. }
  766. startSize = utils.StartIndex(currentIndex, pageSize)
  767. if companyId == 0 {
  768. br.Msg = "请选择对应公司ID"
  769. return
  770. }
  771. var condition string
  772. var pars []interface{}
  773. var err error
  774. condition, pars, err = getServeBillTag(tagType, tagId) // 标签ID搜索语句处理
  775. if err != nil {
  776. br.Msg = "获取信息失败!"
  777. br.ErrMsg = "获取用户信息失败-getServeBillTag!Err:" + err.Error()
  778. return
  779. }
  780. if whatWeek > 0 {
  781. now := time.Now()
  782. // 计算所选周的周一
  783. monday := now.AddDate(0, 0, -int(now.Weekday()-time.Monday)-(whatWeek-1)*7)
  784. condition += " AND week_start_date = ? "
  785. pars = append(pars, monday.Format(utils.FormatDate))
  786. }
  787. condition += " AND company_id = ? "
  788. pars = append(pars, companyId)
  789. if serveTypeId > 0 {
  790. condition += " AND serve_type_id = ? "
  791. pars = append(pars, serveTypeId)
  792. }
  793. total, err := cygx.GetCygxRaiServeBillCount(condition, pars)
  794. if err != nil {
  795. br.Msg = "获取失败"
  796. br.ErrMsg = "获取失败,GetCygxRaiServeBillCount:" + err.Error()
  797. return
  798. }
  799. list, err := cygx.GetCygxRaiServeBillRespList(condition, pars, startSize, pageSize)
  800. if err != nil {
  801. br.Msg = "获取失败"
  802. br.ErrMsg = "获取失败,GetCygxRaiServeBillRespList:" + err.Error()
  803. return
  804. }
  805. page := paging.GetPaging(currentIndex, pageSize, total)
  806. resp := new(cygx.CygxRaiServeBillListResp)
  807. resp.Paging = page
  808. if len(list) == 0 {
  809. resp.List = make([]*cygx.CygxRaiServeBillResp, 0)
  810. } else {
  811. var activityIds []int
  812. var activitySpecialIds []int
  813. var articleIds []int
  814. var rsCalendarIds []int
  815. for _, v := range list {
  816. switch v.Source {
  817. case utils.CYGX_OBJ_ARTICLE:
  818. articleIds = append(articleIds, v.SourceId)
  819. case utils.CYGX_OBJ_ACTIVITY:
  820. activityIds = append(activityIds, v.SourceId)
  821. case utils.CYGX_OBJ_ACTIVITYSPECIAL:
  822. activitySpecialIds = append(activitySpecialIds, v.SourceId)
  823. case utils.CYGX_OBJ_RS_CALENDAR:
  824. rsCalendarIds = append(rsCalendarIds, v.SourceId)
  825. }
  826. }
  827. maparticleIndustrialLabel := make(map[int][]string) //文章产业标签
  828. maparticleSubjectLabel := make(map[int][]string) // 文章行业标签
  829. if len(articleIds) > 0 {
  830. maparticleIndustrialLabel = cygxService.GetArticleIndustrialLabelByArticleId(articleIds) // 关联产业
  831. maparticleSubjectLabel = cygxService.GetArticleSubjectLabelByArticleId(articleIds) // 关联标的
  832. }
  833. mapActivityIndustrialLabel := make(map[int][]string) //活动产业标签
  834. mapActivitySubjectLabel := make(map[int][]string) //活动标的标签
  835. mapActivityIndustrialLabel = cygxService.GetActivityIndustrialLabelByActivityIds(activityIds, 1)
  836. mapActivitySubjectLabel = cygxService.GetActivitySubjectLabelByActivityIds(activityIds, 1)
  837. mapActivitySpeicalIndustrialLabel := make(map[int][]string) //活动产业标签
  838. mapActivitySpeicalSubjectLabel := make(map[int][]string) //活动标的标签
  839. mapActivitySpeicalIndustrialLabel = cygxService.GetActivityIndustrialLabelByActivityIds(activityIds, 2)
  840. mapActivitySpeicalSubjectLabel = cygxService.GetActivitySubjectLabelByActivityIds(activityIds, 2)
  841. mapRsCalendarLabel := make(map[int][]string) //1v1 路演标签
  842. mapRsCalendarLabel = cygxService.GetRsCalendarLabelByRsCalendarIds(rsCalendarIds)
  843. for _, v := range list {
  844. switch v.Source {
  845. case utils.CYGX_OBJ_ARTICLE:
  846. if v.ChartPermissionName == utils.GU_SHOU_NAME || v.ChartPermissionName == utils.CE_LUE_NAME {
  847. v.Tag = v.ChartPermissionName
  848. } else {
  849. v.Tag = strings.Join(maparticleIndustrialLabel[v.SourceId], ",")
  850. if len(maparticleSubjectLabel[v.SourceId]) > 0 {
  851. v.Tag += "," + strings.Join(maparticleSubjectLabel[v.SourceId], ",")
  852. }
  853. }
  854. case utils.CYGX_OBJ_ACTIVITY:
  855. v.Tag = strings.Join(mapActivityIndustrialLabel[v.SourceId], ",")
  856. if len(mapActivitySubjectLabel[v.SourceId]) > 0 {
  857. v.Tag += "," + strings.Join(mapActivitySubjectLabel[v.SourceId], ",")
  858. }
  859. case utils.CYGX_OBJ_ACTIVITYSPECIAL:
  860. v.Tag = strings.Join(mapActivitySpeicalIndustrialLabel[v.SourceId], ",")
  861. if len(mapActivitySpeicalSubjectLabel[v.SourceId]) > 0 {
  862. v.Tag += "," + strings.Join(mapActivitySpeicalSubjectLabel[v.SourceId], ",")
  863. }
  864. case utils.CYGX_OBJ_RS_CALENDAR:
  865. if v.ChartPermissionName == utils.GU_SHOU_NAME || v.ChartPermissionName == utils.CE_LUE_NAME {
  866. v.Tag = v.ChartPermissionName
  867. } else {
  868. v.Tag = strings.Join(mapRsCalendarLabel[v.SourceId], ",")
  869. }
  870. }
  871. }
  872. resp.List = list
  873. }
  874. br.Ret = 200
  875. br.Success = true
  876. br.Msg = "获取成功"
  877. br.Data = resp
  878. }