company_ascribe.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package company
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CompanyAscribe struct {
  7. CompanyAscribeId int `orm:"column(company_ascribe_id);pk" description:"归因ID"`
  8. AscribeContent string `description:"归因说明"`
  9. AdminId int `description:"管理员ID"`
  10. CreateTime time.Time `description:"创建时间"`
  11. ModifyTime time.Time `description:"更新时间"`
  12. }
  13. type CompanyAscribeResp struct {
  14. CompanyAscribeId int `orm:"column(company_ascribe_id);pk" description:"归因ID"`
  15. AscribeContent string `description:"归因说明"`
  16. AdminId int `description:"管理员ID"`
  17. CreateTime string `description:"创建时间"`
  18. }
  19. type CompanyAscribeDetailResp struct {
  20. Detail *CompanyAscribeResp
  21. }
  22. type CompanyAscribeListResp struct {
  23. List []*CompanyAscribeResp
  24. }
  25. type CompanyAscribeAddReq struct {
  26. AscribeContent string `description:"归因说明"`
  27. }
  28. // 添加
  29. func AddCompanyAscribe(item *CompanyAscribe) (newId int64, err error) {
  30. o := orm.NewOrm()
  31. newId, err = o.Insert(item)
  32. return
  33. }
  34. // 获取数量
  35. func GetCompanyAscribeCount(condition string, pars []interface{}) (count int, err error) {
  36. sqlCount := ` SELECT COUNT(1) AS count FROM company_ascribe as a WHERE 1= 1 `
  37. if condition != "" {
  38. sqlCount += condition
  39. }
  40. o := orm.NewOrm()
  41. err = o.Raw(sqlCount, pars).QueryRow(&count)
  42. return
  43. }
  44. // 列表
  45. func GetCompanyAscribeList(condition string, pars []interface{}, startSize, pageSize int) (items []*CompanyAscribeResp, err error) {
  46. o := orm.NewOrm()
  47. sql := `SELECT * FROM company_ascribe as a WHERE 1= 1 `
  48. if condition != "" {
  49. sql += condition
  50. }
  51. if startSize+pageSize > 0 {
  52. sql += ` LIMIT ?,? `
  53. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  54. }
  55. _, err = o.Raw(sql, pars).QueryRows(&items)
  56. return
  57. }
  58. // 通过ID获取详情
  59. func GetCompanyAscribeDetail(companyAscribeId int) (item *CompanyAscribeResp, err error) {
  60. o := orm.NewOrm()
  61. sql := `SELECT * FROM company_ascribe WHERE company_ascribe_id=? `
  62. err = o.Raw(sql, companyAscribeId).QueryRow(&item)
  63. return
  64. }