operation.go 5.9 KB

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