enter_score.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  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 []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. _, err = o.Raw(sql, enterScoreIds).QueryRows(&items)
  293. return
  294. }
  295. // 自定义分组列表
  296. func GeCygxEnterScoreGroupListById(enterScoreId int) (items []*CygxEnterScoreGroup, err error) {
  297. o := orm.NewOrmUsingDB("hz_cygx")
  298. sql := `SELECT * FROM cygx_enter_score_group WHERE enter_score_id = ? `
  299. _, err = o.Raw(sql, enterScoreId).QueryRows(&items)
  300. return
  301. }
  302. // 根据多个录分ID获取自定义分组列表
  303. func GeCygxEnterScoreGroupListByIds(enterScoreIds []int) (items []*CygxEnterScoreGroup, err error) {
  304. lenArr := len(enterScoreIds)
  305. if lenArr == 0 {
  306. return
  307. }
  308. o := orm.NewOrmUsingDB("hz_cygx")
  309. sql := `SELECT * FROM cygx_enter_score_group WHERE enter_score_id IN (` + utils.GetOrmInReplace(lenArr) + `) `
  310. _, err = o.Raw(sql, enterScoreIds).QueryRows(&items)
  311. return
  312. }
  313. // 获取列表
  314. func GetCygxEnterScoreList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxEnterScore, err error) {
  315. o := orm.NewOrmUsingDB("hz_cygx")
  316. sql := `SELECT * FROM cygx_enter_score WHERE 1 = 1 `
  317. if condition != "" {
  318. sql += condition
  319. }
  320. sql += ` LIMIT ?,?`
  321. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  322. return
  323. }
  324. // 获取数量
  325. func GetCygxEnterScoreCount(condition string, pars []interface{}) (count int, err error) {
  326. o := orm.NewOrmUsingDB("hz_cygx")
  327. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_enter_score WHERE 1= 1 `
  328. if condition != "" {
  329. sqlCount += condition
  330. }
  331. err = o.Raw(sqlCount, pars).QueryRow(&count)
  332. return
  333. }
  334. type EnterScoreListResp struct {
  335. EnterScoreId int `comment:"录分ID"`
  336. CompanyId int `comment:"公司ID,公司标识符"`
  337. CompanyName string `comment:"公司名称"`
  338. Quarter []string `comment:"季度,评分季度"`
  339. EnterScoreType int `comment:"录入方式 1:按评分录入、2:按比例录入"`
  340. Ranking string `comment:"排名"`
  341. IsMergeScoring int `comment:"是否合并打分"`
  342. SecuritiesFirmsName string `comment:"券商名称"`
  343. ProportionTotal float64 `comment:"合计总占比"`
  344. SellerId int `comment:"所属销售id"`
  345. SellerName string `comment:"所属销售名称"`
  346. CreateTime string `comment:"创建时间"`
  347. ModifyTime string `comment:"更新时间"`
  348. }
  349. type GetCygxEnterScoreListRep struct {
  350. Paging *paging.PagingItem `description:"分页数据"`
  351. List []*EnterScoreListResp
  352. }
  353. // 删除
  354. func DeleteEnterScore(enterScoreId int) (err error) {
  355. o := orm.NewOrmUsingDB("hz_cygx")
  356. to, err := o.Begin()
  357. if err != nil {
  358. return
  359. }
  360. defer func() {
  361. if err != nil {
  362. _ = to.Rollback()
  363. } else {
  364. _ = to.Commit()
  365. }
  366. }()
  367. //删除单条录分信息
  368. sql := `DELETE FROM cygx_enter_score WHERE enter_score_id = ?`
  369. _, err = to.Raw(sql, enterScoreId).Exec()
  370. if err != nil {
  371. return
  372. }
  373. //批量删除行业信息
  374. sql = `DELETE FROM cygx_enter_score_permission WHERE enter_score_id = ?`
  375. _, err = to.Raw(sql, enterScoreId).Exec()
  376. if err != nil {
  377. return
  378. }
  379. //批量删除研究员信息
  380. sql = ` DELETE FROM cygx_enter_score_researcher WHERE enter_score_id = ?`
  381. _, err = to.Raw(sql, enterScoreId).Exec()
  382. if err != nil {
  383. return
  384. }
  385. //批量删除自定义分组信息
  386. sql = ` DELETE FROM cygx_enter_score_group WHERE enter_score_id = ?`
  387. _, err = to.Raw(sql, enterScoreId).Exec()
  388. if err != nil {
  389. return
  390. }
  391. return
  392. }
  393. type ScoreOverviewListResp struct {
  394. ListCompany []*company.CompanyNameAndId
  395. ListPermission []*EnterScorePermissionListResp
  396. ListGroup []*EnterScoreGroupListResp
  397. }
  398. type RankingOverviewListResp struct {
  399. ListCompany []*company.CompanyNameAndId
  400. ListQuarterDate []*QuarterDateListResp
  401. }
  402. // 排名总览
  403. type QuarterDateListResp struct {
  404. Quarter string `description:"季度"`
  405. ProportionListText []string `description:"占比列表"`
  406. }