variety.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package data_manage
  2. import (
  3. "eta/eta_hub/utils"
  4. "fmt"
  5. "github.com/beego/beego/v2/client/orm"
  6. "strings"
  7. "time"
  8. )
  9. // Variety variety 装置检修-品种表
  10. type Variety struct {
  11. VarietyId int `orm:"column(variety_id);pk"`
  12. VarietyName string `description:"品种名称"`
  13. LastUpdateSysUserId int `description:"最后更新人id"`
  14. LastUpdateSysUserRealName string `description:"最后更新人名称"`
  15. ProductionDay int `description:"生产天数"`
  16. SysUserId int `description:"创建人id"`
  17. SysUserRealName string `description:"创建人姓名"`
  18. CreateTime time.Time `description:"创建时间"`
  19. ModifyTime time.Time `description:"修改时间"`
  20. }
  21. func (m *Variety) GetItemsByCondition(cond string, pars []interface{}, fieldArr []string, orderRule string) (items []*Variety, err error) {
  22. o := orm.NewOrmUsingDB("data")
  23. fields := strings.Join(fieldArr, ",")
  24. if len(fieldArr) == 0 {
  25. fields = `*`
  26. }
  27. order := `ORDER BY create_time DESC`
  28. if orderRule != "" {
  29. order = ` ORDER BY ` + orderRule
  30. }
  31. sql := fmt.Sprintf(`SELECT %s FROM variety WHERE 1=1 %s %s`, fields, cond, order)
  32. _, err = o.Raw(sql, pars).QueryRows(&items)
  33. return
  34. }
  35. // VarietyItem 品种信息
  36. type VarietyItem struct {
  37. VarietyId int `description:"品种ID"`
  38. VarietyName string `description:"品种名称"`
  39. ProductionDay int `description:"生产天数"`
  40. CreateTime string `description:"创建时间"`
  41. UpdateTime string `description:"更新时间"`
  42. }
  43. func FormatVariety2Item(origin *Variety) (item *VarietyItem) {
  44. if origin == nil {
  45. return
  46. }
  47. item = new(VarietyItem)
  48. item.VarietyId = origin.VarietyId
  49. item.VarietyName = origin.VarietyName
  50. item.ProductionDay = origin.ProductionDay
  51. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
  52. item.UpdateTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
  53. return
  54. }