enter_score.go 15 KB

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