...
|
...
|
@@ -370,3 +370,49 @@ func DepartmentListAll(companyId int64) ([]protocol.ResponseDepartmentInfo, erro |
|
|
|
|
|
return departs, nil
|
|
|
}
|
|
|
|
|
|
//获取部门下的人员
|
|
|
func GetDepartmentUser(companyid int64, departmentid int64) ([]protocol.DepartUserBase, error) {
|
|
|
var (
|
|
|
department *models.Department
|
|
|
err error
|
|
|
)
|
|
|
department, err = models.GetDepartmentById(departmentid)
|
|
|
if err != nil {
|
|
|
log.Error("获取部门失败:%s", err)
|
|
|
return nil, protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
if department.CompanyId != companyid {
|
|
|
log.Error("deparment.CompanyId err")
|
|
|
return nil, protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
const dataSql string = `SELECT b.user_id,b.id AS user_company_id FROM user_department AS a
|
|
|
JOIN user_company AS b ON a.user_company_id = b.id
|
|
|
WHERE a.department_id=? AND b.delete_at=0 `
|
|
|
type UsercompanyId struct {
|
|
|
UserCompanyId int64 `orm:"column(user_company_id)"`
|
|
|
UserId int64 `orm:"column(user_id)"`
|
|
|
}
|
|
|
var (
|
|
|
usercompanyData []UsercompanyId
|
|
|
returnData []protocol.DepartUserBase
|
|
|
)
|
|
|
err = utils.ExecuteQueryAll(&usercompanyData, dataSql, department.Id)
|
|
|
if err != nil {
|
|
|
log.Error("EXECUTE SQL err:%s", err)
|
|
|
return nil, protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
for _, v := range usercompanyData {
|
|
|
udata, err := models.GetUserById(v.UserId)
|
|
|
if err != nil {
|
|
|
log.Error("获取user数据失败:%s", err)
|
|
|
continue
|
|
|
}
|
|
|
d := protocol.DepartUserBase{
|
|
|
UserCompanyId: v.UserCompanyId,
|
|
|
Name: udata.NickName,
|
|
|
}
|
|
|
returnData = append(returnData, d)
|
|
|
}
|
|
|
return nil, nil
|
|
|
} |
...
|
...
|
|