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

202 lines
6.4 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
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. "leit.com/aps_engine/grmi"
  7. "xorm.io/core"
  8. )
  9. type WorkShift struct {
  10. PlantNr int `xorm:"pk int 'PlantNr'" json:"WorkShift-PlantNr"`
  11. WorkShiftNr int `xorm:"pk int 'WorkShiftNr' autoincr" json:"WorkShift-WorkShiftNr"`
  12. Descr string `xorm:"nvarchar(100) 'Descr'" json:"WorkShift-Descr"`
  13. Abrev string `xorm:"nvarchar(10) 'Abrev' not null" json:"WorkShift-Abrev"`
  14. HexColor string `xorm:"nvarchar(10) 'HexColor'" json:"WorkShift-HexColor"`
  15. PlanPersonQty int `xorm:"int 'PlanPersonQty'" json:"WorkShift-PlanPersonQty"`
  16. PlanEfficiency float64 `xorm:"float 'PlanEfficiency' not null" json:"WorkShift-PlanEfficiency"`
  17. SBeg int `xorm:"int 'S_Beg'" json:"WorkShift-S_Beg"`
  18. SEnd int `xorm:"int 'S_End'" json:"WorkShift-S_End"`
  19. SLen int `xorm:"int 'S_Len'" json:"WorkShift-S_Len"`
  20. SB1Beg int `xorm:"int 'S_B1_Beg'" json:"WorkShift-S_B1_Beg"`
  21. SB1End int `xorm:"int 'S_B1_End'" json:"WorkShift-S_B1_End"`
  22. SB2Beg int `xorm:"int 'S_B2_Beg'" json:"WorkShift-S_B2_Beg"`
  23. SB2End int `xorm:"int 'S_B2_End'" json:"WorkShift-S_B2_End"`
  24. SB3Beg int `xorm:"int 'S_B3_Beg'" json:"WorkShift-S_B3_Beg"`
  25. SB3End int `xorm:"int 'S_B3_End'" json:"WorkShift-S_B3_End"`
  26. SB4Beg int `xorm:"int 'S_B4_Beg'" json:"WorkShift-S_B4_Beg"`
  27. SB4End int `xorm:"int 'S_B4_End'" json:"WorkShift-S_B4_End"`
  28. SB5Beg int `xorm:"int 'S_B5_Beg'" json:"WorkShift-S_B5_Beg"`
  29. SB5End int `xorm:"int 'S_B5_End'" json:"WorkShift-S_B5_End"`
  30. LastModify grmi.DateTime `xorm:"datetime 'LastModify' not null updated" json:"WorkShift-LastModify"`
  31. LastUser string `xorm:"nvarchar(20) 'LastUser' not null" json:"WorkShift-LastUser"`
  32. CreateTime grmi.DateTime `xorm:"datetime 'CreateTime' not null created" json:"WorkShift-CreateTime"`
  33. WorkShiftEffLst []WorkShiftEffLst `xorm:"-" json:"WorkShift-WorkShiftEffLst"`
  34. }
  35. /******数据表名******/
  36. func (t *WorkShift) TableName() string {
  37. return "Workshift"
  38. }
  39. /******************************************************************************
  40. *
  41. * @Function Name : GetKey
  42. *-----------------------------------------------------------------------------
  43. *
  44. * @Description : 获取实体的主键
  45. *
  46. * @Return Value : 实体的主键
  47. *
  48. * @Author : 代码生成器创建
  49. *
  50. * @Date : 2021-03-23 17:06:57
  51. *
  52. ******************************************************************************/
  53. func (self *WorkShift) GetKey() core.PK {
  54. return core.PK{self.PlantNr, self.WorkShiftNr}
  55. }
  56. /******************************************************************************
  57. *
  58. * @Function Name :
  59. *-----------------------------------------------------------------------------
  60. *
  61. * @Description : 数据添加
  62. *
  63. * @Function Parameters:
  64. *
  65. * @Return Value :
  66. *
  67. * @Author : Lou Wenzhi
  68. *
  69. * @Date : 2021/3/6 8:47
  70. *
  71. ******************************************************************************/
  72. func (t *WorkShift) Add() error {
  73. e := db.Eloquent.Master()
  74. count := new(WorkShift)
  75. affw, err := e.Table(t.TableName()).ID(t.GetKey()).Count(count)
  76. if err != nil {
  77. return err
  78. }
  79. if affw > 0 {
  80. return errors.New("数据已经存在!")
  81. }
  82. _, err = e.Table(t.TableName()).Insert(t)
  83. if err != nil {
  84. return err
  85. }
  86. return nil
  87. }
  88. /******************************************************************************
  89. *
  90. * @Function Name :
  91. *-----------------------------------------------------------------------------
  92. *
  93. * @Description : 数据删除
  94. *
  95. * @Function Parameters:
  96. *
  97. * @Return Value :
  98. *
  99. * @Author : Lou Wenzhi
  100. *
  101. * @Date : 2021/3/6 8:47
  102. *
  103. ******************************************************************************/
  104. func (t *WorkShift) Del() bool {
  105. e := db.Eloquent.Master()
  106. _, err := e.ID(t.GetKey()).Delete(&WorkShift{})
  107. if err != nil {
  108. return false
  109. }
  110. return true
  111. }
  112. /******************************************************************************
  113. *
  114. * @Function Name :
  115. *-----------------------------------------------------------------------------
  116. *
  117. * @Description : 数据修改
  118. *
  119. * @Function Parameters:
  120. *
  121. * @Return Value :
  122. *
  123. * @Author : Lou Wenzhi
  124. *
  125. * @Date : 2021/3/6 8:47
  126. *
  127. ******************************************************************************/
  128. func (t *WorkShift) Update() error {
  129. e := db.Eloquent.Master()
  130. _, err := e.ID(t.GetKey()).Update(t)
  131. if err != nil {
  132. return err
  133. }
  134. return nil
  135. }
  136. /******************************************************************************
  137. *
  138. * @Function Name :
  139. *-----------------------------------------------------------------------------
  140. *
  141. * @Description : 数据查找
  142. *
  143. * @Function Parameters:
  144. *
  145. * @Return Value :
  146. *
  147. * @Author : Lou Wenzhi
  148. *
  149. * @Date : 2021/3/6 8:47
  150. *
  151. ******************************************************************************/
  152. func (t *WorkShift) SelectOne() (WorkShift, error) {
  153. e := db.Eloquent.Master()
  154. var data WorkShift
  155. _, err := e.ID(t.GetKey()).Get(&data)
  156. if err != nil {
  157. return data, err
  158. }
  159. return data, nil
  160. }
  161. /******************************************************************************
  162. *
  163. * @Function Name :
  164. *-----------------------------------------------------------------------------
  165. *
  166. * @Description : 数据查找
  167. *
  168. * @Function Parameters:
  169. *
  170. * @Return Value :
  171. *
  172. * @Author : Lou Wenzhi
  173. *
  174. * @Date : 2021/3/6 8:47
  175. *
  176. ******************************************************************************/
  177. func (t *WorkShift) SelectAll() (datalst []WorkShift, err error) {
  178. var i int
  179. e := db.Eloquent.Master()
  180. if err = e.Table(t.TableName()).Where("PlantNr = ?",t.PlantNr).OrderBy("WorkShiftNr").Find(&datalst);err != nil {
  181. return
  182. }
  183. for i = 0; i < len(datalst); i++ {
  184. if err = e.Table("Workshiftefflst").Where("PlantNr = ? and WorkShiftNr = ?", datalst[i].PlantNr,
  185. datalst[i].WorkShiftNr).OrderBy("LevelId").Find(&datalst[i].WorkShiftEffLst); err != nil {
  186. return
  187. }
  188. }
  189. return
  190. }