diff --git a/.gitea/workflows/cd-test.yml b/.gitea/workflows/cd-test.yml index 1ab63f0..b6a8ba7 100644 --- a/.gitea/workflows/cd-test.yml +++ b/.gitea/workflows/cd-test.yml @@ -54,4 +54,5 @@ jobs: docker pull ${{ vars.REGISTRY }}/lone/store:latest docker pull ${{ vars.REGISTRY }}/lone/analysis:latest docker pull ${{ vars.REGISTRY }}/lone/ws:latest + docker pull ${{ vars.REGISTRY }}/lone/aiserver:latest docker compose up -d diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 0ba4c81..b4c6dcd 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -26,7 +26,7 @@ jobs: - name: Detect changes id: filter run: | - SERVICES="bff product admin user ad chore order express sale wecom task equipment record payment factory message support percutaneous water store analysis ws" + SERVICES="bff product admin user ad chore order express sale wecom task equipment record payment factory message support percutaneous water store analysis ws aiserver" pattern_for() { case "$1" in @@ -103,6 +103,7 @@ jobs: - store - analysis - ws + - aiserver env: BUILD_LIST: ${{ needs.changes.outputs.build_list }} NAME: lone/${{ matrix.name }} diff --git a/rpc/aiserver/aiserver.pb b/rpc/aiserver/aiserver.pb new file mode 100644 index 0000000..74608dc Binary files /dev/null and b/rpc/aiserver/aiserver.pb differ diff --git a/rpc/aiserver/aiserver.proto b/rpc/aiserver/aiserver.proto new file mode 100644 index 0000000..e0a6888 --- /dev/null +++ b/rpc/aiserver/aiserver.proto @@ -0,0 +1,147 @@ +syntax = "proto3"; + +package aiserver; +option go_package="./aiserver"; +import "google/api/annotations.proto"; + +message Response { + int32 code = 1; + string msg = 2; + string data = 3; +} + +message ApiAddProductRequest { + string product_code = 1; + string product_serial_number = 2; +} + +message ApiAddUseRequest { + string product_serial_number = 1; + int32 mg = 2; + int64 id = 3; +} + +message ApiProductItemsRequest { + repeated string product_code = 1; +} + +message ApiEditPlanningRequest { + string name = 1; + string begin_time = 2; + int64 id = 3; + string end_time = 4; +} + +message ApiEditPlanningProductRequest { + string product_code = 1; + int32 use_mg = 2; + int64 planning_id = 3; +} + +message ApiPlanningDeleteRequest { + int64 id = 1; +} + +message EmptyRequest { + +} + +message ApiUsedItemsRequest { + int32 page = 1; + int32 size = 2; + repeated string time = 3; +} + +message ApiSystemSetRequest { + int32 lang = 1; //语言 + int32 wifi = 2; //wifi + int32 screen = 3; //屏幕亮度 + int32 sound = 4; //声音 + int32 light_open = 5; //是否开灯 + string light_work_time = 6; //灯工作时间 + int32 light_brightness = 7; //灯亮度 + int32 screen_sleep_time = 8; //屏幕休眠时间 + +} + +service Aiserver { + // 添加产品 + rpc ApiAddProduct(ApiAddProductRequest) returns(Response) { + option (google.api.http) = { + post: "/api/v3/aiserver/add/product" + }; + }; + // 添加使用记录 + rpc ApiAddUse(ApiAddUseRequest) returns(Response) { + option (google.api.http) = { + post: "/api/v3/aiserver/add/use" + }; + }; + // 获取产品信息 + rpc ApiProductItems(ApiProductItemsRequest) returns(Response) { + option (google.api.http) = { + post: "/api/v3/aiserver/product/items" + }; + }; + // 添加方案 + rpc ApiAddPlanning(ApiEditPlanningRequest) returns(Response) { + option (google.api.http) = { + post: "/api/v3/aiserver/add/planning" + }; + }; + // 编辑方案产品 + rpc ApiEditPlanningProduct(ApiEditPlanningProductRequest) returns(Response) { + option (google.api.http) = { + post: "/api/v3/aiserver/add/planning" + }; + }; + // 编辑方案 + rpc ApiEditPlanning(ApiEditPlanningRequest) returns(Response) { + option (google.api.http) = { + post: "/api/v3/aiserver/edit/planning" + }; + }; + // 方案列表 + rpc ApiPlanningItems(EmptyRequest) returns(Response) { + option (google.api.http) = { + post: "/api/v3/aiserver/planning/items" + }; + }; + + // 方案删除 + rpc ApiPlanningDelete(ApiPlanningDeleteRequest) returns(Response) { + option (google.api.http) = { + post: "/api/v3/aiserver/planning/delete" + }; + }; + // 获取天气 + rpc ApiWeather(EmptyRequest) returns(Response) { + option (google.api.http) = { + post: "/api/v3/aiserver/weather" + }; + }; + // 获取使用记录 + rpc ApiUsedItems(ApiUsedItemsRequest) returns(Response) { + option (google.api.http) = { + post: "/api/v3/aiserver/used/items" + }; + }; + // 获取系统时间 + rpc ApiSystemTime(EmptyRequest) returns(Response) { + option (google.api.http) = { + post: "/api/v3/aiserver/system/time" + }; + }; + // 设置系统参数 + rpc ApiSystemSet(ApiSystemSetRequest) returns(Response) { + option (google.api.http) = { + post: "/api/v3/aiserver/system/set" + }; + }; + // 获取系统设置 + rpc ApiGetSystem(EmptyRequest) returns(Response) { + option (google.api.http) = { + post: "/api/v3/aiserver/get/system" + }; + }; +} diff --git a/rpc/aiserver/pb/aiserver.pb.go b/rpc/aiserver/pb/aiserver.pb.go new file mode 100644 index 0000000..734ad8b --- /dev/null +++ b/rpc/aiserver/pb/aiserver.pb.go @@ -0,0 +1,754 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.36.11 +// protoc v4.25.8 +// source: aiserver/aiserver.proto + +package aiserver + +import ( + _ "google.golang.org/genproto/googleapis/api/annotations" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" + unsafe "unsafe" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type Response struct { + state protoimpl.MessageState `protogen:"open.v1"` + Code int32 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` + Msg string `protobuf:"bytes,2,opt,name=msg,proto3" json:"msg,omitempty"` + Data string `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *Response) Reset() { + *x = Response{} + mi := &file_aiserver_aiserver_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *Response) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Response) ProtoMessage() {} + +func (x *Response) ProtoReflect() protoreflect.Message { + mi := &file_aiserver_aiserver_proto_msgTypes[0] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Response.ProtoReflect.Descriptor instead. +func (*Response) Descriptor() ([]byte, []int) { + return file_aiserver_aiserver_proto_rawDescGZIP(), []int{0} +} + +func (x *Response) GetCode() int32 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *Response) GetMsg() string { + if x != nil { + return x.Msg + } + return "" +} + +func (x *Response) GetData() string { + if x != nil { + return x.Data + } + return "" +} + +type ApiAddProductRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + ProductCode string `protobuf:"bytes,1,opt,name=product_code,json=productCode,proto3" json:"product_code,omitempty"` + ProductSerialNumber string `protobuf:"bytes,2,opt,name=product_serial_number,json=productSerialNumber,proto3" json:"product_serial_number,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *ApiAddProductRequest) Reset() { + *x = ApiAddProductRequest{} + mi := &file_aiserver_aiserver_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *ApiAddProductRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ApiAddProductRequest) ProtoMessage() {} + +func (x *ApiAddProductRequest) ProtoReflect() protoreflect.Message { + mi := &file_aiserver_aiserver_proto_msgTypes[1] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ApiAddProductRequest.ProtoReflect.Descriptor instead. +func (*ApiAddProductRequest) Descriptor() ([]byte, []int) { + return file_aiserver_aiserver_proto_rawDescGZIP(), []int{1} +} + +func (x *ApiAddProductRequest) GetProductCode() string { + if x != nil { + return x.ProductCode + } + return "" +} + +func (x *ApiAddProductRequest) GetProductSerialNumber() string { + if x != nil { + return x.ProductSerialNumber + } + return "" +} + +type ApiAddUseRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + ProductSerialNumber string `protobuf:"bytes,1,opt,name=product_serial_number,json=productSerialNumber,proto3" json:"product_serial_number,omitempty"` + Mg int32 `protobuf:"varint,2,opt,name=mg,proto3" json:"mg,omitempty"` + Id int64 `protobuf:"varint,3,opt,name=id,proto3" json:"id,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *ApiAddUseRequest) Reset() { + *x = ApiAddUseRequest{} + mi := &file_aiserver_aiserver_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *ApiAddUseRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ApiAddUseRequest) ProtoMessage() {} + +func (x *ApiAddUseRequest) ProtoReflect() protoreflect.Message { + mi := &file_aiserver_aiserver_proto_msgTypes[2] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ApiAddUseRequest.ProtoReflect.Descriptor instead. +func (*ApiAddUseRequest) Descriptor() ([]byte, []int) { + return file_aiserver_aiserver_proto_rawDescGZIP(), []int{2} +} + +func (x *ApiAddUseRequest) GetProductSerialNumber() string { + if x != nil { + return x.ProductSerialNumber + } + return "" +} + +func (x *ApiAddUseRequest) GetMg() int32 { + if x != nil { + return x.Mg + } + return 0 +} + +func (x *ApiAddUseRequest) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +type ApiProductItemsRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + ProductCode []string `protobuf:"bytes,1,rep,name=product_code,json=productCode,proto3" json:"product_code,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *ApiProductItemsRequest) Reset() { + *x = ApiProductItemsRequest{} + mi := &file_aiserver_aiserver_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *ApiProductItemsRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ApiProductItemsRequest) ProtoMessage() {} + +func (x *ApiProductItemsRequest) ProtoReflect() protoreflect.Message { + mi := &file_aiserver_aiserver_proto_msgTypes[3] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ApiProductItemsRequest.ProtoReflect.Descriptor instead. +func (*ApiProductItemsRequest) Descriptor() ([]byte, []int) { + return file_aiserver_aiserver_proto_rawDescGZIP(), []int{3} +} + +func (x *ApiProductItemsRequest) GetProductCode() []string { + if x != nil { + return x.ProductCode + } + return nil +} + +type ApiEditPlanningRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + BeginTime string `protobuf:"bytes,2,opt,name=begin_time,json=beginTime,proto3" json:"begin_time,omitempty"` + Id int64 `protobuf:"varint,3,opt,name=id,proto3" json:"id,omitempty"` + EndTime string `protobuf:"bytes,4,opt,name=end_time,json=endTime,proto3" json:"end_time,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *ApiEditPlanningRequest) Reset() { + *x = ApiEditPlanningRequest{} + mi := &file_aiserver_aiserver_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *ApiEditPlanningRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ApiEditPlanningRequest) ProtoMessage() {} + +func (x *ApiEditPlanningRequest) ProtoReflect() protoreflect.Message { + mi := &file_aiserver_aiserver_proto_msgTypes[4] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ApiEditPlanningRequest.ProtoReflect.Descriptor instead. +func (*ApiEditPlanningRequest) Descriptor() ([]byte, []int) { + return file_aiserver_aiserver_proto_rawDescGZIP(), []int{4} +} + +func (x *ApiEditPlanningRequest) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *ApiEditPlanningRequest) GetBeginTime() string { + if x != nil { + return x.BeginTime + } + return "" +} + +func (x *ApiEditPlanningRequest) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *ApiEditPlanningRequest) GetEndTime() string { + if x != nil { + return x.EndTime + } + return "" +} + +type ApiEditPlanningProductRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + ProductCode string `protobuf:"bytes,1,opt,name=product_code,json=productCode,proto3" json:"product_code,omitempty"` + UseMg int32 `protobuf:"varint,2,opt,name=use_mg,json=useMg,proto3" json:"use_mg,omitempty"` + PlanningId int64 `protobuf:"varint,3,opt,name=planning_id,json=planningId,proto3" json:"planning_id,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *ApiEditPlanningProductRequest) Reset() { + *x = ApiEditPlanningProductRequest{} + mi := &file_aiserver_aiserver_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *ApiEditPlanningProductRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ApiEditPlanningProductRequest) ProtoMessage() {} + +func (x *ApiEditPlanningProductRequest) ProtoReflect() protoreflect.Message { + mi := &file_aiserver_aiserver_proto_msgTypes[5] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ApiEditPlanningProductRequest.ProtoReflect.Descriptor instead. +func (*ApiEditPlanningProductRequest) Descriptor() ([]byte, []int) { + return file_aiserver_aiserver_proto_rawDescGZIP(), []int{5} +} + +func (x *ApiEditPlanningProductRequest) GetProductCode() string { + if x != nil { + return x.ProductCode + } + return "" +} + +func (x *ApiEditPlanningProductRequest) GetUseMg() int32 { + if x != nil { + return x.UseMg + } + return 0 +} + +func (x *ApiEditPlanningProductRequest) GetPlanningId() int64 { + if x != nil { + return x.PlanningId + } + return 0 +} + +type ApiPlanningDeleteRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *ApiPlanningDeleteRequest) Reset() { + *x = ApiPlanningDeleteRequest{} + mi := &file_aiserver_aiserver_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *ApiPlanningDeleteRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ApiPlanningDeleteRequest) ProtoMessage() {} + +func (x *ApiPlanningDeleteRequest) ProtoReflect() protoreflect.Message { + mi := &file_aiserver_aiserver_proto_msgTypes[6] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ApiPlanningDeleteRequest.ProtoReflect.Descriptor instead. +func (*ApiPlanningDeleteRequest) Descriptor() ([]byte, []int) { + return file_aiserver_aiserver_proto_rawDescGZIP(), []int{6} +} + +func (x *ApiPlanningDeleteRequest) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +type EmptyRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *EmptyRequest) Reset() { + *x = EmptyRequest{} + mi := &file_aiserver_aiserver_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *EmptyRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*EmptyRequest) ProtoMessage() {} + +func (x *EmptyRequest) ProtoReflect() protoreflect.Message { + mi := &file_aiserver_aiserver_proto_msgTypes[7] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use EmptyRequest.ProtoReflect.Descriptor instead. +func (*EmptyRequest) Descriptor() ([]byte, []int) { + return file_aiserver_aiserver_proto_rawDescGZIP(), []int{7} +} + +type ApiUsedItemsRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Page int32 `protobuf:"varint,1,opt,name=page,proto3" json:"page,omitempty"` + Size int32 `protobuf:"varint,2,opt,name=size,proto3" json:"size,omitempty"` + Time []string `protobuf:"bytes,3,rep,name=time,proto3" json:"time,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *ApiUsedItemsRequest) Reset() { + *x = ApiUsedItemsRequest{} + mi := &file_aiserver_aiserver_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *ApiUsedItemsRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ApiUsedItemsRequest) ProtoMessage() {} + +func (x *ApiUsedItemsRequest) ProtoReflect() protoreflect.Message { + mi := &file_aiserver_aiserver_proto_msgTypes[8] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ApiUsedItemsRequest.ProtoReflect.Descriptor instead. +func (*ApiUsedItemsRequest) Descriptor() ([]byte, []int) { + return file_aiserver_aiserver_proto_rawDescGZIP(), []int{8} +} + +func (x *ApiUsedItemsRequest) GetPage() int32 { + if x != nil { + return x.Page + } + return 0 +} + +func (x *ApiUsedItemsRequest) GetSize() int32 { + if x != nil { + return x.Size + } + return 0 +} + +func (x *ApiUsedItemsRequest) GetTime() []string { + if x != nil { + return x.Time + } + return nil +} + +type ApiSystemSetRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Lang int32 `protobuf:"varint,1,opt,name=lang,proto3" json:"lang,omitempty"` //语言 + Wifi int32 `protobuf:"varint,2,opt,name=wifi,proto3" json:"wifi,omitempty"` //wifi + Screen int32 `protobuf:"varint,3,opt,name=screen,proto3" json:"screen,omitempty"` //屏幕亮度 + Sound int32 `protobuf:"varint,4,opt,name=sound,proto3" json:"sound,omitempty"` //声音 + LightOpen int32 `protobuf:"varint,5,opt,name=light_open,json=lightOpen,proto3" json:"light_open,omitempty"` //是否开灯 + LightWorkTime string `protobuf:"bytes,6,opt,name=light_work_time,json=lightWorkTime,proto3" json:"light_work_time,omitempty"` //灯工作时间 + LightBrightness int32 `protobuf:"varint,7,opt,name=light_brightness,json=lightBrightness,proto3" json:"light_brightness,omitempty"` //灯亮度 + ScreenSleepTime int32 `protobuf:"varint,8,opt,name=screen_sleep_time,json=screenSleepTime,proto3" json:"screen_sleep_time,omitempty"` //屏幕休眠时间 + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *ApiSystemSetRequest) Reset() { + *x = ApiSystemSetRequest{} + mi := &file_aiserver_aiserver_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *ApiSystemSetRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ApiSystemSetRequest) ProtoMessage() {} + +func (x *ApiSystemSetRequest) ProtoReflect() protoreflect.Message { + mi := &file_aiserver_aiserver_proto_msgTypes[9] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ApiSystemSetRequest.ProtoReflect.Descriptor instead. +func (*ApiSystemSetRequest) Descriptor() ([]byte, []int) { + return file_aiserver_aiserver_proto_rawDescGZIP(), []int{9} +} + +func (x *ApiSystemSetRequest) GetLang() int32 { + if x != nil { + return x.Lang + } + return 0 +} + +func (x *ApiSystemSetRequest) GetWifi() int32 { + if x != nil { + return x.Wifi + } + return 0 +} + +func (x *ApiSystemSetRequest) GetScreen() int32 { + if x != nil { + return x.Screen + } + return 0 +} + +func (x *ApiSystemSetRequest) GetSound() int32 { + if x != nil { + return x.Sound + } + return 0 +} + +func (x *ApiSystemSetRequest) GetLightOpen() int32 { + if x != nil { + return x.LightOpen + } + return 0 +} + +func (x *ApiSystemSetRequest) GetLightWorkTime() string { + if x != nil { + return x.LightWorkTime + } + return "" +} + +func (x *ApiSystemSetRequest) GetLightBrightness() int32 { + if x != nil { + return x.LightBrightness + } + return 0 +} + +func (x *ApiSystemSetRequest) GetScreenSleepTime() int32 { + if x != nil { + return x.ScreenSleepTime + } + return 0 +} + +var File_aiserver_aiserver_proto protoreflect.FileDescriptor + +const file_aiserver_aiserver_proto_rawDesc = "" + + "\n" + + "\x17aiserver/aiserver.proto\x12\baiserver\x1a\x1cgoogle/api/annotations.proto\"D\n" + + "\bResponse\x12\x12\n" + + "\x04code\x18\x01 \x01(\x05R\x04code\x12\x10\n" + + "\x03msg\x18\x02 \x01(\tR\x03msg\x12\x12\n" + + "\x04data\x18\x03 \x01(\tR\x04data\"m\n" + + "\x14ApiAddProductRequest\x12!\n" + + "\fproduct_code\x18\x01 \x01(\tR\vproductCode\x122\n" + + "\x15product_serial_number\x18\x02 \x01(\tR\x13productSerialNumber\"f\n" + + "\x10ApiAddUseRequest\x122\n" + + "\x15product_serial_number\x18\x01 \x01(\tR\x13productSerialNumber\x12\x0e\n" + + "\x02mg\x18\x02 \x01(\x05R\x02mg\x12\x0e\n" + + "\x02id\x18\x03 \x01(\x03R\x02id\";\n" + + "\x16ApiProductItemsRequest\x12!\n" + + "\fproduct_code\x18\x01 \x03(\tR\vproductCode\"v\n" + + "\x16ApiEditPlanningRequest\x12\x12\n" + + "\x04name\x18\x01 \x01(\tR\x04name\x12\x1d\n" + + "\n" + + "begin_time\x18\x02 \x01(\tR\tbeginTime\x12\x0e\n" + + "\x02id\x18\x03 \x01(\x03R\x02id\x12\x19\n" + + "\bend_time\x18\x04 \x01(\tR\aendTime\"z\n" + + "\x1dApiEditPlanningProductRequest\x12!\n" + + "\fproduct_code\x18\x01 \x01(\tR\vproductCode\x12\x15\n" + + "\x06use_mg\x18\x02 \x01(\x05R\x05useMg\x12\x1f\n" + + "\vplanning_id\x18\x03 \x01(\x03R\n" + + "planningId\"*\n" + + "\x18ApiPlanningDeleteRequest\x12\x0e\n" + + "\x02id\x18\x01 \x01(\x03R\x02id\"\x0e\n" + + "\fEmptyRequest\"Q\n" + + "\x13ApiUsedItemsRequest\x12\x12\n" + + "\x04page\x18\x01 \x01(\x05R\x04page\x12\x12\n" + + "\x04size\x18\x02 \x01(\x05R\x04size\x12\x12\n" + + "\x04time\x18\x03 \x03(\tR\x04time\"\x89\x02\n" + + "\x13ApiSystemSetRequest\x12\x12\n" + + "\x04lang\x18\x01 \x01(\x05R\x04lang\x12\x12\n" + + "\x04wifi\x18\x02 \x01(\x05R\x04wifi\x12\x16\n" + + "\x06screen\x18\x03 \x01(\x05R\x06screen\x12\x14\n" + + "\x05sound\x18\x04 \x01(\x05R\x05sound\x12\x1d\n" + + "\n" + + "light_open\x18\x05 \x01(\x05R\tlightOpen\x12&\n" + + "\x0flight_work_time\x18\x06 \x01(\tR\rlightWorkTime\x12)\n" + + "\x10light_brightness\x18\a \x01(\x05R\x0flightBrightness\x12*\n" + + "\x11screen_sleep_time\x18\b \x01(\x05R\x0fscreenSleepTime2\xf3\n" + + "\n" + + "\bAiserver\x12i\n" + + "\rApiAddProduct\x12\x1e.aiserver.ApiAddProductRequest\x1a\x12.aiserver.Response\"$\x82\xd3\xe4\x93\x02\x1e\"\x1c/api/v3/aiserver/add/product\x12]\n" + + "\tApiAddUse\x12\x1a.aiserver.ApiAddUseRequest\x1a\x12.aiserver.Response\" \x82\xd3\xe4\x93\x02\x1a\"\x18/api/v3/aiserver/add/use\x12o\n" + + "\x0fApiProductItems\x12 .aiserver.ApiProductItemsRequest\x1a\x12.aiserver.Response\"&\x82\xd3\xe4\x93\x02 \"\x1e/api/v3/aiserver/product/items\x12m\n" + + "\x0eApiAddPlanning\x12 .aiserver.ApiEditPlanningRequest\x1a\x12.aiserver.Response\"%\x82\xd3\xe4\x93\x02\x1f\"\x1d/api/v3/aiserver/add/planning\x12|\n" + + "\x16ApiEditPlanningProduct\x12'.aiserver.ApiEditPlanningProductRequest\x1a\x12.aiserver.Response\"%\x82\xd3\xe4\x93\x02\x1f\"\x1d/api/v3/aiserver/add/planning\x12o\n" + + "\x0fApiEditPlanning\x12 .aiserver.ApiEditPlanningRequest\x1a\x12.aiserver.Response\"&\x82\xd3\xe4\x93\x02 \"\x1e/api/v3/aiserver/edit/planning\x12g\n" + + "\x10ApiPlanningItems\x12\x16.aiserver.EmptyRequest\x1a\x12.aiserver.Response\"'\x82\xd3\xe4\x93\x02!\"\x1f/api/v3/aiserver/planning/items\x12u\n" + + "\x11ApiPlanningDelete\x12\".aiserver.ApiPlanningDeleteRequest\x1a\x12.aiserver.Response\"(\x82\xd3\xe4\x93\x02\"\" /api/v3/aiserver/planning/delete\x12Z\n" + + "\n" + + "ApiWeather\x12\x16.aiserver.EmptyRequest\x1a\x12.aiserver.Response\" \x82\xd3\xe4\x93\x02\x1a\"\x18/api/v3/aiserver/weather\x12f\n" + + "\fApiUsedItems\x12\x1d.aiserver.ApiUsedItemsRequest\x1a\x12.aiserver.Response\"#\x82\xd3\xe4\x93\x02\x1d\"\x1b/api/v3/aiserver/used/items\x12a\n" + + "\rApiSystemTime\x12\x16.aiserver.EmptyRequest\x1a\x12.aiserver.Response\"$\x82\xd3\xe4\x93\x02\x1e\"\x1c/api/v3/aiserver/system/time\x12f\n" + + "\fApiSystemSet\x12\x1d.aiserver.ApiSystemSetRequest\x1a\x12.aiserver.Response\"#\x82\xd3\xe4\x93\x02\x1d\"\x1b/api/v3/aiserver/system/set\x12_\n" + + "\fApiGetSystem\x12\x16.aiserver.EmptyRequest\x1a\x12.aiserver.Response\"#\x82\xd3\xe4\x93\x02\x1d\"\x1b/api/v3/aiserver/get/systemB\fZ\n" + + "./aiserverb\x06proto3" + +var ( + file_aiserver_aiserver_proto_rawDescOnce sync.Once + file_aiserver_aiserver_proto_rawDescData []byte +) + +func file_aiserver_aiserver_proto_rawDescGZIP() []byte { + file_aiserver_aiserver_proto_rawDescOnce.Do(func() { + file_aiserver_aiserver_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_aiserver_aiserver_proto_rawDesc), len(file_aiserver_aiserver_proto_rawDesc))) + }) + return file_aiserver_aiserver_proto_rawDescData +} + +var file_aiserver_aiserver_proto_msgTypes = make([]protoimpl.MessageInfo, 10) +var file_aiserver_aiserver_proto_goTypes = []any{ + (*Response)(nil), // 0: aiserver.Response + (*ApiAddProductRequest)(nil), // 1: aiserver.ApiAddProductRequest + (*ApiAddUseRequest)(nil), // 2: aiserver.ApiAddUseRequest + (*ApiProductItemsRequest)(nil), // 3: aiserver.ApiProductItemsRequest + (*ApiEditPlanningRequest)(nil), // 4: aiserver.ApiEditPlanningRequest + (*ApiEditPlanningProductRequest)(nil), // 5: aiserver.ApiEditPlanningProductRequest + (*ApiPlanningDeleteRequest)(nil), // 6: aiserver.ApiPlanningDeleteRequest + (*EmptyRequest)(nil), // 7: aiserver.EmptyRequest + (*ApiUsedItemsRequest)(nil), // 8: aiserver.ApiUsedItemsRequest + (*ApiSystemSetRequest)(nil), // 9: aiserver.ApiSystemSetRequest +} +var file_aiserver_aiserver_proto_depIdxs = []int32{ + 1, // 0: aiserver.Aiserver.ApiAddProduct:input_type -> aiserver.ApiAddProductRequest + 2, // 1: aiserver.Aiserver.ApiAddUse:input_type -> aiserver.ApiAddUseRequest + 3, // 2: aiserver.Aiserver.ApiProductItems:input_type -> aiserver.ApiProductItemsRequest + 4, // 3: aiserver.Aiserver.ApiAddPlanning:input_type -> aiserver.ApiEditPlanningRequest + 5, // 4: aiserver.Aiserver.ApiEditPlanningProduct:input_type -> aiserver.ApiEditPlanningProductRequest + 4, // 5: aiserver.Aiserver.ApiEditPlanning:input_type -> aiserver.ApiEditPlanningRequest + 7, // 6: aiserver.Aiserver.ApiPlanningItems:input_type -> aiserver.EmptyRequest + 6, // 7: aiserver.Aiserver.ApiPlanningDelete:input_type -> aiserver.ApiPlanningDeleteRequest + 7, // 8: aiserver.Aiserver.ApiWeather:input_type -> aiserver.EmptyRequest + 8, // 9: aiserver.Aiserver.ApiUsedItems:input_type -> aiserver.ApiUsedItemsRequest + 7, // 10: aiserver.Aiserver.ApiSystemTime:input_type -> aiserver.EmptyRequest + 9, // 11: aiserver.Aiserver.ApiSystemSet:input_type -> aiserver.ApiSystemSetRequest + 7, // 12: aiserver.Aiserver.ApiGetSystem:input_type -> aiserver.EmptyRequest + 0, // 13: aiserver.Aiserver.ApiAddProduct:output_type -> aiserver.Response + 0, // 14: aiserver.Aiserver.ApiAddUse:output_type -> aiserver.Response + 0, // 15: aiserver.Aiserver.ApiProductItems:output_type -> aiserver.Response + 0, // 16: aiserver.Aiserver.ApiAddPlanning:output_type -> aiserver.Response + 0, // 17: aiserver.Aiserver.ApiEditPlanningProduct:output_type -> aiserver.Response + 0, // 18: aiserver.Aiserver.ApiEditPlanning:output_type -> aiserver.Response + 0, // 19: aiserver.Aiserver.ApiPlanningItems:output_type -> aiserver.Response + 0, // 20: aiserver.Aiserver.ApiPlanningDelete:output_type -> aiserver.Response + 0, // 21: aiserver.Aiserver.ApiWeather:output_type -> aiserver.Response + 0, // 22: aiserver.Aiserver.ApiUsedItems:output_type -> aiserver.Response + 0, // 23: aiserver.Aiserver.ApiSystemTime:output_type -> aiserver.Response + 0, // 24: aiserver.Aiserver.ApiSystemSet:output_type -> aiserver.Response + 0, // 25: aiserver.Aiserver.ApiGetSystem:output_type -> aiserver.Response + 13, // [13:26] is the sub-list for method output_type + 0, // [0:13] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_aiserver_aiserver_proto_init() } +func file_aiserver_aiserver_proto_init() { + if File_aiserver_aiserver_proto != nil { + return + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: unsafe.Slice(unsafe.StringData(file_aiserver_aiserver_proto_rawDesc), len(file_aiserver_aiserver_proto_rawDesc)), + NumEnums: 0, + NumMessages: 10, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_aiserver_aiserver_proto_goTypes, + DependencyIndexes: file_aiserver_aiserver_proto_depIdxs, + MessageInfos: file_aiserver_aiserver_proto_msgTypes, + }.Build() + File_aiserver_aiserver_proto = out.File + file_aiserver_aiserver_proto_goTypes = nil + file_aiserver_aiserver_proto_depIdxs = nil +} diff --git a/rpc/aiserver/pb/aiserver_grpc.pb.go b/rpc/aiserver/pb/aiserver_grpc.pb.go new file mode 100644 index 0000000..b83a208 --- /dev/null +++ b/rpc/aiserver/pb/aiserver_grpc.pb.go @@ -0,0 +1,603 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.6.2 +// - protoc v4.25.8 +// source: aiserver/aiserver.proto + +package aiserver + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.64.0 or later. +const _ = grpc.SupportPackageIsVersion9 + +const ( + Aiserver_ApiAddProduct_FullMethodName = "/aiserver.Aiserver/ApiAddProduct" + Aiserver_ApiAddUse_FullMethodName = "/aiserver.Aiserver/ApiAddUse" + Aiserver_ApiProductItems_FullMethodName = "/aiserver.Aiserver/ApiProductItems" + Aiserver_ApiAddPlanning_FullMethodName = "/aiserver.Aiserver/ApiAddPlanning" + Aiserver_ApiEditPlanningProduct_FullMethodName = "/aiserver.Aiserver/ApiEditPlanningProduct" + Aiserver_ApiEditPlanning_FullMethodName = "/aiserver.Aiserver/ApiEditPlanning" + Aiserver_ApiPlanningItems_FullMethodName = "/aiserver.Aiserver/ApiPlanningItems" + Aiserver_ApiPlanningDelete_FullMethodName = "/aiserver.Aiserver/ApiPlanningDelete" + Aiserver_ApiWeather_FullMethodName = "/aiserver.Aiserver/ApiWeather" + Aiserver_ApiUsedItems_FullMethodName = "/aiserver.Aiserver/ApiUsedItems" + Aiserver_ApiSystemTime_FullMethodName = "/aiserver.Aiserver/ApiSystemTime" + Aiserver_ApiSystemSet_FullMethodName = "/aiserver.Aiserver/ApiSystemSet" + Aiserver_ApiGetSystem_FullMethodName = "/aiserver.Aiserver/ApiGetSystem" +) + +// AiserverClient is the client API for Aiserver 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. +type AiserverClient interface { + // 添加产品 + ApiAddProduct(ctx context.Context, in *ApiAddProductRequest, opts ...grpc.CallOption) (*Response, error) + // 添加使用记录 + ApiAddUse(ctx context.Context, in *ApiAddUseRequest, opts ...grpc.CallOption) (*Response, error) + // 获取产品信息 + ApiProductItems(ctx context.Context, in *ApiProductItemsRequest, opts ...grpc.CallOption) (*Response, error) + // 添加方案 + ApiAddPlanning(ctx context.Context, in *ApiEditPlanningRequest, opts ...grpc.CallOption) (*Response, error) + // 编辑方案产品 + ApiEditPlanningProduct(ctx context.Context, in *ApiEditPlanningProductRequest, opts ...grpc.CallOption) (*Response, error) + // 编辑方案 + ApiEditPlanning(ctx context.Context, in *ApiEditPlanningRequest, opts ...grpc.CallOption) (*Response, error) + // 方案列表 + ApiPlanningItems(ctx context.Context, in *EmptyRequest, opts ...grpc.CallOption) (*Response, error) + // 方案删除 + ApiPlanningDelete(ctx context.Context, in *ApiPlanningDeleteRequest, opts ...grpc.CallOption) (*Response, error) + // 获取天气 + ApiWeather(ctx context.Context, in *EmptyRequest, opts ...grpc.CallOption) (*Response, error) + // 获取使用记录 + ApiUsedItems(ctx context.Context, in *ApiUsedItemsRequest, opts ...grpc.CallOption) (*Response, error) + // 获取系统时间 + ApiSystemTime(ctx context.Context, in *EmptyRequest, opts ...grpc.CallOption) (*Response, error) + // 设置系统参数 + ApiSystemSet(ctx context.Context, in *ApiSystemSetRequest, opts ...grpc.CallOption) (*Response, error) + // 获取系统设置 + ApiGetSystem(ctx context.Context, in *EmptyRequest, opts ...grpc.CallOption) (*Response, error) +} + +type aiserverClient struct { + cc grpc.ClientConnInterface +} + +func NewAiserverClient(cc grpc.ClientConnInterface) AiserverClient { + return &aiserverClient{cc} +} + +func (c *aiserverClient) ApiAddProduct(ctx context.Context, in *ApiAddProductRequest, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Aiserver_ApiAddProduct_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *aiserverClient) ApiAddUse(ctx context.Context, in *ApiAddUseRequest, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Aiserver_ApiAddUse_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *aiserverClient) ApiProductItems(ctx context.Context, in *ApiProductItemsRequest, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Aiserver_ApiProductItems_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *aiserverClient) ApiAddPlanning(ctx context.Context, in *ApiEditPlanningRequest, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Aiserver_ApiAddPlanning_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *aiserverClient) ApiEditPlanningProduct(ctx context.Context, in *ApiEditPlanningProductRequest, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Aiserver_ApiEditPlanningProduct_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *aiserverClient) ApiEditPlanning(ctx context.Context, in *ApiEditPlanningRequest, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Aiserver_ApiEditPlanning_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *aiserverClient) ApiPlanningItems(ctx context.Context, in *EmptyRequest, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Aiserver_ApiPlanningItems_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *aiserverClient) ApiPlanningDelete(ctx context.Context, in *ApiPlanningDeleteRequest, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Aiserver_ApiPlanningDelete_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *aiserverClient) ApiWeather(ctx context.Context, in *EmptyRequest, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Aiserver_ApiWeather_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *aiserverClient) ApiUsedItems(ctx context.Context, in *ApiUsedItemsRequest, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Aiserver_ApiUsedItems_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *aiserverClient) ApiSystemTime(ctx context.Context, in *EmptyRequest, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Aiserver_ApiSystemTime_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *aiserverClient) ApiSystemSet(ctx context.Context, in *ApiSystemSetRequest, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Aiserver_ApiSystemSet_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *aiserverClient) ApiGetSystem(ctx context.Context, in *EmptyRequest, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Aiserver_ApiGetSystem_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +// AiserverServer is the server API for Aiserver service. +// All implementations must embed UnimplementedAiserverServer +// for forward compatibility. +type AiserverServer interface { + // 添加产品 + ApiAddProduct(context.Context, *ApiAddProductRequest) (*Response, error) + // 添加使用记录 + ApiAddUse(context.Context, *ApiAddUseRequest) (*Response, error) + // 获取产品信息 + ApiProductItems(context.Context, *ApiProductItemsRequest) (*Response, error) + // 添加方案 + ApiAddPlanning(context.Context, *ApiEditPlanningRequest) (*Response, error) + // 编辑方案产品 + ApiEditPlanningProduct(context.Context, *ApiEditPlanningProductRequest) (*Response, error) + // 编辑方案 + ApiEditPlanning(context.Context, *ApiEditPlanningRequest) (*Response, error) + // 方案列表 + ApiPlanningItems(context.Context, *EmptyRequest) (*Response, error) + // 方案删除 + ApiPlanningDelete(context.Context, *ApiPlanningDeleteRequest) (*Response, error) + // 获取天气 + ApiWeather(context.Context, *EmptyRequest) (*Response, error) + // 获取使用记录 + ApiUsedItems(context.Context, *ApiUsedItemsRequest) (*Response, error) + // 获取系统时间 + ApiSystemTime(context.Context, *EmptyRequest) (*Response, error) + // 设置系统参数 + ApiSystemSet(context.Context, *ApiSystemSetRequest) (*Response, error) + // 获取系统设置 + ApiGetSystem(context.Context, *EmptyRequest) (*Response, error) + mustEmbedUnimplementedAiserverServer() +} + +// UnimplementedAiserverServer must be embedded to have +// forward compatible implementations. +// +// NOTE: this should be embedded by value instead of pointer to avoid a nil +// pointer dereference when methods are called. +type UnimplementedAiserverServer struct{} + +func (UnimplementedAiserverServer) ApiAddProduct(context.Context, *ApiAddProductRequest) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method ApiAddProduct not implemented") +} +func (UnimplementedAiserverServer) ApiAddUse(context.Context, *ApiAddUseRequest) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method ApiAddUse not implemented") +} +func (UnimplementedAiserverServer) ApiProductItems(context.Context, *ApiProductItemsRequest) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method ApiProductItems not implemented") +} +func (UnimplementedAiserverServer) ApiAddPlanning(context.Context, *ApiEditPlanningRequest) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method ApiAddPlanning not implemented") +} +func (UnimplementedAiserverServer) ApiEditPlanningProduct(context.Context, *ApiEditPlanningProductRequest) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method ApiEditPlanningProduct not implemented") +} +func (UnimplementedAiserverServer) ApiEditPlanning(context.Context, *ApiEditPlanningRequest) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method ApiEditPlanning not implemented") +} +func (UnimplementedAiserverServer) ApiPlanningItems(context.Context, *EmptyRequest) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method ApiPlanningItems not implemented") +} +func (UnimplementedAiserverServer) ApiPlanningDelete(context.Context, *ApiPlanningDeleteRequest) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method ApiPlanningDelete not implemented") +} +func (UnimplementedAiserverServer) ApiWeather(context.Context, *EmptyRequest) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method ApiWeather not implemented") +} +func (UnimplementedAiserverServer) ApiUsedItems(context.Context, *ApiUsedItemsRequest) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method ApiUsedItems not implemented") +} +func (UnimplementedAiserverServer) ApiSystemTime(context.Context, *EmptyRequest) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method ApiSystemTime not implemented") +} +func (UnimplementedAiserverServer) ApiSystemSet(context.Context, *ApiSystemSetRequest) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method ApiSystemSet not implemented") +} +func (UnimplementedAiserverServer) ApiGetSystem(context.Context, *EmptyRequest) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method ApiGetSystem not implemented") +} +func (UnimplementedAiserverServer) mustEmbedUnimplementedAiserverServer() {} +func (UnimplementedAiserverServer) testEmbeddedByValue() {} + +// UnsafeAiserverServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to AiserverServer will +// result in compilation errors. +type UnsafeAiserverServer interface { + mustEmbedUnimplementedAiserverServer() +} + +func RegisterAiserverServer(s grpc.ServiceRegistrar, srv AiserverServer) { + // If the following call panics, it indicates UnimplementedAiserverServer was + // embedded by pointer and is nil. This will cause panics if an + // unimplemented method is ever invoked, so we test this at initialization + // time to prevent it from happening at runtime later due to I/O. + if t, ok := srv.(interface{ testEmbeddedByValue() }); ok { + t.testEmbeddedByValue() + } + s.RegisterService(&Aiserver_ServiceDesc, srv) +} + +func _Aiserver_ApiAddProduct_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ApiAddProductRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AiserverServer).ApiAddProduct(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Aiserver_ApiAddProduct_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AiserverServer).ApiAddProduct(ctx, req.(*ApiAddProductRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Aiserver_ApiAddUse_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ApiAddUseRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AiserverServer).ApiAddUse(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Aiserver_ApiAddUse_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AiserverServer).ApiAddUse(ctx, req.(*ApiAddUseRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Aiserver_ApiProductItems_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ApiProductItemsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AiserverServer).ApiProductItems(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Aiserver_ApiProductItems_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AiserverServer).ApiProductItems(ctx, req.(*ApiProductItemsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Aiserver_ApiAddPlanning_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ApiEditPlanningRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AiserverServer).ApiAddPlanning(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Aiserver_ApiAddPlanning_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AiserverServer).ApiAddPlanning(ctx, req.(*ApiEditPlanningRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Aiserver_ApiEditPlanningProduct_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ApiEditPlanningProductRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AiserverServer).ApiEditPlanningProduct(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Aiserver_ApiEditPlanningProduct_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AiserverServer).ApiEditPlanningProduct(ctx, req.(*ApiEditPlanningProductRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Aiserver_ApiEditPlanning_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ApiEditPlanningRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AiserverServer).ApiEditPlanning(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Aiserver_ApiEditPlanning_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AiserverServer).ApiEditPlanning(ctx, req.(*ApiEditPlanningRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Aiserver_ApiPlanningItems_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(EmptyRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AiserverServer).ApiPlanningItems(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Aiserver_ApiPlanningItems_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AiserverServer).ApiPlanningItems(ctx, req.(*EmptyRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Aiserver_ApiPlanningDelete_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ApiPlanningDeleteRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AiserverServer).ApiPlanningDelete(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Aiserver_ApiPlanningDelete_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AiserverServer).ApiPlanningDelete(ctx, req.(*ApiPlanningDeleteRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Aiserver_ApiWeather_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(EmptyRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AiserverServer).ApiWeather(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Aiserver_ApiWeather_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AiserverServer).ApiWeather(ctx, req.(*EmptyRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Aiserver_ApiUsedItems_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ApiUsedItemsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AiserverServer).ApiUsedItems(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Aiserver_ApiUsedItems_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AiserverServer).ApiUsedItems(ctx, req.(*ApiUsedItemsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Aiserver_ApiSystemTime_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(EmptyRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AiserverServer).ApiSystemTime(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Aiserver_ApiSystemTime_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AiserverServer).ApiSystemTime(ctx, req.(*EmptyRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Aiserver_ApiSystemSet_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ApiSystemSetRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AiserverServer).ApiSystemSet(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Aiserver_ApiSystemSet_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AiserverServer).ApiSystemSet(ctx, req.(*ApiSystemSetRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Aiserver_ApiGetSystem_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(EmptyRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AiserverServer).ApiGetSystem(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Aiserver_ApiGetSystem_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AiserverServer).ApiGetSystem(ctx, req.(*EmptyRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// Aiserver_ServiceDesc is the grpc.ServiceDesc for Aiserver service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var Aiserver_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "aiserver.Aiserver", + HandlerType: (*AiserverServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "ApiAddProduct", + Handler: _Aiserver_ApiAddProduct_Handler, + }, + { + MethodName: "ApiAddUse", + Handler: _Aiserver_ApiAddUse_Handler, + }, + { + MethodName: "ApiProductItems", + Handler: _Aiserver_ApiProductItems_Handler, + }, + { + MethodName: "ApiAddPlanning", + Handler: _Aiserver_ApiAddPlanning_Handler, + }, + { + MethodName: "ApiEditPlanningProduct", + Handler: _Aiserver_ApiEditPlanningProduct_Handler, + }, + { + MethodName: "ApiEditPlanning", + Handler: _Aiserver_ApiEditPlanning_Handler, + }, + { + MethodName: "ApiPlanningItems", + Handler: _Aiserver_ApiPlanningItems_Handler, + }, + { + MethodName: "ApiPlanningDelete", + Handler: _Aiserver_ApiPlanningDelete_Handler, + }, + { + MethodName: "ApiWeather", + Handler: _Aiserver_ApiWeather_Handler, + }, + { + MethodName: "ApiUsedItems", + Handler: _Aiserver_ApiUsedItems_Handler, + }, + { + MethodName: "ApiSystemTime", + Handler: _Aiserver_ApiSystemTime_Handler, + }, + { + MethodName: "ApiSystemSet", + Handler: _Aiserver_ApiSystemSet_Handler, + }, + { + MethodName: "ApiGetSystem", + Handler: _Aiserver_ApiGetSystem_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "aiserver/aiserver.proto", +} diff --git a/rpc/water/pb/water.pb.go b/rpc/water/pb/water.pb.go index 93ea87f..ddfc15e 100644 --- a/rpc/water/pb/water.pb.go +++ b/rpc/water/pb/water.pb.go @@ -225,8 +225,9 @@ func (x *LogItemsRequest) GetHostCode() string { type AddLogRequest struct { state protoimpl.MessageState `protogen:"open.v1"` HostCode string `protobuf:"bytes,1,opt,name=host_code,json=hostCode,proto3" json:"host_code,omitempty"` - Data string `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` - Time string `protobuf:"bytes,3,opt,name=time,proto3" json:"time,omitempty"` + Time string `protobuf:"bytes,2,opt,name=time,proto3" json:"time,omitempty"` + Salt int64 `protobuf:"varint,3,opt,name=salt,proto3" json:"salt,omitempty"` + Water int64 `protobuf:"varint,4,opt,name=water,proto3" json:"water,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -268,13 +269,6 @@ func (x *AddLogRequest) GetHostCode() string { return "" } -func (x *AddLogRequest) GetData() string { - if x != nil { - return x.Data - } - return "" -} - func (x *AddLogRequest) GetTime() string { if x != nil { return x.Time @@ -282,6 +276,20 @@ func (x *AddLogRequest) GetTime() string { return "" } +func (x *AddLogRequest) GetSalt() int64 { + if x != nil { + return x.Salt + } + return 0 +} + +func (x *AddLogRequest) GetWater() int64 { + if x != nil { + return x.Water + } + return 0 +} + type Response struct { state protoimpl.MessageState `protogen:"open.v1"` Code int32 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` @@ -386,6 +394,7 @@ type SettingRequest struct { RefreshTime string `protobuf:"bytes,4,opt,name=refresh_time,json=refreshTime,proto3" json:"refresh_time,omitempty"` UseNumber int32 `protobuf:"varint,5,opt,name=use_number,json=useNumber,proto3" json:"use_number,omitempty"` Soften int32 `protobuf:"varint,6,opt,name=soften,proto3" json:"soften,omitempty"` + NoDisturbing string `protobuf:"bytes,7,opt,name=no_disturbing,json=noDisturbing,proto3" json:"no_disturbing,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -462,6 +471,13 @@ func (x *SettingRequest) GetSoften() int32 { return 0 } +func (x *SettingRequest) GetNoDisturbing() string { + if x != nil { + return x.NoDisturbing + } + return "" +} + var File_water_water_proto protoreflect.FileDescriptor const file_water_water_proto_rawDesc = "" + @@ -477,16 +493,17 @@ const file_water_water_proto_rawDesc = "" + "\x04page\x18\x01 \x01(\x05R\x04page\x12\x12\n" + "\x04size\x18\x02 \x01(\x05R\x04size\x12\x12\n" + "\x04time\x18\x03 \x03(\tR\x04time\x12\x1b\n" + - "\thost_code\x18\x04 \x01(\tR\bhostCode\"T\n" + + "\thost_code\x18\x04 \x01(\tR\bhostCode\"j\n" + "\rAddLogRequest\x12\x1b\n" + "\thost_code\x18\x01 \x01(\tR\bhostCode\x12\x12\n" + - "\x04data\x18\x02 \x01(\tR\x04data\x12\x12\n" + - "\x04time\x18\x03 \x01(\tR\x04time\"D\n" + + "\x04time\x18\x02 \x01(\tR\x04time\x12\x12\n" + + "\x04salt\x18\x03 \x01(\x03R\x04salt\x12\x14\n" + + "\x05water\x18\x04 \x01(\x03R\x05water\"D\n" + "\bResponse\x12\x12\n" + "\x04code\x18\x01 \x01(\x05R\x04code\x12\x10\n" + "\x03msg\x18\x02 \x01(\tR\x03msg\x12\x12\n" + "\x04data\x18\x03 \x01(\tR\x04data\"\x0e\n" + - "\fEmptyRequest\"\xc6\x01\n" + + "\fEmptyRequest\"\xeb\x01\n" + "\x0eSettingRequest\x12\x1b\n" + "\thost_code\x18\x01 \x01(\tR\bhostCode\x12!\n" + "\fsalt_percent\x18\x02 \x01(\x05R\vsaltPercent\x12\x1a\n" + @@ -494,7 +511,8 @@ const file_water_water_proto_rawDesc = "" + "\frefresh_time\x18\x04 \x01(\tR\vrefreshTime\x12\x1d\n" + "\n" + "use_number\x18\x05 \x01(\x05R\tuseNumber\x12\x16\n" + - "\x06soften\x18\x06 \x01(\x05R\x06soften2\x97\x04\n" + + "\x06soften\x18\x06 \x01(\x05R\x06soften\x12#\n" + + "\rno_disturbing\x18\a \x01(\tR\fnoDisturbing2\x97\x04\n" + "\x05Water\x12Z\n" + "\tWifiCheck\x12\x17.water.WifiCheckRequest\x1a\x0f.water.Response\"#\x82\xd3\xe4\x93\x02\x1d:\x01*\x12\x18/api/v3/water/wifi/check\x12T\n" + "\aWifiSet\x12\x15.water.WifiSetRequest\x1a\x0f.water.Response\"!\x82\xd3\xe4\x93\x02\x1b:\x01*\"\x16/api/v3/water/wifi/set\x12Q\n" + diff --git a/rpc/water/water.pb b/rpc/water/water.pb index 24ae2eb..17ae92c 100644 Binary files a/rpc/water/water.pb and b/rpc/water/water.pb differ diff --git a/rpc/water/water.proto b/rpc/water/water.proto index 87ff0c3..4d61c39 100644 --- a/rpc/water/water.proto +++ b/rpc/water/water.proto @@ -25,8 +25,9 @@ message LogItemsRequest { message AddLogRequest { string host_code = 1; - string data = 2; - string time = 3; + string time = 2; + int64 salt = 3; + int64 water = 4; } message Response { @@ -46,6 +47,7 @@ message SettingRequest { string refresh_time = 4; int32 use_number = 5; int32 soften = 6; + string no_disturbing = 7; } diff --git a/services/aiserver/.gitignore b/services/aiserver/.gitignore new file mode 100644 index 0000000..6022c46 --- /dev/null +++ b/services/aiserver/.gitignore @@ -0,0 +1,3 @@ +run.toml +tmp +etc/aiserver.yaml \ No newline at end of file diff --git a/services/aiserver/Dockerfile b/services/aiserver/Dockerfile new file mode 100644 index 0000000..51c39fd --- /dev/null +++ b/services/aiserver/Dockerfile @@ -0,0 +1,37 @@ +FROM golang:1.26.5-alpine AS builder + +WORKDIR /src + +ENV GOPROXY=https://goproxy.cn,direct \ + CGO_ENABLED=0 \ + GOOS=linux \ + GOARCH=amd64 + +COPY pkg ./pkg +COPY go.mod go.sum ./ + +RUN --mount=type=cache,target=/go/pkg/mod \ + go mod download + +COPY rpc/ ./rpc +COPY services/aiserver/ ./services/aiserver/ + +WORKDIR /src/services/aiserver + +RUN --mount=type=cache,target=/go/pkg/mod \ + --mount=type=cache,target=/root/.cache/go-build \ + go build -ldflags="-s -w" -o /out/main ./ + +FROM alpine:3.22 + +WORKDIR /app + +ENV TZ=Asia/Shanghai + +RUN apk add --no-cache tzdata \ + && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ + && echo "Asia/Shanghai" > /etc/timezone + +COPY --from=builder /out/main . + +CMD ["./main", "-f", "etc/aiserver.yaml"] diff --git a/services/aiserver/aiserver.go b/services/aiserver/aiserver.go new file mode 100644 index 0000000..ce19951 --- /dev/null +++ b/services/aiserver/aiserver.go @@ -0,0 +1,170 @@ +package main + +import ( + "flag" + "lone-services/pkg/discovery" + "lone-services/pkg/logRedis" + "lone-services/pkg/modelbase" + "lone-services/pkg/mysql" + "lone-services/pkg/redis" + "lone-services/pkg/utils" + "lone-services/pkg/validate" + aiserver "lone-services/rpc/aiserver/pb" + "net" + "os" + "strconv" + + "lone-services/services/aiserver/internal/config" + "lone-services/services/aiserver/internal/server" + "lone-services/services/aiserver/internal/svc" + + "github.com/zeromicro/go-zero/core/conf" + "github.com/zeromicro/go-zero/core/logx" + "github.com/zeromicro/go-zero/core/service" + "github.com/zeromicro/go-zero/zrpc" + "google.golang.org/grpc" + "google.golang.org/grpc/reflection" +) + +var configFile = flag.String("f", "etc/aiserver.yaml", "the config file") + +func main() { + flag.Parse() + var c config.Config + conf.MustLoad(*configFile, &c) + + // Nacos配置拉取初始化 + nacosParam := utils.NacosConfig{ + Hosts: c.Nacos.Hosts, + NamespaceId: c.Nacos.NamespaceId, + Group: c.Nacos.Group, + ConfigID: c.Nacos.ConfigID, + } + utils.InitConfig(nacosParam) + + // 日志配置 + logConf := logx.LogConf{ + ServiceName: utils.GetConfigString("log.serviceName"), + Mode: utils.GetConfigString("log.mode"), + Encoding: utils.GetConfigString("log.encoding"), + Level: utils.GetConfigString("log.level"), + Path: utils.GetConfigString("log.path"), + KeepDays: utils.GetConfigInt("log.keepDays"), + MaxSize: utils.GetConfigInt("log.maxSize"), + MaxBackups: utils.GetConfigInt("log.maxBackups"), + Compress: utils.GetConfigBool("log.compress"), + } + logx.SetUp(logConf) + logx.AddWriter(logx.NewWriter(os.Stdout)) + + listenOn := utils.GetConfigString("base.listenOn") + mode := utils.GetConfigString("base.mode") + serviceName := utils.GetConfigString("base.name") + + // 初始化服务发现 + if err := discovery.Init(discovery.Config{ + Hosts: c.Nacos.Hosts, + NamespaceId: c.Nacos.NamespaceId, + Group: c.Nacos.Group, + }); err != nil { + logx.Errorf("nacos init: %v", err) + os.Exit(1) + } + + port, err := listenPort(listenOn) + if err != nil { + logx.Errorf("parse ListenOn: %v", err) + os.Exit(1) + } + + // 注册服务 + if err := discovery.Register(discovery.Instance{ + ServiceName: serviceName, + IP: c.Nacos.RegisterIP, + Port: port, + Group: c.Nacos.Group, + }); err != nil { + logx.Errorf("nacos register: %v", err) + os.Exit(1) + } + logx.Infof("服务注册成功: %s:%d", c.Nacos.RegisterIP, port) + + defer func() { + if err := discovery.Deregister(); err != nil { + logx.Errorf("nacos deregister: %v", err) + } + }() + + // 初始化MySQL + db, err := mysql.New(mysql.Config{ + Host: utils.GetConfigString("mysql.host"), + Port: utils.GetConfigInt("mysql.port"), + User: utils.GetConfigString("mysql.user"), + Password: utils.GetConfigString("mysql.password"), + Database: utils.GetConfigString("mysql.database"), + Charset: utils.GetConfigString("mysql.charset"), + Prefix: utils.GetConfigString("mysql.prefix"), + ReadHost: utils.GetConfigString("mysql_read.host"), + ReadPort: utils.GetConfigInt("mysql_read.port"), + ReadUser: utils.GetConfigString("mysql_read.user"), + ReadPassword: utils.GetConfigString("mysql_read.password"), + ReadDatabase: utils.GetConfigString("mysql_read.database"), + }) + if err != nil { + logx.Errorf("mysql init: %v", err) + os.Exit(1) + } + + // 初始化Redis + if err := redis.Init(redis.Config{ + Host: utils.GetConfigString("redis.host"), + Port: utils.GetConfigInt("redis.port"), + Password: utils.GetConfigString("redis.password"), + DB: utils.GetConfigInt("redis.db"), + }); err != nil { + logx.Errorf("redis init: %v", err) + os.Exit(1) + } + + if err := logRedis.Init(logRedis.LogRedisConfig{ + Host: utils.GetConfigString("log-redis.host"), + Port: utils.GetConfigInt("log-redis.port"), + Password: utils.GetConfigString("log-redis.password"), + DB: utils.GetConfigInt("log-redis.db"), + }); err != nil { + logx.Errorf("log redis init: %v", err) + os.Exit(1) + } + + debug := utils.GetConfigBool("mysql.debug") + modelbase.Init(db, modelbase.Config{Prefix: utils.GetConfigString("mysql.prefix"), Debug: debug}) + + // 初始化服务信息 + rpcConf := zrpc.RpcServerConf{ + ListenOn: listenOn, + } + rpcConf.Mode = mode + ctx := svc.NewServiceContext(c, db) + + s := zrpc.MustNewServer(rpcConf, func(grpcServer *grpc.Server) { + aiserver.RegisterAiserverServer(grpcServer, server.NewAiserverServer(ctx)) + if mode == service.DevMode || mode == service.TestMode { + reflection.Register(grpcServer) + } + }) + defer s.Stop() + + s.AddUnaryInterceptors(validate.UnaryServerInterceptor(validate.MustNew())) + + logx.Infof("Starting rpc server at %s...", listenOn) + s.Start() +} + +// listenPort 拆分端口 +func listenPort(listenOn string) (uint64, error) { + _, portStr, err := net.SplitHostPort(listenOn) + if err != nil { + return utils.NumberZero, err + } + return strconv.ParseUint(portStr, utils.NumberTen, utils.NumberSixtyFourth) +} diff --git a/services/aiserver/aiserverclient/aiserver.go b/services/aiserver/aiserverclient/aiserver.go new file mode 100644 index 0000000..21b140e --- /dev/null +++ b/services/aiserver/aiserverclient/aiserver.go @@ -0,0 +1,144 @@ +// Code generated by goctl. DO NOT EDIT. +// goctl 1.10.2 +// Source: aiserver.proto + +package aiserverClient + +import ( + "context" + + "lone-services/rpc/aiserver/pb" + + "github.com/zeromicro/go-zero/zrpc" + "google.golang.org/grpc" +) + +type ( + ApiAddProductRequest = aiserver.ApiAddProductRequest + ApiAddUseRequest = aiserver.ApiAddUseRequest + ApiEditPlanningProductRequest = aiserver.ApiEditPlanningProductRequest + ApiEditPlanningRequest = aiserver.ApiEditPlanningRequest + ApiPlanningDeleteRequest = aiserver.ApiPlanningDeleteRequest + ApiProductItemsRequest = aiserver.ApiProductItemsRequest + ApiSystemSetRequest = aiserver.ApiSystemSetRequest + ApiUsedItemsRequest = aiserver.ApiUsedItemsRequest + EmptyRequest = aiserver.EmptyRequest + Response = aiserver.Response + + Aiserver interface { + // 添加产品 + ApiAddProduct(ctx context.Context, in *ApiAddProductRequest, opts ...grpc.CallOption) (*Response, error) + // 添加使用记录 + ApiAddUse(ctx context.Context, in *ApiAddUseRequest, opts ...grpc.CallOption) (*Response, error) + // 获取产品信息 + ApiProductItems(ctx context.Context, in *ApiProductItemsRequest, opts ...grpc.CallOption) (*Response, error) + // 添加方案 + ApiAddPlanning(ctx context.Context, in *ApiEditPlanningRequest, opts ...grpc.CallOption) (*Response, error) + // 编辑方案产品 + ApiEditPlanningProduct(ctx context.Context, in *ApiEditPlanningProductRequest, opts ...grpc.CallOption) (*Response, error) + // 编辑方案 + ApiEditPlanning(ctx context.Context, in *ApiEditPlanningRequest, opts ...grpc.CallOption) (*Response, error) + // 方案列表 + ApiPlanningItems(ctx context.Context, in *EmptyRequest, opts ...grpc.CallOption) (*Response, error) + // 方案删除 + ApiPlanningDelete(ctx context.Context, in *ApiPlanningDeleteRequest, opts ...grpc.CallOption) (*Response, error) + // 获取天气 + ApiWeather(ctx context.Context, in *EmptyRequest, opts ...grpc.CallOption) (*Response, error) + // 获取使用记录 + ApiUsedItems(ctx context.Context, in *ApiUsedItemsRequest, opts ...grpc.CallOption) (*Response, error) + // 获取系统时间 + ApiSystemTime(ctx context.Context, in *EmptyRequest, opts ...grpc.CallOption) (*Response, error) + // 设置系统参数 + ApiSystemSet(ctx context.Context, in *ApiSystemSetRequest, opts ...grpc.CallOption) (*Response, error) + // 获取系统设置 + ApiGetSystem(ctx context.Context, in *EmptyRequest, opts ...grpc.CallOption) (*Response, error) + } + + defaultAiserver struct { + cli zrpc.Client + } +) + +func NewAiserver(cli zrpc.Client) Aiserver { + return &defaultAiserver{ + cli: cli, + } +} + +// 添加产品 +func (m *defaultAiserver) ApiAddProduct(ctx context.Context, in *ApiAddProductRequest, opts ...grpc.CallOption) (*Response, error) { + client := aiserver.NewAiserverClient(m.cli.Conn()) + return client.ApiAddProduct(ctx, in, opts...) +} + +// 添加使用记录 +func (m *defaultAiserver) ApiAddUse(ctx context.Context, in *ApiAddUseRequest, opts ...grpc.CallOption) (*Response, error) { + client := aiserver.NewAiserverClient(m.cli.Conn()) + return client.ApiAddUse(ctx, in, opts...) +} + +// 获取产品信息 +func (m *defaultAiserver) ApiProductItems(ctx context.Context, in *ApiProductItemsRequest, opts ...grpc.CallOption) (*Response, error) { + client := aiserver.NewAiserverClient(m.cli.Conn()) + return client.ApiProductItems(ctx, in, opts...) +} + +// 添加方案 +func (m *defaultAiserver) ApiAddPlanning(ctx context.Context, in *ApiEditPlanningRequest, opts ...grpc.CallOption) (*Response, error) { + client := aiserver.NewAiserverClient(m.cli.Conn()) + return client.ApiAddPlanning(ctx, in, opts...) +} + +// 编辑方案产品 +func (m *defaultAiserver) ApiEditPlanningProduct(ctx context.Context, in *ApiEditPlanningProductRequest, opts ...grpc.CallOption) (*Response, error) { + client := aiserver.NewAiserverClient(m.cli.Conn()) + return client.ApiEditPlanningProduct(ctx, in, opts...) +} + +// 编辑方案 +func (m *defaultAiserver) ApiEditPlanning(ctx context.Context, in *ApiEditPlanningRequest, opts ...grpc.CallOption) (*Response, error) { + client := aiserver.NewAiserverClient(m.cli.Conn()) + return client.ApiEditPlanning(ctx, in, opts...) +} + +// 方案列表 +func (m *defaultAiserver) ApiPlanningItems(ctx context.Context, in *EmptyRequest, opts ...grpc.CallOption) (*Response, error) { + client := aiserver.NewAiserverClient(m.cli.Conn()) + return client.ApiPlanningItems(ctx, in, opts...) +} + +// 方案删除 +func (m *defaultAiserver) ApiPlanningDelete(ctx context.Context, in *ApiPlanningDeleteRequest, opts ...grpc.CallOption) (*Response, error) { + client := aiserver.NewAiserverClient(m.cli.Conn()) + return client.ApiPlanningDelete(ctx, in, opts...) +} + +// 获取天气 +func (m *defaultAiserver) ApiWeather(ctx context.Context, in *EmptyRequest, opts ...grpc.CallOption) (*Response, error) { + client := aiserver.NewAiserverClient(m.cli.Conn()) + return client.ApiWeather(ctx, in, opts...) +} + +// 获取使用记录 +func (m *defaultAiserver) ApiUsedItems(ctx context.Context, in *ApiUsedItemsRequest, opts ...grpc.CallOption) (*Response, error) { + client := aiserver.NewAiserverClient(m.cli.Conn()) + return client.ApiUsedItems(ctx, in, opts...) +} + +// 获取系统时间 +func (m *defaultAiserver) ApiSystemTime(ctx context.Context, in *EmptyRequest, opts ...grpc.CallOption) (*Response, error) { + client := aiserver.NewAiserverClient(m.cli.Conn()) + return client.ApiSystemTime(ctx, in, opts...) +} + +// 设置系统参数 +func (m *defaultAiserver) ApiSystemSet(ctx context.Context, in *ApiSystemSetRequest, opts ...grpc.CallOption) (*Response, error) { + client := aiserver.NewAiserverClient(m.cli.Conn()) + return client.ApiSystemSet(ctx, in, opts...) +} + +// 获取系统设置 +func (m *defaultAiserver) ApiGetSystem(ctx context.Context, in *EmptyRequest, opts ...grpc.CallOption) (*Response, error) { + client := aiserver.NewAiserverClient(m.cli.Conn()) + return client.ApiGetSystem(ctx, in, opts...) +} diff --git a/services/aiserver/internal/config/config.go b/services/aiserver/internal/config/config.go new file mode 100644 index 0000000..a1979dd --- /dev/null +++ b/services/aiserver/internal/config/config.go @@ -0,0 +1,13 @@ +package config + +type Config struct { + Nacos NacosConf +} + +type NacosConf struct { + Hosts []string + NamespaceId string `json:",optional"` + Group string `json:",optional"` + RegisterIP string `json:",optional"` + ConfigID string `json:",optional"` +} diff --git a/services/aiserver/internal/dao/planning.go b/services/aiserver/internal/dao/planning.go new file mode 100644 index 0000000..6249c00 --- /dev/null +++ b/services/aiserver/internal/dao/planning.go @@ -0,0 +1,24 @@ +package dao + +import "lone-services/pkg/utils" + +// PlanningCreate 权限表 +type PlanningCreate struct { + Id int64 `gorm:"column:id;type:int;not null;autoIncrement" json:"id"` + UserId int64 `gorm:"column:user_id;type:int;not null" json:"user_id"` // 用户ID + Name string `gorm:"column:name;type:varchar(255);default:NULL" json:"name"` // 名称 + BeginTime string `gorm:"column:begin_time;type:char(10);not null;default:''" json:"begin_time"` // 计划开始时间 + EndTime string `gorm:"column:end_time;type:char(10);not null;default:''" json:"end_time"` // 计划结束时间 + Status int32 `gorm:"column:status;type:tinyint(1);not null;default:1" json:"status"` // 状态:1为正常,2为删除 + +} + +type PlanningInfo struct { + Id int64 `gorm:"column:id;type:int;not null;autoIncrement" json:"id"` + UserId int64 `gorm:"column:user_id;type:int;not null" json:"user_id"` // 用户ID + Name string `gorm:"column:name;type:varchar(255);default:NULL" json:"name"` // 名称 + BeginTime string `gorm:"column:begin_time;type:char(10);not null;default:''" json:"begin_time"` // 计划开始时间 + EndTime string `gorm:"column:end_time;type:char(10);not null;default:''" json:"end_time"` // 计划结束时间 + Status int32 `gorm:"column:status;type:tinyint(1);not null;default:1" json:"status"` // 状态:1为正常,2为删除 + CreateTime utils.CustomTime `json:"create_time"` +} diff --git a/services/aiserver/internal/dao/planningProduct.go b/services/aiserver/internal/dao/planningProduct.go new file mode 100644 index 0000000..2b32784 --- /dev/null +++ b/services/aiserver/internal/dao/planningProduct.go @@ -0,0 +1,26 @@ +package dao + +import "lone-services/pkg/utils" + +// PlanningProductCreate 权限表 +type PlanningProductCreate struct { + Id int64 `gorm:"column:id;type:int;not null;autoIncrement" json:"id"` + UserId int64 `gorm:"column:user_id;type:int;not null" json:"user_id"` // 用户ID + PlanningId int64 `gorm:"column:planning_id;type:int;default:NULL" json:"planning_id"` // 计划ID + ProductId int64 `gorm:"column:product_id;type:int;default:0" json:"product_id"` // 产品ID + Sort int32 `gorm:"column:sort;type:tinyint;default:NULL" json:"sort"` // 排序 + EveryTimeUseMg int32 `gorm:"column:every_time_use_mg;type:smallint;default:NULL" json:"every_time_use_mg"` // 每次使用量 + Status int32 `gorm:"column:status;type:tinyint(1);not null;default:1" json:"status"` // 状态:1为正常,2为删除 + +} + +type PlanningProductInfo struct { + Id int64 `gorm:"column:id;type:int;not null;autoIncrement" json:"id"` + UserId int64 `gorm:"column:user_id;type:int;not null" json:"user_id"` // 用户ID + PlanningId int64 `gorm:"column:planning_id;type:int;default:NULL" json:"planning_id"` // 计划ID + ProductId int64 `gorm:"column:product_id;type:int;default:0" json:"product_id"` // 产品ID + Sort int32 `gorm:"column:sort;type:tinyint;default:NULL" json:"sort"` // 排序 + UseMg int32 `gorm:"column:use_mg;type:smallint;default:NULL" json:"use_mg"` // 每次使用量 + Status int32 `gorm:"column:status;type:tinyint(1);not null;default:1" json:"status"` // 状态:1为正常,2为删除 + CreateTime utils.CustomTime `json:"create_time"` +} diff --git a/services/aiserver/internal/dao/product.go b/services/aiserver/internal/dao/product.go new file mode 100644 index 0000000..3fe21d1 --- /dev/null +++ b/services/aiserver/internal/dao/product.go @@ -0,0 +1,32 @@ +package dao + +import "lone-services/pkg/utils" + +// ProductCreate 权限表 +type ProductCreate struct { + Id int64 `gorm:"column:id;type:int;not null;autoIncrement" json:"id"` + UserId int64 `gorm:"column:user_id;type:int;not null" json:"user_id"` // 用户ID + ProductName string `gorm:"column:product_name;type:varchar(255);default:NULL" json:"product_name"` // 名称 + ProductCode string `gorm:"column:product_code;type:varchar(255);default:''" json:"product_code"` // 产品代码 + ProductSerialNumber string `gorm:"column:product_serial_number;type:varchar(255);default:''" json:"product_serial_number"` // 产品序列号 + ProductId int64 `gorm:"column:product_id;type:int;default:0" json:"product_id"` // 产品ID + UseMg int32 `gorm:"column:use_mg;type:smallint;default:NULL" json:"use_mg"` // 使用量 + TotalMg int32 `gorm:"column:total_mg;type:smallint;default:NULL" json:"total_mg"` // 总量 + DefUseMg int32 `gorm:"column:def_use_mg;type:smallint;default:NULL" json:"def_use_mg"` // 默认每次使用量 + Status int32 `gorm:"column:status;type:tinyint(1);not null;default:1" json:"status"` // 状态:1为正常,2为删除 + +} + +type ProductInfo struct { + Id int64 `gorm:"column:id;type:int;not null;autoIncrement" json:"id"` + UserId int64 `gorm:"column:user_id;type:int;not null" json:"user_id"` // 用户ID + ProductName string `gorm:"column:product_name;type:varchar(255);default:NULL" json:"product_name"` // 名称 + ProductCode string `gorm:"column:product_code;type:varchar(255);default:''" json:"product_code"` // 产品代码 + ProductSerialNumber string `gorm:"column:product_serial_number;type:varchar(255);default:''" json:"product_serial_number"` // 产品序列号 + ProductId int64 `gorm:"column:product_id;type:int;default:0" json:"product_id"` // 产品ID + UseMg int32 `gorm:"column:use_mg;type:smallint;default:NULL" json:"use_mg"` // 使用量 + TotalMg int32 `gorm:"column:total_mg;type:smallint;default:NULL" json:"total_mg"` // 总量 + DefUseMg int32 `gorm:"column:def_use_mg;type:smallint;default:NULL" json:"def_use_mg"` // 默认每次使用量 + Status int32 `gorm:"column:status;type:tinyint(1);not null;default:1" json:"status"` // 状态:1为正常,2为删除 + CreateTime utils.CustomTime `json:"create_time"` +} diff --git a/services/aiserver/internal/dao/setting.go b/services/aiserver/internal/dao/setting.go new file mode 100644 index 0000000..1360437 --- /dev/null +++ b/services/aiserver/internal/dao/setting.go @@ -0,0 +1,32 @@ +package dao + +import "lone-services/pkg/utils" + +// SettingCreate 权限表 +type SettingCreate struct { + Id int64 `gorm:"column:id;type:int;not null;autoIncrement" json:"id"` + UserId int64 `gorm:"column:user_id;type:int;not null" json:"user_id"` // 用户ID + Lang int32 `gorm:"column:lang;type:tinyint(1);not null;default:1" json:"lang"` // 语言:1为中文,2为英文 + Wifi int32 `gorm:"column:wifi;type:tinyint(1);not null;default:2" json:"wifi"` // wifi:1为设置过,2为没有设置过 + Screen int32 `gorm:"column:screen;type:tinyint;not null" json:"screen"` // 屏幕亮度 + Sound int32 `gorm:"column:sound;type:tinyint;not null" json:"sound"` // 声音 + LightOpen int32 `gorm:"column:light_open;type:tinyint(1);not null;default:1" json:"light_open"` // 是否开灯,1为开灯,2为不开灯 + LightWorkTime string `gorm:"column:light_work_time;type:char(50);default:NULL" json:"light_work_time"` // 灯工作时间 + ScreenSleepTime int32 `gorm:"column:screen_sleep_time;type:smallint;default:NULL" json:"screen_sleep_time"` // 屏幕休眠时间 + LightBrightness int32 `gorm:"column:light_brightness;type:tinyint;default:NULL" json:"light_brightness"` // 灯亮度 + +} + +type SettingInfo struct { + Id int64 `gorm:"column:id;type:int;not null;autoIncrement" json:"id"` + UserId int64 `gorm:"column:user_id;type:int;not null" json:"user_id"` // 用户ID + Lang int32 `gorm:"column:lang;type:tinyint(1);not null;default:1" json:"lang"` // 语言:1为中文,2为英文 + Wifi int32 `gorm:"column:wifi;type:tinyint(1);not null;default:2" json:"wifi"` // wifi:1为设置过,2为没有设置过 + Screen int32 `gorm:"column:screen;type:tinyint;not null" json:"screen"` // 屏幕亮度 + Sound int32 `gorm:"column:sound;type:tinyint;not null" json:"sound"` // 声音 + LightOpen int32 `gorm:"column:light_open;type:tinyint(1);not null;default:1" json:"light_open"` // 是否开灯,1为开灯,2为不开灯 + LightWorkTime string `gorm:"column:light_work_time;type:char(50);default:NULL" json:"light_work_time"` // 灯工作时间 + ScreenSleepTime int32 `gorm:"column:screen_sleep_time;type:smallint;default:NULL" json:"screen_sleep_time"` // 屏幕休眠时间 + LightBrightness int32 `gorm:"column:light_brightness;type:tinyint;default:NULL" json:"light_brightness"` // 灯亮度 + CreateTime utils.CustomTime `json:"create_time"` +} diff --git a/services/aiserver/internal/dao/useLog.go b/services/aiserver/internal/dao/useLog.go new file mode 100644 index 0000000..60fe5b9 --- /dev/null +++ b/services/aiserver/internal/dao/useLog.go @@ -0,0 +1,23 @@ +package dao + +import "lone-services/pkg/utils" + +// UseLogCreate 权限表 +type UseLogCreate struct { + Id int64 `gorm:"column:id;type:int;not null;autoIncrement" json:"id"` + UserId int64 `gorm:"column:user_id;type:int;default:NULL" json:"user_id"` // 用户 + ProductId int64 `gorm:"column:product_id;type:int;default:0" json:"product_id"` // 产品ID + ProductName string `gorm:"column:product_name;type:varchar(255);default:NULL" json:"product_name"` // 产品名 + UseMg int32 `gorm:"column:use_mg;type:smallint;not null;default:0" json:"use_mg"` // 使用量 + PlanningId int64 `gorm:"column:planning_id;type:int;not null;default:0" json:"planning_id"` // 计划ID +} + +type UseLogInfo struct { + Id int64 `gorm:"column:id;type:int;not null;autoIncrement" json:"id"` + UserId int64 `gorm:"column:user_id;type:int;default:NULL" json:"user_id"` // 用户 + ProductId int64 `gorm:"column:product_id;type:int;default:0" json:"product_id"` // 产品ID + ProductName string `gorm:"column:product_name;type:varchar(255);default:NULL" json:"product_name"` // 产品名 + UseMg int32 `gorm:"column:use_mg;type:smallint;not null;default:0" json:"use_mg"` // 使用量 + PlanningId int64 `gorm:"column:planning_id;type:int;not null;default:0" json:"planning_id"` // 计划ID + CreateTime utils.CustomTime `json:"create_time"` +} diff --git a/services/aiserver/internal/logic/apiAddPlanningLogic.go b/services/aiserver/internal/logic/apiAddPlanningLogic.go new file mode 100644 index 0000000..ecef187 --- /dev/null +++ b/services/aiserver/internal/logic/apiAddPlanningLogic.go @@ -0,0 +1,54 @@ +package logic + +import ( + "context" + "lone-services/pkg/utils" + "lone-services/services/aiserver/internal/dao" + "lone-services/services/aiserver/internal/model" + "lone-services/services/aiserver/validator" + + "lone-services/rpc/aiserver/pb" + "lone-services/services/aiserver/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" +) + +type ApiAddPlanningLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger + BaseLogic +} + +func NewApiAddPlanningLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ApiAddPlanningLogic { + return &ApiAddPlanningLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +// ApiAddPlanning 添加方案 //info = [{"product":{"code":"aaa", "mg":1.23}}] +func (l *ApiAddPlanningLogic) ApiAddPlanning(in *aiserver.ApiEditPlanningRequest) (*aiserver.Response, error) { + var v validator.PlanningEditValidator + if fail := l.checkParams(in, &v); fail != nil { + return fail, nil + } + adminInfo := utils.GetUserFromCtx(l.ctx) + if adminInfo.ID < utils.NumberOne { + return l.fail(utils.ErrorNoLoginInfo) + } + info := dao.PlanningCreate{ + UserId: adminInfo.ID, + Name: in.Name, + BeginTime: in.BeginTime, + EndTime: in.EndTime, + } + + err := model.PlanningModel{}.Init().Create(&info) + if err != nil { + return l.fail(utils.Fail) + } + + return l.ok(utils.NumberOne) +} diff --git a/services/aiserver/internal/logic/apiAddProductLogic.go b/services/aiserver/internal/logic/apiAddProductLogic.go new file mode 100644 index 0000000..affa383 --- /dev/null +++ b/services/aiserver/internal/logic/apiAddProductLogic.go @@ -0,0 +1,52 @@ +package logic + +import ( + "context" + "lone-services/pkg/utils" + "lone-services/services/aiserver/internal/dao" + "lone-services/services/aiserver/internal/model" + "lone-services/services/aiserver/validator" + + "lone-services/rpc/aiserver/pb" + "lone-services/services/aiserver/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" +) + +type ApiAddProductLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger + BaseLogic +} + +func NewApiAddProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ApiAddProductLogic { + return &ApiAddProductLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +// 添加产品 +func (l *ApiAddProductLogic) ApiAddProduct(in *aiserver.ApiAddProductRequest) (*aiserver.Response, error) { + var v validator.ProductAddValidator + if fail := l.checkParams(in, &v); fail != nil { + return fail, nil + } + adminInfo := utils.GetUserFromCtx(l.ctx) + if adminInfo.ID < utils.NumberOne { + return l.fail(utils.ErrorNoLoginInfo) + } + info := dao.ProductCreate{ + UserId: adminInfo.ID, + ProductCode: in.ProductCode, + ProductSerialNumber: in.ProductSerialNumber, + } + //TODO 产品信息 + err := model.ProductModel{}.Init().Create(&info) + if err != nil { + return l.fail(utils.Fail) + } + return l.ok(utils.NumberOne) +} diff --git a/services/aiserver/internal/logic/apiAddUseLogic.go b/services/aiserver/internal/logic/apiAddUseLogic.go new file mode 100644 index 0000000..b488d25 --- /dev/null +++ b/services/aiserver/internal/logic/apiAddUseLogic.go @@ -0,0 +1,68 @@ +package logic + +import ( + "context" + "lone-services/pkg/modelbase" + "lone-services/pkg/utils" + "lone-services/services/aiserver/internal/dao" + "lone-services/services/aiserver/internal/model" + "lone-services/services/aiserver/validator" + "strconv" + + "lone-services/rpc/aiserver/pb" + "lone-services/services/aiserver/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" +) + +type ApiAddUseLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger + BaseLogic +} + +func NewApiAddUseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ApiAddUseLogic { + return &ApiAddUseLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +// 添加使用记录 +func (l *ApiAddUseLogic) ApiAddUse(in *aiserver.ApiAddUseRequest) (*aiserver.Response, error) { + var v validator.UdeLogAddValidator + if fail := l.checkParams(in, &v); fail != nil { + return fail, nil + } + adminInfo := utils.GetUserFromCtx(l.ctx) + if adminInfo.ID < utils.NumberOne { + return l.fail(utils.ErrorNoLoginInfo) + } + + w := modelbase.Params{Eq: map[string]string{"product_serial_number": in.ProductSerialNumber, "user_id": strconv.FormatInt(adminInfo.ID, utils.NumberTen)}} + var product dao.ProductInfo + err := model.ProductModel{}.Init().GetOne(w, &product) + if err != nil { + return l.fail(utils.Fail) + } + if product.Id < utils.NumberOne { + return l.fail(utils.Fail) + } + + info := dao.UseLogCreate{ + UserId: adminInfo.ID, + UseMg: in.Mg, + ProductId: product.Id, + ProductName: product.ProductName, + PlanningId: in.Id, + } + + //TODO 产品信息 + err = model.UseLogModel{}.Init().Create(&info) + if err != nil { + return l.fail(utils.Fail) + } + return l.ok(utils.NumberOne) +} diff --git a/services/aiserver/internal/logic/apiEditPlanningLogic.go b/services/aiserver/internal/logic/apiEditPlanningLogic.go new file mode 100644 index 0000000..6937112 --- /dev/null +++ b/services/aiserver/internal/logic/apiEditPlanningLogic.go @@ -0,0 +1,68 @@ +package logic + +import ( + "context" + "lone-services/pkg/modelbase" + "lone-services/pkg/utils" + "lone-services/services/aiserver/internal/dao" + "lone-services/services/aiserver/internal/model" + "lone-services/services/aiserver/validator" + "strconv" + + "lone-services/rpc/aiserver/pb" + "lone-services/services/aiserver/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" +) + +type ApiEditPlanningLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger + BaseLogic +} + +func NewApiEditPlanningLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ApiEditPlanningLogic { + return &ApiEditPlanningLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +// ApiEditPlanning 编辑方案 +func (l *ApiEditPlanningLogic) ApiEditPlanning(in *aiserver.ApiEditPlanningRequest) (*aiserver.Response, error) { + var v validator.PlanningEditValidator + if fail := l.checkParams(in, &v); fail != nil { + return fail, nil + } + if in.Id < utils.NumberOne { + return l.fail(utils.SetError(utils.Fail, "ID不能为空")) + } + adminInfo := utils.GetUserFromCtx(l.ctx) + if adminInfo.ID < utils.NumberOne { + return l.fail(utils.ErrorNoLoginInfo) + } + w := modelbase.Params{Eq: map[string]string{ + "id": strconv.FormatInt(in.Id, utils.NumberTen), + "user_id": strconv.FormatInt(adminInfo.ID, utils.NumberTen)}} + var info dao.PlanningCreate + err := model.PlanningModel{}.Init().GetOne(w, &info) + if err != nil { + return l.fail(utils.Fail) + } + + if info.Id < utils.NumberOne { + return l.fail(utils.ErrorNotFund) + } + + info.BeginTime = in.BeginTime + info.EndTime = in.EndTime + info.Name = in.Name + _, err = model.PlanningModel{}.Init().Edit(w, &info) + if err != nil { + return l.fail(utils.Fail) + } + + return l.ok(utils.NumberOne) +} diff --git a/services/aiserver/internal/logic/apiEditPlanningProductLogic.go b/services/aiserver/internal/logic/apiEditPlanningProductLogic.go new file mode 100644 index 0000000..54e18af --- /dev/null +++ b/services/aiserver/internal/logic/apiEditPlanningProductLogic.go @@ -0,0 +1,31 @@ +package logic + +import ( + "context" + + "lone-services/rpc/aiserver/pb" + "lone-services/services/aiserver/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" +) + +type ApiEditPlanningProductLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger +} + +func NewApiEditPlanningProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ApiEditPlanningProductLogic { + return &ApiEditPlanningProductLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +// 编辑方案产品 +func (l *ApiEditPlanningProductLogic) ApiEditPlanningProduct(in *aiserver.ApiEditPlanningProductRequest) (*aiserver.Response, error) { + // todo: add your logic here and delete this line + + return &aiserver.Response{}, nil +} diff --git a/services/aiserver/internal/logic/apiGetSystemLogic.go b/services/aiserver/internal/logic/apiGetSystemLogic.go new file mode 100644 index 0000000..0d0152a --- /dev/null +++ b/services/aiserver/internal/logic/apiGetSystemLogic.go @@ -0,0 +1,31 @@ +package logic + +import ( + "context" + + "lone-services/rpc/aiserver/pb" + "lone-services/services/aiserver/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" +) + +type ApiGetSystemLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger + BaseLogic +} + +func NewApiGetSystemLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ApiGetSystemLogic { + return &ApiGetSystemLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *ApiGetSystemLogic) ApiGetSystem(in *aiserver.EmptyRequest) (*aiserver.Response, error) { + // todo: add your logic here and delete this line + + return &aiserver.Response{}, nil +} diff --git a/services/aiserver/internal/logic/apiPlanningDeleteLogic.go b/services/aiserver/internal/logic/apiPlanningDeleteLogic.go new file mode 100644 index 0000000..e9a77ae --- /dev/null +++ b/services/aiserver/internal/logic/apiPlanningDeleteLogic.go @@ -0,0 +1,31 @@ +package logic + +import ( + "context" + + "lone-services/rpc/aiserver/pb" + "lone-services/services/aiserver/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" +) + +type ApiPlanningDeleteLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger +} + +func NewApiPlanningDeleteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ApiPlanningDeleteLogic { + return &ApiPlanningDeleteLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +// 方案删除 +func (l *ApiPlanningDeleteLogic) ApiPlanningDelete(in *aiserver.ApiPlanningDeleteRequest) (*aiserver.Response, error) { + // todo: add your logic here and delete this line + + return &aiserver.Response{}, nil +} diff --git a/services/aiserver/internal/logic/apiPlanningItemsLogic.go b/services/aiserver/internal/logic/apiPlanningItemsLogic.go new file mode 100644 index 0000000..859dd0a --- /dev/null +++ b/services/aiserver/internal/logic/apiPlanningItemsLogic.go @@ -0,0 +1,31 @@ +package logic + +import ( + "context" + + "lone-services/rpc/aiserver/pb" + "lone-services/services/aiserver/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" +) + +type ApiPlanningItemsLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger +} + +func NewApiPlanningItemsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ApiPlanningItemsLogic { + return &ApiPlanningItemsLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +// 方案列表 +func (l *ApiPlanningItemsLogic) ApiPlanningItems(in *aiserver.EmptyRequest) (*aiserver.Response, error) { + // todo: add your logic here and delete this line + + return &aiserver.Response{}, nil +} diff --git a/services/aiserver/internal/logic/apiProductItemsLogic.go b/services/aiserver/internal/logic/apiProductItemsLogic.go new file mode 100644 index 0000000..95e5472 --- /dev/null +++ b/services/aiserver/internal/logic/apiProductItemsLogic.go @@ -0,0 +1,32 @@ +package logic + +import ( + "context" + + "lone-services/rpc/aiserver/pb" + "lone-services/services/aiserver/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" +) + +type ApiProductItemsLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger + BaseLogic +} + +func NewApiProductItemsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ApiProductItemsLogic { + return &ApiProductItemsLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +// 获取产品信息 +func (l *ApiProductItemsLogic) ApiProductItems(in *aiserver.ApiProductItemsRequest) (*aiserver.Response, error) { + // todo: add your logic here and delete this line + + return &aiserver.Response{}, nil +} diff --git a/services/aiserver/internal/logic/apiSystemSetLogic.go b/services/aiserver/internal/logic/apiSystemSetLogic.go new file mode 100644 index 0000000..194db2c --- /dev/null +++ b/services/aiserver/internal/logic/apiSystemSetLogic.go @@ -0,0 +1,31 @@ +package logic + +import ( + "context" + + "lone-services/rpc/aiserver/pb" + "lone-services/services/aiserver/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" +) + +type ApiSystemSetLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger + BaseLogic +} + +func NewApiSystemSetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ApiSystemSetLogic { + return &ApiSystemSetLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *ApiSystemSetLogic) ApiSystemSet(in *aiserver.ApiSystemSetRequest) (*aiserver.Response, error) { + // todo: add your logic here and delete this line + + return &aiserver.Response{}, nil +} diff --git a/services/aiserver/internal/logic/apiSystemTimeLogic.go b/services/aiserver/internal/logic/apiSystemTimeLogic.go new file mode 100644 index 0000000..b1f076a --- /dev/null +++ b/services/aiserver/internal/logic/apiSystemTimeLogic.go @@ -0,0 +1,31 @@ +package logic + +import ( + "context" + + "lone-services/rpc/aiserver/pb" + "lone-services/services/aiserver/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" +) + +type ApiSystemTimeLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger + BaseLogic +} + +func NewApiSystemTimeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ApiSystemTimeLogic { + return &ApiSystemTimeLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *ApiSystemTimeLogic) ApiSystemTime(in *aiserver.EmptyRequest) (*aiserver.Response, error) { + // todo: add your logic here and delete this line + + return &aiserver.Response{}, nil +} diff --git a/services/aiserver/internal/logic/apiUsedItemsLogic.go b/services/aiserver/internal/logic/apiUsedItemsLogic.go new file mode 100644 index 0000000..276f4c4 --- /dev/null +++ b/services/aiserver/internal/logic/apiUsedItemsLogic.go @@ -0,0 +1,31 @@ +package logic + +import ( + "context" + + "lone-services/rpc/aiserver/pb" + "lone-services/services/aiserver/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" +) + +type ApiUsedItemsLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger + BaseLogic +} + +func NewApiUsedItemsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ApiUsedItemsLogic { + return &ApiUsedItemsLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *ApiUsedItemsLogic) ApiUsedItems(in *aiserver.ApiUsedItemsRequest) (*aiserver.Response, error) { + // todo: add your logic here and delete this line + + return &aiserver.Response{}, nil +} diff --git a/services/aiserver/internal/logic/apiWeatherLogic.go b/services/aiserver/internal/logic/apiWeatherLogic.go new file mode 100644 index 0000000..1c16428 --- /dev/null +++ b/services/aiserver/internal/logic/apiWeatherLogic.go @@ -0,0 +1,31 @@ +package logic + +import ( + "context" + + "lone-services/rpc/aiserver/pb" + "lone-services/services/aiserver/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" +) + +type ApiWeatherLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger + BaseLogic +} + +func NewApiWeatherLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ApiWeatherLogic { + return &ApiWeatherLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *ApiWeatherLogic) ApiWeather(in *aiserver.EmptyRequest) (*aiserver.Response, error) { + // todo: add your logic here and delete this line + + return &aiserver.Response{}, nil +} diff --git a/services/aiserver/internal/logic/base.go b/services/aiserver/internal/logic/base.go new file mode 100644 index 0000000..5404a53 --- /dev/null +++ b/services/aiserver/internal/logic/base.go @@ -0,0 +1,44 @@ +package logic + +import ( + "lone-services/pkg/utils" + "lone-services/pkg/validate" + aiserver "lone-services/rpc/aiserver/pb" + "reflect" + + jsoniter "github.com/json-iterator/go" +) + +type BaseLogic struct { +} + +func (l *BaseLogic) checkParams(in interface{}, v validate.IValidator) *aiserver.Response { + rv := reflect.ValueOf(in) + if rv.Kind() != reflect.Ptr || rv.IsNil() { + return &aiserver.Response{ + Code: utils.ErrorParams.Code, + Msg: "request must be non‑nil proto pointer", + } + } + + resp := validate.ValidateFromProto(in, v) + if resp != utils.StringEmpty { + return &aiserver.Response{ + Code: utils.ErrorParams.Code, + Msg: resp, + } + } + return nil +} + +func (l *BaseLogic) fail(status utils.Status) (*aiserver.Response, error) { + return l.out(status, status.Msg) +} +func (l *BaseLogic) out(status utils.Status, msg string) (*aiserver.Response, error) { + return &aiserver.Response{Code: status.Code, Msg: msg}, nil +} + +func (l *BaseLogic) ok(data any) (*aiserver.Response, error) { + buf, _ := jsoniter.Marshal(data) + return &aiserver.Response{Code: utils.Ok.Code, Msg: utils.Ok.Msg, Data: string(buf)}, nil +} diff --git a/services/aiserver/internal/model/planning.go b/services/aiserver/internal/model/planning.go new file mode 100644 index 0000000..7027c70 --- /dev/null +++ b/services/aiserver/internal/model/planning.go @@ -0,0 +1,23 @@ +package model + +import ( + "lone-services/pkg/modelbase" + "lone-services/services/aiserver/internal/dao" +) + +type PlanningModel struct { + modelbase.Base +} + +func (m PlanningModel) TableName() string { + return modelbase.Prefix() + "planning" +} + +func (m PlanningModel) Init() PlanningModel { + m.Table = m.TableName() + return m +} + +func (m PlanningModel) Create(data *dao.PlanningCreate) error { + return m.Base.Create(data) +} diff --git a/services/aiserver/internal/model/planningProduct.go b/services/aiserver/internal/model/planningProduct.go new file mode 100644 index 0000000..730e7ab --- /dev/null +++ b/services/aiserver/internal/model/planningProduct.go @@ -0,0 +1,23 @@ +package model + +import ( + "lone-services/pkg/modelbase" + "lone-services/services/aiserver/internal/dao" +) + +type PlanningProductModel struct { + modelbase.Base +} + +func (m PlanningProductModel) TableName() string { + return modelbase.Prefix() + "planning_product" +} + +func (m PlanningProductModel) Init() PlanningProductModel { + m.Table = m.TableName() + return m +} + +func (m PlanningProductModel) Create(data *dao.PlanningProductCreate) error { + return m.Base.Create(data) +} diff --git a/services/aiserver/internal/model/product.go b/services/aiserver/internal/model/product.go new file mode 100644 index 0000000..dc7efc8 --- /dev/null +++ b/services/aiserver/internal/model/product.go @@ -0,0 +1,23 @@ +package model + +import ( + "lone-services/pkg/modelbase" + "lone-services/services/aiserver/internal/dao" +) + +type ProductModel struct { + modelbase.Base +} + +func (m ProductModel) TableName() string { + return modelbase.Prefix() + "product" +} + +func (m ProductModel) Init() ProductModel { + m.Table = m.TableName() + return m +} + +func (m ProductModel) Create(data *dao.ProductCreate) error { + return m.Base.Create(data) +} diff --git a/services/aiserver/internal/model/setting.go b/services/aiserver/internal/model/setting.go new file mode 100644 index 0000000..7e78480 --- /dev/null +++ b/services/aiserver/internal/model/setting.go @@ -0,0 +1,23 @@ +package model + +import ( + "lone-services/pkg/modelbase" + "lone-services/services/aiserver/internal/dao" +) + +type SettingModel struct { + modelbase.Base +} + +func (m SettingModel) TableName() string { + return modelbase.Prefix() + "setting" +} + +func (m SettingModel) Init() SettingModel { + m.Table = m.TableName() + return m +} + +func (m SettingModel) Create(data *dao.SettingCreate) error { + return m.Base.Create(data) +} diff --git a/services/aiserver/internal/model/useLog.go b/services/aiserver/internal/model/useLog.go new file mode 100644 index 0000000..843f094 --- /dev/null +++ b/services/aiserver/internal/model/useLog.go @@ -0,0 +1,23 @@ +package model + +import ( + "lone-services/pkg/modelbase" + "lone-services/services/aiserver/internal/dao" +) + +type UseLogModel struct { + modelbase.Base +} + +func (m UseLogModel) TableName() string { + return modelbase.Prefix() + "use_log" +} + +func (m UseLogModel) Init() UseLogModel { + m.Table = m.TableName() + return m +} + +func (m UseLogModel) Create(data *dao.UseLogCreate) error { + return m.Base.Create(data) +} diff --git a/services/aiserver/internal/server/aiserverServer.go b/services/aiserver/internal/server/aiserverServer.go new file mode 100644 index 0000000..2bd6d91 --- /dev/null +++ b/services/aiserver/internal/server/aiserverServer.go @@ -0,0 +1,102 @@ +// Code generated by goctl. DO NOT EDIT. +// goctl 1.10.2 +// Source: aiserver.proto + +package server + +import ( + "context" + + "lone-services/rpc/aiserver/pb" + "lone-services/services/aiserver/internal/logic" + "lone-services/services/aiserver/internal/svc" +) + +type AiserverServer struct { + svcCtx *svc.ServiceContext + aiserver.UnimplementedAiserverServer +} + +func NewAiserverServer(svcCtx *svc.ServiceContext) *AiserverServer { + return &AiserverServer{ + svcCtx: svcCtx, + } +} + +// 添加产品 +func (s *AiserverServer) ApiAddProduct(ctx context.Context, in *aiserver.ApiAddProductRequest) (*aiserver.Response, error) { + l := logic.NewApiAddProductLogic(ctx, s.svcCtx) + return l.ApiAddProduct(in) +} + +// 添加使用记录 +func (s *AiserverServer) ApiAddUse(ctx context.Context, in *aiserver.ApiAddUseRequest) (*aiserver.Response, error) { + l := logic.NewApiAddUseLogic(ctx, s.svcCtx) + return l.ApiAddUse(in) +} + +// 获取产品信息 +func (s *AiserverServer) ApiProductItems(ctx context.Context, in *aiserver.ApiProductItemsRequest) (*aiserver.Response, error) { + l := logic.NewApiProductItemsLogic(ctx, s.svcCtx) + return l.ApiProductItems(in) +} + +// 添加方案 +func (s *AiserverServer) ApiAddPlanning(ctx context.Context, in *aiserver.ApiEditPlanningRequest) (*aiserver.Response, error) { + l := logic.NewApiAddPlanningLogic(ctx, s.svcCtx) + return l.ApiAddPlanning(in) +} + +// 编辑方案产品 +func (s *AiserverServer) ApiEditPlanningProduct(ctx context.Context, in *aiserver.ApiEditPlanningProductRequest) (*aiserver.Response, error) { + l := logic.NewApiEditPlanningProductLogic(ctx, s.svcCtx) + return l.ApiEditPlanningProduct(in) +} + +// 编辑方案 +func (s *AiserverServer) ApiEditPlanning(ctx context.Context, in *aiserver.ApiEditPlanningRequest) (*aiserver.Response, error) { + l := logic.NewApiEditPlanningLogic(ctx, s.svcCtx) + return l.ApiEditPlanning(in) +} + +// 方案列表 +func (s *AiserverServer) ApiPlanningItems(ctx context.Context, in *aiserver.EmptyRequest) (*aiserver.Response, error) { + l := logic.NewApiPlanningItemsLogic(ctx, s.svcCtx) + return l.ApiPlanningItems(in) +} + +// 方案删除 +func (s *AiserverServer) ApiPlanningDelete(ctx context.Context, in *aiserver.ApiPlanningDeleteRequest) (*aiserver.Response, error) { + l := logic.NewApiPlanningDeleteLogic(ctx, s.svcCtx) + return l.ApiPlanningDelete(in) +} + +// 获取天气 +func (s *AiserverServer) ApiWeather(ctx context.Context, in *aiserver.EmptyRequest) (*aiserver.Response, error) { + l := logic.NewApiWeatherLogic(ctx, s.svcCtx) + return l.ApiWeather(in) +} + +// 获取使用记录 +func (s *AiserverServer) ApiUsedItems(ctx context.Context, in *aiserver.ApiUsedItemsRequest) (*aiserver.Response, error) { + l := logic.NewApiUsedItemsLogic(ctx, s.svcCtx) + return l.ApiUsedItems(in) +} + +// 获取系统时间 +func (s *AiserverServer) ApiSystemTime(ctx context.Context, in *aiserver.EmptyRequest) (*aiserver.Response, error) { + l := logic.NewApiSystemTimeLogic(ctx, s.svcCtx) + return l.ApiSystemTime(in) +} + +// 设置系统参数 +func (s *AiserverServer) ApiSystemSet(ctx context.Context, in *aiserver.ApiSystemSetRequest) (*aiserver.Response, error) { + l := logic.NewApiSystemSetLogic(ctx, s.svcCtx) + return l.ApiSystemSet(in) +} + +// 获取系统设置 +func (s *AiserverServer) ApiGetSystem(ctx context.Context, in *aiserver.EmptyRequest) (*aiserver.Response, error) { + l := logic.NewApiGetSystemLogic(ctx, s.svcCtx) + return l.ApiGetSystem(in) +} diff --git a/services/aiserver/internal/svc/product.go b/services/aiserver/internal/svc/product.go new file mode 100644 index 0000000..f9c3807 --- /dev/null +++ b/services/aiserver/internal/svc/product.go @@ -0,0 +1,42 @@ +package svc + +import ( + "context" + product "lone-services/rpc/product/pb" + + "github.com/zeromicro/go-zero/core/logx" +) + +func GetProducts(ids []int64, name string) []*product.Item { + cli, err := GetRpcClient(name) + if err != nil { + logx.Error(err) + return nil + } + + client := product.NewProductClient(cli.Conn()) + items, err := client.ItemsByIds(context.Background(), &product.ItemsByIdsReq{Ids: ids}) + if err != nil { + logx.Errorf("get store err: %v", err) + return nil + } + + return items.Items +} + +func GetProduct(id int64, name string) *product.Item { + cli, err := GetRpcClient(name) + if err != nil { + logx.Error(err) + return nil + } + + client := product.NewProductClient(cli.Conn()) + info, err := client.InfoById(context.Background(), &product.InfoByIdReq{Id: id}) + if err != nil { + logx.Errorf("get store err: %v", err) + return nil + } + + return info +} diff --git a/services/aiserver/internal/svc/servicecontext.go b/services/aiserver/internal/svc/servicecontext.go new file mode 100644 index 0000000..a83a111 --- /dev/null +++ b/services/aiserver/internal/svc/servicecontext.go @@ -0,0 +1,94 @@ +package svc + +import ( + "fmt" + "lone-services/pkg/discovery" + "lone-services/pkg/utils" + "lone-services/services/aiserver/internal/config" + "net" + "strconv" + "sync" + "time" + + "github.com/zeromicro/go-zero/core/logx" + "github.com/zeromicro/go-zero/zrpc" + "gorm.io/gorm" +) + +type rpcClientCacheEntry struct { + cli zrpc.Client + target string + expireAt time.Time +} + +const rpcClientCacheTTL = 30 * time.Second //缓存过期时间 + +var ( + rpcCacheLock sync.Mutex + rpcCache = make(map[string]*rpcClientCacheEntry) +) + +func GetRpcClient(serviceName string) (zrpc.Client, error) { + if serviceName == utils.StringEmpty { + err := fmt.Errorf("rpc serviceName is empty") + logx.Error(err) + return nil, err + } + + cacheKey := serviceName + + rpcCacheLock.Lock() + entry, ok := rpcCache[cacheKey] + if ok && time.Now().Before(entry.expireAt) { + rpcCacheLock.Unlock() + return entry.cli, nil + } + delete(rpcCache, cacheKey) + rpcCacheLock.Unlock() + + inst, err := discovery.Pick(serviceName) + if err != nil { + err = fmt.Errorf("discovery pick %s failed: %w", serviceName, err) + logx.Error(err) + return nil, err + } + + target := net.JoinHostPort(inst.IP, strconv.FormatUint(inst.Port, utils.NumberTen)) + + cli := zrpc.MustNewClient(zrpc.RpcClientConf{ + Target: target, + Timeout: utils.RpcTimeOut, //rpc调用超时5s + }) + + rpcCacheLock.Lock() + rpcCache[cacheKey] = &rpcClientCacheEntry{ + cli: cli, + target: target, + expireAt: time.Now().Add(rpcClientCacheTTL), + } + rpcCacheLock.Unlock() + + return cli, nil +} + +type ServiceContext struct { + Config config.Config + DB *gorm.DB + Prefix string + productName string +} + +func NewServiceContext(c config.Config, db *gorm.DB) *ServiceContext { + //启动仅读取配置,不建立rpc连接 多个服务就多个 + productSvc := utils.GetConfigString("services.product") + if productSvc == utils.StringEmpty { + logx.Error("config services.product empty") + } + + return &ServiceContext{ + Config: c, + DB: db, + Prefix: utils.GetConfigString("mysql.prefix"), + productName: productSvc, + } +} diff --git a/services/aiserver/validator/planning.go b/services/aiserver/validator/planning.go new file mode 100644 index 0000000..fb20705 --- /dev/null +++ b/services/aiserver/validator/planning.go @@ -0,0 +1,34 @@ +package validator + +import "lone-services/pkg/validate" + +// PlanningEditValidator 创建/编辑 +type PlanningEditValidator struct { + Name string `validate:"required"` + Id int64 + BeginTime string + EndTime string +} + +// GetMessage 创建 - 提示消息 +func (p PlanningEditValidator) GetMessage() validate.ValidatorMessages { + return validate.ValidatorMessages{ + "Name.required": "名称不能为空", + "Info.required": "信息不能为空", + } +} + +type PlanningProductEditValidator struct { + ProductCode string `validate:"required"` + UseMg int32 `validate:"required"` + PlanningId int64 `validate:"required"` +} + +// GetMessage 创建 - 提示消息 +func (p PlanningProductEditValidator) GetMessage() validate.ValidatorMessages { + return validate.ValidatorMessages{ + "ProductCode.required": "产品编码不能为空", + "UseMg.required": "使用量不能为空", + "PlanningId.required": "计划ID不能为空", + } +} diff --git a/services/aiserver/validator/product.go b/services/aiserver/validator/product.go new file mode 100644 index 0000000..2992d25 --- /dev/null +++ b/services/aiserver/validator/product.go @@ -0,0 +1,17 @@ +package validator + +import "lone-services/pkg/validate" + +// ProductAddValidator 创建/编辑 +type ProductAddValidator struct { + ProductCode string `json:"product_code" validate:"required"` + ProductSerialNumber string `json:"product_serial_number" validate:"required"` +} + +// GetMessage 创建 - 提示消息 +func (p ProductAddValidator) GetMessage() validate.ValidatorMessages { + return validate.ValidatorMessages{ + "ProductCode.required": "产品编码不能为空", + "ProductSerialNumber.required": "产品序列号不能为空", + } +} diff --git a/services/aiserver/validator/setting.go b/services/aiserver/validator/setting.go new file mode 100644 index 0000000..ecc77c1 --- /dev/null +++ b/services/aiserver/validator/setting.go @@ -0,0 +1,21 @@ +package validator + +import "lone-services/pkg/validate" + +// SettingEditValidator 创建/编辑 +type SettingEditValidator struct { + Lang int32 + Language int32 + Wifi int32 + Screen int32 + Sound int32 + LightOpen int32 + LightWorkTime string + LightBrightness int32 + ScreenSleepTime int32 +} + +// GetMessage 创建 - 提示消息 +func (p SettingEditValidator) GetMessage() validate.ValidatorMessages { + return validate.ValidatorMessages{} +} diff --git a/services/aiserver/validator/useLog.go b/services/aiserver/validator/useLog.go new file mode 100644 index 0000000..c148a71 --- /dev/null +++ b/services/aiserver/validator/useLog.go @@ -0,0 +1,18 @@ +package validator + +import "lone-services/pkg/validate" + +// UdeLogAddValidator 创建/编辑 +type UdeLogAddValidator struct { + ProductSerialNumber string `validate:"required"` + Mg int32 `validate:"required"` + Id int64 +} + +// GetMessage 创建 - 提示消息 +func (p UdeLogAddValidator) GetMessage() validate.ValidatorMessages { + return validate.ValidatorMessages{ + "ProductSerialNumber.required": "产品编码不能为空", + "Mg.required": "使用量不能为空", + } +} diff --git a/services/water/dao/log.go b/services/water/dao/log.go deleted file mode 100644 index 9784600..0000000 --- a/services/water/dao/log.go +++ /dev/null @@ -1,18 +0,0 @@ -package dao - -import "lone-services/pkg/utils" - -type LogCreate struct { - Id int64 `json:"id" gorm:"id"` - UserId int64 `json:"user_id" gorm:"user_id"` // 用户ID - HostCode string `json:"host_code" gorm:"host_code"` // 设备号 - Data string `json:"data" gorm:"data"` // 数据 -} - -type LogInfo struct { - Id int64 `json:"id" gorm:"id"` - UserId int64 `json:"user_id" gorm:"user_id"` // 用户ID - HostCode string `json:"host_code" gorm:"host_code"` // 设备号 - Data string `json:"data" gorm:"data"` // 数据 - CarteTime utils.CustomTime `json:"carte_time" gorm:"carte_time"` -} diff --git a/services/water/dao/setting.go b/services/water/dao/setting.go deleted file mode 100644 index 6531866..0000000 --- a/services/water/dao/setting.go +++ /dev/null @@ -1,39 +0,0 @@ -package dao - -import "lone-services/pkg/utils" - -const ( - UserTypeStore = 1 - UserTypeUser = 2 - - WifiDone = 1 - WifiNotDone = 2 -) - -type SettingCreate struct { - Id int64 `json:"id" gorm:"id"` - UserId int64 `json:"user_id" gorm:"user_id"` // 用户ID - UserType int32 `json:"user_type" gorm:"user_type"` // 用户类型,1为用户,2为门店 - HostCode string `json:"host_code" gorm:"host_code"` // 设备 - WifiDone int32 `json:"wifi_done" gorm:"wifi_done"` // 是否配置了wifi,2为没有配置,1为配置了 - Hardness int32 `json:"hardness" gorm:"hardness"` // 水的硬度 - RefreshTime string `json:"refresh_time" gorm:"refresh_time"` // 重生时间 - SaltPercent int32 `json:"salt_percent" gorm:"salt_percent"` // 盐量最大100 - UseNumber int32 `json:"use_number" gorm:"use_number"` // 剩余使用次数 - Soften int32 `json:"soften" gorm:"soften"` // 软化最大100 -} - -type WifiInfo struct { - Id int64 `json:"id" gorm:"id"` - UserId int64 `json:"user_id" gorm:"user_id"` // 用户ID - UserType int32 `json:"user_type" gorm:"user_type"` // 用户类型,1为用户,2为门店 - HostCode string `json:"host_code" gorm:"host_code"` // 设备 - WifiDone int32 `json:"wifi_done" gorm:"wifi_done"` // 是否配置了wifi,2为没有配置,1为配置了 - Hardness int32 `json:"hardness" gorm:"hardness"` // 水的硬度 - RefreshTime string `json:"refresh_time" gorm:"refresh_time"` // 重生时间 - SaltPercent int32 `json:"salt_percent" gorm:"salt_percent"` // 盐量最大100 - UseNumber int32 `json:"use_number" gorm:"use_number"` // 剩余使用次数 - Soften int32 `json:"soften" gorm:"soften"` // 软化最大100 - UpdateTime utils.CustomTime `json:"update_time" gorm:"update_time"` - CarteTime utils.CustomTime `json:"carte_time" gorm:"carte_time"` -} diff --git a/services/water/internal/dao/log.go b/services/water/internal/dao/log.go new file mode 100644 index 0000000..4a93870 --- /dev/null +++ b/services/water/internal/dao/log.go @@ -0,0 +1,20 @@ +package dao + +import "lone-services/pkg/utils" + +type LogCreate struct { + Id int64 `json:"id" gorm:"id"` + UserId int64 `json:"user_id" gorm:"user_id"` // 用户ID + HostCode string `json:"host_code" gorm:"host_code"` // 设备号 + Salt int64 `gorm:"column:salt;type:int;default:NULL" json:"salt"` // 剩余盐量 + Water int64 `gorm:"column:water;type:int;default:NULL" json:"water"` // 水量 +} + +type LogInfo struct { + Id int64 `json:"id" gorm:"id"` + UserId int64 `json:"user_id" gorm:"user_id"` // 用户ID + HostCode string `json:"host_code" gorm:"host_code"` // 设备号 + Salt int64 `gorm:"column:salt;type:int;default:NULL" json:"salt"` // 剩余盐量 + Water int64 `gorm:"column:water;type:int;default:NULL" json:"water"` // 水量 + CarteTime utils.CustomTime `json:"carte_time" gorm:"carte_time"` +} diff --git a/services/water/internal/dao/logDate.go b/services/water/internal/dao/logDate.go new file mode 100644 index 0000000..e17faa8 --- /dev/null +++ b/services/water/internal/dao/logDate.go @@ -0,0 +1,10 @@ +package dao + +type LogDate struct { + Id int64 `json:"id" gorm:"id"` + UserId int64 `json:"user_id" gorm:"user_id"` // 用户ID + HostCode string `json:"host_code" gorm:"host_code"` // 设备号 + Salt int64 `gorm:"column:salt;type:int;default:NULL" json:"salt"` // 剩余盐量 + Water int64 `gorm:"column:water;type:int;default:NULL" json:"water"` // 水量 + Date string `gorm:"column:date;type:char(12);default:NULL" json:"date"` +} diff --git a/services/water/internal/dao/logMonth.go b/services/water/internal/dao/logMonth.go new file mode 100644 index 0000000..9253401 --- /dev/null +++ b/services/water/internal/dao/logMonth.go @@ -0,0 +1,10 @@ +package dao + +type LogMonth struct { + Id int64 `json:"id" gorm:"id"` + UserId int64 `json:"user_id" gorm:"user_id"` // 用户ID + HostCode string `json:"host_code" gorm:"host_code"` // 设备号 + Salt int64 `gorm:"column:salt;type:int;default:NULL" json:"salt"` // 剩余盐量 + Water int64 `gorm:"column:water;type:int;default:NULL" json:"water"` // 水量 + Month string `gorm:"column:month;type:char(10);default:NULL" json:"month"` +} diff --git a/services/water/internal/dao/setting.go b/services/water/internal/dao/setting.go new file mode 100644 index 0000000..ac33d53 --- /dev/null +++ b/services/water/internal/dao/setting.go @@ -0,0 +1,41 @@ +package dao + +import "lone-services/pkg/utils" + +const ( + UserTypeStore = 1 + UserTypeUser = 2 + + WifiDone = 1 + WifiNotDone = 2 +) + +type SettingCreate struct { + Id int64 `json:"id" gorm:"id"` + UserId int64 `json:"user_id" gorm:"user_id"` // 用户ID + UserType int32 `json:"user_type" gorm:"user_type"` // 用户类型,1为用户,2为门店 + HostCode string `json:"host_code" gorm:"host_code"` // 设备 + WifiDone int32 `json:"wifi_done" gorm:"wifi_done"` // 是否配置了wifi,2为没有配置,1为配置了 + Hardness int32 `json:"hardness" gorm:"hardness"` // 水的硬度 + RefreshTime string `json:"refresh_time" gorm:"refresh_time"` // 重生时间 + SaltPercent int32 `json:"salt_percent" gorm:"salt_percent"` // 盐量最大100 + UseNumber int32 `json:"use_number" gorm:"use_number"` // 剩余使用次数 + NoDisturbing string `gorm:"column:no_disturbing;type:varchar(50);not null;default:''" json:"no_disturbing"` // 免打扰 + Soften int32 `json:"soften" gorm:"soften"` // 软化最大100 +} + +type WifiInfo struct { + Id int64 `json:"id" gorm:"id"` + UserId int64 `json:"user_id" gorm:"user_id"` // 用户ID + UserType int32 `json:"user_type" gorm:"user_type"` // 用户类型,1为用户,2为门店 + HostCode string `json:"host_code" gorm:"host_code"` // 设备 + WifiDone int32 `json:"wifi_done" gorm:"wifi_done"` // 是否配置了wifi,2为没有配置,1为配置了 + Hardness int32 `json:"hardness" gorm:"hardness"` // 水的硬度 + RefreshTime string `json:"refresh_time" gorm:"refresh_time"` // 重生时间 + SaltPercent int32 `json:"salt_percent" gorm:"salt_percent"` // 盐量最大100 + NoDisturbing string `gorm:"column:no_disturbing;type:varchar(50);not null;default:''" json:"no_disturbing"` // 免打扰 + UseNumber int32 `json:"use_number" gorm:"use_number"` // 剩余使用次数 + Soften int32 `json:"soften" gorm:"soften"` // 软化最大100 + UpdateTime utils.CustomTime `json:"update_time" gorm:"update_time"` + CarteTime utils.CustomTime `json:"carte_time" gorm:"carte_time"` +} diff --git a/services/water/internal/logic/addLogLogic.go b/services/water/internal/logic/addLogLogic.go index c1e9869..18b0126 100644 --- a/services/water/internal/logic/addLogLogic.go +++ b/services/water/internal/logic/addLogLogic.go @@ -2,10 +2,12 @@ package logic import ( "context" + "lone-services/pkg/modelbase" "lone-services/pkg/utils" - "lone-services/services/water/dao" + "lone-services/services/water/internal/dao" "lone-services/services/water/model" "lone-services/services/water/validator" + "time" "lone-services/rpc/water/pb" "lone-services/services/water/internal/svc" @@ -38,13 +40,66 @@ func (l *AddLogLogic) AddLog(in *water.AddLogRequest) (*water.Response, error) { return l.fail(utils.ErrorNoLoginInfo) } info := dao.LogCreate{ - Data: in.Data, HostCode: in.HostCode, + Water: in.Water, + Salt: in.Salt, UserId: adminInfo.ID, } err := model.LogModel{}.Init().Create(&info) if err != nil { return l.fail(utils.Fail) } + + date := utils.Now().Format(time.DateOnly) + w := modelbase.Params{Eq: map[string]string{"date": date}} + var logDate dao.LogDate + err = model.LogDateModel{}.Init().GetOne(w, &logDate) + if err != nil { + return l.fail(utils.Fail) + } + if logDate.Id < utils.NumberOne { + logDate.Date = date + logDate.Water = in.Water + logDate.Salt = in.Salt + logDate.UserId = adminInfo.ID + logDate.HostCode = in.HostCode + err = model.LogDateModel{}.Init().Create(&logDate) + if err != nil { + return l.fail(utils.Fail) + } + } else { + logDate.Water += in.Water + logDate.Salt += in.Salt + _, err = model.LogDateModel{}.Init().Edit(w, &logDate) + if err != nil { + return l.fail(utils.Fail) + } + } + + month := utils.Now().Format("2006-01") + w = modelbase.Params{Eq: map[string]string{"month": month}} + var logMonth dao.LogMonth + err = model.LogMonthModel{}.Init().GetOne(w, &logMonth) + if err != nil { + return l.fail(utils.Fail) + } + if logMonth.Id < utils.NumberOne { + logMonth.Month = month + logMonth.Water = in.Water + logMonth.Salt = in.Salt + logMonth.UserId = adminInfo.ID + logMonth.HostCode = in.HostCode + err = model.LogMonthModel{}.Init().Create(&logMonth) + if err != nil { + return l.fail(utils.Fail) + } + } else { + logMonth.Water += in.Water + logMonth.Salt += in.Salt + _, err = model.LogMonthModel{}.Init().Edit(w, &logMonth) + if err != nil { + return l.fail(utils.Fail) + } + } return l.ok(utils.NumberOne) } diff --git a/services/water/internal/logic/getSettingLogic.go b/services/water/internal/logic/getSettingLogic.go index fd0078c..d02bc04 100644 --- a/services/water/internal/logic/getSettingLogic.go +++ b/services/water/internal/logic/getSettingLogic.go @@ -4,7 +4,7 @@ import ( "context" "lone-services/pkg/modelbase" "lone-services/pkg/utils" - "lone-services/services/water/dao" + "lone-services/services/water/internal/dao" "lone-services/services/water/model" "lone-services/services/water/validator" diff --git a/services/water/internal/logic/logItemsLogic.go b/services/water/internal/logic/logItemsLogic.go index 0cdbfd4..df35b92 100644 --- a/services/water/internal/logic/logItemsLogic.go +++ b/services/water/internal/logic/logItemsLogic.go @@ -5,7 +5,7 @@ import ( "lone-services/pkg/modelbase" "lone-services/pkg/utils" "lone-services/rpc/water/pb" - "lone-services/services/water/dao" + "lone-services/services/water/internal/dao" "lone-services/services/water/internal/svc" "lone-services/services/water/model" "lone-services/services/water/validator" diff --git a/services/water/internal/logic/settingLogic.go b/services/water/internal/logic/settingLogic.go index d3a5527..8fc0124 100644 --- a/services/water/internal/logic/settingLogic.go +++ b/services/water/internal/logic/settingLogic.go @@ -4,7 +4,7 @@ import ( "context" "lone-services/pkg/modelbase" "lone-services/pkg/utils" - "lone-services/services/water/dao" + "lone-services/services/water/internal/dao" "lone-services/services/water/model" "lone-services/services/water/validator" @@ -64,10 +64,15 @@ func (l *SettingLogic) Setting(in *water.SettingRequest) (*water.Response, error change = true info.SaltPercent = in.SaltPercent } - if in.RefreshTime != "" && info.RefreshTime != in.RefreshTime { + if in.RefreshTime != utils.StringEmpty && info.RefreshTime != in.RefreshTime { change = true info.RefreshTime = in.RefreshTime } + + if in.NoDisturbing != utils.StringEmpty && info.NoDisturbing != in.NoDisturbing { + change = true + info.NoDisturbing = in.NoDisturbing + } if change { _, err = model.SettingModel{}.Init().Edit(w, &info) if err != nil { diff --git a/services/water/internal/logic/wifiCheckLogic.go b/services/water/internal/logic/wifiCheckLogic.go index 2071dfb..87e9d7d 100644 --- a/services/water/internal/logic/wifiCheckLogic.go +++ b/services/water/internal/logic/wifiCheckLogic.go @@ -4,7 +4,7 @@ import ( "context" "lone-services/pkg/modelbase" "lone-services/pkg/utils" - "lone-services/services/water/dao" + "lone-services/services/water/internal/dao" "lone-services/services/water/model" "lone-services/services/water/validator" diff --git a/services/water/internal/logic/wifiSetLogic.go b/services/water/internal/logic/wifiSetLogic.go index 7aaf4d9..1b7b894 100644 --- a/services/water/internal/logic/wifiSetLogic.go +++ b/services/water/internal/logic/wifiSetLogic.go @@ -4,7 +4,7 @@ import ( "context" "lone-services/pkg/modelbase" "lone-services/pkg/utils" - "lone-services/services/water/dao" + "lone-services/services/water/internal/dao" "lone-services/services/water/model" "lone-services/services/water/validator" diff --git a/services/water/model/log.go b/services/water/model/log.go index a4e71ea..2862c13 100644 --- a/services/water/model/log.go +++ b/services/water/model/log.go @@ -2,7 +2,7 @@ package model import ( "lone-services/pkg/modelbase" - "lone-services/services/water/dao" + "lone-services/services/water/internal/dao" ) type LogModel struct { diff --git a/services/water/model/logDate.go b/services/water/model/logDate.go new file mode 100644 index 0000000..3a39c88 --- /dev/null +++ b/services/water/model/logDate.go @@ -0,0 +1,23 @@ +package model + +import ( + "lone-services/pkg/modelbase" + "lone-services/services/water/internal/dao" +) + +type LogDateModel struct { + modelbase.Base +} + +func (m LogDateModel) TableName() string { + return modelbase.Prefix() + "log_date" +} + +func (m LogDateModel) Init() LogDateModel { + m.Table = m.TableName() + return m +} + +func (m LogDateModel) Create(data *dao.LogDate) error { + return m.Base.Create(data) +} diff --git a/services/water/model/logMonth.go b/services/water/model/logMonth.go new file mode 100644 index 0000000..e938260 --- /dev/null +++ b/services/water/model/logMonth.go @@ -0,0 +1,23 @@ +package model + +import ( + "lone-services/pkg/modelbase" + "lone-services/services/water/internal/dao" +) + +type LogMonthModel struct { + modelbase.Base +} + +func (m LogMonthModel) TableName() string { + return modelbase.Prefix() + "log_month" +} + +func (m LogMonthModel) Init() LogMonthModel { + m.Table = m.TableName() + return m +} + +func (m LogMonthModel) Create(data *dao.LogMonth) error { + return m.Base.Create(data) +} diff --git a/services/water/model/setting.go b/services/water/model/setting.go index b92e26d..4a0887c 100644 --- a/services/water/model/setting.go +++ b/services/water/model/setting.go @@ -2,7 +2,7 @@ package model import ( "lone-services/pkg/modelbase" - "lone-services/services/water/dao" + "lone-services/services/water/internal/dao" ) type SettingModel struct { diff --git a/services/water/validator/log.go b/services/water/validator/log.go index af8a2ea..67b2590 100644 --- a/services/water/validator/log.go +++ b/services/water/validator/log.go @@ -5,8 +5,9 @@ import "lone-services/pkg/validate" // LogAddValidator 查看列表 type LogAddValidator struct { HostCode string `validate:"required"` - Data string `validate:"required"` Time string `validate:"required"` + Salt int64 `validate:"required"` + Water int64 `validate:"required"` } // GetMessage 查看列表 - 提示消息 @@ -14,6 +15,7 @@ func (p LogAddValidator) GetMessage() validate.ValidatorMessages { return validate.ValidatorMessages{ "HostCode.required": "设备不能为空", "Time.required": "时间不能为空", - "Data.required": "数据不能为空", + "Salt.required": "盐量不能为空", + "Water.required": "水量不能为空", } }