sys_team.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package system
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type SysTeamAddReq struct {
  7. GroupId int `description:"大组id"`
  8. DepartmentId int `description:"部门id"`
  9. TeamName string `description:"分组名称,多个用英文逗号隔开"`
  10. }
  11. type SysTeam struct {
  12. GroupId int `orm:"column(group_id);pk" description:"分组ID"`
  13. ParentId int `description:"父级Id"`
  14. DepartmentId int `description:"部门id"`
  15. GroupName string `description:"分组名称"`
  16. CreateTime time.Time `description:"创建时间"`
  17. }
  18. func GetSysTeamCount(groupId int, teamName string) (count int, err error) {
  19. sql := `SELECT COUNT(1) AS count FROM sys_group WHERE parent_id=? AND group_name=? `
  20. o := orm.NewOrm()
  21. err = o.Raw(sql, groupId, teamName).QueryRow(&count)
  22. return
  23. }
  24. type SysTeamEditReq struct {
  25. TeamId int `description:"分组ID"`
  26. TeamName string `description:"分组名称"`
  27. }
  28. func GetSysTeamByName(teamName string) (item *SysGroup, err error) {
  29. sql := `SELECT * FROM sys_group WHERE group_name=? `
  30. o := orm.NewOrm()
  31. err = o.Raw(sql, teamName).QueryRow(&item)
  32. return
  33. }
  34. func ModifySysTeam(teamName string, teamId int) (err error) {
  35. o := orm.NewOrm()
  36. to, err := o.Begin()
  37. if err != nil {
  38. return
  39. }
  40. defer func() {
  41. if err != nil {
  42. _ = to.Rollback()
  43. } else {
  44. _ = to.Commit()
  45. }
  46. }()
  47. sql := `UPDATE sys_group SET group_name=? WHERE group_id=? `
  48. _, err = to.Raw(sql, teamName, teamId).Exec()
  49. sql = `UPDATE admin SET group_name=? WHERE group_id=? `
  50. _, err = to.Raw(sql, teamName, teamId).Exec()
  51. return
  52. }
  53. type SysTeamDeleteReq struct {
  54. TeamId int `description:"小组ID"`
  55. }
  56. type SysTeamList struct {
  57. GroupId int `orm:"column(group_id);pk" json:"DepartmentId" description:"小组ID"`
  58. ParentId int `json:"GroupId" description:"小组Id"`
  59. GroupName string `json:"DepartmentName" description:"分组名称"`
  60. CreateTime time.Time `description:"创建时间"`
  61. }
  62. func GetSysTeamByDepartmentId(groupId int) (items []*SysTeamList, err error) {
  63. sql := `SELECT * FROM sys_group WHERE parent_id=? ORDER BY sort ASC, create_time ASC`
  64. o := orm.NewOrm()
  65. _, err = o.Raw(sql, groupId).QueryRows(&items)
  66. return
  67. }
  68. func ClearSysUserTeam(groupId int) (err error) {
  69. sql := `UPDATE admin SET group_id=0,group_name='' WHERE group_id=? `
  70. o := orm.NewOrm()
  71. _, err = o.Raw(sql, groupId).Exec()
  72. return
  73. }