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.

113 lines
2.7 KiB

3 years ago
  1. package db
  2. import (
  3. "github.com/go-xorm/xorm"
  4. "github.com/pkg/errors"
  5. "leit.com/leit_seat_aps/common"
  6. "xorm.io/core"
  7. )
  8. // EDI控制表
  9. type Edi_control struct {
  10. Finr int `xorm:"pk" json:"edi_control.finr"`
  11. Projectid string `xorm:"pk" json:"edi_control.projectid"`
  12. Ediid string `xorm:"pk" json:"edi_control.ediid"`
  13. Descr string `json:"edi_control.descr"`
  14. Enabled int `json:"edi_control.enabled"`
  15. Ctrlpara1 int `json:"edi_control.ctrlpara1"`
  16. Ctrlpara2 int `json:"edi_control.ctrlpara2"`
  17. Lastmodif string `json:"edi_control.lastmodif"`
  18. Lastuser string `json:"edi_control.lastuser"`
  19. Credatuz string `json:"edi_control.credatuz"`
  20. }
  21. func (t *Edi_control) Clipped() {
  22. common.TrimStruct(t, *t)
  23. }
  24. func (t *Edi_control) TableName() string {
  25. return "edi_control"
  26. }
  27. //增
  28. func (t *Edi_control) Add() (err error) {
  29. var (
  30. affw int64
  31. editab Edi_control
  32. )
  33. e := G_DbEngine
  34. editab = Edi_control{}
  35. affw, err = e.Table("edi_control").ID(core.PK{G_FINR, t.Projectid, t.Ediid}).Count(editab)
  36. if err != nil {
  37. return err
  38. }
  39. if affw > 0 {
  40. return errors.New("数据已经存在!")
  41. }
  42. _, err = e.Table("edi_control").Insert(t)
  43. if err != nil {
  44. return err
  45. }
  46. return nil
  47. }
  48. //增
  49. func (t *Edi_control) Insert(session *xorm.Session) (err error) {
  50. var (
  51. affw int64
  52. editab Edi_control
  53. )
  54. editab = Edi_control{}
  55. affw, err = session.Table("edi_control").ID(core.PK{G_FINR, t.Projectid, t.Ediid}).Count(editab)
  56. if err != nil {
  57. return err
  58. }
  59. if affw > 0 {
  60. return errors.New("数据已经存在!")
  61. }
  62. _, err = session.Table("edi_control").Insert(t)
  63. if err != nil {
  64. return err
  65. }
  66. return nil
  67. }
  68. //删
  69. func (t *Edi_control) Del() bool {
  70. e := G_DbEngine
  71. _, err := e.ID(core.PK{G_FINR, t.Projectid, t.Ediid}).Delete(&Edi_control{})
  72. if err != nil {
  73. return false
  74. }
  75. return true
  76. }
  77. //改
  78. func (t *Edi_control) Update() bool {
  79. e := G_DbEngine
  80. _, err := e.ID(core.PK{G_FINR, t.Projectid, t.Ediid}).Update(t)
  81. if err != nil {
  82. return false
  83. }
  84. return true
  85. }
  86. //更新指定字段
  87. func (t *Edi_control) UpdateFields(session *xorm.Session, fields string) (err error) {
  88. if _, err = session.Table("edi_control").ID(core.PK{G_FINR, t.Projectid, t.Ediid}).Cols(fields).Update(t); err != nil {
  89. return
  90. }
  91. return
  92. }
  93. //查
  94. func (t *Edi_control) SelectOne() (data Edi_control, err error) {
  95. e := G_DbEngine
  96. _, err = e.ID(core.PK{G_FINR, t.Projectid, t.Ediid}).Get(&data)
  97. if err != nil {
  98. return data, err
  99. }
  100. return data, nil
  101. }