Jelajahi Sumber

feat: 11111

lanjianrong 4 tahun lalu
induk
melakukan
1163b6cc5a
4 mengubah file dengan 57 tambahan dan 42 penghapusan
  1. 31 30
      proto/safe.pb.go
  2. 1 1
      proto/safe.proto
  3. 14 8
      services/safe_service.go
  4. 11 3
      web/api/safe_rpc_api.go

+ 31 - 30
proto/safe.pb.go

@@ -82,11 +82,11 @@ type SafePostRequest struct {
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 
-	Id         int32  `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
-	Code       string `protobuf:"bytes,2,opt,name=code,proto3" json:"code,omitempty"`
-	Position   string `protobuf:"bytes,3,opt,name=position,proto3" json:"position,omitempty"`
-	CreateTime string `protobuf:"bytes,4,opt,name=create_time,json=createTime,proto3" json:"create_time,omitempty"`
-	Inspection string `protobuf:"bytes,5,opt,name=inspection,proto3" json:"inspection,omitempty"`
+	BidsectionId int32  `protobuf:"varint,1,opt,name=bidsectionId,proto3" json:"bidsectionId,omitempty"`
+	Code         string `protobuf:"bytes,2,opt,name=code,proto3" json:"code,omitempty"`
+	Position     string `protobuf:"bytes,3,opt,name=position,proto3" json:"position,omitempty"`
+	CreateTime   string `protobuf:"bytes,4,opt,name=create_time,json=createTime,proto3" json:"create_time,omitempty"`
+	Inspection   string `protobuf:"bytes,5,opt,name=inspection,proto3" json:"inspection,omitempty"`
 }
 
 func (x *SafePostRequest) Reset() {
@@ -121,9 +121,9 @@ func (*SafePostRequest) Descriptor() ([]byte, []int) {
 	return file_safe_proto_rawDescGZIP(), []int{1}
 }
 
-func (x *SafePostRequest) GetId() int32 {
+func (x *SafePostRequest) GetBidsectionId() int32 {
 	if x != nil {
-		return x.Id
+		return x.BidsectionId
 	}
 	return 0
 }
@@ -226,29 +226,30 @@ var file_safe_proto_rawDesc = []byte{
 	0x0a, 0x0a, 0x73, 0x61, 0x66, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x70, 0x72,
 	0x6f, 0x74, 0x6f, 0x22, 0x20, 0x0a, 0x0e, 0x53, 0x61, 0x66, 0x65, 0x47, 0x65, 0x74, 0x52, 0x65,
 	0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28,
-	0x05, 0x52, 0x02, 0x69, 0x64, 0x22, 0x92, 0x01, 0x0a, 0x0f, 0x53, 0x61, 0x66, 0x65, 0x50, 0x6f,
-	0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18,
-	0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64,
-	0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x1a, 0x0a,
-	0x08, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52,
-	0x08, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1f, 0x0a, 0x0b, 0x63, 0x72, 0x65,
-	0x61, 0x74, 0x65, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a,
-	0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x69, 0x6e,
-	0x73, 0x70, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a,
-	0x69, 0x6e, 0x73, 0x70, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x45, 0x0a, 0x09, 0x53, 0x61,
-	0x66, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18,
-	0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x64,
-	0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12,
-	0x10, 0x0a, 0x03, 0x6d, 0x73, 0x67, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6d, 0x73,
-	0x67, 0x32, 0x78, 0x0a, 0x04, 0x53, 0x61, 0x66, 0x65, 0x12, 0x38, 0x0a, 0x0b, 0x67, 0x65, 0x74,
-	0x53, 0x61, 0x66, 0x65, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x15, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
-	0x2e, 0x53, 0x61, 0x66, 0x65, 0x47, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a,
-	0x10, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x53, 0x61, 0x66, 0x65, 0x52, 0x65, 0x70, 0x6c,
-	0x79, 0x22, 0x00, 0x12, 0x36, 0x0a, 0x08, 0x70, 0x6f, 0x73, 0x74, 0x53, 0x61, 0x66, 0x65, 0x12,
-	0x16, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x53, 0x61, 0x66, 0x65, 0x50, 0x6f, 0x73, 0x74,
-	0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e,
-	0x53, 0x61, 0x66, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x62, 0x06, 0x70, 0x72, 0x6f,
-	0x74, 0x6f, 0x33,
+	0x05, 0x52, 0x02, 0x69, 0x64, 0x22, 0xa6, 0x01, 0x0a, 0x0f, 0x53, 0x61, 0x66, 0x65, 0x50, 0x6f,
+	0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x22, 0x0a, 0x0c, 0x62, 0x69, 0x64,
+	0x73, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52,
+	0x0c, 0x62, 0x69, 0x64, 0x73, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x12, 0x0a,
+	0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x63, 0x6f, 0x64,
+	0x65, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20,
+	0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1f, 0x0a,
+	0x0b, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01,
+	0x28, 0x09, 0x52, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x1e,
+	0x0a, 0x0a, 0x69, 0x6e, 0x73, 0x70, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x05, 0x20, 0x01,
+	0x28, 0x09, 0x52, 0x0a, 0x69, 0x6e, 0x73, 0x70, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x45,
+	0x0a, 0x09, 0x53, 0x61, 0x66, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x63,
+	0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12,
+	0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x64,
+	0x61, 0x74, 0x61, 0x12, 0x10, 0x0a, 0x03, 0x6d, 0x73, 0x67, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09,
+	0x52, 0x03, 0x6d, 0x73, 0x67, 0x32, 0x78, 0x0a, 0x04, 0x53, 0x61, 0x66, 0x65, 0x12, 0x38, 0x0a,
+	0x0b, 0x67, 0x65, 0x74, 0x53, 0x61, 0x66, 0x65, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x15, 0x2e, 0x70,
+	0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x53, 0x61, 0x66, 0x65, 0x47, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75,
+	0x65, 0x73, 0x74, 0x1a, 0x10, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x53, 0x61, 0x66, 0x65,
+	0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x12, 0x36, 0x0a, 0x08, 0x70, 0x6f, 0x73, 0x74, 0x53,
+	0x61, 0x66, 0x65, 0x12, 0x16, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x53, 0x61, 0x66, 0x65,
+	0x50, 0x6f, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10, 0x2e, 0x70, 0x72,
+	0x6f, 0x74, 0x6f, 0x2e, 0x53, 0x61, 0x66, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x62,
+	0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
 }
 
 var (

+ 1 - 1
proto/safe.proto

@@ -14,7 +14,7 @@ message SafeGetRequest {
     int32 id = 1;
 }
 message SafePostRequest {
-  int32 id = 1;
+  int32 bidsectionId = 1;
   string code = 2;
   string position = 3;
   string create_time = 4;

+ 14 - 8
services/safe_service.go

@@ -20,21 +20,23 @@ import (
 
 type SafeService interface {
 	Get(id int) (int32, string, []viewmodels.Safe)
-	Post(id int, code string, position string, createTime string, inspection string) (int32, string)
+	Post(bidsectionId int, code string, position string, createTime string, inspection string) (int32, string)
 	ValidRule(ctx iris.Context) (viewmodels.Safe, error)
 }
 
 // //返回service操作类
 type safeService struct {
-	rpcClient *grpc.ClientConn
-	valid     string
+	rpcClient   *grpc.ClientConn
+	valid       string
+	validCreate string
 }
 
 //创建项目用户service
 func NewSafeService() SafeService {
 	return &safeService{
-		rpcClient: newGrpcClient(conf.NodeRpcHost),
-		valid:     "/api/safe",
+		rpcClient:   newGrpcClient(conf.NodeRpcHost),
+		valid:       "/api/safe",
+		validCreate: "/api/safe/create",
 	}
 }
 
@@ -80,7 +82,8 @@ func (s *safeService) Get(id int) (int32, string, []viewmodels.Safe) {
 		safeVM.BidsectionId = bidId
 		// safeVM.CreateTime = item.CreateTime
 		safeVM.Demand = item.Demand
-		// safeVM.EndTime = item.EndTime
+		safeVM.EndTime = item.EndTime.Format("2006-01-02 15:04:05")
+
 		id, _ := comm.AesEncrypt(strconv.Itoa(item.Id), conf.SignSecret)
 		safeVM.Id = id
 
@@ -94,12 +97,12 @@ func (s *safeService) Get(id int) (int32, string, []viewmodels.Safe) {
 	return res.GetCode(), res.GetMsg(), safeList
 }
 
-func (s *safeService) Post(id int, code string, position string, createTime string, inspection string) (int32, string) {
+func (s *safeService) Post(bidsectionId int, code string, position string, createTime string, inspection string) (int32, string) {
 	rpcClient := rpc.NewSafeClient(s.rpcClient)
 
 	ctx, cancel := context.WithTimeout(context.Background(), time.Second)
 	defer cancel()
-	res, err := rpcClient.PostSafe(ctx, &rpc.SafePostRequest{Id: int32(id), Code: code, Position: position, CreateTime: createTime, Inspection: inspection})
+	res, err := rpcClient.PostSafe(ctx, &rpc.SafePostRequest{BidsectionId: int32(bidsectionId), Code: code, Position: position, CreateTime: createTime, Inspection: inspection})
 	if err != nil {
 		log.Fatalf("could not greet: %v", err)
 		return -1, ""
@@ -120,6 +123,9 @@ func (s *safeService) ValidRule(ctx iris.Context) (viewmodels.Safe, error) {
 		err = safeVaild.ValidateList()
 	}
 
+	if ctx.Path() == s.validCreate {
+		err = safeVaild.ValidateCreate()
+	}
 	if err != nil {
 		log.Println("获取安全巡检列表, error=", err)
 		return safeVaild, err

+ 11 - 3
web/api/safe_rpc_api.go

@@ -8,6 +8,8 @@
 package api
 
 import (
+	"fmt"
+
 	"github.com/kataras/iris/v12"
 	"go.mod/services"
 	"go.mod/web/utils"
@@ -26,6 +28,7 @@ type SafeRpcApi struct {
 // @Accept  json
 // @Produce  json
 // @Security ApiKeyAuth
+// @Param   bidsectionId     path    string     true        "标段ID"
 // @Success 200 {object} viewmodels.Safe "{code:0成功,data:viewmodels.Safe,msg:}"
 // @Failure 400 {string} string	"{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
 // @Router /api/safe [get]
@@ -58,17 +61,22 @@ func (c *SafeRpcApi) Get() {
 // @Accept  json
 // @Produce  json
 // @Security ApiKeyAuth
+// @Param   bidsectionId     body    string     true        "标段ID"
+// @Param   code     					body    string     true        "编号"
+// @Param   createTime     body    string     true        "日期"
+// @Param   inspection     body    string     true        "检查部位"
+// @Param   position     body    string     true        "部位"
 // @Success 200 {object} viewmodels.Safe "{code:0成功,msg:}"
 // @Failure 400 {string} string	"{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
-// @Router /api/safe [post]
-func (c *SafeRpcApi) Post() {
+// @Router /api/safe/create [post]
+func (c *SafeRpcApi) PostCreate() {
 	// 1.规则验证
 	safeData, err := c.ServiceSafe.ValidRule(c.Ctx)
 	if err != nil {
 		c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
 		return
 	}
-
+	fmt.Println(safeData)
 	bidsectionId, err := utils.GetDecryptId(safeData.BidsectionId)
 	if err != nil {
 		c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})