enter_score.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. package cygx
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hz_crm_api/models/company"
  6. "hongze/hz_crm_api/utils"
  7. "time"
  8. )
  9. // CygxEnterScore 结构体代表了 cygx_enter_score 表格
  10. type CygxEnterScore struct {
  11. EnterScoreId int `orm:"column(enter_score_id);pk";comment:"主键"`
  12. CompanyId int `comment:"公司ID"`
  13. CompanyName string `comment:"客户名称"`
  14. StartDate string `comment:"开始日期"`
  15. EndDate string `comment:"结束日期"`
  16. Quarter string `comment:"季度"`
  17. QuarterDate string `comment:"季度带有年月日的多个数组转成的字符串"`
  18. EnterScoreType int `comment:"录入方式 1:按评分录入、2:按比例录入"`
  19. Ranking string `comment:"排名"`
  20. IsMergeScoring int `comment:"是否合并打分"`
  21. SecuritiesFirmsName string `comment:"券商名称"`
  22. MergeProportion float64 `comment:"合并占比"`
  23. RaiProportionTotal float64 `comment:"权益研究员占比"`
  24. FiccProportionTotal float64 `comment:"FICC研究员占比"`
  25. ProportionTotal float64 `comment:"合计总占比"`
  26. SellerId int `comment:"所属销售id"`
  27. SellerName string `comment:"所属销售名称"`
  28. AdminId int `comment:"操作人ID"`
  29. AdminName string `comment:"操作人姓名"`
  30. CreateTime time.Time `comment:"创建时间"`
  31. ModifyTime time.Time `comment:"更新时间"`
  32. }
  33. type CygxEnterScoreDetailResp struct {
  34. EnterScoreId int `comment:"录分ID"`
  35. CompanyId int `comment:"公司ID,公司标识符"`
  36. CompanyName string `comment:"公司名称"`
  37. StartDate string `comment:"开始日期"`
  38. EndDate string `comment:"结束日期"`
  39. Quarter []string `comment:"季度,评分季度"`
  40. EnterScoreType int `comment:"录入方式 1:按评分录入、2:按比例录入"`
  41. Ranking string `comment:"排名"`
  42. IsMergeScoring int `comment:"是否合并打分"`
  43. SecuritiesFirmsName string `comment:"券商名称"`
  44. MergeProportion float64 `comment:"合并占比"`
  45. ProportionTotal float64 `comment:"合计总占比"`
  46. RaiProportionTotal float64 `comment:"权益研究员占比"`
  47. FiccProportionTotal float64 `comment:"FICC研究员占比"`
  48. EnterScoreObj EnterScoreDateObj `comment:"按评分录入"`
  49. PercentageObj EnterScoreDateObj `comment:"按比例录入"`
  50. }
  51. // 行业
  52. type EnterScoreDateObj struct {
  53. ListRai []*EnterScorePermissionListResp //权益列表
  54. ListFicc []*EnterScorePermissionListResp //FICC列表
  55. ListGroup []*EnterScoreGroupListResp //其他配置信息
  56. }
  57. // 行业
  58. type EnterScorePermissionListResp struct {
  59. ChartPermissionName string `description:"行业名称"`
  60. Proportion float64 `description:"占比"`
  61. ProportionListText []string `description:"占比列表"`
  62. EnterScoreId int `comment:"录分ID"`
  63. List []*EnterScoreRealNameListResp
  64. }
  65. // 占比描述
  66. type EnterScoreProportionTextResp struct {
  67. ProportionText string
  68. }
  69. // 研究员
  70. type EnterScoreRealNameListResp struct {
  71. RealName string `comment:"研究员姓名"`
  72. Proportion float64 `comment:"占比"`
  73. ProportionListText []string `description:"占比列表"`
  74. ChartPermissionName string `comment:"行业名称"`
  75. }
  76. // 其他分组
  77. type EnterScoreGroupListResp struct {
  78. GroupName string `description:"组名"`
  79. Proportion float64 `description:"占比"`
  80. ProportionListText []string `description:"占比列表"`
  81. }
  82. // 添加或修改录分时的入参结构体
  83. type UpdateEnterScoreReq struct {
  84. EnterScoreId int `comment:"录分ID"`
  85. CompanyId int `comment:"公司ID"`
  86. CompanyName string `comment:"客户名称"`
  87. StartDate string `comment:"开始日期"`
  88. EndDate string `comment:"结束日期"`
  89. Quarter []string `comment:"季度"`
  90. EnterScoreType int `comment:"录入方式 1:按评分录入、2:按比例录入"`
  91. Ranking string `comment:"排名"`
  92. IsMergeScoring int `comment:"是否合并打分"`
  93. SecuritiesFirmsName string `comment:"券商名称"`
  94. MergeProportion float64 `comment:"合并占比"`
  95. RaiProportionTotal float64 `comment:"权益研究员占比"`
  96. FiccProportionTotal float64 `comment:"FICC研究员占比"`
  97. ProportionTotal float64 `comment:"合计总占比"`
  98. ListRai []*EnterScorePermissionListResp //权益列表
  99. ListFicc []*EnterScorePermissionListResp //FICC列表
  100. ListGroup []*EnterScoreGroupListResp //其他配置信息
  101. }
  102. type EnterScoreIdReq struct {
  103. EnterScoreId int `comment:"录分ID"`
  104. }
  105. // CygxEnterScoreGroup 结构体代表 cygx_enter_score_group 表
  106. type CygxEnterScoreGroup struct {
  107. EnterScoreGroupId int `orm:"column(enter_score_group_id);pk";comment:"主键"`
  108. EnterScoreId int `comment:"cygx_enter_score主键"`
  109. CompanyId int `comment:"公司ID"`
  110. GroupName string `comment:"名称"`
  111. Proportion float64 `comment:"占比"`
  112. AdminId int `comment:"操作人ID"`
  113. AdminName string `comment:"操作人姓名"`
  114. CreateTime time.Time `comment:"创建时间"`
  115. ModifyTime time.Time `comment:"更新时间"`
  116. }
  117. // CygxEnterScorePermission 结构体代表 cygx_enter_score_permission 表
  118. type CygxEnterScorePermission struct {
  119. EnterScorePermissionId int `orm:"column(enter_score_permission_id);pk";comment:"主键"`
  120. EnterScoreId int `comment:"cygx_enter_score主键"`
  121. CompanyId int `comment:"公司ID"`
  122. ChartPermissionName string `comment:"名称"`
  123. Proportion float64 `comment:"占比"`
  124. ProductId float64 `comment:"产品id,1:FICC、2:权益"`
  125. AdminId int `comment:"操作人ID"`
  126. AdminName string `comment:"操作人姓名"`
  127. CreateTime time.Time `comment:"创建时间"`
  128. ModifyTime time.Time `comment:"更新时间"`
  129. }
  130. // CygxEnterScoreResearcher 结构体代表 cygx_enter_score_researcher 表
  131. type CygxEnterScoreResearcher struct {
  132. EnterScoreDataId int `orm:"column(enter_score_data_id);pk";comment:"主键"`
  133. EnterScoreId int `comment:"cygx_enter_score主键"`
  134. CompanyId int `comment:"公司ID"`
  135. Proportion float64 `comment:"占比"`
  136. RealName string `comment:"研究员姓名"`
  137. ChartPermissionName string `comment:"名称"`
  138. ProductId float64 `comment:"产品id,1:FICC、2:权益"`
  139. AdminId int `comment:"操作人ID"`
  140. AdminName string `comment:"操作人姓名"`
  141. CreateTime time.Time `comment:"创建时间"`
  142. ModifyTime time.Time `comment:"更新时间"`
  143. }
  144. // 更新派点信息
  145. func AddCygxEnterScore(item *CygxEnterScore, itemsPermission []*CygxEnterScorePermission, itemsResearcher []*CygxEnterScoreResearcher, itemsGroup []*CygxEnterScoreGroup) (err error) {
  146. o := orm.NewOrmUsingDB("hz_cygx")
  147. to, err := o.Begin()
  148. if err != nil {
  149. return
  150. }
  151. defer func() {
  152. if err != nil {
  153. _ = to.Rollback()
  154. } else {
  155. _ = to.Commit()
  156. }
  157. }()
  158. newId, err := to.Insert(item)
  159. if err != nil {
  160. return
  161. }
  162. enterScoreId := int(newId)
  163. for _, v := range itemsPermission {
  164. v.EnterScoreId = enterScoreId
  165. }
  166. for _, v := range itemsResearcher {
  167. v.EnterScoreId = enterScoreId
  168. }
  169. for _, v := range itemsGroup {
  170. v.EnterScoreId = enterScoreId
  171. }
  172. //批量添加行业信息
  173. _, err = to.InsertMulti(len(itemsPermission), itemsPermission)
  174. if err != nil {
  175. return
  176. }
  177. //批量添加研究员信息
  178. _, err = to.InsertMulti(len(itemsResearcher), itemsResearcher)
  179. if err != nil {
  180. return
  181. }
  182. //批量添加自定义分组信息
  183. _, err = to.InsertMulti(len(itemsGroup), itemsGroup)
  184. if err != nil {
  185. return
  186. }
  187. return
  188. }
  189. // 更新派点信息
  190. func UpdateCygxEnterScore(item *CygxEnterScore, itemsPermission []*CygxEnterScorePermission, itemsResearcher []*CygxEnterScoreResearcher, itemsGroup []*CygxEnterScoreGroup) (err error) {
  191. o := orm.NewOrmUsingDB("hz_cygx")
  192. to, err := o.Begin()
  193. if err != nil {
  194. return
  195. }
  196. defer func() {
  197. if err != nil {
  198. _ = to.Rollback()
  199. } else {
  200. _ = to.Commit()
  201. }
  202. }()
  203. _, err = to.Update(item, "CompanyId", "CompanyName", "StartDate", "EndDate", "Quarter", "QuarterDate", "EnterScoreType", "Ranking", "IsMergeScoring", "SecuritiesFirmsName", "MergeProportion", "RaiProportionTotal", "FiccProportionTotal", "ProportionTotal", "SellerId", "SellerName", "AdminId", "AdminName", "ModifyTime")
  204. if err != nil {
  205. return
  206. }
  207. enterScoreId := item.EnterScoreId
  208. //批量删除行业信息
  209. sql := `DELETE FROM cygx_enter_score_permission WHERE enter_score_id = ?`
  210. _, err = to.Raw(sql, enterScoreId).Exec()
  211. if err != nil {
  212. return
  213. }
  214. //批量删除研究员信息
  215. sql = ` DELETE FROM cygx_enter_score_researcher WHERE enter_score_id = ?`
  216. _, err = to.Raw(sql, enterScoreId).Exec()
  217. if err != nil {
  218. return
  219. }
  220. //批量删除自定义分组信息
  221. sql = ` DELETE FROM cygx_enter_score_group WHERE enter_score_id = ?`
  222. _, err = to.Raw(sql, enterScoreId).Exec()
  223. if err != nil {
  224. return
  225. }
  226. for _, v := range itemsPermission {
  227. v.EnterScoreId = enterScoreId
  228. }
  229. for _, v := range itemsResearcher {
  230. v.EnterScoreId = enterScoreId
  231. }
  232. for _, v := range itemsGroup {
  233. v.EnterScoreId = enterScoreId
  234. }
  235. //批量添加行业信息
  236. _, err = to.InsertMulti(len(itemsPermission), itemsPermission)
  237. if err != nil {
  238. return
  239. }
  240. //批量添加研究员信息
  241. _, err = to.InsertMulti(len(itemsResearcher), itemsResearcher)
  242. if err != nil {
  243. return
  244. }
  245. //批量添加自定义分组信息
  246. _, err = to.InsertMulti(len(itemsGroup), itemsGroup)
  247. if err != nil {
  248. return
  249. }
  250. return
  251. }
  252. // 通过ID获取详情
  253. func GetCygxEnterScoreInfoById(id int) (item *CygxEnterScore, err error) {
  254. o := orm.NewOrmUsingDB("hz_cygx")
  255. sql := `SELECT * FROM cygx_enter_score WHERE enter_score_id = ? `
  256. err = o.Raw(sql, id).QueryRow(&item)
  257. return
  258. }
  259. // 行业列表
  260. func GetCygxEnterScorePermissionListById(enterScoreId int) (items []*CygxEnterScorePermission, err error) {
  261. o := orm.NewOrmUsingDB("hz_cygx")
  262. sql := `SELECT * FROM cygx_enter_score_permission WHERE enter_score_id = ? `
  263. _, err = o.Raw(sql, enterScoreId).QueryRows(&items)
  264. return
  265. }
  266. // 根据多个录分ID获取行业列表
  267. func GetCygxEnterScorePermissionListByIds(enterScoreIds []int) (items []*CygxEnterScorePermission, err error) {
  268. lenArr := len(enterScoreIds)
  269. if lenArr == 0 {
  270. return
  271. }
  272. o := orm.NewOrmUsingDB("hz_cygx")
  273. sql := `SELECT * FROM cygx_enter_score_permission WHERE enter_score_id IN (` + utils.GetOrmInReplace(lenArr) + `) `
  274. _, err = o.Raw(sql, enterScoreIds).QueryRows(&items)
  275. return
  276. }
  277. // 研究员列表
  278. func GeCygxEnterScoreResearcherListById(enterScoreId int) (items []*CygxEnterScoreResearcher, err error) {
  279. o := orm.NewOrmUsingDB("hz_cygx")
  280. sql := `SELECT * FROM cygx_enter_score_researcher WHERE enter_score_id = ? `
  281. _, err = o.Raw(sql, enterScoreId).QueryRows(&items)
  282. return
  283. }
  284. // 根据多个录分ID获取研究员列表
  285. func GeCygxEnterScoreResearcherListByIds(enterScoreIds, newcompanyIds []int) (items []*CygxEnterScoreResearcher, err error) {
  286. lenArr := len(enterScoreIds)
  287. if lenArr == 0 {
  288. return
  289. }
  290. o := orm.NewOrmUsingDB("hz_cygx")
  291. sql := `SELECT * FROM cygx_enter_score_researcher WHERE enter_score_id IN (` + utils.GetOrmInReplace(lenArr) + `) AND proportion > 0 `
  292. //过滤销售可见的公司与研究员
  293. lenCompany := len(newcompanyIds)
  294. if lenCompany > 0 {
  295. sql += ` AND company_id IN (` + utils.GetOrmInReplace(lenCompany) + `) `
  296. _, err = o.Raw(sql, enterScoreIds, newcompanyIds).QueryRows(&items)
  297. } else {
  298. _, err = o.Raw(sql, enterScoreIds).QueryRows(&items)
  299. }
  300. return
  301. }
  302. // 自定义分组列表
  303. func GeCygxEnterScoreGroupListById(enterScoreId int) (items []*CygxEnterScoreGroup, err error) {
  304. o := orm.NewOrmUsingDB("hz_cygx")
  305. sql := `SELECT * FROM cygx_enter_score_group WHERE enter_score_id = ? `
  306. _, err = o.Raw(sql, enterScoreId).QueryRows(&items)
  307. return
  308. }
  309. // 根据多个录分ID获取自定义分组列表
  310. func GeCygxEnterScoreGroupListByIds(enterScoreIds []int) (items []*CygxEnterScoreGroup, err error) {
  311. lenArr := len(enterScoreIds)
  312. if lenArr == 0 {
  313. return
  314. }
  315. o := orm.NewOrmUsingDB("hz_cygx")
  316. sql := `SELECT * FROM cygx_enter_score_group WHERE enter_score_id IN (` + utils.GetOrmInReplace(lenArr) + `) `
  317. _, err = o.Raw(sql, enterScoreIds).QueryRows(&items)
  318. return
  319. }
  320. // 获取列表
  321. func GetCygxEnterScoreList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxEnterScore, err error) {
  322. o := orm.NewOrmUsingDB("hz_cygx")
  323. sql := `SELECT * FROM cygx_enter_score WHERE 1 = 1 `
  324. if condition != "" {
  325. sql += condition
  326. }
  327. sql += ` LIMIT ?,?`
  328. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  329. return
  330. }
  331. // 根据券商名称获取列表
  332. func GetCygxEnterScoreListBySecuritiesFirmsName(keyWord string) (items []*CygxEnterScore, err error) {
  333. o := orm.NewOrmUsingDB("hz_cygx")
  334. sql := `SELECT company_id FROM cygx_enter_score WHERE 1 = 1 `
  335. sql += ` AND securities_firms_name LIKE '%` + keyWord + `%' `
  336. sql += ` GROUP BY company_id `
  337. _, err = o.Raw(sql).QueryRows(&items)
  338. return
  339. }
  340. // 获取数量
  341. func GetCygxEnterScoreCount(condition string, pars []interface{}) (count int, err error) {
  342. o := orm.NewOrmUsingDB("hz_cygx")
  343. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_enter_score WHERE 1= 1 `
  344. if condition != "" {
  345. sqlCount += condition
  346. }
  347. err = o.Raw(sqlCount, pars).QueryRow(&count)
  348. return
  349. }
  350. type EnterScoreListResp struct {
  351. EnterScoreId int `comment:"录分ID"`
  352. CompanyId int `comment:"公司ID,公司标识符"`
  353. CompanyName string `comment:"公司名称"`
  354. Quarter []string `comment:"季度,评分季度"`
  355. EnterScoreType int `comment:"录入方式 1:按评分录入、2:按比例录入"`
  356. Ranking string `comment:"排名"`
  357. IsMergeScoring int `comment:"是否合并打分"`
  358. SecuritiesFirmsName string `comment:"券商名称"`
  359. ProportionTotal float64 `comment:"合计总占比"`
  360. SellerId int `comment:"所属销售id"`
  361. SellerName string `comment:"所属销售名称"`
  362. CreateTime string `comment:"创建时间"`
  363. ModifyTime string `comment:"更新时间"`
  364. }
  365. type GetCygxEnterScoreListRep struct {
  366. Paging *paging.PagingItem `description:"分页数据"`
  367. List []*EnterScoreListResp
  368. }
  369. // 删除
  370. func DeleteEnterScore(enterScoreId int) (err error) {
  371. o := orm.NewOrmUsingDB("hz_cygx")
  372. to, err := o.Begin()
  373. if err != nil {
  374. return
  375. }
  376. defer func() {
  377. if err != nil {
  378. _ = to.Rollback()
  379. } else {
  380. _ = to.Commit()
  381. }
  382. }()
  383. //删除单条录分信息
  384. sql := `DELETE FROM cygx_enter_score WHERE enter_score_id = ?`
  385. _, err = to.Raw(sql, enterScoreId).Exec()
  386. if err != nil {
  387. return
  388. }
  389. //批量删除行业信息
  390. sql = `DELETE FROM cygx_enter_score_permission WHERE enter_score_id = ?`
  391. _, err = to.Raw(sql, enterScoreId).Exec()
  392. if err != nil {
  393. return
  394. }
  395. //批量删除研究员信息
  396. sql = ` DELETE FROM cygx_enter_score_researcher WHERE enter_score_id = ?`
  397. _, err = to.Raw(sql, enterScoreId).Exec()
  398. if err != nil {
  399. return
  400. }
  401. //批量删除自定义分组信息
  402. sql = ` DELETE FROM cygx_enter_score_group WHERE enter_score_id = ?`
  403. _, err = to.Raw(sql, enterScoreId).Exec()
  404. if err != nil {
  405. return
  406. }
  407. return
  408. }
  409. type ScoreOverviewListResp struct {
  410. ListCompany []*company.CompanyNameAndId
  411. ListPermission []*EnterScorePermissionListResp
  412. ListGroup []*EnterScoreGroupListResp
  413. }
  414. type RankingOverviewListResp struct {
  415. ListCompany []*company.CompanyNameAndId
  416. ListQuarterDate []*QuarterDateListResp
  417. }
  418. // 排名总览
  419. type QuarterDateListResp struct {
  420. Quarter string `description:"季度"`
  421. ProportionListText []string `description:"占比列表"`
  422. }