正在显示
4 个修改的文件
包含
42 行增加
和
1 行删除
| @@ -75,6 +75,27 @@ func (t *Department) GetManages() []protocol.DepartmentManager { | @@ -75,6 +75,27 @@ func (t *Department) GetManages() []protocol.DepartmentManager { | ||
| 75 | return managesdata | 75 | return managesdata |
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | +func (t *Department) GetMembers() []protocol.DepartmentMember { | ||
| 79 | + ids, err := GetUserDepartmentIds(int(t.CompanyId), int(t.Id)) | ||
| 80 | + if err != nil { | ||
| 81 | + log.Error(err.Error()) | ||
| 82 | + return nil | ||
| 83 | + } | ||
| 84 | + users, err := getUserNameByIds(ids) | ||
| 85 | + if err != nil { | ||
| 86 | + log.Error("GetUserNameByIds err :%s", err) | ||
| 87 | + return nil | ||
| 88 | + } | ||
| 89 | + managesdata := []protocol.DepartmentMember{} | ||
| 90 | + for _, v := range users { | ||
| 91 | + m := protocol.DepartmentMember{ | ||
| 92 | + Id: v.Id, Name: v.NickName, | ||
| 93 | + } | ||
| 94 | + managesdata = append(managesdata, m) | ||
| 95 | + } | ||
| 96 | + return managesdata | ||
| 97 | +} | ||
| 98 | + | ||
| 78 | // AddDepartment insert a new Department into database and returns | 99 | // AddDepartment insert a new Department into database and returns |
| 79 | // last inserted Id on success. | 100 | // last inserted Id on success. |
| 80 | func AddDepartment(m *Department, om ...orm.Ormer) (id int64, err error) { | 101 | func AddDepartment(m *Department, om ...orm.Ormer) (id int64, err error) { |
| @@ -112,3 +112,16 @@ func CountUserDepartByDepart(departid int64) (int64, error) { | @@ -112,3 +112,16 @@ func CountUserDepartByDepart(departid int64) (int64, error) { | ||
| 112 | Count() | 112 | Count() |
| 113 | return cnt, err | 113 | return cnt, err |
| 114 | } | 114 | } |
| 115 | + | ||
| 116 | +func GetUserDepartmentIds(companyId, dId int) (v []int64, err error) { | ||
| 117 | + o := orm.NewOrm() | ||
| 118 | + sql := ` | ||
| 119 | + select user_id from user_company where company_id=? and id in ( | ||
| 120 | + select user_company_id from user_department where company_id=? and department_id=? and enable=1 | ||
| 121 | + ) | ||
| 122 | +` | ||
| 123 | + if _, err = o.Raw(sql, companyId, companyId, dId).QueryRows(&v); err != nil { | ||
| 124 | + return | ||
| 125 | + } | ||
| 126 | + return | ||
| 127 | +} |
| @@ -17,6 +17,11 @@ type DepartmentManager struct { | @@ -17,6 +17,11 @@ type DepartmentManager struct { | ||
| 17 | Name string `json:"name"` | 17 | Name string `json:"name"` |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | +type DepartmentMember struct { | ||
| 21 | + Id int64 `json:"id"` | ||
| 22 | + Name string `json:"name"` | ||
| 23 | +} | ||
| 24 | + | ||
| 20 | //RequestDepartmentEdit 编辑 | 25 | //RequestDepartmentEdit 编辑 |
| 21 | type RequestDepartmentEdit struct { | 26 | type RequestDepartmentEdit struct { |
| 22 | ID int64 `json:"id"` | 27 | ID int64 `json:"id"` |
| @@ -36,6 +41,7 @@ type ResponseDepartmentInfo struct { | @@ -36,6 +41,7 @@ type ResponseDepartmentInfo struct { | ||
| 36 | Name string `json:"name"` //部门名字 | 41 | Name string `json:"name"` //部门名字 |
| 37 | ParantID int64 `json:"parant_id"` //父级部门Id | 42 | ParantID int64 `json:"parant_id"` //父级部门Id |
| 38 | Manages []DepartmentManager `json:"manages"` //部门管理员 | 43 | Manages []DepartmentManager `json:"manages"` //部门管理员 |
| 44 | + Members []DepartmentMember `json:"members"` //部门成员 | ||
| 39 | Member int64 `json:"member"` //成员数 | 45 | Member int64 `json:"member"` //成员数 |
| 40 | } | 46 | } |
| 41 | 47 |
| @@ -286,7 +286,7 @@ func DepartmentListAll(companyId int64) ([]protocol.ResponseDepartmentInfo, erro | @@ -286,7 +286,7 @@ func DepartmentListAll(companyId int64) ([]protocol.ResponseDepartmentInfo, erro | ||
| 286 | err error | 286 | err error |
| 287 | ) | 287 | ) |
| 288 | const ( | 288 | const ( |
| 289 | - datasql0 string = `SELECT id, company_id,name,parent_id,member,managers,delete_at ` + | 289 | + datasql0 string = `SELECT id, company_id,name,parent_id,managers,delete_at ` + |
| 290 | ` FROM department WHERE company_id = ? AND delete_at = 0` | 290 | ` FROM department WHERE company_id = ? AND delete_at = 0` |
| 291 | ) | 291 | ) |
| 292 | err = utils.ExecuteQueryAll(&departmodels, datasql0, companyId) | 292 | err = utils.ExecuteQueryAll(&departmodels, datasql0, companyId) |
| @@ -308,6 +308,7 @@ func DepartmentListAll(companyId int64) ([]protocol.ResponseDepartmentInfo, erro | @@ -308,6 +308,7 @@ func DepartmentListAll(companyId int64) ([]protocol.ResponseDepartmentInfo, erro | ||
| 308 | var manage []protocol.DepartmentManager | 308 | var manage []protocol.DepartmentManager |
| 309 | manage = v.GetManages() | 309 | manage = v.GetManages() |
| 310 | depart.Manages = manage | 310 | depart.Manages = manage |
| 311 | + depart.Members = v.GetMembers() | ||
| 311 | departs = append(departs, depart) | 312 | departs = append(departs, depart) |
| 312 | } | 313 | } |
| 313 | 314 |
-
请 注册 或 登录 后发表评论