outbound.go 3.0 KB

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