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.

76 lines
2.7 KiB

  1. package models
  2. import (
  3. "LAPP_LF_MOM_BACKEND/db"
  4. "LAPP_LF_MOM_BACKEND/utils"
  5. "strings"
  6. )
  7. type PmWostatus struct {
  8. Finr int `json:"finr" xorm:"not null pk INT(4)"`
  9. Worecnr int `json:"worecnr" xorm:"not null pk INT(4)"`
  10. Maintwoid string `json:"maintwoid" xorm:"not null VARCHAR(18)"`
  11. Operator int `json:"operator" xorm:"not null INT(4)"`
  12. Wobagtype string `json:"wobagtype" xorm:"not null VARCHAR(14)"`
  13. Statusfrom int `json:"statusfrom" xorm:"not null INT(4)"`
  14. Statusto int `json:"statusto" xorm:"not null INT(4)"`
  15. Operatetime string `json:"operatetime" xorm:"not null VARCHAR(14)"`
  16. Lastmodif string `json:"lastmodif" xorm:"not null VARCHAR(14)"`
  17. Lastuser string `json:"lastuser" xorm:"not null VARCHAR(20)"`
  18. Credatuz string `json:"credatuz" xorm:"not null VARCHAR(14)"`
  19. }
  20. func (t *PmWostatus) TableName() string {
  21. return "pm_wostatus"
  22. }
  23. func (t *PmWostatus) Add() error {
  24. e := db.Eloquent.Master()
  25. _, err := e.Table("pm_wostatus").Insert(t)
  26. if err != nil {
  27. return err
  28. }
  29. return nil
  30. }
  31. //按维护工单调度ID查询日志
  32. func (t *PmWostatus) SelectAllByID() ([]PmWostatus, error) {
  33. e := db.Eloquent.Master()
  34. data := make([]PmWostatus, 0)
  35. err := e.Table("pm_wostatus").Where("finr = ? and maintwoid = ?", t.Finr, t.Maintwoid).Find(&data)
  36. if err != nil {
  37. return data, err
  38. }
  39. return data, nil
  40. }
  41. //分页
  42. func (t *PmWostatus) GetPage(pageSize int, pageIndex int, searchtime string) ([]PmWostatus, int, error) {
  43. data := make([]PmWostatus, 0)
  44. e := db.Eloquent.Master()
  45. table := e.Table("pm_wostatus").Where("finr = ? ", t.Finr)
  46. where := "where finr = " + "'" + utils.ValueToString(t.Finr, "") + "'"
  47. if !utils.ValueIsEmpty(searchtime) {
  48. searchtimes := strings.Split(searchtime, "-")
  49. table = table.And("operatetime >= ?", searchtimes[0])
  50. table = table.And("operatetime <= ?", searchtimes[1])
  51. where += " and operatetime >= " + "'" + utils.ValueToString(searchtimes[0], "") + "'"
  52. where += " and operatetime <= " + "'" + utils.ValueToString(searchtimes[1], "") + "'"
  53. }
  54. if !utils.ValueIsEmpty(t.Maintwoid) {
  55. table = table.And("maintwoid = ?", t.Maintwoid)
  56. where += " and maintwoid = " + "'" + utils.ValueToString(t.Maintwoid, "") + "'"
  57. }
  58. Offset := (pageIndex - 1) * pageSize
  59. err := e.SQL("SELECT TOP " + utils.ValueToString(pageSize, "") + " pm_wostatus.* FROM pm_wostatus " + where + " AND (convert(varchar(10),finr)+convert(varchar(40),worecnr) NOT IN (SELECT TOP " + utils.ValueToString(Offset, "") + " convert(varchar(10),finr)+convert(varchar(40),worecnr) FROM pm_wostatus " + where + " ORDER BY credatuz DESC)) ORDER BY credatuz DESC").Find(&data)
  60. pcount := new(PmWostatus)
  61. count, err := table.Count(pcount)
  62. if err != nil {
  63. return data, 0, err
  64. }
  65. return data, int(count), nil
  66. }