feat 增加简洁审批
feat 增加数据校验
This commit is contained in:
parent
bc562c5976
commit
c98a5e86f4
File diff suppressed because it is too large
Load Diff
@ -14,10 +14,27 @@ service Approval {
|
|||||||
rpc List(ListRequest) returns (ListResponse) {};
|
rpc List(ListRequest) returns (ListResponse) {};
|
||||||
rpc Information(InformationRequest) returns (InformationResponse) {};
|
rpc Information(InformationRequest) returns (InformationResponse) {};
|
||||||
rpc Viewed(ViewedRequest) returns (ApprovalResponse) {};
|
rpc Viewed(ViewedRequest) returns (ApprovalResponse) {};
|
||||||
|
rpc SetStatus(StatusRequest) returns (StatusResponse) {};
|
||||||
|
|
||||||
rpc DetailSetting(DetailSettingRequest) returns (SettingRequest) {};
|
rpc DetailSetting(DetailSettingRequest) returns (SettingRequest) {};
|
||||||
rpc UpdateSetting(SettingRequest) returns (SettingResponse) {};
|
rpc UpdateSetting(SettingRequest) returns (SettingResponse) {};
|
||||||
|
|
||||||
|
}
|
||||||
|
enum StatusType {
|
||||||
|
Doing = 0;
|
||||||
|
Ok = 1;
|
||||||
|
Fail = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message StatusRequest {
|
||||||
|
string Domain = 1 [json_name = "domain"];
|
||||||
|
uint64 ID = 2 [json_name = "ID"];
|
||||||
|
string Replay = 3 [json_name = "replay"];
|
||||||
|
StatusType Status = 4 [json_name = "status",(validator.field) = {is_in_enum: true,human_error: "状态非法"}];
|
||||||
|
}
|
||||||
|
|
||||||
|
message StatusResponse {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
message ListRequest {
|
message ListRequest {
|
||||||
|
@ -16,6 +16,15 @@ var _ = proto.Marshal
|
|||||||
var _ = fmt.Errorf
|
var _ = fmt.Errorf
|
||||||
var _ = math.Inf
|
var _ = math.Inf
|
||||||
|
|
||||||
|
func (this *StatusRequest) Validate() error {
|
||||||
|
if _, ok := StatusType_name[int32(this.Status)]; !ok {
|
||||||
|
return github_com_mwitkow_go_proto_validators.FieldError("Status", fmt.Errorf(`状态非法`))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (this *StatusResponse) Validate() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
func (this *ListRequest) Validate() error {
|
func (this *ListRequest) Validate() error {
|
||||||
if this.Domain == "" {
|
if this.Domain == "" {
|
||||||
return github_com_mwitkow_go_proto_validators.FieldError("Domain", fmt.Errorf(`环境变量必须要有`))
|
return github_com_mwitkow_go_proto_validators.FieldError("Domain", fmt.Errorf(`环境变量必须要有`))
|
||||||
|
@ -35,6 +35,7 @@ type ApprovalClient interface {
|
|||||||
List(ctx context.Context, in *ListRequest, opts ...grpc_go.CallOption) (*ListResponse, common.ErrorWithAttachment)
|
List(ctx context.Context, in *ListRequest, opts ...grpc_go.CallOption) (*ListResponse, common.ErrorWithAttachment)
|
||||||
Information(ctx context.Context, in *InformationRequest, opts ...grpc_go.CallOption) (*InformationResponse, common.ErrorWithAttachment)
|
Information(ctx context.Context, in *InformationRequest, opts ...grpc_go.CallOption) (*InformationResponse, common.ErrorWithAttachment)
|
||||||
Viewed(ctx context.Context, in *ViewedRequest, opts ...grpc_go.CallOption) (*ApprovalResponse, common.ErrorWithAttachment)
|
Viewed(ctx context.Context, in *ViewedRequest, opts ...grpc_go.CallOption) (*ApprovalResponse, common.ErrorWithAttachment)
|
||||||
|
SetStatus(ctx context.Context, in *StatusRequest, opts ...grpc_go.CallOption) (*StatusResponse, common.ErrorWithAttachment)
|
||||||
DetailSetting(ctx context.Context, in *DetailSettingRequest, opts ...grpc_go.CallOption) (*SettingRequest, common.ErrorWithAttachment)
|
DetailSetting(ctx context.Context, in *DetailSettingRequest, opts ...grpc_go.CallOption) (*SettingRequest, common.ErrorWithAttachment)
|
||||||
UpdateSetting(ctx context.Context, in *SettingRequest, opts ...grpc_go.CallOption) (*SettingResponse, common.ErrorWithAttachment)
|
UpdateSetting(ctx context.Context, in *SettingRequest, opts ...grpc_go.CallOption) (*SettingResponse, common.ErrorWithAttachment)
|
||||||
}
|
}
|
||||||
@ -51,6 +52,7 @@ type ApprovalClientImpl struct {
|
|||||||
List func(ctx context.Context, in *ListRequest) (*ListResponse, error)
|
List func(ctx context.Context, in *ListRequest) (*ListResponse, error)
|
||||||
Information func(ctx context.Context, in *InformationRequest) (*InformationResponse, error)
|
Information func(ctx context.Context, in *InformationRequest) (*InformationResponse, error)
|
||||||
Viewed func(ctx context.Context, in *ViewedRequest) (*ApprovalResponse, error)
|
Viewed func(ctx context.Context, in *ViewedRequest) (*ApprovalResponse, error)
|
||||||
|
SetStatus func(ctx context.Context, in *StatusRequest) (*StatusResponse, error)
|
||||||
DetailSetting func(ctx context.Context, in *DetailSettingRequest) (*SettingRequest, error)
|
DetailSetting func(ctx context.Context, in *DetailSettingRequest) (*SettingRequest, error)
|
||||||
UpdateSetting func(ctx context.Context, in *SettingRequest) (*SettingResponse, error)
|
UpdateSetting func(ctx context.Context, in *SettingRequest) (*SettingResponse, error)
|
||||||
}
|
}
|
||||||
@ -109,6 +111,12 @@ func (c *approvalClient) Viewed(ctx context.Context, in *ViewedRequest, opts ...
|
|||||||
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/Viewed", in, out)
|
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/Viewed", in, out)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *approvalClient) SetStatus(ctx context.Context, in *StatusRequest, opts ...grpc_go.CallOption) (*StatusResponse, common.ErrorWithAttachment) {
|
||||||
|
out := new(StatusResponse)
|
||||||
|
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
|
||||||
|
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/SetStatus", in, out)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *approvalClient) DetailSetting(ctx context.Context, in *DetailSettingRequest, opts ...grpc_go.CallOption) (*SettingRequest, common.ErrorWithAttachment) {
|
func (c *approvalClient) DetailSetting(ctx context.Context, in *DetailSettingRequest, opts ...grpc_go.CallOption) (*SettingRequest, common.ErrorWithAttachment) {
|
||||||
out := new(SettingRequest)
|
out := new(SettingRequest)
|
||||||
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
|
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
|
||||||
@ -132,6 +140,7 @@ type ApprovalServer interface {
|
|||||||
List(context.Context, *ListRequest) (*ListResponse, error)
|
List(context.Context, *ListRequest) (*ListResponse, error)
|
||||||
Information(context.Context, *InformationRequest) (*InformationResponse, error)
|
Information(context.Context, *InformationRequest) (*InformationResponse, error)
|
||||||
Viewed(context.Context, *ViewedRequest) (*ApprovalResponse, error)
|
Viewed(context.Context, *ViewedRequest) (*ApprovalResponse, error)
|
||||||
|
SetStatus(context.Context, *StatusRequest) (*StatusResponse, error)
|
||||||
DetailSetting(context.Context, *DetailSettingRequest) (*SettingRequest, error)
|
DetailSetting(context.Context, *DetailSettingRequest) (*SettingRequest, error)
|
||||||
UpdateSetting(context.Context, *SettingRequest) (*SettingResponse, error)
|
UpdateSetting(context.Context, *SettingRequest) (*SettingResponse, error)
|
||||||
mustEmbedUnimplementedApprovalServer()
|
mustEmbedUnimplementedApprovalServer()
|
||||||
@ -163,6 +172,9 @@ func (UnimplementedApprovalServer) Information(context.Context, *InformationRequ
|
|||||||
func (UnimplementedApprovalServer) Viewed(context.Context, *ViewedRequest) (*ApprovalResponse, error) {
|
func (UnimplementedApprovalServer) Viewed(context.Context, *ViewedRequest) (*ApprovalResponse, error) {
|
||||||
return nil, status.Errorf(codes.Unimplemented, "method Viewed not implemented")
|
return nil, status.Errorf(codes.Unimplemented, "method Viewed not implemented")
|
||||||
}
|
}
|
||||||
|
func (UnimplementedApprovalServer) SetStatus(context.Context, *StatusRequest) (*StatusResponse, error) {
|
||||||
|
return nil, status.Errorf(codes.Unimplemented, "method SetStatus not implemented")
|
||||||
|
}
|
||||||
func (UnimplementedApprovalServer) DetailSetting(context.Context, *DetailSettingRequest) (*SettingRequest, error) {
|
func (UnimplementedApprovalServer) DetailSetting(context.Context, *DetailSettingRequest) (*SettingRequest, error) {
|
||||||
return nil, status.Errorf(codes.Unimplemented, "method DetailSetting not implemented")
|
return nil, status.Errorf(codes.Unimplemented, "method DetailSetting not implemented")
|
||||||
}
|
}
|
||||||
@ -400,6 +412,35 @@ func _Approval_Viewed_Handler(srv interface{}, ctx context.Context, dec func(int
|
|||||||
return interceptor(ctx, in, info, handler)
|
return interceptor(ctx, in, info, handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func _Approval_SetStatus_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(StatusRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
base := srv.(dubbo3.Dubbo3GrpcService)
|
||||||
|
args := []interface{}{}
|
||||||
|
args = append(args, in)
|
||||||
|
md, _ := metadata.FromIncomingContext(ctx)
|
||||||
|
invAttachment := make(map[string]interface{}, len(md))
|
||||||
|
for k, v := range md {
|
||||||
|
invAttachment[k] = v
|
||||||
|
}
|
||||||
|
invo := invocation.NewRPCInvocation("SetStatus", args, invAttachment)
|
||||||
|
if interceptor == nil {
|
||||||
|
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||||
|
return result, result.Error()
|
||||||
|
}
|
||||||
|
info := &grpc_go.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: ctx.Value("XXX_TRIPLE_GO_INTERFACE_NAME").(string),
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||||
|
return result, result.Error()
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
func _Approval_DetailSetting_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
|
func _Approval_DetailSetting_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
|
||||||
in := new(DetailSettingRequest)
|
in := new(DetailSettingRequest)
|
||||||
if err := dec(in); err != nil {
|
if err := dec(in); err != nil {
|
||||||
@ -493,6 +534,10 @@ var Approval_ServiceDesc = grpc_go.ServiceDesc{
|
|||||||
MethodName: "Viewed",
|
MethodName: "Viewed",
|
||||||
Handler: _Approval_Viewed_Handler,
|
Handler: _Approval_Viewed_Handler,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
MethodName: "SetStatus",
|
||||||
|
Handler: _Approval_SetStatus_Handler,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
MethodName: "DetailSetting",
|
MethodName: "DetailSetting",
|
||||||
Handler: _Approval_DetailSetting_Handler,
|
Handler: _Approval_DetailSetting_Handler,
|
||||||
|
@ -146,6 +146,7 @@ func UpdateApproval(in *approval.CreateRequest) (*Approval, error) {
|
|||||||
//CopyUsers: FormatCopyUsers(in.CopyUsers),
|
//CopyUsers: FormatCopyUsers(in.CopyUsers),
|
||||||
//Type: in.Type,
|
//Type: in.Type,
|
||||||
Content: in.Content,
|
Content: in.Content,
|
||||||
|
Reply: in.Reply,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := DB.Where(&Approval{ID: in.ID}).Updates(&entity).Error; err != nil {
|
if err := DB.Where(&Approval{ID: in.ID}).Updates(&entity).Error; err != nil {
|
||||||
|
@ -2,7 +2,9 @@ package service
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"github.com/fonchain_enterprise/fonchain-approval/api/approval"
|
"github.com/fonchain_enterprise/fonchain-approval/api/approval"
|
||||||
|
"github.com/fonchain_enterprise/fonchain-approval/pkg/m"
|
||||||
"github.com/fonchain_enterprise/fonchain-approval/pkg/model"
|
"github.com/fonchain_enterprise/fonchain-approval/pkg/model"
|
||||||
"github.com/fonchain_enterprise/fonchain-approval/pkg/serializer"
|
"github.com/fonchain_enterprise/fonchain-approval/pkg/serializer"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
@ -34,7 +36,25 @@ func (a *ApprovalProvider) Update(ctx context.Context, in *approval.CreateReques
|
|||||||
}
|
}
|
||||||
|
|
||||||
return response, err
|
return response, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *ApprovalProvider) SetStatus(ctx context.Context, in *approval.StatusRequest) (*approval.StatusResponse, error) {
|
||||||
|
|
||||||
|
response := &approval.StatusResponse{}
|
||||||
|
var approvalObj *model.Approval
|
||||||
|
|
||||||
|
if err := model.DB.First(&approvalObj, in.ID).Error; err != nil {
|
||||||
|
return response, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if approvalObj.Status != model.StatusDoing {
|
||||||
|
return response, errors.New(m.ErrorWrongStatus)
|
||||||
|
}
|
||||||
|
|
||||||
|
err := model.DB.Where(&model.Approval{ID: in.ID, Domain: &in.Domain}).
|
||||||
|
Updates(&model.Approval{Status: int8(in.Status), Reply: in.Replay}).Error
|
||||||
|
|
||||||
|
return response, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *ApprovalProvider) Remove(ctx context.Context, in *approval.DetailRequest) (*approval.RemoveResponse, error) {
|
func (a *ApprovalProvider) Remove(ctx context.Context, in *approval.DetailRequest) (*approval.RemoveResponse, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user