123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- package system
- import (
- "eta_gn/eta_api/global"
- "time"
- )
- type SysDepartmentAddReq struct {
- DepartmentName string `description:"部门名称"`
- }
- type SysDepartment struct {
- DepartmentId int `gorm:"primaryKey;" description:"部门Id"`
- DepartmentName string `description:"部门名称"`
- Sort int `description:"排序"`
- CreateTime time.Time `description:"创建时间"`
- }
- func GetSysDepartmentCount(departmentName string) (count int, err error) {
- sql := `SELECT COUNT(1) AS count FROM sys_department WHERE department_name=? `
- err = global.DEFAULT_DmSQL.Raw(sql, departmentName).Scan(&count).Error
- return
- }
- func AddSysDepartment(item *SysDepartment) (lastId int64, err error) {
- err = global.DEFAULT_DmSQL.Create(item).Error
- return
- }
- type SysDepartmentEditReq struct {
- DepartmentId int `description:"部门Id"`
- DepartmentName string `description:"部门名称"`
- }
- func GetSysDepartmentById(departmentId int) (item *SysDepartment, err error) {
- sql := `SELECT * FROM sys_department WHERE department_id=? `
- err = global.DEFAULT_DmSQL.Raw(sql, departmentId).First(&item).Error
- return
- }
- func GetSysDepartmentByName(departmentName string) (item *SysDepartment, err error) {
- sql := `SELECT * FROM sys_department WHERE department_name=? `
- err = global.DEFAULT_DmSQL.Raw(sql, departmentName).First(&item).Error
- return
- }
- func ModifySysDepartment(departmentName string, departmentId int) (err error) {
- tx := global.DEFAULT_DmSQL.Begin()
- defer func() {
- if err != nil {
- _ = tx.Rollback()
- return
- }
- _ = tx.Commit()
- }()
- sql := `UPDATE sys_department SET department_name=? WHERE department_id=? `
- err = tx.Exec(sql, departmentName, departmentId).Error
- if err != nil {
- return
- }
- sql = `UPDATE "admin" SET department_name=? WHERE department_id=? `
- err = tx.Exec(sql, departmentName, departmentId).Error
- return
- }
- type SysDepartmentDeleteReq struct {
- DepartmentId int `description:"部门Id"`
- }
- func DeleteSysDepartment(departmentId int) (err error) {
- sql := `DELETE FROM sys_department WHERE department_id=? `
- err = global.DEFAULT_DmSQL.Exec(sql, departmentId).Error
- return
- }
- type SysDepartmentList struct {
- DepartmentId int `orm:"column(department_id);pk" description:"部门Id"`
- DepartmentName string `description:"部门名称"`
- CreateTime time.Time `description:"创建时间"`
- Child []*SysGroupList `gorm:"-" description:"分组"`
- IsDepartment bool `description:"true:部门,false:分组"`
- }
- func GetDepartmentList() (items []*SysDepartmentList, err error) {
- sql := `SELECT * FROM sys_department ORDER BY sort ASC, create_time ASC `
- err = global.DEFAULT_DmSQL.Raw(sql).Find(&items).Error
- return
- }
- // GetDepartmentListByIds 根据部门id集合获取部门列表信息
- func GetDepartmentListByIds(departmentIds string) (items []*SysDepartmentList, err error) {
- sql := `SELECT * FROM sys_department where 1 = 1 `
- if departmentIds != "" {
- sql += `and department_id in(` + departmentIds + `) `
- }
- sql += ` ORDER BY sort ASC, create_time ASC `
- err = global.DEFAULT_DmSQL.Raw(sql).Find(&items).Error
- return
- }
- type SysDepartmentListResp struct {
- List []*SysDepartmentList
- }
- func GetSysDepartmentAll() (item []*SysDepartment, err error) {
- sql := `SELECT * FROM sys_department ORDER BY sort ASC, department_id ASC `
- err = global.DEFAULT_DmSQL.Raw(sql).Find(&item).Error
- return
- }
- type DepartmentSort struct {
- DepartmentId int
- Sort int
- }
- func MultiUpdateDepartmentSort(items []*DepartmentSort) (err error) {
- if len(items) == 0 {
- return
- }
- sql := "UPDATE sys_department SET sort = ? WHERE department_id = ?"
- for _, v := range items {
- err = global.DEFAULT_DmSQL.Exec(sql, v.Sort, v.DepartmentId).Error
- if err != nil {
- return
- }
- }
- return
- }
- // DepartmentUserTree 部门用户树
- type DepartmentUserTree struct {
- NodeId int `description:"节点ID"`
- NodeType int `description:"节点类型:1-部门;2-分组;3-用户"`
- NodeName string `description:"节点名称"`
- Children []*DepartmentUserTree `gorm:"-" description:"子节点"`
- }
|