You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
1.7 KiB
83 lines
1.7 KiB
package BaseOrganizationManagerDao
|
|
|
|
import (
|
|
"dsBaseRpc/Utils/CommonUtil"
|
|
"dsBaseRpc/Utils/DbUtil"
|
|
"dsBaseRpc/Utils/SqlKit"
|
|
"dsBaseRpc/models"
|
|
)
|
|
|
|
//操作数据库的变量
|
|
var db = DbUtil.Engine
|
|
|
|
//更新部门的管理员
|
|
func UpdateOrgManager(OrgId string, OrgManagerIds []string) error {
|
|
//1、先删除
|
|
tbom := new(models.TBaseOrganizationManager)
|
|
tbom.BUse = -1
|
|
_, err := db.Where("org_id=?", OrgId).Update(tbom)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
//2、后插入
|
|
|
|
//部门所在的单位
|
|
list := SqlKit.QueryByIds([]string{OrgId}, "t_base_organization")
|
|
BureauId := list[0]["bureau_id"].(string)
|
|
|
|
//事务声明
|
|
session := db.NewSession()
|
|
defer session.Close()
|
|
session.Begin()
|
|
|
|
//事务的内容
|
|
for i := range OrgManagerIds {
|
|
u := new(models.TBaseOrganizationManager)
|
|
u.Id = CommonUtil.GetUUID()
|
|
u.BUse = 1
|
|
u.PersonId = OrgManagerIds[i]
|
|
u.BureauId = BureauId
|
|
u.OrgId = OrgId
|
|
_, err := session.Insert(u)
|
|
if err != nil {
|
|
session.Rollback()
|
|
return err
|
|
}
|
|
}
|
|
//事务提交
|
|
err = session.Commit()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
//删除部门管理员(通过部门IDS)
|
|
func DeleteOrgManagerByOrgIds(OrgIds []string) error {
|
|
for i := range OrgIds {
|
|
OrgId := OrgIds[i]
|
|
tbom := new(models.TBaseOrganizationManager)
|
|
tbom.BUse = -1
|
|
_, err := db.Where("org_id=?", OrgId).And("b_use=?", 1).Update(tbom)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
//删除部门管理员(通过人员IDS)
|
|
func DeleteOrgManagerByPersonIds(PersonIds []string) error {
|
|
for i := range PersonIds {
|
|
PersonId := PersonIds[i]
|
|
tbom := new(models.TBaseOrganizationManager)
|
|
tbom.BUse = -1
|
|
_, err := db.Where("person_id=?", PersonId).And("b_use", 1).Update(tbom)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|