sys_team.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. err = to.Exec(sql, teamName, teamId).Error
  49. return
  50. }
  51. type SysTeamDeleteReq struct {
  52. TeamId int `description:"小组ID"`
  53. }
  54. type SysTeamList struct {
  55. GroupId int `orm:"column(group_id);pk" gorm:"primaryKey" json:"DepartmentId" description:"小组ID"`
  56. ParentId int `json:"GroupId" description:"小组Id"`
  57. GroupName string `json:"DepartmentName" description:"分组名称"`
  58. CreateTime time.Time `description:"创建时间"`
  59. }
  60. func GetSysTeamByDepartmentId(groupId int) (items []*SysTeamList, err error) {
  61. sql := `SELECT * FROM sys_group WHERE parent_id=? ORDER BY sort ASC, create_time ASC`
  62. o := global.DbMap[utils.DbNameMaster]
  63. err = o.Raw(sql, groupId).Find(&items).Error
  64. return
  65. }
  66. func ClearSysUserTeam(groupId int) (err error) {
  67. sql := `UPDATE "admin" SET group_id=0,group_name='' WHERE group_id=? `
  68. o := global.DbMap[utils.DbNameMaster]
  69. err = o.Exec(sql, groupId).Error
  70. return
  71. }