...
|
...
|
@@ -18,9 +18,10 @@ func DepartmentAdd(param protocol.RequestDepartmentAdd) (protocol.ResponseDepart |
|
|
returndata protocol.ResponseDepartmenrAdd
|
|
|
err error
|
|
|
)
|
|
|
if param.ParentID == 0 {
|
|
|
//部门必定有上级部门 ,至少是公司一级
|
|
|
return returndata, protocol.NewErrWithMessage("10042")
|
|
|
|
|
|
ok := models.ExistDepartmentName(param.ParentID, param.Name)
|
|
|
if ok {
|
|
|
return returndata, protocol.NewErrWithMessage("10045")
|
|
|
}
|
|
|
if param.ParentID > 0 {
|
|
|
parentDepart, err = models.GetDepartmentById(param.ParentID)
|
...
|
...
|
@@ -34,6 +35,12 @@ func DepartmentAdd(param protocol.RequestDepartmentAdd) (protocol.ResponseDepart |
|
|
log.Error(e.Error())
|
|
|
return returndata, protocol.NewErrWithMessage("1", e)
|
|
|
}
|
|
|
|
|
|
r := parentDepart.Relation
|
|
|
rs := strings.Split(r, "/")
|
|
|
if len(rs) >= 10 {
|
|
|
return returndata, protocol.NewErrWithMessage("10046")
|
|
|
}
|
|
|
}
|
|
|
// for _, v := range param.Managers {
|
|
|
// uc, err := models.GetUserCompanyReal([]int64{v})
|
...
|
...
|
@@ -55,6 +62,7 @@ func DepartmentAdd(param protocol.RequestDepartmentAdd) (protocol.ResponseDepart |
|
|
Name: param.Name,
|
|
|
CreateAt: time.Now(),
|
|
|
UpdateAt: time.Now(),
|
|
|
DeleteAt: time.Now(),
|
|
|
ParentId: param.ParentID,
|
|
|
}
|
|
|
departmentAdd.SetManages(nil)
|
...
|
...
|
@@ -74,7 +82,8 @@ func DepartmentAdd(param protocol.RequestDepartmentAdd) (protocol.ResponseDepart |
|
|
log.Error(e.Error())
|
|
|
return returndata, protocol.NewErrWithMessage("1", e)
|
|
|
}
|
|
|
err = models.UpdateDepartmentById(departmentAdd, []string{"Relation"}, o)
|
|
|
departmentAdd.DeleteAt = time.Unix(0, 0)
|
|
|
err = models.UpdateDepartmentById(departmentAdd, []string{"Relation", "DeleteAt"}, o)
|
|
|
if err != nil {
|
|
|
o.Rollback()
|
|
|
e := fmt.Errorf("UpdateDepartmentById err:%s", err)
|
...
|
...
|
@@ -114,6 +123,12 @@ func DepartmentEdit(param protocol.RequestDepartmentEdit) error { |
|
|
return protocol.NewErrWithMessage("10042")
|
|
|
}
|
|
|
}
|
|
|
if param.Name != departUpdate.Name {
|
|
|
ok := models.ExistDepartmentName(param.ParentID, param.Name)
|
|
|
if ok {
|
|
|
return protocol.NewErrWithMessage("10045")
|
|
|
}
|
|
|
}
|
|
|
//确认部门主管变更情况
|
|
|
var (
|
|
|
newManage []int64
|
...
|
...
|
@@ -253,7 +268,7 @@ func DepartmentDelete(param protocol.RequestDepartmentDelete) error { |
|
|
)
|
|
|
const (
|
|
|
//获取部门子集,
|
|
|
dataSql0 string = `SELECT id,relation,member FROM department WHERE relation LIKE ? AND delete_at = 0 `
|
|
|
dataSql0 string = `SELECT id,relation FROM department WHERE relation LIKE ? AND delete_at = 0 `
|
|
|
dataSql2 string = `update department set delete_at=? where relation LIKE ?`
|
|
|
)
|
|
|
for _, id := range param.IDs {
|
...
|
...
|
@@ -289,7 +304,7 @@ func DepartmentDelete(param protocol.RequestDepartmentDelete) error { |
|
|
cnt, err := models.CountUserDepartByDepart(subset.Id)
|
|
|
if err != nil {
|
|
|
log.Error("CountUserDepartByDepart err:%s", err)
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
return protocol.NewErrWithMessage("10047")
|
|
|
}
|
|
|
if cnt > 0 {
|
|
|
e := fmt.Errorf("user in department,relation:%s", subset.Relation)
|
...
|
...
|
@@ -327,7 +342,7 @@ func DepartmentListAll(companyId int64) ([]protocol.ResponseDepartmentInfo, erro |
|
|
err error
|
|
|
)
|
|
|
const (
|
|
|
datasql0 string = `SELECT id, company_id,name,parent_id,member,managers ` +
|
|
|
datasql0 string = `SELECT id, company_id,name,parent_id,managers ` +
|
|
|
` FROM department WHERE company_id = ? AND delete_at = 0`
|
|
|
)
|
|
|
err = utils.ExecuteQueryAll(&departmodels, datasql0, companyId)
|
...
|
...
|
|