123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601 |
- package models
- import (
- sql2 "database/sql"
- "errors"
- "eta/eta_api/global"
- "eta/eta_api/models/report"
- "eta/eta_api/utils"
- )
- // AddReportAndChapter
- // @Description: 新增报告及章节
- // @author: Roc
- // @datetime 2024-06-06 17:08:34
- // @param reportItem *Report
- // @param allGrantUserList []*report.ReportGrant
- // @param addReportChapterList []AddReportChapter
- // @return reportId int64
- // @return err error
- func AddReportAndChapter(reportItem *Report, reportFreeLayoutList []*report.ReportFreeLayout, allGrantUserList []*report.ReportGrant, addReportChapterList []AddReportChapter) (reportId int64, err error) {
- to := global.DbMap[utils.DbNameReport].Begin()
- defer func() {
- if err != nil {
- _ = to.Rollback()
- } else {
- _ = to.Commit()
- }
- }()
- // 新增报告
- err = to.Create(reportItem).Error
- if err != nil {
- return
- }
- reportId = int64(reportItem.Id)
- // 新增报告分页内容
- if len(reportFreeLayoutList) > 0 {
- for _, reportFreeLayout := range reportFreeLayoutList {
- reportFreeLayout.ReportId = int(reportId)
- }
- err = to.CreateInBatches(reportFreeLayoutList, utils.MultiAddNum).Error
- if err != nil {
- return
- }
- }
- // 新增报告授权
- if len(allGrantUserList) > 0 {
- for _, v := range allGrantUserList {
- v.ReportId = reportItem.Id
- }
- err = to.CreateInBatches(allGrantUserList, utils.MultiAddNum).Error
- if err != nil {
- return
- }
- }
- // 新增报告章节
- if len(addReportChapterList) > 0 {
- for _, addReportChapter := range addReportChapterList {
- // 新增章节
- chapterItem := addReportChapter.ReportChapter
- chapterItem.ReportId = int(reportId)
- tmpErr := to.Create(chapterItem).Error
- if tmpErr != nil {
- err = tmpErr
- return
- }
- // 新增章节授权
- if len(addReportChapter.GrantList) > 0 {
- grantList := addReportChapter.GrantList
- for _, v := range grantList {
- v.ReportChapterId = chapterItem.ReportChapterId
- }
- err = to.CreateInBatches(grantList, utils.MultiAddNum).Error
- if err != nil {
- return
- }
- }
- // 新增报告章节关联的品种
- if len(addReportChapter.GrantPermissionList) > 0 {
- permissionList := addReportChapter.GrantPermissionList
- for _, v := range permissionList {
- v.ReportChapterId = chapterItem.ReportChapterId
- }
- err = to.CreateInBatches(permissionList, utils.MultiAddNum).Error
- if err != nil {
- return
- }
- }
- // 新增报告章节分页内容
- if len(addReportChapter.ReportChapterFreeLayoutList) > 0 {
- reportChapterFreeLayoutList := addReportChapter.ReportChapterFreeLayoutList
- for _, reportChapterFreeLayout := range reportChapterFreeLayoutList {
- reportChapterFreeLayout.ReportId = int(reportId)
- reportChapterFreeLayout.ReportChapterId = chapterItem.ReportChapterId
- }
- err = to.CreateInBatches(reportChapterFreeLayoutList, utils.MultiAddNum).Error
- if err != nil {
- return
- }
- }
- }
- }
- return
- }
- // EditReportAndPermission
- // @Description: 修改报告的基础信息、授权用户权限
- // @author: Roc
- // @datetime 2024-06-06 17:11:12
- // @param reportInfo *Report
- // @param updateCols []string
- // @param addReportGrantList []*report.ReportGrant
- // @param delReportGrantIdList []int
- // @return err error
- func EditReportAndPermission(reportInfo *Report, updateCols []string, addReportGrantList []*report.ReportGrant, delReportGrantIdList []int) (err error) {
- to := global.DbMap[utils.DbNameReport].Begin()
- defer func() {
- if err != nil {
- _ = to.Rollback()
- } else {
- _ = to.Commit()
- }
- }()
- // 变更报告章节信息
- if len(updateCols) > 0 {
- err = to.Select(updateCols).Updates(reportInfo).Error
- if err != nil {
- return
- }
- }
- // 新增报告授权用户
- if len(addReportGrantList) > 0 {
- err = to.CreateInBatches(addReportGrantList, utils.MultiAddNum).Error
- if err != nil {
- return
- }
- }
- // 删除报告授权用户
- delNum := len(delReportGrantIdList)
- if delNum > 0 {
- sql := `DELETE FROM report_grant WHERE grant_id IN (` + utils.GetOrmInReplace(delNum) + `)`
- err = to.Exec(sql, delReportGrantIdList).Error
- if err != nil {
- return
- }
- }
- return
- }
- // AddChapterBaseInfoAndPermission
- // @Description: 新增报告章节的基础信息、授权用户权限
- // @author: Roc
- // @datetime 2024-06-11 15:33:50
- // @param reportChapterInfo *ReportChapter
- // @param addReportChapterGrantList []*report.ReportChapterGrant
- // @param addChapterPermissionMap []*report.ReportChapterPermissionMapping
- // @return err error
- func AddChapterBaseInfoAndPermission(reportChapterInfo *ReportChapter, addReportChapterGrantList []*report.ReportChapterGrant, addChapterPermissionMap []*report.ReportChapterPermissionMapping) (err error) {
- to := global.DbMap[utils.DbNameReport].Begin()
- defer func() {
- if err != nil {
- _ = to.Rollback()
- } else {
- _ = to.Commit()
- }
- }()
- err = to.Create(reportChapterInfo).Error
- if err != nil {
- return
- }
- // 新增报告章节授权用户
- if len(addReportChapterGrantList) > 0 {
- for k, _ := range addReportChapterGrantList {
- addReportChapterGrantList[k].ReportChapterId = reportChapterInfo.ReportChapterId
- }
- err = to.CreateInBatches(addReportChapterGrantList, utils.MultiAddNum).Error
- if err != nil {
- return
- }
- }
- // 新增报告章节关联的品种配置
- if len(addChapterPermissionMap) > 0 {
- for k, _ := range addChapterPermissionMap {
- addChapterPermissionMap[k].ReportChapterId = reportChapterInfo.ReportChapterId
- }
- err = to.CreateInBatches(addChapterPermissionMap, utils.MultiAddNum).Error
- if err != nil {
- return
- }
- }
- return
- }
- // EditChapterBaseInfoAndPermission
- // @Description: 修改报告章节的基础信息、授权用户权限、品种权限
- // @author: Roc
- // @datetime 2024-06-05 11:45:04
- // @param reportChapterInfo *ReportChapter
- // @param updateCols []string
- // @param addReportChapterGrantList []report.ReportChapterGrant
- // @param addChapterPermissionMap []*report.ReportChapterPermissionMapping
- // @param delReportChapterGrantIdList []int
- // @param delChapterPermissionMappingIdList []int
- // @return err error
- func EditChapterBaseInfoAndPermission(reportInfo *Report, reportChapterInfo *ReportChapter, updateCols []string, addReportChapterGrantList []*report.ReportChapterGrant, addChapterPermissionMap []*report.ReportChapterPermissionMapping, delReportChapterGrantIdList, delChapterPermissionMappingIdList []int) (err error) {
- to := global.DbMap[utils.DbNameReport].Begin()
- defer func() {
- if err != nil {
- _ = to.Rollback()
- } else {
- _ = to.Commit()
- }
- }()
- // 变更报告的最后编辑人信息
- {
- err = to.Select([]string{"LastModifyAdminId", "LastModifyAdminName", "ModifyTime"}).Updates(reportInfo).Error
- if err != nil {
- return
- }
- }
- // 变更报告章节信息
- if len(updateCols) > 0 {
- err = to.Select(updateCols).Updates(reportChapterInfo).Error
- if err != nil {
- return
- }
- }
- // 新增报告章节授权用户
- if len(addReportChapterGrantList) > 0 {
- err = to.CreateInBatches(addReportChapterGrantList, utils.MultiAddNum).Error
- if err != nil {
- return
- }
- }
- // 删除报告章节授权用户
- delNum := len(delReportChapterGrantIdList)
- if delNum > 0 {
- sql := `DELETE FROM report_chapter_grant WHERE grant_id IN (` + utils.GetOrmInReplace(delNum) + `)`
- err = to.Exec(sql, delReportChapterGrantIdList).Error
- if err != nil {
- return
- }
- }
- // 新增报告章节的品种配置
- if len(addChapterPermissionMap) > 0 {
- err = to.CreateInBatches(addChapterPermissionMap, utils.MultiAddNum).Error
- if err != nil {
- return
- }
- }
- // 删除报告章节的品种配置
- delNum = len(delChapterPermissionMappingIdList)
- if delNum > 0 {
- sql := `DELETE FROM report_chapter_permission_mapping WHERE report_chapter_permission_mapping_id IN (` + utils.GetOrmInReplace(delNum) + `)`
- err = to.Exec(sql, delChapterPermissionMappingIdList).Error
- if err != nil {
- return
- }
- }
- return
- }
- // DelChapterAndPermission
- // @Description: 删除报告章节、授权用户权限、品种权限
- // @author: Roc
- // @datetime 2024-06-06 17:25:47
- // @param reportInfo *Report
- // @param updateReportCols []string
- // @param reportChapterInfo *ReportChapter
- // @return err error
- func DelChapterAndPermission(reportInfo *Report, updateReportCols []string, reportChapterInfo *ReportChapter) (err error) {
- to := global.DbMap[utils.DbNameReport].Begin()
- defer func() {
- if err != nil {
- _ = to.Rollback()
- } else {
- _ = to.Commit()
- }
- }()
- // 变更报告信息
- if len(updateReportCols) > 0 {
- err = to.Select(updateReportCols).Updates(reportInfo).Error
- if err != nil {
- return
- }
- }
- // 删除报告对应章节
- {
- err = to.Delete(reportChapterInfo).Error
- if err != nil {
- return
- }
- }
- // 删除报告章节的授权用户权限
- {
- sql := `DELETE FROM report_chapter_grant WHERE report_chapter_id = ? `
- err = to.Exec(sql, reportChapterInfo.ReportChapterId).Error
- if err != nil {
- return
- }
- }
- // 删除报告章节的品种配置
- {
- sql := `DELETE FROM report_chapter_permission_mapping WHERE report_chapter_id = ? `
- err = to.Exec(sql, reportChapterInfo.ReportChapterId).Error
- if err != nil {
- return
- }
- }
- return
- }
- // GetReportListCountByAuthorized
- // @Description: 获取有权限的报告列表的报告数量
- // @author: Roc
- // @datetime 2024-05-30 15:14:01
- // @param condition string
- // @param pars []interface{}
- // @return count int
- // @return err error
- func GetReportListCountByAuthorized(condition string, pars []interface{}) (count int, err error) {
- o := global.DbMap[utils.DbNameReport]
- sql := `SELECT COUNT(1) AS count FROM report as a WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- var countNull sql2.NullInt64
- err = o.Raw(sql, pars...).Scan(&countNull).Error
- if err != nil {
- return
- }
- if countNull.Valid {
- count = int(countNull.Int64)
- }
- return
- }
- // GetReportListByAuthorized
- // @Description: 获取有权限的报告列表的数据
- // @author: Roc
- // @datetime 2024-05-30 15:15:07
- // @param condition string
- // @param pars []interface{}
- // @param startSize int
- // @param pageSize int
- // @return items []*ReportList
- // @return err error
- func GetReportListByAuthorized(condition string, pars []interface{}, startSize, pageSize int) (items []*ReportList, err error) {
- o := global.DbMap[utils.DbNameReport]
- sql := `SELECT id,classify_id_first,classify_name_first,classify_id_second,classify_name_second,classify_id_third,classify_name_third,title,stage,create_time,author,report_layout,collaborate_type,is_public_publish,abstract,has_chapter,publish_time FROM report as a WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- // 排序:1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过
- sql += ` GROUP BY a.id ORDER BY report_create_time DESC LIMIT ?,?`
- pars = append(pars, startSize, pageSize)
- err = o.Raw(sql, pars...).Find(&items).Error
- return
- }
- // ModifyReportClassifyAndReportChapterTypeByCondition
- // @Description:
- // @author: Roc
- // @datetime 2024-06-17 16:12:44
- // @param condition string
- // @param pars []interface{}
- // @param updateStr string
- // @param chapterTypeIdMap map[int]int 当前的章节类型ID ---> 继承的章节类型ID
- // @param oldClassifyId int
- // @param currClassifyId int
- // @param currClassifyName string
- // @return err error
- func ModifyReportClassifyAndReportChapterTypeByCondition(condition string, pars []interface{}, updateStr string, chapterTypeIdMap map[int]int, oldClassifyId, currClassifyId int, currClassifyName string) (err error) {
- to := global.DbMap[utils.DbNameReport].Begin()
- defer func() {
- if err != nil {
- _ = to.Rollback()
- } else {
- _ = to.Commit()
- }
- }()
- if condition == `` {
- err = errors.New("condition不能为空")
- return
- }
- // 修改报告的所属分类
- sql := `UPDATE report as a SET ` + updateStr + ` WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- err = to.Exec(sql, pars...).Error
- if err != nil {
- return
- }
- // 修改历史报告中的章节分类归属
- sql = `UPDATE report_chapter set classify_id_first=?,classify_name_first=? where classify_id_first = ?`
- err = to.Exec(sql, currClassifyId, currClassifyName, oldClassifyId).Error
- if err != nil {
- return
- }
- for currTypeId, oldTypeId := range chapterTypeIdMap {
- // 没有章节类型的不处理
- if oldTypeId == 0 {
- continue
- }
- tmpSql := `UPDATE report_chapter set type_id=? where type_id = ?`
- err = to.Exec(tmpSql, currTypeId, oldTypeId).Error
- if err != nil {
- return
- }
- }
- return
- }
- // EditLayoutImgReq
- // @Description: 版图设置请求
- type EditLayoutImgReq struct {
- ReportId int64 `description:"报告id"`
- HeadImg string `description:"报告头图地址"`
- EndImg string `description:"报告尾图地址"`
- CanvasColor string `description:"画布颜色"`
- HeadResourceId int `description:"版头资源ID"`
- EndResourceId int `description:"版尾资源ID"`
- }
- type ExportReportItem struct {
- Total int
- AdminId int
- AdminName string
- ClassifyIdFirst int
- ClassifyNameFirst string
- ClassifyIdSecond int
- ClassifyNameSecond string
- }
- func GetExportReportList(startDate, endDate string, otherReportClassifyIdList []int) (items []*ExportReportItem, err error) {
- otherReportClassifyIdList = append(otherReportClassifyIdList, 229) //固收报告,权益的
- o := global.DbMap[utils.DbNameReport]
- sql := `SELECT
- count(1) total,admin_id,admin_real_name admin_name,classify_id_first,classify_name_first
- FROM
- report
- WHERE
- create_time >= ?
- AND create_time < ?
- AND has_chapter =0
- AND state IN (2,6)
- `
- pars := []interface{}{startDate, endDate}
- if len(otherReportClassifyIdList) > 0 {
- sql += ` AND classify_id_first not in (?)`
- pars = append(pars, otherReportClassifyIdList)
- }
- sql += ` GROUP BY admin_id,classify_id_first; `
- err = o.Raw(sql, pars...).Find(&items).Error
- return
- }
- func GetExportReportListByClassifyIdList(startDate, endDate string, classifyIdList []int) (items []*ExportReportItem, err error) {
- o := global.DbMap[utils.DbNameReport]
- sql := `SELECT
- count(1) total,admin_id,admin_real_name admin_name,classify_id_first,classify_name_first
- FROM
- report
- WHERE
- create_time >= ?
- AND create_time < ?
- AND classify_id_first in (?)
- AND state IN (2,6)
- GROUP BY admin_id,classify_id_first; `
- err = o.Raw(sql, startDate, endDate, classifyIdList).Find(&items).Error
- return
- }
- func GetExportHongGuanReportListByClassifyIdList(startDate, endDate string, classifyIdList []int) (items []*ExportReportItem, err error) {
- o := global.DbMap[utils.DbNameReport]
- sql := `SELECT
- count(1) total,admin_id,admin_real_name admin_name,classify_id_first,classify_name_first,classify_id_second,classify_name_second
- FROM
- report
- WHERE
- create_time >= ?
- AND create_time < ?
- AND classify_id_first in (?)
- AND state IN (2,6)
- GROUP BY admin_id,classify_id_second; `
- err = o.Raw(sql, startDate, endDate, classifyIdList).Find(&items).Error
- return
- }
- func GetExportReportChapterList(startDate, endDate string, otherReportClassifyIdList []int) (items []*ExportReportItem, err error) {
- otherReportClassifyIdList = append(otherReportClassifyIdList, 229) //固收报告,权益的
- o := global.DbMap[utils.DbNameReport]
- sql := `SELECT count(1) total,b.last_modify_admin_id admin_id,b.last_modify_admin_name admin_name,a.classify_id_first,a.classify_name_first
- FROM report as a
- join report_chapter b on a.id = b.report_id
- WHERE
- a.create_time > ?
- AND a.create_time < ?
- AND a.state IN (2,6)
- AND a.has_chapter =1
- AND b.publish_state=2 `
- pars := []interface{}{startDate, endDate}
- if len(otherReportClassifyIdList) > 0 {
- sql += ` AND a.classify_id_first not in (?)`
- pars = append(pars, otherReportClassifyIdList)
- }
- sql += ` GROUP BY b.last_modify_admin_id,a.classify_id_first; `
- err = o.Raw(sql, pars...).Find(&items).Error
- return
- }
- // GetExportVoiceBroadcastList
- // @Description: 获取语音播报统计数据
- // @param startDate
- // @param endDate
- // @return items
- // @return err
- func GetExportVoiceBroadcastList(startDate, endDate string) (items []*ExportReportItem, err error) {
- o := global.DbMap[utils.DbNameWeekly]
- sql := `SELECT
- author_id admin_id,author admin_name,count(1) total
- FROM
- yb_voice_broadcast
- where publish_time>=? AND publish_time< ? and publish_state=1
- GROUP BY
- author_id`
- err = o.Raw(sql, startDate, endDate).Find(&items).Error
- return
- }
- type ExportEnglishReportItem struct {
- Total int
- AdminId int
- AdminName string
- FirstClassifyId int
- FirstClassifyName string
- SecondClassifyId int
- SecondClassifyName string
- ThirdClassifyId int
- ThirdClassifyName string
- }
- func GetExportEnglishReportList(startDate, endDate string) (items []*ExportEnglishReportItem, err error) {
- o := global.DbMap[utils.DbNameReport]
- sql := `select count(1) total,admin_id,admin_real_name admin_name,classify_id_first second_classify_id,classify_name_first second_classify_name,classify_id_second third_classify_id,classify_name_second third_classify_name
- from english_report where
- publish_time >= ?
- AND publish_time < ?
- AND state IN (2,6)
- group by classify_id_first ,classify_id_second,admin_id`
- pars := []interface{}{startDate, endDate}
- err = o.Raw(sql, pars...).Find(&items).Error
- return
- }
|