| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- package opsdev
- import (
- "context"
- "dashoo.cn/common_definition/comm_def"
- "dashoo.cn/opms_libary/myerrors"
- opsdevmodel "dashoo.cn/opms_parent/app/model/opsdev"
- opsdevSrv "dashoo.cn/opms_parent/app/service/opsdev"
- "github.com/gogf/gf/frame/g"
- "github.com/gogf/gf/util/gvalid"
- )
- type OperationHandler struct{}
- func (h *OperationHandler) GetList(ctx context.Context, req *opsdevmodel.OpsOperationEventSearchReq, rsp *comm_def.CommonMsg) error {
- srv, err := opsdevSrv.NewOperationService(ctx)
- if err != nil {
- return err
- }
- total, list, err := srv.GetList(req)
- if err != nil {
- return err
- }
- rsp.Data = g.Map{"list": list, "total": total}
- return nil
- }
- func (h *OperationHandler) GetEntityById(ctx context.Context, req *comm_def.IdReq, rsp *comm_def.CommonMsg) error {
- srv, err := opsdevSrv.NewOperationService(ctx)
- if err != nil {
- return err
- }
- detail, err := srv.GetEntityById(req)
- if err != nil {
- return err
- }
- rsp.Data = detail
- return nil
- }
- func (h *OperationHandler) Create(ctx context.Context, req *opsdevmodel.OpsOperationEventReq, rsp *comm_def.CommonMsg) error {
- if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
- return myerrors.ValidError(err.Error())
- }
- srv, err := opsdevSrv.NewOperationService(ctx)
- if err != nil {
- return err
- }
- if err := srv.Create(req); err != nil {
- return err
- }
- rsp.Data = g.Map{"message": "创建成功"}
- return nil
- }
- func (h *OperationHandler) UpdateById(ctx context.Context, req *opsdevmodel.UpdateOpsOperationEventReq, rsp *comm_def.CommonMsg) error {
- if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
- return myerrors.ValidError(err.Error())
- }
- srv, err := opsdevSrv.NewOperationService(ctx)
- if err != nil {
- return err
- }
- if err := srv.UpdateById(req); err != nil {
- return err
- }
- rsp.Data = g.Map{"message": "更新成功"}
- return nil
- }
- func (h *OperationHandler) DeleteByIds(ctx context.Context, req *comm_def.IdsReq, rsp *comm_def.CommonMsg) error {
- if len(req.Ids) == 0 {
- return myerrors.ValidError("参数有误!")
- }
- srv, err := opsdevSrv.NewOperationService(ctx)
- if err != nil {
- return err
- }
- if err := srv.DeleteByIds(req); err != nil {
- return err
- }
- rsp.Data = g.Map{"message": "删除成功"}
- return nil
- }
- func (h *OperationHandler) Process(ctx context.Context, req *opsdevmodel.OpsOperationEventProcessReq, rsp *comm_def.CommonMsg) error {
- if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
- return myerrors.ValidError(err.Error())
- }
- srv, err := opsdevSrv.NewOperationService(ctx)
- if err != nil {
- return err
- }
- if err := srv.Process(ctx, req); err != nil {
- return err
- }
- rsp.Data = g.Map{"message": "处理成功"}
- return nil
- }
- func (h *OperationHandler) GetRecords(ctx context.Context, req *opsdevmodel.OpsOperationEventRecordSearchReq, rsp *comm_def.CommonMsg) error {
- srv, err := opsdevSrv.NewOperationService(ctx)
- if err != nil {
- return err
- }
- total, list, err := srv.GetRecords(req)
- if err != nil {
- return err
- }
- rsp.Data = g.Map{"list": list, "total": total}
- return nil
- }
- func (h *OperationHandler) UploadAttachment(ctx context.Context, req *opsdevmodel.OpsOperationEventAttachmentReq, rsp *comm_def.CommonMsg) error {
- if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
- return myerrors.ValidError(err.Error())
- }
- srv, err := opsdevSrv.NewOperationService(ctx)
- if err != nil {
- return err
- }
- attachment, err := srv.UploadAttachment(req)
- if err != nil {
- return err
- }
- rsp.Data = attachment
- return nil
- }
- func (h *OperationHandler) GetAttachments(ctx context.Context, req *comm_def.IdReq, rsp *comm_def.CommonMsg) error {
- srv, err := opsdevSrv.NewOperationService(ctx)
- if err != nil {
- return err
- }
- list, err := srv.GetAttachments(int(req.Id))
- if err != nil {
- return err
- }
- rsp.Data = list
- return nil
- }
- func (h *OperationHandler) GetStats(ctx context.Context, req *comm_def.CommonMsg, rsp *comm_def.CommonMsg) error {
- srv, err := opsdevSrv.NewOperationService(ctx)
- if err != nil {
- return err
- }
- stats, err := srv.GetStats()
- if err != nil {
- return err
- }
- rsp.Data = stats
- return nil
- }
- func (h *OperationHandler) GetKanbanData(ctx context.Context, req *opsdevmodel.OpsOperationEventKanbanSearchReq, rsp *comm_def.CommonMsg) error {
- srv, err := opsdevSrv.NewOperationService(ctx)
- if err != nil {
- return err
- }
- result, err := srv.GetKanbanData(req)
- if err != nil {
- return err
- }
- rsp.Data = result
- return nil
- }
- func (h *OperationHandler) AssignOpsUser(ctx context.Context, req *opsdevmodel.AssignOpsUserReq, rsp *comm_def.CommonMsg) error {
- if req.Id <= 0 {
- return myerrors.ValidError("事件ID不能为空")
- }
- srv, err := opsdevSrv.NewOperationService(ctx)
- if err != nil {
- return err
- }
- if err := srv.AssignOpsUser(req); err != nil {
- return err
- }
- rsp.Data = g.Map{"message": "分配成功"}
- return nil
- }
- func (h *OperationHandler) AddRecord(ctx context.Context, req *opsdevmodel.AddRecordReq, rsp *comm_def.CommonMsg) error {
- if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
- return myerrors.ValidError(err.Error())
- }
- srv, err := opsdevSrv.NewOperationService(ctx)
- if err != nil {
- return err
- }
- if err := srv.AddRecord(req); err != nil {
- return err
- }
- rsp.Data = g.Map{"message": "添加成功"}
- return nil
- }
- func (h *OperationHandler) DeleteAttachment(ctx context.Context, req *comm_def.IdReq, rsp *comm_def.CommonMsg) error {
- if req.Id <= 0 {
- return myerrors.ValidError("参数有误!")
- }
- srv, err := opsdevSrv.NewOperationService(ctx)
- if err != nil {
- return err
- }
- if err := srv.DeleteAttachment(req); err != nil {
- return err
- }
- rsp.Data = g.Map{"message": "删除成功"}
- return nil
- }
- func (h *OperationHandler) GetHistoryList(ctx context.Context, req *opsdevmodel.OpsOperationEventHistorySearchReq, rsp *comm_def.CommonMsg) error {
- srv, err := opsdevSrv.NewOperationService(ctx)
- if err != nil {
- return err
- }
- total, list, err := srv.GetHistoryList(req)
- if err != nil {
- return err
- }
- rsp.Data = g.Map{"list": list, "total": total}
- return nil
- }
|