work_process.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. package models
  2. import (
  3. "errors"
  4. "zhiyuan/pkg/db"
  5. "github.com/gin-gonic/gin"
  6. )
  7. type WorkProcess struct {
  8. ID int64 `json:"id" prop:"add:false"`
  9. NodeId int64 `json:"node_id" type:"int" prop:"add" search:"="`
  10. Name string `json:"name" label:"工序名称" type:"string" prop:"add edit" search:"like"`
  11. State int64 `json:"state" label:"状态" type:"int" prop:"edit" default:"0"`
  12. OrderAt int64 `json:"order_at" prop:"add:false select:false"`
  13. DeletedAt int64 `json:"deleted_at" prop:"add:false select:false"`
  14. CreatedAt int64 `json:"created_at" prop:"add:false select:false"`
  15. UpdatedAt int64 `json:"updated_at" prop:"add:false select:false"`
  16. Requires []WorkProcessRequire `json:"requires" prop:"ignore"`
  17. db.BaseModel
  18. }
  19. func (WorkProcess) TableName() string {
  20. return "zy_work_process"
  21. }
  22. func (WorkProcess) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
  23. return true
  24. }
  25. func (WorkProcess) OnePrivilege(c *gin.Context, id int64) bool {
  26. return true
  27. }
  28. func (WorkProcess) AddPrivilege(c *gin.Context, data map[string]interface{}, post map[string]interface{}) error {
  29. return nil
  30. }
  31. func (WorkProcess) EditPrivilege(c *gin.Context, id int64, data map[string]interface{}, post map[string]interface{}) error {
  32. return nil
  33. }
  34. func (WorkProcess) DelPrivilege(c *gin.Context, id int64) error {
  35. return nil
  36. }
  37. func (WorkProcess) OrderField() string {
  38. return "order_at"
  39. }
  40. func (WorkProcess) Page() bool {
  41. return false
  42. }
  43. func (WorkProcess) Count() bool {
  44. return true
  45. }
  46. func (a WorkProcess) GetOne(where map[string]interface{}, fields []string, retVal interface{}) (*WorkProcess, error) {
  47. if retVal == nil {
  48. var work_process *WorkProcess
  49. err := db.GetOne(a.TableName(), where, fields, &work_process)
  50. return work_process, err
  51. } else {
  52. err := db.GetOne(a.TableName(), where, fields, retVal)
  53. return nil, err
  54. }
  55. }
  56. func (a WorkProcess) GetMulti(where map[string]interface{}, fields []string, retVal interface{}) ([]*WorkProcess, error) {
  57. if retVal == nil {
  58. var work_process []*WorkProcess
  59. err := db.GetMulti(a.TableName(), where, fields, &work_process)
  60. return work_process, err
  61. } else {
  62. err := db.GetMulti(a.TableName(), where, fields, retVal)
  63. return nil, err
  64. }
  65. }
  66. func (a WorkProcess) GetOneRaw(where map[string]string, param map[string]interface{}, retVal interface{}) (*WorkProcess, error) {
  67. work_process, err := a.GetMultiRaw(where, param, retVal)
  68. if err != nil {
  69. return nil, err
  70. }
  71. if len(work_process) == 0 {
  72. return nil, errors.New("empty record2")
  73. }
  74. return work_process[0], nil
  75. }
  76. func (a WorkProcess) GetMultiRaw(where map[string]string, param map[string]interface{}, retVal interface{}) ([]*WorkProcess, error) {
  77. field := "SELECT * FROM zy_work_process "
  78. if retVal == nil {
  79. var work_process []*WorkProcess
  80. err := db.GetMultiRaw(field, where, param, &work_process)
  81. return work_process, err
  82. } else {
  83. err := db.GetMultiRaw(field, where, param, retVal)
  84. return nil, err
  85. }
  86. }
  87. func CopyWorkProcesss(processs []WorkProcess, node_id int64, order int64) error {
  88. for i, process := range processs {
  89. _, err := process.Copy(node_id, order+int64(len(processs)-i))
  90. if err != nil {
  91. return err
  92. }
  93. }
  94. return nil
  95. }
  96. func (model WorkProcess) Copy(node_id int64, order int64) (int64, error) {
  97. id, err := db.InsertModel(db.Type(model), map[string]interface{}{
  98. "node_id": node_id,
  99. "name": model.Name,
  100. "state": model.State,
  101. "order_at": order,
  102. })
  103. if err != nil {
  104. return 0, err
  105. }
  106. err = CopyWorkProcessRequires(model.Requires, id, order)
  107. if err != nil {
  108. return id, err
  109. }
  110. return id, nil
  111. }