正在显示
5 个修改的文件
包含
70 行增加
和
3 行删除
@@ -87,3 +87,23 @@ func (c *CommonController) SelectorPosition() { | @@ -87,3 +87,23 @@ func (c *CommonController) SelectorPosition() { | ||
87 | msg = protocol.NewReturnResponse(departs, nil) | 87 | msg = protocol.NewReturnResponse(departs, nil) |
88 | return | 88 | return |
89 | } | 89 | } |
90 | + | ||
91 | +func (c *CommonController) SelectorUserAndDepart() { | ||
92 | + var msg *protocol.ResponseMessage | ||
93 | + defer func() { | ||
94 | + c.ResposeJson(msg) | ||
95 | + }() | ||
96 | + type Parameter struct { | ||
97 | + DepartmentId int64 `json:"department_id"` | ||
98 | + } | ||
99 | + var param Parameter | ||
100 | + if err := json.Unmarshal(c.Ctx.Input.RequestBody, ¶m); err != nil { | ||
101 | + log.Error("json 解析失败 err:%s", err) | ||
102 | + msg = protocol.BadRequestParam("1") | ||
103 | + return | ||
104 | + } | ||
105 | + companyid := c.GetCompanyId() | ||
106 | + departs, err := servecommon.SelectorUserAndDepartment(param.DepartmentId, companyid) | ||
107 | + msg = protocol.NewReturnResponse(departs, err) | ||
108 | + return | ||
109 | +} |
@@ -90,8 +90,8 @@ var AllowOption = func(ctx *context.Context) { | @@ -90,8 +90,8 @@ var AllowOption = func(ctx *context.Context) { | ||
90 | AllowAllOrigins: true, //允许的请求来源 | 90 | AllowAllOrigins: true, //允许的请求来源 |
91 | }) | 91 | }) |
92 | f(ctx) | 92 | f(ctx) |
93 | - ctx.Output.Body([]byte("{}")) | ||
94 | ctx.Output.SetStatus(204) | 93 | ctx.Output.SetStatus(204) |
94 | + ctx.Output.Body([]byte("{}")) | ||
95 | return | 95 | return |
96 | } | 96 | } |
97 | 97 |
@@ -17,7 +17,7 @@ type ResponsePageInfo struct { | @@ -17,7 +17,7 @@ type ResponsePageInfo struct { | ||
17 | type DepartmentBase struct { | 17 | type DepartmentBase struct { |
18 | Id int64 `json:"id" orm:"column(id)"` | 18 | Id int64 `json:"id" orm:"column(id)"` |
19 | Name string `json:"name" orm:"column(name)"` | 19 | Name string `json:"name" orm:"column(name)"` |
20 | - ParentId int64 `json:"parent_id" orm:"column(parent_id)"` | 20 | + ParentId int64 `json:"parentId" orm:"column(parent_id)"` |
21 | } | 21 | } |
22 | 22 | ||
23 | //RoleBase 下拉选择列表-角色 | 23 | //RoleBase 下拉选择列表-角色 |
@@ -33,7 +33,7 @@ type RoleBase struct { | @@ -33,7 +33,7 @@ type RoleBase struct { | ||
33 | type PositionBase struct { | 33 | type PositionBase struct { |
34 | Id int64 `json:"id" orm:"column(id)"` | 34 | Id int64 `json:"id" orm:"column(id)"` |
35 | Name string `json:"name" orm:"column(name)"` | 35 | Name string `json:"name" orm:"column(name)"` |
36 | - ParentId int64 `json:"parent_id" orm:"column(parent_id)"` | 36 | + ParentId int64 `json:"parentId" orm:"column(parent_id)"` |
37 | } | 37 | } |
38 | 38 | ||
39 | //DepartUserBase 下拉选择列表-部门下的人员 | 39 | //DepartUserBase 下拉选择列表-部门下的人员 |
@@ -41,3 +41,9 @@ type DepartUserBase struct { | @@ -41,3 +41,9 @@ type DepartUserBase struct { | ||
41 | UserCompanyId int64 `json:"id" orm:"column(user_company_id)"` | 41 | UserCompanyId int64 `json:"id" orm:"column(user_company_id)"` |
42 | Name string `json:"name" orm:"-"` | 42 | Name string `json:"name" orm:"-"` |
43 | } | 43 | } |
44 | + | ||
45 | +//部门和人员混合 | ||
46 | +type DepartAndUser struct { | ||
47 | + Departments []DepartmentBase `json:"departments"` | ||
48 | + Members []DepartmentMember `json:"members"` | ||
49 | +} |
@@ -64,6 +64,7 @@ func init() { | @@ -64,6 +64,7 @@ func init() { | ||
64 | beego.NSRouter("/department", &controllers.CommonController{}, "post:SelectorDepartment"), | 64 | beego.NSRouter("/department", &controllers.CommonController{}, "post:SelectorDepartment"), |
65 | beego.NSRouter("/role", &controllers.CommonController{}, "post:SelectorRole"), | 65 | beego.NSRouter("/role", &controllers.CommonController{}, "post:SelectorRole"), |
66 | beego.NSRouter("/position", &controllers.CommonController{}, "post:SelectorPosition"), | 66 | beego.NSRouter("/position", &controllers.CommonController{}, "post:SelectorPosition"), |
67 | + beego.NSRouter("/user_and_department", &controllers.CommonController{}, "post:SelectorUserAndDepart"), | ||
67 | ), | 68 | ), |
68 | beego.NSNamespace("/template", | 69 | beego.NSNamespace("/template", |
69 | beego.NSRouter("/add", &controllers.TemplateController{}, "post:TemplateAdd"), | 70 | beego.NSRouter("/add", &controllers.TemplateController{}, "post:TemplateAdd"), |
@@ -105,3 +105,43 @@ func SelectorPosition(companyid int64) []protocol.PositionBase { | @@ -105,3 +105,43 @@ func SelectorPosition(companyid int64) []protocol.PositionBase { | ||
105 | return positions | 105 | return positions |
106 | 106 | ||
107 | } | 107 | } |
108 | + | ||
109 | +func SelectorUserAndDepartment(departid int64, companyId int64) (*protocol.DepartAndUser, error) { | ||
110 | + var ( | ||
111 | + mDepart *models.Department | ||
112 | + departsUser protocol.DepartAndUser | ||
113 | + departbase []protocol.DepartmentBase | ||
114 | + departMember []protocol.DepartmentMember | ||
115 | + err error | ||
116 | + where string | ||
117 | + cond []interface{} | ||
118 | + ) | ||
119 | + if departid > 0 { | ||
120 | + mDepart, err = models.GetDepartmentById(departid) | ||
121 | + if err != nil { | ||
122 | + log.Error("GetDepartmentById err:%s", err) | ||
123 | + return nil, protocol.NewErrWithMessage("1") | ||
124 | + } | ||
125 | + if mDepart.CompanyId != companyId { | ||
126 | + log.Error("companyid err") | ||
127 | + return nil, protocol.NewErrWithMessage("1") | ||
128 | + } | ||
129 | + departMember = mDepart.GetMembers() | ||
130 | + departsUser.Members = departMember | ||
131 | + } | ||
132 | + datasql0 := `SELECT id, company_id,name,parent_id ` + | ||
133 | + ` FROM department WHERE company_id = ? AND delete_at = 0 ` | ||
134 | + cond = append(cond, companyId) | ||
135 | + if departid >= 0 { | ||
136 | + cond = append(cond, departid) | ||
137 | + where += ` AND parent_id =? ` | ||
138 | + } | ||
139 | + err = utils.ExecuteQueryAll(&departbase, datasql0+where, cond...) | ||
140 | + if err != nil { | ||
141 | + e := fmt.Errorf("EXECUTE SQL err:%s", err) | ||
142 | + log.Error(e.Error()) | ||
143 | + return nil, protocol.NewErrWithMessage("1", err) | ||
144 | + } | ||
145 | + departsUser.Departments = departbase | ||
146 | + return &departsUser, nil | ||
147 | +} |
-
请 注册 或 登录 后发表评论