gmy 5 місяців тому
батько
коміт
64614f5af0

+ 1 - 1
.idea/vcs.xml

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project version="4">
   <component name="VcsDirectoryMappings">
-    <mapping directory="$PROJECT_DIR$" vcs="Git" />
+    <mapping directory="" vcs="Git" />
   </component>
 </project>

+ 397 - 0
controllers/document_manange/document_manage_controller.go

@@ -0,0 +1,397 @@
+// Package document_manange
+// @Author gmy 2024/9/19 14:09:00
+package document_manange
+
+import (
+	"encoding/json"
+	"eta/eta_mobile/controllers"
+	"eta/eta_mobile/models"
+	"eta/eta_mobile/models/document_manage_model"
+	"eta/eta_mobile/services/document_manage_service"
+	"eta/eta_mobile/utils"
+	"strings"
+)
+
+// DocumentManageController 文档管理库
+type DocumentManageController struct {
+	controllers.BaseAuthController
+}
+
+// HandleResponseWithValidation
+// 处理响应和校验
+func HandleResponseWithValidation(this *DocumentManageController, br *models.BaseResponse) bool {
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	// 验证用户是否已登录
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return false
+	}
+
+	return true
+}
+
+// DocumentClassifyList
+// @Title 文档分类列表
+// @Description 文档分类列表
+// @Success 200 {object} []models.ClassifyVO
+// @router /document/classify/list [get]
+func (this *DocumentManageController) DocumentClassifyList() {
+	br := new(models.BaseResponse).Init()
+
+	if !HandleResponseWithValidation(this, br) {
+		return
+	}
+	sysUser := this.SysUser
+	classifyList, err := document_manage_service.DocumentClassifyList(sysUser.AdminId)
+	if err != nil {
+		br.Msg = "获取分类列表失败"
+		br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = classifyList
+	return
+}
+
+// DocumentCollectClassify
+// @Title 收藏/取消分类
+// @Description 收藏/取消分类
+// @Success 200 “操作成功”
+// @router /document/collect/classify [post]
+func (this *DocumentManageController) DocumentCollectClassify() {
+	br := new(models.BaseResponse).Init()
+
+	if !HandleResponseWithValidation(this, br) {
+		return
+	}
+
+	sysUser := this.SysUser
+	type collectClassify struct {
+		ClassifyId int `json:"ClassifyId"`
+	}
+
+	var req *collectClassify
+	if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + e.Error()
+		return
+	}
+
+	err := document_manage_service.DocumentCollectClassify(req.ClassifyId, sysUser.AdminId)
+	if err != nil {
+		br.Msg = "收藏分类失败"
+		br.ErrMsg = "收藏分类失败,Err:" + err.Error()
+		return
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "操作成功"
+	return
+}
+
+// DocumentVarietyList
+// @Title 文档品种列表
+// @Description 文档品种列表
+// @Success 200 {object} []models.ChartPermission
+// @router /document/variety/list [get]
+func (this *DocumentManageController) DocumentVarietyList() {
+	br := new(models.BaseResponse).Init()
+
+	if !HandleResponseWithValidation(this, br) {
+		return
+	}
+
+	chartPermissionList, err := document_manage_service.DocumentVarietyList()
+	if err != nil {
+		br.Msg = "获取品种列表失败"
+		br.ErrMsg = "获取品种列表失败,Err:" + err.Error()
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = chartPermissionList
+	return
+}
+
+// DocumentReportList
+// @Title 文档管理库报告列表
+// @Description 文档管理库报告列表
+// @Success 200 {object} document_manage_model.OutsideReportPage
+// @router /document/report/list [get]
+func (this *DocumentManageController) DocumentReportList() {
+	br := new(models.BaseResponse).Init()
+
+	if !HandleResponseWithValidation(this, br) {
+		return
+	}
+	// 文档类型 1-文档管理库 2-战研中心-pci
+	documentType, err := this.GetInt("DocumentType")
+	if err != nil {
+		br.Msg = "获取文档类型失败"
+		br.ErrMsg = "获取文档类型失败,Err:" + err.Error()
+		return
+	}
+	if documentType == 0 {
+		br.Msg = "文档类型不能为空"
+		br.ErrMsg = "文档类型不能为空"
+		return
+	}
+
+	chartPermissionIdString := this.GetString("ChartPermissionIdList")
+	chartPermissionIdList := strings.Split(chartPermissionIdString, ",")
+
+	classifyIdString := this.GetString("ClassifyIdList")
+	classifyIdList := strings.Split(classifyIdString, ",")
+
+	keyword := this.GetString("Keyword")
+	orderField := this.GetString("OrderField")
+	orderType := this.GetString("OrderType")
+
+	pageSize, _ := this.GetInt("PageSize")
+	currentIndex, _ := this.GetInt("CurrentIndex")
+	if pageSize <= 0 {
+		pageSize = utils.PageSize20
+	}
+	if currentIndex <= 0 {
+		currentIndex = 1
+	}
+	documentReportPage, err := document_manage_service.DocumentReportList(documentType, chartPermissionIdList, classifyIdList, keyword, orderField, orderType, currentIndex, pageSize)
+	if err != nil {
+		br.Msg = "获取报告列表失败"
+		br.ErrMsg = "获取报告列表失败,Err:" + err.Error()
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = documentReportPage
+	return
+}
+
+// RuiSiReportList
+// @Title 睿思报告列表
+// @Description 睿思报告列表
+// @Success 200 {object} models.ReportListResp
+// @router /document/rui/si/report/list [get]
+func (this *DocumentManageController) RuiSiReportList() {
+	br := new(models.BaseResponse).Init()
+
+	if !HandleResponseWithValidation(this, br) {
+		return
+	}
+
+	classifyIdFirstString := this.GetString("classifyIdFirstList")
+	classifyIdFirstList := strings.Split(classifyIdFirstString, ",")
+
+	classifyIdSecondString := this.GetString("classifyIdSecondList")
+	classifyIdSecondList := strings.Split(classifyIdSecondString, ",")
+
+	classifyIdThirdString := this.GetString("classifyIdThirdList")
+	classifyIdThirdList := strings.Split(classifyIdThirdString, ",")
+
+	keyword := this.GetString("Keyword")
+	orderField := this.GetString("OrderField")
+	orderType := this.GetString("OrderType")
+
+	pageSize, _ := this.GetInt("PageSize")
+	currentIndex, _ := this.GetInt("CurrentIndex")
+	if pageSize <= 0 {
+		pageSize = utils.PageSize20
+	}
+	if currentIndex <= 0 {
+		currentIndex = 1
+	}
+	RuiSiReportPage, err := document_manage_service.RuiSiReportList(classifyIdFirstList, classifyIdSecondList, classifyIdThirdList, keyword, orderField, orderType, currentIndex, pageSize)
+	if err != nil {
+		br.Msg = "获取报告列表失败"
+		br.ErrMsg = "获取报告列表失败,Err:" + err.Error()
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = RuiSiReportPage
+	return
+}
+
+// DocumentRuiSiDetail
+// @Title 睿思报告详情
+// @Description 睿思报告详情
+// @Success 200 “获取成功”
+// @router /document/rui/si/detail [get]
+func (this *DocumentManageController) DocumentRuiSiDetail() {
+	br := new(models.BaseResponse).Init()
+
+	if !HandleResponseWithValidation(this, br) {
+		return
+	}
+	// 获取指标数据列表
+	this.GetString("DocumentRuiSiDetail")
+
+	reportId, err := this.GetInt("ReportId")
+	if err != nil {
+		br.Msg = "获取报告ID失败"
+		br.ErrMsg = "获取报告ID失败,Err:" + err.Error()
+		return
+	}
+
+	reportDetail, err := document_manage_service.DocumentRuiSiDetail(reportId)
+	if err != nil {
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = &reportDetail
+	return
+}
+
+// DocumentSave
+// @Title 新建文档
+// @Description 新建文档
+// @Success 200 “操作成功”
+// @router /document/save [post]
+func (this *DocumentManageController) DocumentSave() {
+	br := new(models.BaseResponse).Init()
+
+	if !HandleResponseWithValidation(this, br) {
+		return
+	}
+
+	sysUser := this.SysUser
+	var req *document_manage_model.OutsideReportBO
+	if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + e.Error()
+		return
+	}
+
+	req.SysUserId = sysUser.AdminId
+	req.SysUserName = sysUser.AdminName
+	err := document_manage_service.DocumentSave(req)
+	if err != nil {
+		br.Msg = "保存文档失败"
+		br.ErrMsg = "保存文档失败,Err:" + err.Error()
+		return
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "操作成功"
+	return
+}
+
+// DocumentDetail
+// @Title 文档详情
+// @Description 文档详情
+// @Success 200 “操作成功”
+// @router /document/detail [get]
+func (this *DocumentManageController) DocumentDetail() {
+	br := new(models.BaseResponse).Init()
+
+	if !HandleResponseWithValidation(this, br) {
+		return
+	}
+	// 获取指标数据列表
+	this.GetString("ChartPermissionId")
+
+	outsideReportId, err := this.GetInt("OutsideReportId")
+	if err != nil {
+		br.Msg = "获取报告ID失败"
+		br.ErrMsg = "获取报告ID失败,Err:" + err.Error()
+		return
+	}
+
+	reportDetail, err := document_manage_service.DocumentReportDetail(outsideReportId)
+	if err != nil {
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = &reportDetail
+	return
+}
+
+// DocumentUpdate
+// @Title 编辑文档
+// @Description 编辑文档
+// @Success 200 “操作成功”
+// @router /document/update [post]
+func (this *DocumentManageController) DocumentUpdate() {
+	br := new(models.BaseResponse).Init()
+
+	if !HandleResponseWithValidation(this, br) {
+		return
+	}
+
+	var req *document_manage_model.OutsideReportBO
+	if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + e.Error()
+		return
+	}
+	err := document_manage_service.DocumentUpdate(req)
+	if err != nil {
+		br.Msg = "修改文档失败"
+		br.ErrMsg = "修改文档失败,Err:" + err.Error()
+		return
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "操作成功"
+	return
+}
+
+// DocumentDelete
+// @Title 删除文档
+// @Description 删除文档
+// @Success 200 “操作成功”
+// @router /document/delete [post]
+func (this *DocumentManageController) DocumentDelete() {
+	br := new(models.BaseResponse).Init()
+
+	if !HandleResponseWithValidation(this, br) {
+		return
+	}
+
+	type DocumentDelete struct {
+		OutsideReportId int `json:"OutsideReportId"`
+	}
+
+	var req *DocumentDelete
+	if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + e.Error()
+		return
+	}
+	err := document_manage_service.DocumentDelete(req.OutsideReportId)
+	if err != nil {
+		br.Msg = "删除文档失败"
+		br.ErrMsg = "删除文档失败,Err:" + err.Error()
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "操作成功"
+	return
+}

+ 12 - 0
models/chart_permission.go

@@ -35,6 +35,18 @@ type ChartPermission struct {
 	IsPublic              int       `description:"是否是公有权限1:公有权限,0私有权限" json:"is_public"`
 }
 
+type ChartPermissionVO struct {
+	ChartPermissionId   int       `orm:"column(chart_permission_id);pk" description:"问题ID" json:"chart_permission_id"`
+	ChartPermissionName string    `description:"名称" json:"chart_permission_name"`
+	PermissionName      string    `description:"权限名" json:"permission_name"`
+	Sort                int       `description:"排序" json:"sort"`
+	Enabled             int       `description:"是否可用" json:"enabled"`
+	CreatedTime         time.Time `description:"创建时间" json:"created_time"`
+	LastUpdatedTime     time.Time `description:"更新时间" json:"last_updated_time"`
+	ParentId            int       `description:"父级权限id" json:"parent_id"`
+	Children            []*ChartPermissionVO
+}
+
 type ChartPermissionItem struct {
 	PermissionId   int    `description:"品种权限ID"`
 	PermissionName string `description:"品种权限名称"`

+ 27 - 0
models/classify.go

@@ -40,6 +40,20 @@ type Classify struct {
 	RelateTel         int       `description:"是否在电话会中可选: 0-否; 1-是"`
 	RelateVideo       int       `description:"是否在路演视频中可选: 0-否; 1-是"`
 	IsMassSend        int       `description:"1:群发,0:非群发"`
+	Enabled           int       `description:"是否可用,1可用,0禁用"`
+	Level             int       `description:"层级"`
+}
+
+type ClassifyVO struct {
+	Id            int    `orm:"column(id);pk"`
+	ClassifyName  string `description:"分类名称"`
+	Sort          int    `json:"-"`
+	ParentId      int    `description:"父级分类id"`
+	ClassifyLabel string `description:"分类标签"`
+	Enabled       int    `description:"是否可用,1可用,0禁用"`
+	Level         int    `description:"层级"`
+	IsCollect     int    `description:"是否收藏 1-是 0-否"`
+	Children      *[]ClassifyVO
 }
 
 type ClassifyAddReq struct {
@@ -74,6 +88,19 @@ type ClassifyAddReq struct {
 	RelateVideo       int                    `description:"是否在路演视频中可选: 0-否; 1-是"`
 }
 
+// GetClassifyListByCondition 根据条件查询列表
+func GetClassifyListByCondition(condition string, pars []interface{}) (list []Classify, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `select * from classify where 1 = 1 `
+	sql += sql + condition
+	_, err = o.Raw(sql, pars).QueryRows(&list)
+	if err != nil {
+		return nil, err
+	}
+
+	return nil, err
+}
+
 func GetClassifyByName(classifyName string, parentId int) (item *Classify, err error) {
 	sql := `SELECT * FROM classify WHERE classify_name=? AND parent_id=? `
 	o := orm.NewOrmUsingDB("rddp")

+ 138 - 0
models/document_manage_model/outside_report.go

@@ -0,0 +1,138 @@
+// @Author gmy 2024/9/19 14:53:00
+package document_manage_model
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"github.com/rdlucklib/rdluck_tools/paging"
+)
+
+type OutsideReport struct {
+	OutsideReportId  int    `orm:"column(outside_report_id);pk" description:"外部报告ID"`
+	Source           int    `orm:"column(source)" description:"来源,1:ETA系统录入;2:API接口录入;3:邮件监听录入"`
+	Title            string `orm:"column(title)" description:"报告标题"`
+	Abstract         string `orm:"column(abstract)" description:"摘要"`
+	ClassifyId       int    `orm:"column(classify_id)" description:"所属分类id"`
+	ClassifyName     string `orm:"column(classify_name)" description:"所属分类名称(整个分类链条)"`
+	Content          string `orm:"column(content)" description:"报告富文本内容"`
+	SysUserId        int    `orm:"column(sys_user_id)" description:"创建人id"`
+	SysUserName      string `orm:"column(sys_user_name)" description:"创建人姓名"`
+	EmailMessageUid  int    `orm:"column(email_message_uid)" description:"该邮件在邮箱中的唯一id"`
+	ReportUpdateTime string `orm:"column(report_update_time)" description:"报告更新时间,如果来源于邮件,那么取邮件的收件时间"`
+	ModifyTime       string `orm:"column(modify_time)" description:"最近一次修改时间"`
+	CreateTime       string `orm:"column(create_time)" description:"创建时间"`
+}
+
+type OutsideReportPage struct {
+	List   []OutsideReport    `description:"报告列表"`
+	Paging *paging.PagingItem `description:"分页数据"`
+}
+
+type OutsideReportBO struct {
+	OutsideReportId int    `orm:"column(outside_report_id);pk" description:"外部报告ID"`
+	Source          int    `orm:"column(source)" description:"来源,1:ETA系统录入;2:API接口录入;3:邮件监听录入"`
+	Title           string `orm:"column(title)" description:"报告标题"`
+	Abstract        string `orm:"column(abstract)" description:"摘要"`
+	ClassifyId      int    `orm:"column(classify_id)" description:"所属分类id"`
+	ClassifyName    string `orm:"column(classify_name)" description:"所属分类名称(整个分类链条)"`
+	Content         string `orm:"column(content)" description:"报告富文本内容"`
+	SysUserId       int    `orm:"column(sys_user_id)" description:"创建人id"`
+	SysUserName     string `orm:"column(sys_user_name)" description:"创建人姓名"`
+	AttachmentList  []*OutsideReportAttachment
+}
+
+// 在 init 函数中注册模型
+func init() {
+	orm.RegisterModel(new(OutsideReport))
+}
+
+// GetOutsideReportListByConditionCount 根据条件查询列表条数
+func GetOutsideReportListByConditionCount(condition string, pars []interface{}) (count int, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `select count(1) from outside_report t1 inner join chart_permission_search_key_word_mapping t2 on t1.classify_id = t2.classify_id  where 1 = 1 `
+	sql += sql + condition
+	err = o.Raw(sql, pars).QueryRow(&count)
+	if err != nil {
+		return 0, err
+	}
+
+	return 0, err
+}
+
+// GetOutsideReportListByCondition 根据条件查询列表
+func GetOutsideReportListByCondition(condition string, pars []interface{}) (list []OutsideReport, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `select * from outside_report t1 left join chart_permission_search_key_word_mapping t2 on t1.classify_id = t2.classify_id  where 1 = 1 `
+	sql += condition
+	_, err = o.Raw(sql, pars).QueryRows(&list)
+	if err != nil {
+		return nil, err
+	}
+
+	return list, err
+}
+
+/*// GetOutsideReportListByDocumentTypeCount 根据文档类型查询列表条数
+func GetOutsideReportListByDocumentTypeCount(documentType int, condition string, pars []interface{}) (count int, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	var sql string
+	if documentType == 1 {
+		sql = `select count(t1.OutsideReportId) from outside_report t1 left join chart_permission_search_key_word_mapping t2 on t1.classify_id = t2.classify_id  where 1 = 1 `
+	} else if documentType == 2 {
+		sql = `select count(t1.OutsideReportId) from outside_report t1 left join chart_permission_search_key_word_mapping t2  on t1.classify_id = t2.classify_id left join user_collect_classify t3 on t1.classify_id = t3.classify_id where 1 = 1 `
+	}
+
+	sql += sql + condition
+	err = o.Raw(sql, pars).QueryRow(&count)
+	if err != nil {
+		return 0, err
+	}
+
+	return 0, err
+}
+
+// GetOutsideReportListByDocumentType 根据文档类型查询列表
+func GetOutsideReportListByDocumentType(documentType int, condition string, pars []interface{}) (list []OutsideReport, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	var sql string
+	if documentType == 1 {
+		sql = `select t1.* from outside_report t1 left join chart_permission_search_key_word_mapping t2 on t1.classify_id = t2.classify_id  where 1 = 1 `
+	} else if documentType == 2 {
+		sql = `select t1.* from outside_report t1 left join chart_permission_search_key_word_mapping t2  on t1.classify_id = t2.classify_id left join user_collect_classify t3 on t1.classify_id = t3.classify_id where 1 = 1 `
+	}
+
+	sql += condition
+	_, err = o.Raw(sql, pars).QueryRows(&list)
+	if err != nil {
+		return nil, err
+	}
+
+	return list, err
+}*/
+
+// SaveOutsideReport 保存报告
+func SaveOutsideReport(outsideReport OutsideReport) (id int64, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	id, err = o.Insert(&outsideReport)
+	return
+}
+
+// GetOutsideReportById 根据ID获取报告
+func GetOutsideReportById(id int) (outsideReport *OutsideReport, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	err = o.QueryTable("outside_report").Filter("outside_report_id", id).One(&outsideReport)
+	return
+}
+
+// UpdateOutsideReport 更新报告
+func UpdateOutsideReport(outsideReport *OutsideReport) (err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	_, err = o.Update(&outsideReport)
+	return
+}
+
+// DeleteOutsideReport 删除报告
+func DeleteOutsideReport(id int) (err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	_, err = o.QueryTable("outside_report").Filter("outside_report_id", id).Delete()
+	return
+}

+ 45 - 0
models/document_manage_model/outside_report_attachment.go

@@ -0,0 +1,45 @@
+// @Author gmy 2024/9/19 15:13:00
+package document_manage_model
+
+import "github.com/beego/beego/v2/client/orm"
+
+type OutsideReportAttachment struct {
+	OutsideReportAttachmentId int    `orm:"column(outside_report_attachment_id);pk" description:"外部报告附件ID"`
+	OutsideReportId           int    `orm:"column(outside_report_id)" description:"报告id"`
+	Title                     string `orm:"column(title)" description:"附件名称"`
+	Url                       string `orm:"column(url)" description:"附件地址"`
+	CreateTime                string `orm:"column(create_time)" description:"附件新增时间"`
+}
+
+// 在 init 函数中注册模型
+func init() {
+	orm.RegisterModel(new(OutsideReportAttachment))
+}
+
+// SaveOutsideReportAttachment 保存附件
+func SaveOutsideReportAttachment(attachment *OutsideReportAttachment) (int64, error) {
+	o := orm.NewOrmUsingDB("rddp")
+	return o.Insert(attachment)
+}
+
+// GetOutsideReportAttachmentListByReportId 根据报告id获取附件列表
+func GetOutsideReportAttachmentListByReportId(outsideReportId int) ([]*OutsideReportAttachment, error) {
+	o := orm.NewOrmUsingDB("rddp")
+	var attachmentList []*OutsideReportAttachment
+	_, err := o.QueryTable("outside_report_attachment").
+		Filter("outside_report_id", outsideReportId).
+		All(&attachmentList)
+	if err != nil {
+		return nil, err
+	}
+	return attachmentList, nil
+}
+
+// DeleteReportAttachmentByReportId 根据报告id删除附件
+func DeleteReportAttachmentByReportId(outsideReportId int) error {
+	o := orm.NewOrmUsingDB("rddp")
+	_, err := o.QueryTable("outside_report_attachment").
+		Filter("outside_report_id", outsideReportId).
+		Delete()
+	return err
+}

+ 234 - 2
models/report.go

@@ -1174,11 +1174,243 @@ func ModifyReportImgUrl(reportId int, detailImgUrl string) (err error) {
 	return
 }
 
-
 // UpdatePdfUrlReportById 清空pdf相关字段
 func UpdatePdfUrlReportById(reportId int) (err error) {
 	o := orm.NewOrmUsingDB("rddp")
 	sql := `UPDATE report SET detail_img_url = '',detail_pdf_url='',modify_time=NOW() WHERE id = ? `
 	_, err = o.Raw(sql, reportId).Exec()
 	return
-}
+}
+
+func GetReportListByCollectCount(classifyIdFirst, classifyIdSecond, classifyIdThird []string, keyword, author string, enabled int) (count int, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	var params []interface{}
+
+	// SQL 主体
+	sql := `
+		SELECT COUNT(DISTINCT t.id) AS totalCount
+		FROM (
+			SELECT b.id
+			FROM report AS b
+			LEFT JOIN user_collect_classify AS a ON a.classify_id = b.classify_id_first
+			WHERE 1 = 1
+	`
+
+	// 处理 classifyIdFirst
+	if len(classifyIdFirst) > 0 {
+		sql += " AND a.classify_id IN ( " + utils.GetOrmInReplace(len(classifyIdFirst)) + " ) "
+		for _, id := range classifyIdFirst {
+			params = append(params, id)
+		}
+	}
+
+	// 处理关键词
+	if keyword != "" {
+		sql += " AND (b.title LIKE ? OR b.admin_real_name LIKE ?)"
+		params = append(params, "%"+keyword+"%", "%"+keyword+"%")
+	}
+
+	if author != "" {
+		sql += " AND b.author = ? "
+		params = append(params, author)
+	}
+
+	if enabled > 0 {
+		sql += " AND b.enabled = ? "
+		params = append(params, enabled)
+	}
+
+	// 第二段 SQL
+	sql += `
+		UNION ALL
+		SELECT b.id
+		FROM report AS b
+		LEFT JOIN user_collect_classify AS a ON a.classify_id = b.classify_id_second
+		WHERE 1 = 1
+	`
+
+	// 处理 classifyIdSecond
+	if len(classifyIdSecond) > 0 {
+		sql += " AND a.classify_id IN ( " + utils.GetOrmInReplace(len(classifyIdSecond)) + " ) "
+		for _, id := range classifyIdSecond {
+			params = append(params, id)
+		}
+	}
+
+	// 处理关键词
+	if keyword != "" {
+		sql += " AND (b.title LIKE ? OR b.admin_real_name LIKE ?)"
+		params = append(params, "%"+keyword+"%", "%"+keyword+"%")
+	}
+
+	if author != "" {
+		sql += " AND b.author = ? "
+		params = append(params, author)
+	}
+
+	if enabled > 0 {
+		sql += " AND b.enabled = ? "
+		params = append(params, enabled)
+	}
+
+	// 第三段 SQL
+	sql += `
+		UNION ALL
+		SELECT b.id
+		FROM report AS b
+		LEFT JOIN user_collect_classify AS a ON a.classify_id = b.classify_id_third
+		WHERE 1 = 1
+	`
+
+	// 处理 classifyIdThird
+	if len(classifyIdThird) > 0 {
+		sql += " AND a.classify_id IN ( " + utils.GetOrmInReplace(len(classifyIdThird)) + " ) "
+		for _, id := range classifyIdThird {
+			params = append(params, id)
+		}
+	}
+
+	// 处理关键词
+	if keyword != "" {
+		sql += " AND (b.title LIKE ? OR b.admin_real_name LIKE ?)"
+		params = append(params, "%"+keyword+"%", "%"+keyword+"%")
+	}
+
+	if author != "" {
+		sql += " AND b.author = ? "
+		params = append(params, author)
+	}
+
+	if enabled > 0 {
+		sql += " AND b.enabled = ? "
+		params = append(params, enabled)
+	}
+
+	sql += ") AS t"
+
+	// 执行 SQL 查询获取总数
+	err = o.Raw(sql, params...).QueryRow(&count)
+	return
+}
+
+func GetReportListByCollectList(classifyIdFirst, classifyIdSecond, classifyIdThird []string, keyword, orderField, orderType string, startSize, pageSize int, author string, enabled int) (items []*ReportList, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	var params []interface{}
+
+	// SQL 主体
+	sql := `
+		SELECT DISTINCT t.id, t.title, t.author, t.modify_time, t.publish_time
+		FROM (
+			SELECT b.id, b.title, b.author, b.modify_time, b.publish_time
+			FROM report AS b
+			LEFT JOIN user_collect_classify AS a ON a.classify_id = b.classify_id_first
+			WHERE 1 = 1
+	`
+
+	// 处理 classifyIdFirst
+	if len(classifyIdFirst) > 0 {
+		sql += " AND a.classify_id IN ( " + utils.GetOrmInReplace(len(classifyIdFirst)) + " ) "
+		for _, id := range classifyIdFirst {
+			params = append(params, id)
+		}
+	}
+
+	// 处理关键词
+	if keyword != "" {
+		sql += " AND (b.title LIKE ? OR b.admin_real_name LIKE ?)"
+		params = append(params, "%"+keyword+"%", "%"+keyword+"%")
+	}
+
+	if author != "" {
+		sql += " AND b.author = ? "
+		params = append(params, author)
+	}
+
+	if enabled > 0 {
+		sql += " AND b.enabled = ? "
+		params = append(params, enabled)
+	}
+
+	// 第二段 SQL
+	sql += `
+		UNION ALL
+		SELECT b.id, b.title, b.author, b.modify_time, b.publish_time
+		FROM report AS b
+		LEFT JOIN user_collect_classify AS a ON a.classify_id = b.classify_id_second
+		WHERE 1 = 1
+	`
+
+	// 处理 classifyIdSecond
+	if len(classifyIdSecond) > 0 {
+		sql += " AND a.classify_id IN ( " + utils.GetOrmInReplace(len(classifyIdSecond)) + " ) "
+		for _, id := range classifyIdSecond {
+			params = append(params, id)
+		}
+	}
+
+	// 处理关键词
+	if keyword != "" {
+		sql += " AND (b.title LIKE ? OR b.admin_real_name LIKE ?)"
+		params = append(params, "%"+keyword+"%", "%"+keyword+"%")
+	}
+
+	if author != "" {
+		sql += " AND b.author = ? "
+		params = append(params, author)
+	}
+
+	if enabled > 0 {
+		sql += " AND b.enabled = ? "
+		params = append(params, enabled)
+	}
+
+	// 第三段 SQL
+	sql += `
+		UNION ALL
+		SELECT b.id, b.title, b.author, b.modify_time, b.publish_time
+		FROM report AS b
+		LEFT JOIN user_collect_classify AS a ON a.classify_id = b.classify_id_third
+		WHERE 1 = 1
+	`
+
+	// 处理 classifyIdThird
+	if len(classifyIdThird) > 0 {
+		sql += " AND a.classify_id IN ( " + utils.GetOrmInReplace(len(classifyIdThird)) + " ) "
+		for _, id := range classifyIdThird {
+			params = append(params, id)
+		}
+	}
+
+	// 处理关键词
+	if keyword != "" {
+		sql += " AND (b.title LIKE ? OR b.admin_real_name LIKE ?)"
+		params = append(params, "%"+keyword+"%", "%"+keyword+"%")
+	}
+
+	if author != "" {
+		sql += " AND b.author = ? "
+		params = append(params, author)
+	}
+
+	if enabled > 0 {
+		sql += " AND b.enabled = ? "
+		params = append(params, enabled)
+	}
+
+	sql += ") AS t "
+
+	// 排序处理
+	if orderField != "" && orderType != "" {
+		sql += " ORDER BY " + orderField + " " + orderType
+	} else {
+		sql += " ORDER BY t.modify_time DESC, t.publish_time DESC "
+	}
+
+	// 分页
+	sql += " LIMIT ?, ?"
+	params = append(params, startSize, pageSize)
+
+	// 执行 SQL 查询
+	_, err = o.Raw(sql, params...).QueryRows(&items)
+	return
+}

+ 51 - 0
models/user_collect_classify.go

@@ -0,0 +1,51 @@
+// @Author gmy 2024/9/21 14:47:00
+package models
+
+import "github.com/beego/beego/v2/client/orm"
+
+/**
+CREATE TABLE `user_collect_classify` (
+  `user_collect_classify_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+  `classify_id` int(9) unsigned NOT NULL DEFAULT '0' COMMENT '分类id',
+  `sys_user_id` int(9) unsigned DEFAULT '0' COMMENT '收藏人用户id',
+  `create_time` datetime DEFAULT NULL COMMENT '收藏时间',
+  PRIMARY KEY (`user_collect_classify_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户收藏的分类id';
+*/
+
+type UserCollectClassify struct {
+	UserCollectClassifyId int    `orm:"column(user_collect_classify_id);pk" description:"用户收藏的分类id"`
+	ClassifyId            int    `orm:"column(classify_id)" description:"分类id"`
+	SysUserId             int    `orm:"column(sys_user_id)" description:"收藏人用户id"`
+	CreateTime            string `orm:"column(create_time)" description:"收藏时间"`
+}
+
+// GetUserCollectClassifyList 查询用户收藏的分类列表
+func GetUserCollectClassifyList(sysUserId, classifyId int) (list []*UserCollectClassify, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `SELECT * FROM user_collect_classify WHERE 1=1`
+	if sysUserId > 0 {
+		sql += ` AND sys_user_id=?`
+	}
+	if classifyId > 0 {
+		sql += ` AND classify_id=?`
+	}
+	_, err = o.Raw(sql, sysUserId, classifyId).QueryRows(&list)
+
+	return
+}
+
+// InsertUserCollectClassify 新增用户收藏的分类
+func InsertUserCollectClassify(item *UserCollectClassify) (err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	_, err = o.Insert(item)
+	return
+}
+
+// DeleteUserCollectClassify 删除分类
+func DeleteUserCollectClassify(sysUserId, classifyId int) (err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `DELETE FROM user_collect_classify WHERE sys_user_id=? AND classify_id=?`
+	_, err = o.Raw(sql, sysUserId, classifyId).Exec()
+	return
+}

+ 90 - 0
routers/commentsRouter.go

@@ -3526,6 +3526,96 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_mobile/controllers/document_manange:DocumentManageController"] = append(beego.GlobalControllerRouter["eta/eta_mobile/controllers/document_manange:DocumentManageController"],
+        beego.ControllerComments{
+            Method: "DocumentClassifyList",
+            Router: `/document/classify/list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_mobile/controllers/document_manange:DocumentManageController"] = append(beego.GlobalControllerRouter["eta/eta_mobile/controllers/document_manange:DocumentManageController"],
+        beego.ControllerComments{
+            Method: "DocumentCollectClassify",
+            Router: `/document/collect/classify`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_mobile/controllers/document_manange:DocumentManageController"] = append(beego.GlobalControllerRouter["eta/eta_mobile/controllers/document_manange:DocumentManageController"],
+        beego.ControllerComments{
+            Method: "DocumentDelete",
+            Router: `/document/delete`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_mobile/controllers/document_manange:DocumentManageController"] = append(beego.GlobalControllerRouter["eta/eta_mobile/controllers/document_manange:DocumentManageController"],
+        beego.ControllerComments{
+            Method: "DocumentDetail",
+            Router: `/document/detail`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_mobile/controllers/document_manange:DocumentManageController"] = append(beego.GlobalControllerRouter["eta/eta_mobile/controllers/document_manange:DocumentManageController"],
+        beego.ControllerComments{
+            Method: "DocumentReportList",
+            Router: `/document/report/list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_mobile/controllers/document_manange:DocumentManageController"] = append(beego.GlobalControllerRouter["eta/eta_mobile/controllers/document_manange:DocumentManageController"],
+        beego.ControllerComments{
+            Method: "DocumentRuiSiDetail",
+            Router: `/document/rui/si/detail`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_mobile/controllers/document_manange:DocumentManageController"] = append(beego.GlobalControllerRouter["eta/eta_mobile/controllers/document_manange:DocumentManageController"],
+        beego.ControllerComments{
+            Method: "RuiSiReportList",
+            Router: `/document/rui/si/report/list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_mobile/controllers/document_manange:DocumentManageController"] = append(beego.GlobalControllerRouter["eta/eta_mobile/controllers/document_manange:DocumentManageController"],
+        beego.ControllerComments{
+            Method: "DocumentSave",
+            Router: `/document/save`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_mobile/controllers/document_manange:DocumentManageController"] = append(beego.GlobalControllerRouter["eta/eta_mobile/controllers/document_manange:DocumentManageController"],
+        beego.ControllerComments{
+            Method: "DocumentUpdate",
+            Router: `/document/update`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_mobile/controllers/document_manange:DocumentManageController"] = append(beego.GlobalControllerRouter["eta/eta_mobile/controllers/document_manange:DocumentManageController"],
+        beego.ControllerComments{
+            Method: "DocumentVarietyList",
+            Router: `/document/variety/list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_mobile/controllers/english_report:EnPermissionController"] = append(beego.GlobalControllerRouter["eta/eta_mobile/controllers/english_report:EnPermissionController"],
         beego.ControllerComments{
             Method: "List",

+ 404 - 0
services/document_manage_service/document_manage_service.go

@@ -0,0 +1,404 @@
+// @Author gmy 2024/9/19 16:45:00
+package document_manage_service
+
+import (
+	"eta/eta_mobile/models"
+	"eta/eta_mobile/models/document_manage_model"
+	"eta/eta_mobile/utils"
+	"fmt"
+	"github.com/beego/beego/v2/core/logs"
+	"github.com/rdlucklib/rdluck_tools/paging"
+)
+
+func DocumentClassifyList(userId int) ([]models.ClassifyVO, error) {
+	logs.Info("DocumentClassifyList")
+
+	//获取所有已启用分类
+	var condition string
+	pars := make([]interface{}, 0)
+
+	condition = ` and enabled=?`
+	pars = append(pars, 1)
+
+	classifyList, err := models.GetClassifyListByCondition(condition, pars)
+	if err != nil {
+		return nil, err
+	}
+
+	// 查询用户已收藏的分类
+	collectClassifyList, err := models.GetUserCollectClassifyList(userId, 0)
+	if err != nil {
+		return nil, err
+	}
+	// 转换成map
+	collectClassifyMap := make(map[int]bool)
+	for _, collectClassify := range collectClassifyList {
+		collectClassifyMap[collectClassify.ClassifyId] = true
+	}
+
+	// 递归处理分类 拿到父级分类和对应的子级分类
+	classifyVOList := make([]models.ClassifyVO, 0)
+	for _, classify := range classifyList {
+
+		if classify.ParentId == 0 {
+			classifyVO := models.ClassifyVO{
+				Id:           classify.Id,
+				ClassifyName: classify.ClassifyName,
+				ParentId:     classify.ParentId,
+				Sort:         classify.Sort,
+				Enabled:      classify.Enabled,
+				Level:        classify.Level,
+			}
+			if _, ok := collectClassifyMap[classify.Id]; ok {
+				classifyVO.IsCollect = 1
+			}
+
+			classifyVO.Children = getChildClassify(classifyList, classify.Id)
+			classifyVOList = append(classifyVOList, classifyVO)
+		}
+	}
+
+	return classifyVOList, nil
+}
+
+func getChildClassify(classifyList []models.Classify, classifyId int) *[]models.ClassifyVO {
+	childList := make([]models.ClassifyVO, 0)
+	for _, classify := range classifyList {
+		if classify.ParentId == classifyId {
+			classifyVO := models.ClassifyVO{
+				Id:           classify.Id,
+				ClassifyName: classify.ClassifyName,
+				ParentId:     classify.ParentId,
+				Sort:         classify.Sort,
+				Enabled:      classify.Enabled,
+			}
+			classifyVO.Children = getChildClassify(classifyList, classify.Id)
+			childList = append(childList, classifyVO)
+		}
+	}
+	return &childList
+}
+
+func DocumentCollectClassify(userId, classifyId int) error {
+	logs.Info("DocumentCollectClassify")
+
+	// 查询用户是否已收藏该分类
+	collectClassifyList, err := models.GetUserCollectClassifyList(userId, classifyId)
+	if err != nil {
+		return err
+	}
+	if len(collectClassifyList) > 0 {
+		err := models.DeleteUserCollectClassify(userId, classifyId)
+		if err != nil {
+			return err
+		}
+	} else {
+		err = models.InsertUserCollectClassify(&models.UserCollectClassify{
+			ClassifyId: classifyId,
+			SysUserId:  userId,
+			CreateTime: utils.GetCurrentTime(),
+		})
+		if err != nil {
+			return err
+		}
+	}
+
+	return nil
+}
+
+func DocumentVarietyList() ([]models.ChartPermissionVO, error) {
+	logs.Info("DocumentVarietyList")
+
+	cp := new(models.ChartPermission)
+	var condition string
+	pars := make([]interface{}, 0)
+
+	condition = ` and enabled=?`
+	pars = append(pars, 1)
+
+	chartPermissionList, err := cp.GetItemsByCondition(condition, pars)
+	if err != nil {
+		return nil, err
+	}
+
+	// 递归处理品种 拿到父级品种和对应的子级品种
+	permissionVOList := make([]models.ChartPermissionVO, 0)
+	for _, chartPermission := range chartPermissionList {
+		if chartPermission.ParentId == 0 {
+			permissionVO := models.ChartPermissionVO{
+				ChartPermissionId:   chartPermission.ChartPermissionId,
+				ChartPermissionName: chartPermission.ChartPermissionName,
+				ParentId:            chartPermission.ParentId,
+				Enabled:             chartPermission.Enabled,
+				Sort:                chartPermission.Sort,
+				CreatedTime:         chartPermission.CreatedTime,
+			}
+			permissionVO.Children = getChildVariety(chartPermissionList, permissionVO.ChartPermissionId)
+			permissionVOList = append(permissionVOList, permissionVO)
+		}
+	}
+
+	return permissionVOList, nil
+}
+
+func getChildVariety(permissionList []*models.ChartPermission, permissionId int) []*models.ChartPermissionVO {
+	childList := make([]*models.ChartPermissionVO, 0)
+	for _, permission := range permissionList {
+		if permission.ParentId == permissionId {
+			permissionVO := models.ChartPermissionVO{
+				ChartPermissionId:   permission.ChartPermissionId,
+				ChartPermissionName: permission.ChartPermissionName,
+				ParentId:            permission.ParentId,
+				Enabled:             permission.Enabled,
+				Sort:                permission.Sort,
+				CreatedTime:         permission.CreatedTime,
+			}
+			permissionVO.Children = getChildVariety(permissionList, permissionVO.ChartPermissionId)
+			childList = append(childList, &permissionVO)
+		}
+	}
+	return childList
+
+}
+
+func DocumentReportList(documentType int, chartPermissionIdList []string, classifyIdList []string, keyword string, orderField, orderType string, startSize, pageSize int) (*document_manage_model.OutsideReportPage, error) {
+	logs.Info("DocumentVarietyList")
+
+	var condition string
+	pars := make([]interface{}, 0)
+
+	if documentType == 1 {
+		condition = ` and t1.source!=3`
+	}
+	if len(classifyIdList) > 0 {
+		condition += ` and t1.classify_id in (` + utils.GetOrmInReplace(len(classifyIdList)) + `)`
+		for _, classifyId := range classifyIdList {
+			pars = append(pars, classifyId)
+		}
+	}
+	if len(chartPermissionIdList) > 0 {
+		condition += ` and t2.chart_permission_id in (` + utils.GetOrmInReplace(len(chartPermissionIdList)) + `)`
+		for _, chartPermissionId := range chartPermissionIdList {
+			pars = append(pars, chartPermissionId)
+		}
+	}
+	if keyword != "" {
+		condition += ` and t1.title like ? or t1.sys_user_name like ?`
+		pars = append(pars, "%"+keyword+"%", "%"+keyword+"%")
+	}
+
+	count, err := document_manage_model.GetOutsideReportListByConditionCount(condition, pars)
+	if err != nil {
+		return nil, err
+	}
+	reportPage := document_manage_model.OutsideReportPage{}
+
+	page := paging.GetPaging(startSize, pageSize, count)
+	if count <= 0 {
+		reportPage.Paging = page
+		return &reportPage, nil
+	}
+
+	if orderField != "" && orderType != "" {
+		condition += ` order by t1.` + orderField + ` ` + orderType
+	} else {
+		condition += ` order by t1.modify_time desc`
+	}
+
+	outsideReportList, err := document_manage_model.GetOutsideReportListByCondition(condition, pars)
+	if err != nil {
+		return nil, err
+	}
+	reportPage.Paging = page
+	reportPage.List = outsideReportList
+
+	return &reportPage, nil
+}
+
+func RuiSiReportList(classifyIdFirst, classifyIdSecond, classifyIdThird []string, keyword, orderField, orderType string, startSize, pageSize int) (*models.ReportListResp, error) {
+	logs.Info("RuiSiReportList")
+
+	// 作者为 全球市场战略研究中心 PCI Research
+	author := "全球市场战略研究中心 PCI Research"
+	// 已发布的报告
+	enabled := 2
+
+	count, err := models.GetReportListByCollectCount(classifyIdFirst, classifyIdSecond, classifyIdThird, keyword, author, enabled)
+	if err != nil {
+		return nil, err
+	}
+	reportPage := models.ReportListResp{}
+
+	page := paging.GetPaging(startSize, pageSize, count)
+	if count <= 0 {
+		reportPage.Paging = page
+		return &reportPage, nil
+	}
+
+	reportList, err := models.GetReportListByCollectList(classifyIdFirst, classifyIdSecond, classifyIdThird, keyword, orderField, orderType, startSize, pageSize, author, enabled)
+	if err != nil {
+		return nil, err
+	}
+
+	reportPage.Paging = page
+	reportPage.List = reportList
+
+	return &reportPage, nil
+}
+
+func DocumentRuiSiDetail(reportId int) (*models.ReportDetail, error) {
+	logs.Info("DocumentRuiSiDetail")
+
+	reportDetail, err := models.GetReportById(reportId)
+	if err != nil {
+		return nil, err
+	}
+
+	return reportDetail, nil
+}
+
+func DocumentSave(outsideReport *document_manage_model.OutsideReportBO) error {
+	logs.Info("DocumentSave")
+
+	// 保存报告
+	report := document_manage_model.OutsideReport{
+		Source:           outsideReport.Source,
+		Title:            outsideReport.Title,
+		Abstract:         outsideReport.Abstract,
+		ClassifyId:       outsideReport.ClassifyId,
+		ClassifyName:     outsideReport.ClassifyName,
+		Content:          outsideReport.Content,
+		SysUserId:        outsideReport.SysUserId,
+		SysUserName:      outsideReport.SysUserName,
+		ReportUpdateTime: utils.GetCurrentTime(),
+		ModifyTime:       utils.GetCurrentTime(),
+		CreateTime:       utils.GetCurrentTime(),
+	}
+	id, err := document_manage_model.SaveOutsideReport(report)
+	if err != nil {
+		return err
+	}
+
+	// 保存附件
+	attachmentList := outsideReport.AttachmentList
+	if len(attachmentList) > 0 {
+		for _, attachment := range attachmentList {
+			if attachment.Title == "" || attachment.Url == "" {
+				continue
+			}
+			attachment.OutsideReportId = int(id)
+			attachment.CreateTime = utils.GetCurrentTime()
+			_, err := document_manage_model.SaveOutsideReportAttachment(attachment)
+			if err != nil {
+				return err
+			}
+		}
+	}
+	return err
+}
+
+func DocumentReportDetail(outsideReportId int) (*document_manage_model.OutsideReportBO, error) {
+	logs.Info("DocumentReportDetail")
+
+	outsideReport, err := document_manage_model.GetOutsideReportById(outsideReportId)
+	if err != nil {
+		return nil, err
+	}
+
+	attachmentList, err := document_manage_model.GetOutsideReportAttachmentListByReportId(outsideReportId)
+	if err != nil {
+		return nil, err
+	}
+
+	outsideReportBO := document_manage_model.OutsideReportBO{
+		OutsideReportId: outsideReportId,
+		Source:          outsideReport.Source,
+		Title:           outsideReport.Title,
+		Abstract:        outsideReport.Abstract,
+		ClassifyId:      outsideReport.ClassifyId,
+		ClassifyName:    outsideReport.ClassifyName,
+		Content:         outsideReport.Content,
+		SysUserId:       outsideReport.SysUserId,
+		SysUserName:     outsideReport.SysUserName,
+		AttachmentList:  attachmentList,
+	}
+	return &outsideReportBO, nil
+}
+
+func DocumentUpdate(outsideReport *document_manage_model.OutsideReportBO) error {
+	logs.Info("DocumentUpdate")
+	report, err := document_manage_model.GetOutsideReportById(outsideReport.OutsideReportId)
+	if err != nil {
+		return err
+	}
+
+	if report == nil {
+		return fmt.Errorf("报告不存在")
+	}
+	// 更新报告
+	if outsideReport.Title != "" {
+		report.Title = outsideReport.Title
+	}
+	if outsideReport.Abstract != "" {
+		report.Abstract = outsideReport.Abstract
+	}
+	if outsideReport.ClassifyId > 0 {
+		report.ClassifyId = outsideReport.ClassifyId
+	}
+	if outsideReport.ClassifyName != "" {
+		report.ClassifyName = outsideReport.ClassifyName
+	}
+	if outsideReport.Content != "" {
+		report.Content = outsideReport.Content
+	}
+	report.ModifyTime = utils.GetCurrentTime()
+	report.ReportUpdateTime = utils.GetCurrentTime()
+	err = document_manage_model.UpdateOutsideReport(report)
+	if err != nil {
+		return fmt.Errorf("更新报告失败, Err: %s", err.Error())
+	}
+
+	// 更新报告附件
+	attachmentList := outsideReport.AttachmentList
+	if len(attachmentList) > 0 {
+		err = document_manage_model.DeleteReportAttachmentByReportId(outsideReport.OutsideReportId)
+		if err != nil {
+			return fmt.Errorf("删除报告附件失败, Err: %s", err.Error())
+		}
+
+		for _, attachment := range attachmentList {
+			if attachment.Title == "" || attachment.Url == "" {
+				continue
+			}
+			attachment.OutsideReportId = outsideReport.OutsideReportId
+			attachment.CreateTime = utils.GetCurrentTime()
+			_, err := document_manage_model.SaveOutsideReportAttachment(attachment)
+			if err != nil {
+				return err
+			}
+		}
+	}
+	return nil
+}
+
+func DocumentDelete(outsideReportId int) error {
+	logs.Info("DocumentDelete")
+
+	report, err := document_manage_model.GetOutsideReportById(outsideReportId)
+	if err != nil {
+		return err
+	}
+	if report == nil {
+		return fmt.Errorf("报告不存在")
+	}
+
+	err = document_manage_model.DeleteOutsideReport(outsideReportId)
+	if err != nil {
+		return err
+	}
+	err = document_manage_model.DeleteReportAttachmentByReportId(outsideReportId)
+	if err != nil {
+		return err
+	}
+	return nil
+}

+ 5 - 0
utils/common.go

@@ -2427,3 +2427,8 @@ func CompareFloatByOpStrings(op string, a, b float64) bool {
 	}
 	return false
 }
+
+// GetCurrentTime 获取当前时间 格式为 2024-08-07 15:29:58
+func GetCurrentTime() string {
+	return time.Now().Format("2006-01-02 15:04:05")
+}