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

278 lines
9.7 KiB

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/common"
  6. "leit.com/aps_engine/db"
  7. "time"
  8. "xorm.io/core"
  9. )
  10. type OmWorkorder struct {
  11. Plantnr int `json:"PlantNr" xorm:"not null pk INT(4)"`
  12. Workorderid string `json:"WorkOrderId" xorm:"not null pk NVARCHAR(80)"`
  13. Artid string `json:"ArtId" xorm:"not null NVARCHAR(80)"`
  14. Custartid string `json:"CustArtId" xorm:"not null NVARCHAR(80)"`
  15. Routetemplateid string `json:"RouteTemplateId" xorm:"not null NVARCHAR(80)"`
  16. Ordertype string `json:"OrderType" xorm:"not null NVARCHAR(40)"`
  17. Ordertype1 string `json:"OrderType1" xorm:"not null NVARCHAR(40)"`
  18. Ordertype2 string `json:"OrderType2" xorm:"not null NVARCHAR(40)"`
  19. Orderinfo string `json:"OrderInfo" xorm:"not null NVARCHAR(200)"`
  20. Custorderid string `json:"CustOrderId" xorm:"not null NVARCHAR(80)"`
  21. Erporderid string `json:"ErpOrderId" xorm:"not null NVARCHAR(80)"`
  22. Parentorderid string `json:"ParentOrderId" xorm:"not null NVARCHAR(80)"`
  23. Priority int `json:"Priority" xorm:"not null INT(4)"`
  24. Planresourcegroupid string `json:"PlanResourceGroupId" xorm:"not null NVARCHAR(80)"`
  25. Planresourceid string `json:"PlanResourceId" xorm:"not null NVARCHAR(80)"`
  26. Usedresourceid string `json:"UsedResourceId" xorm:"not null NVARCHAR(80)"`
  27. Planqty float32 `json:"PlanQty" xorm:"not null FLOAT(8)"`
  28. Qtyuomid string `json:"QtyUomId" xorm:"not null NVARCHAR(80)"`
  29. Rateperhourtoggle int `json:"RatePerHourToggle" xorm:"not null BIT(1)"`
  30. Timeperitemtoggle int `json:"TimePerItemToggle" xorm:"not null BIT(1)"`
  31. Timeperbatchtoggle int `json:"TimePerBatchToggle" xorm:"not null BIT(1)"`
  32. Batchtimefieldtoggle int `json:"BatchTimeFieldToggle" xorm:"not null BIT(1)"`
  33. Optimeperitem float32 `json:"OpTimePerItem" xorm:"FLOAT(8)"`
  34. Batchtime float32 `json:"BatchTime" xorm:"FLOAT(8)"`
  35. Quantityperhour float32 `json:"QuantityPerHour" xorm:"not null FLOAT(8)"`
  36. Batchquantity float32 `json:"BatchQuantity" xorm:"not null FLOAT(8)"`
  37. Timeuomid string `json:"TimeUomId" xorm:"not null NVARCHAR(80)"`
  38. Batchingmethod int `json:"BatchingMethod" xorm:"not null INT(4)"`
  39. Planstartdate time.Time `json:"PlanStartDate" xorm:"not null DATE(3)"`
  40. Planenddate time.Time `json:"PlanEndDate" xorm:"not null DATE(3)"`
  41. Setupstarttime time.Time `json:"SetupStartTime" xorm:"not null DATETIME(8)"`
  42. Setupendtime time.Time `json:"SetupEndTime" xorm:"not null DATETIME(8)"`
  43. Planstarttime time.Time `json:"PlanStartTime" xorm:"not null DATETIME(8)"`
  44. Planendtime time.Time `json:"PlanEndTime" xorm:"not null DATETIME(8)"`
  45. Actstarttime time.Time `json:"ActStartTime" xorm:"not null DATETIME(8)"`
  46. Actendtime time.Time `json:"ActEndTime" xorm:"not null DATETIME(8)"`
  47. Projectid string `json:"ProjectId" xorm:"not null NVARCHAR(80)"`
  48. Customerid string `json:"CustomerId" xorm:"not null NVARCHAR(80)"`
  49. Customername string `json:"CustomerName" xorm:"not null NVARCHAR(200)"`
  50. Lastmodify time.Time `json:"LastModify" xorm:"DATETIME(8)"`
  51. Lastuser string `json:"LastUser" xorm:"not null NVARCHAR(40)"`
  52. Createtime time.Time `json:"CreateTime" xorm:"DATETIME(8)"`
  53. Operationlst []OmWooperation `xorm:"-"`
  54. }
  55. // 客户订单和它的版本头综合视图
  56. type VWorkorder struct {
  57. OmWorkorder `xorm:"extends"`
  58. OmWorkorderstatus `xorm:"extends"`
  59. OmWorkorderqty `xorm:"extends"`
  60. }
  61. /******数据表名******/
  62. func (t *OmWorkorder) TableName() string {
  63. return "OmWorkorder"
  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 *OmWorkorder) Add() error {
  82. e := db.Eloquent.Master()
  83. count := new(OmWorkorder)
  84. /**主键:****/
  85. affw, err := e.Table(t.TableName()).ID(core.PK{t.Plantnr, t.Workorderid}).Count(count)
  86. if err != nil {
  87. return err
  88. }
  89. if affw > 0 {
  90. return errors.New("数据已经存在!")
  91. }
  92. _, err = e.Table(t.TableName()).Insert(t)
  93. if err != nil {
  94. return err
  95. }
  96. return nil
  97. }
  98. /******************************************************************************
  99. *
  100. * @Function Name :
  101. *-----------------------------------------------------------------------------
  102. *
  103. * @Description : 数据删除
  104. *
  105. * @Function Parameters:
  106. *
  107. * @Return Value :
  108. *
  109. * @Author : Lou Wenzhi
  110. *
  111. * @Date : 2021/3/6 8:47
  112. *
  113. ******************************************************************************/
  114. func (t *OmWorkorder) Del() (err error) {
  115. e := db.Eloquent.Master()
  116. _, err = e.ID(core.PK{t.Plantnr, t.Workorderid}).Delete(&OmWorkorder{})
  117. if err != nil {
  118. return
  119. }
  120. return nil
  121. }
  122. /******************************************************************************
  123. *
  124. * @Function Name :
  125. *-----------------------------------------------------------------------------
  126. *
  127. * @Description : 数据修改
  128. *
  129. * @Function Parameters:
  130. *
  131. * @Return Value :
  132. *
  133. * @Author : Lou Wenzhi
  134. *
  135. * @Date : 2021/3/6 8:47
  136. *
  137. ******************************************************************************/
  138. func (t *OmWorkorder) Update() error {
  139. e := db.Eloquent.Master()
  140. _, err := e.ID(core.PK{t.Plantnr, t.Workorderid}).Update(t)
  141. if err != nil {
  142. return err
  143. }
  144. return nil
  145. }
  146. /******************************************************************************
  147. *
  148. * @Function Name :
  149. *-----------------------------------------------------------------------------
  150. *
  151. * @Description : 数据查找
  152. *
  153. * @Function Parameters:
  154. *
  155. * @Return Value :
  156. *
  157. * @Author : Lou Wenzhi
  158. *
  159. * @Date : 2021/3/6 8:47
  160. *
  161. ******************************************************************************/
  162. func (t *OmWorkorder) SelectOne() (data OmWorkorder, err error) {
  163. e := db.Eloquent.Master()
  164. _, err = e.ID(core.PK{t.Plantnr, t.Workorderid}).Get(&data)
  165. if err != nil {
  166. return data, err
  167. }
  168. return data, nil
  169. }
  170. /******************************************************************************
  171. *
  172. * @Function Name :
  173. *-----------------------------------------------------------------------------
  174. *
  175. * @Description : 查找单个工单的完整数据
  176. *
  177. * @Function Parameters:
  178. *
  179. * @Return Value :
  180. *
  181. * @Author : LEO XUE
  182. *
  183. * @Date : 2021/3/6 8:47
  184. *
  185. ******************************************************************************/
  186. func (t *OmWorkorder) SelectOneFullData() (vdata VWorkorder, err error) {
  187. var (
  188. j int
  189. vdatalst []VWorkorder
  190. )
  191. e := db.Eloquent.Master()
  192. query := e.Table(t.TableName())
  193. query = query.Join("INNER", "OmWorkorderstatus", "OmWorkorder.PlantNr = OmWorkorderstatus.PlantNr and OmWorkorder.WorkOrderId = OmWorkorderstatus.WorkOrderId")
  194. query = query.Join("INNER", "OmWorkorderqty", "OmWorkorder.PlantNr = OmWorkorderqty.PlantNr and OmWorkorder.WorkOrderId = OmWorkorderqty.WorkOrderId")
  195. query = query.Where("OmWorkorder.PlantNr = ? and OmWorkorder.WorkOrderId = ?", t.Plantnr, t.Workorderid)
  196. if err = query.Find(&vdatalst); err != nil {
  197. return
  198. }
  199. if len(vdatalst) > 0 {
  200. vdata = vdatalst[0]
  201. }
  202. if err = e.Table("OmWooperation").Where("PlantNr = ? and WorkOrderId = ?",t.Plantnr,
  203. t.Workorderid).Asc("OperationNr", "SplitNr").Find(&vdata.OmWorkorder.Operationlst); err != nil{
  204. return
  205. }
  206. for j = 0; j < len(vdata.OmWorkorder.Operationlst); j++ {
  207. if vdata.OmWorkorder.Operationlst[j], err = vdata.OmWorkorder.Operationlst[j].SelectOne(); err != nil {
  208. return
  209. }
  210. }
  211. return
  212. }
  213. /******************************************************************************
  214. *
  215. * @Function Name :
  216. *-----------------------------------------------------------------------------
  217. *
  218. * @Description : 查找所有未完成的工单数据包括它的状态和数量数据
  219. *
  220. * @Function Parameters:
  221. *
  222. * @Return Value :
  223. *
  224. * @Author : LEO XUE
  225. *
  226. * @Date : 2021/5/10 8:47
  227. *
  228. ******************************************************************************/
  229. func (t *OmWorkorder) SelectAllUnfinishedFullData() (vdatalst []VWorkorder, err error) {
  230. var (
  231. i,j int
  232. )
  233. e := db.Eloquent.Master()
  234. query := e.Table(t.TableName())
  235. query = query.Join("INNER", "OmWorkorderstatus", "OmWorkorder.PlantNr = OmWorkorderstatus.PlantNr and OmWorkorder.WorkOrderId = OmWorkorderstatus.WorkOrderId")
  236. query = query.Join("INNER", "OmWorkorderqty", "OmWorkorder.PlantNr = OmWorkorderqty.PlantNr and OmWorkorder.WorkOrderId = OmWorkorderqty.WorkOrderId")
  237. query = query.Where("OmWorkorder.PlantNr = ? and OmWorkorder.status < ?", t.Plantnr, common.WO_STATUS_FINISHED).Desc("OmWorkorderstatus.Status", "OmWorkorder.PlanStartTime")
  238. if err = query.Find(&vdatalst); err != nil {
  239. return
  240. }
  241. // 获取订单工序数据
  242. for i = 0; i < len(vdatalst); i++ {
  243. if err = e.Table("OmWooperation").Where("PlantNr = ? and WorkOrderId = ?",t.Plantnr,
  244. t.Workorderid).Asc("OperationNr", "SplitNr").Find(&vdatalst[i].OmWorkorder.Operationlst); err != nil{
  245. return
  246. }
  247. for j = 0; j < len(vdatalst[i].OmWorkorder.Operationlst); j++ {
  248. if vdatalst[i].OmWorkorder.Operationlst[j], err = vdatalst[i].OmWorkorder.Operationlst[j].SelectOne(); err != nil {
  249. return
  250. }
  251. }
  252. }
  253. return
  254. }