SJA工艺
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.

135 lines
4.8 KiB

3 years ago
  1. package models
  2. import (
  3. "LAPP_SJA_ME/db"
  4. "LAPP_SJA_ME/utils"
  5. "xorm.io/core"
  6. "errors"
  7. )
  8. //生产线
  9. type Workline struct {
  10. Finr int `xorm:"pk comment('工厂号') Int" json:"workline-finr"`
  11. Worklineid string `xorm:"pk comment('生产线ID') VARCHAR(20)" json:"workline-worklineid"`
  12. Descr string `xorm:"comment('描述1') VARCHAR(40)" json:"workline-descr"`
  13. Linetype string `xorm:"comment('产线类型') VARCHAR(1)" json:"workline-linetype"`
  14. Lineplanmode string `xorm:"comment('产线计划模块') VARCHAR(3)" json:"workline-lineplanmode"`
  15. Weekmodelid int `xorm:"comment('周模块ID') Int" json:"workline-weekmodelid"`
  16. Workcalendarid int `xorm:"comment('工作日历') Int" json:"workline-workcalendarid"`
  17. Location string `xorm:"comment('位置') VARCHAR(40)" json:"workline-location"`
  18. Costcenterid string `xorm:"comment('成本中心') VARCHAR(40)" json:"workline-costcenterid"`
  19. Costrate float64 `xorm:"comment('成本费率') Double" json:"workline-costrate"`
  20. Prodeff float64 `xorm:"comment('生产效率') Double" json:"workline-prodeff"`
  21. Reqworkers int `xorm:"comment('定额人数') Int" json:"workline-reqworkers"`
  22. Pos int `xorm:"comment('位置') Int" json:"workline-pos"`
  23. Releaseparameter int `xorm:"comment('下达参数') Int" json:"workline-releaseparameter"`
  24. Multiqueuemixsort int `xorm:"comment('混线排序逻辑') Int" json:"workline-multiqueuemixsort"`
  25. Taskqueuesortway string `xorm:"comment('任务队列排序方式') VARCHAR(14)" json:"workline-taskqueuesortway"`
  26. Taskqueuemixsortway string `xorm:"comment('混线排序方式') VARCHAR(14)" json:"workline-taskqueuemixsortway"`
  27. Mixsortlogic string `xorm:"comment('混线排序逻辑') VARCHAR(14)" json:"workline-mixsortlogic"`
  28. Taskreleaseway string `xorm:"comment('任务下达方式') VARCHAR(14)" json:"workline-taskreleaseway"`
  29. Lastmodif string `xorm:"comment('最近一次更改时间') VARCHAR(14)" json:"workline-lastmodif"`
  30. Lastuser string `xorm:"comment('最近一次更改人') VARCHAR(20)" json:"workline-lastuser"`
  31. Credatuz string `xorm:"comment('创建时间') VARCHAR(14)" json:"workline-credatuz"`
  32. }
  33. func (t *Workline) TableName() string {
  34. return "workline"
  35. }
  36. // 清除string字段的右侧空格
  37. func (t *Workline) Clipped() {
  38. utils.TrimStruct(t, *t)
  39. }
  40. //增
  41. func (t *Workline) Add() error {
  42. e := db.Eloquent.Master()
  43. countrole := new(Workline)
  44. affw, err := e.Table("workline").ID(core.PK{t.Finr, t.Worklineid}).Count(countrole)
  45. if err != nil {
  46. return err
  47. }
  48. if affw > 0 {
  49. return errors.New("数据已经存在!")
  50. }
  51. _, err = e.Table("workline").Insert(t)
  52. if err != nil {
  53. return err
  54. }
  55. return nil
  56. }
  57. //删
  58. func (t *Workline) Del() bool {
  59. e := db.Eloquent.Master()
  60. _, err := e.ID(core.PK{t.Finr, t.Worklineid}).Delete(&Workline{})
  61. if err != nil {
  62. return false
  63. }
  64. return true
  65. }
  66. //改
  67. func (t *Workline) Update() bool {
  68. e := db.Eloquent.Master()
  69. _, err := e.ID(core.PK{t.Finr, t.Worklineid}).Update(t)
  70. if err != nil {
  71. return false
  72. }
  73. return true
  74. }
  75. //查
  76. func (t *Workline) SelectOne() (Workline, error) {
  77. e := db.Eloquent.Master()
  78. var data Workline
  79. _, err := e.ID(core.PK{t.Finr, t.Worklineid}).Get(&data)
  80. if err != nil {
  81. return data, err
  82. }
  83. return data, nil
  84. }
  85. //分页
  86. func (t *Workline) GetPage(pageSize int, pageIndex int) ([]Workline, int, error) {
  87. data := make([]Workline, 0)
  88. e := db.Eloquent.Master()
  89. table := e.Table("workline").Where("finr = ? ", t.Finr)
  90. where := "where finr = " + "'" + utils.ValueToString(t.Finr, "") + "'"
  91. if !utils.ValueIsEmpty(t.Worklineid) {
  92. table = table.And("worklineid = ?", t.Worklineid)
  93. where += " and worklineid = " + "'" + t.Worklineid + "'"
  94. }
  95. if !utils.ValueIsEmpty(t.Linetype) {
  96. table = table.And("linetype = ?", t.Linetype)
  97. where += " and linetype = " + "'" + t.Linetype + "'"
  98. }
  99. Offset := (pageIndex - 1) * pageSize
  100. err := e.SQL("SELECT TOP " + utils.ValueToString(pageSize, "") + " workline.* FROM workline " + where + " AND (convert(varchar(10),finr)+convert(varchar(40),worklineid) NOT IN (SELECT TOP " + utils.ValueToString(Offset, "") + " convert(varchar(10),finr)+convert(varchar(40),worklineid) FROM workline " + where + " ORDER BY credatuz DESC)) ORDER BY credatuz DESC").Find(&data)
  101. pcount := new(Workline)
  102. count, err := table.Count(pcount)
  103. if err != nil {
  104. return data, 0, err
  105. }
  106. for k, _ := range data {
  107. data[k].Clipped()
  108. }
  109. return data, int(count), nil
  110. }
  111. //查询当前worklineids集合
  112. func (t *Workline) SelectArr() (arr []string, err error) {
  113. e := db.Eloquent.Master()
  114. var data []Workline
  115. err = e.Where("finr = ? ", t.Finr).Cols("worklineid").Find(&data)
  116. for _, v := range data {
  117. v.Clipped()
  118. arr = append(arr, v.Worklineid)
  119. }
  120. if err != nil {
  121. return arr, err
  122. }
  123. return arr, nil
  124. }