enter_score.go 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585
  1. package cygx
  2. import (
  3. "encoding/json"
  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/company"
  10. "hongze/hz_crm_api/models/cygx"
  11. "hongze/hz_crm_api/models/system"
  12. cygxService "hongze/hz_crm_api/services/cygx"
  13. "hongze/hz_crm_api/utils"
  14. "os"
  15. "path/filepath"
  16. "strings"
  17. "time"
  18. )
  19. // X类客户录分模块
  20. type EnterScoreController struct {
  21. controllers.BaseAuthController
  22. }
  23. // @Title X试用类客户检索
  24. // @Description X试用类客户检索接口
  25. // @Param KeyWord query string true "搜索关键词"
  26. // @Success 200 {object} company.CompanyNameAndIdListResp
  27. // @router /enterScore/company/searchlist [get]
  28. func (this *EnterScoreController) CompanySearchList() {
  29. br := new(models.BaseResponse).Init()
  30. defer func() {
  31. this.Data["json"] = br
  32. this.ServeJSON()
  33. }()
  34. sysUser := this.SysUser
  35. if sysUser == nil {
  36. br.Msg = "请登录"
  37. br.ErrMsg = "请登录,SysUser Is Empty"
  38. br.Ret = 408
  39. return
  40. }
  41. keyWord := this.GetString("KeyWord")
  42. keyWord = strings.Trim(keyWord, " ")
  43. keyWord = strings.Replace(keyWord, "'", "", -1)
  44. resp := new(company.CompanyNameAndIdListResp)
  45. var companyCondition string
  46. var companypars []interface{}
  47. var listResp []*company.CompanyNameAndId
  48. companyCondition += ` AND b.product_name = ? `
  49. companypars = append(companypars, "权益")
  50. companyCondition += ` AND b.status = ? `
  51. companypars = append(companypars, "永续")
  52. if keyWord != "" {
  53. companyCondition += ` AND a.company_name LIKE '%` + keyWord + `%' `
  54. }
  55. //权益申请销售只能看到自己名下的客户的申请
  56. companyIds, err := cygxService.GetAdminLookUserCompanyIdsByResearcher(sysUser)
  57. if err != nil {
  58. br.Msg = "获取失败"
  59. br.ErrMsg = "获取失败,GetAdminLookUserCompanyIds Err:" + err.Error()
  60. return
  61. }
  62. lencompanyIds := len(companyIds)
  63. if lencompanyIds > 0 {
  64. companyCondition += ` AND a.company_id IN (` + utils.GetOrmInReplace(lencompanyIds) + `)`
  65. companypars = append(companypars, companyIds)
  66. }
  67. companyList, err := company.GetCompanyIdListByproductName(companyCondition, companypars)
  68. if err != nil {
  69. br.Msg = "获取失败"
  70. br.ErrMsg = "获取失败,Err:" + err.Error()
  71. return
  72. }
  73. if len(companyList) == 0 {
  74. listResp = make([]*company.CompanyNameAndId, 0)
  75. } else {
  76. listResp = companyList
  77. }
  78. resp.List = listResp
  79. br.Ret = 200
  80. br.Success = true
  81. br.Msg = "获取成功"
  82. br.Data = resp
  83. }
  84. // @Title 详情
  85. // @Description 获取详情接口
  86. // @Param EnterScoreId query int true "录分ID"
  87. // @Success Ret=200 {object} cygx.CygxEnterScoreDetailResp
  88. // @router /enterScore/detail [get]
  89. func (this *EnterScoreController) EnterScoreDetail() {
  90. br := new(models.BaseResponse).Init()
  91. defer func() {
  92. this.Data["json"] = br
  93. this.ServeJSON()
  94. }()
  95. AdminUser := this.SysUser
  96. if AdminUser == nil {
  97. br.Msg = "请登录"
  98. br.ErrMsg = "请登录,用户信息为空"
  99. br.Ret = 408
  100. return
  101. }
  102. enterScoreId, _ := this.GetInt("EnterScoreId")
  103. resp := new(cygx.CygxEnterScoreDetailResp)
  104. var itemslistPermission []*cygx.EnterScorePermissionListResp // 权益行业
  105. var itemsFicclistPermission []*cygx.EnterScorePermissionListResp // FICC行业
  106. mapRaiUser := make(map[string][]*cygx.EnterScoreRealNameListResp) //权益研究员
  107. mapFiccUser := make(map[string][]*cygx.EnterScoreRealNameListResp) // FICC研究员
  108. var itemsGroup []*cygx.EnterScoreGroupListResp //自定义分组
  109. if enterScoreId == 0 {
  110. //权益研究员
  111. sysUserList, err := cygx.GetAskEmailList()
  112. if err != nil {
  113. br.Msg = "获取失败"
  114. br.ErrMsg = "获取失败,GetAskEmailList Err: " + err.Error()
  115. return
  116. }
  117. for _, v := range sysUserList {
  118. item := new(cygx.EnterScoreRealNameListResp)
  119. item.RealName = v.Name
  120. item.ChartPermissionName = v.ChartPermissionName
  121. mapRaiUser[v.ChartPermissionName] = append(mapRaiUser[v.ChartPermissionName], item)
  122. }
  123. listPermission, err := cygx.GetChartPermissionAll()
  124. if err != nil {
  125. br.Msg = "获取信息失败"
  126. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  127. return
  128. }
  129. permissionNameArr := []string{"医药", "消费", "科技", "智造", "策略", "固收"}
  130. for _, v := range listPermission {
  131. if !utils.InArrayByStr(permissionNameArr, v.PermissionName) {
  132. continue
  133. }
  134. item := new(cygx.EnterScorePermissionListResp)
  135. item.ChartPermissionName = v.PermissionName
  136. if len(mapRaiUser[v.PermissionName]) == 0 {
  137. item.List = make([]*cygx.EnterScoreRealNameListResp, 0)
  138. } else {
  139. item.List = mapRaiUser[v.PermissionName]
  140. }
  141. itemslistPermission = append(itemslistPermission, item)
  142. }
  143. resp.EnterScoreObj.ListRai = itemslistPermission
  144. //ficc 研究员
  145. ficcUserList, err := system.GetFiccEnterScoreAdmin()
  146. if err != nil {
  147. br.Msg = "获取失败"
  148. br.ErrMsg = "获取失败,GetFiccEnterScoreAdmin Err: " + err.Error()
  149. return
  150. }
  151. for _, v := range ficcUserList {
  152. item := new(cygx.EnterScoreRealNameListResp)
  153. item.RealName = v.RealName
  154. item.ChartPermissionName = v.GroupName
  155. mapFiccUser[v.GroupName] = append(mapFiccUser[v.GroupName], item)
  156. }
  157. permissionFiccNameArr := []string{"宏观组", "建材组", "有色组", "能化组", "海外组"}
  158. for _, v := range permissionFiccNameArr {
  159. item := new(cygx.EnterScorePermissionListResp)
  160. item.ChartPermissionName = v
  161. if len(mapFiccUser[v]) == 0 {
  162. item.List = make([]*cygx.EnterScoreRealNameListResp, 0)
  163. } else {
  164. item.List = mapFiccUser[v]
  165. }
  166. itemsFicclistPermission = append(itemsFicclistPermission, item)
  167. }
  168. resp.EnterScoreObj.ListFicc = itemsFicclistPermission
  169. groupNameArr := []string{"销售分", "专题分", "专家分", "云图大拓", "艾摩宏观"}
  170. for _, v := range groupNameArr {
  171. item := new(cygx.EnterScoreGroupListResp)
  172. item.GroupName = v
  173. itemsGroup = append(itemsGroup, item)
  174. }
  175. resp.EnterScoreObj.ListGroup = itemsGroup
  176. resp.PercentageObj = resp.EnterScoreObj
  177. resp.EnterScoreType = 1
  178. resp.Quarter = make([]string, 0)
  179. } else {
  180. //初始化数据,方便前端渲染
  181. var itemslistPermissionInit []*cygx.EnterScorePermissionListResp // 权益行业
  182. var itemsFicclistPermissionInit []*cygx.EnterScorePermissionListResp // FICC行业
  183. var itemsGroupInit []*cygx.EnterScoreGroupListResp //自定义分组
  184. mapRaiUserInit := make(map[string][]*cygx.EnterScoreRealNameListResp) //权益研究员
  185. mapFiccUserInit := make(map[string][]*cygx.EnterScoreRealNameListResp) // FICC研究员
  186. enterScoreDetail, err := cygx.GetCygxEnterScoreInfoById(enterScoreId)
  187. if err != nil {
  188. br.Msg = "获取失败"
  189. br.ErrMsg = "获取失败,GetCygxEnterScoreInfoById Err: " + err.Error()
  190. return
  191. }
  192. resp.EnterScoreId = enterScoreDetail.EnterScoreId
  193. resp.CompanyId = enterScoreDetail.CompanyId
  194. resp.CompanyName = enterScoreDetail.CompanyName
  195. resp.StartDate = enterScoreDetail.StartDate
  196. resp.EndDate = enterScoreDetail.EndDate
  197. resp.Quarter = strings.Split(enterScoreDetail.Quarter, ",")
  198. resp.EnterScoreType = enterScoreDetail.EnterScoreType
  199. resp.Ranking = enterScoreDetail.Ranking
  200. resp.IsMergeScoring = enterScoreDetail.IsMergeScoring
  201. resp.SecuritiesFirmsName = enterScoreDetail.SecuritiesFirmsName
  202. resp.MergeProportion = enterScoreDetail.MergeProportion
  203. resp.ProportionTotal = enterScoreDetail.ProportionTotal
  204. resp.RaiProportionTotal = enterScoreDetail.RaiProportionTotal
  205. resp.FiccProportionTotal = enterScoreDetail.FiccProportionTotal
  206. listResearcher, err := cygx.GeCygxEnterScoreResearcherListById(enterScoreId)
  207. if err != nil {
  208. br.Msg = "获取失败"
  209. br.ErrMsg = "获取失败,GeCygxEnterScoreResearcherListById Err: " + err.Error()
  210. return
  211. }
  212. for _, v := range listResearcher {
  213. item := new(cygx.EnterScoreRealNameListResp)
  214. item.RealName = v.RealName
  215. item.ChartPermissionName = v.ChartPermissionName
  216. item.Proportion = v.Proportion
  217. if v.ProductId == utils.COMPANY_PRODUCT_RAI_ID {
  218. mapRaiUser[v.ChartPermissionName] = append(mapRaiUser[v.ChartPermissionName], item)
  219. } else {
  220. mapFiccUser[v.ChartPermissionName] = append(mapFiccUser[v.ChartPermissionName], item)
  221. }
  222. }
  223. for _, v := range listResearcher {
  224. item := new(cygx.EnterScoreRealNameListResp)
  225. item.RealName = v.RealName
  226. item.ChartPermissionName = v.ChartPermissionName
  227. if v.ProductId == utils.COMPANY_PRODUCT_RAI_ID {
  228. mapRaiUserInit[v.ChartPermissionName] = append(mapRaiUserInit[v.ChartPermissionName], item)
  229. } else {
  230. mapFiccUserInit[v.ChartPermissionName] = append(mapFiccUserInit[v.ChartPermissionName], item)
  231. }
  232. }
  233. listPermission, err := cygx.GetCygxEnterScorePermissionListById(enterScoreId)
  234. if err != nil {
  235. br.Msg = "获取失败"
  236. br.ErrMsg = "获取失败,GetCygxEnterScorePermissionListById Err: " + err.Error()
  237. return
  238. }
  239. for _, v := range listPermission {
  240. item := new(cygx.EnterScorePermissionListResp)
  241. item.ChartPermissionName = v.ChartPermissionName
  242. item.Proportion = v.Proportion
  243. if v.ProductId == utils.COMPANY_PRODUCT_RAI_ID {
  244. item.List = mapRaiUser[v.ChartPermissionName]
  245. itemslistPermission = append(itemslistPermission, item)
  246. } else {
  247. item.List = mapFiccUser[v.ChartPermissionName]
  248. itemsFicclistPermission = append(itemsFicclistPermission, item)
  249. }
  250. }
  251. for _, v := range listPermission {
  252. item := new(cygx.EnterScorePermissionListResp)
  253. item.ChartPermissionName = v.ChartPermissionName
  254. if v.ProductId == utils.COMPANY_PRODUCT_RAI_ID {
  255. item.List = mapRaiUserInit[v.ChartPermissionName]
  256. itemslistPermissionInit = append(itemslistPermissionInit, item)
  257. } else {
  258. item.List = mapFiccUserInit[v.ChartPermissionName]
  259. itemsFicclistPermissionInit = append(itemsFicclistPermissionInit, item)
  260. }
  261. }
  262. listGroup, err := cygx.GeCygxEnterScoreGroupListById(enterScoreId)
  263. if err != nil {
  264. br.Msg = "获取失败"
  265. br.ErrMsg = "获取失败,GeCygxEnterScoreGroupListById Err: " + err.Error()
  266. return
  267. }
  268. for _, v := range listGroup {
  269. item := new(cygx.EnterScoreGroupListResp)
  270. item.GroupName = v.GroupName
  271. item.Proportion = v.Proportion
  272. itemsGroup = append(itemsGroup, item)
  273. }
  274. for _, v := range listGroup {
  275. item := new(cygx.EnterScoreGroupListResp)
  276. item.GroupName = v.GroupName
  277. itemsGroupInit = append(itemsGroupInit, item)
  278. }
  279. if enterScoreDetail.EnterScoreType == 1 {
  280. resp.EnterScoreObj.ListGroup = itemsGroup
  281. resp.EnterScoreObj.ListRai = itemslistPermission
  282. resp.EnterScoreObj.ListFicc = itemsFicclistPermission
  283. resp.PercentageObj.ListGroup = itemsGroupInit
  284. resp.PercentageObj.ListRai = itemslistPermissionInit
  285. resp.PercentageObj.ListFicc = itemsFicclistPermissionInit
  286. } else {
  287. resp.PercentageObj.ListGroup = itemsGroup
  288. resp.PercentageObj.ListRai = itemslistPermission
  289. resp.PercentageObj.ListFicc = itemsFicclistPermission
  290. resp.EnterScoreObj.ListGroup = itemsGroupInit
  291. resp.EnterScoreObj.ListRai = itemslistPermissionInit
  292. resp.EnterScoreObj.ListFicc = itemsFicclistPermissionInit
  293. }
  294. }
  295. br.Ret = 200
  296. br.Success = true
  297. br.Msg = "获取成功"
  298. br.Data = resp
  299. }
  300. // @Title 更新录分
  301. // @Description 更新录分接口
  302. // @Param request body cygx.UpdateEnterScoreReq true "type json string"
  303. // @Success 200 {object} "保存成功"
  304. // @router /enterScore/update [post]
  305. func (this *EnterScoreController) EnterScoreUpdate() {
  306. br := new(models.BaseResponse).Init()
  307. defer func() {
  308. this.Data["json"] = br
  309. this.ServeJSON()
  310. }()
  311. sysUser := this.SysUser
  312. if sysUser == nil {
  313. br.Msg = "请登录"
  314. br.ErrMsg = "请登录,SysUser Is Empty"
  315. br.Ret = 408
  316. return
  317. }
  318. var req cygx.UpdateEnterScoreReq
  319. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  320. if err != nil {
  321. br.Msg = "参数解析异常!"
  322. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  323. return
  324. }
  325. enterScoreId := req.EnterScoreId
  326. companyId := req.CompanyId
  327. if companyId == 0 {
  328. br.Msg = "参数错误"
  329. br.ErrMsg = "参数错误,companyId不可为空"
  330. return
  331. }
  332. startDate := req.StartDate
  333. endDate := req.EndDate
  334. if startDate == "" || endDate == "" {
  335. br.Msg = "请选择季度信息"
  336. return
  337. }
  338. var condition string
  339. var pars []interface{}
  340. condition += " AND company_id =? AND end_date BETWEEN ? AND ? "
  341. pars = append(pars, companyId, startDate, endDate)
  342. if enterScoreId > 0 {
  343. condition += " AND enter_score_id != ? "
  344. pars = append(pars, enterScoreId)
  345. }
  346. total, err := cygx.GetCygxEnterScoreCount(condition, pars)
  347. if err != nil {
  348. br.Msg = "获取失败"
  349. br.ErrMsg = "获取失败,Err:" + err.Error()
  350. return
  351. }
  352. if total > 0 {
  353. listEnterScore, err := cygx.GetCygxEnterScoreList(condition, pars, 0, 1)
  354. if err != nil {
  355. br.Msg = "获取失败"
  356. br.ErrMsg = "获取失败,Err:" + err.Error()
  357. return
  358. }
  359. var startDateEnter, endDateEnter string
  360. for _, v := range listEnterScore {
  361. startDateEnter = v.StartDate
  362. endDateEnter = v.EndDate
  363. }
  364. quarter, err := utils.GetQuarterStrStartDatesInRangeHaveYear(startDateEnter, endDateEnter)
  365. if err != nil {
  366. br.Msg = "操作失败"
  367. br.ErrMsg = "获取已录过分的季度失败,Err:" + err.Error()
  368. return
  369. }
  370. br.Msg = quarter + "季度已录过分,请核实"
  371. return
  372. }
  373. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(companyId, utils.COMPANY_PRODUCT_RAI_ID)
  374. if err != nil {
  375. br.Msg = "查询客户产品信息失败"
  376. br.ErrMsg = "查询客户产品信息失败,Err:" + err.Error()
  377. return
  378. }
  379. item := new(cygx.CygxEnterScore)
  380. item.EnterScoreId = enterScoreId
  381. item.CompanyId = companyId
  382. item.CompanyName = req.CompanyName
  383. item.StartDate = req.StartDate
  384. item.EndDate = req.EndDate
  385. item.Quarter = strings.Join(req.Quarter, ",")
  386. quarterDate, err := utils.GetQuarterStartDatesInRange(req.StartDate, req.EndDate)
  387. if err != nil {
  388. br.Msg = "操作失败"
  389. br.ErrMsg = "获取对应季度信息失败,Err:" + err.Error()
  390. return
  391. }
  392. item.QuarterDate = strings.Join(quarterDate, ",")
  393. item.EnterScoreType = req.EnterScoreType
  394. item.Ranking = req.Ranking
  395. item.IsMergeScoring = req.IsMergeScoring
  396. item.SecuritiesFirmsName = req.SecuritiesFirmsName
  397. item.MergeProportion = req.MergeProportion
  398. item.RaiProportionTotal = req.RaiProportionTotal
  399. item.FiccProportionTotal = req.FiccProportionTotal
  400. item.ProportionTotal = req.ProportionTotal
  401. item.SellerId = companyProduct.SellerId
  402. item.SellerName = companyProduct.SellerName
  403. item.AdminId = sysUser.AdminId
  404. item.AdminName = sysUser.RealName
  405. item.CreateTime = time.Now()
  406. item.ModifyTime = time.Now()
  407. var itemsPermission []*cygx.CygxEnterScorePermission //行业数组
  408. var itemsResearcher []*cygx.CygxEnterScoreResearcher //研究员数组
  409. var itemsGroup []*cygx.CygxEnterScoreGroup //自定义分组
  410. listRai := req.ListRai
  411. listFicc := req.ListFicc
  412. listGroup := req.ListGroup
  413. for _, v := range listRai { // 权益数据
  414. itemPermission := new(cygx.CygxEnterScorePermission)
  415. itemPermission.ChartPermissionName = v.ChartPermissionName
  416. itemPermission.Proportion = v.Proportion
  417. itemPermission.EnterScoreId = v.EnterScoreId
  418. itemPermission.CompanyId = companyId
  419. itemPermission.AdminId = sysUser.AdminId
  420. itemPermission.AdminName = sysUser.RealName
  421. itemPermission.ProductId = utils.COMPANY_PRODUCT_RAI_ID
  422. itemPermission.CreateTime = time.Now()
  423. itemPermission.ModifyTime = time.Now()
  424. itemsPermission = append(itemsPermission, itemPermission)
  425. for _, vResearcher := range v.List {
  426. itemResearcher := new(cygx.CygxEnterScoreResearcher)
  427. itemResearcher.ChartPermissionName = v.ChartPermissionName
  428. itemResearcher.EnterScoreId = v.EnterScoreId
  429. itemResearcher.CompanyId = companyId
  430. itemResearcher.RealName = vResearcher.RealName
  431. itemResearcher.Proportion = vResearcher.Proportion
  432. itemResearcher.AdminId = sysUser.AdminId
  433. itemResearcher.AdminName = sysUser.RealName
  434. itemResearcher.ProductId = utils.COMPANY_PRODUCT_RAI_ID
  435. itemResearcher.CreateTime = time.Now()
  436. itemResearcher.ModifyTime = time.Now()
  437. itemsResearcher = append(itemsResearcher, itemResearcher)
  438. }
  439. }
  440. for _, v := range listFicc { // FICC数据
  441. itemPermission := new(cygx.CygxEnterScorePermission)
  442. itemPermission.ChartPermissionName = v.ChartPermissionName
  443. itemPermission.Proportion = v.Proportion
  444. itemPermission.EnterScoreId = v.EnterScoreId
  445. itemPermission.CompanyId = companyId
  446. itemPermission.AdminId = sysUser.AdminId
  447. itemPermission.AdminName = sysUser.RealName
  448. itemPermission.ProductId = utils.COMPANY_PRODUCT_FICC_ID
  449. itemPermission.CreateTime = time.Now()
  450. itemPermission.ModifyTime = time.Now()
  451. itemsPermission = append(itemsPermission, itemPermission)
  452. for _, vResearcher := range v.List {
  453. itemResearcher := new(cygx.CygxEnterScoreResearcher)
  454. itemResearcher.ChartPermissionName = v.ChartPermissionName
  455. itemResearcher.EnterScoreId = v.EnterScoreId
  456. itemResearcher.CompanyId = companyId
  457. itemResearcher.RealName = vResearcher.RealName
  458. itemResearcher.Proportion = vResearcher.Proportion
  459. itemResearcher.AdminId = sysUser.AdminId
  460. itemResearcher.AdminName = sysUser.RealName
  461. itemResearcher.ProductId = utils.COMPANY_PRODUCT_FICC_ID
  462. itemResearcher.CreateTime = time.Now()
  463. itemResearcher.ModifyTime = time.Now()
  464. itemsResearcher = append(itemsResearcher, itemResearcher)
  465. }
  466. }
  467. for _, v := range listGroup {
  468. itemGroup := new(cygx.CygxEnterScoreGroup)
  469. itemGroup.GroupName = v.GroupName
  470. itemGroup.Proportion = v.Proportion
  471. itemGroup.CompanyId = companyId
  472. itemGroup.AdminId = sysUser.AdminId
  473. itemGroup.AdminName = sysUser.RealName
  474. itemGroup.CreateTime = time.Now()
  475. itemGroup.ModifyTime = time.Now()
  476. itemsGroup = append(itemsGroup, itemGroup)
  477. }
  478. if enterScoreId == 0 { // 新增
  479. err = cygx.AddCygxEnterScore(item, itemsPermission, itemsResearcher, itemsGroup)
  480. } else { // 修改
  481. item.EnterScoreId = enterScoreId
  482. err = cygx.UpdateCygxEnterScore(item, itemsPermission, itemsResearcher, itemsGroup)
  483. }
  484. if err != nil {
  485. br.Msg = "操作失败"
  486. br.ErrMsg = "操作失败Err:" + err.Error()
  487. return
  488. }
  489. go cygxService.UpdateCygxallocationCompanyContractByEnterScore(itemsPermission, itemsResearcher, startDate, endDate, companyId, sysUser) //权益永续客户录分自动派点
  490. br.Ret = 200
  491. br.Success = true
  492. br.IsAddLog = true
  493. br.Msg = "操作成功"
  494. }
  495. // @Title 列表
  496. // @Description 列表接口
  497. // @Param PageSize query int true "每页数据条数"
  498. // @Param CurrentIndex query int true "当前页页码,从1开始"
  499. // @Param KeyWord query string true "搜索关键词"
  500. // @Param CompanyName query string true "客户名称"
  501. // @Param AdminId query string true "销售id,多个用英文逗号隔开,空字符串为全部"
  502. // @Param IsExport query bool false "是否导出excel,默认是false"
  503. // @Success 200 {object} cygx.GetCygxEnterScoreListRep
  504. // @router /enterScore/list [get]
  505. func (this *EnterScoreController) EnterScoreList() {
  506. br := new(models.BaseResponse).Init()
  507. defer func() {
  508. this.Data["json"] = br
  509. this.ServeJSON()
  510. }()
  511. sysUser := this.SysUser
  512. if sysUser == nil {
  513. br.Msg = "请登录"
  514. br.ErrMsg = "请登录,SysUser Is Empty"
  515. br.Ret = 408
  516. return
  517. }
  518. pageSize, _ := this.GetInt("PageSize")
  519. currentIndex, _ := this.GetInt("CurrentIndex")
  520. keyWord := this.GetString("KeyWord")
  521. adminId := this.GetString("AdminId")
  522. //是否导出报表
  523. isExport, _ := this.GetBool("IsExport")
  524. var startSize int
  525. if pageSize <= 0 {
  526. pageSize = utils.PageSize20
  527. }
  528. if currentIndex <= 0 {
  529. currentIndex = 1
  530. }
  531. fmt.Println(isExport)
  532. startSize = utils.StartIndex(currentIndex, pageSize)
  533. if isExport {
  534. startSize = 0
  535. pageSize = 9999
  536. }
  537. var condition string
  538. var pars []interface{}
  539. //如果不是权益管理员和admin、财务,就做可见权限限制
  540. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_RAI_ADMIN && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_RAI_RESEARCHR && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_FINANCE {
  541. var conditionAdmin string
  542. var parsAdmin []interface{}
  543. conditionAdmin = " AND product_id = 2 AND status = '永续' AND seller_id = ? "
  544. parsAdmin = append(parsAdmin, sysUser.AdminId)
  545. listProduct, err := company.GetCompanyProductList(conditionAdmin, parsAdmin)
  546. if err != nil {
  547. br.Msg = "获取失败"
  548. br.ErrMsg = "获取失败,Err:" + err.Error()
  549. return
  550. }
  551. var companyIds []int
  552. for _, v := range listProduct {
  553. companyIds = append(companyIds, v.CompanyId)
  554. }
  555. companyIds = append(companyIds, 0)
  556. condition += ` AND company_id IN (` + utils.GetOrmInReplace(len(companyIds)) + `) `
  557. pars = append(pars, companyIds)
  558. }
  559. if keyWord != "" {
  560. condition += ` AND company_name LIKE '%` + keyWord + `%' `
  561. }
  562. if adminId != "" {
  563. condition += ` AND seller_id IN (` + adminId + `) `
  564. }
  565. total, err := cygx.GetCygxEnterScoreCount(condition, pars)
  566. if err != nil {
  567. br.Msg = "获取失败"
  568. br.ErrMsg = "获取失败,Err:" + err.Error()
  569. return
  570. }
  571. condition += ` ORDER BY enter_score_id DESC `
  572. list, err := cygx.GetCygxEnterScoreList(condition, pars, startSize, pageSize)
  573. if err != nil {
  574. br.Msg = "获取失败"
  575. br.ErrMsg = "获取失败,Err:" + err.Error()
  576. return
  577. }
  578. resp := new(cygx.GetCygxEnterScoreListRep)
  579. if len(list) == 0 {
  580. resp.List = make([]*cygx.EnterScoreListResp, 0)
  581. } else {
  582. for _, v := range list {
  583. item := new(cygx.EnterScoreListResp)
  584. item.EnterScoreId = v.EnterScoreId
  585. item.CompanyId = v.CompanyId
  586. item.CompanyName = v.CompanyName
  587. item.Quarter = strings.Split(v.Quarter, ",")
  588. item.EnterScoreType = v.EnterScoreType
  589. item.Ranking = v.Ranking
  590. item.IsMergeScoring = v.IsMergeScoring
  591. item.SecuritiesFirmsName = v.SecuritiesFirmsName
  592. item.ProportionTotal = v.ProportionTotal
  593. item.EnterScoreId = v.EnterScoreId
  594. item.SellerId = v.SellerId
  595. item.SellerName = v.SellerName
  596. item.CreateTime = v.CreateTime.Format(utils.FormatDateTime)
  597. item.ModifyTime = v.ModifyTime.Format(utils.FormatDateTime)
  598. resp.List = append(resp.List, item)
  599. }
  600. }
  601. //导出excel
  602. if isExport {
  603. EnterScoreScoreListExport(this, resp, br)
  604. return
  605. }
  606. page := paging.GetPaging(currentIndex, pageSize, total)
  607. resp.Paging = page
  608. br.Ret = 200
  609. br.Success = true
  610. br.Msg = "获取成功"
  611. br.Data = resp
  612. }
  613. // EnterScoreScoreListExport 导出Excel
  614. func EnterScoreScoreListExport(this *EnterScoreController, resp *cygx.GetCygxEnterScoreListRep, br *models.BaseResponse) {
  615. dir, err := os.Executable()
  616. exPath := filepath.Dir(dir)
  617. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  618. xlsxFile := xlsx.NewFile()
  619. if err != nil {
  620. br.Msg = "生成文件失败"
  621. br.ErrMsg = "生成文件失败"
  622. return
  623. }
  624. style := xlsx.NewStyle()
  625. alignment := xlsx.Alignment{
  626. Horizontal: "center",
  627. Vertical: "center",
  628. WrapText: true,
  629. }
  630. style.Alignment = alignment
  631. style.ApplyAlignment = true
  632. sheel, err := xlsxFile.AddSheet("录分记录")
  633. if err != nil {
  634. br.Msg = "新增Sheet失败"
  635. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  636. return
  637. }
  638. sheel.SetColWidth(0, 0, 30)
  639. sheel.SetColWidth(1, 1, 15)
  640. sheel.SetColWidth(2, 2, 15)
  641. sheel.SetColWidth(3, 3, 18)
  642. titleRow := sheel.AddRow()
  643. cellA := titleRow.AddCell()
  644. cellA.SetStyle(style)
  645. cellA.SetValue("客户名称")
  646. cellB := titleRow.AddCell()
  647. cellB.SetStyle(style)
  648. cellB.SetValue("销售")
  649. cellC := titleRow.AddCell()
  650. cellC.SetStyle(style)
  651. cellC.SetValue("季度")
  652. cellD := titleRow.AddCell()
  653. cellD.SetStyle(style)
  654. cellD.SetValue("总分")
  655. cellE := titleRow.AddCell()
  656. cellE.SetStyle(style)
  657. cellE.SetValue("排名")
  658. cellF := titleRow.AddCell()
  659. cellF.SetStyle(style)
  660. cellF.SetValue("合并打分")
  661. cellG := titleRow.AddCell()
  662. cellG.SetStyle(style)
  663. cellG.SetValue("券商名称")
  664. for _, v := range resp.List {
  665. dataRow := sheel.AddRow()
  666. dataRow.SetHeight(20)
  667. cellA := dataRow.AddCell()
  668. cellA.SetStyle(style)
  669. cellA.SetValue(v.CompanyName)
  670. cellB := dataRow.AddCell()
  671. cellB.SetStyle(style)
  672. cellB.SetValue(v.SellerName)
  673. cellC := dataRow.AddCell()
  674. cellC.SetStyle(style)
  675. cellC.SetValue(strings.Join(v.Quarter, ","))
  676. cellD := dataRow.AddCell()
  677. cellD.SetStyle(style)
  678. cellD.SetValue(v.ProportionTotal)
  679. cellE := dataRow.AddCell()
  680. cellE.SetStyle(style)
  681. cellE.SetValue(v.Ranking)
  682. cellF := dataRow.AddCell()
  683. cellF.SetStyle(style)
  684. if v.IsMergeScoring == 1 {
  685. cellF.SetValue("是")
  686. } else {
  687. cellF.SetValue("否")
  688. }
  689. cellG := dataRow.AddCell()
  690. cellG.SetStyle(style)
  691. cellG.SetValue(v.SecuritiesFirmsName)
  692. }
  693. err = xlsxFile.Save(downLoadnFilePath)
  694. if err != nil {
  695. br.Msg = "保存文件失败"
  696. br.ErrMsg = "保存文件失败"
  697. return
  698. }
  699. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  700. downloadFileName := "录分记录导出数据_" + randStr + ".xlsx"
  701. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  702. defer func() {
  703. os.Remove(downLoadnFilePath)
  704. }()
  705. br.Ret = 200
  706. br.Success = true
  707. br.Msg = "导出成功"
  708. }
  709. // @Title 删除录分
  710. // @Description 删除录分接口
  711. // @Param request body cygx.UpdateEnterScoreReq true "type json string"
  712. // @Success 200 {object} "保存成功"
  713. // @router /enterScore/delete [post]
  714. func (this *EnterScoreController) EnterScoreDelete() {
  715. br := new(models.BaseResponse).Init()
  716. defer func() {
  717. this.Data["json"] = br
  718. this.ServeJSON()
  719. }()
  720. sysUser := this.SysUser
  721. if sysUser == nil {
  722. br.Msg = "请登录"
  723. br.ErrMsg = "请登录,SysUser Is Empty"
  724. br.Ret = 408
  725. return
  726. }
  727. var req cygx.EnterScoreIdReq
  728. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  729. if err != nil {
  730. br.Msg = "参数解析异常!"
  731. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  732. return
  733. }
  734. enterScoreId := req.EnterScoreId
  735. if enterScoreId == 0 {
  736. br.Msg = "参数错误!"
  737. br.ErrMsg = "参数错误,EnterScoreId 不能为0"
  738. return
  739. }
  740. err = cygx.DeleteEnterScore(enterScoreId)
  741. if err != nil {
  742. br.Msg = "删除失败"
  743. br.ErrMsg = "操作失败Err:" + err.Error()
  744. return
  745. }
  746. br.Ret = 200
  747. br.Success = true
  748. br.IsAddLog = true
  749. br.Msg = "删除成功"
  750. }
  751. // @Title 评分总览
  752. // @Description 评分总览接口
  753. // @Param KeyWord query string true "搜索关键词"
  754. // @Param City query string true "城市"
  755. // @Param StartDate query string false "开始日期"
  756. // @Param EndDate query string false "结束日期"
  757. // @Param EnterScoreType query string false "展示法方式 1:按评分录入、2:按比例录入,默认1"
  758. // @Param IsExport query bool false "是否导出excel,默认是false"
  759. // @Success Ret=200 {object} cygx.ScoreOverviewListResp
  760. // @router /enterScore/scoreOverview [get]
  761. func (this *EnterScoreController) EnterScoreScoreOverview() {
  762. br := new(models.BaseResponse).Init()
  763. defer func() {
  764. this.Data["json"] = br
  765. this.ServeJSON()
  766. }()
  767. AdminUser := this.SysUser
  768. if AdminUser == nil {
  769. br.Msg = "请登录"
  770. br.ErrMsg = "请登录,用户信息为空"
  771. br.Ret = 408
  772. return
  773. }
  774. resp := new(cygx.ScoreOverviewListResp)
  775. keyWord := this.GetString("KeyWord")
  776. city := this.GetString("City")
  777. enterScoreType, _ := this.GetInt("EnterScoreType", 1)
  778. startDate := this.GetString("StartDate")
  779. endDate := this.GetString("EndDate")
  780. //是否导出报表
  781. isExport, _ := this.GetBool("IsExport")
  782. if startDate == "" {
  783. br.Msg = "请选择对应年份与季度"
  784. return
  785. }
  786. var companyCondition string
  787. var companypars []interface{}
  788. companyCondition += ` AND b.product_name = ? `
  789. companypars = append(companypars, "权益")
  790. companyCondition += ` AND b.status = ? `
  791. companypars = append(companypars, "永续")
  792. if city != "" {
  793. //传过来多个城市的时候的筛选
  794. citySlice := strings.Split(city, ",")
  795. city = strings.Join(citySlice, "','")
  796. city = "'" + city + "'"
  797. companyCondition += ` AND a.city IN (` + city + `) `
  798. }
  799. //权益申请销售只能看到自己名下的客户的申请
  800. companyIds, err := cygxService.GetAdminLookUserCompanyIdsByResearcher(AdminUser)
  801. if err != nil {
  802. br.Msg = "获取失败"
  803. br.ErrMsg = "获取失败,GetAdminLookUserCompanyIds Err:" + err.Error()
  804. return
  805. }
  806. var newcompanyIds []int
  807. var searchcompanyIds []int
  808. //如果机构搜索做了限制 ,那么公司列表的纵向展示也做限制
  809. if keyWord != "" {
  810. listSearchCompany, err := cygx.GetCygxEnterScoreListBySecuritiesFirmsName(keyWord)
  811. if err != nil && err.Error() != utils.ErrNoRow() {
  812. br.Msg = "获取失败"
  813. br.ErrMsg = "获取失败,Err:" + err.Error()
  814. return
  815. }
  816. if len(listSearchCompany) > 0 {
  817. for _, v := range listSearchCompany {
  818. searchcompanyIds = append(searchcompanyIds, v.CompanyId)
  819. }
  820. } else {
  821. searchcompanyIds = append(searchcompanyIds, 0)
  822. }
  823. if len(companyIds) > 0 {
  824. newcompanyIds = utils.IntersectInt(searchcompanyIds, companyIds) //获取销售可见权限,与搜索权限的交集
  825. } else {
  826. newcompanyIds = searchcompanyIds
  827. }
  828. } else {
  829. newcompanyIds = companyIds
  830. }
  831. newlencompanyIds := len(newcompanyIds)
  832. if newlencompanyIds > 0 {
  833. companyCondition += ` AND a.company_id IN (` + utils.GetOrmInReplace(newlencompanyIds) + `)`
  834. companypars = append(companypars, newcompanyIds)
  835. }
  836. companyList, err := company.GetCompanyIdListByproductName(companyCondition, companypars)
  837. if err != nil {
  838. br.Msg = "获取失败"
  839. br.ErrMsg = "获取失败,Err:" + err.Error()
  840. return
  841. }
  842. var condition string
  843. var pars []interface{}
  844. if endDate != "" {
  845. condition += ` AND start_date <= ? AND end_date >= ? `
  846. pars = append(pars, startDate, endDate)
  847. }
  848. //if enterScoreType == 2 {
  849. //condition += ` AND enter_score_type = 2 `
  850. //}
  851. if keyWord != "" {
  852. condition += ` AND securities_firms_name LIKE '%` + keyWord + `%' `
  853. }
  854. if newlencompanyIds > 0 {
  855. condition += ` AND company_id IN (` + utils.GetOrmInReplace(newlencompanyIds) + `)`
  856. pars = append(pars, newcompanyIds)
  857. }
  858. total, err := cygx.GetCygxEnterScoreCount(condition, pars)
  859. if err != nil {
  860. br.Msg = "获取失败"
  861. br.ErrMsg = "获取失败,Err:" + err.Error()
  862. return
  863. }
  864. if total > 0 {
  865. list, err := cygx.GetCygxEnterScoreList(condition, pars, 0, 100)
  866. if err != nil {
  867. br.Msg = "获取失败"
  868. br.ErrMsg = "获取失败,GetCygxEnterScoreListErr:" + err.Error()
  869. return
  870. }
  871. mapenterScoreTypeCompanyIds := make(map[int]bool)
  872. mapenterScoreProportionTotal := make(map[int]float64)
  873. var enterScoreIds []int
  874. mapenterScore := make(map[int]*cygx.CygxEnterScore) //录分详情放在map中
  875. for _, v := range list {
  876. mapenterScore[v.CompanyId] = v
  877. mapenterScoreProportionTotal[v.CompanyId] = v.ProportionTotal
  878. enterScoreIds = append(enterScoreIds, v.EnterScoreId)
  879. if v.EnterScoreType == 2 {
  880. mapenterScoreTypeCompanyIds[v.CompanyId] = true //记录按照百分比录入的公司
  881. }
  882. }
  883. //fmt.Println(enterScoreIds)
  884. listResearcher, err := cygx.GeCygxEnterScoreResearcherListByIds(enterScoreIds, newcompanyIds) //获取所有的研究员
  885. if err != nil {
  886. br.Msg = "获取失败"
  887. br.ErrMsg = "获取失败,GetCygxEnterScorePermissionListByIds Err:" + err.Error()
  888. return
  889. }
  890. mapResearcher := make(map[string][]*cygx.EnterScoreRealNameListResp)
  891. mapResearcherProportion := make(map[string]string)
  892. //mapResearcherPermission := make(map[string][]map[string]string)
  893. var researcherArr []string // 会出现的研究员姓名
  894. mapResearcherbool := make(map[string]bool)
  895. for _, v := range listResearcher {
  896. if v.Proportion == 0 {
  897. continue
  898. }
  899. if !mapResearcherbool[v.RealName] {
  900. researcherArr = append(researcherArr, v.RealName)
  901. mapResearcherbool[v.RealName] = true
  902. }
  903. if enterScoreType == 2 && !mapenterScoreTypeCompanyIds[v.CompanyId] {
  904. mapResearcherProportion[fmt.Sprint(v.RealName, "_", v.CompanyId)] = utils.SubFloatToString(v.Proportion/mapenterScoreProportionTotal[v.CompanyId]*100, 2) //研究员姓名、公司ID,占比值对应关系绑定
  905. } else {
  906. mapResearcherProportion[fmt.Sprint(v.RealName, "_", v.CompanyId)] = fmt.Sprint(v.Proportion) //研究员姓名、公司ID,占比值对应关系绑定
  907. }
  908. }
  909. mapResearcherProportionText := make(map[string][]string)
  910. for _, vC := range companyList {
  911. for _, vR := range researcherArr {
  912. var proportionText string
  913. if mapResearcherProportion[fmt.Sprint(vR, "_", vC.CompanyId)] != "" {
  914. proportionText = mapResearcherProportion[fmt.Sprint(vR, "_", vC.CompanyId)]
  915. } else {
  916. if mapenterScoreProportionTotal[vC.CompanyId] > 0 {
  917. proportionText = "0"
  918. } else {
  919. proportionText = ""
  920. }
  921. }
  922. //0与空的展示逻辑处理
  923. if mapenterScoreTypeCompanyIds[vC.CompanyId] || enterScoreType == 2 { //按照百分比展示的拼接 %
  924. if proportionText != "" {
  925. proportionText += "%"
  926. }
  927. }
  928. mapResearcherProportionText[vR] = append(mapResearcherProportionText[vR], proportionText)
  929. }
  930. }
  931. researcherArr = make([]string, 0)
  932. for _, v := range listResearcher {
  933. if v.Proportion == 0 {
  934. continue
  935. }
  936. if utils.InArrayByStr(researcherArr, v.RealName) { //避免重复合并到数组
  937. continue
  938. }
  939. item := new(cygx.EnterScoreRealNameListResp) // 研究员结构体数据
  940. item.RealName = v.RealName
  941. item.ChartPermissionName = v.ChartPermissionName
  942. item.ProportionListText = mapResearcherProportionText[v.RealName]
  943. mapResearcher[v.ChartPermissionName] = append(mapResearcher[v.ChartPermissionName], item)
  944. researcherArr = append(researcherArr, v.RealName)
  945. }
  946. listPermission, err := cygx.GetCygxEnterScorePermissionListByIds(enterScoreIds) // 获取所有的行业名称
  947. if err != nil {
  948. br.Msg = "获取失败"
  949. br.ErrMsg = "获取失败,GetCygxEnterScorePermissionListByIds Err:" + err.Error()
  950. return
  951. }
  952. mapPermissionProportion := make(map[string]string)
  953. for _, v := range listPermission {
  954. if v.Proportion == 0 {
  955. continue
  956. }
  957. //mapPermissionProportion[fmt.Sprint(v.ChartPermissionName, "_", v.CompanyId)] = fmt.Sprint(v.Proportion) //行业名称、公司ID,占比值对应关系绑定
  958. if enterScoreType == 2 && !mapenterScoreTypeCompanyIds[v.CompanyId] {
  959. mapPermissionProportion[fmt.Sprint(v.ChartPermissionName, "_", v.CompanyId)] = utils.SubFloatToString(v.Proportion/mapenterScoreProportionTotal[v.CompanyId]*100, 2) //研究员姓名、公司ID,占比值对应关系绑定
  960. } else {
  961. mapPermissionProportion[fmt.Sprint(v.ChartPermissionName, "_", v.CompanyId)] = fmt.Sprint(v.Proportion) //行业名称、公司ID,占比值对应关系绑定
  962. }
  963. }
  964. var permissionArr []string // 会出现的行业名称
  965. mapPermissionbool := make(map[string]bool)
  966. for _, v := range listPermission {
  967. if mapPermissionbool[v.ChartPermissionName] {
  968. continue
  969. }
  970. permissionArr = append(permissionArr, v.ChartPermissionName)
  971. mapPermissionbool[v.ChartPermissionName] = true
  972. }
  973. mapPermissionProportionText := make(map[string][]string)
  974. for _, vC := range companyList {
  975. for _, vP := range permissionArr {
  976. var proportionText string
  977. if mapPermissionProportion[fmt.Sprint(vP, "_", vC.CompanyId)] != "" {
  978. proportionText = mapPermissionProportion[fmt.Sprint(vP, "_", vC.CompanyId)]
  979. } else {
  980. if mapenterScoreProportionTotal[vC.CompanyId] > 0 {
  981. proportionText = "0"
  982. } else {
  983. proportionText = ""
  984. }
  985. }
  986. if mapenterScoreTypeCompanyIds[vC.CompanyId] || enterScoreType == 2 { //按照百分比展示的拼接 %
  987. if proportionText != "" {
  988. proportionText += "%"
  989. }
  990. }
  991. mapPermissionProportionText[vP] = append(mapPermissionProportionText[vP], proportionText)
  992. }
  993. }
  994. var itemsP []*cygx.EnterScorePermissionListResp
  995. for _, v := range permissionArr {
  996. itemP := new(cygx.EnterScorePermissionListResp) //行业结构体
  997. itemP.ChartPermissionName = v
  998. itemP.ProportionListText = mapPermissionProportionText[v]
  999. itemP.List = mapResearcher[v]
  1000. itemsP = append(itemsP, itemP)
  1001. }
  1002. listGroup, err := cygx.GeCygxEnterScoreGroupListByIds(enterScoreIds) // 获取所有自定义分组名称
  1003. if err != nil {
  1004. br.Msg = "获取失败"
  1005. br.ErrMsg = "获取失败,GeCygxEnterScoreGroupListByIds Err:" + err.Error()
  1006. return
  1007. }
  1008. mapGroupProportion := make(map[string]string)
  1009. var groupArr []string // 会出现的自定义分组名称
  1010. mapGroupbool := make(map[string]bool)
  1011. for _, v := range listGroup {
  1012. if enterScoreType == 2 && !mapenterScoreTypeCompanyIds[v.CompanyId] {
  1013. mapGroupProportion[fmt.Sprint(v.GroupName, "_", v.CompanyId)] = utils.SubFloatToString(v.Proportion/mapenterScoreProportionTotal[v.CompanyId]*100, 2) //自定义分组名称、公司ID,占比值对应关系绑定
  1014. } else {
  1015. mapGroupProportion[fmt.Sprint(v.GroupName, "_", v.CompanyId)] = fmt.Sprint(v.Proportion) //自定义分组名称、公司ID,占比值对应关系绑定
  1016. }
  1017. //mapGroupProportion[fmt.Sprint(v.GroupName, "_", v.CompanyId)] = fmt.Sprint(v.Proportion) //自定义分组名称、公司ID,占比值对应关系绑定
  1018. if mapGroupbool[v.GroupName] {
  1019. continue
  1020. }
  1021. groupArr = append(groupArr, v.GroupName)
  1022. mapGroupbool[v.GroupName] = true
  1023. }
  1024. mapGroupProportionText := make(map[string][]string)
  1025. for _, vC := range companyList {
  1026. for _, vP := range groupArr {
  1027. var proportionText string
  1028. if mapGroupProportion[fmt.Sprint(vP, "_", vC.CompanyId)] != "" {
  1029. proportionText = mapGroupProportion[fmt.Sprint(vP, "_", vC.CompanyId)]
  1030. } else {
  1031. if mapenterScoreProportionTotal[vC.CompanyId] > 0 {
  1032. proportionText = "0"
  1033. } else {
  1034. proportionText = ""
  1035. }
  1036. }
  1037. if mapenterScoreTypeCompanyIds[vC.CompanyId] || enterScoreType == 2 { //按照百分比展示的拼接 %
  1038. if proportionText != "" {
  1039. proportionText += "%"
  1040. }
  1041. }
  1042. mapGroupProportionText[vP] = append(mapGroupProportionText[vP], proportionText)
  1043. }
  1044. }
  1045. var itemsG []*cygx.EnterScoreGroupListResp
  1046. for _, v := range groupArr {
  1047. itemG := new(cygx.EnterScoreGroupListResp) //行业结构体
  1048. itemG.GroupName = v
  1049. itemG.ProportionListText = mapGroupProportionText[v]
  1050. itemsG = append(itemsG, itemG)
  1051. }
  1052. var proportionTotalText []string //总计
  1053. var rankingText []string //排名
  1054. var securitiesFirmsNameText []string //券商名称
  1055. var mergeProportionTotalText []string //占比
  1056. for _, vC := range companyList {
  1057. var ranking, securitiesFirmsName, proportionTotal, mergeProportionTotal string
  1058. item := mapenterScore[vC.CompanyId]
  1059. if item != nil {
  1060. ranking = item.Ranking
  1061. securitiesFirmsName = item.SecuritiesFirmsName
  1062. proportionTotal = fmt.Sprint(item.ProportionTotal)
  1063. mergeProportionTotal = fmt.Sprint(item.MergeProportion)
  1064. }
  1065. //if mapenterScoreTypeCompanyIds[vC.CompanyId] { //按照百分比展示的拼接 %
  1066. if mapenterScoreProportionTotal[vC.CompanyId] > 0 {
  1067. mergeProportionTotal += "%"
  1068. }
  1069. rankingText = append(rankingText, ranking)
  1070. securitiesFirmsNameText = append(securitiesFirmsNameText, securitiesFirmsName)
  1071. proportionTotalText = append(proportionTotalText, proportionTotal)
  1072. mergeProportionTotalText = append(mergeProportionTotalText, mergeProportionTotal)
  1073. }
  1074. itemproportionTotal := new(cygx.EnterScoreGroupListResp) //券商名称结构体
  1075. itemproportionTotal.GroupName = "合计"
  1076. itemproportionTotal.ProportionListText = proportionTotalText
  1077. itemsG = append(itemsG, itemproportionTotal)
  1078. itemranking := new(cygx.EnterScoreGroupListResp) //排名结构体
  1079. itemranking.GroupName = "排名"
  1080. itemranking.ProportionListText = rankingText
  1081. itemsG = append(itemsG, itemranking)
  1082. itemsecuritiesFirmsName := new(cygx.EnterScoreGroupListResp) //券商名称结构体
  1083. itemsecuritiesFirmsName.GroupName = "券商名称"
  1084. itemsecuritiesFirmsName.ProportionListText = securitiesFirmsNameText
  1085. itemsG = append(itemsG, itemsecuritiesFirmsName)
  1086. itemmergeProportionTotal := new(cygx.EnterScoreGroupListResp) //券商名称结构体
  1087. itemmergeProportionTotal.GroupName = "占比"
  1088. itemmergeProportionTotal.ProportionListText = mergeProportionTotalText
  1089. itemsG = append(itemsG, itemmergeProportionTotal)
  1090. resp.ListPermission = itemsP
  1091. resp.ListGroup = itemsG
  1092. } else {
  1093. listPermission, err := cygx.GetChartPermissionAll()
  1094. if err != nil {
  1095. br.Msg = "获取信息失败"
  1096. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  1097. return
  1098. }
  1099. permissionNameArr := []string{"医药", "消费", "科技", "智造", "策略", "固收", "宏观组", "建材组", "有色组", "能化组"}
  1100. for _, v := range listPermission {
  1101. if !utils.InArrayByStr(permissionNameArr, v.PermissionName) {
  1102. continue
  1103. }
  1104. item := new(cygx.EnterScorePermissionListResp)
  1105. item.ChartPermissionName = v.PermissionName
  1106. item.ProportionListText = make([]string, len(companyList))
  1107. item.List = make([]*cygx.EnterScoreRealNameListResp, 0)
  1108. resp.ListPermission = append(resp.ListPermission, item)
  1109. }
  1110. groupNameArr := []string{"销售分", "专题分", "专家分", "云图大拓", "艾摩宏观", "合计", "排名", "券商名称", "占比"}
  1111. for _, v := range groupNameArr {
  1112. item := new(cygx.EnterScoreGroupListResp)
  1113. item.GroupName = v
  1114. item.ProportionListText = make([]string, len(companyList))
  1115. resp.ListGroup = append(resp.ListGroup, item)
  1116. }
  1117. //resp.ListPermission = make([]*cygx.EnterScorePermissionListResp, 0)
  1118. //resp.ListGroup = make([]*cygx.EnterScoreGroupListResp, 0)
  1119. }
  1120. if len(companyList) == 0 {
  1121. resp.ListCompany = make([]*company.CompanyNameAndId, 0)
  1122. } else {
  1123. resp.ListCompany = companyList
  1124. }
  1125. //导出excel
  1126. if isExport {
  1127. EnterScoreScoreOverviewExport(this, resp, br)
  1128. return
  1129. }
  1130. br.Ret = 200
  1131. br.Success = true
  1132. br.Msg = "获取成功"
  1133. br.Data = resp
  1134. }
  1135. // EnterScoreScoreOverviewExport 导出Excel
  1136. func EnterScoreScoreOverviewExport(this *EnterScoreController, resp *cygx.ScoreOverviewListResp, br *models.BaseResponse) {
  1137. dir, err := os.Executable()
  1138. exPath := filepath.Dir(dir)
  1139. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  1140. xlsxFile := xlsx.NewFile()
  1141. if err != nil {
  1142. br.Msg = "生成文件失败"
  1143. br.ErrMsg = "生成文件失败"
  1144. return
  1145. }
  1146. style := xlsx.NewStyle()
  1147. alignment := xlsx.Alignment{
  1148. Horizontal: "center",
  1149. Vertical: "center",
  1150. WrapText: true,
  1151. }
  1152. style.Alignment = alignment
  1153. style.ApplyAlignment = true
  1154. sheel, err := xlsxFile.AddSheet("评分总览")
  1155. if err != nil {
  1156. br.Msg = "新增Sheet失败"
  1157. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  1158. return
  1159. }
  1160. sheel.SetColWidth(0, 0, 30)
  1161. sheel.SetColWidth(1, 1, 15)
  1162. sheel.SetColWidth(2, 2, 15)
  1163. sheel.SetColWidth(3, 3, 18)
  1164. companyList := resp.ListCompany
  1165. listPermission := resp.ListPermission
  1166. listGroup := resp.ListGroup
  1167. titleRow := sheel.AddRow()
  1168. cellNull := titleRow.AddCell()
  1169. cellNull.SetStyle(style)
  1170. cellNull.SetValue("")
  1171. for _, v := range companyList { //第一行公司
  1172. cellA := titleRow.AddCell()
  1173. cellA.SetStyle(style)
  1174. cellA.SetValue(v.CompanyName)
  1175. }
  1176. for _, v := range listPermission { // 行业排序名称
  1177. dataRow := sheel.AddRow()
  1178. dataRow.SetHeight(20)
  1179. cellA := dataRow.AddCell()
  1180. cellA.SetStyle(style)
  1181. cellA.SetValue(v.ChartPermissionName)
  1182. for _, vCp := range v.ProportionListText { // 行业对应的占比值
  1183. cellP := dataRow.AddCell()
  1184. cellP.SetStyle(style)
  1185. cellP.SetValue(vCp)
  1186. }
  1187. for _, vUser := range v.List { // 研究员姓名
  1188. dataRowName := sheel.AddRow()
  1189. dataRowName.SetHeight(20)
  1190. cellName := dataRowName.AddCell()
  1191. cellName.SetStyle(style)
  1192. cellName.SetValue(vUser.RealName)
  1193. for _, vUp := range vUser.ProportionListText { //研究员占比值
  1194. cellP := dataRowName.AddCell()
  1195. cellP.SetStyle(style)
  1196. cellP.SetValue(vUp)
  1197. }
  1198. }
  1199. }
  1200. for _, v := range listGroup { // 自定义名称
  1201. dataRow := sheel.AddRow()
  1202. dataRow.SetHeight(20)
  1203. cellA := dataRow.AddCell()
  1204. cellA.SetStyle(style)
  1205. cellA.SetValue(v.GroupName)
  1206. for _, vG := range v.ProportionListText { // 自定义名称所对应的值
  1207. cellP := dataRow.AddCell()
  1208. cellP.SetStyle(style)
  1209. cellP.SetValue(vG)
  1210. }
  1211. }
  1212. err = xlsxFile.Save(downLoadnFilePath)
  1213. if err != nil {
  1214. br.Msg = "保存文件失败"
  1215. br.ErrMsg = "保存文件失败"
  1216. return
  1217. }
  1218. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  1219. downloadFileName := "评分总览" + randStr + ".xlsx"
  1220. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  1221. defer func() {
  1222. os.Remove(downLoadnFilePath)
  1223. }()
  1224. br.Ret = 200
  1225. br.Success = true
  1226. br.Msg = "导出成功"
  1227. }
  1228. // @Title 排名总览
  1229. // @Description 排名总览接口
  1230. // @Param AdminId query string true "销售id,多个用英文逗号隔开,空字符串为全部"
  1231. // @Param City query string true "城市"
  1232. // @Param IsExport query bool false "是否导出excel,默认是false"
  1233. // @Success Ret=200 {object} cygx.CompanyNameAndIdListResp
  1234. // @router /enterScore/rankingOverview [get]
  1235. func (this *EnterScoreController) EnterScoreRankingOverview() {
  1236. br := new(models.BaseResponse).Init()
  1237. defer func() {
  1238. this.Data["json"] = br
  1239. this.ServeJSON()
  1240. }()
  1241. AdminUser := this.SysUser
  1242. if AdminUser == nil {
  1243. br.Msg = "请登录"
  1244. br.ErrMsg = "请登录,用户信息为空"
  1245. br.Ret = 408
  1246. return
  1247. }
  1248. resp := new(cygx.RankingOverviewListResp)
  1249. city := this.GetString("City")
  1250. adminId := this.GetString("AdminId")
  1251. //是否导出报表
  1252. isExport, _ := this.GetBool("IsExport")
  1253. var companyCondition string
  1254. var companypars []interface{}
  1255. companyCondition += ` AND b.product_name = ? `
  1256. companypars = append(companypars, "权益")
  1257. companyCondition += ` AND b.status = ? `
  1258. companypars = append(companypars, "永续")
  1259. if adminId != "" {
  1260. companyCondition += ` AND b.seller_id IN (` + adminId + `) `
  1261. }
  1262. if city != "" {
  1263. //传过来多个城市的时候的筛选
  1264. citySlice := strings.Split(city, ",")
  1265. city = strings.Join(citySlice, "','")
  1266. city = "'" + city + "'"
  1267. companyCondition += ` AND a.city IN (` + city + `) `
  1268. }
  1269. //权益申请销售只能看到自己名下的客户的申请
  1270. companyIds, err := cygxService.GetAdminLookUserCompanyIdsByResearcher(AdminUser)
  1271. if err != nil {
  1272. br.Msg = "获取失败"
  1273. br.ErrMsg = "获取失败,GetAdminLookUserCompanyIdsBySelf Err:" + err.Error()
  1274. return
  1275. }
  1276. lencompanyIds := len(companyIds)
  1277. if lencompanyIds > 0 {
  1278. companyCondition += ` AND a.company_id IN (` + utils.GetOrmInReplace(lencompanyIds) + `)`
  1279. companypars = append(companypars, companyIds)
  1280. }
  1281. companyList, err := company.GetCompanyIdListByproductName(companyCondition, companypars)
  1282. if err != nil {
  1283. br.Msg = "获取失败"
  1284. br.ErrMsg = "获取失败,Err:" + err.Error()
  1285. return
  1286. }
  1287. var condition string
  1288. var pars []interface{}
  1289. total, err := cygx.GetCygxEnterScoreCount(condition, pars)
  1290. if err != nil {
  1291. br.Msg = "获取失败"
  1292. br.ErrMsg = "获取失败,Err:" + err.Error()
  1293. return
  1294. }
  1295. dataMd := []string{"10-01", "07-01", "04-01", "01-01"}
  1296. thisYear := time.Now().Year()
  1297. startYear := 2018 // 自定义开始时间
  1298. var quarterDate []string
  1299. for _, v := range dataMd {
  1300. dateTimeStr := fmt.Sprint(thisYear, "-", v)
  1301. dateTime, err := time.Parse("2006-01-02", dateTimeStr)
  1302. if err != nil {
  1303. br.Msg = "获取失败"
  1304. br.ErrMsg = "获取失败,Err:" + err.Error()
  1305. return
  1306. }
  1307. if dateTime.After(time.Now()) {
  1308. continue
  1309. }
  1310. quarterDate = append(quarterDate, dateTimeStr)
  1311. }
  1312. for i := thisYear - 1; i >= startYear; i-- {
  1313. for _, v := range dataMd {
  1314. dateTimeStr := fmt.Sprint(i, "-", v)
  1315. quarterDate = append(quarterDate, dateTimeStr)
  1316. }
  1317. }
  1318. var itemsQuarter []*cygx.QuarterDateListResp
  1319. if total > 0 {
  1320. list, err := cygx.GetCygxEnterScoreList(condition, pars, 0, 9999)
  1321. if err != nil {
  1322. br.Msg = "获取失败"
  1323. br.ErrMsg = "获取失败,GetCygxEnterScoreList Err:" + err.Error()
  1324. return
  1325. }
  1326. mapQuarter := make(map[string]string)
  1327. for _, v := range list {
  1328. silicequarter := strings.Split(v.QuarterDate, ",")
  1329. for _, vQ := range silicequarter {
  1330. mapQuarter[fmt.Sprint(vQ, "_", v.CompanyId)] = v.Ranking //季度时间、公司ID,排名对应关系绑定
  1331. }
  1332. }
  1333. mapRankingText := make(map[string][]string)
  1334. for _, vC := range companyList {
  1335. for _, vQ := range quarterDate {
  1336. var ranking string
  1337. ranking = mapQuarter[fmt.Sprint(vQ, "_", vC.CompanyId)]
  1338. mapRankingText[vQ] = append(mapRankingText[vQ], ranking)
  1339. }
  1340. }
  1341. for _, v := range quarterDate {
  1342. itemQuarter := new(cygx.QuarterDateListResp)
  1343. quarter := v
  1344. //时间后面的月日替换成季度 Q几
  1345. quarter = strings.Replace(quarter, "-10-01", "Q4", -1)
  1346. quarter = strings.Replace(quarter, "-07-01", "Q3", -1)
  1347. quarter = strings.Replace(quarter, "-04-01", "Q2", -1)
  1348. quarter = strings.Replace(quarter, "-01-01", "Q1", -1)
  1349. itemQuarter.Quarter = quarter
  1350. itemQuarter.ProportionListText = mapRankingText[v]
  1351. itemsQuarter = append(itemsQuarter, itemQuarter)
  1352. }
  1353. } else {
  1354. for _, v := range quarterDate {
  1355. itemQuarter := new(cygx.QuarterDateListResp)
  1356. quarter := v
  1357. //时间后面的月日替换成季度 Q几
  1358. quarter = strings.Replace(quarter, "-10-01", "Q4", -1)
  1359. quarter = strings.Replace(quarter, "-07-01", "Q3", -1)
  1360. quarter = strings.Replace(quarter, "-04-01", "Q2", -1)
  1361. quarter = strings.Replace(quarter, "-01-01", "Q1", -1)
  1362. itemQuarter.Quarter = quarter
  1363. itemQuarter.ProportionListText = make([]string, len(companyList))
  1364. itemsQuarter = append(itemsQuarter, itemQuarter)
  1365. }
  1366. }
  1367. resp.ListCompany = companyList
  1368. resp.ListQuarterDate = itemsQuarter
  1369. //导出excel
  1370. if isExport {
  1371. RankingOverviewExport(this, resp, br)
  1372. return
  1373. }
  1374. br.Ret = 200
  1375. br.Success = true
  1376. br.Msg = "获取成功"
  1377. br.Data = resp
  1378. }
  1379. // RankingOverviewExport 导出Excel
  1380. func RankingOverviewExport(this *EnterScoreController, resp *cygx.RankingOverviewListResp, br *models.BaseResponse) {
  1381. dir, err := os.Executable()
  1382. exPath := filepath.Dir(dir)
  1383. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  1384. xlsxFile := xlsx.NewFile()
  1385. if err != nil {
  1386. br.Msg = "生成文件失败"
  1387. br.ErrMsg = "生成文件失败"
  1388. return
  1389. }
  1390. style := xlsx.NewStyle()
  1391. alignment := xlsx.Alignment{
  1392. Horizontal: "center",
  1393. Vertical: "center",
  1394. WrapText: true,
  1395. }
  1396. style.Alignment = alignment
  1397. style.ApplyAlignment = true
  1398. sheel, err := xlsxFile.AddSheet("排名总览")
  1399. if err != nil {
  1400. br.Msg = "新增Sheet失败"
  1401. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  1402. return
  1403. }
  1404. sheel.SetColWidth(0, 0, 30)
  1405. sheel.SetColWidth(1, 1, 15)
  1406. sheel.SetColWidth(2, 2, 15)
  1407. sheel.SetColWidth(3, 3, 18)
  1408. companyList := resp.ListCompany
  1409. listQuarterDate := resp.ListQuarterDate
  1410. titleRow := sheel.AddRow()
  1411. cellNull := titleRow.AddCell()
  1412. cellNull.SetStyle(style)
  1413. cellNull.SetValue("")
  1414. for _, v := range companyList { //第一行公司
  1415. cellA := titleRow.AddCell()
  1416. cellA.SetStyle(style)
  1417. cellA.SetValue(v.CompanyName)
  1418. }
  1419. for _, v := range listQuarterDate { // 季度排序
  1420. dataRow := sheel.AddRow()
  1421. dataRow.SetHeight(20)
  1422. cellA := dataRow.AddCell()
  1423. cellA.SetStyle(style)
  1424. cellA.SetValue(v.Quarter)
  1425. for _, vCp := range v.ProportionListText { // 行业对应的占比值
  1426. cellP := dataRow.AddCell()
  1427. cellP.SetStyle(style)
  1428. cellP.SetValue(vCp)
  1429. }
  1430. }
  1431. err = xlsxFile.Save(downLoadnFilePath)
  1432. if err != nil {
  1433. br.Msg = "保存文件失败"
  1434. br.ErrMsg = "保存文件失败"
  1435. return
  1436. }
  1437. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  1438. downloadFileName := "排名总览" + randStr + ".xlsx"
  1439. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  1440. defer func() {
  1441. os.Remove(downLoadnFilePath)
  1442. }()
  1443. br.Ret = 200
  1444. br.Success = true
  1445. br.Msg = "导出成功"
  1446. }