fonchain-approval-fork/pkg/serializer/approval.go

112 lines
2.9 KiB
Go
Raw Normal View History

package serializer
import (
2023-06-21 06:54:47 +00:00
"github.com/fonchain_enterprise/fonchain-approval-fork/api/approval"
"github.com/fonchain_enterprise/fonchain-approval-fork/pkg/e"
"github.com/fonchain_enterprise/fonchain-approval-fork/pkg/model"
)
2023-06-21 06:54:47 +00:00
// BuildApproval 处理单个detail返回
func BuildApproval(entity *model.Approval, userId uint64) *approval.CreateRequest {
var work *approval.Work
var show *approval.Show
var exhibition *approval.Exhibition
var bundle *approval.Bundle
2022-08-16 10:45:28 +00:00
var workFlows []*approval.WorkFlow
2023-04-25 07:25:30 +00:00
var financialForm *approval.FinancialForm
2022-08-18 05:26:14 +00:00
canViewed := false
2022-08-16 10:45:28 +00:00
canApproval := false
2022-08-18 05:26:14 +00:00
allStatus := uint64(entity.Status)
copyUsers := model.FormatToResponse(entity.CopyUsers)
2022-08-18 05:26:14 +00:00
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
}
}
}
}
2022-08-16 10:45:28 +00:00
for _, tt := range entity.ApprovalWorkFlows {
temp := &approval.WorkFlow{
2022-08-18 05:26:14 +00:00
ID: tt.ID,
UserID: tt.UserId,
Name: tt.Name,
Level: uint64(tt.Level),
Status: uint64(tt.Status),
Reply: tt.Reply,
2022-08-16 10:45:28 +00:00
}
2022-08-18 05:26:14 +00:00
if tt.OperatedAt != nil {
temp.OperatedAt = tt.OperatedAt.Format("2006-01-02 15:04:05")
}
2022-08-16 10:45:28 +00:00
workFlows = append(workFlows, temp)
}
if entity.Status == model.StatusDoing && entity.NowUserId == userId {
canApproval = true
}
2022-07-29 09:08:00 +00:00
response := &approval.CreateRequest{
ID: entity.ID,
Domain: *entity.Domain,
2022-08-18 05:26:14 +00:00
Status: uint64(entity.Status),
Type: entity.Type,
CopyUsers: copyUsers,
SubmitterID: entity.SubmitterID,
SubmitterName: entity.SubmitterName,
Content: entity.Content,
2022-08-18 05:26:14 +00:00
CanView: canViewed,
2023-01-16 08:09:19 +00:00
IsCustom: e.Is_IsCustom_Yes,
2022-08-16 10:45:28 +00:00
CanApproval: canApproval,
WorkFlows: workFlows,
Reply: entity.Reply,
Work: work,
Show: show,
Exhibition: exhibition,
Bundle: bundle,
2023-04-25 07:25:30 +00:00
FinancialForm: financialForm,
2023-01-16 08:09:19 +00:00
CustomizeInfo: BuildKeyInfo(entity.ValueJson),
2022-08-23 08:20:06 +00:00
CreatedAt: entity.CreatedAt.Format("2006-01-02 15:04:05"),
2023-01-16 08:09:19 +00:00
AllStatus: allStatus, //0-未处理 1-通过 2-拒绝 3-已阅读 4-待阅读
NowUserId: entity.NowUserId,
NowUserName: entity.NowUserName,
Level: uint64(entity.Level),
NowLevel: uint64(entity.NowLevel),
}
if model.IsSystemType(entity.Type) == true {
response.IsCustom = e.Is_IsCustom_No
}
2023-03-01 10:53:47 +00:00
if entity.ApprovalType != nil {
response.TypeName = entity.ApprovalType.Title
if entity.ApprovalType.ApprovalTypeGroup != nil {
response.GroupName = entity.ApprovalType.ApprovalTypeGroup.Title
}
}
_ = entity.SetResContent(response)
2023-03-22 02:24:24 +00:00
//fmt.Println("check:", response.BundlePayPrice)
return response
}
2023-06-21 06:54:47 +00:00
// BuildApprovals 处理单个detail返回
func BuildApprovals(list []*model.Approval, userId uint64) (details []*approval.CreateRequest) {
for _, item := range list {
temp := BuildApproval(item, userId)
details = append(details, temp)
}
return details
}