Browse Source

文档管理中心

gmy 7 months ago
parent
commit
4b8a0f66c6

+ 330 - 0
controllers/document_manange/document_manage_controller.go

@@ -0,0 +1,330 @@
+// Package document_manange
+// @Author gmy 2024/9/19 14:09:00
+package document_manange
+
+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
+}
+
+// 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
+	}
+
+	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()
+
+	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
+	}
+
+	chartPermissionId, err := this.GetInt("ChartPermissionId")
+	if err != nil {
+		br.Msg = "获取品种ID失败"
+		br.ErrMsg = "获取品种ID失败,Err:" + err.Error()
+		return
+	}
+
+	classifyId, err := this.GetInt("ClassifyId")
+	if err != nil {
+		br.Msg = "获取分类ID失败"
+		br.ErrMsg = "获取分类ID失败,Err:" + err.Error()
+		return
+	}
+
+	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, chartPermissionId, classifyId, 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/report/list [get]
+func (this *DocumentManageController) RuiSiReportList() {
+	br := new(models.BaseResponse).Init()
+
+	if !HandleResponseWithValidation(this, br) {
+		return
+	}
+
+	classifyIdSting := this.GetString("ClassifyIdList")
+	classifyIdList := strings.Split(classifyIdSting, ",")
+
+	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(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 = RuiSiReportPage
+	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
+}

+ 11 - 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"`

+ 100 - 0
models/document_manage_model/outside_report.go

@@ -0,0 +1,100 @@
+// @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 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).QueryRows(&list)
+	if err != nil {
+		return nil, err
+	}
+
+	return nil, 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
+}

+ 319 - 0
services/document_manage_service/document_manage_service.go

@@ -0,0 +1,319 @@
+// @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/rdlucklib/rdluck_tools/paging"
+)
+
+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.ChartPermission, 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
+	}
+
+	return chartPermissionList, nil
+}
+
+func DocumentReportList(documentType, chartPermissionId, classifyId int, 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 classifyId > 0 {
+		condition += ` and t1.classify_id=?`
+		pars = append(pars, classifyId)
+	}
+	if chartPermissionId > 0 {
+		condition += ` and t2.chart_permission_id=?`
+		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 ` + 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(classifyList []string, keyword string, orderField, orderType string, startSize, pageSize int) (*models.ReportListResp, error) {
+	logs.Info("RuiSiReportList")
+
+	var condition string
+	pars := make([]interface{}, 0)
+
+	if len(classifyList) > 0 {
+		// 查询所有子级分类
+
+		condition += ` and t1.classify_id in (` + utils.GetOrmInReplace(len(classifyList)) + `)`
+
+	}
+	if keyword != "" {
+		condition += ` and t1.title like ? or t1.sys_user_name like ?`
+		pars = append(pars, "%"+keyword+"%", "%"+keyword+"%")
+	}
+
+	models.GetReportListCountV1(condition, pars)
+
+	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 ` + 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 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

@@ -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,