outbound.go 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package model
  2. import (
  3. "fmt"
  4. "kpt-pasture/util"
  5. "time"
  6. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  7. )
  8. type Outbound struct {
  9. Id int64 `json:"id"`
  10. Number string `json:"number"`
  11. OutType pasturePb.OutType_Kind `json:"outType"`
  12. AuditStatus pasturePb.AuditStatus_Kind `json:"auditStatus"`
  13. ApplicantId int32 `json:"applicantId"`
  14. ApplicantName string `json:"applicantName"`
  15. ApplicantAt int64 `json:"applicantAt"`
  16. ApplicantRemarks string `json:"applicantRemarks"`
  17. ExamineId int32 `json:"examineId"`
  18. ExamineName string `json:"examineName"`
  19. ExamineAt int64 `json:"examineAt"`
  20. ExamineRemarks string `json:"examineRemarks"`
  21. CreatedAt int64 `json:"createdAt"`
  22. UpdatedAt int64 `json:"updatedAt"`
  23. }
  24. func (o *Outbound) TableName() string {
  25. return "outbound"
  26. }
  27. func (o *Outbound) Delete() {
  28. o.AuditStatus = pasturePb.AuditStatus_Delete
  29. }
  30. func NewOutbound(req *pasturePb.OutboundApplyItem, currentUser *SystemUser) *Outbound {
  31. return &Outbound{
  32. Number: fmt.Sprintf("%s%s", util.GenerateRandomNumberString(8), time.Now().Format(LayoutDate)),
  33. OutType: req.OutType,
  34. AuditStatus: pasturePb.AuditStatus_Pending,
  35. ApplicantId: int32(currentUser.Id),
  36. ApplicantName: currentUser.Name,
  37. ApplicantAt: time.Now().Unix(),
  38. ApplicantRemarks: req.ApplicantRemarks,
  39. }
  40. }
  41. type OutboundSlice []*Outbound
  42. func (o OutboundSlice) ToPB(outTypeMap map[pasturePb.OutType_Kind]string, auditStatusMap map[pasturePb.AuditStatus_Kind]string) []*pasturePb.OutboundApplyDetail {
  43. res := make([]*pasturePb.OutboundApplyDetail, len(o))
  44. for i, v := range o {
  45. applicantAtFormat, examineAtFormat, outTypeName, auditStatusName := "", "", "", ""
  46. if v.ApplicantAt > 0 {
  47. applicantAtFormat = time.Unix(v.ApplicantAt, 0).Format(LayoutTime)
  48. }
  49. if v.ExamineAt > 0 {
  50. examineAtFormat = time.Unix(v.ExamineAt, 0).Format(LayoutTime)
  51. }
  52. if outType, ok := outTypeMap[v.OutType]; ok {
  53. outTypeName = outType
  54. }
  55. if auditStatus, ok := auditStatusMap[v.AuditStatus]; ok {
  56. auditStatusName = auditStatus
  57. }
  58. res[i] = &pasturePb.OutboundApplyDetail{
  59. Id: int32(v.Id),
  60. Number: v.Number,
  61. OutType: v.OutType,
  62. OutTypeName: outTypeName,
  63. AuditStatus: v.AuditStatus,
  64. AuditStatusName: auditStatusName,
  65. ApplicantName: v.ApplicantName,
  66. ApplicantRemarks: v.ApplicantRemarks,
  67. ExamineName: v.ExamineName,
  68. ExamineRemarks: v.ExamineRemarks,
  69. ApplicantAtFormat: applicantAtFormat,
  70. ExamineAtFormat: examineAtFormat,
  71. }
  72. }
  73. return res
  74. }