...
|
...
|
@@ -18,6 +18,10 @@ func DepartmentAdd(param protocol.RequestDepartmentAdd) (protocol.ResponseDepart |
|
|
returndata protocol.ResponseDepartmenrAdd
|
|
|
err error
|
|
|
)
|
|
|
if param.ParentID == 0 {
|
|
|
//部门必定有上级部门 ,至少是公司一级
|
|
|
return returndata, protocol.NewErrWithMessage("10042")
|
|
|
}
|
|
|
if param.ParentID > 0 {
|
|
|
parentDepart, err = models.GetDepartmentById(param.ParentID)
|
|
|
if err != nil {
|
...
|
...
|
@@ -100,22 +104,46 @@ func DepartmentEdit(param protocol.RequestDepartmentEdit) error { |
|
|
log.Error(e.Error())
|
|
|
return protocol.NewErrWithMessage("1", e)
|
|
|
}
|
|
|
//校验数据
|
|
|
if ok := departUpdate.IsTopDepartment(); ok {
|
|
|
//公司一级不能修改上级,不能修改名称
|
|
|
param.Name = departUpdate.Name
|
|
|
param.ParentID = departUpdate.ParentId
|
|
|
} else {
|
|
|
if param.ParentID <= 0 {
|
|
|
return protocol.NewErrWithMessage("10042")
|
|
|
}
|
|
|
}
|
|
|
//确认部门主管变更情况
|
|
|
var (
|
|
|
oldmanage []int64
|
|
|
newManage []int64
|
|
|
)
|
|
|
oldmanage = departUpdate.GetManagesIds()
|
|
|
diffmanage := utils.ArrayInt64Diff(param.Managers, oldmanage)
|
|
|
for i := range diffmanage {
|
|
|
_, err = models.GetUserCompanyBy(diffmanage[i], param.CompanyID)
|
|
|
if err != nil {
|
|
|
e := fmt.Errorf("GetUserCompanyBy(userid,companyid)[%d,%d] err:%s", diffmanage[i], param.CompanyID, err)
|
|
|
//oldmanage = departUpdate.GetManagesIds()
|
|
|
//diffmanage := utils.ArrayInt64Diff(param.Managers, oldmanage)
|
|
|
uc, err := models.GetUserCompanyReal(param.Managers)
|
|
|
if err != nil {
|
|
|
e := fmt.Errorf("GetUserCompanyReal err:%s", err)
|
|
|
log.Error(e.Error())
|
|
|
return protocol.NewErrWithMessage("10041")
|
|
|
}
|
|
|
for i := range uc {
|
|
|
if uc[i].CompanyId != param.CompanyID {
|
|
|
e := fmt.Errorf("managers err")
|
|
|
log.Error(e.Error())
|
|
|
return protocol.NewErrWithMessage("1", e)
|
|
|
return protocol.NewErrWithMessage("10041")
|
|
|
}
|
|
|
//检查设置的主管是否是部门下的人员
|
|
|
ok := models.ExistUserDepart(param.ID, uc[i].Id)
|
|
|
if !ok {
|
|
|
log.Error("false=aExistUserDepart(departid,usercompanyid) [%d,%d]", param.ID, uc[i].Id)
|
|
|
return protocol.NewErrWithMessage("10041")
|
|
|
}
|
|
|
newManage = append(newManage, uc[i].Id)
|
|
|
}
|
|
|
departUpdate.SetManages(param.Managers)
|
|
|
departUpdate.SetManages(newManage)
|
|
|
|
|
|
departUpdate.Name = param.Name
|
|
|
|
|
|
departUpdate.UpdateAt = time.Now()
|
|
|
err = models.UpdateDepartmentById(departUpdate, []string{"Manages", "Name", "UpdateAt"})
|
|
|
if err != nil {
|
...
|
...
|
@@ -127,7 +155,9 @@ func DepartmentEdit(param protocol.RequestDepartmentEdit) error { |
|
|
var (
|
|
|
newparent *models.Department
|
|
|
)
|
|
|
|
|
|
if departUpdate.ParentId != param.ParentID {
|
|
|
//检查上级部门是否合法
|
|
|
newparent, err = models.GetDepartmentById(param.ParentID)
|
|
|
if err != nil {
|
|
|
e := fmt.Errorf("GetDepartmentById(%d) err:%s", param.ParentID, err)
|
...
|
...
|
@@ -195,7 +225,7 @@ func departmentRelationUpdate(departUpdate *models.Department, newparent *models |
|
|
o.Rollback()
|
|
|
e := fmt.Errorf("departSubset[i].Id == newparent.Id")
|
|
|
log.Error(e.Error())
|
|
|
return protocol.NewErrWithMessage("1", e)
|
|
|
return protocol.NewErrWithMessage("10042")
|
|
|
}
|
|
|
//重建关系树
|
|
|
s := strings.TrimPrefix(departSubset[i].Relation, oldRelation)
|
...
|
...
|
@@ -234,6 +264,10 @@ func DepartmentDelete(param protocol.RequestDepartmentDelete) error { |
|
|
log.Error(e.Error())
|
|
|
return protocol.NewErrWithMessage("1", e)
|
|
|
}
|
|
|
//一级部门不能删除
|
|
|
if ok := p.IsTopDepartment(); ok {
|
|
|
continue
|
|
|
}
|
|
|
if p.CompanyId != param.CompanyID {
|
|
|
e := fmt.Errorf("CompanyID err")
|
|
|
log.Error(e.Error())
|
...
|
...
|
|