sys_group.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package system
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type SysGroupAddReq struct {
  7. DepartmentId int `description:"部门Id"`
  8. GroupName string `description:"分组名称,多个用英文逗号隔开"`
  9. }
  10. type SysGroup struct {
  11. GroupId int `orm:"column(group_id);pk" description:"分组ID"`
  12. DepartmentId int `description:"部门Id"`
  13. ParentId int `description:"父级Id"`
  14. GroupName string `description:"分组名称"`
  15. CreateTime time.Time `description:"创建时间"`
  16. }
  17. type SysGroupEditReq struct {
  18. GroupId int `description:"分组ID"`
  19. GroupName string `description:"分组名称"`
  20. }
  21. type SysGroupDeleteReq struct {
  22. GroupId int `description:"分组ID"`
  23. }
  24. func DeleteSysGroup(groupId int) (err error) {
  25. sql := `DELETE FROM sys_group WHERE group_id=? `
  26. o := orm.NewOrm()
  27. _, err = o.Raw(sql, groupId).Exec()
  28. return
  29. }
  30. // 因前端显示需要,TopId字段用来当做一级部门id,DepartmentId为当前分组id
  31. type SysGroupList struct {
  32. GroupId int `orm:"column(group_id);pk" json:"DepartmentId" description:"分组ID"`
  33. ParentId int `json:"ParentId" description:"父级ID"`
  34. DepartmentId int `json:"TopId" description:"部门Id"`
  35. GroupName string `json:"DepartmentName" description:"分组名称"`
  36. Child []*SysTeamList `description:"小组"`
  37. CreateTime time.Time `description:"创建时间"`
  38. IsGroup bool `description:"是否为二级部门"`
  39. }
  40. type SysFullGroup struct {
  41. GroupId int `orm:"column(group_id);pk" description:"分组ID"`
  42. DepartmentId int `description:"部门Id"`
  43. ParentId int `description:"父级Id"`
  44. GroupName string `description:"分组名称"`
  45. ParentGroupName string `description:"父级分组名称"`
  46. DepartmentName string `description:"部门名称"`
  47. CreateTime time.Time `description:"创建时间"`
  48. }
  49. // GetFullGroup 获取完整的分组信息
  50. func GetFullGroup() (list []*SysFullGroup, err error) {
  51. sql := `SELECT s.*,g.group_name as parent_group_name , d.department_name
  52. from sys_group s
  53. LEFT JOIN sys_group g on s.parent_id=g.group_id
  54. LEFT JOIN sys_department d on s.department_id=d.department_id`
  55. o := orm.NewOrm()
  56. _, err = o.Raw(sql).QueryRows(&list)
  57. return
  58. }
  59. func GetGroupByDepartmentId(departmentId int) (list []*SysFullGroup, err error) {
  60. sql := `SELECT
  61. s.*, g.group_name AS parent_group_name,
  62. d.department_name
  63. FROM
  64. sys_group s
  65. LEFT JOIN sys_group g ON s.parent_id = g.group_id
  66. LEFT JOIN sys_department d ON s.department_id = d.department_id
  67. WHERE
  68. s.department_id = ?
  69. ORDER BY
  70. s.sort ASC,
  71. s.create_time ASC`
  72. o := orm.NewOrm()
  73. _, err = o.Raw(sql, departmentId).QueryRows(&list)
  74. return
  75. }
  76. type RoadshowGroupResp struct {
  77. List []RoadshowGroups
  78. }
  79. type RoadshowGroups struct {
  80. GroupId int `description:"分组ID"`
  81. GroupName string `description:"分组名称"`
  82. Child []RoadshowGroupSellers `description:"销售"`
  83. }
  84. type RoadshowGroupSellers struct {
  85. GroupId int `description:"大组ID"`
  86. TeamId int `description:"小组ID"`
  87. AdminId int `description:"销售ID"`
  88. AdminName string `description:"销售名称"`
  89. }