第二代基于事件的高级计划排程引擎
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.

179 lines
5.0 KiB

3 years ago
3 years ago
3 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/aps_engine/db"
  6. "time"
  7. "xorm.io/core"
  8. )
  9. type Workplacegrp struct {
  10. Plantnr int `json:"PlantNr" xorm:"not null pk INT(4)"`
  11. Workplacegrpnr int `json:"WorkPlaceGrpNr" xorm:"not null pk INT(4)"`
  12. Workplacegrpid string `json:"WorkPlaceGrpId" xorm:"not null NVARCHAR(80)"`
  13. Descr string `json:"Descr" xorm:"not null NVARCHAR(200)"`
  14. Workplacetype string `json:"WorkPlaceType" xorm:"not null NVARCHAR(80)"`
  15. Capacitytype string `json:"CapacityType" xorm:"not null NVARCHAR(80)"`
  16. Capacityfactor float32 `json:"CapacityFactor" xorm:"not null FLOAT(8)"`
  17. Planefficiency float32 `json:"PlanEfficiency" xorm:"not null FLOAT(8)"`
  18. Costrate float32 `json:"CostRate" xorm:"not null FLOAT(8)"`
  19. Weekmodelnr int `json:"WeekModelNr" xorm:"not null INT(4)"`
  20. Workcalendarnr int `json:"WorkCalendarNr" xorm:"not null INT(4)"`
  21. Costcenterid string `json:"CostCenterId" xorm:"not null NVARCHAR(80)"`
  22. Locationid string `json:"LocationId" xorm:"not null NVARCHAR(80)"`
  23. Lastmodify time.Time `json:"LastModify" xorm:"DATETIME(8)"`
  24. Lastuser string `json:"LastUser" xorm:"not null NVARCHAR(40)"`
  25. Createtime time.Time `json:"CreateTime" xorm:"DATETIME(8)"`
  26. }
  27. /******数据表名******/
  28. func (t *Workplacegrp) TableName() string {
  29. return "Workplacegrp"
  30. }
  31. /******************************************************************************
  32. *
  33. * @Function Name :
  34. *-----------------------------------------------------------------------------
  35. *
  36. * @Description : 数据添加
  37. *
  38. * @Function Parameters:
  39. *
  40. * @Return Value :
  41. *
  42. * @Author : Lou Wenzhi
  43. *
  44. * @Date : 2021/3/6 8:47
  45. *
  46. ******************************************************************************/
  47. func (t *Workplacegrp) Add() error {
  48. e := db.Eloquent.Master()
  49. count := new(Workplacegrp)
  50. /**主键:****/
  51. /******/
  52. affw, err := e.Table(t.TableName()).ID(core.PK{t.Plantnr, t.Workplacegrpnr}).Count(count)
  53. if err != nil {
  54. return err
  55. }
  56. if affw > 0 {
  57. return errors.New("数据已经存在!")
  58. }
  59. _, err = e.Table(t.TableName()).Insert(t)
  60. if err != nil {
  61. return err
  62. }
  63. return nil
  64. }
  65. /******************************************************************************
  66. *
  67. * @Function Name :
  68. *-----------------------------------------------------------------------------
  69. *
  70. * @Description : 数据删除
  71. *
  72. * @Function Parameters:
  73. *
  74. * @Return Value :
  75. *
  76. * @Author : Lou Wenzhi
  77. *
  78. * @Date : 2021/3/6 8:47
  79. *
  80. ******************************************************************************/
  81. func (t *Workplacegrp) Del() (err error) {
  82. e := db.Eloquent.Master()
  83. /**主键:****/
  84. /******/
  85. _, err = e.ID(core.PK{t.Plantnr, t.Workplacegrpnr}).Delete(&Workplacegrp{})
  86. if err != nil {
  87. return
  88. }
  89. return nil
  90. }
  91. /******************************************************************************
  92. *
  93. * @Function Name :
  94. *-----------------------------------------------------------------------------
  95. *
  96. * @Description : 数据修改
  97. *
  98. * @Function Parameters:
  99. *
  100. * @Return Value :
  101. *
  102. * @Author : Lou Wenzhi
  103. *
  104. * @Date : 2021/3/6 8:47
  105. *
  106. ******************************************************************************/
  107. func (t *Workplacegrp) Update() error {
  108. e := db.Eloquent.Master()
  109. /**主键:****/
  110. /******/
  111. _, err := e.ID(core.PK{t.Plantnr, t.Workplacegrpnr}).Update(t)
  112. if err != nil {
  113. return err
  114. }
  115. return nil
  116. }
  117. /******************************************************************************
  118. *
  119. * @Function Name :
  120. *-----------------------------------------------------------------------------
  121. *
  122. * @Description : 数据查找
  123. *
  124. * @Function Parameters:
  125. *
  126. * @Return Value :
  127. *
  128. * @Author : Lou Wenzhi
  129. *
  130. * @Date : 2021/3/6 8:47
  131. *
  132. ******************************************************************************/
  133. func (t *Workplacegrp) SelectOne() (Workplacegrp, error) {
  134. e := db.Eloquent.Master()
  135. var data Workplacegrp
  136. /**主键:****/
  137. /******/
  138. _, err := e.ID(core.PK{t.Plantnr, t.Workplacegrpnr}).Get(&data)
  139. if err != nil {
  140. return data, err
  141. }
  142. return data, nil
  143. }
  144. /******************************************************************************
  145. *
  146. * @Function Name :
  147. *-----------------------------------------------------------------------------
  148. *
  149. * @Description : 查找所有的工位组
  150. *
  151. * @Function Parameters:
  152. *
  153. * @Return Value :
  154. *
  155. * @Author : LEO XUE
  156. *
  157. * @Date : 2021/3/6 8:47
  158. *
  159. ******************************************************************************/
  160. func (t *Workplacegrp) SelectAll() (datalst []Workplacegrp, err error) {
  161. e := db.Eloquent.Master()
  162. if err = e.Table(t.TableName()).Where("PlantNr = ?",t.Plantnr).OrderBy("WorkPlaceGrpNr").Find(&datalst); err != nil{
  163. return
  164. }
  165. return
  166. }