Ver Fonte

Merge branch 'refs/heads/eta_2.2.0_document_manage_0919@guomengyuan' into custom

gmy há 5 meses atrás
pai
commit
722d3fc265

+ 0 - 1
controllers/base_auth.go

@@ -292,7 +292,6 @@ func (c *BaseAuthController) ServeJSON(encoding ...bool) {
 		}
 	}
 
-
 	//新增uuid记录
 	{
 		if _, ok := AdminOperateRecordMap[urlPath]; !ok && !strings.Contains(urlPath, "cygx") {

+ 430 - 0
controllers/document_manage/document_manage_controller.go

@@ -0,0 +1,430 @@
+// Package document_manage
+// @Author gmy 2024/9/19 14:09:00
+package document_manage
+
+import (
+	"encoding/json"
+	"eta/eta_api/controllers"
+	"eta/eta_api/models"
+	"eta/eta_api/models/document_manage_model"
+	"eta/eta_api/services/document_manage_service"
+	"eta/eta_api/utils"
+	"strings"
+)
+
+// DocumentManageController 文档管理库
+type DocumentManageController struct {
+	controllers.BaseAuthController
+}
+
+// ValidateUser
+// 处理响应和校验
+func ValidateUser(this *DocumentManageController, br *models.BaseResponse) bool {
+	// 验证用户是否已登录
+	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()
+
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	if !ValidateUser(this, br) {
+		return
+	}
+
+	classifyList, err := document_manage_service.DocumentClassifyList()
+	if err != nil {
+		br.Msg = "获取分类列表失败"
+		br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = classifyList
+	return
+}
+
+// DocumentVarietyList
+// @Title 文档品种列表
+// @Description 文档品种列表
+// @Success 200 {object} []models.ChartPermission
+// @router /document/variety/list [get]
+func (this *DocumentManageController) DocumentVarietyList() {
+	br := new(models.BaseResponse).Init()
+
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	if !ValidateUser(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()
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	if !ValidateUser(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")
+	var chartPermissionIdList []string
+	if strings.TrimSpace(chartPermissionIdString) != "" {
+		chartPermissionIdList = strings.Split(chartPermissionIdString, ",")
+	}
+
+	classifyIdString := this.GetString("ClassifyIdList")
+	var classifyIdList []string
+	if strings.TrimSpace(classifyIdString) != "" {
+		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()
+
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	if !ValidateUser(this, br) {
+		return
+	}
+
+	classifyIdFirst, _ := this.GetInt("ClassifyIdFirst", 0)
+	classifyIdSecond, _ := this.GetInt("ClassifyIdSecond", 0)
+	classifyIdThird, _ := this.GetInt("ClassifyIdThird", 0)
+
+	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(classifyIdFirst, classifyIdSecond, classifyIdThird, 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()
+
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	if !ValidateUser(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 {
+		if err.Error() == utils.ErrNoRow() {
+			br.Msg = "报告已被删除"
+			return
+		}
+		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()
+
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	if !ValidateUser(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.RealName
+	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()
+
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	if !ValidateUser(this, br) {
+		return
+	}
+	// 获取指标数据列表
+
+	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()
+
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	if !ValidateUser(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()
+
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	if !ValidateUser(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
+}

+ 1 - 1
go.mod

@@ -33,6 +33,7 @@ require (
 	github.com/mojocn/base64Captcha v1.3.6
 	github.com/nosixtools/solarlunar v0.0.0-20211112060703-1b6dea7b4a19
 	github.com/olivere/elastic/v7 v7.0.32
+	github.com/pdfcpu/pdfcpu v0.8.0
 	github.com/qiniu/qmgo v1.1.8
 	github.com/rdlucklib/rdluck_tools v1.0.3
 	github.com/shopspring/decimal v1.3.1
@@ -108,7 +109,6 @@ require (
 	github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
 	github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect
 	github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b // indirect
-	github.com/pdfcpu/pdfcpu v0.8.0 // indirect
 	github.com/pelletier/go-toml v1.9.2 // indirect
 	github.com/pkg/errors v0.9.1 // indirect
 	github.com/prometheus/client_golang v1.16.0 // indirect

+ 13 - 1
models/chart_permission.go

@@ -39,15 +39,27 @@ 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:"品种权限名称"`
 	ParentId       int    `description:"父级ID"`
-	IsPublic       int    `description:"是否是公有权限1:公有权限,0私有权限" `
 	Enabled        int    `description:"是否可用:1可用,0不可用" `
 	Sort           int    `description:"排序"`
 	CreateTime     string `description:"创建时间"`
 	Child          []*ChartPermissionItem
+	IsPublic       int
 }
 
 // Update 更新

+ 21 - 0
models/classify.go

@@ -46,6 +46,17 @@ type Classify struct {
 	ReportDetailShowType int       `description:"报告详情的展示类型:1-拼接;2:目录"`
 }
 
+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:"层级"`
+	Children      *[]ClassifyVO
+}
+
 type ClassifyAddReq struct {
 	ClassifyName          string `description:"分类名称"`
 	ParentId              int    `description:"父级分类id,没有父级分类传0"`
@@ -573,3 +584,13 @@ func GetClassifyListByIdList(classifyIdList []int) (items []*Classify, err error
 	_, err = o.Raw(sql, classifyIdList).QueryRows(&items)
 	return
 }
+
+// GetClassifyListByParentId 查询父分类下所有的子分类
+func GetClassifyListByParentId(parentId int) (items []*Classify, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `SELECT * FROM classify WHERE parent_id = ? and enabled = 1`
+
+	_, err = o.Raw(sql, parentId).QueryRows(&items)
+
+	return items, err
+}

+ 120 - 0
models/document_manage_model/outside_report.go

@@ -0,0 +1,120 @@
+// @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:"创建时间"`
+	ReportCode       string `orm:"column(report_code)" 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:"创建人姓名"`
+	ReportCode      string `orm:"column(report_code)" description:"报告唯一编码"`
+	ModifyTime      string `orm:"column(modify_time)" description:"最近一次修改时间"`
+	CreateTime      string `orm:"column(create_time)" 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(distinct t1.outside_report_id) 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).QueryRow(&count)
+	if err != nil {
+		return 0, err
+	}
+
+	return count, err
+}
+
+// GetOutsideReportListByCondition 根据条件查询列表
+func GetOutsideReportListByCondition(condition string, pars []interface{}, currentIndex int, pageSize int) (list []OutsideReport, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `select distinct t1.* 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
+	sql += ` limit ?, ?`
+	_, err = o.Raw(sql, pars, (currentIndex-1)*pageSize, pageSize).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")
+
+	outsideReport = &OutsideReport{}
+
+	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
+}
+
+// GetOutsideReportListByClassifyId 根据分类id查询报告列表
+func GetOutsideReportListByClassifyId(classifyId int) (list []OutsideReport, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `select * from outside_report where classify_id = ?`
+	_, err = o.Raw(sql, classifyId).QueryRows(&list)
+	if err != nil {
+		return nil, err
+	}
+
+	return list, err
+}

+ 48 - 0
models/document_manage_model/outside_report_attachment.go

@@ -0,0 +1,48 @@
+// @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:"附件新增时间"`
+	FileSize                  int64  `orm:"column(file_size)" 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
+}

+ 34 - 2
models/report.go

@@ -101,7 +101,7 @@ type ReportList struct {
 	Author             string                    `description:"作者"`
 	Frequency          string                    `description:"频度"`
 	CreateTime         string                    `description:"创建时间"`
-	ModifyTime         time.Time                 `description:"修改时间"`
+	ModifyTime         string                    `description:"修改时间"`
 	State              int                       `description:"1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过"`
 	PublishTime        string                    `description:"发布时间"`
 	PrePublishTime     string                    `description:"预发布时间"`
@@ -192,11 +192,24 @@ func GetReportListV1(condition string, pars []interface{}, startSize, pageSize i
 		sql += condition
 	}
 	// 排序:1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过
-	sql += `ORDER BY FIELD(state,3,1,4,5,6,2), modify_time DESC LIMIT ?,?`
+	sql += ` ORDER BY FIELD(state,3,1,4,5,6,2), modify_time DESC LIMIT ?,?`
 	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
 	return
 }
 
+// GetReportListByCondition 获取报告列表
+func GetReportListByCondition(condition string, pars []interface{}, startSize, pageSize int) (items []*ReportList, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+
+	sql := `SELECT * FROM report as a WHERE 1=1  `
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` LIMIT ?,?`
+	_, err = o.Raw(sql, pars, (startSize-1)*pageSize, pageSize).QueryRows(&items)
+	return
+}
+
 type ReportPvUv struct {
 	ReportId int
 	PvTotal  int
@@ -1505,3 +1518,22 @@ func GetReportFieldsByIds(ids []int, fields []string) (items []*Report, err erro
 	_, err = o.Raw(sql, ids).QueryRows(&items)
 	return
 }
+
+// GetReportListByClassifyId 根据分类id 获取报告列表
+func GetReportListByClassifyId(classifyId int) (items []*Report, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `SELECT * FROM report WHERE classify_id_first = ? or classify_id_second = ? or classify_id_third = ?`
+	_, err = o.Raw(sql, classifyId, classifyId, classifyId).QueryRows(&items)
+	return items, err
+}
+
+// UpdateReportInfo 修改报告
+func UpdateReportInfo(reports *Report) (err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	_, err = o.Update(reports)
+	if err != nil {
+		return err
+	}
+
+	return
+}

+ 81 - 0
routers/commentsRouter.go

@@ -6388,6 +6388,87 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_api/controllers/document_manage:DocumentManageController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/document_manage:DocumentManageController"],
+        beego.ControllerComments{
+            Method: "DocumentClassifyList",
+            Router: `/document/classify/list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/document_manage:DocumentManageController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/document_manage:DocumentManageController"],
+        beego.ControllerComments{
+            Method: "DocumentDelete",
+            Router: `/document/delete`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/document_manage:DocumentManageController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/document_manage:DocumentManageController"],
+        beego.ControllerComments{
+            Method: "DocumentDetail",
+            Router: `/document/detail`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/document_manage:DocumentManageController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/document_manage:DocumentManageController"],
+        beego.ControllerComments{
+            Method: "DocumentReportList",
+            Router: `/document/report/list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/document_manage:DocumentManageController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/document_manage:DocumentManageController"],
+        beego.ControllerComments{
+            Method: "DocumentRuiSiDetail",
+            Router: `/document/rui/si/detail`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/document_manage:DocumentManageController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/document_manage: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_api/controllers/document_manage:DocumentManageController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/document_manage:DocumentManageController"],
+        beego.ControllerComments{
+            Method: "DocumentSave",
+            Router: `/document/save`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/document_manage:DocumentManageController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/document_manage:DocumentManageController"],
+        beego.ControllerComments{
+            Method: "DocumentUpdate",
+            Router: `/document/update`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/document_manage:DocumentManageController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/document_manage:DocumentManageController"],
+        beego.ControllerComments{
+            Method: "DocumentVarietyList",
+            Router: `/document/variety/list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_api/controllers/english_report:EnPermissionController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/english_report:EnPermissionController"],
         beego.ControllerComments{
             Method: "Add",

+ 6 - 0
routers/router.go

@@ -22,6 +22,7 @@ import (
 	"eta/eta_api/controllers/data_manage/supply_analysis"
 	"eta/eta_api/controllers/data_source"
 	"eta/eta_api/controllers/data_stat"
+	"eta/eta_api/controllers/document_manage"
 	"eta/eta_api/controllers/english_report"
 	"eta/eta_api/controllers/eta_trial"
 	"eta/eta_api/controllers/fe_calendar"
@@ -391,6 +392,11 @@ func init() {
 				&range_analysis.RangeChartChartInfoController{},
 			),
 		),
+		web.NSNamespace("/document_manage",
+			web.NSInclude(
+				&document_manage.DocumentManageController{},
+			),
+		),
 	)
 	web.AddNamespace(ns)
 }

+ 43 - 72
services/classify.go

@@ -3,6 +3,7 @@ package services
 import (
 	"errors"
 	"eta/eta_api/models"
+	"eta/eta_api/models/document_manage_model"
 	"eta/eta_api/models/report_approve"
 	"eta/eta_api/utils"
 	"fmt"
@@ -269,83 +270,53 @@ func AddReportClassify(classifyName string, parentId int, chartPermissionIdList
 	classify.ReportDetailShowType = 1 //默认列表格式
 	classify.IsShow = 1
 	classify.Level = level
-	/*classify.Abstract = req.Abstract
-	classify.Descript = req.Descript
-	classify.Abstract = req.Abstract
-	classify.Descript = req.Descript
-	classify.ReportAuthor = req.ReportAuthor
-	classify.AuthorDescript = req.AuthorDescript
-	classify.ColumnImgUrl = req.ColumnImgUrl
-	classify.ReportImgUrl = req.ReportImgUrl
-	classify.HeadImgUrl = req.HeadImgUrl
-	classify.AvatarImgUrl = req.AvatarImgUrl
-	classify.HomeImgUrl = req.HomeImgUrl
-	classify.ClassifyLabel = req.ClassifyLabel
-	classify.ShowType = req.ShowType
-	classify.HasTeleconference = req.HasTeleconference
-	classify.VipTitle = req.VipTitle
-
-	classify.IsShow = req.IsShow
-	classify.YbFiccSort = req.YbFiccSort
-	classify.YbFiccIcon = req.YbFiccIcon
-	classify.YbFiccPcIcon = req.YbFiccPcIcon
-	classify.YbIconUrl = req.YbIconUrl
-	classify.YbBgUrl = req.YbBgUrl
-	classify.YbListImg = req.YbListImg
-	classify.YbShareBgImg = req.YbShareBgImg
-	classify.YbRightBanner = req.YbRightBanner
-	classify.RelateTel = req.RelateTel
-	classify.RelateVideo = req.RelateVideo
-	if req.ParentId > 0 {
-		parentClassify := new(models.Classify)
-		if parentClassify, err = models.GetClassifyById(req.ParentId); err != nil {
-			br.Msg = "获取父级分类信息失败"
-			br.ErrMsg = "获取父级分类信息失败, Err:" + err.Error()
-			return
-		}
-		updateParent := false
-		updateCols := make([]string, 0)
-		updateCols = append(updateCols, "HasTeleconference")
-		if req.HasTeleconference == 1 {
-			// 二级分类包含电话会,则一级分类也默认包含电话会
-			if parentClassify.HasTeleconference == 0 {
-				parentClassify.HasTeleconference = 1
-				updateParent = true
+
+	err = models.AddClassify(classify)
+	if err != nil {
+		return
+	}
+
+	// 如果父级分类下有报告,修改报告到子级分类下
+	reports, err := models.GetReportListByClassifyId(parentId)
+	if err != nil {
+		return err, "查询报告列表失败", false
+	}
+	if len(reports) > 0 {
+		for _, report := range reports {
+			if report.ClassifyIdFirst == 0 {
+				report.ClassifyIdFirst = classify.Id
+				report.ClassifyNameFirst = classifyName
+			} else if report.ClassifyIdSecond == 0 {
+				report.ClassifyIdSecond = classify.Id
+				report.ClassifyNameSecond = classifyName
+			} else {
+				report.ClassifyIdThird = classify.Id
+				report.ClassifyNameThird = classifyName
 			}
-		} else {
-			// 二级分类均无电话会,则一级分类也无电话会
-			if parentClassify.HasTeleconference == 1 {
-				child, err := models.GetClassifyChild(parentClassify.Id, "")
-				if err != nil {
-					br.Msg = "获取子分类失败"
-					br.ErrMsg = "获取子分类失败,Err:" + err.Error()
-					return
-				}
-				// 存在同一级分类下的二级分类有电话会则不变动
-				hasTel := false
-				for i := 0; i < len(child); i++ {
-					if child[i].HasTeleconference == 1 {
-						hasTel = true
-						break
-					}
-				}
-				if !hasTel {
-					parentClassify.HasTeleconference = 0
-					updateParent = true
-				}
+
+			// beego orm 不支持批量修改,所以只能一个一个修改
+			err := models.UpdateReportInfo(report)
+			if err != nil {
+				return err, "修改报告分类失败", false
 			}
 		}
-		if updateParent {
-			if err = parentClassify.UpdateClassify(updateCols); err != nil {
-				br.Msg = "更新父级分类失败"
-				br.ErrMsg = "更新父级分类失败, Err:" + err.Error()
-				return
+	}
+	outsideReports, err := document_manage_model.GetOutsideReportListByClassifyId(parentId)
+	if err != nil {
+		return err, "查询外部报告列表失败", false
+	}
+	if len(outsideReports) > 0 {
+		for _, report := range outsideReports {
+			tempReport := report
+
+			tempReport.ClassifyId = classify.Id
+			tempReport.ClassifyName = classifyName
+			// 修改报告
+			err := document_manage_model.UpdateOutsideReport(&tempReport)
+			if err != nil {
+				return err, "修改外部报告分类失败", false
 			}
 		}
-	}*/
-	err = models.AddClassify(classify)
-	if err != nil {
-		return
 	}
 
 	//获取报告分类权限列表

+ 436 - 0
services/document_manage_service/document_manage_service.go

@@ -0,0 +1,436 @@
+// @Author gmy 2024/9/19 16:45:00
+package document_manage_service
+
+import (
+	"eta/eta_api/models"
+	"eta/eta_api/models/document_manage_model"
+	"eta/eta_api/utils"
+	"fmt"
+	"github.com/beego/beego/v2/core/logs"
+	"github.com/google/uuid"
+	"github.com/rdlucklib/rdluck_tools/paging"
+	"html"
+	"strconv"
+)
+
+func DocumentClassifyList() ([]models.ClassifyVO, error) {
+	logs.Info("DocumentClassifyList")
+
+	//获取所有已启用分类
+	classifyList, err := models.GetClassifyListByKeyword(``, utils.IS_ENABLE)
+	if err != nil {
+		return nil, err
+	}
+
+	// 递归处理分类 拿到父级分类和对应的子级分类
+	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,
+			}
+			classifyVO.Children = getChildClassify(classifyList, classify.Id)
+			classifyVOList = append(classifyVOList, classifyVO)
+		}
+	}
+
+	return classifyVOList, nil
+}
+
+func getChildClassify(classifyList []*models.ClassifyList, 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 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)
+	condition += ` and product_id=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,
+				PermissionName:      chartPermission.PermissionName,
+				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,
+				PermissionName:      permission.PermissionName,
+				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 {
+		// 递归查询子分类
+		for _, classifyId := range classifyIdList {
+			id, err := strconv.Atoi(classifyId)
+			if err != nil {
+				return nil, err
+			}
+
+			if id == 0 {
+				classifyIdList = append(classifyIdList, classifyId)
+			} else {
+				childrenClassifyIdList, err := GetAllClassifyIdsByParentId(id)
+				if err != nil {
+					return nil, err
+				}
+				classifyIdList = append(classifyIdList, childrenClassifyIdList...)
+			}
+		}
+		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, startSize, pageSize)
+	if err != nil {
+		return nil, err
+	}
+	reportPage.Paging = page
+	reportPage.List = outsideReportList
+
+	return &reportPage, nil
+}
+
+// GetAllClassifyIdsByParentId 递归查询子分类
+func GetAllClassifyIdsByParentId(parentId int) ([]string, error) {
+	var classifyIdList []string
+
+	// 获取子分类
+	classifyList, err := models.GetClassifyListByParentId(parentId)
+	if err != nil {
+		return nil, err
+	}
+
+	// 遍历子分类
+	for _, classify := range classifyList {
+		classifyIdList = append(classifyIdList, strconv.Itoa(classify.Id))
+		// 递归调用
+		subClassifyIds, err := GetAllClassifyIdsByParentId(classify.Id)
+		if err != nil {
+			return nil, err
+		}
+		classifyIdList = append(classifyIdList, subClassifyIds...)
+	}
+
+	return classifyIdList, nil
+}
+
+func RuiSiReportList(classifyIdFirst, classifyIdSecond, classifyIdThird int, keyword string, orderField, orderType string, startSize, pageSize int) (*models.ReportListResp, error) {
+	logs.Info("RuiSiReportList")
+
+	var condition string
+	pars := make([]interface{}, 0)
+
+	if classifyIdFirst > 0 {
+		condition += ` AND a.classify_id_first = ? `
+		pars = append(pars, classifyIdFirst)
+	}
+	if classifyIdSecond > 0 {
+		condition += ` AND a.classify_id_second = ? `
+		pars = append(pars, classifyIdSecond)
+	}
+	if classifyIdThird > 0 {
+		condition += ` AND a.classify_id_third = ? `
+		pars = append(pars, classifyIdThird)
+	}
+	if keyword != "" {
+		condition += ` and ( a.title like ? or a.admin_real_name like ? ) `
+		pars = append(pars, "%"+keyword+"%", "%"+keyword+"%")
+	}
+
+	// 作者为 全球市场战略研究中心 PCI Research
+	condition += ` and a.author = '全球市场战略研究中心 PCI Research'`
+	// 已发布的报告
+	condition += ` and a.state = 2`
+
+	count, err := models.GetReportListCountV1(condition, pars)
+	if err != nil {
+		return nil, err
+	}
+	reportPage := models.ReportListResp{}
+
+	page := paging.GetPaging(startSize, pageSize, count)
+	if count <= 0 {
+		reportPage.Paging = page
+		return &reportPage, nil
+	}
+
+	if orderField != "" && orderType != "" {
+		condition += ` order by a.` + orderField + ` ` + orderType
+	} else {
+		condition += ` order by a.publish_time desc`
+	}
+
+	reportList, err := models.GetReportListByCondition(condition, pars, startSize, pageSize)
+	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 {
+		if err.Error() == utils.ErrNoRow() {
+			return nil, fmt.Errorf("报告已被删除")
+		}
+		return nil, err
+	}
+	reportDetail.Content = html.UnescapeString(reportDetail.Content)
+
+	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(),
+		ReportCode:       uuid.New().String(),
+	}
+	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:         html.UnescapeString(outsideReport.Content),
+		SysUserId:       outsideReport.SysUserId,
+		SysUserName:     outsideReport.SysUserName,
+		CreateTime:      outsideReport.CreateTime,
+		ModifyTime:      outsideReport.ModifyTime,
+		ReportCode:      outsideReport.ReportCode,
+		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

@@ -2747,3 +2747,8 @@ func GenerateEdbCode(num int, pre string) (edbCode string, err error) {
 
 	return
 }
+
+// GetCurrentTime 获取当前时间 格式为 2024-08-07 15:29:58
+func GetCurrentTime() string {
+	return time.Now().Format("2006-01-02 15:04:05")
+}

+ 6 - 0
utils/constants.go

@@ -340,6 +340,12 @@ const (
 	IS_NO  = 0
 )
 
+// 是否可用
+const (
+	IS_ENABLE  = 1
+	IS_DISABLE = 0
+)
+
 // FrequencyDaysMap 频度日期的map关系
 var FrequencyDaysMap = map[string]int{
 	"天": 1, "周": 7, "月": 30, "季": 90, "年": 365,