|
@@ -17,13 +17,13 @@ type SysDepartment struct {
|
|
|
}
|
|
|
|
|
|
func (s *SysDepartment) Add() (err error) {
|
|
|
- o := orm.NewOrmUsingDB("master")
|
|
|
+ o := orm.NewOrm()
|
|
|
_, err = o.Insert(s)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func (s *SysDepartment) Update(cols []string) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("master")
|
|
|
+ o := orm.NewOrm()
|
|
|
_, err = o.Update(s, cols...)
|
|
|
return
|
|
|
}
|
|
@@ -37,7 +37,7 @@ type SysDepartmentList struct {
|
|
|
}
|
|
|
|
|
|
func DeleteSysDepartmentById(sysDepartmentIds []string, level int) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("master")
|
|
|
+ o := orm.NewOrm()
|
|
|
err = o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error {
|
|
|
sql := `DELETE FROM sys_department WHERE sys_department_id IN (?) `
|
|
|
_, e := txOrm.QueryTable(&SysDepartment{}).
|
|
@@ -72,7 +72,7 @@ func DeleteSysDepartmentById(sysDepartmentIds []string, level int) (err error) {
|
|
|
}
|
|
|
|
|
|
func DeleteSysDepartmentByIdV2(sysDepartmentIds []string, level int) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("master")
|
|
|
+ o := orm.NewOrm()
|
|
|
err = o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error {
|
|
|
// sql := `DELETE FROM sys_department WHERE sys_department_id IN (?) `
|
|
|
_, e := txOrm.QueryTable(&SysDepartment{}).
|
|
@@ -99,7 +99,7 @@ func DeleteSysDepartmentByIdV2(sysDepartmentIds []string, level int) (err error)
|
|
|
}
|
|
|
|
|
|
func UpdateDepartmentSortByIds(sysDepartmentIds []int) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("master")
|
|
|
+ o := orm.NewOrm()
|
|
|
err = o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error {
|
|
|
sql := `UPDATE sys_department SET sort=? WHERE sys_department_id=?`
|
|
|
for i, depId := range sysDepartmentIds {
|
|
@@ -114,56 +114,56 @@ func UpdateDepartmentSortByIds(sysDepartmentIds []int) (err error) {
|
|
|
}
|
|
|
|
|
|
func GetSysDepartmentById(sysDepartmentId int) (item *SysDepartment, err error) {
|
|
|
- o := orm.NewOrmUsingDB("master")
|
|
|
+ o := orm.NewOrm()
|
|
|
sql := `SELECT * FROM sys_department WHERE sys_department_id=? `
|
|
|
err = o.Raw(sql, sysDepartmentId).QueryRow(&item)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func GetSysDepartmentCountById(sysDepartmentId int) (count int, err error) {
|
|
|
- o := orm.NewOrmUsingDB("master")
|
|
|
+ o := orm.NewOrm()
|
|
|
sql := `SELECT COUNT(1) AS count FROM sys_department WHERE sys_department_id=?`
|
|
|
err = o.Raw(sql, sysDepartmentId).QueryRow(&count)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func GetSysDepartmentCountByParentId(parentId int, sysDepartmentName string) (count int, err error) {
|
|
|
- o := orm.NewOrmUsingDB("master")
|
|
|
+ o := orm.NewOrm()
|
|
|
sql := `SELECT COUNT(1) AS count FROM sys_department WHERE parent_id=? AND sys_department_name=?`
|
|
|
err = o.Raw(sql, parentId, sysDepartmentName).QueryRow(&count)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func GetSysDepartmentCountByName(sysDepartmentName string) (count int, err error) {
|
|
|
- o := orm.NewOrmUsingDB("master")
|
|
|
+ o := orm.NewOrm()
|
|
|
sql := `SELECT COUNT(1) AS count FROM sys_department WHERE sys_department_name=?`
|
|
|
err = o.Raw(sql, sysDepartmentName).QueryRow(&count)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func GetSysDepartmentListByLevel(level int) (items []*SysDepartmentList, err error) {
|
|
|
- o := orm.NewOrmUsingDB("master")
|
|
|
+ o := orm.NewOrm()
|
|
|
sql := `SELECT * FROM sys_department WHERE level=? ORDER BY sort`
|
|
|
_, err = o.Raw(sql, level).QueryRows(&items)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func GetSysDepartmentListByParentId(parentId int) (item SysDepartmentList, err error) {
|
|
|
- o := orm.NewOrmUsingDB("master")
|
|
|
+ o := orm.NewOrm()
|
|
|
sql := `SELECT * FROM sys_department WHERE sys_department_id=? `
|
|
|
err = o.Raw(sql, parentId).QueryRow(&item)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func GetChildSysDepartmentListById(sysDepartmentId int) (items []*SysDepartmentList, err error) {
|
|
|
- o := orm.NewOrmUsingDB("master")
|
|
|
+ o := orm.NewOrm()
|
|
|
sql := `SELECT * FROM sys_department WHERE parent_id=? `
|
|
|
_, err = o.Raw(sql, sysDepartmentId).QueryRows(&items)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func GetChildSysDepartmentListByIds(sysDepartmentIds string) (items []*SysDepartmentList, err error) {
|
|
|
- o := orm.NewOrmUsingDB("master")
|
|
|
+ o := orm.NewOrm()
|
|
|
sql := `SELECT * FROM sys_department WHERE parent_id in (?) `
|
|
|
_, err = o.Raw(sql, sysDepartmentIds).QueryRows(&items)
|
|
|
return
|