2024-11-14 17:02:41 +08:00
|
|
|
package flow_instance
|
|
|
|
|
|
|
|
import (
|
|
|
|
instanceModel "approveflow/app/provider/flow_instance/model"
|
|
|
|
"approveflow/app/utils"
|
|
|
|
)
|
|
|
|
|
|
|
|
func MapApprovalInstanceToDTOBatch(approvalInstances []*instanceModel.ApprovalInstance) ([]*ApprovalInstanceDTO, error) {
|
|
|
|
res := make([]*ApprovalInstanceDTO, 0, len(approvalInstances))
|
|
|
|
for _, instance := range approvalInstances {
|
2024-11-19 17:03:12 +08:00
|
|
|
for _, step := range instance.Steps {
|
|
|
|
step.Status = step.GetStatus()
|
|
|
|
}
|
2024-11-14 17:02:41 +08:00
|
|
|
dto, err := MapApprovalInstanceToDTO(instance)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
res = append(res, dto)
|
|
|
|
}
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func MapApprovalInstanceToDTO(approvalInstance *instanceModel.ApprovalInstance) (*ApprovalInstanceDTO, error) {
|
|
|
|
// 创建目标 ApprovalInstanceDTO 对象
|
|
|
|
approvalInstanceDTO := &ApprovalInstanceDTO{}
|
|
|
|
|
2024-11-19 17:03:12 +08:00
|
|
|
for _, step := range approvalInstance.Steps {
|
|
|
|
step.Status = step.GetStatus()
|
|
|
|
}
|
|
|
|
|
2024-11-14 17:02:41 +08:00
|
|
|
// 使用 Convert 方法将 实体对象 转换为 DTO
|
|
|
|
if err := utils.Convert(approvalInstance, approvalInstanceDTO); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return approvalInstanceDTO, nil
|
|
|
|
}
|