123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 |
- 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
- }
|