123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- package system
- import (
- "eta_gn/eta_api/global"
- "time"
- )
- type SysTeamAddReq struct {
- GroupId int `description:"大组id"`
- DepartmentId int `description:"部门id"`
- TeamName string `description:"分组名称,多个用英文逗号隔开"`
- }
- type SysTeam struct {
- GroupId int `orm:"column(group_id);pk" description:"分组ID"`
- ParentId int `description:"父级Id"`
- DepartmentId int `description:"部门id"`
- GroupName string `description:"分组名称"`
- CreateTime time.Time `description:"创建时间"`
- }
- func GetSysTeamCount(groupId int, teamName string) (count int, err error) {
- sql := `SELECT COUNT(1) AS count FROM sys_group WHERE parent_id=? AND group_name=? `
- //o := orm.NewOrm()
- //err = o.Raw(sql, groupId, teamName).QueryRow(&count)
- err = global.DEFAULT_DmSQL.Raw(sql, groupId, teamName).Scan(&count).Error
- return
- }
- type SysTeamEditReq struct {
- TeamId int `description:"分组ID"`
- TeamName string `description:"分组名称"`
- }
- func GetSysTeamByName(teamName string) (item *SysGroup, err error) {
- sql := `SELECT * FROM sys_group WHERE group_name=? `
- //o := orm.NewOrm()
- //err = o.Raw(sql, teamName).QueryRow(&item)
- err = global.DEFAULT_DmSQL.Raw(sql, teamName).First(&item).Error
- return
- }
- func ModifySysTeam(teamName string, teamId 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, teamName, teamId).Exec()
- //sql = `UPDATE admin SET group_name=? WHERE group_id=? `
- //_, err = to.Raw(sql, teamName, teamId).Exec()
- tx := global.DEFAULT_DmSQL.Begin()
- defer func() {
- if err != nil {
- _ = tx.Rollback()
- return
- }
- _ = tx.Commit()
- }()
- sql := `UPDATE sys_group SET group_name=? WHERE group_id=? `
- //_, err = to.Raw(sql, teamName, teamId).Exec()
- err = tx.Exec(sql, teamName, teamId).Error
- if err != nil {
- return
- }
- sql = `UPDATE "admin" SET group_name=? WHERE group_id=? `
- //_, err = to.Raw(sql, teamName, teamId).Exec()
- err = tx.Exec(sql, teamName, teamId).Error
- return
- }
- type SysTeamDeleteReq struct {
- TeamId int `description:"小组ID"`
- }
- type SysTeamList struct {
- GroupId int `orm:"column(group_id);pk" json:"DepartmentId" description:"小组ID"`
- ParentId int `json:"GroupId" description:"小组Id"`
- GroupName string `json:"DepartmentName" description:"分组名称"`
- CreateTime time.Time `description:"创建时间"`
- }
- func GetSysTeamByDepartmentId(groupId int) (items []*SysTeamList, err error) {
- sql := `SELECT * FROM sys_group WHERE parent_id=? ORDER BY sort ASC, create_time ASC`
- //o := orm.NewOrm()
- //_, err = o.Raw(sql, groupId).QueryRows(&items)
- err = global.DEFAULT_DmSQL.Raw(sql, groupId).Find(&items).Error
- return
- }
- func ClearSysUserTeam(groupId int) (err error) {
- sql := `UPDATE "admin" SET group_id=0,group_name='' WHERE group_id=? `
- //o := orm.NewOrm()
- //_, err = o.Raw(sql, groupId).Exec()
- err = global.DEFAULT_DmSQL.Exec(sql, groupId).Error
- return
- }
|