article_department.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. package cygx
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CygxArticleDepartment struct {
  7. DepartmentId int `orm:"column(department_id);pk"`
  8. CreateTime time.Time `description:"创建时间"`
  9. NickName string `description:"昵称"`
  10. Remark string `description:"备注"`
  11. Remarks string `description:"备注辅助字段"`
  12. Content string `description:"初始内容"`
  13. ImgUrl string `description:"作者头像"`
  14. }
  15. type CygxArticleDepartmentRep struct {
  16. DepartmentId int `description:"主键ID"`
  17. CreateTime string `description:"创建时间"`
  18. NickName string `description:"昵称"`
  19. Remark string `description:"备注"`
  20. Remarks string `description:"备注辅助字段"`
  21. Content string `description:"初始内容"`
  22. ImgUrl string `description:"作者头像"`
  23. }
  24. type CygxArticleDepartmentList struct {
  25. List []*CygxArticleDepartmentRep
  26. }
  27. // 新增
  28. func AddCygxArticleDepartment(item *CygxArticleDepartment) (newId int64, err error) {
  29. o := orm.NewOrmUsingDB("hz_cygx")
  30. newId, err = o.Insert(item)
  31. return
  32. }
  33. // 详情
  34. func GetArticleDepartmentDateil(nickName, remarks string) (item *CygxArticleDepartmentRep, err error) {
  35. o := orm.NewOrmUsingDB("hz_cygx")
  36. sql := `SELECT * FROM cygx_article_department WHERE nick_name = ? AND remarks = ? LIMIT 1 `
  37. err = o.Raw(sql, nickName, remarks).QueryRow(&item)
  38. return
  39. }
  40. // 详情
  41. func GetArticleDepartmentDateilById(departmentId int) (item *CygxArticleDepartmentRep, err error) {
  42. o := orm.NewOrmUsingDB("hz_cygx")
  43. sql := `SELECT * FROM cygx_article_department WHERE department_id = ? `
  44. err = o.Raw(sql, departmentId).QueryRow(&item)
  45. return
  46. }
  47. // 数量
  48. func GetArticleDepartmentCount(nickName, remarks string) (count int, err error) {
  49. o := orm.NewOrmUsingDB("hz_cygx")
  50. sql := `SELECT COUNT(1) FROM cygx_article_department WHERE nick_name = ? AND remarks = ? `
  51. err = o.Raw(sql, nickName, remarks).QueryRow(&count)
  52. return
  53. }
  54. // 数量
  55. func GetArticleDepartmentCountAll() (count int, err error) {
  56. o := orm.NewOrmUsingDB("hz_cygx")
  57. sql := `SELECT COUNT(1) FROM cygx_article_department`
  58. err = o.Raw(sql).QueryRow(&count)
  59. return
  60. }
  61. // 列表
  62. func GetCygxArticleDepartmentList(condition string) (items []*CygxArticleDepartmentRep, err error) {
  63. o := orm.NewOrmUsingDB("hz_cygx")
  64. sql := `SELECT * FROM cygx_article_department `
  65. if condition != "" {
  66. sql += condition
  67. }
  68. _, err = o.Raw(sql).QueryRows(&items)
  69. return
  70. }
  71. type CygxDepartmentFllowList struct {
  72. RealName string `description:"姓名"`
  73. CompanyName string `description:"公司名称"`
  74. CompanyId int `description:"公司Id"`
  75. SellerName string `description:"公司名称"`
  76. CreateTime string `description:"创建时间"`
  77. }
  78. type CygxDepartmentFllowRep struct {
  79. NickName string `description:"作者昵称"`
  80. FllowNum int `description:"关注数量"`
  81. List []*CygxDepartmentFllowList
  82. }
  83. // 列表
  84. func GetCygxDepartmentFllowList(departmentId int) (items []*CygxDepartmentFllowList, err error) {
  85. o := orm.NewOrmUsingDB("hz_cygx")
  86. sql := `SELECT
  87. f.*
  88. FROM
  89. cygx_article_department_follow AS f
  90. WHERE
  91. f.department_id = ?
  92. AND f.type = 1 `
  93. _, err = o.Raw(sql, departmentId).QueryRows(&items)
  94. return
  95. }
  96. // 详情
  97. func GetArticleDepartmentDateilByDepartmentId(departmentId int) (item *CygxArticleDepartment, err error) {
  98. o := orm.NewOrmUsingDB("hz_cygx")
  99. sql := `SELECT * FROM cygx_article_department WHERE department_id = ? `
  100. err = o.Raw(sql, departmentId).QueryRow(&item)
  101. return
  102. }