enter_score.go 13 KB

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