SJA APS后端代码
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.

142 lines
4.3 KiB

  1. package db
  2. import (
  3. "errors"
  4. "github.com/go-xorm/xorm"
  5. "leit.com/leit_seat_aps/common"
  6. "xorm.io/core"
  7. )
  8. //生产订单生产包装状态
  9. type Prod_wo_packstatus struct {
  10. Finr int `xorm:"pk" json:"prod_wo_packstatus.finr"`
  11. Workordernr string `xorm:"pk" json:"prod_wo_packstatus.workordernr"`
  12. Projnr string `json:"prod_wo_packstatus.projnr"`
  13. Packorderid string `json:"prod_wo_packstatus.packorderid"`
  14. Packstatus int `json:"prod_wo_packstatus.packstatus"`
  15. Status1 int `json:"prod_wo_packstatus.status1"`
  16. Status2 int `json:"prod_wo_packstatus.status2"`
  17. Lastmodif string `json:"prod_wo_packstatus.lastmodif"`
  18. Lastuser string `json:"prod_wo_packstatus.lastuser"`
  19. Credatuz string `json:"prod_wo_packstatus.credatuz"`
  20. }
  21. // 带生产包装状态的生产工单
  22. type VWorkOrderPackStatus struct {
  23. Pln_workorder `xorm:"extends"`
  24. Prod_wo_packstatus `xorm:"extends"`
  25. }
  26. func (t *Prod_wo_packstatus) Clipped() {
  27. common.TrimStruct(t, *t)
  28. }
  29. func (t *Prod_wo_packstatus) TableName() string {
  30. return "prod_wo_packstatus"
  31. }
  32. //增
  33. func (t *Prod_wo_packstatus) Add() error {
  34. e := G_DbEngine
  35. prodpakstatab := new(Prod_wo_packstatus)
  36. affw, err := e.Table("prod_wo_packstatus").ID(core.PK{G_FINR, t.Workordernr}).Count(prodpakstatab)
  37. if err != nil {
  38. return err
  39. }
  40. if affw > 0 {
  41. return errors.New("数据已经存在!")
  42. }
  43. _, err = e.Table("prod_wo_packstatus").Insert(t)
  44. if err != nil {
  45. return err
  46. }
  47. return nil
  48. }
  49. //增
  50. func (t *Prod_wo_packstatus) Insert(session *xorm.Session) error {
  51. prodpakstatab := new(Prod_wo_packstatus)
  52. affw, err := session.Table("prod_wo_packstatus").ID(core.PK{G_FINR, t.Workordernr}).Count(prodpakstatab)
  53. if err != nil {
  54. return err
  55. }
  56. if affw > 0 {
  57. return errors.New("数据已经存在!")
  58. }
  59. _, err = session.Table("prod_wo_packstatus").Insert(t)
  60. if err != nil {
  61. return err
  62. }
  63. return nil
  64. }
  65. //删
  66. func (t *Prod_wo_packstatus) Del() bool {
  67. e := G_DbEngine
  68. _, err := e.ID(core.PK{G_FINR, t.Workordernr}).Delete(&Prod_wo_packstatus{})
  69. if err != nil {
  70. return false
  71. }
  72. return true
  73. }
  74. //改
  75. func (t *Prod_wo_packstatus) Update() bool {
  76. e := G_DbEngine
  77. _, err := e.ID(core.PK{G_FINR, t.Workordernr}).Update(t)
  78. if err != nil {
  79. return false
  80. }
  81. return true
  82. }
  83. //改
  84. func (t *Prod_wo_packstatus) UpdateBySession(session *xorm.Session) bool {
  85. _, err := session.ID(core.PK{G_FINR, t.Workordernr}).Update(t)
  86. if err != nil {
  87. return false
  88. }
  89. return true
  90. }
  91. //更新指定字段
  92. func (t *Prod_wo_packstatus) UpdateFields(session *xorm.Session, fields string) (err error) {
  93. if _, err = session.Table("prod_wo_packstatus").ID(core.PK{G_FINR, t.Workordernr}).Cols(fields).Update(t); err != nil {
  94. return
  95. }
  96. return
  97. }
  98. //查
  99. func (t *Prod_wo_packstatus) SelectOne() (data Prod_wo_packstatus, err error) {
  100. e := G_DbEngine
  101. _, err = e.ID(core.PK{G_FINR, t.Workordernr}).Get(&data)
  102. if err != nil {
  103. return data, err
  104. }
  105. return data, nil
  106. }
  107. // 获取已下达未生产包装,类型为SEQ的生产订单
  108. func (t *Prod_wo_packstatus) GetUnpackedWOByStartOemseq(startseq int, endseq int) (datalist []VWorkOrderPackStatus, err error) {
  109. e := G_DbEngine
  110. datalist = make([]VWorkOrderPackStatus, 0)
  111. if endseq < startseq || endseq <= 0 {
  112. if err = e.Table("pln_workorder").Alias("wo").Join("INNER", []string{"prod_wo_packstatus", "pkostat"},
  113. "wo.finr = pkostat.finr and wo.workordernr = pkostat.workordernr and wo.projnr = pkostat.projnr").Where("wo.finr = ? and wo.ordertype = ? and wo.oemseq >= ? and wo.status >= ? and wo.status < ? and wo.shippable = ? and pkostat.packstatus = ?",
  114. G_FINR, common.WO_TYPE_SEQ, startseq, common.WO_STATUS_RELEASED, common.WO_STATUS_CLOSED, 1, common.MESWO_UNPACK_STATUS).OrderBy("wo.oemseq, wo.worklineid").Find(&datalist); err != nil {
  115. return
  116. }
  117. }else{
  118. if err = e.Table("pln_workorder").Alias("wo").Join("INNER", []string{"prod_wo_packstatus", "pkostat"},
  119. "wo.finr = pkostat.finr and wo.workordernr = pkostat.workordernr and wo.projnr = pkostat.projnr").Where("wo.finr = ? and wo.ordertype = ? and wo.oemseq >= ? and wo.oemseq <= ? and wo.status >= ? and wo.status < ? and wo.shippable = ? and pkostat.packstatus = ?",
  120. G_FINR, common.WO_TYPE_SEQ, startseq, endseq, common.WO_STATUS_RELEASED, common.WO_STATUS_CLOSED, 1, common.MESWO_UNPACK_STATUS).OrderBy("wo.oemseq, wo.worklineid").Find(&datalist); err != nil {
  121. return
  122. }
  123. }
  124. return
  125. }