123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302 |
- package models
- import (
- "eta/eta_mobile/utils"
- "fmt"
- "github.com/beego/beego/v2/client/orm"
- "strconv"
- "time"
- )
- // ResearchReport 研究报告表(晨报、周报等)结构体
- type ResearchReport struct {
- ResearchReportId int `orm:"column(research_report_id);pk" description:"研究报告id"`
- ResearchReportName string `description:"研究报告名称"`
- ResearchReportTitle string `description:"研究报告标题"`
- ResearchReportImg string `description:"报告缩略图URL"`
- ResearchReportDate time.Time `description:"报告日期"`
- Type string `description:"报告类型,枚举值:day 晨报 week 周报 twoweek双周报 month 月报;默认:day"`
- Author string `description:"作者"`
- ReportVariety string `description:"研究报告的品种,双周报和月报有标识"`
- IsHasMenu int8 `description:"报告是否含有目录"`
- IsSendedMsg int8 `description:"是否发送过模板消息"`
- Periods int `description:"期数"`
- Status string `description:"状态,draft:草稿,"`
- Enabled int8 `description:"报告状态"`
- CreatedTime string `description:"创建时间"`
- LastUpdatedTime time.Time `description:"最近一次更新时间"`
- Viewers int `description:"H5观看用户数"`
- }
- // GetResearchReportListByIds 根据报告id集合获取报告数据列表
- func GetResearchReportListByIds(researchReportIds string) (list []*ResearchReport, err error) {
- if researchReportIds == "" {
- return
- }
- o := orm.NewOrm()
- sql := `select * from research_report where research_report_id in (` + researchReportIds + `)`
- _, err = o.Raw(sql).QueryRows(&list)
- return
- }
- // Update 更新数据
- func (researchReport *ResearchReport) Update(updateCols []string) (err error) {
- o := orm.NewOrm()
- _, err = o.Update(researchReport, updateCols...)
- return
- }
- type ResearchReportList struct {
- ResearchReportId int `orm:"column(research_report_id);pk" description:"研究报告id"`
- ResearchReportName string `description:"研究报告名称"`
- ResearchReportTitle string `description:"研究报告标题"`
- ResearchReportImg string `description:"报告缩略图URL"`
- ResearchReportDate time.Time `description:"报告日期"`
- Type string `description:"报告类型,枚举值:day 晨报 week 周报 twoweek双周报 month 月报;默认:day"`
- Author string `description:"作者"`
- ReportVariety string `description:"研究报告的品种,双周报和月报有标识"`
- IsHasMenu int8 `description:"报告是否含有目录"`
- IsSendedMsg int8 `description:"是否发送过模板消息"`
- Periods int `description:"期数"`
- Status string `description:"状态,draft:草稿,"`
- Enabled int8 `description:"报告状态"`
- CreatedTime string `description:"创建时间"`
- LastUpdatedTime time.Time `description:"最近一次更新时间"`
- Viewers int `description:"H5观看用户数"`
- LinkUrl string `description:"报告阅读地址"`
- }
- // GetResearchReportList 获取报告列表
- func GetResearchReportList(condition string, pars []interface{}, startSize, pageSize int) (total int, list []*ResearchReportList, err error) {
- o := orm.NewOrm()
- sql := `select * from research_report where enabled = 1 `
- sql += condition
- sql += ` order by research_report_date desc,created_time desc `
- totalSql := `select count(1) total from (` + sql + `) z `
- err = o.Raw(totalSql, pars).QueryRow(&total)
- if err != nil {
- return
- }
- sql += ` LIMIT ?,? `
- _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
- return
- }
- // 获取今年报告
- func GetMigrateReportList() (list []*ResearchReport, err error) {
- o := orm.NewOrm()
- sql := ` SELECT
- *
- FROM
- research_report AS a
- WHERE
- a.enabled = 1
- AND a.status = "report"
- AND a.research_report_date >= "2022-01-01"
- ORDER BY a.research_report_date ASC `
- _, err = o.Raw(sql).QueryRows(&list)
- return
- }
- // ResearchReport 研究报告表(晨报、周报等)结构体
- type ResearchReportType struct {
- ResearchReportTypeId int `orm:"column(research_report_type_id);pk" description:"报告章节ID"`
- ResearchReportId int `description:"报告ID"`
- TypeId int `description:"分类ID"`
- Edit int `description:"是否编辑过"`
- Trend string `description:"趋势观点"`
- ResearchReportTypeTitle string `description:"报告标题"`
- CreatedTime string `description:"创建时间"`
- LastUpdatedTime time.Time `description:"最近一次更新时间"`
- }
- type ResearchReportTypeContent struct {
- ResearchReportTypeContentId int `orm:"column(research_report_type_content_id);pk" description:"章节内容ID"`
- ResearchReportTypeId int `description:"报告章节ID"`
- Sort int `description:"排序"`
- ContentType string `description:"内容分类类型"`
- Content string `description:"内容"`
- ImgUrl string `description:"图片路径"`
- CreatedTime time.Time `description:"创建时间"`
- LastUpdatedTime time.Time `description:"最近一次更新时间"`
- }
- type ResearchReportTypeTicker struct {
- ResearchReportTypeTickerId int `orm:"column(research_report_type_ticker_id);pk" description:"章节tickerID"`
- ResearchReportTypeId int `description:"报告章节ID"`
- Sort int `description:"排序"`
- Ticker string `description:"指标的ticker"`
- CreatedTime time.Time `description:"创建时间"`
- LastUpdatedTime time.Time `description:"最近一次更新时间"`
- }
- func GetResearchReportTypeList(researchReportId int) (list []*ResearchReportType, err error) {
- o := orm.NewOrm()
- sql := ` SELECT * FROM research_report_type WHERE research_report_id = ? ORDER BY created_time ASC `
- _, err = o.Raw(sql, researchReportId).QueryRows(&list)
- return
- }
- func GetResearchReportTypeListByReportIds(reportIds string) (list []*ResearchReportType, err error) {
- o := orm.NewOrm()
- sql := ` SELECT * FROM research_report_type WHERE research_report_id IN (` + reportIds + `) ORDER BY created_time ASC,research_report_type_id ASC `
- _, err = o.Raw(sql).QueryRows(&list)
- return
- }
- func GetResearchReportTypeContentList(researchReportTypeId int) (list []*ResearchReportTypeContent, err error) {
- o := orm.NewOrm()
- sql := ` SELECT * FROM research_report_type_content WHERE research_report_type_id = ? ORDER BY sort ASC `
- _, err = o.Raw(sql, researchReportTypeId).QueryRows(&list)
- return
- }
- func GetResearchReportTypeContentListByReportTypeIds(reportTypeIds string) (list []*ResearchReportTypeContent, err error) {
- o := orm.NewOrm()
- sql := ` SELECT * FROM research_report_type_content WHERE research_report_type_id IN (` + reportTypeIds + `) ORDER BY research_report_type_id ASC,sort ASC `
- _, err = o.Raw(sql).QueryRows(&list)
- return
- }
- func GetResearchReportTypeTickerList(researchReportTypeId int) (list []*ResearchReportTypeTicker, err error) {
- o := orm.NewOrm()
- sql := ` SELECT * FROM research_report_type_ticker WHERE research_report_type_id = ? ORDER BY sort ASC `
- _, err = o.Raw(sql, researchReportTypeId).QueryRows(&list)
- return
- }
- func GetResearchReportTypeTickerListByReportTypeIds(reportTypeIds string) (list []*ResearchReportTypeTicker, err error) {
- o := orm.NewOrm()
- sql := ` SELECT * FROM research_report_type_ticker WHERE research_report_type_id IN (` + reportTypeIds + `) ORDER BY research_report_type_id ASC,sort ASC `
- _, err = o.Raw(sql).QueryRows(&list)
- return
- }
- type CreateDayWeekReport struct {
- Report *Report
- ChapterList []*CreateDayWeekReportChapter
- }
- type CreateDayWeekReportChapter struct {
- Chapter *ReportChapter
- TickerList []*ReportChapterTicker
- }
- // 新增迁移晨周报
- func CreateMigrateNewDayWeekReport(newDayWeekReport *CreateDayWeekReport) (newReportId int, err error) {
- o := orm.NewOrmUsingDB("rddp")
- to, err := o.Begin()
- if err != nil {
- return
- }
- defer func() {
- if err != nil {
- _ = to.Rollback()
- } else {
- _ = to.Commit()
- }
- }()
- // 新增报告
- reportId, err := to.Insert(newDayWeekReport.Report)
- if err != nil {
- fmt.Println("InsertReportErr:" + err.Error())
- return
- }
- // 新增章节
- for _, chapter := range newDayWeekReport.ChapterList {
- chapter.Chapter.ReportId = int(reportId)
- lastChapterId, tmpErr := to.Insert(chapter.Chapter)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- // 新增晨报ticker
- for _, ticker := range chapter.TickerList {
- ticker.ReportChapterId = int(lastChapterId)
- if _, tmpErr = to.Insert(ticker); tmpErr != nil {
- err = tmpErr
- return
- }
- }
- }
- // 修改报告code
- reportCode := utils.MD5(strconv.Itoa(int(reportId)))
- sql := `UPDATE report SET report_code = ? WHERE id = ? `
- if _, err = to.Raw(sql, reportCode, reportId).Exec(); err != nil {
- fmt.Println("UpdateReportCodeErr:" + err.Error())
- }
- newReportId = int(reportId)
- return
- }
- // 新增迁移其他报告
- func CreateMigrateNewOtherReport(reportInfo *Report, mappingList []*ChartPermissionChapterMapping) (newReportId int, err error) {
- o := orm.NewOrmUsingDB("rddp")
- to, err := o.Begin()
- if err != nil {
- return
- }
- defer func() {
- if err != nil {
- _ = to.Rollback()
- } else {
- _ = to.Commit()
- }
- }()
- // 新增报告
- reportId, err := to.Insert(reportInfo)
- if err != nil {
- fmt.Println("InsertReportErr:" + err.Error())
- return
- }
- // 修改报告code
- reportCode := utils.MD5(strconv.Itoa(int(reportId)))
- sql := `UPDATE report SET report_code = ? WHERE id = ? `
- if _, err = to.Raw(sql, reportCode, reportId).Exec(); err != nil {
- fmt.Println("UpdateReportCodeErr:" + err.Error())
- return
- }
- // 新增权限
- newReportId = int(reportId)
- if len(mappingList) > 0 {
- r := orm.NewOrm()
- for _, mapping := range mappingList {
- sql := ` INSERT INTO chart_permission_chapter_mapping (chart_permission_id, report_chapter_type_id,research_type) VALUES(?,?,?) `
- if _, err = r.Raw(sql, mapping.ChartPermissionId, newReportId, "rddp").Exec(); err != nil {
- fmt.Println("InsertChartPermissionErr:" + err.Error())
- return
- }
- }
- }
- return
- }
- type ChartPermissionChapterMapping struct {
- Id int `orm:"column(id);pk"`
- ChartPermissionId int `description:"权限ID"`
- ReportChapterTypeId int `description:"report_chapter_type表主键id或research_report表主键id或tactic表主键id"`
- ResearchType string `description:"报告类型 week;two_week;tactic;month;other;rddp; "`
- }
- func GetChapterPermissionMappingByCondition(reportChapterTypeId int, researchType string) (list []*ChartPermissionChapterMapping, err error) {
- o := orm.NewOrm()
- sql := ` SELECT * FROM chart_permission_chapter_mapping WHERE report_chapter_type_id = ? AND research_type = ? `
- _, err = o.Raw(sql, reportChapterTypeId, researchType).QueryRows(&list)
- return
- }
- func GetChapterPermissionMappingByResearchReportIds(researchReportIds string) (list []*ChartPermissionChapterMapping, err error) {
- o := orm.NewOrm()
- sql := ` SELECT * FROM chart_permission_chapter_mapping WHERE report_chapter_type_id IN (` + researchReportIds + `) AND research_type != "rddp" ORDER BY report_chapter_type_id ASC `
- _, err = o.Raw(sql).QueryRows(&list)
- return
- }
|