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.

101 lines
3.3 KiB

4 years ago
  1. package models
  2. import (
  3. "leit.com/LAPP_GAAS_GFrame/db"
  4. "leit.com/LAPP_GAAS_GFrame/utils"
  5. "errors"
  6. "xorm.io/core"
  7. )
  8. type WorklineSpecialday struct {
  9. Finr int `xorm:"pk comment('工厂号') Int" json:"workline_specialday-finr"`
  10. Worklineid string `xorm:"pk comment('产线ID') VARCHAR(20)" json:"workline_specialday-worklineid"`
  11. Specialday string `xorm:"pk comment('指定日期') VARCHAR(8)" json:"workline_specialday-specialday"`
  12. Daymodelid string `xorm:"comment('日模型ID') Int" json:"workline_specialday-daymodelid"`
  13. Descr string `xorm:"comment('描述') VARCHAR(30)" json:"workline_specialday-descr"`
  14. Lastmodif string `xorm:"comment('最近一次更改时间') VARCHAR(14)" json:"workline_specialday-lastmodif"`
  15. Lastuser string `xorm:"comment('最近一次更改人') VARCHAR(20)" json:"workline_specialday-lastuser"`
  16. Credatuz string `xorm:"comment('创建时间') VARCHAR(14)" json:"workline_specialday-credatuz"`
  17. }
  18. func (t *WorklineSpecialday) TableName() string {
  19. return "workline_specialday"
  20. }
  21. // 清除string字段的右侧空格
  22. func (t *WorklineSpecialday) Clipped() {
  23. utils.TrimStruct(t, *t)
  24. }
  25. //增
  26. func (t *WorklineSpecialday) Add() error {
  27. e := db.Eloquent.Master()
  28. countrole := new(WorklineSpecialday)
  29. affw, err := e.Table("workline_specialday").ID(core.PK{t.Finr, t.Worklineid, t.Specialday}).Count(countrole)
  30. if err != nil {
  31. return err
  32. }
  33. if affw > 0 {
  34. return errors.New("数据已经存在!")
  35. }
  36. _, err = e.Table("workline_specialday").Insert(t)
  37. if err != nil {
  38. return err
  39. }
  40. return nil
  41. }
  42. //删
  43. func (t *WorklineSpecialday) Del() bool {
  44. e := db.Eloquent.Master()
  45. _, err := e.ID(core.PK{t.Finr, t.Worklineid, t.Specialday}).Delete(&WorklineSpecialday{})
  46. if err != nil {
  47. return false
  48. }
  49. return true
  50. }
  51. //改
  52. func (t *WorklineSpecialday) Update() bool {
  53. e := db.Eloquent.Master()
  54. _, err := e.ID(core.PK{t.Finr, t.Worklineid, t.Specialday}).Update(t)
  55. if err != nil {
  56. return false
  57. }
  58. return true
  59. }
  60. //查
  61. func (t *WorklineSpecialday) SelectOne() (WorklineSpecialday, error) {
  62. e := db.Eloquent.Master()
  63. var data WorklineSpecialday
  64. _, err := e.ID(core.PK{t.Finr, t.Worklineid, t.Specialday}).Get(&data)
  65. if err != nil {
  66. return data, err
  67. }
  68. return data, nil
  69. }
  70. //分页
  71. func (t *WorklineSpecialday) GetPage(pageSize int, pageIndex int) ([]WorklineSpecialday, int, error) {
  72. data := make([]WorklineSpecialday, 0)
  73. e := db.Eloquent.Master()
  74. table := e.Table("workline_specialday").Where("finr = ? ", t.Finr)
  75. where := "where finr = " + "'" + utils.ValueToString(t.Finr, "") + "'"
  76. if !utils.ValueIsEmpty(t.Worklineid) {
  77. table = table.And("worklineid = ?", t.Worklineid)
  78. where += " and worklineid = " + "'" + t.Worklineid + "'"
  79. }
  80. Offset := (pageIndex - 1) * pageSize
  81. err := e.SQL("SELECT TOP " + utils.ValueToString(pageSize, "") + " workline_specialday.* FROM workline_specialday " + where + " AND (convert(varchar(10),finr)+convert(varchar(40),worklineid)+convert(varchar(40),specialday) NOT IN (SELECT TOP " + utils.ValueToString(Offset, "") + " convert(varchar(10),finr)+convert(varchar(40),worklineid)+convert(varchar(40),specialday) FROM workline_specialday " + where + " ORDER BY credatuz DESC)) ORDER BY credatuz DESC").Find(&data)
  82. pcount := new(WorklineSpecialday)
  83. count, err := table.Count(pcount)
  84. if err != nil {
  85. return data, 0, err
  86. }
  87. for k, _ := range data {
  88. data[k].Clipped()
  89. }
  90. return data, int(count), nil
  91. }