feat 多级审批

feat 审批类型
This commit is contained in:
耿阳 2022-08-18 13:26:14 +08:00
parent 130a73bf70
commit e77bd62ba8
14 changed files with 1014 additions and 694 deletions

File diff suppressed because it is too large Load Diff

View File

@ -10,8 +10,9 @@ service Approval {
rpc Create(CreateRequest) returns (ApprovalResponse) {};
rpc Detail(DetailRequest) returns (CreateRequest) {};
rpc Update(CreateRequest) returns (ApprovalResponse) {};
rpc Remove(DetailRequest) returns (RemoveResponse) {};
rpc List(ListRequest) returns (ListResponse) {};
rpc Remove(RemoveRequest) returns (RemoveResponse) {};
rpc MyWork(ListRequest) returns (ListResponse) {};// ---
rpc MySubmit(ListRequest) returns (ListResponse) {};//
rpc NowLevelByInfo(NowLevelByInfoRequest) returns (WorkFlowResponse) {};
rpc Information(InformationRequest) returns (InformationResponse) {};
rpc Viewed(ViewedRequest) returns (ApprovalResponse) {};
@ -41,13 +42,15 @@ message WorkFlowResponse {
message CommonRequest {
string Domain = 1 [json_name = "domain"];
uint64 Page = 2 [json_name = "Page"];
uint64 PageSize = 3 [json_name = "pageSize"];
}
message CreateTypeRequest {
string Domain = 1 [json_name = "domain"];
uint64 ID = 2 [json_name = "ID"];
string Title = 3 [json_name = "title"];
string KeyWord = 4 [json_name = "keyWord"];
string Remark = 5 [json_name = "keyWord"];
}
message TypeResponse {
@ -60,19 +63,12 @@ message AllTypeResponse {
uint64 Count = 2;
}
enum StatusType {
Doing = 0;
Ok = 1;
Fail = 2;
}
message StatusRequest {
string Domain = 1 [json_name = "domain"];
uint64 ID = 2 [json_name = "ID"];
string Reply = 3 [json_name = "Reply"];
uint64 WorkFlowId = 4 [json_name = "workFlowId"];
StatusType Status = 5 [json_name = "status",(validator.field) = {is_in_enum: true,human_error: "状态非法"}];
uint64 Status = 5 [json_name = "status",(validator.field) = {int_lt: 4,int_gt: 0,human_error: "状态非法"}];
uint64 Level = 6 [json_name = "level"];
}
@ -84,7 +80,7 @@ message ListRequest {
string Domain = 1 [json_name = "domain",(validator.field) = {string_not_empty: true,human_error: "环境变量必须要有"} ];
uint64 PageSize = 2 [json_name = "PageSize"]; //
uint64 Page = 3 [json_name = "Page"]; //
uint64 Status = 4 [json_name = "status"];//0 1- 2-
uint64 Status = 4 [json_name = "status"];//0 1- 2- 4-
string Type = 5 [json_name = "type"]; //
uint64 UserID = 6 [json_name = "userID"]; //
}
@ -163,25 +159,24 @@ message ApprovalExhibition {
}
message Exhibition {
uint64 ID =1 [json_name = "ID"];
string ReceivedAt =2 [json_name = "receivedAt"];
string Address =3 [json_name = "address"];
repeated ApprovalExhibition ApprovalExhibitions = 4 [json_name = "approvalExhibitions"];
uint64 ID =1 [json_name = "ID"];
string ReceivedAt =2 [json_name = "receivedAt"];
string Address =3 [json_name = "address"];
uint64 PidApprovalID =4 [json_name = "pidApprovalID"];
repeated ApprovalExhibition ApprovalExhibitions = 5 [json_name = "approvalExhibitions"];
}
message CreateRequest {
uint64 ID = 1 [json_name = "ID"];
string Domain = 2 [json_name = "domain",(validator.field) = {string_not_empty: true,human_error: "环境变量必须要有"} ];
StatusType Status = 3 [json_name = "status",(validator.field) = {is_in_enum: true,human_error: "状态非法"}];
uint64 Status = 3 [json_name = "status"];
string Type = 4 [json_name = "type",(validator.field) = {string_not_empty: true,human_error: "类型必须要有"} ];
uint64 ApproverID = 5 [json_name = "approverID",(validator.field) = {string_not_empty: true,human_error: "提交人人ID"} ];
string ApproverName = 6 [json_name = "approverName",(validator.field) = {string_not_empty: true,human_error: "提交人名称"} ];
uint64 SubmitterID = 7 [json_name = "submitterID"];//
string SubmitterName = 8 [json_name = "submitterName"];
repeated CopyUser CopyUsers = 9 [json_name = "copyName"];//
string Content = 10 [json_name = "content"];//
string Reply = 11 [json_name = "reply"];//
bool IsViewed = 12 [json_name = "IsViewed"];//
bool CanView = 12 [json_name = "CanView"];//
Work Work = 13 [json_name = "work"];
Show Show = 14 [json_name = "show"];
Exhibition Exhibition = 15 [json_name = "exhibition"];
@ -189,6 +184,11 @@ message CreateRequest {
repeated ApprovalUser ApprovalUsers= 17 [json_name = "approvalUsers"];//
bool CanApproval = 18 [json_name = "canApproval"];//
repeated WorkFlow WorkFlows = 19 [json_name = "workFlows"];//
uint64 AllStatus = 20 [json_name = "allStatus"];// 0 1 2 3 4-
uint64 NowUserId = 21 [json_name = "nowUserId"];
string NowUserName = 22 [json_name = "nowUserName"];
uint64 Level = 23 [json_name = "level"];
uint64 NowLevel = 24 [json_name = "nowLevel"];
}
message WorkFlow {
@ -204,8 +204,16 @@ message WorkFlow {
message DetailRequest {
uint64 ID=1 [json_name = "ID"];
string Domain=2 [json_name = "domain"];
uint64 UserId=3 [json_name = "userId"];
}
message RemoveRequest {
repeated uint64 IDs=1 [json_name = "IDs"];
string Domain=2 [json_name = "domain"];
}
message ApprovalResponse {
uint64 ID=1 [json_name = "ID"];
bool Success=2 [json_name = "success"];

View File

@ -42,7 +42,10 @@ func (this *AllTypeResponse) Validate() error {
return nil
}
func (this *StatusRequest) Validate() error {
if _, ok := StatusType_name[int32(this.Status)]; !ok {
if !(this.Status > 0) {
return github_com_mwitkow_go_proto_validators.FieldError("Status", fmt.Errorf(`状态非法`))
}
if !(this.Status < 4) {
return github_com_mwitkow_go_proto_validators.FieldError("Status", fmt.Errorf(`状态非法`))
}
return nil
@ -129,15 +132,9 @@ func (this *CreateRequest) Validate() error {
if this.Domain == "" {
return github_com_mwitkow_go_proto_validators.FieldError("Domain", fmt.Errorf(`环境变量必须要有`))
}
if _, ok := StatusType_name[int32(this.Status)]; !ok {
return github_com_mwitkow_go_proto_validators.FieldError("Status", fmt.Errorf(`状态非法`))
}
if this.Type == "" {
return github_com_mwitkow_go_proto_validators.FieldError("Type", fmt.Errorf(`类型必须要有`))
}
if this.ApproverName == "" {
return github_com_mwitkow_go_proto_validators.FieldError("ApproverName", fmt.Errorf(`提交人名称`))
}
for _, item := range this.CopyUsers {
if item != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
@ -187,6 +184,9 @@ func (this *WorkFlow) Validate() error {
func (this *DetailRequest) Validate() error {
return nil
}
func (this *RemoveRequest) Validate() error {
return nil
}
func (this *ApprovalResponse) Validate() error {
return nil
}

View File

@ -31,8 +31,9 @@ type ApprovalClient interface {
Create(ctx context.Context, in *CreateRequest, opts ...grpc_go.CallOption) (*ApprovalResponse, common.ErrorWithAttachment)
Detail(ctx context.Context, in *DetailRequest, opts ...grpc_go.CallOption) (*CreateRequest, common.ErrorWithAttachment)
Update(ctx context.Context, in *CreateRequest, opts ...grpc_go.CallOption) (*ApprovalResponse, common.ErrorWithAttachment)
Remove(ctx context.Context, in *DetailRequest, opts ...grpc_go.CallOption) (*RemoveResponse, common.ErrorWithAttachment)
List(ctx context.Context, in *ListRequest, opts ...grpc_go.CallOption) (*ListResponse, common.ErrorWithAttachment)
Remove(ctx context.Context, in *RemoveRequest, opts ...grpc_go.CallOption) (*RemoveResponse, common.ErrorWithAttachment)
MyWork(ctx context.Context, in *ListRequest, opts ...grpc_go.CallOption) (*ListResponse, common.ErrorWithAttachment)
MySubmit(ctx context.Context, in *ListRequest, opts ...grpc_go.CallOption) (*ListResponse, common.ErrorWithAttachment)
NowLevelByInfo(ctx context.Context, in *NowLevelByInfoRequest, opts ...grpc_go.CallOption) (*WorkFlowResponse, 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)
@ -54,8 +55,9 @@ type ApprovalClientImpl struct {
Create func(ctx context.Context, in *CreateRequest) (*ApprovalResponse, error)
Detail func(ctx context.Context, in *DetailRequest) (*CreateRequest, error)
Update func(ctx context.Context, in *CreateRequest) (*ApprovalResponse, error)
Remove func(ctx context.Context, in *DetailRequest) (*RemoveResponse, error)
List func(ctx context.Context, in *ListRequest) (*ListResponse, error)
Remove func(ctx context.Context, in *RemoveRequest) (*RemoveResponse, error)
MyWork func(ctx context.Context, in *ListRequest) (*ListResponse, error)
MySubmit func(ctx context.Context, in *ListRequest) (*ListResponse, error)
NowLevelByInfo func(ctx context.Context, in *NowLevelByInfoRequest) (*WorkFlowResponse, error)
Information func(ctx context.Context, in *InformationRequest) (*InformationResponse, error)
Viewed func(ctx context.Context, in *ViewedRequest) (*ApprovalResponse, error)
@ -99,16 +101,22 @@ func (c *approvalClient) Update(ctx context.Context, in *CreateRequest, opts ...
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/Update", in, out)
}
func (c *approvalClient) Remove(ctx context.Context, in *DetailRequest, opts ...grpc_go.CallOption) (*RemoveResponse, common.ErrorWithAttachment) {
func (c *approvalClient) Remove(ctx context.Context, in *RemoveRequest, opts ...grpc_go.CallOption) (*RemoveResponse, common.ErrorWithAttachment) {
out := new(RemoveResponse)
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/Remove", in, out)
}
func (c *approvalClient) List(ctx context.Context, in *ListRequest, opts ...grpc_go.CallOption) (*ListResponse, common.ErrorWithAttachment) {
func (c *approvalClient) MyWork(ctx context.Context, in *ListRequest, opts ...grpc_go.CallOption) (*ListResponse, common.ErrorWithAttachment) {
out := new(ListResponse)
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/List", in, out)
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/MyWork", in, out)
}
func (c *approvalClient) MySubmit(ctx context.Context, in *ListRequest, opts ...grpc_go.CallOption) (*ListResponse, common.ErrorWithAttachment) {
out := new(ListResponse)
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/MySubmit", in, out)
}
func (c *approvalClient) NowLevelByInfo(ctx context.Context, in *NowLevelByInfoRequest, opts ...grpc_go.CallOption) (*WorkFlowResponse, common.ErrorWithAttachment) {
@ -184,8 +192,9 @@ type ApprovalServer interface {
Create(context.Context, *CreateRequest) (*ApprovalResponse, error)
Detail(context.Context, *DetailRequest) (*CreateRequest, error)
Update(context.Context, *CreateRequest) (*ApprovalResponse, error)
Remove(context.Context, *DetailRequest) (*RemoveResponse, error)
List(context.Context, *ListRequest) (*ListResponse, error)
Remove(context.Context, *RemoveRequest) (*RemoveResponse, error)
MyWork(context.Context, *ListRequest) (*ListResponse, error)
MySubmit(context.Context, *ListRequest) (*ListResponse, error)
NowLevelByInfo(context.Context, *NowLevelByInfoRequest) (*WorkFlowResponse, error)
Information(context.Context, *InformationRequest) (*InformationResponse, error)
Viewed(context.Context, *ViewedRequest) (*ApprovalResponse, error)
@ -214,11 +223,14 @@ func (UnimplementedApprovalServer) Detail(context.Context, *DetailRequest) (*Cre
func (UnimplementedApprovalServer) Update(context.Context, *CreateRequest) (*ApprovalResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method Update not implemented")
}
func (UnimplementedApprovalServer) Remove(context.Context, *DetailRequest) (*RemoveResponse, error) {
func (UnimplementedApprovalServer) Remove(context.Context, *RemoveRequest) (*RemoveResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method Remove not implemented")
}
func (UnimplementedApprovalServer) List(context.Context, *ListRequest) (*ListResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method List not implemented")
func (UnimplementedApprovalServer) MyWork(context.Context, *ListRequest) (*ListResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method MyWork not implemented")
}
func (UnimplementedApprovalServer) MySubmit(context.Context, *ListRequest) (*ListResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method MySubmit not implemented")
}
func (UnimplementedApprovalServer) NowLevelByInfo(context.Context, *NowLevelByInfoRequest) (*WorkFlowResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method NowLevelByInfo not implemented")
@ -369,7 +381,7 @@ func _Approval_Update_Handler(srv interface{}, ctx context.Context, dec func(int
}
func _Approval_Remove_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
in := new(DetailRequest)
in := new(RemoveRequest)
if err := dec(in); err != nil {
return nil, err
}
@ -397,7 +409,7 @@ func _Approval_Remove_Handler(srv interface{}, ctx context.Context, dec func(int
return interceptor(ctx, in, info, handler)
}
func _Approval_List_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
func _Approval_MyWork_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
in := new(ListRequest)
if err := dec(in); err != nil {
return nil, err
@ -410,7 +422,36 @@ func _Approval_List_Handler(srv interface{}, ctx context.Context, dec func(inter
for k, v := range md {
invAttachment[k] = v
}
invo := invocation.NewRPCInvocation("List", args, invAttachment)
invo := invocation.NewRPCInvocation("MyWork", 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_MySubmit_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
in := new(ListRequest)
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("MySubmit", args, invAttachment)
if interceptor == nil {
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
return result, result.Error()
@ -769,8 +810,12 @@ var Approval_ServiceDesc = grpc_go.ServiceDesc{
Handler: _Approval_Remove_Handler,
},
{
MethodName: "List",
Handler: _Approval_List_Handler,
MethodName: "MyWork",
Handler: _Approval_MyWork_Handler,
},
{
MethodName: "MySubmit",
Handler: _Approval_MySubmit_Handler,
},
{
MethodName: "NowLevelByInfo",

16
pkg/common/md5/md5.go Normal file
View File

@ -0,0 +1,16 @@
package md5
import (
"crypto/md5"
"encoding/hex"
)
func Md5(str string) string {
h := md5.New()
h.Write([]byte(str))
return hex.EncodeToString(h.Sum(nil))
}
func Md5Part(str string, start int, end int) string {
return Md5(str)[start:end]
}

View File

@ -15,9 +15,14 @@ const (
)
const (
ErrorNotFound = "暂无数据"
ErrorWrongStatus = "当前状态无法修改"
ErrorChangeType = "无法修改其类型"
ErrorNotFound = "暂无数据"
ErrorWrongStatus = "当前状态无法修改"
ErrorDoingNotView = "进行中的状态无法设置已阅读"
ErrorChangeType = "无法修改其类型"
ErrorSettingView = "您不可设置已读"
ErrorAlreadySettingView = "已经设置过已读"
ErrorWrongNum = "数量设置错误"
ErrorAlreadyExist = "已经存在"
)
const (

View File

@ -2,6 +2,7 @@ package model
import (
"errors"
"fmt"
"github.com/fonchain_enterprise/fonchain-approval/api/approval"
"github.com/fonchain_enterprise/fonchain-approval/pkg/common/page"
msg "github.com/fonchain_enterprise/fonchain-approval/pkg/m"
@ -44,9 +45,14 @@ const (
TypeBundle = "bundle"
)
const (
StatusDoing = 0
StatusOk = 1
StatusFail = 2
StatusDoing = 1
StatusOk = 2
StatusFail = 3
)
const (
StatusNeedViewed = 4
StatusViewed = 5
)
type ApprovalContentInterface interface {
@ -61,9 +67,36 @@ func (m *Approval) TableName() string {
return "approval"
}
func preValidateExhibition(in *approval.CreateRequest) error {
var entity *Bundle
if in.Type != TypeExhibition {
return nil
}
if in.Exhibition == nil || in.Exhibition.PidApprovalID == 0 {
return errors.New(msg.ErrorApprovalType)
}
if err := DB.Where(Bundle{ApprovalID: in.Exhibition.PidApprovalID}).First(&entity).Error; err != nil {
return err
}
if len(in.Exhibition.ApprovalExhibitions) != int(entity.ApplicationsNum) {
return errors.New(msg.ErrorWrongNum)
}
return nil
}
func StoreApproval(in *approval.CreateRequest) (*Approval, error) {
var entity *Approval
if err1 := preValidateExhibition(in); err1 != nil {
return entity, err1
}
err := DB.Transaction(func(tx *gorm.DB) error {
setting, terr := GetApprovalSettingFromKeyWord(in.Domain, in.Type)
@ -80,6 +113,7 @@ func StoreApproval(in *approval.CreateRequest) (*Approval, error) {
ApprovalUsers: setting.ApprovalUsers,
Type: in.Type,
Content: in.Content,
Status: StatusDoing,
Level: uint8(len(setting.ApprovalUsers)),
NowLevel: 1,
NowUserId: setting.ApprovalUsers[0].ID,
@ -108,20 +142,34 @@ func Viewed(in *approval.ViewedRequest) error {
var entity *Approval
var err error
var isView = false
if err = DB.First(&entity, in.ID).Error; err != nil {
return errors.New(msg.ErrorNotFound)
}
if entity.Status != StatusOk {
return errors.New(msg.ErrorDoingNotView)
}
copyUsers := entity.CopyUsers
for i, temp := range copyUsers {
if temp.ID == in.UserID {
temp.IsViewed = true
if temp.IsViewed == true {
return errors.New(msg.ErrorAlreadySettingView)
}
isView = true
temp.IsViewed = isView
copyUsers[i] = temp
}
}
if isView == false {
return errors.New(msg.ErrorSettingView)
}
return DB.Model(&Approval{}).Where(&Approval{ID: in.ID}).Updates(&Approval{CopyUsers: copyUsers}).Error
}
@ -129,6 +177,10 @@ func Viewed(in *approval.ViewedRequest) error {
func UpdateApproval(in *approval.CreateRequest) (*Approval, error) {
var entity *Approval
if err1 := preValidateExhibition(in); err1 != nil {
return entity, err1
}
err := DB.Transaction(func(tx *gorm.DB) error {
if departErr := DB.First(&entity, in.ID).Error; departErr != nil {
@ -139,31 +191,9 @@ func UpdateApproval(in *approval.CreateRequest) (*Approval, error) {
return errors.New(msg.ErrorChangeType)
}
if entity.Status != StatusDoing {
return errors.New(msg.ErrorWrongStatus)
} else if in.Status != StatusDoing { //审批
// 保存基本信息
entity = &Approval{
ID: in.ID,
Status: int8(in.Status),
Reply: in.Reply,
}
return DB.Save(&entity).Error
}
// 保存基本信息
entity = &Approval{
ID: in.ID,
//Domain: in.Domain,
//SubmitterID: in.SubmitterId,
//SubmitterName: in.SubmitterName,
//ApproverID: in.ApproverId,
//ApproverName: in.ApproverName,
//CopyUsers: FormatCopyUsers(in.CopyUsers),
//Type: in.Type,
Content: in.Content,
Reply: in.Reply,
}
if err := DB.Where(&Approval{ID: in.ID}).Updates(&entity).Error; err != nil {
@ -194,7 +224,7 @@ func approvalCalc(filter *Approval) *approval.Information {
DB.Model(&Approval{}).Where(&filter).Count(&num)
info.Total = uint64(num)
DB.Model(&Approval{}).Where(&filter).Where(&Approval{Status: StatusOk}).Count(&num)
DB.Model(&Approval{}).Where(&filter).Where(&Approval{Status: StatusDoing}).Count(&num)
info.DoingTotal = uint64(num)
DB.Model(&Approval{}).Where(&filter).Where(&Approval{Status: StatusOk}).Count(&num)
@ -209,7 +239,7 @@ func approvalCalc(filter *Approval) *approval.Information {
func approvalCalcJson(domain string, userId uint64) *approval.Information {
var num int64
var jsonStr = "JSON_CONTAINS(approve_users,JSON_OBJECT('ID', ?))"
var jsonStr = "JSON_CONTAINS(approval_users,JSON_OBJECT('ID', ?))"
info := &approval.Information{
Total: 0,
@ -221,7 +251,7 @@ func approvalCalcJson(domain string, userId uint64) *approval.Information {
DB.Model(&Approval{}).Where(jsonStr, userId).Count(&num)
info.Total = uint64(num)
DB.Model(&Approval{}).Where(jsonStr, userId).Where(&Approval{Status: StatusOk, Domain: &domain}).Count(&num)
DB.Model(&Approval{}).Where(jsonStr, userId).Where(&Approval{Status: StatusDoing, Domain: &domain}).Count(&num)
info.DoingTotal = uint64(num)
DB.Model(&Approval{}).Where(jsonStr, userId).Where(&Approval{Status: StatusOk, Domain: &domain}).Count(&num)
@ -310,7 +340,7 @@ func (m *Approval) UpdateContent(in *approval.CreateRequest) error {
return err
}
func ApprovalList(in *approval.ListRequest) ([]*Approval, int64) {
func MyWorkApprovals(in *approval.ListRequest) ([]*Approval, int64) {
var list []*Approval
var count int64
@ -327,8 +357,8 @@ func ApprovalList(in *approval.ListRequest) ([]*Approval, int64) {
}
if in.UserID != 0 {
modelObj = modelObj.Where(DB.Where("JSON_CONTAINS(approve_users,JSON_OBJECT('ID', ?))", in.UserID).
Or("JSON_CONTAINS(copy_users,JSON_OBJECT('ID', ?))", in.UserID))
modelObj = modelObj.Where(DB.Where("JSON_CONTAINS(approval_users,JSON_OBJECT('ID', ?))", in.UserID).
Or(DB.Where("JSON_CONTAINS(copy_users,JSON_OBJECT('ID', ?))", in.UserID)).Where("status != ?", StatusDoing))
}
if in.Status != 0 {
@ -342,6 +372,35 @@ func ApprovalList(in *approval.ListRequest) ([]*Approval, int64) {
return list, count
}
func MySubmitApprovals(in *approval.ListRequest) ([]*Approval, int64) {
var list []*Approval
var count int64
//list
modelObj := DB.Model(&Approval{}).
Preload("Show").
Preload("Work.ApprovalWorks").
Preload("Bundle").
Preload("ApprovalWorkFlows").
Preload("Exhibition.ApprovalExhibitions")
if in.Status != 0 {
modelObj = modelObj.Where(&Approval{Status: int8(in.Status)})
}
if in.Type != "" {
modelObj = modelObj.Where(&Approval{Type: in.Type})
}
modelObj = modelObj.Where(&Approval{SubmitterID: in.UserID})
modelObj.Count(&count)
modelObj.Limit(int(in.PageSize)).Offset(page.GetOffset(in.Page, in.PageSize)).Order("id desc").Find(&list)
return list, count
}
func (m *Approval) Pass(reply string, workFlowId uint64) error {
return m.operateStatus(StatusOk, reply, workFlowId)
}
@ -354,6 +413,7 @@ func (m *Approval) operateStatus(status uint8, reply string, workFlowId uint64)
var workFlow ApprovalWorkFlow
m.Reply = reply
if err := DB.Model(&ApprovalWorkFlow{ApprovalID: m.ID, Status: StatusDoing}).First(&workFlow, workFlowId).Error; err != nil {
return err
}
@ -362,9 +422,9 @@ func (m *Approval) operateStatus(status uint8, reply string, workFlowId uint64)
return errors.New(msg.ErrorOperate)
}
if status == StatusFail { //拒绝
// 拒绝通过
if status == StatusFail {
m.Status = StatusFail
m.Reply = reply
if err := DB.Save(m).Error; err != nil {
return err
@ -373,12 +433,16 @@ func (m *Approval) operateStatus(status uint8, reply string, workFlowId uint64)
return workFlow.Refuse(reply)
}
//层级审批通过
if m.Level == m.NowLevel { // 整个审批通过
/*--------层级审批通过---------*/
// 整个审批通过
if m.Level == m.NowLevel {
m.Status = StatusOk
} else { //审批层级通过
//审批层级通过
} else {
m.NowLevel = workFlow.Level + 1
nextFlow, err := GetWorkFlowByLevel(m.ID, m.NowLevel)
fmt.Println(nextFlow)
if err != nil {
return err
}
@ -386,7 +450,6 @@ func (m *Approval) operateStatus(status uint8, reply string, workFlowId uint64)
m.NowUserName = nextFlow.Name
}
m.Reply = reply
if err := DB.Save(m).Error; err != nil {
return err
}

View File

@ -40,8 +40,6 @@ func (m *ApprovalSetting) TableName() string {
return "approval_setting"
}
type JSON json.RawMessage
func (j *CopyUsers) Scan(src interface{}) error {
return json.Unmarshal(src.([]byte), j)
}
@ -53,13 +51,13 @@ func (j CopyUsers) Value() (driver.Value, error) {
return string(v), err
}
func (j *ApprovalUsers) Scan(src interface{}) error {
return json.Unmarshal(src.([]byte), j)
func (s *ApprovalUsers) Scan(src interface{}) error {
return json.Unmarshal(src.([]byte), s)
}
func (j ApprovalUsers) Value() (driver.Value, error) {
func (s ApprovalUsers) Value() (driver.Value, error) {
v, err := json.Marshal(j)
v, err := json.Marshal(s)
return string(v), err
}

View File

@ -1,7 +1,10 @@
package model
import (
md52 "github.com/fonchain_enterprise/fonchain-approval/pkg/common/md5"
"gorm.io/plugin/soft_delete"
"math/rand"
"strconv"
"time"
)
@ -14,9 +17,45 @@ type ApprovalType struct {
KeyWord string `gorm:"column:key_word" json:"keyWord"` // 回复内容
Domain string `gorm:"column:domain" json:"domain"` // 回复内容
Title string `gorm:"column:title" json:"title"` // 回复内容
Remark string `gorm:"column:remark" json:"remark"` // 回复内容
}
// TableName get sql table name.获取数据库表名
func (m *ApprovalType) TableName() string {
return "approval_type"
}
var keyWordMap = map[string]string{
"普通审批": "content",
"画作申请审批": "work",
"画展包审批": "exhibition",
"画展包数量审批": "bundle",
"画展审批": "show",
}
func DataExist(domain, keyWork string) bool {
var count int64
DB.Model(&ApprovalType{}).Where(&ApprovalType{Domain: domain, KeyWord: keyWork}).Count(&count)
if count != 0 {
return true
}
return false
}
func KeyWordFromTitle(title string) string {
keyWord := md52.Md5Part(title+strconv.Itoa(rand.Intn(100)), 8, 16)
if IsSystemKeyWork(title) == true {
keyWord = keyWordMap[title]
}
return keyWord
}
func IsSystemKeyWork(title string) bool {
_, isOk := keyWordMap[title]
return isOk
}

View File

@ -19,13 +19,15 @@ type ApprovalWorkFlow struct {
Level uint8 `gorm:"column:level" json:"Level"`
Status uint8 `gorm:"column:status" json:"Status"`
Reply string `gorm:"column:reply" json:"Reply"`
OperatedAt time.Time `gorm:"column:operated_at" json:"operatedAt"`
OperatedAt *time.Time `gorm:"column:operated_at" json:"operatedAt"`
}
func GetNowWorkFlowByApprovalId(approvalId uint64) (*ApprovalWorkFlow, error) {
var workFlow *ApprovalWorkFlow
if err := DB.Model(&ApprovalWorkFlow{ApprovalID: approvalId, Status: StatusDoing}).Order("level asc").First(&workFlow).Error; err != nil {
if err := DB.Model(&ApprovalWorkFlow{}).
Where(&ApprovalWorkFlow{ApprovalID: approvalId, Status: StatusDoing}).
Order("level asc").First(&workFlow).Error; err != nil {
return nil, err
}
@ -36,7 +38,7 @@ func GetNowWorkFlowByApprovalId(approvalId uint64) (*ApprovalWorkFlow, error) {
func GetWorkFlowByLevel(approvalId uint64, level uint8) (*ApprovalWorkFlow, error) {
var workFlow *ApprovalWorkFlow
if err := DB.Model(&ApprovalWorkFlow{ApprovalID: approvalId, Level: level}).First(&workFlow).Error; err != nil {
if err := DB.Model(&ApprovalWorkFlow{}).Where(&ApprovalWorkFlow{ApprovalID: approvalId, Level: level}).First(&workFlow).Error; err != nil {
return nil, err
}
@ -56,6 +58,7 @@ func BatchSave(users ApprovalUsers, approvalId uint64) error {
UserId: user.ID,
Name: user.Name,
ApprovalID: approvalId,
Status: StatusDoing,
Level: uint8(index + 1),
}
@ -81,6 +84,8 @@ func (m *ApprovalWorkFlow) Refuse(replay string) error {
func (m *ApprovalWorkFlow) SetStatus(status uint8, reply string) error {
m.Status = status
m.Reply = reply
temp := time.Now()
m.OperatedAt = &temp
DB.Save(m)
return DB.Save(m).Error
}

View File

@ -35,10 +35,7 @@ func init() {
LoadMysqlData(file)
//MySQL数据库
path := strings.Join([]string{DbUser, ":", DbPassWord, "@tcp(", DbHost, ":", DbPort, ")/", DbName, "?charset=utf8&parseTime=true"}, "")
fmt.Println("-----------------------------")
fmt.Println(path)
fmt.Println("-----------------------------")
path := strings.Join([]string{DbUser, ":", DbPassWord, "@tcp(", DbHost, ":", DbPort, ")/", DbName, "?charset=utf8&parseTime=true&loc=Local"}, "")
//连接数据库
Database(path)
}

View File

@ -12,27 +12,38 @@ func BuildApproval(entity *model.Approval, userId uint64) *approval.CreateReques
var exhibition *approval.Exhibition
var bundle *approval.Bundle
var workFlows []*approval.WorkFlow
isViewed := false
canViewed := false
canApproval := false
allStatus := uint64(entity.Status)
copyUsers := model.FormatToResponse(entity.CopyUsers)
for _, cu := range copyUsers {
if userId != 0 && cu.ID == userId && cu.IsViewed == true {
isViewed = true
if allStatus != model.StatusDoing {
for _, cu := range copyUsers {
if userId != 0 && cu.ID == userId {
allStatus = model.StatusNeedViewed
if cu.IsViewed == true {
canViewed = true
allStatus = model.StatusViewed
}
}
}
}
for _, tt := range entity.ApprovalWorkFlows {
temp := &approval.WorkFlow{
ID: tt.ID,
UserID: tt.UserId,
Name: tt.Name,
Level: uint64(tt.Level),
Status: uint64(tt.Status),
Reply: tt.Reply,
OperatedAt: entity.CreatedAt.Format("2006-01-02 15:04:05"),
ID: tt.ID,
UserID: tt.UserId,
Name: tt.Name,
Level: uint64(tt.Level),
Status: uint64(tt.Status),
Reply: tt.Reply,
}
if tt.OperatedAt != nil {
temp.OperatedAt = tt.OperatedAt.Format("2006-01-02 15:04:05")
}
workFlows = append(workFlows, temp)
}
@ -44,13 +55,13 @@ func BuildApproval(entity *model.Approval, userId uint64) *approval.CreateReques
response := &approval.CreateRequest{
ID: entity.ID,
Domain: *entity.Domain,
Status: approval.StatusType(uint64(entity.Status)),
Status: uint64(entity.Status),
Type: entity.Type,
CopyUsers: copyUsers,
SubmitterID: entity.SubmitterID,
SubmitterName: entity.SubmitterName,
Content: entity.Content,
IsViewed: isViewed,
CanView: canViewed,
CanApproval: canApproval,
WorkFlows: workFlows,
Reply: entity.Reply,
@ -58,6 +69,11 @@ func BuildApproval(entity *model.Approval, userId uint64) *approval.CreateReques
Show: show,
Exhibition: exhibition,
Bundle: bundle,
AllStatus: allStatus, //0-未处理 1-通过 2-拒绝 3-已阅读 4-待阅读
NowUserId: entity.NowUserId, //0-未处理 1-通过 2-拒绝 3-已阅读 4-待阅读
NowUserName: entity.NowUserName, //0-未处理 1-通过 2-拒绝 3-已阅读 4-待阅读
Level: uint64(entity.Level), //0-未处理 1-通过 2-拒绝 3-已阅读 4-待阅读
NowLevel: uint64(entity.NowLevel), //0-未处理 1-通过 2-拒绝 3-已阅读 4-待阅读
}
_ = entity.SetResContent(response)

View File

@ -9,10 +9,10 @@ import (
func BuildType(entity *model.ApprovalType) *approval.CreateTypeRequest {
response := &approval.CreateTypeRequest{
ID: entity.ID,
Domain: entity.Domain,
KeyWord: entity.KeyWord,
Title: entity.Title,
ID: entity.ID,
Domain: entity.Domain,
Remark: entity.Remark,
Title: entity.Title,
}
return response

View File

@ -4,6 +4,7 @@ import (
"context"
"errors"
"github.com/fonchain_enterprise/fonchain-approval/api/approval"
"github.com/fonchain_enterprise/fonchain-approval/pkg/common/page"
"github.com/fonchain_enterprise/fonchain-approval/pkg/m"
"github.com/fonchain_enterprise/fonchain-approval/pkg/model"
"github.com/fonchain_enterprise/fonchain-approval/pkg/serializer"
@ -18,6 +19,10 @@ func (a *ApprovalProvider) Create(ctx context.Context, in *approval.CreateReques
response := &approval.ApprovalResponse{}
entity, err := model.StoreApproval(in)
if err != nil {
return response, err
}
response.ID = entity.ID
response.Success = true
@ -53,6 +58,7 @@ func (a *ApprovalProvider) NowLevelByInfo(ctx context.Context, in *approval.NowL
return response, err1
}
response.ID = workFlow.ID
response.UserID = workFlow.UserId
response.Status = uint64(workFlow.Status)
return response, nil
@ -87,37 +93,45 @@ func (a *ApprovalProvider) SetStatus(ctx context.Context, in *approval.StatusReq
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.RemoveRequest) (*approval.RemoveResponse, error) {
response := &approval.RemoveResponse{}
err := model.DB.Transaction(func(tx *gorm.DB) error {
for _, ID := range in.IDs {
var err error
var entity *model.Approval
err := model.DB.Transaction(func(tx *gorm.DB) error {
// 确定有数据则执行删除
if err = model.DB.Where(&model.Approval{Domain: &in.Domain}).
Find(&entity, in.ID).Error; err != nil {
return err
var err error
var entity *model.Approval
// 确定有数据则执行删除
if err = model.DB.Where(&model.Approval{Domain: &in.Domain}).
Find(&entity, ID).Error; err != nil {
return err
}
//删除子关联数据
if err = entity.DeleteContent(); err != nil {
return err
}
if err = model.DB.Where(&model.Approval{Domain: &in.Domain}).
Delete(&model.Approval{}, ID).Error; err != nil {
return err
}
//删除流
if err = model.DB.Where(&model.ApprovalWorkFlow{ApprovalID: ID}).
Delete(&model.ApprovalWorkFlow{}).Error; err != nil {
return err
}
return nil
})
if err != nil {
return nil, err
}
//删除子关联数据
if err = entity.DeleteContent(); err != nil {
return err
}
if err = model.DB.Where(&model.Approval{Domain: &in.Domain}).
Delete(&model.Approval{}, in.ID).Error; err != nil {
return err
}
return nil
})
if err != nil {
return nil, err
}
response.Success = true
@ -140,7 +154,7 @@ func (a *ApprovalProvider) Detail(ctx context.Context, in *approval.DetailReques
return response, err
}
response = serializer.BuildApproval(entity, 0)
response = serializer.BuildApproval(entity, in.UserId)
return response, err
}
@ -167,7 +181,7 @@ func (a *ApprovalProvider) Viewed(ctx context.Context, in *approval.ViewedReques
}
func (a *ApprovalProvider) List(ctx context.Context, in *approval.ListRequest) (*approval.ListResponse, error) {
func (a *ApprovalProvider) MySubmit(ctx context.Context, in *approval.ListRequest) (*approval.ListResponse, error) {
//获取人的 部门角色1、管理组 2、超级管理 3、Leader角色
response := &approval.ListResponse{}
@ -175,7 +189,22 @@ func (a *ApprovalProvider) List(ctx context.Context, in *approval.ListRequest) (
var list []*model.Approval
var count int64
list, count = model.ApprovalList(in)
list, count = model.MySubmitApprovals(in)
response.Count = uint64(count)
response.Data = serializer.BuildApprovals(list, in.UserID)
return response, nil
}
func (a *ApprovalProvider) MyWork(ctx context.Context, in *approval.ListRequest) (*approval.ListResponse, error) {
//获取人的 部门角色1、管理组 2、超级管理 3、Leader角色
response := &approval.ListResponse{}
var list []*model.Approval
var count int64
list, count = model.MyWorkApprovals(in)
response.Count = uint64(count)
response.Data = serializer.BuildApprovals(list, in.UserID)
@ -244,16 +273,23 @@ func (a *ApprovalProvider) DetailSetting(ctx context.Context, in *approval.Detai
func (a *ApprovalProvider) CreateType(ctx context.Context, in *approval.CreateTypeRequest) (*approval.TypeResponse, error) {
response := &approval.TypeResponse{}
keyWord := model.KeyWordFromTitle(in.Title)
if model.DataExist(in.Domain, keyWord) == true {
return response, errors.New(m.ErrorAlreadyExist)
}
typeObj := model.ApprovalType{
KeyWord: in.KeyWord,
KeyWord: keyWord,
Title: in.Title,
Domain: in.Domain,
Remark: in.Remark,
}
if err := model.DB.Create(&typeObj).Error; err != nil {
return response, err
}
response.ID = typeObj.ID
response.Domain = typeObj.Domain
@ -281,8 +317,12 @@ func (a *ApprovalProvider) UpdateType(ctx context.Context, in *approval.CreateTy
return nil, err
}
if typeObj.Title != in.Title && model.IsSystemKeyWork(in.Title) == true {
return response, errors.New(m.ErrorChangeType)
}
typeObj.Title = in.Title
typeObj.KeyWord = in.Title
typeObj.Remark = in.Remark
if err := model.DB.Save(&typeObj).Error; err != nil {
return nil, err
@ -297,14 +337,20 @@ func (a *ApprovalProvider) AllType(ctx context.Context, in *approval.CommonReque
response := &approval.AllTypeResponse{}
var list []*model.ApprovalType
var count int64
if err := model.DB.Where(&model.ApprovalType{Domain: in.Domain}).Find(&list).Error; err != nil {
return nil, err
modelObj := model.DB.Model(&model.ApprovalType{}).Where(&model.ApprovalType{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.BuildTypes(list)
response.Count = uint64(len(list))
response.Count = uint64(count)
return response, nil
}
@ -320,6 +366,7 @@ func (a *ApprovalProvider) RemoveType(ctx context.Context, in *approval.TypeResp
if err := model.DB.Delete(&typeObj, in.ID).Error; err != nil {
return nil, err
}
response.ID = in.ID
response.Domain = in.Domain