chart_classify_permission.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package company_user
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. // 联系人图表分类权限
  7. type ChartClassifyPermission struct {
  8. Id int `orm:"column(id);pk"`
  9. CompanyId int `description:"客户ID"`
  10. UserId int `description:"用户ID"`
  11. StartTime time.Time `description:"起始时间"`
  12. EndTime time.Time `description:"终止时间"`
  13. Enabled int `description:"状态 0-关闭 1-开启"`
  14. CreateTime time.Time `description:"创建时间"`
  15. UpdateTime time.Time `description:"更新时间"`
  16. }
  17. func (chartClassifyPermission *ChartClassifyPermission) TableName() string {
  18. return "company_user_chart_classify_permission"
  19. }
  20. // Update 更新分类权限
  21. func (chartClassifyPermission *ChartClassifyPermission) Update(cols []string) (err error) {
  22. o := orm.NewOrm()
  23. _, err = o.Update(chartClassifyPermission, cols...)
  24. return
  25. }
  26. // AddChartClassifyPermission 新增分类权限
  27. func AddChartClassifyPermission(item *ChartClassifyPermission) (lastId int64, err error) {
  28. o := orm.NewOrm()
  29. lastId, err = o.Insert(item)
  30. return
  31. }
  32. // GetChartClassifyPermissionByUserId 获取联系人分类权限
  33. func GetChartClassifyPermissionByUserId(userId int) (item *ChartClassifyPermission, err error) {
  34. o := orm.NewOrm()
  35. sql := ` SELECT * FROM company_user_chart_classify_permission WHERE user_id = ? `
  36. err = o.Raw(sql, userId).QueryRow(&item)
  37. return
  38. }
  39. // GetChartClassifyPermissionListByUserIds 通过联系人Id集合获取分类权限列表
  40. func GetChartClassifyPermissionListByUserIds(userIds string) (list []*ChartClassifyPermission, err error) {
  41. o := orm.NewOrm()
  42. sql := ` SELECT * FROM company_user_chart_classify_permission WHERE user_id IN (` + userIds + `) `
  43. _, err = o.Raw(sql).QueryRows(&list)
  44. return
  45. }
  46. // ClearCompanyChartPermission 清除客户下所有联系人图表权限
  47. func ClearCompanyChartPermission(companyId int) (err error) {
  48. o := orm.NewOrm()
  49. sql := ` DELETE FROM company_user_chart_classify_permission WHERE company_id = ? `
  50. _, err = o.Raw(sql, companyId).Exec()
  51. return
  52. }
  53. // GetCompanyChartPermissionByCompanyId 获取客户下所有联系人图表权限
  54. func GetCompanyChartPermissionByCompanyId(companyId int) (items []*ChartClassifyPermission, err error) {
  55. o := orm.NewOrm()
  56. sql := ` select * FROM company_user_chart_classify_permission WHERE company_id = ? `
  57. _, err = o.Raw(sql, companyId).QueryRows(&items)
  58. return
  59. }
  60. // ClearUserChartPermission 清除联系人图表权限
  61. func ClearUserChartPermission(userId int) (err error) {
  62. o := orm.NewOrm()
  63. sql := ` DELETE FROM company_user_chart_classify_permission WHERE user_id = ? LIMIT 1 `
  64. _, err = o.Raw(sql, userId).Exec()
  65. return
  66. }
  67. // CompanyUserChartPermissionOperationRecord 图表权限设置记录
  68. type CompanyUserChartPermissionOperationRecord struct {
  69. Id int `orm:"column(id);pk"`
  70. Type int `description:"操作类型 1-新增 2-编辑"`
  71. CompanyId int `description:"当前所属客户ID"`
  72. UserId int `description:"用户ID"`
  73. AdminId int `description:"操作人ID"`
  74. StartTime time.Time `description:"设置的起始时间"`
  75. EndTime time.Time `description:"设置的终止时间"`
  76. Enabled int `description:"设置的开启关闭状态"`
  77. CreateTime time.Time `description:"操作时间"`
  78. }
  79. // AddChartPermissionOperationRecord 新增图表权限设置记录
  80. func AddChartPermissionOperationRecord(item *CompanyUserChartPermissionOperationRecord) (lastId int64, err error) {
  81. o := orm.NewOrm()
  82. lastId, err = o.Insert(item)
  83. return
  84. }