feat
This commit is contained in:
parent
d29b55b318
commit
c2331415fe
File diff suppressed because it is too large
Load Diff
@ -28,6 +28,7 @@ service Approval {
|
||||
rpc UpdateType(CreateTypeRequest) returns (TypeResponse) {};
|
||||
rpc AllType(CommonRequest) returns (AllTypeResponse) {};
|
||||
rpc RemoveType(RemoveRequest) returns (StatusResponse) {};
|
||||
rpc AllGroup(CommonRequest) returns (AllGroupResponse) {};
|
||||
}
|
||||
|
||||
message KeyInfo {
|
||||
@ -71,16 +72,19 @@ message CommonRequest {
|
||||
string Domain = 1 [json_name = "domain"];
|
||||
uint64 Page = 2 [json_name = "Page"];
|
||||
uint64 PageSize = 3 [json_name = "pageSize"];
|
||||
uint64 GroupId = 4 [json_name = "groupId"];
|
||||
}
|
||||
|
||||
message CreateTypeRequest {
|
||||
string Domain = 1 [json_name = "domain"];
|
||||
uint64 ID = 2 [json_name = "ID"];
|
||||
string Title = 3 [json_name = "title"];
|
||||
string Remark = 5 [json_name = "remark"];
|
||||
string KeyWord = 6 [json_name = "keyWord"];
|
||||
repeated KeyInfo KeyInfos = 7 [json_name = "keyInfos"];
|
||||
uint64 IsCustom = 8 [json_name = "isCustom"];
|
||||
string Domain = 1 [json_name = "domain"];
|
||||
uint64 ID = 2 [json_name = "ID"];
|
||||
string Title = 3 [json_name = "title"];
|
||||
string Remark = 5 [json_name = "remark"];
|
||||
string KeyWord = 6 [json_name = "keyWord"];
|
||||
repeated KeyInfo KeyInfos = 7 [json_name = "keyInfos"];
|
||||
uint64 IsCustom = 8 [json_name = "isCustom"];
|
||||
uint64 GroupId = 9 [json_name = "groupId"];
|
||||
string GroupName = 10 [json_name = "groupName"];
|
||||
}
|
||||
|
||||
message TypeResponse {
|
||||
@ -93,6 +97,18 @@ message AllTypeResponse {
|
||||
uint64 Count = 2;
|
||||
}
|
||||
|
||||
message CreateTypeGroupRequest {
|
||||
uint64 ID = 1 [json_name = "ID"];
|
||||
string Domain = 2 [json_name = "domain"];
|
||||
string Title = 3 [json_name = "title"];
|
||||
repeated CreateTypeRequest List = 4 [json_name = "list"];
|
||||
}
|
||||
|
||||
message AllGroupResponse {
|
||||
repeated CreateTypeGroupRequest Data = 1;
|
||||
uint64 Count = 2;
|
||||
}
|
||||
|
||||
message StatusRequest {
|
||||
string Domain = 1 [json_name = "domain"];
|
||||
uint64 ID = 2 [json_name = "ID"];
|
||||
|
@ -63,6 +63,26 @@ func (this *AllTypeResponse) Validate() error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (this *CreateTypeGroupRequest) Validate() error {
|
||||
for _, item := range this.List {
|
||||
if item != nil {
|
||||
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
|
||||
return github_com_mwitkow_go_proto_validators.FieldError("List", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (this *AllGroupResponse) Validate() error {
|
||||
for _, item := range this.Data {
|
||||
if item != nil {
|
||||
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
|
||||
return github_com_mwitkow_go_proto_validators.FieldError("Data", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (this *StatusRequest) Validate() error {
|
||||
if !(this.Status > 0) {
|
||||
return github_com_mwitkow_go_proto_validators.FieldError("Status", fmt.Errorf(`70008`))
|
||||
|
@ -47,6 +47,7 @@ type ApprovalClient interface {
|
||||
UpdateType(ctx context.Context, in *CreateTypeRequest, opts ...grpc_go.CallOption) (*TypeResponse, common.ErrorWithAttachment)
|
||||
AllType(ctx context.Context, in *CommonRequest, opts ...grpc_go.CallOption) (*AllTypeResponse, common.ErrorWithAttachment)
|
||||
RemoveType(ctx context.Context, in *RemoveRequest, opts ...grpc_go.CallOption) (*StatusResponse, common.ErrorWithAttachment)
|
||||
AllGroup(ctx context.Context, in *CommonRequest, opts ...grpc_go.CallOption) (*AllGroupResponse, common.ErrorWithAttachment)
|
||||
}
|
||||
|
||||
type approvalClient struct {
|
||||
@ -73,6 +74,7 @@ type ApprovalClientImpl struct {
|
||||
UpdateType func(ctx context.Context, in *CreateTypeRequest) (*TypeResponse, error)
|
||||
AllType func(ctx context.Context, in *CommonRequest) (*AllTypeResponse, error)
|
||||
RemoveType func(ctx context.Context, in *RemoveRequest) (*StatusResponse, error)
|
||||
AllGroup func(ctx context.Context, in *CommonRequest) (*AllGroupResponse, error)
|
||||
}
|
||||
|
||||
func (c *ApprovalClientImpl) GetDubboStub(cc *triple.TripleConn) ApprovalClient {
|
||||
@ -201,6 +203,12 @@ func (c *approvalClient) RemoveType(ctx context.Context, in *RemoveRequest, opts
|
||||
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/RemoveType", in, out)
|
||||
}
|
||||
|
||||
func (c *approvalClient) AllGroup(ctx context.Context, in *CommonRequest, opts ...grpc_go.CallOption) (*AllGroupResponse, common.ErrorWithAttachment) {
|
||||
out := new(AllGroupResponse)
|
||||
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
|
||||
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/AllGroup", in, out)
|
||||
}
|
||||
|
||||
// ApprovalServer is the server API for Approval service.
|
||||
// All implementations must embed UnimplementedApprovalServer
|
||||
// for forward compatibility
|
||||
@ -224,6 +232,7 @@ type ApprovalServer interface {
|
||||
UpdateType(context.Context, *CreateTypeRequest) (*TypeResponse, error)
|
||||
AllType(context.Context, *CommonRequest) (*AllTypeResponse, error)
|
||||
RemoveType(context.Context, *RemoveRequest) (*StatusResponse, error)
|
||||
AllGroup(context.Context, *CommonRequest) (*AllGroupResponse, error)
|
||||
mustEmbedUnimplementedApprovalServer()
|
||||
}
|
||||
|
||||
@ -289,6 +298,9 @@ func (UnimplementedApprovalServer) AllType(context.Context, *CommonRequest) (*Al
|
||||
func (UnimplementedApprovalServer) RemoveType(context.Context, *RemoveRequest) (*StatusResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method RemoveType not implemented")
|
||||
}
|
||||
func (UnimplementedApprovalServer) AllGroup(context.Context, *CommonRequest) (*AllGroupResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method AllGroup not implemented")
|
||||
}
|
||||
func (s *UnimplementedApprovalServer) XXX_SetProxyImpl(impl protocol.Invoker) {
|
||||
s.proxyImpl = impl
|
||||
}
|
||||
@ -868,6 +880,35 @@ func _Approval_RemoveType_Handler(srv interface{}, ctx context.Context, dec func
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Approval_AllGroup_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(CommonRequest)
|
||||
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("AllGroup", 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)
|
||||
}
|
||||
|
||||
// Approval_ServiceDesc is the grpc_go.ServiceDesc for Approval service.
|
||||
// It's only intended for direct use with grpc_go.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
@ -951,6 +992,10 @@ var Approval_ServiceDesc = grpc_go.ServiceDesc{
|
||||
MethodName: "RemoveType",
|
||||
Handler: _Approval_RemoveType_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "AllGroup",
|
||||
Handler: _Approval_AllGroup_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc_go.StreamDesc{},
|
||||
Metadata: "api/approval/approval.proto",
|
||||
|
@ -12,16 +12,18 @@ import (
|
||||
|
||||
// ApprovalType 审批类型
|
||||
type ApprovalType struct {
|
||||
ID uint64 `gorm:"primaryKey;column:id" json:"id"` // ID
|
||||
DeletedAt soft_delete.DeletedAt `gorm:"column:deleted_at" json:"deletedAt"` // 删除时间
|
||||
CreatedAt time.Time `gorm:"column:created_at" json:"createdAt"` // 创建时间
|
||||
UpdatedAt time.Time `gorm:"column:updated_at" json:"updatedAt"` // 更新时间
|
||||
KeyWord string `gorm:"column:key_word" json:"keyWord"` // 回复内容
|
||||
IsNormal uint64 `gorm:"type:tinyint;column:is_normal;default:1;comment:是否是自定义" json:"isNormal"` // 回复内容
|
||||
KeyJson KeyInfos `gorm:"type:json;column:key_json;default:null;comment:自定义字段" json:"keyJson"`
|
||||
Domain string `gorm:"column:domain" json:"domain"` // 回复内容
|
||||
Title string `gorm:"column:title" json:"title"` // 回复内容
|
||||
Remark string `gorm:"column:remark" json:"remark"` // 回复内容
|
||||
ID uint64 `gorm:"primaryKey;column:id" json:"id"` // ID
|
||||
DeletedAt soft_delete.DeletedAt `gorm:"column:deleted_at" json:"deletedAt"` // 删除时间
|
||||
CreatedAt time.Time `gorm:"column:created_at" json:"createdAt"` // 创建时间
|
||||
UpdatedAt time.Time `gorm:"column:updated_at" json:"updatedAt"` // 更新时间
|
||||
KeyWord string `gorm:"column:key_word" json:"keyWord"` // 回复内容
|
||||
IsNormal uint64 `gorm:"type:tinyint;column:is_normal;default:1;comment:是否是自定义" json:"isNormal"` // 回复内容
|
||||
GroupId uint64 `gorm:"type:int(11);column:group_id;default:0;comment:类型的分组" json:"groupId"` // 回复内容
|
||||
KeyJson KeyInfos `gorm:"type:json;column:key_json;default:null;comment:自定义字段" json:"keyJson"`
|
||||
Domain string `gorm:"column:domain" json:"domain"` //
|
||||
Title string `gorm:"column:title" json:"title"` // 标题
|
||||
Remark string `gorm:"column:remark" json:"remark"` // 备注
|
||||
ApprovalTypeGroup *ApprovalTypeGroup `gorm:"foreignKey:GroupId" json:"ApprovalTypeGroup"` // 绑定的分租
|
||||
}
|
||||
|
||||
// TableName get sql table name.获取数据库表名
|
||||
|
40
pkg/model/approval_type_group.go
Normal file
40
pkg/model/approval_type_group.go
Normal file
@ -0,0 +1,40 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/plugin/soft_delete"
|
||||
"time"
|
||||
)
|
||||
|
||||
// ApprovalTypeGroup 审批类型分组
|
||||
type ApprovalTypeGroup struct {
|
||||
ID uint64 `gorm:"primaryKey;column:id" json:"id"` // ID
|
||||
DeletedAt soft_delete.DeletedAt `gorm:"column:deleted_at" json:"deletedAt"` // 删除时间
|
||||
CreatedAt time.Time `gorm:"column:created_at" json:"createdAt"` // 创建时间
|
||||
UpdatedAt time.Time `gorm:"column:updated_at" json:"updatedAt"` // 更新时间
|
||||
Domain *string `gorm:"column:domain" json:"domain"` // domain
|
||||
Title string `gorm:"column:title" json:"title"` // 名称
|
||||
ApprovalTypes []*ApprovalType `gorm:"foreignKey:GroupId" json:"approvalTypes"` //
|
||||
}
|
||||
|
||||
// TableName get sql table name.获取数据库表名
|
||||
func (m *ApprovalTypeGroup) TableName() string {
|
||||
return "approval_type_group"
|
||||
}
|
||||
|
||||
func GetGroupIdByName(title, domain string) (uint64, error) {
|
||||
var groupObj *ApprovalTypeGroup
|
||||
DB.Model(&ApprovalTypeGroup{}).Where(&ApprovalTypeGroup{Title: title, Domain: &domain}).First(&groupObj)
|
||||
if groupObj == nil || groupObj.ID == 0 {
|
||||
groupObj = &ApprovalTypeGroup{
|
||||
Domain: &domain,
|
||||
Title: title,
|
||||
}
|
||||
|
||||
err := DB.Model(&ApprovalTypeGroup{}).Save(&groupObj).Error
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
return groupObj.ID, nil
|
||||
}
|
@ -7,9 +7,12 @@ import (
|
||||
//类型迁移
|
||||
func migration() {
|
||||
//自动迁移模式
|
||||
addTable(&ApprovalTypeGroup{})
|
||||
|
||||
//增加字段
|
||||
addColumn(&ApprovalType{}, "is_normal")
|
||||
addColumn(&ApprovalType{}, "key_json")
|
||||
addColumn(&ApprovalType{}, "group_id")
|
||||
|
||||
addColumn(&Exhibition{}, "apply_id")
|
||||
addColumn(&ApprovalExhibition{}, "package_id")
|
||||
@ -30,3 +33,12 @@ func addColumn(dst interface{}, column string) {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func addTable(dst interface{}) {
|
||||
|
||||
if DB.Migrator().HasTable(dst) == false {
|
||||
_ = DB.Migrator().CreateTable(dst)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -18,6 +18,10 @@ func BuildType(entity *model.ApprovalType) *approval.CreateTypeRequest {
|
||||
IsCustom: e.Is_IsCustom_Yes,
|
||||
KeyInfos: BuildKeyInfo(entity.KeyJson),
|
||||
}
|
||||
if entity.ApprovalTypeGroup != nil {
|
||||
response.GroupName = entity.ApprovalTypeGroup.Title
|
||||
response.GroupId = entity.ApprovalTypeGroup.ID
|
||||
}
|
||||
|
||||
if model.IsSystemType(entity.KeyWord) == true {
|
||||
response.IsCustom = e.Is_IsCustom_No
|
||||
@ -42,6 +46,19 @@ func BuildKeyInfo(infos model.KeyInfos) []*approval.KeyInfo {
|
||||
return keyInfos
|
||||
}
|
||||
|
||||
//BuildGroup 处理单个detail返回
|
||||
func BuildGroup(entity *model.ApprovalTypeGroup) *approval.CreateTypeGroupRequest {
|
||||
|
||||
response := &approval.CreateTypeGroupRequest{
|
||||
ID: entity.ID,
|
||||
Domain: *entity.Domain,
|
||||
Title: entity.Title,
|
||||
}
|
||||
response.List = BuildTypes(entity.ApprovalTypes)
|
||||
|
||||
return response
|
||||
}
|
||||
|
||||
func BuildTypes(entity []*model.ApprovalType) (details []*approval.CreateTypeRequest) {
|
||||
|
||||
for _, temp := range entity {
|
||||
@ -50,3 +67,12 @@ func BuildTypes(entity []*model.ApprovalType) (details []*approval.CreateTypeReq
|
||||
|
||||
return details
|
||||
}
|
||||
|
||||
func BuildGroups(entity []*model.ApprovalTypeGroup) (details []*approval.CreateTypeGroupRequest) {
|
||||
|
||||
for _, temp := range entity {
|
||||
details = append(details, BuildGroup(temp))
|
||||
}
|
||||
|
||||
return details
|
||||
}
|
||||
|
@ -304,6 +304,12 @@ func (a *ApprovalProvider) CreateType(ctx context.Context, in *approval.CreateTy
|
||||
response := &approval.TypeResponse{}
|
||||
|
||||
fmt.Println("创建类型:", in.String())
|
||||
//创建分组
|
||||
groupId, err := model.GetGroupIdByName(in.GroupName, in.Domain)
|
||||
if err != nil {
|
||||
return response, err
|
||||
}
|
||||
|
||||
keyWord := model.KeyWordFromTitle(in.Title)
|
||||
|
||||
if model.DataExist(in.Domain, keyWord, in.Title) == true {
|
||||
@ -315,6 +321,7 @@ func (a *ApprovalProvider) CreateType(ctx context.Context, in *approval.CreateTy
|
||||
Title: in.Title,
|
||||
Domain: in.Domain,
|
||||
Remark: in.Remark,
|
||||
GroupId: groupId,
|
||||
KeyJson: model.ToKeyInfos(in.KeyInfos),
|
||||
}
|
||||
|
||||
@ -332,7 +339,7 @@ func (a *ApprovalProvider) DetailType(ctx context.Context, in *approval.TypeResp
|
||||
response := &approval.CreateTypeRequest{}
|
||||
var typeObj model.ApprovalType
|
||||
|
||||
if err := model.DB.First(&typeObj, in.ID).Error; err != nil {
|
||||
if err := model.DB.Preload("ApprovalTypeGroup").First(&typeObj, in.ID).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -371,7 +378,8 @@ func (a *ApprovalProvider) AllType(ctx context.Context, in *approval.CommonReque
|
||||
var list []*model.ApprovalType
|
||||
var count int64
|
||||
|
||||
modelObj := model.DB.Model(&model.ApprovalType{}).Where(&model.ApprovalType{Domain: in.Domain}).Order("id desc")
|
||||
modelObj := model.DB.Model(&model.ApprovalType{}).Preload("ApprovalTypeGroup").
|
||||
Where(&model.ApprovalType{Domain: in.Domain, GroupId: in.GroupId}).Order("id desc")
|
||||
modelObj.Count(&count)
|
||||
|
||||
if in.Page != 0 && in.PageSize != 0 {
|
||||
@ -387,6 +395,29 @@ func (a *ApprovalProvider) AllType(ctx context.Context, in *approval.CommonReque
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (a *ApprovalProvider) AllGroup(ctx context.Context, in *approval.CommonRequest) (*approval.AllGroupResponse, error) {
|
||||
|
||||
response := &approval.AllGroupResponse{}
|
||||
var list []*model.ApprovalTypeGroup
|
||||
var count int64
|
||||
|
||||
modelObj := model.DB.Model(&model.ApprovalTypeGroup{}).Preload("ApprovalTypes").
|
||||
Where(&model.ApprovalTypeGroup{Domain: &in.Domain}).Order("id desc")
|
||||
modelObj.Count(&count)
|
||||
|
||||
if in.Page != 0 && in.PageSize != 0 {
|
||||
modelObj.Limit(int(in.PageSize)).Offset(page.GetOffset(in.Page, in.PageSize))
|
||||
}
|
||||
|
||||
modelObj.Find(&list)
|
||||
|
||||
response.Data = serializer.BuildGroups(list)
|
||||
|
||||
response.Count = uint64(count)
|
||||
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (a *ApprovalProvider) RemoveType(ctx context.Context, in *approval.RemoveRequest) (*approval.StatusResponse, error) {
|
||||
response := &approval.StatusResponse{}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user