...
|
...
|
@@ -105,3 +105,43 @@ func SelectorPosition(companyid int64) []protocol.PositionBase { |
|
|
return positions
|
|
|
|
|
|
}
|
|
|
|
|
|
func SelectorUserAndDepartment(departid int64, companyId int64) (*protocol.DepartAndUser, error) {
|
|
|
var (
|
|
|
mDepart *models.Department
|
|
|
departsUser protocol.DepartAndUser
|
|
|
departbase []protocol.DepartmentBase
|
|
|
departMember []protocol.DepartmentMember
|
|
|
err error
|
|
|
where string
|
|
|
cond []interface{}
|
|
|
)
|
|
|
if departid > 0 {
|
|
|
mDepart, err = models.GetDepartmentById(departid)
|
|
|
if err != nil {
|
|
|
log.Error("GetDepartmentById err:%s", err)
|
|
|
return nil, protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
if mDepart.CompanyId != companyId {
|
|
|
log.Error("companyid err")
|
|
|
return nil, protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
departMember = mDepart.GetMembers()
|
|
|
departsUser.Members = departMember
|
|
|
}
|
|
|
datasql0 := `SELECT id, company_id,name,parent_id ` +
|
|
|
` FROM department WHERE company_id = ? AND delete_at = 0 `
|
|
|
cond = append(cond, companyId)
|
|
|
if departid >= 0 {
|
|
|
cond = append(cond, departid)
|
|
|
where += ` AND parent_id =? `
|
|
|
}
|
|
|
err = utils.ExecuteQueryAll(&departbase, datasql0+where, cond...)
|
|
|
if err != nil {
|
|
|
e := fmt.Errorf("EXECUTE SQL err:%s", err)
|
|
|
log.Error(e.Error())
|
|
|
return nil, protocol.NewErrWithMessage("1", err)
|
|
|
}
|
|
|
departsUser.Departments = departbase
|
|
|
return &departsUser, nil
|
|
|
} |
...
|
...
|
|