|
@@ -0,0 +1,181 @@
|
|
|
|
+package system
|
|
|
|
+
|
|
|
|
+import (
|
|
|
|
+ "github.com/beego/beego/v2/client/orm"
|
|
|
|
+ "time"
|
|
|
|
+)
|
|
|
|
+
|
|
|
|
+type SysGroupAddReq struct {
|
|
|
|
+ List []*SysGroup
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+type SysGroup struct {
|
|
|
|
+ GroupId int `orm:"column(group_id);pk" description:"分组ID"`
|
|
|
|
+ DepartmentId int `description:"部门Id"`
|
|
|
|
+ ParentId int `description:"父级Id"`
|
|
|
|
+ GroupName string `description:"分组名称"`
|
|
|
|
+ Sort int `description:"排序"`
|
|
|
|
+ CreateTime string `description:"创建时间"`
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func GetSysGroupCount(departmentId int, groupName string) (count int, err error) {
|
|
|
|
+ sql := `SELECT COUNT(1) AS count FROM sys_group WHERE department_id=? AND group_name=? `
|
|
|
|
+ o := orm.NewOrm()
|
|
|
|
+ err = o.Raw(sql, departmentId, groupName).QueryRow(&count)
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func AddSysGroup(item *SysGroup) (lastId int64, err error) {
|
|
|
|
+ o := orm.NewOrm()
|
|
|
|
+ lastId, err = o.Insert(item)
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+type SysGroupEditReq struct {
|
|
|
|
+ GroupId int `description:"分组ID"`
|
|
|
|
+ GroupName string `description:"分组名称"`
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func GetSysGroupById(groupId int) (item *SysGroup, err error) {
|
|
|
|
+ sql := `SELECT * FROM sys_group WHERE group_id=? `
|
|
|
|
+ o := orm.NewOrm()
|
|
|
|
+ err = o.Raw(sql, groupId).QueryRow(&item)
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func GetSysGroupByName(groupName string) (item *SysGroup, err error) {
|
|
|
|
+ sql := `SELECT * FROM sys_group WHERE group_name=? `
|
|
|
|
+ o := orm.NewOrm()
|
|
|
|
+ err = o.Raw(sql, groupName).QueryRow(&item)
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func ModifySysGroup(groupName string, groupId int) (err error) {
|
|
|
|
+ o := orm.NewOrm()
|
|
|
|
+ to, err := o.Begin()
|
|
|
|
+ if err != nil {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ defer func() {
|
|
|
|
+ if err != nil {
|
|
|
|
+ _ = to.Rollback()
|
|
|
|
+ } else {
|
|
|
|
+ _ = to.Commit()
|
|
|
|
+ }
|
|
|
|
+ }()
|
|
|
|
+ sql := `UPDATE sys_group SET group_name=? WHERE group_id=? `
|
|
|
|
+ _, err = to.Raw(sql, groupName, groupId).Exec()
|
|
|
|
+ sql = `UPDATE admin SET group_name=? WHERE group_id=? `
|
|
|
|
+ _, err = to.Raw(sql, groupName, groupId).Exec()
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+type SysGroupDeleteReq struct {
|
|
|
|
+ GroupId int `description:"分组ID"`
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func DeleteSysGroup(groupId int) (err error) {
|
|
|
|
+ sql := `DELETE FROM sys_group WHERE group_id=? `
|
|
|
|
+ o := orm.NewOrm()
|
|
|
|
+ _, err = o.Raw(sql, groupId).Exec()
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+type SysFullGroup struct {
|
|
|
|
+ GroupId int `orm:"column(group_id);pk" description:"分组ID"`
|
|
|
|
+ DepartmentId int `description:"部门Id"`
|
|
|
|
+ ParentId int `description:"父级Id"`
|
|
|
|
+ GroupName string `description:"分组名称"`
|
|
|
|
+ ParentGroupName string `description:"父级分组名称"`
|
|
|
|
+ DepartmentName string `description:"部门名称"`
|
|
|
|
+ CreateTime time.Time `description:"创建时间"`
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+type SysGroupSortReq struct {
|
|
|
|
+ //ParentId int `description:"上级部门/分组ID"`
|
|
|
|
+ DepartmentIds []int `description:"移动后的一级ID排序"`
|
|
|
|
+ GroupIds []int `description:"移动后的二级ID排序"`
|
|
|
|
+ TeamIds []int `description:"移动后的三级ID排序"`
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+type GroupSort struct {
|
|
|
|
+ GroupId int
|
|
|
|
+ Sort int
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func MultiUpdateGroupSort(items []*GroupSort) (err error) {
|
|
|
|
+ if len(items) == 0 {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ o := orm.NewOrm()
|
|
|
|
+ p, err := o.Raw("UPDATE sys_group SET sort = ? WHERE group_id = ?").Prepare()
|
|
|
|
+ if err != nil {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ defer func() {
|
|
|
|
+ _ = p.Close()
|
|
|
|
+ }()
|
|
|
|
+ for _, v := range items {
|
|
|
|
+ _, err = p.Exec(v.Sort, v.GroupId)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func GetGroupByDepartmentId(departmentId int) (list []*SysFullGroup, err error) {
|
|
|
|
+ sql := `SELECT
|
|
|
|
+ s.*, g.group_name AS parent_group_name,
|
|
|
|
+ d.department_name
|
|
|
|
+ FROM
|
|
|
|
+ sys_group s
|
|
|
|
+ LEFT JOIN sys_group g ON s.parent_id = g.group_id
|
|
|
|
+ LEFT JOIN sys_department d ON s.department_id = d.department_id
|
|
|
|
+ WHERE
|
|
|
|
+ s.department_id = ?
|
|
|
|
+ ORDER BY
|
|
|
|
+ s.sort ASC,
|
|
|
|
+ s.create_time ASC`
|
|
|
|
+ o := orm.NewOrm()
|
|
|
|
+ _, err = o.Raw(sql, departmentId).QueryRows(&list)
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+type RoadshowGroupResp struct {
|
|
|
|
+ List []RoadshowGroups
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+type RoadshowGroups struct {
|
|
|
|
+ GroupId int `description:"分组ID"`
|
|
|
|
+ GroupName string `description:"分组名称"`
|
|
|
|
+ Child []RoadshowGroupSellers `description:"销售"`
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+type RoadshowGroupSellers struct {
|
|
|
|
+ GroupId int `description:"大组ID"`
|
|
|
|
+ TeamId int `description:"小组ID"`
|
|
|
|
+ AdminId int `description:"销售ID"`
|
|
|
|
+ AdminName string `description:"销售名称"`
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func GetAllSysGroupByGroupId(groupId int) (items []*SysGroup, err error) {
|
|
|
|
+ sql := `SELECT * FROM sys_group WHERE parent_id=? OR parent_id = ? ORDER BY sort ASC, create_time ASC`
|
|
|
|
+ o := orm.NewOrm()
|
|
|
|
+ _, err = o.Raw(sql, groupId, groupId).QueryRows(&items)
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func GetParentIdFromGroup(gid int) (items *int, err error) {
|
|
|
|
+ o := orm.NewOrm()
|
|
|
|
+ sql := `SELECT parent_id FROM sys_group WHERE group_id=? `
|
|
|
|
+ err = o.Raw(sql, gid).QueryRow(&items)
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// Update 更新用户基础信息
|
|
|
|
+func (item *SysGroup) AddOrUpdate() (err error) {
|
|
|
|
+ o := orm.NewOrm()
|
|
|
|
+ _, err = o.InsertOrUpdate(item)
|
|
|
|
+ return
|
|
|
|
+}
|