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

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