作者 yangfu

部门列表修改

... ... @@ -75,6 +75,27 @@ func (t *Department) GetManages() []protocol.DepartmentManager {
return managesdata
}
func (t *Department) GetMembers() []protocol.DepartmentMember {
ids, err := GetUserDepartmentIds(int(t.CompanyId), int(t.Id))
if err != nil {
log.Error(err.Error())
return nil
}
users, err := getUserNameByIds(ids)
if err != nil {
log.Error("GetUserNameByIds err :%s", err)
return nil
}
managesdata := []protocol.DepartmentMember{}
for _, v := range users {
m := protocol.DepartmentMember{
Id: v.Id, Name: v.NickName,
}
managesdata = append(managesdata, m)
}
return managesdata
}
// AddDepartment insert a new Department into database and returns
// last inserted Id on success.
func AddDepartment(m *Department, om ...orm.Ormer) (id int64, err error) {
... ...
... ... @@ -112,3 +112,16 @@ func CountUserDepartByDepart(departid int64) (int64, error) {
Count()
return cnt, err
}
func GetUserDepartmentIds(companyId, dId int) (v []int64, err error) {
o := orm.NewOrm()
sql := `
select user_id from user_company where company_id=? and id in (
select user_company_id from user_department where company_id=? and department_id=? and enable=1
)
`
if _, err = o.Raw(sql, companyId, companyId, dId).QueryRows(&v); err != nil {
return
}
return
}
... ...
... ... @@ -17,6 +17,11 @@ type DepartmentManager struct {
Name string `json:"name"`
}
type DepartmentMember struct {
Id int64 `json:"id"`
Name string `json:"name"`
}
//RequestDepartmentEdit 编辑
type RequestDepartmentEdit struct {
ID int64 `json:"id"`
... ... @@ -36,6 +41,7 @@ type ResponseDepartmentInfo struct {
Name string `json:"name"` //部门名字
ParantID int64 `json:"parant_id"` //父级部门Id
Manages []DepartmentManager `json:"manages"` //部门管理员
Members []DepartmentMember `json:"members"` //部门成员
Member int64 `json:"member"` //成员数
}
... ...
... ... @@ -286,7 +286,7 @@ func DepartmentListAll(companyId int64) ([]protocol.ResponseDepartmentInfo, erro
err error
)
const (
datasql0 string = `SELECT id, company_id,name,parent_id,member,managers,delete_at ` +
datasql0 string = `SELECT id, company_id,name,parent_id,managers,delete_at ` +
` FROM department WHERE company_id = ? AND delete_at = 0`
)
err = utils.ExecuteQueryAll(&departmodels, datasql0, companyId)
... ... @@ -308,6 +308,7 @@ func DepartmentListAll(companyId int64) ([]protocol.ResponseDepartmentInfo, erro
var manage []protocol.DepartmentManager
manage = v.GetManages()
depart.Manages = manage
depart.Members = v.GetMembers()
departs = append(departs, depart)
}
... ...