2 次代码提交 45266d3561 ... 812eaa4d25

作者 SHA1 备注 提交日期
  songxiaohang 812eaa4d25 双胞胎图表接口平替 1 年之前
  songxiaohang ea7338c90a 双胞胎图表接口平替 1 年之前

+ 1 - 1
app/cmd/dtgateway/etc/dtgateway.yaml

@@ -1,7 +1,7 @@
 Name: dtgateway-api
 Host: 0.0.0.0
 Port: 1009
-Mode: dev
+Mode: pro
 Timeout: 0
 #100MB
 MaxBytes: 104857600

+ 2 - 1
app/cmd/dtgateway/internal/logic/dtgateway/itemHistoryDataListLogic.go

@@ -25,13 +25,14 @@ func NewItemHistoryDataListLogic(ctx context.Context, svcCtx *svc.ServiceContext
 }
 
 func (l *ItemHistoryDataListLogic) ItemHistoryDataList(req *types.ItemHistoryDataListReq) (resp *types.CommonResponse, err error) {
-	dataList, err := l.svcCtx.OrganizationRpc.ItemHistoryDataList(l.ctx, &pb.ItemHistoryDataListReq{
+	dataList, err := l.svcCtx.OrganizationRpc.ItemHistoryDataForChart(l.ctx, &pb.ItemHistoryDataForChartReq{
 		ProjectId:  req.ProjectId,
 		ItemName:   req.ItemName,
 		Interval:   req.Interval,
 		Aggregator: req.Aggregator,
 		Stime:      req.STime,
 		Etime:      req.ETime,
+		Size:       req.Size,
 	})
 	if err != nil {
 		return nil, err

+ 34 - 0
app/cmd/organization/internal/logic/itemHistoryDataForChartLogic.go

@@ -0,0 +1,34 @@
+package logic
+
+import (
+	"GtDataStore/common/xerr"
+	"context"
+	"github.com/pkg/errors"
+
+	"GtDataStore/app/cmd/organization/internal/svc"
+	"GtDataStore/app/cmd/organization/pb"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type ItemHistoryDataForChartLogic struct {
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+	logx.Logger
+}
+
+func NewItemHistoryDataForChartLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ItemHistoryDataForChartLogic {
+	return &ItemHistoryDataForChartLogic{
+		ctx:    ctx,
+		svcCtx: svcCtx,
+		Logger: logx.WithContext(ctx),
+	}
+}
+
+func (l *ItemHistoryDataForChartLogic) ItemHistoryDataForChart(in *pb.ItemHistoryDataForChartReq) (*pb.ItemHistoryDataForChartResp, error) {
+	modeList, err := l.svcCtx.ItemHistoryData.QueryHistoryDataForChart(l.ctx, in)
+	if err != nil {
+		return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "model QueryHistoryDataForChart get data err:%v", err)
+	}
+	return &pb.ItemHistoryDataForChartResp{List: modeList}, nil
+}

+ 5 - 0
app/cmd/organization/internal/server/organizationServer.go

@@ -81,3 +81,8 @@ func (s *OrganizationServer) ChangeTypeItemHistoryData(ctx context.Context, in *
 	l := logic.NewChangeTypeItemHistoryDataLogic(ctx, s.svcCtx)
 	return l.ChangeTypeItemHistoryData(in)
 }
+
+func (s *OrganizationServer) ItemHistoryDataForChart(ctx context.Context, in *pb.ItemHistoryDataForChartReq) (*pb.ItemHistoryDataForChartResp, error) {
+	l := logic.NewItemHistoryDataForChartLogic(ctx, s.svcCtx)
+	return l.ItemHistoryDataForChart(in)
+}

+ 32 - 0
app/cmd/organization/organization.proto

@@ -484,6 +484,37 @@ message ItemHistoryDataList {
   string    h_time = 3;
 }
 
+message ItemHistoryDataForChart {
+  // @gotags: json:"name"
+  string    name = 1;
+  // @gotags: json:"val"
+  double    val = 2;
+  // @gotags: json:"htime_at"
+  string    htime_at = 3;
+}
+
+message ItemHistoryDataForChartReq {
+  // @gotags: json:"project_id"
+  int64     project_id = 1;
+  // @gotags: json:"item_name"
+  string    item_name = 2;
+  // @gotags: json:"stime"
+  string    stime = 3;
+  // @gotags: json:"etime"
+  string     etime = 4;
+  // @gotags: json:"interval"
+  string    interval = 5;
+  // @gotags: json:"size"
+  int64     size = 6;
+  // @gotags: json:"aggregator"
+  string    aggregator = 7;
+}
+
+message ItemHistoryDataForChartResp {
+  // @gotags: json:"list"
+  repeated ItemHistoryDataForChart list = 1;
+}
+
 message ItemHistoryDataListResp {
   // @gotags: json:"list"
   repeated ItemHistoryDataList list = 1;
@@ -552,4 +583,5 @@ service Organization {
   rpc ItemHistoryDataMaxMinByTime(ItemHistoryDataByTimeReq) returns(ItemHistoryDataMaxMinResp);
   rpc ItemHistoryDataFirstLastByTime(ItemHistoryDataByTimeReq) returns(ItemHistoryDataFirstLastResp);
   rpc ChangeTypeItemHistoryData(ItemHistoryDataByTimeReq) returns(ChangeTypeItemHistoryDataResp);
+  rpc ItemHistoryDataForChart(ItemHistoryDataForChartReq) returns(ItemHistoryDataForChartResp);
 }

+ 9 - 0
app/cmd/organization/organization/organization.go

@@ -27,6 +27,9 @@ type (
 	ItemHistoryData               = pb.ItemHistoryData
 	ItemHistoryDataByTimeReq      = pb.ItemHistoryDataByTimeReq
 	ItemHistoryDataFirstLastResp  = pb.ItemHistoryDataFirstLastResp
+	ItemHistoryDataForChart       = pb.ItemHistoryDataForChart
+	ItemHistoryDataForChartReq    = pb.ItemHistoryDataForChartReq
+	ItemHistoryDataForChartResp   = pb.ItemHistoryDataForChartResp
 	ItemHistoryDataList           = pb.ItemHistoryDataList
 	ItemHistoryDataListReq        = pb.ItemHistoryDataListReq
 	ItemHistoryDataListResp       = pb.ItemHistoryDataListResp
@@ -54,6 +57,7 @@ type (
 		ItemHistoryDataMaxMinByTime(ctx context.Context, in *ItemHistoryDataByTimeReq, opts ...grpc.CallOption) (*ItemHistoryDataMaxMinResp, error)
 		ItemHistoryDataFirstLastByTime(ctx context.Context, in *ItemHistoryDataByTimeReq, opts ...grpc.CallOption) (*ItemHistoryDataFirstLastResp, error)
 		ChangeTypeItemHistoryData(ctx context.Context, in *ItemHistoryDataByTimeReq, opts ...grpc.CallOption) (*ChangeTypeItemHistoryDataResp, error)
+		ItemHistoryDataForChart(ctx context.Context, in *ItemHistoryDataForChartReq, opts ...grpc.CallOption) (*ItemHistoryDataForChartResp, error)
 	}
 
 	defaultOrganization struct {
@@ -126,3 +130,8 @@ func (m *defaultOrganization) ChangeTypeItemHistoryData(ctx context.Context, in
 	client := pb.NewOrganizationClient(m.cli.Conn())
 	return client.ChangeTypeItemHistoryData(ctx, in, opts...)
 }
+
+func (m *defaultOrganization) ItemHistoryDataForChart(ctx context.Context, in *ItemHistoryDataForChartReq, opts ...grpc.CallOption) (*ItemHistoryDataForChartResp, error) {
+	client := pb.NewOrganizationClient(m.cli.Conn())
+	return client.ItemHistoryDataForChart(ctx, in, opts...)
+}

文件差异内容过多而无法显示
+ 485 - 197
app/cmd/organization/pb/organization.pb.go


+ 78 - 26
app/cmd/organization/pb/organization_grpc.pb.go

@@ -1,7 +1,7 @@
 // Code generated by protoc-gen-go-grpc. DO NOT EDIT.
 // versions:
-// - protoc-gen-go-grpc v1.2.0
-// - protoc             v4.23.4
+// - protoc-gen-go-grpc v1.3.0
+// - protoc             v3.21.12
 // source: organization.proto
 
 package pb
@@ -18,6 +18,22 @@ import (
 // Requires gRPC-Go v1.32.0 or later.
 const _ = grpc.SupportPackageIsVersion7
 
+const (
+	Organization_GetWorkingUfByCode_FullMethodName             = "/pb.Organization/GetWorkingUfByCode"
+	Organization_FindWorkingUfByCycle_FullMethodName           = "/pb.Organization/FindWorkingUfByCycle"
+	Organization_GetWorkingRoByCode_FullMethodName             = "/pb.Organization/GetWorkingRoByCode"
+	Organization_GetWorkingChestByCode_FullMethodName          = "/pb.Organization/GetWorkingChestByCode"
+	Organization_GetWorkingPumpByCode_FullMethodName           = "/pb.Organization/GetWorkingPumpByCode"
+	Organization_GetWorkingValveByCode_FullMethodName          = "/pb.Organization/GetWorkingValveByCode"
+	Organization_MultiAddItemHistoryData_FullMethodName        = "/pb.Organization/MultiAddItemHistoryData"
+	Organization_ItemHistoryDataList_FullMethodName            = "/pb.Organization/ItemHistoryDataList"
+	Organization_ItemHistoryDataByTime_FullMethodName          = "/pb.Organization/ItemHistoryDataByTime"
+	Organization_ItemHistoryDataMaxMinByTime_FullMethodName    = "/pb.Organization/ItemHistoryDataMaxMinByTime"
+	Organization_ItemHistoryDataFirstLastByTime_FullMethodName = "/pb.Organization/ItemHistoryDataFirstLastByTime"
+	Organization_ChangeTypeItemHistoryData_FullMethodName      = "/pb.Organization/ChangeTypeItemHistoryData"
+	Organization_ItemHistoryDataForChart_FullMethodName        = "/pb.Organization/ItemHistoryDataForChart"
+)
+
 // OrganizationClient is the client API for Organization service.
 //
 // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
@@ -34,6 +50,7 @@ type OrganizationClient interface {
 	ItemHistoryDataMaxMinByTime(ctx context.Context, in *ItemHistoryDataByTimeReq, opts ...grpc.CallOption) (*ItemHistoryDataMaxMinResp, error)
 	ItemHistoryDataFirstLastByTime(ctx context.Context, in *ItemHistoryDataByTimeReq, opts ...grpc.CallOption) (*ItemHistoryDataFirstLastResp, error)
 	ChangeTypeItemHistoryData(ctx context.Context, in *ItemHistoryDataByTimeReq, opts ...grpc.CallOption) (*ChangeTypeItemHistoryDataResp, error)
+	ItemHistoryDataForChart(ctx context.Context, in *ItemHistoryDataForChartReq, opts ...grpc.CallOption) (*ItemHistoryDataForChartResp, error)
 }
 
 type organizationClient struct {
@@ -46,7 +63,7 @@ func NewOrganizationClient(cc grpc.ClientConnInterface) OrganizationClient {
 
 func (c *organizationClient) GetWorkingUfByCode(ctx context.Context, in *DcWorkingReq, opts ...grpc.CallOption) (*GetWorkingUfByCodeResp, error) {
 	out := new(GetWorkingUfByCodeResp)
-	err := c.cc.Invoke(ctx, "/pb.Organization/GetWorkingUfByCode", in, out, opts...)
+	err := c.cc.Invoke(ctx, Organization_GetWorkingUfByCode_FullMethodName, in, out, opts...)
 	if err != nil {
 		return nil, err
 	}
@@ -55,7 +72,7 @@ func (c *organizationClient) GetWorkingUfByCode(ctx context.Context, in *DcWorki
 
 func (c *organizationClient) FindWorkingUfByCycle(ctx context.Context, in *FindWorkingUfByCycleReq, opts ...grpc.CallOption) (*FindWorkingUfByCycleResp, error) {
 	out := new(FindWorkingUfByCycleResp)
-	err := c.cc.Invoke(ctx, "/pb.Organization/FindWorkingUfByCycle", in, out, opts...)
+	err := c.cc.Invoke(ctx, Organization_FindWorkingUfByCycle_FullMethodName, in, out, opts...)
 	if err != nil {
 		return nil, err
 	}
@@ -64,7 +81,7 @@ func (c *organizationClient) FindWorkingUfByCycle(ctx context.Context, in *FindW
 
 func (c *organizationClient) GetWorkingRoByCode(ctx context.Context, in *DcWorkingReq, opts ...grpc.CallOption) (*GetWorkingRoByCodeResp, error) {
 	out := new(GetWorkingRoByCodeResp)
-	err := c.cc.Invoke(ctx, "/pb.Organization/GetWorkingRoByCode", in, out, opts...)
+	err := c.cc.Invoke(ctx, Organization_GetWorkingRoByCode_FullMethodName, in, out, opts...)
 	if err != nil {
 		return nil, err
 	}
@@ -73,7 +90,7 @@ func (c *organizationClient) GetWorkingRoByCode(ctx context.Context, in *DcWorki
 
 func (c *organizationClient) GetWorkingChestByCode(ctx context.Context, in *DcWorkingReq, opts ...grpc.CallOption) (*GetWorkingChestByCodeResp, error) {
 	out := new(GetWorkingChestByCodeResp)
-	err := c.cc.Invoke(ctx, "/pb.Organization/GetWorkingChestByCode", in, out, opts...)
+	err := c.cc.Invoke(ctx, Organization_GetWorkingChestByCode_FullMethodName, in, out, opts...)
 	if err != nil {
 		return nil, err
 	}
@@ -82,7 +99,7 @@ func (c *organizationClient) GetWorkingChestByCode(ctx context.Context, in *DcWo
 
 func (c *organizationClient) GetWorkingPumpByCode(ctx context.Context, in *DcWorkingReq, opts ...grpc.CallOption) (*GetWorkingPumpByCodeResp, error) {
 	out := new(GetWorkingPumpByCodeResp)
-	err := c.cc.Invoke(ctx, "/pb.Organization/GetWorkingPumpByCode", in, out, opts...)
+	err := c.cc.Invoke(ctx, Organization_GetWorkingPumpByCode_FullMethodName, in, out, opts...)
 	if err != nil {
 		return nil, err
 	}
@@ -91,7 +108,7 @@ func (c *organizationClient) GetWorkingPumpByCode(ctx context.Context, in *DcWor
 
 func (c *organizationClient) GetWorkingValveByCode(ctx context.Context, in *DcWorkingReq, opts ...grpc.CallOption) (*GetWorkingValveByCodeResp, error) {
 	out := new(GetWorkingValveByCodeResp)
-	err := c.cc.Invoke(ctx, "/pb.Organization/GetWorkingValveByCode", in, out, opts...)
+	err := c.cc.Invoke(ctx, Organization_GetWorkingValveByCode_FullMethodName, in, out, opts...)
 	if err != nil {
 		return nil, err
 	}
@@ -100,7 +117,7 @@ func (c *organizationClient) GetWorkingValveByCode(ctx context.Context, in *DcWo
 
 func (c *organizationClient) MultiAddItemHistoryData(ctx context.Context, in *MultiAddItemHistoryDataReq, opts ...grpc.CallOption) (*MultiAddItemHistoryDataResp, error) {
 	out := new(MultiAddItemHistoryDataResp)
-	err := c.cc.Invoke(ctx, "/pb.Organization/MultiAddItemHistoryData", in, out, opts...)
+	err := c.cc.Invoke(ctx, Organization_MultiAddItemHistoryData_FullMethodName, in, out, opts...)
 	if err != nil {
 		return nil, err
 	}
@@ -109,7 +126,7 @@ func (c *organizationClient) MultiAddItemHistoryData(ctx context.Context, in *Mu
 
 func (c *organizationClient) ItemHistoryDataList(ctx context.Context, in *ItemHistoryDataListReq, opts ...grpc.CallOption) (*ItemHistoryDataListResp, error) {
 	out := new(ItemHistoryDataListResp)
-	err := c.cc.Invoke(ctx, "/pb.Organization/ItemHistoryDataList", in, out, opts...)
+	err := c.cc.Invoke(ctx, Organization_ItemHistoryDataList_FullMethodName, in, out, opts...)
 	if err != nil {
 		return nil, err
 	}
@@ -118,7 +135,7 @@ func (c *organizationClient) ItemHistoryDataList(ctx context.Context, in *ItemHi
 
 func (c *organizationClient) ItemHistoryDataByTime(ctx context.Context, in *ItemHistoryDataByTimeReq, opts ...grpc.CallOption) (*ItemHistoryDataListResp, error) {
 	out := new(ItemHistoryDataListResp)
-	err := c.cc.Invoke(ctx, "/pb.Organization/ItemHistoryDataByTime", in, out, opts...)
+	err := c.cc.Invoke(ctx, Organization_ItemHistoryDataByTime_FullMethodName, in, out, opts...)
 	if err != nil {
 		return nil, err
 	}
@@ -127,7 +144,7 @@ func (c *organizationClient) ItemHistoryDataByTime(ctx context.Context, in *Item
 
 func (c *organizationClient) ItemHistoryDataMaxMinByTime(ctx context.Context, in *ItemHistoryDataByTimeReq, opts ...grpc.CallOption) (*ItemHistoryDataMaxMinResp, error) {
 	out := new(ItemHistoryDataMaxMinResp)
-	err := c.cc.Invoke(ctx, "/pb.Organization/ItemHistoryDataMaxMinByTime", in, out, opts...)
+	err := c.cc.Invoke(ctx, Organization_ItemHistoryDataMaxMinByTime_FullMethodName, in, out, opts...)
 	if err != nil {
 		return nil, err
 	}
@@ -136,7 +153,7 @@ func (c *organizationClient) ItemHistoryDataMaxMinByTime(ctx context.Context, in
 
 func (c *organizationClient) ItemHistoryDataFirstLastByTime(ctx context.Context, in *ItemHistoryDataByTimeReq, opts ...grpc.CallOption) (*ItemHistoryDataFirstLastResp, error) {
 	out := new(ItemHistoryDataFirstLastResp)
-	err := c.cc.Invoke(ctx, "/pb.Organization/ItemHistoryDataFirstLastByTime", in, out, opts...)
+	err := c.cc.Invoke(ctx, Organization_ItemHistoryDataFirstLastByTime_FullMethodName, in, out, opts...)
 	if err != nil {
 		return nil, err
 	}
@@ -145,7 +162,16 @@ func (c *organizationClient) ItemHistoryDataFirstLastByTime(ctx context.Context,
 
 func (c *organizationClient) ChangeTypeItemHistoryData(ctx context.Context, in *ItemHistoryDataByTimeReq, opts ...grpc.CallOption) (*ChangeTypeItemHistoryDataResp, error) {
 	out := new(ChangeTypeItemHistoryDataResp)
-	err := c.cc.Invoke(ctx, "/pb.Organization/ChangeTypeItemHistoryData", in, out, opts...)
+	err := c.cc.Invoke(ctx, Organization_ChangeTypeItemHistoryData_FullMethodName, in, out, opts...)
+	if err != nil {
+		return nil, err
+	}
+	return out, nil
+}
+
+func (c *organizationClient) ItemHistoryDataForChart(ctx context.Context, in *ItemHistoryDataForChartReq, opts ...grpc.CallOption) (*ItemHistoryDataForChartResp, error) {
+	out := new(ItemHistoryDataForChartResp)
+	err := c.cc.Invoke(ctx, Organization_ItemHistoryDataForChart_FullMethodName, in, out, opts...)
 	if err != nil {
 		return nil, err
 	}
@@ -168,6 +194,7 @@ type OrganizationServer interface {
 	ItemHistoryDataMaxMinByTime(context.Context, *ItemHistoryDataByTimeReq) (*ItemHistoryDataMaxMinResp, error)
 	ItemHistoryDataFirstLastByTime(context.Context, *ItemHistoryDataByTimeReq) (*ItemHistoryDataFirstLastResp, error)
 	ChangeTypeItemHistoryData(context.Context, *ItemHistoryDataByTimeReq) (*ChangeTypeItemHistoryDataResp, error)
+	ItemHistoryDataForChart(context.Context, *ItemHistoryDataForChartReq) (*ItemHistoryDataForChartResp, error)
 	mustEmbedUnimplementedOrganizationServer()
 }
 
@@ -211,6 +238,9 @@ func (UnimplementedOrganizationServer) ItemHistoryDataFirstLastByTime(context.Co
 func (UnimplementedOrganizationServer) ChangeTypeItemHistoryData(context.Context, *ItemHistoryDataByTimeReq) (*ChangeTypeItemHistoryDataResp, error) {
 	return nil, status.Errorf(codes.Unimplemented, "method ChangeTypeItemHistoryData not implemented")
 }
+func (UnimplementedOrganizationServer) ItemHistoryDataForChart(context.Context, *ItemHistoryDataForChartReq) (*ItemHistoryDataForChartResp, error) {
+	return nil, status.Errorf(codes.Unimplemented, "method ItemHistoryDataForChart not implemented")
+}
 func (UnimplementedOrganizationServer) mustEmbedUnimplementedOrganizationServer() {}
 
 // UnsafeOrganizationServer may be embedded to opt out of forward compatibility for this service.
@@ -234,7 +264,7 @@ func _Organization_GetWorkingUfByCode_Handler(srv interface{}, ctx context.Conte
 	}
 	info := &grpc.UnaryServerInfo{
 		Server:     srv,
-		FullMethod: "/pb.Organization/GetWorkingUfByCode",
+		FullMethod: Organization_GetWorkingUfByCode_FullMethodName,
 	}
 	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
 		return srv.(OrganizationServer).GetWorkingUfByCode(ctx, req.(*DcWorkingReq))
@@ -252,7 +282,7 @@ func _Organization_FindWorkingUfByCycle_Handler(srv interface{}, ctx context.Con
 	}
 	info := &grpc.UnaryServerInfo{
 		Server:     srv,
-		FullMethod: "/pb.Organization/FindWorkingUfByCycle",
+		FullMethod: Organization_FindWorkingUfByCycle_FullMethodName,
 	}
 	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
 		return srv.(OrganizationServer).FindWorkingUfByCycle(ctx, req.(*FindWorkingUfByCycleReq))
@@ -270,7 +300,7 @@ func _Organization_GetWorkingRoByCode_Handler(srv interface{}, ctx context.Conte
 	}
 	info := &grpc.UnaryServerInfo{
 		Server:     srv,
-		FullMethod: "/pb.Organization/GetWorkingRoByCode",
+		FullMethod: Organization_GetWorkingRoByCode_FullMethodName,
 	}
 	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
 		return srv.(OrganizationServer).GetWorkingRoByCode(ctx, req.(*DcWorkingReq))
@@ -288,7 +318,7 @@ func _Organization_GetWorkingChestByCode_Handler(srv interface{}, ctx context.Co
 	}
 	info := &grpc.UnaryServerInfo{
 		Server:     srv,
-		FullMethod: "/pb.Organization/GetWorkingChestByCode",
+		FullMethod: Organization_GetWorkingChestByCode_FullMethodName,
 	}
 	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
 		return srv.(OrganizationServer).GetWorkingChestByCode(ctx, req.(*DcWorkingReq))
@@ -306,7 +336,7 @@ func _Organization_GetWorkingPumpByCode_Handler(srv interface{}, ctx context.Con
 	}
 	info := &grpc.UnaryServerInfo{
 		Server:     srv,
-		FullMethod: "/pb.Organization/GetWorkingPumpByCode",
+		FullMethod: Organization_GetWorkingPumpByCode_FullMethodName,
 	}
 	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
 		return srv.(OrganizationServer).GetWorkingPumpByCode(ctx, req.(*DcWorkingReq))
@@ -324,7 +354,7 @@ func _Organization_GetWorkingValveByCode_Handler(srv interface{}, ctx context.Co
 	}
 	info := &grpc.UnaryServerInfo{
 		Server:     srv,
-		FullMethod: "/pb.Organization/GetWorkingValveByCode",
+		FullMethod: Organization_GetWorkingValveByCode_FullMethodName,
 	}
 	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
 		return srv.(OrganizationServer).GetWorkingValveByCode(ctx, req.(*DcWorkingReq))
@@ -342,7 +372,7 @@ func _Organization_MultiAddItemHistoryData_Handler(srv interface{}, ctx context.
 	}
 	info := &grpc.UnaryServerInfo{
 		Server:     srv,
-		FullMethod: "/pb.Organization/MultiAddItemHistoryData",
+		FullMethod: Organization_MultiAddItemHistoryData_FullMethodName,
 	}
 	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
 		return srv.(OrganizationServer).MultiAddItemHistoryData(ctx, req.(*MultiAddItemHistoryDataReq))
@@ -360,7 +390,7 @@ func _Organization_ItemHistoryDataList_Handler(srv interface{}, ctx context.Cont
 	}
 	info := &grpc.UnaryServerInfo{
 		Server:     srv,
-		FullMethod: "/pb.Organization/ItemHistoryDataList",
+		FullMethod: Organization_ItemHistoryDataList_FullMethodName,
 	}
 	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
 		return srv.(OrganizationServer).ItemHistoryDataList(ctx, req.(*ItemHistoryDataListReq))
@@ -378,7 +408,7 @@ func _Organization_ItemHistoryDataByTime_Handler(srv interface{}, ctx context.Co
 	}
 	info := &grpc.UnaryServerInfo{
 		Server:     srv,
-		FullMethod: "/pb.Organization/ItemHistoryDataByTime",
+		FullMethod: Organization_ItemHistoryDataByTime_FullMethodName,
 	}
 	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
 		return srv.(OrganizationServer).ItemHistoryDataByTime(ctx, req.(*ItemHistoryDataByTimeReq))
@@ -396,7 +426,7 @@ func _Organization_ItemHistoryDataMaxMinByTime_Handler(srv interface{}, ctx cont
 	}
 	info := &grpc.UnaryServerInfo{
 		Server:     srv,
-		FullMethod: "/pb.Organization/ItemHistoryDataMaxMinByTime",
+		FullMethod: Organization_ItemHistoryDataMaxMinByTime_FullMethodName,
 	}
 	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
 		return srv.(OrganizationServer).ItemHistoryDataMaxMinByTime(ctx, req.(*ItemHistoryDataByTimeReq))
@@ -414,7 +444,7 @@ func _Organization_ItemHistoryDataFirstLastByTime_Handler(srv interface{}, ctx c
 	}
 	info := &grpc.UnaryServerInfo{
 		Server:     srv,
-		FullMethod: "/pb.Organization/ItemHistoryDataFirstLastByTime",
+		FullMethod: Organization_ItemHistoryDataFirstLastByTime_FullMethodName,
 	}
 	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
 		return srv.(OrganizationServer).ItemHistoryDataFirstLastByTime(ctx, req.(*ItemHistoryDataByTimeReq))
@@ -432,7 +462,7 @@ func _Organization_ChangeTypeItemHistoryData_Handler(srv interface{}, ctx contex
 	}
 	info := &grpc.UnaryServerInfo{
 		Server:     srv,
-		FullMethod: "/pb.Organization/ChangeTypeItemHistoryData",
+		FullMethod: Organization_ChangeTypeItemHistoryData_FullMethodName,
 	}
 	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
 		return srv.(OrganizationServer).ChangeTypeItemHistoryData(ctx, req.(*ItemHistoryDataByTimeReq))
@@ -440,6 +470,24 @@ func _Organization_ChangeTypeItemHistoryData_Handler(srv interface{}, ctx contex
 	return interceptor(ctx, in, info, handler)
 }
 
+func _Organization_ItemHistoryDataForChart_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
+	in := new(ItemHistoryDataForChartReq)
+	if err := dec(in); err != nil {
+		return nil, err
+	}
+	if interceptor == nil {
+		return srv.(OrganizationServer).ItemHistoryDataForChart(ctx, in)
+	}
+	info := &grpc.UnaryServerInfo{
+		Server:     srv,
+		FullMethod: Organization_ItemHistoryDataForChart_FullMethodName,
+	}
+	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+		return srv.(OrganizationServer).ItemHistoryDataForChart(ctx, req.(*ItemHistoryDataForChartReq))
+	}
+	return interceptor(ctx, in, info, handler)
+}
+
 // Organization_ServiceDesc is the grpc.ServiceDesc for Organization service.
 // It's only intended for direct use with grpc.RegisterService,
 // and not to be introspected or modified (even as a copy)
@@ -495,6 +543,10 @@ var Organization_ServiceDesc = grpc.ServiceDesc{
 			MethodName: "ChangeTypeItemHistoryData",
 			Handler:    _Organization_ChangeTypeItemHistoryData_Handler,
 		},
+		{
+			MethodName: "ItemHistoryDataForChart",
+			Handler:    _Organization_ItemHistoryDataForChart_Handler,
+		},
 	},
 	Streams:  []grpc.StreamDesc{},
 	Metadata: "organization.proto",

+ 69 - 0
app/model/dcitemhistorydatamodel.go

@@ -23,6 +23,7 @@ type (
 		QueryHistoryDataMaxMinByTime(ctx context.Context, in *pb.ItemHistoryDataByTimeReq) (*MaxMinData, error)
 		QueryHistoryDataFirstByTime(ctx context.Context, in *pb.ItemHistoryDataByTimeReq) (*ItemHistoryData, error)
 		QueryHistoryDataLastByTime(ctx context.Context, in *pb.ItemHistoryDataByTimeReq) (*ItemHistoryData, error)
+		QueryHistoryDataForChart(ctx context.Context, in *pb.ItemHistoryDataForChartReq) ([]*pb.ItemHistoryDataForChart, error)
 	}
 
 	customDcItemHistoryDataModel struct {
@@ -166,6 +167,74 @@ func (m *defaultDcItemHistoryDataModel) QueryHistoryDataLastByTime(ctx context.C
 	}
 }
 
+func (m *defaultDcItemHistoryDataModel) QueryHistoryDataForChart(ctx context.Context, in *pb.ItemHistoryDataForChartReq) ([]*pb.ItemHistoryDataForChart, error) {
+	resp := make([]*pb.ItemHistoryDataForChart, 0)
+	var err error
+	var selectFormat, timeLpad, timeZero string
+	if in.Interval == "minute" {
+		selectFormat = "%Y-%m-%d %H:"
+		timeLpad = "%i"
+		timeZero = ":00"
+	} else if in.Interval == "h" {
+		selectFormat = "%Y-%m-%d "
+		timeLpad = "%H"
+		timeZero = ":00:00"
+	} else {
+		// day
+		selectFormat = "%Y-%m-"
+		timeLpad = "%d"
+		timeZero = " 00:00:00"
+	}
+	if in.Aggregator == "realtime" {
+		query := fmt.Sprintf("SELECT t1.item_name AS `name`, t1.val AS `val`, t2.htime AS `htime_at`"+
+			" FROM %s AS t1 JOIN ("+
+			" SELECT hd.item_name,"+
+			" CASE WHEN MINUTE(h_time) >= 30  THEN DATE_FORMAT(DATE_ADD(h_time, INTERVAL 1 HOUR), '%%Y-%%m-%%d %%H:00:00') "+
+			" ELSE DATE_FORMAT(h_time, '%%Y-%%m-%%d %%H:00:00') END AS htime"+
+			" FROM %s AS hd"+
+			" LEFT JOIN dc_item_config as ic ON hd.item_name = ic.item_name "+
+			" WHERE hd.item_name = ? AND h_time >= ? AND h_time < ?"+
+			" AND (ic.id IS NULL OR (hd.val > ic.min_val AND hd.val < ic.max_val))"+
+			" GROUP BY htime) AS t2 ON t1.item_name = t2.item_name AND t1.h_time = t2.htime"+
+			" WHERE t1.item_name = ? ORDER BY t1.h_time ASC",
+			m.getTableName(in.ProjectId), m.getTableName(in.ProjectId))
+		err = m.conn.QueryRowsCtx(ctx, &resp, query, in.ItemName, in.Stime, in.Etime, in.ItemName)
+	} else if in.Aggregator == "new" {
+		query := fmt.Sprintf("SELECT t1.item_name AS `name`, t1.val AS `val`, t2.grouped_h_time AS `htime_at`"+
+			" FROM %s AS t1 JOIN ("+
+			" SELECT hd.item_name,"+
+			" CONCAT(DATE_FORMAT(h_time, '%s'), LPAD(FLOOR(DATE_FORMAT(h_time, '%s') / %d) * %d, 2, 0), '%s') AS grouped_h_time "+
+			" FROM %s AS hd"+
+			" LEFT JOIN dc_item_config as ic ON hd.item_name = ic.item_name "+
+			" WHERE hd.item_name = ? AND h_time >= ? AND h_time < ?"+
+			" AND (ic.id IS NULL OR (hd.val > ic.min_val AND hd.val < ic.max_val))"+
+			" GROUP BY hd.item_name,grouped_h_time) AS t2 ON t1.item_name = t2.item_name AND t1.h_time = t2.grouped_h_time"+
+			" WHERE t1.item_name = ? ORDER BY t1.h_time ASC",
+			m.getTableName(in.ProjectId), selectFormat, timeLpad, in.Size, in.Size, timeZero, m.getTableName(in.ProjectId))
+		err = m.conn.QueryRowsCtx(ctx, &resp, query, in.ItemName, in.Stime, in.Etime, in.ItemName)
+	} else {
+		query := fmt.Sprintf("SELECT hd.item_name AS `name`, %s(val) AS `val`, "+
+			" CONCAT(DATE_FORMAT(h_time,'%s'),LPAD(FLOOR(DATE_FORMAT(h_time, '%s')/%d)*%d,2,0),'%s') AS `htime_at`"+
+			" FROM %s AS hd "+
+			" LEFT JOIN dc_item_config as ic ON hd.item_name = ic.item_name "+
+			" WHERE hd.item_name = ? AND h_time >= ?"+
+			" AND h_time < ?"+
+			" AND (ic.id IS NULL OR (hd.val > ic.min_val AND hd.val < ic.max_val))"+
+			" GROUP BY htime_at ORDER BY htime_at desc",
+			in.Aggregator, selectFormat, timeLpad, in.Size, in.Size, timeZero, m.getTableName(in.ProjectId))
+		err = m.conn.QueryRowsCtx(ctx, &resp, query, in.ItemName, in.Stime, in.Etime)
+	}
+
+	switch err {
+	case nil:
+		return resp, nil
+	case sqlc.ErrNotFound:
+		return nil, ErrNotFound
+	default:
+		return nil, err
+	}
+}
+
 func (m *defaultDcItemHistoryDataModel) getTableName(projectId int64) string {
 	return fmt.Sprintf("dc_item_history_data_%d", projectId)
 }

部分文件因为文件数量过多而无法显示