manual_user.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package data_manage
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. type ManualUser struct {
  8. ManualUserId int `orm:"column(manual_user_id);pk"`
  9. AdminId int `description:"用户id"`
  10. AdminRealName string `description:"用户姓名"`
  11. SysUserId int `description:"创建人id"`
  12. SysUserRealName string `description:"创建人姓名"`
  13. CreateTime time.Time `description:"创建时间"`
  14. }
  15. func DeleteManualUser(adminId int) (err error) {
  16. sql := `DELETE FROM manual_user WHERE admin_id=? `
  17. o := orm.NewOrmUsingDB("data")
  18. _, err = o.Raw(sql, adminId).Exec()
  19. return
  20. }
  21. func AddManualUser(item *ManualUser) (err error) {
  22. o := orm.NewOrmUsingDB("data")
  23. _, err = o.Insert(item)
  24. return
  25. }
  26. type ManualUserItem struct {
  27. AdminId int `description:"用户id"`
  28. AdminRealName string `description:"用户姓名"`
  29. }
  30. func GetManualUserList() (list []*ManualUserItem, err error) {
  31. o := orm.NewOrmUsingDB("data")
  32. sql := ` SELECT admin_id,admin_real_name FROM manual_user
  33. GROUP BY admin_id
  34. ORDER BY create_time DESC `
  35. fmt.Println("GetManualUserList:", sql)
  36. _, err = o.Raw(sql).QueryRows(&list)
  37. return
  38. }
  39. type ManualUserList struct {
  40. AdminId int `description:"用户id"`
  41. AdminRealName int `description:"用户姓名"`
  42. }
  43. func GetManualSysuserAll() (list []*ManualUserList, err error) {
  44. o := orm.NewOrmUsingDB("data")
  45. sql := ` SELECT * FROM manual_user
  46. ORDER BY create_time ASC `
  47. o.Raw(sql).QueryRows()
  48. return
  49. }
  50. type ManualSysUserClassifySaveReq struct {
  51. AdminId int `description:"用户id"`
  52. ClassifyId []int `description:"分类id数组"`
  53. }
  54. type ManualUserClassify struct {
  55. ManualUserClassifyId int `orm:"column(manual_user_classify_id);pk"`
  56. AdminId int
  57. ClassifyId int
  58. CreateTime time.Time
  59. }
  60. func AddManualUserClassifyMulti(items []*ManualUserClassify) (err error) {
  61. o := orm.NewOrmUsingDB("data")
  62. _, err = o.InsertMulti(1, items)
  63. return
  64. }
  65. func DeleteManualUserClassifyCount(adminId int) (err error) {
  66. o := orm.NewOrmUsingDB("data")
  67. sql := ` DELETE FROM manual_user_classify WHERE admin_id=? `
  68. _, err = o.Raw(sql, adminId).Exec()
  69. return
  70. }
  71. func GetManualUserClassifyCount(adminId, classifyId int) (count int, err error) {
  72. o := orm.NewOrmUsingDB("data")
  73. sql := ` SELECT COUNT(1) AS count FROM manual_user_classify WHERE admin_id=? AND classify_id=? `
  74. err = o.Raw(sql, adminId, classifyId).QueryRow(&count)
  75. return
  76. }
  77. func GetManualUserCount(adminId int) (count int, err error) {
  78. o := orm.NewOrmUsingDB("data")
  79. sql := ` SELECT COUNT(1) AS count FROM manual_user WHERE admin_id=? `
  80. err = o.Raw(sql, adminId).QueryRow(&count)
  81. return
  82. }
  83. func GetManualUserSetClassify(adminId int) (list []*EdbdataClassify, err error) {
  84. o := orm.NewOrmUsingDB("data")
  85. sql := ` SELECT * FROM manual_user_classify WHERE admin_id=? `
  86. _, err = o.Raw(sql, adminId).QueryRows(&list)
  87. return
  88. }