123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476 |
- package cygx
- import (
- "github.com/beego/beego/v2/client/orm"
- "github.com/rdlucklib/rdluck_tools/paging"
- "hongze/hz_crm_api/models/company"
- "hongze/hz_crm_api/utils"
- "time"
- )
- // CygxEnterScore 结构体代表了 cygx_enter_score 表格
- type CygxEnterScore struct {
- EnterScoreId int `orm:"column(enter_score_id);pk";comment:"主键"`
- CompanyId int `comment:"公司ID"`
- CompanyName string `comment:"客户名称"`
- StartDate string `comment:"开始日期"`
- EndDate string `comment:"结束日期"`
- Quarter string `comment:"季度"`
- QuarterDate string `comment:"季度带有年月日的多个数组转成的字符串"`
- EnterScoreType int `comment:"录入方式 1:按评分录入、2:按比例录入"`
- Ranking string `comment:"排名"`
- IsMergeScoring int `comment:"是否合并打分"`
- SecuritiesFirmsName string `comment:"券商名称"`
- MergeProportion float64 `comment:"合并占比"`
- RaiProportionTotal float64 `comment:"权益研究员占比"`
- FiccProportionTotal float64 `comment:"FICC研究员占比"`
- ProportionTotal float64 `comment:"合计总占比"`
- SellerId int `comment:"所属销售id"`
- SellerName string `comment:"所属销售名称"`
- AdminId int `comment:"操作人ID"`
- AdminName string `comment:"操作人姓名"`
- CreateTime time.Time `comment:"创建时间"`
- ModifyTime time.Time `comment:"更新时间"`
- }
- type CygxEnterScoreDetailResp struct {
- EnterScoreId int `comment:"录分ID"`
- CompanyId int `comment:"公司ID,公司标识符"`
- CompanyName string `comment:"公司名称"`
- StartDate string `comment:"开始日期"`
- EndDate string `comment:"结束日期"`
- Quarter []string `comment:"季度,评分季度"`
- EnterScoreType int `comment:"录入方式 1:按评分录入、2:按比例录入"`
- Ranking string `comment:"排名"`
- IsMergeScoring int `comment:"是否合并打分"`
- SecuritiesFirmsName string `comment:"券商名称"`
- MergeProportion float64 `comment:"合并占比"`
- ProportionTotal float64 `comment:"合计总占比"`
- RaiProportionTotal float64 `comment:"权益研究员占比"`
- FiccProportionTotal float64 `comment:"FICC研究员占比"`
- EnterScoreObj EnterScoreDateObj `comment:"按评分录入"`
- PercentageObj EnterScoreDateObj `comment:"按比例录入"`
- }
- // 行业
- type EnterScoreDateObj struct {
- ListRai []*EnterScorePermissionListResp //权益列表
- ListFicc []*EnterScorePermissionListResp //FICC列表
- ListGroup []*EnterScoreGroupListResp //其他配置信息
- }
- // 行业
- type EnterScorePermissionListResp struct {
- ChartPermissionName string `description:"行业名称"`
- Proportion float64 `description:"占比"`
- ProportionListText []string `description:"占比列表"`
- EnterScoreId int `comment:"录分ID"`
- List []*EnterScoreRealNameListResp
- }
- // 占比描述
- type EnterScoreProportionTextResp struct {
- ProportionText string
- }
- // 研究员
- type EnterScoreRealNameListResp struct {
- RealName string `comment:"研究员姓名"`
- Proportion float64 `comment:"占比"`
- ProportionListText []string `description:"占比列表"`
- ChartPermissionName string `comment:"行业名称"`
- }
- // 其他分组
- type EnterScoreGroupListResp struct {
- GroupName string `description:"组名"`
- Proportion float64 `description:"占比"`
- ProportionListText []string `description:"占比列表"`
- }
- // 添加或修改录分时的入参结构体
- type UpdateEnterScoreReq struct {
- EnterScoreId int `comment:"录分ID"`
- CompanyId int `comment:"公司ID"`
- CompanyName string `comment:"客户名称"`
- StartDate string `comment:"开始日期"`
- EndDate string `comment:"结束日期"`
- Quarter []string `comment:"季度"`
- EnterScoreType int `comment:"录入方式 1:按评分录入、2:按比例录入"`
- Ranking string `comment:"排名"`
- IsMergeScoring int `comment:"是否合并打分"`
- SecuritiesFirmsName string `comment:"券商名称"`
- MergeProportion float64 `comment:"合并占比"`
- RaiProportionTotal float64 `comment:"权益研究员占比"`
- FiccProportionTotal float64 `comment:"FICC研究员占比"`
- ProportionTotal float64 `comment:"合计总占比"`
- ListRai []*EnterScorePermissionListResp //权益列表
- ListFicc []*EnterScorePermissionListResp //FICC列表
- ListGroup []*EnterScoreGroupListResp //其他配置信息
- }
- type EnterScoreIdReq struct {
- EnterScoreId int `comment:"录分ID"`
- }
- // CygxEnterScoreGroup 结构体代表 cygx_enter_score_group 表
- type CygxEnterScoreGroup struct {
- EnterScoreGroupId int `orm:"column(enter_score_group_id);pk";comment:"主键"`
- EnterScoreId int `comment:"cygx_enter_score主键"`
- CompanyId int `comment:"公司ID"`
- GroupName string `comment:"名称"`
- Proportion float64 `comment:"占比"`
- AdminId int `comment:"操作人ID"`
- AdminName string `comment:"操作人姓名"`
- CreateTime time.Time `comment:"创建时间"`
- ModifyTime time.Time `comment:"更新时间"`
- }
- // CygxEnterScorePermission 结构体代表 cygx_enter_score_permission 表
- type CygxEnterScorePermission struct {
- EnterScorePermissionId int `orm:"column(enter_score_permission_id);pk";comment:"主键"`
- EnterScoreId int `comment:"cygx_enter_score主键"`
- CompanyId int `comment:"公司ID"`
- ChartPermissionName string `comment:"名称"`
- Proportion float64 `comment:"占比"`
- ProductId float64 `comment:"产品id,1:FICC、2:权益"`
- AdminId int `comment:"操作人ID"`
- AdminName string `comment:"操作人姓名"`
- CreateTime time.Time `comment:"创建时间"`
- ModifyTime time.Time `comment:"更新时间"`
- }
- // CygxEnterScoreResearcher 结构体代表 cygx_enter_score_researcher 表
- type CygxEnterScoreResearcher struct {
- EnterScoreDataId int `orm:"column(enter_score_data_id);pk";comment:"主键"`
- EnterScoreId int `comment:"cygx_enter_score主键"`
- CompanyId int `comment:"公司ID"`
- Proportion float64 `comment:"占比"`
- RealName string `comment:"研究员姓名"`
- ChartPermissionName string `comment:"名称"`
- ProductId float64 `comment:"产品id,1:FICC、2:权益"`
- AdminId int `comment:"操作人ID"`
- AdminName string `comment:"操作人姓名"`
- CreateTime time.Time `comment:"创建时间"`
- ModifyTime time.Time `comment:"更新时间"`
- }
- // 更新派点信息
- func AddCygxEnterScore(item *CygxEnterScore, itemsPermission []*CygxEnterScorePermission, itemsResearcher []*CygxEnterScoreResearcher, itemsGroup []*CygxEnterScoreGroup) (err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- to, err := o.Begin()
- if err != nil {
- return
- }
- defer func() {
- if err != nil {
- _ = to.Rollback()
- } else {
- _ = to.Commit()
- }
- }()
- newId, err := to.Insert(item)
- if err != nil {
- return
- }
- enterScoreId := int(newId)
- for _, v := range itemsPermission {
- v.EnterScoreId = enterScoreId
- }
- for _, v := range itemsResearcher {
- v.EnterScoreId = enterScoreId
- }
- for _, v := range itemsGroup {
- v.EnterScoreId = enterScoreId
- }
- //批量添加行业信息
- _, err = to.InsertMulti(len(itemsPermission), itemsPermission)
- if err != nil {
- return
- }
- //批量添加研究员信息
- _, err = to.InsertMulti(len(itemsResearcher), itemsResearcher)
- if err != nil {
- return
- }
- //批量添加自定义分组信息
- _, err = to.InsertMulti(len(itemsGroup), itemsGroup)
- if err != nil {
- return
- }
- return
- }
- // 更新派点信息
- func UpdateCygxEnterScore(item *CygxEnterScore, itemsPermission []*CygxEnterScorePermission, itemsResearcher []*CygxEnterScoreResearcher, itemsGroup []*CygxEnterScoreGroup) (err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- to, err := o.Begin()
- if err != nil {
- return
- }
- defer func() {
- if err != nil {
- _ = to.Rollback()
- } else {
- _ = to.Commit()
- }
- }()
- _, err = to.Update(item, "CompanyId", "CompanyName", "StartDate", "EndDate", "Quarter", "QuarterDate", "EnterScoreType", "Ranking", "IsMergeScoring", "SecuritiesFirmsName", "MergeProportion", "RaiProportionTotal", "FiccProportionTotal", "ProportionTotal", "SellerId", "SellerName", "AdminId", "AdminName", "ModifyTime")
- if err != nil {
- return
- }
- enterScoreId := item.EnterScoreId
- //批量删除行业信息
- sql := `DELETE FROM cygx_enter_score_permission WHERE enter_score_id = ?`
- _, err = to.Raw(sql, enterScoreId).Exec()
- if err != nil {
- return
- }
- //批量删除研究员信息
- sql = ` DELETE FROM cygx_enter_score_researcher WHERE enter_score_id = ?`
- _, err = to.Raw(sql, enterScoreId).Exec()
- if err != nil {
- return
- }
- //批量删除自定义分组信息
- sql = ` DELETE FROM cygx_enter_score_group WHERE enter_score_id = ?`
- _, err = to.Raw(sql, enterScoreId).Exec()
- if err != nil {
- return
- }
- for _, v := range itemsPermission {
- v.EnterScoreId = enterScoreId
- }
- for _, v := range itemsResearcher {
- v.EnterScoreId = enterScoreId
- }
- for _, v := range itemsGroup {
- v.EnterScoreId = enterScoreId
- }
- //批量添加行业信息
- _, err = to.InsertMulti(len(itemsPermission), itemsPermission)
- if err != nil {
- return
- }
- //批量添加研究员信息
- _, err = to.InsertMulti(len(itemsResearcher), itemsResearcher)
- if err != nil {
- return
- }
- //批量添加自定义分组信息
- _, err = to.InsertMulti(len(itemsGroup), itemsGroup)
- if err != nil {
- return
- }
- return
- }
- // 通过ID获取详情
- func GetCygxEnterScoreInfoById(id int) (item *CygxEnterScore, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT * FROM cygx_enter_score WHERE enter_score_id = ? `
- err = o.Raw(sql, id).QueryRow(&item)
- return
- }
- // 行业列表
- func GetCygxEnterScorePermissionListById(enterScoreId int) (items []*CygxEnterScorePermission, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT * FROM cygx_enter_score_permission WHERE enter_score_id = ? `
- _, err = o.Raw(sql, enterScoreId).QueryRows(&items)
- return
- }
- // 根据多个录分ID获取行业列表
- func GetCygxEnterScorePermissionListByIds(enterScoreIds []int) (items []*CygxEnterScorePermission, err error) {
- lenArr := len(enterScoreIds)
- if lenArr == 0 {
- return
- }
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT * FROM cygx_enter_score_permission WHERE enter_score_id IN (` + utils.GetOrmInReplace(lenArr) + `) `
- _, err = o.Raw(sql, enterScoreIds).QueryRows(&items)
- return
- }
- // 研究员列表
- func GeCygxEnterScoreResearcherListById(enterScoreId int) (items []*CygxEnterScoreResearcher, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT * FROM cygx_enter_score_researcher WHERE enter_score_id = ? `
- _, err = o.Raw(sql, enterScoreId).QueryRows(&items)
- return
- }
- // 根据多个录分ID获取研究员列表
- func GeCygxEnterScoreResearcherListByIds(enterScoreIds, newcompanyIds []int) (items []*CygxEnterScoreResearcher, err error) {
- lenArr := len(enterScoreIds)
- if lenArr == 0 {
- return
- }
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT * FROM cygx_enter_score_researcher WHERE enter_score_id IN (` + utils.GetOrmInReplace(lenArr) + `) AND proportion > 0 `
- //过滤销售可见的公司与研究员
- lenCompany := len(newcompanyIds)
- if lenCompany > 0 {
- sql += ` AND company_id IN (` + utils.GetOrmInReplace(lenCompany) + `) `
- _, err = o.Raw(sql, enterScoreIds, newcompanyIds).QueryRows(&items)
- } else {
- _, err = o.Raw(sql, enterScoreIds).QueryRows(&items)
- }
- return
- }
- // 自定义分组列表
- func GeCygxEnterScoreGroupListById(enterScoreId int) (items []*CygxEnterScoreGroup, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT * FROM cygx_enter_score_group WHERE enter_score_id = ? `
- _, err = o.Raw(sql, enterScoreId).QueryRows(&items)
- return
- }
- // 根据多个录分ID获取自定义分组列表
- func GeCygxEnterScoreGroupListByIds(enterScoreIds []int) (items []*CygxEnterScoreGroup, err error) {
- lenArr := len(enterScoreIds)
- if lenArr == 0 {
- return
- }
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT * FROM cygx_enter_score_group WHERE enter_score_id IN (` + utils.GetOrmInReplace(lenArr) + `) `
- _, err = o.Raw(sql, enterScoreIds).QueryRows(&items)
- return
- }
- // 获取列表
- func GetCygxEnterScoreList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxEnterScore, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT * FROM cygx_enter_score WHERE 1 = 1 `
- if condition != "" {
- sql += condition
- }
- sql += ` LIMIT ?,?`
- _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
- return
- }
- // 根据券商名称获取列表
- func GetCygxEnterScoreListBySecuritiesFirmsName(keyWord string) (items []*CygxEnterScore, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT company_id FROM cygx_enter_score WHERE 1 = 1 `
- sql += ` AND securities_firms_name LIKE '%` + keyWord + `%' `
- sql += ` GROUP BY company_id `
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- // 获取数量
- func GetCygxEnterScoreCount(condition string, pars []interface{}) (count int, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sqlCount := ` SELECT COUNT(1) AS count FROM cygx_enter_score WHERE 1= 1 `
- if condition != "" {
- sqlCount += condition
- }
- err = o.Raw(sqlCount, pars).QueryRow(&count)
- return
- }
- type EnterScoreListResp struct {
- EnterScoreId int `comment:"录分ID"`
- CompanyId int `comment:"公司ID,公司标识符"`
- CompanyName string `comment:"公司名称"`
- Quarter []string `comment:"季度,评分季度"`
- EnterScoreType int `comment:"录入方式 1:按评分录入、2:按比例录入"`
- Ranking string `comment:"排名"`
- IsMergeScoring int `comment:"是否合并打分"`
- SecuritiesFirmsName string `comment:"券商名称"`
- ProportionTotal float64 `comment:"合计总占比"`
- SellerId int `comment:"所属销售id"`
- SellerName string `comment:"所属销售名称"`
- CreateTime string `comment:"创建时间"`
- ModifyTime string `comment:"更新时间"`
- }
- type GetCygxEnterScoreListRep struct {
- Paging *paging.PagingItem `description:"分页数据"`
- List []*EnterScoreListResp
- }
- // 删除
- func DeleteEnterScore(enterScoreId int) (err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- to, err := o.Begin()
- if err != nil {
- return
- }
- defer func() {
- if err != nil {
- _ = to.Rollback()
- } else {
- _ = to.Commit()
- }
- }()
- //删除单条录分信息
- sql := `DELETE FROM cygx_enter_score WHERE enter_score_id = ?`
- _, err = to.Raw(sql, enterScoreId).Exec()
- if err != nil {
- return
- }
- //批量删除行业信息
- sql = `DELETE FROM cygx_enter_score_permission WHERE enter_score_id = ?`
- _, err = to.Raw(sql, enterScoreId).Exec()
- if err != nil {
- return
- }
- //批量删除研究员信息
- sql = ` DELETE FROM cygx_enter_score_researcher WHERE enter_score_id = ?`
- _, err = to.Raw(sql, enterScoreId).Exec()
- if err != nil {
- return
- }
- //批量删除自定义分组信息
- sql = ` DELETE FROM cygx_enter_score_group WHERE enter_score_id = ?`
- _, err = to.Raw(sql, enterScoreId).Exec()
- if err != nil {
- return
- }
- return
- }
- type ScoreOverviewListResp struct {
- ListCompany []*company.CompanyNameAndId
- ListPermission []*EnterScorePermissionListResp
- ListGroup []*EnterScoreGroupListResp
- }
- type RankingOverviewListResp struct {
- ListCompany []*company.CompanyNameAndId
- ListQuarterDate []*QuarterDateListResp
- }
- // 排名总览
- type QuarterDateListResp struct {
- Quarter string `description:"季度"`
- ProportionListText []string `description:"占比列表"`
- }
|