rai_serve.go 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295
  1. package cygx
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "github.com/rdlucklib/rdluck_tools/paging"
  7. "github.com/tealeg/xlsx"
  8. "hongze/hz_crm_api/controllers"
  9. "hongze/hz_crm_api/models"
  10. "hongze/hz_crm_api/models/company"
  11. "hongze/hz_crm_api/models/cygx"
  12. "hongze/hz_crm_api/models/roadshow"
  13. cygxService "hongze/hz_crm_api/services/cygx"
  14. "hongze/hz_crm_api/utils"
  15. "os"
  16. "path/filepath"
  17. "strconv"
  18. "strings"
  19. "time"
  20. )
  21. // 权益服务类型
  22. type RaiServeCoAntroller struct {
  23. controllers.BaseAuthController
  24. }
  25. // @Title 服务类型列表
  26. // @Description 服务类型列表接口
  27. // @Success 200 {object} cygx.RaiServeTypeListResp
  28. // @router /rai_serve/type_list [get]
  29. func (this *RaiServeCoAntroller) TypeList() {
  30. br := new(models.BaseResponse).Init()
  31. defer func() {
  32. this.Data["json"] = br
  33. this.ServeJSON()
  34. }()
  35. sysUser := this.SysUser
  36. if sysUser == nil {
  37. br.Msg = "请登录"
  38. br.ErrMsg = "请登录,SysUser Is Empty"
  39. br.Ret = 408
  40. return
  41. }
  42. resp := new(cygx.RaiServeTypeListResp)
  43. var condition string
  44. list, err := cygx.GetRaiServeTypeRespList(condition)
  45. if err != nil {
  46. br.Msg = "获取失败"
  47. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  48. return
  49. }
  50. resp.List = list
  51. br.Ret = 200
  52. br.Success = true
  53. br.Msg = "获取成功"
  54. br.Data = resp
  55. }
  56. // @Title 标签搜索
  57. // @Description 标签搜索接口
  58. // @Param KeyWord query string false "搜索关键词"
  59. // @Success 200 {object} cygx.RaiServeTagListResp
  60. // @router /rai_serve/search_tag [get]
  61. func (this *RaiServeCoAntroller) SearchTag() {
  62. br := new(models.BaseResponse).Init()
  63. defer func() {
  64. this.Data["json"] = br
  65. this.ServeJSON()
  66. }()
  67. sysUser := this.SysUser
  68. if sysUser == nil {
  69. br.Msg = "请登录"
  70. br.ErrMsg = "请登录,SysUser Is Empty"
  71. br.Ret = 408
  72. return
  73. }
  74. keyWord := this.GetString("KeyWord")
  75. if keyWord == "" {
  76. br.Msg = "请输入搜索关键词"
  77. return
  78. }
  79. resp := new(cygx.RaiServeTagListResp)
  80. var chartPermissionId string
  81. if utils.RunMode == "release" {
  82. chartPermissionId = "19, 20, 21, 22 ,62 "
  83. } else {
  84. chartPermissionId = "19, 20, 21, 22 ,148 "
  85. }
  86. list, err := cygx.GetRaiServeSearchTagRespList(keyWord, chartPermissionId)
  87. if err != nil {
  88. br.Msg = "获取失败"
  89. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  90. return
  91. }
  92. //如果有固收或者策略就去查询行业表
  93. if strings.Contains("固收", keyWord) || strings.Contains("策略", keyWord) {
  94. var condition string
  95. var pars []interface{}
  96. keyWord = "%" + keyWord + "%"
  97. condition = ` AND product_id = 2 AND permission_name IN ('策略','固收') AND permission_name LIKE ? `
  98. pars = append(pars, keyWord)
  99. listChartPermission, err := models.GetChartPermissionListByCondition(condition, pars)
  100. if err != nil {
  101. br.Msg = "获取失败"
  102. br.ErrMsg = "获取数据失败,GetChartPermissionListByCondition Err:" + err.Error()
  103. return
  104. }
  105. for _, v := range listChartPermission {
  106. item := new(cygx.RaiServeTagResp)
  107. item.TagType = 3
  108. item.TagId = v.ChartPermissionId
  109. item.TagName = v.PermissionName
  110. list = append(list, item)
  111. }
  112. }
  113. if len(list) == 0 {
  114. list = make([]*cygx.RaiServeTagResp, 0)
  115. } else {
  116. mapUniqueKey := make(map[string]bool)
  117. for _, v := range list {
  118. uniqueKey := fmt.Sprintf("K_", v.TagType, "V_", v.TagName)
  119. if mapUniqueKey[uniqueKey] {
  120. continue
  121. }
  122. v.Md5Key = utils.MD5(fmt.Sprintf("K_", v.TagType, "V_", v.TagId))
  123. mapUniqueKey[uniqueKey] = true
  124. resp.List = append(resp.List, v)
  125. }
  126. }
  127. br.Ret = 200
  128. br.Success = true
  129. br.Msg = "获取成功"
  130. br.Data = resp
  131. }
  132. // @Title 标签搜索(研究员日历添加到会信息)
  133. // @Description 标签搜索接口
  134. // @Param KeyWord query string false "搜索关键词"
  135. // @Param ResearcherId query int false "研究员ID"
  136. // @Success 200 {object} cygx.RaiServeTagListResp
  137. // @router /rai_serve/search_tag_by_calendar [get]
  138. func (this *RaiServeCoAntroller) SearchTagCalendar() {
  139. br := new(models.BaseResponse).Init()
  140. defer func() {
  141. this.Data["json"] = br
  142. this.ServeJSON()
  143. }()
  144. sysUser := this.SysUser
  145. if sysUser == nil {
  146. br.Msg = "请登录"
  147. br.ErrMsg = "请登录,SysUser Is Empty"
  148. br.Ret = 408
  149. return
  150. }
  151. keyWord := this.GetString("KeyWord")
  152. researcherId := this.GetString("ResearcherId")
  153. askEmailList, err := cygx.GetAskEmailListByAdminIds(researcherId)
  154. if err != nil {
  155. br.Msg = "获取失败"
  156. br.ErrMsg = "GetAskEmailCountByCelue,Err:" + err.Error()
  157. return
  158. }
  159. var hasCelue bool
  160. var permissionName []string
  161. for _, v := range askEmailList {
  162. permissionName = append(permissionName, v.ChartPermissionName)
  163. if v.ChartPermissionName == "策略" || v.ChartPermissionName == "固收" {
  164. hasCelue = true
  165. }
  166. }
  167. permissionName = append(permissionName, utils.ZHOU_QI_NAME) //所有行业默认添加周期行业
  168. var permissionNameSql []string
  169. for _, v := range permissionName {
  170. permissionNameSql = append(permissionNameSql, "'"+v+"'")
  171. }
  172. chartList, err := models.GetChartPermissionByNamesByRai(permissionNameSql)
  173. if err != nil {
  174. br.Msg = "获取失败"
  175. br.ErrMsg = "获取数据失败,GetChartPermissionByNames Err:" + err.Error()
  176. return
  177. }
  178. var list []*cygx.RaiServeTagResp
  179. resp := new(cygx.RaiServeTagListResp)
  180. if hasCelue {
  181. for _, v := range chartList {
  182. item := new(cygx.RaiServeTagResp)
  183. item.TagType = 3
  184. item.TagId = v.ChartPermissionId
  185. item.TagName = v.PermissionName
  186. list = append(list, item)
  187. }
  188. } else {
  189. if keyWord == "" {
  190. br.Msg = "请输入搜索关键词"
  191. return
  192. }
  193. keyWordSlice := strings.Split(keyWord, ",")
  194. var conditionindustrial string
  195. var conditionsubject string
  196. for _, v := range keyWordSlice {
  197. conditionindustrial += ` OR i.industry_name LIKE '%` + v + `%' `
  198. conditionsubject += ` OR s.subject_name LIKE '%` + v + `%' `
  199. }
  200. var permissionId []string
  201. for _, v := range chartList {
  202. permissionId = append(permissionId, strconv.Itoa(v.ChartPermissionId))
  203. }
  204. list, err = cygx.GetRaiServeSearchTagRespListBycharId(keyWord, strings.Join(permissionId, ","), conditionindustrial, conditionsubject)
  205. if err != nil {
  206. br.Msg = "获取失败"
  207. br.ErrMsg = "获取数据失败,GetRaiServeSearchTagRespListBycharId Err:" + err.Error()
  208. return
  209. }
  210. }
  211. if len(list) == 0 {
  212. list = make([]*cygx.RaiServeTagResp, 0)
  213. } else {
  214. mapUniqueKey := make(map[string]bool)
  215. for _, v := range list {
  216. uniqueKey := fmt.Sprintf("K_", v.TagType, "V_", v.TagName)
  217. if mapUniqueKey[uniqueKey] {
  218. continue
  219. }
  220. v.Md5Key = utils.MD5(fmt.Sprintf("K_", v.TagType, "V_", v.TagId))
  221. mapUniqueKey[uniqueKey] = true
  222. resp.List = append(resp.List, v)
  223. }
  224. }
  225. br.Ret = 200
  226. br.Success = true
  227. br.Msg = "获取成功"
  228. br.Data = resp
  229. }
  230. // @Title 校验是否属于策略固收
  231. // @Description 校验是否属于策略固收接口
  232. // @Param ResearcherId query int false "研究员ID"
  233. // @Success 200 {object} cygx.RaiServeTagListResp
  234. // @router /rai_serve/chcck_PermissionName [get]
  235. func (this *RaiServeCoAntroller) ChcckPermissionName() {
  236. br := new(models.BaseResponse).Init()
  237. defer func() {
  238. this.Data["json"] = br
  239. this.ServeJSON()
  240. }()
  241. sysUser := this.SysUser
  242. if sysUser == nil {
  243. br.Msg = "请登录"
  244. br.ErrMsg = "请登录,SysUser Is Empty"
  245. br.Ret = 408
  246. return
  247. }
  248. researcherId := this.GetString("ResearcherId")
  249. askEmailList, err := cygx.GetAskEmailListByAdminIds(researcherId)
  250. if err != nil {
  251. br.Msg = "获取失败"
  252. br.ErrMsg = "GetAskEmailCountByCelue,Err:" + err.Error()
  253. return
  254. }
  255. var belong bool
  256. var permissionNameResp []string
  257. var permissionNames []string
  258. for _, v := range askEmailList {
  259. permissionNames = append(permissionNames, v.ChartPermissionName)
  260. if v.ChartPermissionName == "策略" || v.ChartPermissionName == "固收" {
  261. belong = true
  262. permissionNameResp = append(permissionNameResp, v.ChartPermissionName)
  263. }
  264. }
  265. var list []*cygx.RaiServeTagResp
  266. if belong {
  267. var permissionNameSql []string
  268. for _, v := range permissionNameResp {
  269. permissionNameSql = append(permissionNameSql, "'"+v+"'")
  270. }
  271. chartList, err := models.GetChartPermissionByNamesByRai(permissionNameSql)
  272. if err != nil {
  273. br.Msg = "获取失败"
  274. br.ErrMsg = "获取数据失败,GetChartPermissionByNames Err:" + err.Error()
  275. return
  276. }
  277. for _, v := range chartList {
  278. item := new(cygx.RaiServeTagResp)
  279. item.TagType = 3
  280. item.TagId = v.ChartPermissionId
  281. item.TagName = v.PermissionName
  282. item.Md5Key = utils.MD5(fmt.Sprintf("K_", item.TagType, "V_", item.TagId))
  283. list = append(list, item)
  284. }
  285. }
  286. resp := new(cygx.ChekChartPermissionNameResp)
  287. if len(list) == 0 {
  288. list = make([]*cygx.RaiServeTagResp, 0)
  289. }
  290. resp.List = list
  291. resp.Belong = belong
  292. resp.ChartPermissionName = strings.Join(permissionNameResp, ",")
  293. br.Ret = 200
  294. br.Success = true
  295. br.Msg = "获取成功"
  296. br.Data = resp
  297. }
  298. // @Title 权益服务统计列表
  299. // @Description 权益服务统计列表接口
  300. // @Param PageSize query int true "每页数据条数"
  301. // @Param CurrentIndex query int true "当前页页码,从1开始"
  302. // @Param SellerId query string false "销售id"
  303. // @Param ShareSellerId query string false "共享销售ID"
  304. // @Param ServeTypeId int int false "服务类型ID"
  305. // @Param TagType int string false "标签类型"
  306. // @Param TagId int string false "标签ID"
  307. // @Param Status query string false "客户状态,正式、未续约(除了正式之外的所有)"
  308. // @Param SortType query string true "如何排序,是正序还是倒序,枚举值:`asc 正序`,`desc 倒叙`"
  309. // @Param SortParam query string false "排序字段参数,用来排序的字段, 枚举值:'money':金额 、 'endDate':结束时间"
  310. // @Param KeyWord query string false "搜索关键词"
  311. // @Param IsExport query bool false "是否导出excel,默认是false"
  312. // @Success 200 {object} cygx.RaiServeTagListResp
  313. // @router /rai_serve/list [get]
  314. func (this *RaiServeCoAntroller) List() {
  315. br := new(models.BaseResponse).Init()
  316. defer func() {
  317. this.Data["json"] = br
  318. this.ServeJSON()
  319. }()
  320. sysUser := this.SysUser
  321. if sysUser == nil {
  322. br.Msg = "请登录"
  323. br.ErrMsg = "请登录,SysUser Is Empty"
  324. br.Ret = 408
  325. return
  326. }
  327. pageSize, _ := this.GetInt("PageSize")
  328. currentIndex, _ := this.GetInt("CurrentIndex")
  329. status := this.GetString("Status")
  330. sellerId := this.GetString("SellerId")
  331. shareSellerId := this.GetString("ShareSellerId")
  332. //排序参数
  333. sortParam := this.GetString("SortParam")
  334. sortType := this.GetString("SortType")
  335. tagType, _ := this.GetInt("TagType")
  336. tagId, _ := this.GetInt("TagId")
  337. serveTypeId, _ := this.GetInt("ServeTypeId")
  338. keyWord := this.GetString("KeyWord")
  339. isExport, _ := this.GetBool("IsExport")
  340. resp := new(cygx.CygxRaiServeCompanyListResp)
  341. if isExport {
  342. pageSize = 9999
  343. }
  344. var startSize int
  345. if pageSize <= 0 {
  346. pageSize = utils.PageSize20
  347. }
  348. if currentIndex <= 0 {
  349. currentIndex = 1
  350. }
  351. startSize = utils.StartIndex(currentIndex, pageSize)
  352. var condition string
  353. var sortStr string
  354. var pars []interface{}
  355. if status != "" {
  356. if status == "正式" {
  357. condition += " AND status = '正式' "
  358. } else {
  359. condition += " AND status != '正式' "
  360. }
  361. }
  362. if sellerId != "" {
  363. condition += " AND seller_id IN (" + sellerId + ") "
  364. //pars = append(pars, sellerId)
  365. }
  366. if shareSellerId != "" {
  367. condition += " AND share_seller_id IN (" + shareSellerId + ") "
  368. //pars = append(pars, shareSellerId)
  369. }
  370. if sortType != "" && sortParam != "" {
  371. if sortParam == "money" {
  372. sortStr = " ORDER BY money "
  373. }
  374. if sortParam == "endDate" {
  375. sortStr = " ORDER BY end_date "
  376. }
  377. if sortType == "asc" {
  378. sortStr += " ASC "
  379. } else {
  380. sortStr += " DESC "
  381. }
  382. } else {
  383. sortStr = " ORDER BY end_date DESC "
  384. }
  385. //如果不是权益管理员和admin、财务,就做可见权限限制
  386. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_RAI_ADMIN && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_RAI_RESEARCHR {
  387. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER {
  388. condition += " AND (seller_id = ? OR share_seller_id = ? ) "
  389. pars = append(pars, sysUser.AdminId, sysUser.AdminId)
  390. }
  391. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  392. condition += " AND ( seller_id = ? OR share_seller_id = ? OR group_id = ? OR share_group_id = ? ) "
  393. pars = append(pars, sysUser.AdminId, sysUser.AdminId, sysUser.GroupId, sysUser.GroupId)
  394. }
  395. }
  396. //公司名称搜索
  397. if keyWord != "" {
  398. keyWord = "%" + keyWord + "%"
  399. condition += ` AND company_name LIKE ? `
  400. pars = append(pars, keyWord)
  401. }
  402. total, err := cygx.GetCygxRaiServeCompanyCount(condition, pars)
  403. if err != nil {
  404. br.Msg = "获取失败"
  405. br.ErrMsg = "获取失败,GetCygxRaiServeCompanyCountErr:" + err.Error()
  406. return
  407. }
  408. listRaiServeCompany, err := cygx.GetCygxRaiServeCompanyList(condition+sortStr, pars, startSize, pageSize)
  409. if err != nil {
  410. br.Msg = "获取失败"
  411. br.ErrMsg = "获取失败,Err:" + err.Error()
  412. return
  413. }
  414. var companyIds []int
  415. for _, v := range listRaiServeCompany {
  416. companyIds = append(companyIds, v.CompanyId)
  417. }
  418. mapWeekAmount := make(map[string]float64) //周度服务量
  419. mapMonthAmount := make(map[string]float64) //月度服务量
  420. weeks := 4
  421. months := 3
  422. if isExport {
  423. weeks = 12 // 下载获取近12周的数据
  424. months = 6
  425. }
  426. lencompanyIds := len(companyIds)
  427. if lencompanyIds > 0 {
  428. var conditionBill string
  429. var parsBill []interface{}
  430. conditionBill, parsBill, err = getServeBillTag(tagType, tagId) // 标签ID搜索语句处理
  431. if err != nil {
  432. br.Msg = "获取信息失败!"
  433. br.ErrMsg = "获取用户信息失败-getServeBillTag!Err:" + err.Error()
  434. return
  435. }
  436. //服务类型筛选
  437. if serveTypeId > 0 {
  438. conditionBill += ` AND serve_type_id = ? `
  439. parsBill = append(parsBill, serveTypeId)
  440. }
  441. conditionBill += " AND company_id IN (" + utils.GetOrmInReplace(lencompanyIds) + ") "
  442. parsBill = append(parsBill, companyIds)
  443. listBill, err := cygx.GetCygxRaiServeBillListAll(conditionBill, parsBill)
  444. if err != nil {
  445. br.Msg = "获取信息失败!"
  446. br.ErrMsg = "获取用户信息失败-GetCygxRaiServeBillListAll!Err:" + err.Error()
  447. return
  448. }
  449. now := time.Now()
  450. for _, v := range listBill {
  451. for i := 0; i < weeks; i++ {
  452. // 计算当前周的周一
  453. monday := now.AddDate(0, 0, -int(now.Weekday()-time.Monday)-i*7)
  454. weekmonday := monday.Format(utils.FormatDate)
  455. if v.WeekStartDate == weekmonday {
  456. mapWeekAmount[fmt.Sprint("CID_", v.CompanyId, "WEEK_", i)] += v.ServeCount
  457. }
  458. }
  459. for i := 0; i < months; i++ {
  460. // 计算当前月的第一天
  461. monthday := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location()).AddDate(0, -i, 0)
  462. monthFirstDay := monthday.Format(utils.FormatDate)
  463. if v.MonthStartDate == monthFirstDay {
  464. mapMonthAmount[fmt.Sprint("CID_", v.CompanyId, "MONTH_", i)] += v.ServeCount
  465. }
  466. }
  467. }
  468. }
  469. for _, v := range listRaiServeCompany {
  470. item := new(cygx.CygxRaiServeCompanyResp)
  471. item.CompanyId = v.CompanyId
  472. item.CompanyName = v.CompanyName
  473. item.Money = v.Money
  474. item.ServeCoverageRate = v.ServeCoverageRate + "%"
  475. item.SellerId = v.SellerId
  476. item.SellerName = v.SellerName
  477. item.StartDate = v.StartDate
  478. item.StartDate = v.StartDate
  479. item.EndDate = v.EndDate
  480. item.ShareSeller = v.ShareSeller
  481. item.ShareSellerId = v.ShareSellerId
  482. item.Status = v.Status
  483. item.PermissionName = v.PermissionName
  484. item.IsUserMaker = v.IsUserMaker
  485. item.ThisWeekAmount = mapWeekAmount[fmt.Sprint("CID_", v.CompanyId, "WEEK_", 0)]
  486. item.LastWeekAmount = mapWeekAmount[fmt.Sprint("CID_", v.CompanyId, "WEEK_", 1)]
  487. item.TwoWeekAmount = mapWeekAmount[fmt.Sprint("CID_", v.CompanyId, "WEEK_", 2)]
  488. item.ThreeWeekAmount = mapWeekAmount[fmt.Sprint("CID_", v.CompanyId, "WEEK_", 3)]
  489. item.ThisMonthAmount = mapWeekAmount[fmt.Sprint("CID_", v.CompanyId, "MONTH_", 0)]
  490. item.LastMonthAmount = mapWeekAmount[fmt.Sprint("CID_", v.CompanyId, "MONTH_", 1)]
  491. item.TwoMonthAmount = mapWeekAmount[fmt.Sprint("CID_", v.CompanyId, "MONTH_", 2)]
  492. if item.TwoMonthAmount == 0 || item.LastMonthAmount-item.TwoMonthAmount == 0 {
  493. item.LastMonthQoq = "0%" //上月环比=(上月服务量-上上月服务量)/上上月服务量,当数值≤-20%时,用红色字显示
  494. } else {
  495. item.LastMonthQoq = fmt.Sprint(utils.SubFloatToString((item.LastMonthAmount-item.TwoMonthAmount)/item.TwoMonthAmount*100, 2)) + "%"
  496. if (item.LastMonthAmount-item.TwoMonthAmount)/item.TwoMonthAmount <= 0.2 {
  497. item.LastMonthQoqIsRed = true
  498. }
  499. }
  500. resp.List = append(resp.List, item)
  501. }
  502. //导出excel
  503. if isExport {
  504. RaiServeListExport(this, resp, mapWeekAmount, mapMonthAmount, br)
  505. return
  506. }
  507. page := paging.GetPaging(currentIndex, pageSize, total)
  508. resp.Paging = page
  509. br.Ret = 200
  510. br.Success = true
  511. br.Msg = "获取成功"
  512. br.Data = resp
  513. }
  514. // EnterScoreScoreListExport 导出Excel
  515. func RaiServeListExport(this *RaiServeCoAntroller, resp *cygx.CygxRaiServeCompanyListResp, mapWeekAmount map[string]float64, mapMonthAmount map[string]float64, br *models.BaseResponse) {
  516. weeks := 12 // 下载获取近12周的数据
  517. months := 6 // 下载获取近6个月的数据
  518. mapWeekFormat := make(map[int]string)
  519. mapMonthFormat := make(map[int]string)
  520. now := time.Now()
  521. for i := 0; i < weeks; i++ {
  522. // 计算当前周的周一
  523. monday := now.AddDate(0, 0, -int(now.Weekday()-time.Monday)-i*7)
  524. sunday := monday.AddDate(0, 0, 6)
  525. weekmonday := monday.Format(utils.FormatMonthDayUnSpace2)
  526. weeksunday := sunday.Format(utils.FormatMonthDayUnSpace2)
  527. mapWeekFormat[i] = weekmonday + "~" + weeksunday
  528. }
  529. for i := 0; i < months; i++ {
  530. // 处理月份
  531. monthday := now.AddDate(0, -i, 0)
  532. mapMonthFormat[i] = fmt.Sprint(int(monthday.Month()), "月")
  533. }
  534. dir, err := os.Executable()
  535. exPath := filepath.Dir(dir)
  536. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  537. xlsxFile := xlsx.NewFile()
  538. if err != nil {
  539. br.Msg = "生成文件失败"
  540. br.ErrMsg = "生成文件失败"
  541. return
  542. }
  543. style := xlsx.NewStyle()
  544. border := xlsx.NewBorder("thin", "thin", "thin", "thin")
  545. alignment := xlsx.Alignment{
  546. Horizontal: "center",
  547. Vertical: "center",
  548. WrapText: true,
  549. }
  550. redStyle := xlsx.NewStyle()
  551. redStyle.Alignment = alignment
  552. redStyle.ApplyAlignment = true
  553. redStyle.Font.Color = "ff0000"
  554. redStyle.Border = *border
  555. style.Alignment = alignment
  556. style.ApplyAlignment = true
  557. sheel, err := xlsxFile.AddSheet("权益服务统计")
  558. if err != nil {
  559. br.Msg = "新增Sheet失败"
  560. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  561. return
  562. }
  563. sheel.SetColWidth(0, 0, 30)
  564. sheel.SetColWidth(1, 1, 15)
  565. sheel.SetColWidth(2, 2, 15)
  566. sheel.SetColWidth(3, 3, 18)
  567. titleRow := sheel.AddRow()
  568. cellA := titleRow.AddCell()
  569. cellA.SetStyle(style)
  570. cellA.SetValue("客户名称")
  571. cellWeek := titleRow.AddCell()
  572. cellWeek.SetStyle(style)
  573. cellWeek.SetValue("近4周平均服务覆盖率")
  574. cellB := titleRow.AddCell()
  575. cellB.SetStyle(style)
  576. cellB.SetValue("当前状态")
  577. cellC := titleRow.AddCell()
  578. cellC.SetStyle(style)
  579. cellC.SetValue("所属销售")
  580. cellD := titleRow.AddCell()
  581. cellD.SetStyle(style)
  582. cellD.SetValue("服务销售")
  583. cellE := titleRow.AddCell()
  584. cellE.SetStyle(style)
  585. cellE.SetValue("合同期限")
  586. cellF := titleRow.AddCell()
  587. cellF.SetStyle(style)
  588. cellF.SetValue("合同金额")
  589. cellG := titleRow.AddCell()
  590. cellG.SetStyle(style)
  591. cellG.SetValue("签约套餐")
  592. cellWe1 := titleRow.AddCell()
  593. cellWe1.SetStyle(style)
  594. cellWe1.SetValue("本周服务量(" + mapWeekFormat[0] + ")")
  595. cellWe2 := titleRow.AddCell()
  596. cellWe2.SetStyle(style)
  597. cellWe2.SetValue("上周服务量(" + mapWeekFormat[1] + ")")
  598. cellWe3 := titleRow.AddCell()
  599. cellWe3.SetStyle(style)
  600. cellWe3.SetValue("上上周服务量(" + mapWeekFormat[2] + ")")
  601. cellWe4 := titleRow.AddCell()
  602. cellWe4.SetStyle(style)
  603. cellWe4.SetValue("上三周服务量(" + mapWeekFormat[3] + ")")
  604. for i := 0; i < weeks; i++ {
  605. if i < 4 {
  606. continue
  607. }
  608. // 计算当前周的周一
  609. cellWei := titleRow.AddCell()
  610. cellWei.SetStyle(style)
  611. cellWei.SetValue(mapWeekFormat[i])
  612. }
  613. cellMonth1 := titleRow.AddCell()
  614. cellMonth1.SetStyle(style)
  615. cellMonth1.SetValue("本月服务量")
  616. cellMonthQoQ := titleRow.AddCell()
  617. cellMonthQoQ.SetStyle(style)
  618. cellMonthQoQ.SetValue("上月环比")
  619. cellMonth2 := titleRow.AddCell()
  620. cellMonth2.SetStyle(style)
  621. cellMonth2.SetValue("上月服务量")
  622. cellMonth3 := titleRow.AddCell()
  623. cellMonth3.SetStyle(style)
  624. cellMonth3.SetValue("上上月服务量")
  625. for i := 0; i < months; i++ {
  626. if i < 3 {
  627. continue
  628. }
  629. // 计算当前周的周一
  630. cellMonthi := titleRow.AddCell()
  631. cellMonthi.SetStyle(style)
  632. cellMonthi.SetValue(mapMonthFormat[i])
  633. }
  634. for _, v := range resp.List {
  635. dataRow := sheel.AddRow()
  636. dataRow.SetHeight(20)
  637. cellAData := dataRow.AddCell()
  638. if v.IsUserMaker == -1 {
  639. cellAData.SetStyle(redStyle)
  640. } else {
  641. cellAData.SetStyle(style)
  642. }
  643. cellAData.SetValue(v.CompanyName)
  644. cellWeekData := dataRow.AddCell()
  645. cellWeekData.SetStyle(style)
  646. cellWeekData.SetValue(v.ServeCoverageRate)
  647. cellBData := dataRow.AddCell()
  648. cellBData.SetStyle(style)
  649. cellBData.SetValue(v.Status)
  650. cellCData := dataRow.AddCell()
  651. cellCData.SetStyle(style)
  652. cellCData.SetValue(v.SellerName)
  653. cellDData := dataRow.AddCell()
  654. cellDData.SetStyle(style)
  655. cellDData.SetValue(v.ShareSeller)
  656. cellEData := dataRow.AddCell()
  657. cellEData.SetStyle(style)
  658. cellEData.SetValue(v.StartDate + "~" + v.EndDate)
  659. cellFData := dataRow.AddCell()
  660. cellFData.SetStyle(style)
  661. cellFData.SetValue(v.Money)
  662. cellGData := dataRow.AddCell()
  663. cellGData.SetStyle(style)
  664. cellGData.SetValue(v.PermissionName)
  665. for i := 0; i < weeks; i++ {
  666. cellWeiData := dataRow.AddCell()
  667. cellWeiData.SetStyle(style)
  668. cellWeiData.SetValue(mapWeekAmount[fmt.Sprint("CID_", v.CompanyId, "WEEK_", i)])
  669. }
  670. cellMonth1Data := dataRow.AddCell()
  671. cellMonth1Data.SetStyle(style)
  672. cellMonth1Data.SetValue(mapMonthAmount[fmt.Sprint("CID_", v.CompanyId, "MONTH_", 0)])
  673. cellMonthQoQData := dataRow.AddCell()
  674. var cellMonthQoQStr string
  675. if mapMonthAmount[fmt.Sprint("CID_", v.CompanyId, "MONTH_", 1)]-mapMonthAmount[fmt.Sprint("CID_", v.CompanyId, "MONTH_", 2)] == 0 || mapMonthAmount[fmt.Sprint("CID_", v.CompanyId, "MONTH_", 2)] == 0 {
  676. cellMonthQoQStr = "0%"
  677. } else {
  678. cellMonthQoQStr = fmt.Sprint(utils.SubFloatToString((mapMonthAmount[fmt.Sprint("CID_", v.CompanyId, "MONTH_", 1)]-mapMonthAmount[fmt.Sprint("CID_", v.CompanyId, "MONTH_", 2)])/mapMonthAmount[fmt.Sprint("CID_", v.CompanyId, "MONTH_", 2)]*100, 2)) + "%"
  679. if (mapMonthAmount[fmt.Sprint("CID_", v.CompanyId, "MONTH_", 1)]-mapMonthAmount[fmt.Sprint("CID_", v.CompanyId, "MONTH_", 2)])/mapMonthAmount[fmt.Sprint("CID_", v.CompanyId, "MONTH_", 2)] <= 0.2 {
  680. cellMonthQoQData.SetStyle(redStyle) //小于0.2做标红处理
  681. } else {
  682. cellMonthQoQData.SetStyle(style)
  683. }
  684. }
  685. cellMonthQoQData.SetValue(cellMonthQoQStr)
  686. for i := 0; i < months; i++ {
  687. if i == 0 {
  688. continue
  689. }
  690. cellMonthData := dataRow.AddCell()
  691. cellMonthData.SetStyle(style)
  692. cellMonthData.SetValue(mapMonthAmount[fmt.Sprint("CID_", v.CompanyId, "MONTH_", i)])
  693. }
  694. }
  695. err = xlsxFile.Save(downLoadnFilePath)
  696. if err != nil {
  697. br.Msg = "保存文件失败"
  698. br.ErrMsg = "保存文件失败"
  699. return
  700. }
  701. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  702. downloadFileName := "权益服务统计导出数据_" + randStr + ".xlsx"
  703. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  704. defer func() {
  705. os.Remove(downLoadnFilePath)
  706. }()
  707. br.Ret = 200
  708. br.Success = true
  709. br.Msg = "导出成功"
  710. }
  711. // 标签搜索语句筛选
  712. func getServeBillTag(tagType, tagId int) (conditionBill string, parsBill []interface{}, err error) {
  713. if tagType == 0 {
  714. return
  715. }
  716. var activityIds []int
  717. var activitySpecialIds []int
  718. var articleIds []int
  719. var rsCalendarIds []int
  720. switch tagType {
  721. case 1:
  722. listGroupActivity, e := cygx.GetIndustrialActivityGroupManagementListByIndustriaId(tagId, 1) // 关联的活动
  723. if e != nil {
  724. err = errors.New("GetIndustrialActivityGroupManagementListByIndustriaId, Err: " + e.Error())
  725. return
  726. }
  727. for _, v := range listGroupActivity {
  728. activityIds = append(activityIds, v.ActivityId)
  729. }
  730. listGroupActivitySpecial, e := cygx.GetIndustrialActivityGroupManagementListByIndustriaId(tagId, 2) // 关联的产业
  731. if e != nil {
  732. err = errors.New("GetIndustrialActivityGroupManagementListByIndustriaId, Err: " + e.Error())
  733. return
  734. }
  735. for _, v := range listGroupActivitySpecial {
  736. activitySpecialIds = append(activitySpecialIds, v.ActivityId)
  737. }
  738. listGroupArticle, e := cygx.GetIndustrialArticleGroupManagementListByindustrialId(tagId) // 关联的产业
  739. if e != nil {
  740. err = errors.New("GetIndustrialArticleGroupManagementListByindustrialId, Err: " + e.Error())
  741. return
  742. }
  743. for _, v := range listGroupArticle {
  744. articleIds = append(articleIds, v.ArticleId)
  745. }
  746. listGroupRsCalendar, e := roadshow.GetRsCalendarMeetingLabelGroupDetailByTag(tagType, tagId)
  747. if e != nil {
  748. err = errors.New("GetRsCalendarMeetingLabelGroupDetailByTag, Err: " + e.Error())
  749. return
  750. }
  751. for _, v := range listGroupRsCalendar {
  752. rsCalendarIds = append(rsCalendarIds, v.RsCalendarId)
  753. }
  754. case 2:
  755. //通过ID获取标的名称
  756. detailSubjecj, e := cygx.GetIndustrialSubjectDetailById(tagId)
  757. if e != nil {
  758. err = errors.New("GetIndustrialSubjectDetailById, Err: " + e.Error())
  759. return
  760. }
  761. //通过名称获取所有相同名称的标的
  762. listSubject, e := cygx.GetListIndustrialSubjectDetailByName(detailSubjecj.SubjectName)
  763. if e != nil {
  764. err = errors.New("GetIndustrialSubjectDetailById, Err: " + e.Error())
  765. return
  766. }
  767. var industrialSubjectIds []int
  768. for _, v := range listSubject {
  769. industrialSubjectIds = append(industrialSubjectIds, v.IndustrialSubjectId)
  770. }
  771. listGroupActivity, e := cygx.GetSubjectActivityGroupManagementListBySubjectIds(industrialSubjectIds, 1) // 关联的活动
  772. if e != nil {
  773. err = errors.New("GetSubjectActivityGroupManagementListBySubjectId, Err: " + e.Error())
  774. return
  775. }
  776. for _, v := range listGroupActivity {
  777. activityIds = append(activityIds, v.ActivityId)
  778. }
  779. listGroupActivitySpecial, e := cygx.GetSubjectActivityGroupManagementListBySubjectIds(industrialSubjectIds, 2) // 关联的专项调研活动
  780. if e != nil {
  781. err = errors.New("GetSubjectActivityGroupManagementListBySubjectIds, Err: " + e.Error())
  782. return
  783. }
  784. for _, v := range listGroupActivitySpecial {
  785. activitySpecialIds = append(activitySpecialIds, v.ActivityId)
  786. }
  787. listGroupArticle, e := cygx.GetSubjectArticleGroupManagementListBysubjectIds(industrialSubjectIds) // 关联的报告
  788. if e != nil {
  789. err = errors.New("GetSubjectArticleGroupManagementListBysubjectIds, Err: " + e.Error())
  790. return
  791. }
  792. for _, v := range listGroupArticle {
  793. articleIds = append(articleIds, v.ArticleId)
  794. }
  795. listGroupRsCalendar, e := roadshow.GetRsCalendarMeetingLabelGroupDetailByTagIds(tagType, industrialSubjectIds)
  796. if e != nil {
  797. err = errors.New("GetRsCalendarMeetingLabelGroupDetailByTagIds, Err: " + e.Error())
  798. return
  799. }
  800. for _, v := range listGroupRsCalendar {
  801. rsCalendarIds = append(rsCalendarIds, v.RsCalendarId)
  802. }
  803. activityIds = append(activityIds, 0)
  804. lenactivityIds := len(activityIds)
  805. //if lenactivityIds > 0 {
  806. conditionBill += ` AND IF ( source = 'activity', source_id IN (` + utils.GetOrmInReplace(lenactivityIds) + `) , 1 = 1 ) `
  807. parsBill = append(parsBill, activityIds)
  808. //}
  809. activitySpecialIds = append(activitySpecialIds, 0)
  810. lenactivitySpecialIds := len(activitySpecialIds)
  811. //if lenactivitySpecialIds > 0 {
  812. conditionBill += ` AND IF ( source = 'activityspecial', source_id IN (` + utils.GetOrmInReplace(lenactivitySpecialIds) + `) , 1 = 1 ) `
  813. parsBill = append(parsBill, activitySpecialIds)
  814. //}
  815. articleIds = append(articleIds, 0)
  816. lenarticleIds := len(articleIds)
  817. //if lenarticleIds > 0 {
  818. conditionBill += ` AND IF ( source = 'article', source_id IN (` + utils.GetOrmInReplace(lenarticleIds) + `) , 1 = 1 ) `
  819. parsBill = append(parsBill, articleIds)
  820. //}
  821. rsCalendarIds = append(rsCalendarIds, 0)
  822. lenrsCalendarIds := len(rsCalendarIds)
  823. //if lenrsCalendarIds > 0 {
  824. conditionBill += ` AND IF ( source = 'rscalendar', source_id IN (` + utils.GetOrmInReplace(lenrsCalendarIds) + `) , 1 = 1 ) `
  825. parsBill = append(parsBill, rsCalendarIds)
  826. case 3:
  827. conditionBill += " AND chart_permission_id = ? "
  828. parsBill = append(parsBill, tagId)
  829. }
  830. //}
  831. conditionBill += ` AND source != 'yanxuanspecial' AND source != 'userfeedback' `
  832. return
  833. }
  834. // @Title 近四周覆盖率
  835. // @Description 近四周覆盖率接口
  836. // @Param CompanyId query int false "公司ID"
  837. // @Success 200 {object} cygx.RaiServeTagListResp
  838. // @router /rai_serve/coverage_rate [get]
  839. func (this *RaiServeCoAntroller) CoverageRate() {
  840. br := new(models.BaseResponse).Init()
  841. defer func() {
  842. this.Data["json"] = br
  843. this.ServeJSON()
  844. }()
  845. sysUser := this.SysUser
  846. if sysUser == nil {
  847. br.Msg = "请登录"
  848. br.ErrMsg = "请登录,SysUser Is Empty"
  849. br.Ret = 408
  850. return
  851. }
  852. companyId, _ := this.GetInt("CompanyId")
  853. listWeekBill, err := cygx.GetCygxRaiServeBillListWeek4(companyId)
  854. if err != nil {
  855. br.Msg = "获取信息失败!"
  856. br.ErrMsg = "获取用户信息失败-GetCygxRaiServeBillListWeek4!Err:" + err.Error()
  857. return
  858. }
  859. mapWeek := make(map[int]string)
  860. for k, v := range listWeekBill {
  861. mapWeek[k] = utils.SubFloatToString(v.CoverageRate, 2)
  862. }
  863. resp := new(cygx.RaiServeCoverageRateResp)
  864. resp.ThisWeekAmount = mapWeek[0] + "%"
  865. resp.LastWeekAmount = mapWeek[1] + "%"
  866. resp.TwoWeekAmount = mapWeek[2] + "%"
  867. resp.ThreeWeekAmount = mapWeek[3] + "%"
  868. br.Ret = 200
  869. br.Success = true
  870. br.Msg = "获取成功"
  871. br.Data = resp
  872. }
  873. // @Title 明细列表
  874. // @Description 明细列表接口
  875. // @Param PageSize query int true "每页数据条数"
  876. // @Param CurrentIndex query int true "当前页页码,从1开始"
  877. // @Param CompanyId query int false "公司ID"
  878. // @Param TagType query int false "标签类型"
  879. // @Param TagId query int false "标签ID"
  880. // @Param ServeTypeId int int false "服务类型ID"
  881. // @Param WhatWeek query int false "哪一周 ,1:本周、2:上周、3:上上周、4上三周"
  882. // @Param WhatMonth query int false "哪一月 ,1:本月、2:上月、3:上上月"
  883. // @Success 200 {object} cygx.RaiServeTagListResp
  884. // @router /rai_serve/bill_list [get]
  885. func (this *RaiServeCoAntroller) BillList() {
  886. br := new(models.BaseResponse).Init()
  887. defer func() {
  888. this.Data["json"] = br
  889. this.ServeJSON()
  890. }()
  891. sysUser := this.SysUser
  892. if sysUser == nil {
  893. br.Msg = "请登录"
  894. br.ErrMsg = "请登录,SysUser Is Empty"
  895. br.Ret = 408
  896. return
  897. }
  898. pageSize, _ := this.GetInt("PageSize")
  899. currentIndex, _ := this.GetInt("CurrentIndex")
  900. companyId, _ := this.GetInt("CompanyId")
  901. tagType, _ := this.GetInt("TagType")
  902. tagId, _ := this.GetInt("TagId")
  903. serveTypeId, _ := this.GetInt("ServeTypeId")
  904. whatWeek, _ := this.GetInt("WhatWeek")
  905. whatMonth, _ := this.GetInt("WhatMonth")
  906. var startSize int
  907. if pageSize <= 0 {
  908. pageSize = utils.PageSize20
  909. }
  910. if currentIndex <= 0 {
  911. currentIndex = 1
  912. }
  913. startSize = utils.StartIndex(currentIndex, pageSize)
  914. if companyId == 0 {
  915. br.Msg = "请选择对应公司ID"
  916. return
  917. }
  918. var condition string
  919. var pars []interface{}
  920. var err error
  921. condition, pars, err = getServeBillTag(tagType, tagId) // 标签ID搜索语句处理
  922. if err != nil {
  923. br.Msg = "获取信息失败!"
  924. br.ErrMsg = "获取用户信息失败-getServeBillTag!Err:" + err.Error()
  925. return
  926. }
  927. if whatWeek > 0 {
  928. now := time.Now()
  929. // 计算所选周的周一
  930. monday := now.AddDate(0, 0, -int(now.Weekday()-time.Monday)-(whatWeek-1)*7)
  931. condition += " AND week_start_date = ? "
  932. pars = append(pars, monday.Format(utils.FormatDate))
  933. }
  934. if whatMonth > 0 {
  935. now := time.Now()
  936. // 计算所选月份的第一天
  937. monthday := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location()).AddDate(0, -whatMonth+1, 0)
  938. condition += " AND month_start_date = ? "
  939. pars = append(pars, monthday.Format(utils.FormatDate))
  940. }
  941. condition += " AND company_id = ? "
  942. pars = append(pars, companyId)
  943. if serveTypeId > 0 {
  944. condition += " AND serve_type_id = ? "
  945. pars = append(pars, serveTypeId)
  946. }
  947. total, err := cygx.GetCygxRaiServeBillCount(condition, pars)
  948. if err != nil {
  949. br.Msg = "获取失败"
  950. br.ErrMsg = "获取失败,GetCygxRaiServeBillCount:" + err.Error()
  951. return
  952. }
  953. list, err := cygx.GetCygxRaiServeBillRespList(condition, pars, startSize, pageSize)
  954. if err != nil {
  955. br.Msg = "获取失败"
  956. br.ErrMsg = "获取失败,GetCygxRaiServeBillRespList:" + err.Error()
  957. return
  958. }
  959. page := paging.GetPaging(currentIndex, pageSize, total)
  960. resp := new(cygx.CygxRaiServeBillListResp)
  961. resp.Paging = page
  962. if len(list) == 0 {
  963. resp.List = make([]*cygx.CygxRaiServeBillResp, 0)
  964. } else {
  965. var activityIds []int
  966. var activitySpecialIds []int
  967. var articleIds []int
  968. var rsCalendarIds []int
  969. for _, v := range list {
  970. switch v.Source {
  971. case utils.CYGX_OBJ_ARTICLE:
  972. articleIds = append(articleIds, v.SourceId)
  973. case utils.CYGX_OBJ_ACTIVITY:
  974. activityIds = append(activityIds, v.SourceId)
  975. case utils.CYGX_OBJ_ACTIVITYSPECIAL:
  976. activitySpecialIds = append(activitySpecialIds, v.SourceId)
  977. case utils.CYGX_OBJ_RS_CALENDAR:
  978. rsCalendarIds = append(rsCalendarIds, v.SourceId)
  979. }
  980. if v.ServeTypeName == "阅读uv" {
  981. v.ServeTypeName = "报告阅读uv" //服务类型名称做一下,映射修改
  982. }
  983. }
  984. maparticleIndustrialLabel := make(map[int][]string) //文章产业标签
  985. maparticleSubjectLabel := make(map[int][]string) // 文章行业标签
  986. if len(articleIds) > 0 {
  987. maparticleIndustrialLabel = cygxService.GetArticleIndustrialLabelByArticleId(articleIds) // 关联产业
  988. maparticleSubjectLabel = cygxService.GetArticleSubjectLabelByArticleId(articleIds) // 关联标的
  989. }
  990. mapActivityIndustrialLabel := make(map[int][]string) //活动产业标签
  991. mapActivitySubjectLabel := make(map[int][]string) //活动标的标签
  992. mapActivityIndustrialLabel = cygxService.GetActivityIndustrialLabelByActivityIds(activityIds, 1)
  993. mapActivitySubjectLabel = cygxService.GetActivitySubjectLabelByActivityIds(activityIds, 1)
  994. mapActivitySpeicalIndustrialLabel := make(map[int][]string) //活动产业标签
  995. mapActivitySpeicalSubjectLabel := make(map[int][]string) //活动标的标签
  996. mapActivitySpeicalIndustrialLabel = cygxService.GetActivityIndustrialLabelByActivityIds(activityIds, 2)
  997. mapActivitySpeicalSubjectLabel = cygxService.GetActivitySubjectLabelByActivityIds(activityIds, 2)
  998. mapRsCalendarLabel := make(map[int][]string) //1v1 路演标签
  999. mapRsCalendarLabel = cygxService.GetRsCalendarLabelByRsCalendarIds(rsCalendarIds)
  1000. for _, v := range list {
  1001. switch v.Source {
  1002. case utils.CYGX_OBJ_ARTICLE:
  1003. if v.ChartPermissionName == utils.GU_SHOU_NAME || v.ChartPermissionName == utils.CE_LUE_NAME {
  1004. v.Tag = v.ChartPermissionName
  1005. } else {
  1006. v.Tag = strings.Join(maparticleIndustrialLabel[v.SourceId], ",")
  1007. if len(maparticleSubjectLabel[v.SourceId]) > 0 {
  1008. v.Tag += "," + strings.Join(maparticleSubjectLabel[v.SourceId], ",")
  1009. }
  1010. }
  1011. case utils.CYGX_OBJ_ACTIVITY:
  1012. if v.ChartPermissionName == utils.GU_SHOU_NAME || v.ChartPermissionName == utils.CE_LUE_NAME {
  1013. v.Tag = v.ChartPermissionName
  1014. } else {
  1015. v.Tag = strings.Join(mapActivityIndustrialLabel[v.SourceId], ",")
  1016. if len(mapActivitySubjectLabel[v.SourceId]) > 0 {
  1017. v.Tag += "," + strings.Join(mapActivitySubjectLabel[v.SourceId], ",")
  1018. }
  1019. }
  1020. case utils.CYGX_OBJ_ACTIVITYSPECIAL:
  1021. if v.ChartPermissionName == utils.GU_SHOU_NAME || v.ChartPermissionName == utils.CE_LUE_NAME {
  1022. v.Tag = v.ChartPermissionName
  1023. } else {
  1024. v.Tag = strings.Join(mapActivitySpeicalIndustrialLabel[v.SourceId], ",")
  1025. if len(mapActivitySpeicalSubjectLabel[v.SourceId]) > 0 {
  1026. v.Tag += "," + strings.Join(mapActivitySpeicalSubjectLabel[v.SourceId], ",")
  1027. }
  1028. }
  1029. case utils.CYGX_OBJ_RS_CALENDAR:
  1030. if v.ChartPermissionName == utils.GU_SHOU_NAME || v.ChartPermissionName == utils.CE_LUE_NAME {
  1031. v.Tag = v.ChartPermissionName
  1032. } else {
  1033. v.Tag = strings.Join(mapRsCalendarLabel[v.SourceId], ",")
  1034. }
  1035. }
  1036. }
  1037. resp.List = list
  1038. }
  1039. br.Ret = 200
  1040. br.Success = true
  1041. br.Msg = "获取成功"
  1042. br.Data = resp
  1043. }
  1044. // AddCompanyHistoryRemark
  1045. // @Title 新增历史备注
  1046. // @Description 新增历史备注
  1047. // @Param request body company.CompanyHistoryRemarkReq true "type json string"
  1048. // @Success 200 编辑成功
  1049. // @router /rai_serve/remark/add [post]
  1050. func (this *RaiServeCoAntroller) AddRemark() {
  1051. br := new(models.BaseResponse).Init()
  1052. defer func() {
  1053. this.Data["json"] = br
  1054. this.ServeJSON()
  1055. }()
  1056. sysUser := this.SysUser
  1057. if sysUser == nil {
  1058. br.Msg = "请登录"
  1059. br.ErrMsg = "请登录,SysUser Is Empty"
  1060. br.Ret = 408
  1061. return
  1062. }
  1063. var req company.CompanyHistoryRemarkReq
  1064. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1065. if err != nil {
  1066. br.Msg = "参数解析异常!"
  1067. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1068. return
  1069. }
  1070. if req.CompanyId <= 0 {
  1071. br.Msg = "参数缺失"
  1072. br.ErrMsg = "参数缺失,客户编号未传!"
  1073. return
  1074. }
  1075. if req.Content == "" {
  1076. br.Msg = "参数缺失"
  1077. br.ErrMsg = "参数缺失,备注说明未传!"
  1078. return
  1079. }
  1080. var productId int
  1081. //var productName string
  1082. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  1083. br.Msg = "角色类型错误"
  1084. br.ErrMsg = "角色类型错误,该角色不能添加备注!"
  1085. return
  1086. }
  1087. productId = 2
  1088. item := new(company.CompanyHistoryRemark)
  1089. item.CompanyId = req.CompanyId
  1090. item.ProductId = productId
  1091. item.Content = req.Content
  1092. item.SysAdminId = sysUser.AdminId
  1093. item.SysAdminName = sysUser.RealName
  1094. item.CreateTime = time.Now()
  1095. item.ModifyTime = time.Now()
  1096. item.ShowTime = time.Now()
  1097. item.TableName = "company_history_remark"
  1098. err = company.AddCompanyHistoryRemark(item)
  1099. //{
  1100. // approveContent := req.Remark
  1101. // remark := "新增备注"
  1102. // operation := "add_remark"
  1103. // services.AddCompanyOperationRecord(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, companyProduct.ProductId, sysUser.AdminId, companyProduct.CompanyName,
  1104. // companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, sysUser.RealName, "", companyProduct.Status)
  1105. //}
  1106. if err != nil {
  1107. br.Msg = "编辑失败"
  1108. br.ErrMsg = "编辑失败,Err:" + err.Error()
  1109. }
  1110. br.Ret = 200
  1111. br.Success = true
  1112. br.Msg = "编辑成功"
  1113. }
  1114. // RemarkList 备注列表
  1115. // @Title 备注列表
  1116. // @Description 备注列表
  1117. // @Param CompanyId query string true "客户id"
  1118. // @Success 200 {object} company.RemarkResp
  1119. // @router /rai_serve/remark/list [get]
  1120. func (this *RaiServeCoAntroller) RemarkList() {
  1121. br := new(models.BaseResponse).Init()
  1122. defer func() {
  1123. this.Data["json"] = br
  1124. this.ServeJSON()
  1125. }()
  1126. sysUser := this.SysUser
  1127. if sysUser == nil {
  1128. br.Msg = "请登录"
  1129. br.ErrMsg = "请登录,SysUser Is Empty"
  1130. br.Ret = 408
  1131. return
  1132. }
  1133. companyId := this.GetString("CompanyId")
  1134. var remarkList []*company.CompanyHistoryRemark
  1135. var err error
  1136. groupFicc := []string{
  1137. utils.ROLE_TYPE_CODE_FICC_SELLER, utils.ROLE_TYPE_CODE_FICC_TEAM, utils.ROLE_TYPE_CODE_FICC_GROUP,
  1138. utils.ROLE_TYPE_CODE_FICC_DEPARTMENT, utils.ROLE_TYPE_CODE_FICC_ADMIN,
  1139. }
  1140. if utils.InArrayByStr(groupFicc, sysUser.RoleTypeCode) {
  1141. br.Msg = "角色类型错误"
  1142. br.ErrMsg = "角色类型错误,该角色不能添加备注!"
  1143. return
  1144. }
  1145. remarkList, err = company.GetCompanyHistoryRemarkList(companyId, "2")
  1146. if err != nil {
  1147. br.Msg = "获取失败"
  1148. br.ErrMsg = "获取失败,Err:" + err.Error()
  1149. return
  1150. }
  1151. resp := new(company.CompanyHistoryRemarkListResp)
  1152. for _, v := range remarkList {
  1153. item := new(company.CompanyHistoryRemarkResp)
  1154. item.CompanyId = v.CompanyId
  1155. item.Content = v.Content
  1156. item.SysAdminName = v.SysAdminName
  1157. item.CreateTime = v.ShowTime.Format(utils.FormatDateTime)
  1158. switch v.TableName {
  1159. case "company_service_record":
  1160. item.RemarkType = "沟通记录"
  1161. case "company_product_remark":
  1162. item.RemarkType = "备注"
  1163. case "company_no_renewed_note":
  1164. item.RemarkType = "未续约备注"
  1165. case "company_renewal_reason":
  1166. item.RemarkType = "未续约说明"
  1167. case "cygx_user_feedback":
  1168. item.RemarkType = "交流反馈(" + v.RealName + ")"
  1169. default:
  1170. item.RemarkType = "备注"
  1171. }
  1172. resp.List = append(resp.List, item)
  1173. }
  1174. br.Ret = 200
  1175. br.Success = true
  1176. br.Msg = "获取成功"
  1177. br.Data = resp
  1178. }