sys_team.go 2.5 KB

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