sys_team.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package system
  2. import (
  3. "eta_gn/eta_api/global"
  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. err = global.DEFAULT_DmSQL.Raw(sql, groupId, teamName).Scan(&count).Error
  21. return
  22. }
  23. type SysTeamEditReq struct {
  24. TeamId int `description:"分组ID"`
  25. TeamName string `description:"分组名称"`
  26. }
  27. func GetSysTeamByName(teamName string) (item *SysGroup, err error) {
  28. sql := `SELECT * FROM sys_group WHERE group_name=? `
  29. err = global.DEFAULT_DmSQL.Raw(sql, teamName).First(&item).Error
  30. return
  31. }
  32. func ModifySysTeam(teamName string, teamId int) (err error) {
  33. tx := global.DEFAULT_DmSQL.Begin()
  34. defer func() {
  35. if err != nil {
  36. _ = tx.Rollback()
  37. return
  38. }
  39. _ = tx.Commit()
  40. }()
  41. sql := `UPDATE sys_group SET group_name=? WHERE group_id=? `
  42. err = tx.Exec(sql, teamName, teamId).Error
  43. if err != nil {
  44. return
  45. }
  46. sql = `UPDATE "admin" SET group_name=? WHERE group_id=? `
  47. err = tx.Exec(sql, teamName, teamId).Error
  48. return
  49. }
  50. type SysTeamDeleteReq struct {
  51. TeamId int `description:"小组ID"`
  52. }
  53. type SysTeamList struct {
  54. GroupId int `orm:"column(group_id);pk" json:"DepartmentId" description:"小组ID"`
  55. ParentId int `json:"GroupId" description:"小组Id"`
  56. GroupName string `json:"DepartmentName" description:"分组名称"`
  57. CreateTime time.Time `description:"创建时间"`
  58. }
  59. func GetSysTeamByDepartmentId(groupId int) (items []*SysTeamList, err error) {
  60. sql := `SELECT * FROM sys_group WHERE parent_id=? ORDER BY sort ASC, create_time ASC`
  61. err = global.DEFAULT_DmSQL.Raw(sql, groupId).Find(&items).Error
  62. return
  63. }
  64. func ClearSysUserTeam(groupId int) (err error) {
  65. sql := `UPDATE "admin" SET group_id=0,group_name='' WHERE group_id=? `
  66. err = global.DEFAULT_DmSQL.Exec(sql, groupId).Error
  67. return
  68. }