Jelajahi Sumber

时间段内第一条和最后一条数据

songxiaohang 1 tahun lalu
induk
melakukan
3fac278943

+ 28 - 0
app/cmd/dtgateway/internal/handler/dtgateway/itemHistoryDataFirstLastHandler.go

@@ -0,0 +1,28 @@
+package dtgateway
+
+import (
+	"net/http"
+
+	"GtDataStore/app/cmd/dtgateway/internal/logic/dtgateway"
+	"GtDataStore/app/cmd/dtgateway/internal/svc"
+	"GtDataStore/app/cmd/dtgateway/internal/types"
+	"github.com/zeromicro/go-zero/rest/httpx"
+)
+
+func ItemHistoryDataFirstLastHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.ItemHistoryDataByTimeReq
+		if err := httpx.Parse(r, &req); err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+			return
+		}
+
+		l := dtgateway.NewItemHistoryDataFirstLastLogic(r.Context(), svcCtx)
+		resp, err := l.ItemHistoryDataFirstLast(&req)
+		if err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+		} else {
+			httpx.OkJsonCtx(r.Context(), w, resp)
+		}
+	}
+}

+ 43 - 0
app/cmd/dtgateway/internal/logic/dtgateway/itemHistoryDataFirstLastLogic.go

@@ -0,0 +1,43 @@
+package dtgateway
+
+import (
+	"GtDataStore/app/cmd/organization/pb"
+	"GtDataStore/common/xerr"
+	"context"
+
+	"GtDataStore/app/cmd/dtgateway/internal/svc"
+	"GtDataStore/app/cmd/dtgateway/internal/types"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type ItemHistoryDataFirstLastLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewItemHistoryDataFirstLastLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ItemHistoryDataFirstLastLogic {
+	return &ItemHistoryDataFirstLastLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx,
+	}
+}
+
+func (l *ItemHistoryDataFirstLastLogic) ItemHistoryDataFirstLast(req *types.ItemHistoryDataByTimeReq) (resp *types.CommonResponse, err error) {
+	rpcData, err := l.svcCtx.OrganizationRpc.ItemHistoryDataFirstLastByTime(l.ctx, &pb.ItemHistoryDataByTimeReq{
+		ProjectId: req.ProjectId,
+		ItemName:  req.ItemName,
+		Stime:     req.STime,
+		Etime:     req.ETime,
+	})
+	if err != nil {
+		return nil, err
+	}
+	return &types.CommonResponse{
+		Code: xerr.OK,
+		Msg:  xerr.MapErrMsg(xerr.OK),
+		Data: rpcData,
+	}, nil
+}

+ 40 - 0
app/cmd/organization/internal/logic/itemHistoryDataFirstLastByTimeLogic.go

@@ -0,0 +1,40 @@
+package logic
+
+import (
+	"GtDataStore/app/cmd/organization/internal/svc"
+	"GtDataStore/app/cmd/organization/pb"
+	"GtDataStore/common/xerr"
+	"context"
+	"github.com/pkg/errors"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type ItemHistoryDataFirstLastByTimeLogic struct {
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+	logx.Logger
+}
+
+func NewItemHistoryDataFirstLastByTimeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ItemHistoryDataFirstLastByTimeLogic {
+	return &ItemHistoryDataFirstLastByTimeLogic{
+		ctx:    ctx,
+		svcCtx: svcCtx,
+		Logger: logx.WithContext(ctx),
+	}
+}
+
+func (l *ItemHistoryDataFirstLastByTimeLogic) ItemHistoryDataFirstLastByTime(in *pb.ItemHistoryDataByTimeReq) (*pb.ItemHistoryDataFirstLastResp, error) {
+	FirstData, err := l.svcCtx.ItemHistoryData.QueryHistoryDataFirstByTime(l.ctx, in)
+	if err != nil {
+		return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "model QueryHistoryDataFirstByTime get data err:%v", err)
+	}
+	LastData, err := l.svcCtx.ItemHistoryData.QueryHistoryDataLastByTime(l.ctx, in)
+	if err != nil {
+		return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "model QueryHistoryDataLastByTime get data err:%v", err)
+	}
+	return &pb.ItemHistoryDataFirstLastResp{
+		First: FirstData.Val,
+		Last:  LastData.Val,
+	}, nil
+}