document_manage_service.go 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. // @Author gmy 2024/9/19 16:45:00
  2. package document_manage_service
  3. import (
  4. "eta/eta_api/models"
  5. "eta/eta_api/models/document_manage_model"
  6. "eta/eta_api/utils"
  7. "fmt"
  8. "github.com/beego/beego/v2/core/logs"
  9. "github.com/rdlucklib/rdluck_tools/paging"
  10. )
  11. func DocumentClassifyList() ([]models.ClassifyVO, error) {
  12. logs.Info("DocumentClassifyList")
  13. //获取所有已启用分类
  14. classifyList, err := models.GetClassifyListByKeyword(``, utils.IS_ENABLE)
  15. if err != nil {
  16. return nil, err
  17. }
  18. // 递归处理分类 拿到父级分类和对应的子级分类
  19. classifyVOList := make([]models.ClassifyVO, 0)
  20. for _, classify := range classifyList {
  21. if classify.ParentId == 0 {
  22. classifyVO := models.ClassifyVO{
  23. Id: classify.Id,
  24. ClassifyName: classify.ClassifyName,
  25. ParentId: classify.ParentId,
  26. Sort: classify.Sort,
  27. Enabled: classify.Enabled,
  28. Level: classify.Level,
  29. }
  30. classifyVO.Children = getChildClassify(classifyList, classify.Id)
  31. classifyVOList = append(classifyVOList, classifyVO)
  32. }
  33. }
  34. return classifyVOList, nil
  35. }
  36. func getChildClassify(classifyList []*models.ClassifyList, classifyId int) *[]models.ClassifyVO {
  37. childList := make([]models.ClassifyVO, 0)
  38. for _, classify := range classifyList {
  39. if classify.ParentId == classifyId {
  40. classifyVO := models.ClassifyVO{
  41. Id: classify.Id,
  42. ClassifyName: classify.ClassifyName,
  43. ParentId: classify.ParentId,
  44. Sort: classify.Sort,
  45. Enabled: classify.Enabled,
  46. }
  47. classifyVO.Children = getChildClassify(classifyList, classify.Id)
  48. childList = append(childList, classifyVO)
  49. }
  50. }
  51. return &childList
  52. }
  53. func DocumentVarietyList() ([]*models.ChartPermission, error) {
  54. logs.Info("DocumentVarietyList")
  55. cp := new(models.ChartPermission)
  56. var condition string
  57. pars := make([]interface{}, 0)
  58. condition = ` and enabled=?`
  59. pars = append(pars, 1)
  60. chartPermissionList, err := cp.GetItemsByCondition(condition, pars)
  61. if err != nil {
  62. return nil, err
  63. }
  64. return chartPermissionList, nil
  65. }
  66. func DocumentReportList(documentType, chartPermissionId, classifyId int, keyword string, orderField, orderType string, startSize, pageSize int) (*document_manage_model.OutsideReportPage, error) {
  67. logs.Info("DocumentVarietyList")
  68. var condition string
  69. pars := make([]interface{}, 0)
  70. if documentType == 1 {
  71. condition = ` and t1.source!=3`
  72. }
  73. if classifyId > 0 {
  74. condition += ` and t1.classify_id=?`
  75. pars = append(pars, classifyId)
  76. }
  77. if chartPermissionId > 0 {
  78. condition += ` and t2.chart_permission_id=?`
  79. pars = append(pars, chartPermissionId)
  80. }
  81. if keyword != "" {
  82. condition += ` and t1.title like ? or t1.sys_user_name like ?`
  83. pars = append(pars, "%"+keyword+"%", "%"+keyword+"%")
  84. }
  85. count, err := document_manage_model.GetOutsideReportListByConditionCount(condition, pars)
  86. if err != nil {
  87. return nil, err
  88. }
  89. reportPage := document_manage_model.OutsideReportPage{}
  90. page := paging.GetPaging(startSize, pageSize, count)
  91. if count <= 0 {
  92. reportPage.Paging = page
  93. return &reportPage, nil
  94. }
  95. if orderField != "" && orderType != "" {
  96. condition += ` order by ` + orderField + ` ` + orderType
  97. } else {
  98. condition += ` order by t1.modify_time desc`
  99. }
  100. outsideReportList, err := document_manage_model.GetOutsideReportListByCondition(condition, pars)
  101. if err != nil {
  102. return nil, err
  103. }
  104. reportPage.Paging = page
  105. reportPage.List = outsideReportList
  106. return &reportPage, nil
  107. }
  108. func RuiSiReportList(classifyList []string, keyword string, orderField, orderType string, startSize, pageSize int) (*models.ReportListResp, error) {
  109. logs.Info("RuiSiReportList")
  110. var condition string
  111. pars := make([]interface{}, 0)
  112. if len(classifyList) > 0 {
  113. // 查询所有子级分类
  114. condition += ` and t1.classify_id in (` + utils.GetOrmInReplace(len(classifyList)) + `)`
  115. }
  116. if keyword != "" {
  117. condition += ` and t1.title like ? or t1.sys_user_name like ?`
  118. pars = append(pars, "%"+keyword+"%", "%"+keyword+"%")
  119. }
  120. models.GetReportListCountV1(condition, pars)
  121. count, err := document_manage_model.GetOutsideReportListByConditionCount(condition, pars)
  122. if err != nil {
  123. return nil, err
  124. }
  125. reportPage := document_manage_model.OutsideReportPage{}
  126. page := paging.GetPaging(startSize, pageSize, count)
  127. if count <= 0 {
  128. reportPage.Paging = page
  129. return &reportPage, nil
  130. }
  131. if orderField != "" && orderType != "" {
  132. condition += ` order by ` + orderField + ` ` + orderType
  133. } else {
  134. condition += ` order by t1.modify_time desc`
  135. }
  136. outsideReportList, err := document_manage_model.GetOutsideReportListByCondition(condition, pars)
  137. if err != nil {
  138. return nil, err
  139. }
  140. reportPage.Paging = page
  141. reportPage.List = outsideReportList
  142. return &reportPage, nil
  143. }
  144. func DocumentSave(outsideReport *document_manage_model.OutsideReportBO) error {
  145. logs.Info("DocumentSave")
  146. // 保存报告
  147. report := document_manage_model.OutsideReport{
  148. Source: outsideReport.Source,
  149. Title: outsideReport.Title,
  150. Abstract: outsideReport.Abstract,
  151. ClassifyId: outsideReport.ClassifyId,
  152. ClassifyName: outsideReport.ClassifyName,
  153. Content: outsideReport.Content,
  154. SysUserId: outsideReport.SysUserId,
  155. SysUserName: outsideReport.SysUserName,
  156. ReportUpdateTime: utils.GetCurrentTime(),
  157. ModifyTime: utils.GetCurrentTime(),
  158. CreateTime: utils.GetCurrentTime(),
  159. }
  160. id, err := document_manage_model.SaveOutsideReport(report)
  161. if err != nil {
  162. return err
  163. }
  164. // 保存附件
  165. attachmentList := outsideReport.AttachmentList
  166. if len(attachmentList) > 0 {
  167. for _, attachment := range attachmentList {
  168. if attachment.Title == "" || attachment.Url == "" {
  169. continue
  170. }
  171. attachment.OutsideReportId = int(id)
  172. attachment.CreateTime = utils.GetCurrentTime()
  173. _, err := document_manage_model.SaveOutsideReportAttachment(attachment)
  174. if err != nil {
  175. return err
  176. }
  177. }
  178. }
  179. return err
  180. }
  181. func DocumentReportDetail(outsideReportId int) (*document_manage_model.OutsideReportBO, error) {
  182. logs.Info("DocumentReportDetail")
  183. outsideReport, err := document_manage_model.GetOutsideReportById(outsideReportId)
  184. if err != nil {
  185. return nil, err
  186. }
  187. attachmentList, err := document_manage_model.GetOutsideReportAttachmentListByReportId(outsideReportId)
  188. if err != nil {
  189. return nil, err
  190. }
  191. outsideReportBO := document_manage_model.OutsideReportBO{
  192. OutsideReportId: outsideReportId,
  193. Source: outsideReport.Source,
  194. Title: outsideReport.Title,
  195. Abstract: outsideReport.Abstract,
  196. ClassifyId: outsideReport.ClassifyId,
  197. ClassifyName: outsideReport.ClassifyName,
  198. Content: outsideReport.Content,
  199. SysUserId: outsideReport.SysUserId,
  200. SysUserName: outsideReport.SysUserName,
  201. AttachmentList: attachmentList,
  202. }
  203. return &outsideReportBO, nil
  204. }
  205. func DocumentUpdate(outsideReport *document_manage_model.OutsideReportBO) error {
  206. logs.Info("DocumentUpdate")
  207. report, err := document_manage_model.GetOutsideReportById(outsideReport.OutsideReportId)
  208. if err != nil {
  209. return err
  210. }
  211. if report == nil {
  212. return fmt.Errorf("报告不存在")
  213. }
  214. // 更新报告
  215. if outsideReport.Title != "" {
  216. report.Title = outsideReport.Title
  217. }
  218. if outsideReport.Abstract != "" {
  219. report.Abstract = outsideReport.Abstract
  220. }
  221. if outsideReport.ClassifyId > 0 {
  222. report.ClassifyId = outsideReport.ClassifyId
  223. }
  224. if outsideReport.ClassifyName != "" {
  225. report.ClassifyName = outsideReport.ClassifyName
  226. }
  227. if outsideReport.Content != "" {
  228. report.Content = outsideReport.Content
  229. }
  230. report.ModifyTime = utils.GetCurrentTime()
  231. report.ReportUpdateTime = utils.GetCurrentTime()
  232. err = document_manage_model.UpdateOutsideReport(report)
  233. if err != nil {
  234. return fmt.Errorf("更新报告失败, Err: %s", err.Error())
  235. }
  236. // 更新报告附件
  237. attachmentList := outsideReport.AttachmentList
  238. if len(attachmentList) > 0 {
  239. err = document_manage_model.DeleteReportAttachmentByReportId(outsideReport.OutsideReportId)
  240. if err != nil {
  241. return fmt.Errorf("删除报告附件失败, Err: %s", err.Error())
  242. }
  243. for _, attachment := range attachmentList {
  244. if attachment.Title == "" || attachment.Url == "" {
  245. continue
  246. }
  247. attachment.OutsideReportId = outsideReport.OutsideReportId
  248. attachment.CreateTime = utils.GetCurrentTime()
  249. _, err := document_manage_model.SaveOutsideReportAttachment(attachment)
  250. if err != nil {
  251. return err
  252. }
  253. }
  254. }
  255. return nil
  256. }
  257. func DocumentDelete(outsideReportId int) error {
  258. logs.Info("DocumentDelete")
  259. report, err := document_manage_model.GetOutsideReportById(outsideReportId)
  260. if err != nil {
  261. return err
  262. }
  263. if report == nil {
  264. return fmt.Errorf("报告不存在")
  265. }
  266. err = document_manage_model.DeleteOutsideReport(outsideReportId)
  267. if err != nil {
  268. return err
  269. }
  270. err = document_manage_model.DeleteReportAttachmentByReportId(outsideReportId)
  271. if err != nil {
  272. return err
  273. }
  274. return nil
  275. }