document_manage_service.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  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.ChartPermissionVO, 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. // 递归处理品种 拿到父级品种和对应的子级品种
  65. permissionVOList := make([]models.ChartPermissionVO, 0)
  66. for _, chartPermission := range chartPermissionList {
  67. if chartPermission.ParentId == 0 {
  68. permissionVO := models.ChartPermissionVO{
  69. ChartPermissionId: chartPermission.ChartPermissionId,
  70. ChartPermissionName: chartPermission.ChartPermissionName,
  71. ParentId: chartPermission.ParentId,
  72. Enabled: chartPermission.Enabled,
  73. Sort: chartPermission.Sort,
  74. CreatedTime: chartPermission.CreatedTime,
  75. }
  76. permissionVO.Children = getChildVariety(chartPermissionList, permissionVO.ChartPermissionId)
  77. permissionVOList = append(permissionVOList, permissionVO)
  78. }
  79. }
  80. return permissionVOList, nil
  81. }
  82. func getChildVariety(permissionList []*models.ChartPermission, permissionId int) []*models.ChartPermissionVO {
  83. childList := make([]*models.ChartPermissionVO, 0)
  84. for _, permission := range permissionList {
  85. if permission.ParentId == permissionId {
  86. permissionVO := models.ChartPermissionVO{
  87. ChartPermissionId: permission.ChartPermissionId,
  88. ChartPermissionName: permission.ChartPermissionName,
  89. ParentId: permission.ParentId,
  90. Enabled: permission.Enabled,
  91. Sort: permission.Sort,
  92. CreatedTime: permission.CreatedTime,
  93. }
  94. permissionVO.Children = getChildVariety(permissionList, permissionVO.ChartPermissionId)
  95. childList = append(childList, &permissionVO)
  96. }
  97. }
  98. return childList
  99. }
  100. func DocumentReportList(documentType int, chartPermissionIdList []string, classifyIdList []string, keyword string, orderField, orderType string, startSize, pageSize int) (*document_manage_model.OutsideReportPage, error) {
  101. logs.Info("DocumentVarietyList")
  102. var condition string
  103. pars := make([]interface{}, 0)
  104. if documentType == 1 {
  105. condition = ` and t1.source!=3`
  106. }
  107. if len(classifyIdList) > 0 {
  108. condition += ` and t1.classify_id in (` + utils.GetOrmInReplace(len(classifyIdList)) + `)`
  109. for _, classifyId := range classifyIdList {
  110. pars = append(pars, classifyId)
  111. }
  112. }
  113. if len(chartPermissionIdList) > 0 {
  114. condition += ` and t2.chart_permission_id in (` + utils.GetOrmInReplace(len(chartPermissionIdList)) + `)`
  115. for _, chartPermissionId := range chartPermissionIdList {
  116. pars = append(pars, chartPermissionId)
  117. }
  118. }
  119. if keyword != "" {
  120. condition += ` and t1.title like ? or t1.sys_user_name like ?`
  121. pars = append(pars, "%"+keyword+"%", "%"+keyword+"%")
  122. }
  123. count, err := document_manage_model.GetOutsideReportListByConditionCount(condition, pars)
  124. if err != nil {
  125. return nil, err
  126. }
  127. reportPage := document_manage_model.OutsideReportPage{}
  128. page := paging.GetPaging(startSize, pageSize, count)
  129. if count <= 0 {
  130. reportPage.Paging = page
  131. return &reportPage, nil
  132. }
  133. if orderField != "" && orderType != "" {
  134. condition += ` order by t1.` + orderField + ` ` + orderType
  135. } else {
  136. condition += ` order by t1.modify_time desc`
  137. }
  138. outsideReportList, err := document_manage_model.GetOutsideReportListByCondition(condition, pars)
  139. if err != nil {
  140. return nil, err
  141. }
  142. reportPage.Paging = page
  143. reportPage.List = outsideReportList
  144. return &reportPage, nil
  145. }
  146. func RuiSiReportList(classifyIdFirst, classifyIdSecond, classifyIdThird int, keyword string, orderField, orderType string, startSize, pageSize int) (*models.ReportListResp, error) {
  147. logs.Info("RuiSiReportList")
  148. var condition string
  149. pars := make([]interface{}, 0)
  150. if classifyIdFirst > 0 {
  151. condition += ` AND a.classify_id_first = ? `
  152. pars = append(pars, classifyIdFirst)
  153. }
  154. if classifyIdSecond > 0 {
  155. condition += ` AND a.classify_id_second = ? `
  156. pars = append(pars, classifyIdSecond)
  157. }
  158. if classifyIdThird > 0 {
  159. condition += ` AND a.classify_id_third = ? `
  160. pars = append(pars, classifyIdThird)
  161. }
  162. if keyword != "" {
  163. condition += ` and a.title like ? or a.admin_real_name like ?`
  164. pars = append(pars, "%"+keyword+"%", "%"+keyword+"%")
  165. }
  166. // 作者为 全球市场战略研究中心 PCI Research
  167. condition += ` and a.author = '全球市场战略研究中心 PCI Research'`
  168. // 已发布的报告
  169. condition += ` and a.enabled = 2`
  170. count, err := models.GetReportListCountV1(condition, pars)
  171. if err != nil {
  172. return nil, err
  173. }
  174. reportPage := models.ReportListResp{}
  175. page := paging.GetPaging(startSize, pageSize, count)
  176. if count <= 0 {
  177. reportPage.Paging = page
  178. return &reportPage, nil
  179. }
  180. if orderField != "" && orderType != "" {
  181. condition += ` order by a.` + orderField + ` ` + orderType
  182. } else {
  183. condition += ` order by a.publish_time desc`
  184. }
  185. reportList, err := models.GetReportListV1(condition, pars, startSize, pageSize)
  186. if err != nil {
  187. return nil, err
  188. }
  189. reportPage.Paging = page
  190. reportPage.List = reportList
  191. return &reportPage, nil
  192. }
  193. func DocumentRuiSiDetail(reportId int) (*models.ReportDetail, error) {
  194. logs.Info("DocumentRuiSiDetail")
  195. reportDetail, err := models.GetReportById(reportId)
  196. if err != nil {
  197. return nil, err
  198. }
  199. return reportDetail, nil
  200. }
  201. func DocumentSave(outsideReport *document_manage_model.OutsideReportBO) error {
  202. logs.Info("DocumentSave")
  203. // 保存报告
  204. report := document_manage_model.OutsideReport{
  205. Source: outsideReport.Source,
  206. Title: outsideReport.Title,
  207. Abstract: outsideReport.Abstract,
  208. ClassifyId: outsideReport.ClassifyId,
  209. ClassifyName: outsideReport.ClassifyName,
  210. Content: outsideReport.Content,
  211. SysUserId: outsideReport.SysUserId,
  212. SysUserName: outsideReport.SysUserName,
  213. ReportUpdateTime: utils.GetCurrentTime(),
  214. ModifyTime: utils.GetCurrentTime(),
  215. CreateTime: utils.GetCurrentTime(),
  216. }
  217. id, err := document_manage_model.SaveOutsideReport(report)
  218. if err != nil {
  219. return err
  220. }
  221. // 保存附件
  222. attachmentList := outsideReport.AttachmentList
  223. if len(attachmentList) > 0 {
  224. for _, attachment := range attachmentList {
  225. if attachment.Title == "" || attachment.Url == "" {
  226. continue
  227. }
  228. attachment.OutsideReportId = int(id)
  229. attachment.CreateTime = utils.GetCurrentTime()
  230. _, err := document_manage_model.SaveOutsideReportAttachment(attachment)
  231. if err != nil {
  232. return err
  233. }
  234. }
  235. }
  236. return err
  237. }
  238. func DocumentReportDetail(outsideReportId int) (*document_manage_model.OutsideReportBO, error) {
  239. logs.Info("DocumentReportDetail")
  240. outsideReport, err := document_manage_model.GetOutsideReportById(outsideReportId)
  241. if err != nil {
  242. return nil, err
  243. }
  244. attachmentList, err := document_manage_model.GetOutsideReportAttachmentListByReportId(outsideReportId)
  245. if err != nil {
  246. return nil, err
  247. }
  248. outsideReportBO := document_manage_model.OutsideReportBO{
  249. OutsideReportId: outsideReportId,
  250. Source: outsideReport.Source,
  251. Title: outsideReport.Title,
  252. Abstract: outsideReport.Abstract,
  253. ClassifyId: outsideReport.ClassifyId,
  254. ClassifyName: outsideReport.ClassifyName,
  255. Content: outsideReport.Content,
  256. SysUserId: outsideReport.SysUserId,
  257. SysUserName: outsideReport.SysUserName,
  258. AttachmentList: attachmentList,
  259. }
  260. return &outsideReportBO, nil
  261. }
  262. func DocumentUpdate(outsideReport *document_manage_model.OutsideReportBO) error {
  263. logs.Info("DocumentUpdate")
  264. report, err := document_manage_model.GetOutsideReportById(outsideReport.OutsideReportId)
  265. if err != nil {
  266. return err
  267. }
  268. if report == nil {
  269. return fmt.Errorf("报告不存在")
  270. }
  271. // 更新报告
  272. if outsideReport.Title != "" {
  273. report.Title = outsideReport.Title
  274. }
  275. if outsideReport.Abstract != "" {
  276. report.Abstract = outsideReport.Abstract
  277. }
  278. if outsideReport.ClassifyId > 0 {
  279. report.ClassifyId = outsideReport.ClassifyId
  280. }
  281. if outsideReport.ClassifyName != "" {
  282. report.ClassifyName = outsideReport.ClassifyName
  283. }
  284. if outsideReport.Content != "" {
  285. report.Content = outsideReport.Content
  286. }
  287. report.ModifyTime = utils.GetCurrentTime()
  288. report.ReportUpdateTime = utils.GetCurrentTime()
  289. err = document_manage_model.UpdateOutsideReport(report)
  290. if err != nil {
  291. return fmt.Errorf("更新报告失败, Err: %s", err.Error())
  292. }
  293. // 更新报告附件
  294. attachmentList := outsideReport.AttachmentList
  295. if len(attachmentList) > 0 {
  296. err = document_manage_model.DeleteReportAttachmentByReportId(outsideReport.OutsideReportId)
  297. if err != nil {
  298. return fmt.Errorf("删除报告附件失败, Err: %s", err.Error())
  299. }
  300. for _, attachment := range attachmentList {
  301. if attachment.Title == "" || attachment.Url == "" {
  302. continue
  303. }
  304. attachment.OutsideReportId = outsideReport.OutsideReportId
  305. attachment.CreateTime = utils.GetCurrentTime()
  306. _, err := document_manage_model.SaveOutsideReportAttachment(attachment)
  307. if err != nil {
  308. return err
  309. }
  310. }
  311. }
  312. return nil
  313. }
  314. func DocumentDelete(outsideReportId int) error {
  315. logs.Info("DocumentDelete")
  316. report, err := document_manage_model.GetOutsideReportById(outsideReportId)
  317. if err != nil {
  318. return err
  319. }
  320. if report == nil {
  321. return fmt.Errorf("报告不存在")
  322. }
  323. err = document_manage_model.DeleteOutsideReport(outsideReportId)
  324. if err != nil {
  325. return err
  326. }
  327. err = document_manage_model.DeleteReportAttachmentByReportId(outsideReportId)
  328. if err != nil {
  329. return err
  330. }
  331. return nil
  332. }