...
|
...
|
@@ -12,10 +12,47 @@ import ( |
|
|
"github.com/astaxie/beego/orm"
|
|
|
)
|
|
|
|
|
|
func DepartmentAdd(param protocol.RequestDepartmentAdd) (protocol.ResponseDepartmentInfo, error) {
|
|
|
|
|
|
r := protocol.ResponseDepartmentInfo{}
|
|
|
return r, nil
|
|
|
func DepartmentAdd(param protocol.RequestDepartmentAdd) error {
|
|
|
var (
|
|
|
parentDepart *models.Department
|
|
|
err error
|
|
|
)
|
|
|
if param.ParantID > 0 {
|
|
|
parentDepart, err = models.GetDepartmentById(param.ParantID)
|
|
|
if err != nil {
|
|
|
e := fmt.Errorf("GetDepartmentById(%d) err:%s", param.ParantID, err)
|
|
|
log.Error(e.Error())
|
|
|
return protocol.NewErrWithMessage("1", e)
|
|
|
}
|
|
|
if parentDepart.CompanyId != param.CompanyID {
|
|
|
e := fmt.Errorf("parentDepart.CompanyId != param.CompanyID")
|
|
|
log.Error(e.Error())
|
|
|
return protocol.NewErrWithMessage("1", e)
|
|
|
}
|
|
|
}
|
|
|
for _, v := range param.Managers {
|
|
|
_, err = models.GetUserCompanyBy(v, param.CompanyID)
|
|
|
if err != nil {
|
|
|
e := fmt.Errorf("GetUserCompanyBy(%d, %d)", v, param.CompanyID)
|
|
|
log.Error(e.Error())
|
|
|
return protocol.NewErrWithMessage("1", e)
|
|
|
}
|
|
|
}
|
|
|
departmentAdd := &models.Department{
|
|
|
CompanyId: param.CompanyID,
|
|
|
Name: param.Name,
|
|
|
CreateAt: time.Now(),
|
|
|
ParentId: param.ParantID,
|
|
|
Member: 0,
|
|
|
}
|
|
|
departmentAdd.SetRelation(parentDepart)
|
|
|
_, err = models.AddDepartment(departmentAdd)
|
|
|
if err != nil {
|
|
|
e := fmt.Errorf("AddDepartment err:%s", err)
|
|
|
log.Error(e.Error())
|
|
|
return protocol.NewErrWithMessage("1", e)
|
|
|
}
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
...
|
...
|
@@ -74,7 +111,7 @@ func DepartmentEdit(param protocol.RequestDepartmentEdit) error { |
|
|
//更新部门关系数据
|
|
|
err = departmentRelationUpdate(departUpdate, newparent)
|
|
|
if err != nil {
|
|
|
e := fmt.Errorf(" departmentRelationUpdate err:%s", err)
|
|
|
e := fmt.Errorf("departmentRelationUpdate err:%s", err)
|
|
|
log.Error(e.Error())
|
|
|
return protocol.NewErrWithMessage("1", e)
|
|
|
}
|
...
|
...
|
@@ -107,7 +144,16 @@ func departmentRelationUpdate(old *models.Department, newparent *models.Departme |
|
|
log.Error(e.Error())
|
|
|
return protocol.NewErrWithMessage("1", e)
|
|
|
}
|
|
|
|
|
|
for i := range departSubset {
|
|
|
if departSubset[i].Id == newparent.Id {
|
|
|
//确认新的父级id是否合法
|
|
|
o.Rollback()
|
|
|
e := fmt.Errorf("departSubset[i].Id == newparent.Id")
|
|
|
log.Error(e.Error())
|
|
|
return protocol.NewErrWithMessage("1", e)
|
|
|
}
|
|
|
//重建关系树
|
|
|
s := strings.TrimPrefix(departSubset[i].Relation, oldrelation)
|
|
|
departSubset[i].Relation = strings.TrimSpace(fmt.Sprintf("%s%s", newRelation, s))
|
|
|
err := utils.ExcuteSQLWithOrmer(o, dataSql2, departSubset[i].Relation, departSubset[i].Id)
|
...
|
...
|
|