operation.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. package opsdev
  2. import (
  3. "context"
  4. "dashoo.cn/common_definition/comm_def"
  5. "dashoo.cn/opms_libary/myerrors"
  6. opsdevmodel "dashoo.cn/opms_parent/app/model/opsdev"
  7. opsdevSrv "dashoo.cn/opms_parent/app/service/opsdev"
  8. "github.com/gogf/gf/frame/g"
  9. "github.com/gogf/gf/util/gvalid"
  10. )
  11. type OperationHandler struct{}
  12. func (h *OperationHandler) GetList(ctx context.Context, req *opsdevmodel.OpsOperationEventSearchReq, rsp *comm_def.CommonMsg) error {
  13. srv, err := opsdevSrv.NewOperationService(ctx)
  14. if err != nil {
  15. return err
  16. }
  17. total, list, err := srv.GetList(req)
  18. if err != nil {
  19. return err
  20. }
  21. rsp.Data = g.Map{"list": list, "total": total}
  22. return nil
  23. }
  24. func (h *OperationHandler) GetEntityById(ctx context.Context, req *comm_def.IdReq, rsp *comm_def.CommonMsg) error {
  25. srv, err := opsdevSrv.NewOperationService(ctx)
  26. if err != nil {
  27. return err
  28. }
  29. detail, err := srv.GetEntityById(req)
  30. if err != nil {
  31. return err
  32. }
  33. rsp.Data = detail
  34. return nil
  35. }
  36. func (h *OperationHandler) Create(ctx context.Context, req *opsdevmodel.OpsOperationEventReq, rsp *comm_def.CommonMsg) error {
  37. if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
  38. return myerrors.ValidError(err.Error())
  39. }
  40. srv, err := opsdevSrv.NewOperationService(ctx)
  41. if err != nil {
  42. return err
  43. }
  44. if err := srv.Create(req); err != nil {
  45. return err
  46. }
  47. rsp.Data = g.Map{"message": "创建成功"}
  48. return nil
  49. }
  50. func (h *OperationHandler) UpdateById(ctx context.Context, req *opsdevmodel.UpdateOpsOperationEventReq, rsp *comm_def.CommonMsg) error {
  51. if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
  52. return myerrors.ValidError(err.Error())
  53. }
  54. srv, err := opsdevSrv.NewOperationService(ctx)
  55. if err != nil {
  56. return err
  57. }
  58. if err := srv.UpdateById(req); err != nil {
  59. return err
  60. }
  61. rsp.Data = g.Map{"message": "更新成功"}
  62. return nil
  63. }
  64. func (h *OperationHandler) DeleteByIds(ctx context.Context, req *comm_def.IdsReq, rsp *comm_def.CommonMsg) error {
  65. if len(req.Ids) == 0 {
  66. return myerrors.ValidError("参数有误!")
  67. }
  68. srv, err := opsdevSrv.NewOperationService(ctx)
  69. if err != nil {
  70. return err
  71. }
  72. if err := srv.DeleteByIds(req); err != nil {
  73. return err
  74. }
  75. rsp.Data = g.Map{"message": "删除成功"}
  76. return nil
  77. }
  78. func (h *OperationHandler) Process(ctx context.Context, req *opsdevmodel.OpsOperationEventProcessReq, rsp *comm_def.CommonMsg) error {
  79. if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
  80. return myerrors.ValidError(err.Error())
  81. }
  82. srv, err := opsdevSrv.NewOperationService(ctx)
  83. if err != nil {
  84. return err
  85. }
  86. if err := srv.Process(ctx, req); err != nil {
  87. return err
  88. }
  89. rsp.Data = g.Map{"message": "处理成功"}
  90. return nil
  91. }
  92. func (h *OperationHandler) GetRecords(ctx context.Context, req *opsdevmodel.OpsOperationEventRecordSearchReq, rsp *comm_def.CommonMsg) error {
  93. srv, err := opsdevSrv.NewOperationService(ctx)
  94. if err != nil {
  95. return err
  96. }
  97. total, list, err := srv.GetRecords(req)
  98. if err != nil {
  99. return err
  100. }
  101. rsp.Data = g.Map{"list": list, "total": total}
  102. return nil
  103. }
  104. func (h *OperationHandler) UploadAttachment(ctx context.Context, req *opsdevmodel.OpsOperationEventAttachmentReq, rsp *comm_def.CommonMsg) error {
  105. if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
  106. return myerrors.ValidError(err.Error())
  107. }
  108. srv, err := opsdevSrv.NewOperationService(ctx)
  109. if err != nil {
  110. return err
  111. }
  112. attachment, err := srv.UploadAttachment(req)
  113. if err != nil {
  114. return err
  115. }
  116. rsp.Data = attachment
  117. return nil
  118. }
  119. func (h *OperationHandler) GetAttachments(ctx context.Context, req *comm_def.IdReq, rsp *comm_def.CommonMsg) error {
  120. srv, err := opsdevSrv.NewOperationService(ctx)
  121. if err != nil {
  122. return err
  123. }
  124. list, err := srv.GetAttachments(int(req.Id))
  125. if err != nil {
  126. return err
  127. }
  128. rsp.Data = list
  129. return nil
  130. }
  131. func (h *OperationHandler) GetStats(ctx context.Context, req *comm_def.CommonMsg, rsp *comm_def.CommonMsg) error {
  132. srv, err := opsdevSrv.NewOperationService(ctx)
  133. if err != nil {
  134. return err
  135. }
  136. stats, err := srv.GetStats()
  137. if err != nil {
  138. return err
  139. }
  140. rsp.Data = stats
  141. return nil
  142. }
  143. func (h *OperationHandler) GetKanbanData(ctx context.Context, req *opsdevmodel.OpsOperationEventKanbanSearchReq, rsp *comm_def.CommonMsg) error {
  144. srv, err := opsdevSrv.NewOperationService(ctx)
  145. if err != nil {
  146. return err
  147. }
  148. result, err := srv.GetKanbanData(req)
  149. if err != nil {
  150. return err
  151. }
  152. rsp.Data = result
  153. return nil
  154. }
  155. func (h *OperationHandler) AssignOpsUser(ctx context.Context, req *opsdevmodel.AssignOpsUserReq, rsp *comm_def.CommonMsg) error {
  156. if req.Id <= 0 {
  157. return myerrors.ValidError("事件ID不能为空")
  158. }
  159. srv, err := opsdevSrv.NewOperationService(ctx)
  160. if err != nil {
  161. return err
  162. }
  163. if err := srv.AssignOpsUser(req); err != nil {
  164. return err
  165. }
  166. rsp.Data = g.Map{"message": "分配成功"}
  167. return nil
  168. }
  169. func (h *OperationHandler) AddRecord(ctx context.Context, req *opsdevmodel.AddRecordReq, rsp *comm_def.CommonMsg) error {
  170. if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
  171. return myerrors.ValidError(err.Error())
  172. }
  173. srv, err := opsdevSrv.NewOperationService(ctx)
  174. if err != nil {
  175. return err
  176. }
  177. if err := srv.AddRecord(req); err != nil {
  178. return err
  179. }
  180. rsp.Data = g.Map{"message": "添加成功"}
  181. return nil
  182. }
  183. func (h *OperationHandler) DeleteAttachment(ctx context.Context, req *comm_def.IdReq, rsp *comm_def.CommonMsg) error {
  184. if req.Id <= 0 {
  185. return myerrors.ValidError("参数有误!")
  186. }
  187. srv, err := opsdevSrv.NewOperationService(ctx)
  188. if err != nil {
  189. return err
  190. }
  191. if err := srv.DeleteAttachment(req); err != nil {
  192. return err
  193. }
  194. rsp.Data = g.Map{"message": "删除成功"}
  195. return nil
  196. }
  197. func (h *OperationHandler) GetHistoryList(ctx context.Context, req *opsdevmodel.OpsOperationEventHistorySearchReq, rsp *comm_def.CommonMsg) error {
  198. srv, err := opsdevSrv.NewOperationService(ctx)
  199. if err != nil {
  200. return err
  201. }
  202. total, list, err := srv.GetHistoryList(req)
  203. if err != nil {
  204. return err
  205. }
  206. rsp.Data = g.Map{"list": list, "total": total}
  207. return nil
  208. }