You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

148 lines
4.1 KiB

4 years ago
  1. // Copyright (c) Shenyang Leading Edge Intelligent Technology Co., Ltd. All rights reserved.
  2. package models
  3. import (
  4. "errors"
  5. "leit.com/LAPP_GAAS_GFrame/db"
  6. "time"
  7. "xorm.io/core"
  8. )
  9. type OmSerialorderstatus struct {
  10. Plantnr int `json:"PlantNr" xorm:"not null pk INT(4)"`
  11. Serialorderid string `json:"SerialOrderId" xorm:"not null pk NVARCHAR(40)"`
  12. Status int `json:"Status" xorm:"not null INT(4)"`
  13. Triggerevent string `json:"TriggerEvent" xorm:"not null NVARCHAR(40)"`
  14. Triggerobjectid string `json:"TriggerObjectId" xorm:"not null NVARCHAR(40)"`
  15. Triggersubobjectid string `json:"TriggerSubObjectId" xorm:"not null NVARCHAR(40)"`
  16. Lastmodify time.Time `json:"LastModify" xorm:"DATETIME(8)"`
  17. Lastuser string `json:"LastUser" xorm:"not null NVARCHAR(40)"`
  18. Createtime time.Time `json:"CreateTime" xorm:"DATETIME(8)"`
  19. Itemlst []OmSerialorderstatusrecLst `json:"itemlst" xorm:"-"`
  20. }
  21. /******数据表名******/
  22. func (t *OmSerialorderstatus) TableName() string {
  23. return "OmSerialOrderStatus"
  24. }
  25. /******************************************************************************
  26. *
  27. * @Function Name :
  28. *-----------------------------------------------------------------------------
  29. *
  30. * @Description : 数据添加
  31. *
  32. * @Function Parameters:
  33. *
  34. * @Return Value :
  35. *
  36. * @Author : Lou Wenzhi
  37. *
  38. * @Date : 2021/3/6 8:47
  39. *
  40. ******************************************************************************/
  41. func (t *OmSerialorderstatus) Add() error {
  42. e := db.Eloquent.Master()
  43. count := new(OmSerialorderstatus)
  44. /**主键:****/
  45. affw, err := e.Table(t.TableName()).ID(core.PK{t.Plantnr, t.Serialorderid}).Count(count)
  46. if err != nil {
  47. return err
  48. }
  49. if affw > 0 {
  50. return errors.New("数据已经存在!")
  51. }
  52. _, err = e.Table(t.TableName()).Insert(t)
  53. if err != nil {
  54. return err
  55. }
  56. return nil
  57. }
  58. /******************************************************************************
  59. *
  60. * @Function Name :
  61. *-----------------------------------------------------------------------------
  62. *
  63. * @Description : 数据删除
  64. *
  65. * @Function Parameters:
  66. *
  67. * @Return Value :
  68. *
  69. * @Author : Lou Wenzhi
  70. *
  71. * @Date : 2021/3/6 8:47
  72. *
  73. ******************************************************************************/
  74. func (t *OmSerialorderstatus) Del() error {
  75. e := db.Eloquent.Master()
  76. /**主键:****/
  77. _, err := e.ID(core.PK{t.Plantnr, t.Serialorderid}).Delete(&OmSerialorderstatus{})
  78. if err != nil {
  79. return errors.New("删除失败!")
  80. }
  81. // 删除该订单所有的状态记录
  82. return nil
  83. }
  84. /******************************************************************************
  85. *
  86. * @Function Name :
  87. *-----------------------------------------------------------------------------
  88. *
  89. * @Description : 数据修改
  90. *
  91. * @Function Parameters:
  92. *
  93. * @Return Value :
  94. *
  95. * @Author : Lou Wenzhi
  96. *
  97. * @Date : 2021/3/6 8:47
  98. *
  99. ******************************************************************************/
  100. func (t *OmSerialorderstatus) Update() error {
  101. e := db.Eloquent.Master()
  102. /**主键:****/
  103. _, err := e.ID(core.PK{t.Plantnr, t.Serialorderid}).Update(t)
  104. if err != nil {
  105. return err
  106. }
  107. return nil
  108. }
  109. /******************************************************************************
  110. *
  111. * @Function Name :
  112. *-----------------------------------------------------------------------------
  113. *
  114. * @Description : 数据查找
  115. *
  116. * @Function Parameters:
  117. *
  118. * @Return Value :
  119. *
  120. * @Author : Lou Wenzhi
  121. *
  122. * @Date : 2021/3/6 8:47
  123. *
  124. ******************************************************************************/
  125. func (t *OmSerialorderstatus) SelectOne() (data OmSerialorderstatus, err error) {
  126. e := db.Eloquent.Master()
  127. /**主键:****/
  128. _, err = e.ID(core.PK{t.Plantnr, t.Serialorderid}).Get(&data)
  129. if err != nil {
  130. return
  131. }
  132. // 获取值列表
  133. if err = e.Where("Plantnr = ? and SerialOrderId = ? ",
  134. t.Plantnr, t.Serialorderid).OrderBy("pos").Find(&data.Itemlst); err != nil {
  135. return
  136. }
  137. return
  138. }