作者 唐旭辉

Merge branch 'dev' of http://gitlab.fjmaimaimai.com/mmm-go/oppmg into dev

# Conflicts:
#	services/company/department.go
@@ -83,7 +83,7 @@ func (this *TemplateController) TemplateList() { @@ -83,7 +83,7 @@ func (this *TemplateController) TemplateList() {
83 defer func() { 83 defer func() {
84 this.ResposeJson(msg) 84 this.ResposeJson(msg)
85 }() 85 }()
86 - var request *protocol.TemplateUpdateRequest 86 + var request *protocol.TemplateListRequest
87 87
88 if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil { 88 if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil {
89 log.Error("json 解析失败", err) 89 log.Error("json 解析失败", err)
@@ -101,11 +101,40 @@ func (this *TemplateController) TemplateList() { @@ -101,11 +101,40 @@ func (this *TemplateController) TemplateList() {
101 msg = m 101 msg = m
102 return 102 return
103 } 103 }
104 - rsp, err := audit.TemplateUpdate(uid, companyId, request) 104 + rsp, err := audit.TemplateList(uid, companyId, request)
105 msg = protocol.NewReturnResponse(rsp, err) 105 msg = protocol.NewReturnResponse(rsp, err)
106 return 106 return
107 } 107 }
108 108
  109 +//TemplateGet
  110 +//@router /templateGet [post]
  111 +func (this *TemplateController) TemplateGet() {
  112 + var msg *protocol.ResponseMessage
  113 + defer func() {
  114 + this.ResposeJson(msg)
  115 + }()
  116 + var request *protocol.TemplateGetRequest
  117 +
  118 + if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil {
  119 + log.Error("json 解析失败", err)
  120 + msg = protocol.BadRequestParam("1")
  121 + return
  122 + }
  123 + uid := this.GetUserId()
  124 + companyId := this.GetCompanyId()
  125 + if companyId <= 0 {
  126 + log.Debug("companyId:%d err", companyId)
  127 + msg = protocol.BadRequestParam("1")
  128 + return
  129 + }
  130 + if b, m := this.Valid(request); !b {
  131 + msg = m
  132 + return
  133 + }
  134 + rsp, err := audit.TemplateGet(uid, companyId, request)
  135 + msg = protocol.NewReturnResponse(rsp, err)
  136 +}
  137 +
109 //TemplateEditVisible 138 //TemplateEditVisible
110 //@router /templateEditVisible [post] 139 //@router /templateEditVisible [post]
111 func (this *TemplateController) TemplateEditVisible() { 140 func (this *TemplateController) TemplateEditVisible() {
@@ -84,6 +84,27 @@ func (t *Department) GetManages() []protocol.DepartmentManager { @@ -84,6 +84,27 @@ func (t *Department) GetManages() []protocol.DepartmentManager {
84 return managesdata 84 return managesdata
85 } 85 }
86 86
  87 +func (t *Department) GetMembers() []protocol.DepartmentMember {
  88 + ids, err := GetUserDepartmentIds(int(t.CompanyId), int(t.Id))
  89 + if err != nil {
  90 + log.Error(err.Error())
  91 + return nil
  92 + }
  93 + users, err := getUserNameByIds(ids)
  94 + if err != nil {
  95 + log.Error("GetUserNameByIds err :%s", err)
  96 + return nil
  97 + }
  98 + managesdata := []protocol.DepartmentMember{}
  99 + for _, v := range users {
  100 + m := protocol.DepartmentMember{
  101 + Id: v.Id, Name: v.NickName,
  102 + }
  103 + managesdata = append(managesdata, m)
  104 + }
  105 + return managesdata
  106 +}
  107 +
87 // AddDepartment insert a new Department into database and returns 108 // AddDepartment insert a new Department into database and returns
88 // last inserted Id on success. 109 // last inserted Id on success.
89 func AddDepartment(m *Department, om ...orm.Ormer) (id int64, err error) { 110 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"`
@@ -37,6 +42,7 @@ type ResponseDepartmentInfo struct { @@ -37,6 +42,7 @@ type ResponseDepartmentInfo struct {
37 Name string `json:"name"` //部门名字 42 Name string `json:"name"` //部门名字
38 ParantID int64 `json:"parant_id"` //父级部门Id 43 ParantID int64 `json:"parant_id"` //父级部门Id
39 Manages []DepartmentManager `json:"manages"` //部门管理员 44 Manages []DepartmentManager `json:"manages"` //部门管理员
  45 + Members []DepartmentMember `json:"members"` //部门成员
40 Member int64 `json:"member"` //成员数 46 Member int64 `json:"member"` //成员数
41 } 47 }
42 48
@@ -56,6 +56,14 @@ func init() { @@ -56,6 +56,14 @@ func init() {
56 beego.NSRouter("/role", &controllers.CommonController{}, "post:SelectorRole"), 56 beego.NSRouter("/role", &controllers.CommonController{}, "post:SelectorRole"),
57 beego.NSRouter("/position", &controllers.CommonController{}, "post:SelectorPosition"), 57 beego.NSRouter("/position", &controllers.CommonController{}, "post:SelectorPosition"),
58 ), 58 ),
  59 + beego.NSNamespace("/template",
  60 + beego.NSRouter("/add", &controllers.TemplateController{}, "post:TemplateAdd"),
  61 + beego.NSRouter("/list", &controllers.TemplateController{}, "post:TemplateList"),
  62 + beego.NSRouter("/get", &controllers.TemplateController{}, "post:TemplateGet"),
  63 + beego.NSRouter("/update", &controllers.TemplateController{}, "post:TemplateUpdate"),
  64 + beego.NSRouter("/editVisible", &controllers.TemplateController{}, "post:TemplateEditVisible"),
  65 + beego.NSRouter("/operateCategory", &controllers.TemplateController{}, "post:TemplateOperateCategory"),
  66 + ),
59 ) 67 )
60 68
61 nsAuth := beego.NewNamespace("/auth", 69 nsAuth := beego.NewNamespace("/auth",
@@ -315,6 +315,7 @@ func DepartmentListAll(companyId int64) ([]protocol.ResponseDepartmentInfo, erro @@ -315,6 +315,7 @@ func DepartmentListAll(companyId int64) ([]protocol.ResponseDepartmentInfo, erro
315 var manage []protocol.DepartmentManager 315 var manage []protocol.DepartmentManager
316 manage = v.GetManages() 316 manage = v.GetManages()
317 depart.Manages = manage 317 depart.Manages = manage
  318 + depart.Members = v.GetMembers()
318 departs = append(departs, depart) 319 departs = append(departs, depart)
319 } 320 }
320 321