Merge branch 'dev' of http://gitlab.fjmaimaimai.com/mmm-go/oppmg into dev
正在显示
19 个修改的文件
包含
788 行增加
和
160 行删除
1 | ### 接口完成进度 | 1 | ### 接口完成进度 |
2 | 2 | ||
3 | -| 功能 | 完成状态 | 时间 | 接口路径 | 请求方式 | | ||
4 | -| ---------------- | ------------------ | --------------- | -------------------------- | -------- | | ||
5 | -| 登录获取 token | 完成 | 2018/12/11 | /auth/login | post | | ||
6 | -| 短信验证码 | 未开始 | | | | ||
7 | -| 刷新 token | 完成 | 2018/12/11 | /v1/auth/refresh_token | get | | ||
8 | -| 切换公司 | 完成 | 2018/12/11 | /v1/auth/change_company | post | | ||
9 | -| 获取个人基础数据 | 未开始 | | /v1/auth/me | get | | ||
10 | -| 获取角色列表 | 完成 | | /v1/rbac/role | get | | ||
11 | -| 添加角色 | 完成 | 2019.11.26 | /v1/rbac/role/add | post | | ||
12 | -| 编辑角色 | 完成 | 2019.11.26 | /v1/rbac/role/edit | post | | ||
13 | -| ~~删除角色~~ | ~~完成(待变更)~~ | ~~ 2019.11.26~~ | /v1/rbac/role/delete | post | | ||
14 | -| 删除角色 | 完成 | 2019.12.04 | /v1/rbac/role/delete | post | | ||
15 | -| 添加角色组 | 完成 | 2019.12.04 | /v1/rbac/role_group/add | post | | ||
16 | -| 编辑角色组 | 完成 | 2019.12.04 | /v1/rbac/role_group/edit | post | | ||
17 | -| 删除角色组 | 完成 | 2019.12.04 | /v1/rbac/role_group/delete | post | | ||
18 | -| 获取部门列表 | 完成 | 2019.12.5 | /v1/department | get | | ||
19 | -| 添加部门 | 完成 | 2019.11.28 | /v1/department/add | post | | ||
20 | -| 编辑部门 | 完成 | 2019.11.29 | /v1/department/edit | post | | ||
21 | -| ~~删除部门~~ | ~~完成(待变更)~~ | ~~2019.11.29~~ | ~~/v1/department~~ | post | | ||
22 | -| 删除部门 | 完成 | 2019.12.2 | /v1/department/delete | post | | ||
23 | -| 获取职位列表 | 进行中 | | /v1/position | get | | ||
24 | -| 添加职位 | 完成 | 2019.12.2 | /v1/position/add | post | | ||
25 | -| 编辑职位 | 完成 | 2019.12.2 | /v1/position/edit | post | | ||
26 | -| 删除职位 | 完成 | 2019.12.2 | /v1/position/delete | post | | ||
27 | -| 添加员工 | 未开始 | | /v1/company/user | post | | ||
28 | -| 编辑员工 | 未开始 | | /v1/company/user | post | | ||
29 | -| 删除员工 | 未开始 | | /v1/company/user | post | | ||
30 | -| 公告管理 | 未开始 | | | | | ||
31 | -| 公告管理 | 未开始 | | | | | ||
32 | -| 公告管理 | 未开始 | | | | | ||
33 | -| 机会&审批 模板 | 未开始 | | | | | ||
34 | -| 机会&审批 模板 | 未开始 | | | | | ||
35 | -| 机会&审批 模板 | 未开始 | | | | | ||
36 | -| 机会&审批 模板 | 未开始 | | | | | ||
37 | -| 机会类型设置 | 未开始 | | | | | ||
38 | -| 机会类型设置 | 未开始 | | | | | ||
39 | -| 机会类型设置 | 未开始 | | | | | ||
40 | -| 机会类型设置 | 未开始 | | | | | 3 | +| 功能 | 完成状态 | 时间 | 接口路径 | 请求方式 | |
4 | +| ---------------- | -------- | ---------- | -------------------------- | -------- | | ||
5 | +| 登录获取 token | 完成 | 2018/12/11 | /auth/login | post | | ||
6 | +| 短信验证码 | 未开始 | | | | ||
7 | +| 刷新 token | 完成 | 2018/12/11 | /v1/auth/refresh_token | get | | ||
8 | +| 切换公司 | 完成 | 2018/12/11 | /v1/auth/change_company | post | | ||
9 | +| 获取个人基础数据 | (暂停) | | /v1/auth/me | get | | ||
10 | +| 获取角色列表 | 完成 | | /v1/rbac/role | get | | ||
11 | +| 添加角色 | 完成 | 2019.11.26 | /v1/rbac/role/add | post | | ||
12 | +| 编辑角色 | 完成 | 2019.11.26 | /v1/rbac/role/edit | post | | ||
13 | +| 删除角色 | 完成 | 2019.12.04 | /v1/rbac/role/delete | post | | ||
14 | +| 添加角色组 | 完成 | 2019.12.04 | /v1/rbac/role_group/add | post | | ||
15 | +| 编辑角色组 | 完成 | 2019.12.04 | /v1/rbac/role_group/edit | post | | ||
16 | +| 删除角色组 | 完成 | 2019.12.04 | /v1/rbac/role_group/delete | post | | ||
17 | +| 获取部门列表 | 完成 | 2019.12.5 | /v1/department | get | | ||
18 | +| 添加部门 | 完成 | 2019.11.28 | /v1/department/add | post | | ||
19 | +| 编辑部门 | 完成 | 2019.11.29 | /v1/department/edit | post | | ||
20 | +| 删除部门 | 完成 | 2019.12.2 | /v1/department/delete | post | | ||
21 | +| 获取职位列表 | 进行中 | | /v1/position | get | | ||
22 | +| 添加职位 | 完成 | 2019.12.2 | /v1/position/add | post | | ||
23 | +| 编辑职位 | 完成 | 2019.12.2 | /v1/position/edit | post | | ||
24 | +| 删除职位 | 完成 | 2019.12.2 | /v1/position/delete | post | | ||
25 | +| 添加员工 | 未开始 | | /v1/company/user | post | | ||
26 | +| 编辑员工 | 未开始 | | /v1/company/user | post | | ||
27 | +| 删除员工 | 未开始 | | /v1/company/user | post | | ||
28 | +| 公告管理 | 未开始 | | | | | ||
29 | +| 公告管理 | 未开始 | | | | | ||
30 | +| 公告管理 | 未开始 | | | | | ||
31 | +| 机会&审批 模板 | 未开始 | | | | | ||
32 | +| 机会&审批 模板 | 未开始 | | | | | ||
33 | +| 机会&审批 模板 | 未开始 | | | | | ||
34 | +| 机会&审批 模板 | 未开始 | | | | | ||
35 | +| 机会类型设置 | 未开始 | | | | | ||
36 | +| 机会类型设置 | 未开始 | | | | | ||
37 | +| 机会类型设置 | 未开始 | | | | | ||
38 | +| 机会类型设置 | 未开始 | | | | |
@@ -96,13 +96,16 @@ func (c *AuthController) ChangeCompany() { | @@ -96,13 +96,16 @@ func (c *AuthController) ChangeCompany() { | ||
96 | return | 96 | return |
97 | } | 97 | } |
98 | 98 | ||
99 | +//me | ||
100 | +//@router /me [get] | ||
99 | func (c *AuthController) Me() { | 101 | func (c *AuthController) Me() { |
100 | var msg *protocol.ResponseMessage | 102 | var msg *protocol.ResponseMessage |
101 | defer func() { | 103 | defer func() { |
102 | c.ResposeJson(msg) | 104 | c.ResposeJson(msg) |
103 | }() | 105 | }() |
104 | - // userid := c.GetUserId() | ||
105 | - // companyid := c.GetCompanyId() | ||
106 | - | 106 | + userid := c.GetUserId() |
107 | + companyid := c.GetCompanyId() | ||
108 | + userinfo, err := serveauth.UserBaseInfo(userid, companyid) | ||
109 | + msg = protocol.NewReturnResponse(userinfo, err) | ||
107 | return | 110 | return |
108 | } | 111 | } |
@@ -63,7 +63,7 @@ func (c *CompanyController) DepartmentOne() { | @@ -63,7 +63,7 @@ func (c *CompanyController) DepartmentOne() { | ||
63 | } | 63 | } |
64 | 64 | ||
65 | // DepartmentAdd 添加部门 | 65 | // DepartmentAdd 添加部门 |
66 | -// @router /department [post] | 66 | +// @router /department/add [post] |
67 | func (c *CompanyController) DepartmentAdd() { | 67 | func (c *CompanyController) DepartmentAdd() { |
68 | var msg *protocol.ResponseMessage | 68 | var msg *protocol.ResponseMessage |
69 | defer func() { | 69 | defer func() { |
@@ -87,7 +87,7 @@ func (c *CompanyController) DepartmentAdd() { | @@ -87,7 +87,7 @@ func (c *CompanyController) DepartmentAdd() { | ||
87 | } | 87 | } |
88 | 88 | ||
89 | // DepartmentUpdate 更新部门 | 89 | // DepartmentUpdate 更新部门 |
90 | -// @router /department [put] | 90 | +// @router /department/edit [post] |
91 | func (c *CompanyController) DepartmentUpdate() { | 91 | func (c *CompanyController) DepartmentUpdate() { |
92 | var msg *protocol.ResponseMessage | 92 | var msg *protocol.ResponseMessage |
93 | defer func() { | 93 | defer func() { |
@@ -112,7 +112,7 @@ func (c *CompanyController) DepartmentUpdate() { | @@ -112,7 +112,7 @@ func (c *CompanyController) DepartmentUpdate() { | ||
112 | } | 112 | } |
113 | 113 | ||
114 | // DepartmentUpdate 删除部门 | 114 | // DepartmentUpdate 删除部门 |
115 | -// @router /department [delete] | 115 | +// @router /department/delete [post] |
116 | func (c *CompanyController) DepartmentDelete() { | 116 | func (c *CompanyController) DepartmentDelete() { |
117 | var msg *protocol.ResponseMessage | 117 | var msg *protocol.ResponseMessage |
118 | defer func() { | 118 | defer func() { |
@@ -132,7 +132,7 @@ func (c *CompanyController) DepartmentDelete() { | @@ -132,7 +132,7 @@ func (c *CompanyController) DepartmentDelete() { | ||
132 | } | 132 | } |
133 | 133 | ||
134 | // PositionAdd 添加职位 | 134 | // PositionAdd 添加职位 |
135 | -// @router /position [post] | 135 | +// @router /position/add [post] |
136 | func (c *CompanyController) PositionAdd() { | 136 | func (c *CompanyController) PositionAdd() { |
137 | var msg *protocol.ResponseMessage | 137 | var msg *protocol.ResponseMessage |
138 | defer func() { | 138 | defer func() { |
@@ -152,7 +152,7 @@ func (c *CompanyController) PositionAdd() { | @@ -152,7 +152,7 @@ func (c *CompanyController) PositionAdd() { | ||
152 | } | 152 | } |
153 | 153 | ||
154 | // PositionEdit 编辑职位 | 154 | // PositionEdit 编辑职位 |
155 | -// @router /position [put] | 155 | +// @router /position/edit [post] |
156 | func (c *CompanyController) PositionEdit() { | 156 | func (c *CompanyController) PositionEdit() { |
157 | var msg *protocol.ResponseMessage | 157 | var msg *protocol.ResponseMessage |
158 | defer func() { | 158 | defer func() { |
@@ -171,7 +171,7 @@ func (c *CompanyController) PositionEdit() { | @@ -171,7 +171,7 @@ func (c *CompanyController) PositionEdit() { | ||
171 | } | 171 | } |
172 | 172 | ||
173 | // PositionDelete 删除职位 | 173 | // PositionDelete 删除职位 |
174 | -// @router /position [delete] | 174 | +// @router /position/delete [post] |
175 | func (c *CompanyController) PositionDelete() { | 175 | func (c *CompanyController) PositionDelete() { |
176 | var msg *protocol.ResponseMessage | 176 | var msg *protocol.ResponseMessage |
177 | defer func() { | 177 | defer func() { |
@@ -213,7 +213,40 @@ func (c *CompanyController) PositionList() { | @@ -213,7 +213,40 @@ func (c *CompanyController) PositionList() { | ||
213 | return | 213 | return |
214 | } | 214 | } |
215 | 215 | ||
216 | -//获取公司的基本信息 | ||
217 | -func (c *CompanyController) BaseInfo() { | 216 | +//UserAdd 添加用户 |
217 | +//@Router /user/add [post] | ||
218 | +func (c *CompanyController) UserAdd() { | ||
219 | + var msg *protocol.ResponseMessage | ||
220 | + defer func() { | ||
221 | + c.ResposeJson(msg) | ||
222 | + }() | ||
223 | + var param protocol.RequestUserAdd | ||
224 | + if err := json.Unmarshal(c.Ctx.Input.RequestBody, ¶m); err != nil { | ||
225 | + log.Error("json 解析失败 err:%s", err) | ||
226 | + msg = protocol.BadRequestParam("1") | ||
227 | + return | ||
228 | + } | ||
229 | + param.CompanyId = c.GetCompanyId() | ||
230 | + err := servecompany.UserAdd(param) | ||
231 | + msg = protocol.NewReturnResponse(nil, err) | ||
232 | + return | ||
233 | +} | ||
218 | 234 | ||
235 | +//UserAdd 添加用户 | ||
236 | +//@Router /user/edit [post] | ||
237 | +func (c *CompanyController) UserEdit() { | ||
238 | + var msg *protocol.ResponseMessage | ||
239 | + defer func() { | ||
240 | + c.ResposeJson(msg) | ||
241 | + }() | ||
242 | + var param protocol.RequestUserEdit | ||
243 | + if err := json.Unmarshal(c.Ctx.Input.RequestBody, ¶m); err != nil { | ||
244 | + log.Error("json 解析失败 err:%s", err) | ||
245 | + msg = protocol.BadRequestParam("1") | ||
246 | + return | ||
247 | + } | ||
248 | + param.CompanyId = c.GetCompanyId() | ||
249 | + err := servecompany.UserEdit(param) | ||
250 | + msg = protocol.NewReturnResponse(nil, err) | ||
251 | + return | ||
219 | } | 252 | } |
@@ -3,6 +3,7 @@ module oppmg | @@ -3,6 +3,7 @@ module oppmg | ||
3 | go 1.13 | 3 | go 1.13 |
4 | 4 | ||
5 | require ( | 5 | require ( |
6 | + github.com/360EntSecGroup-Skylar/excelize/v2 v2.0.2 | ||
6 | github.com/astaxie/beego v1.11.1 | 7 | github.com/astaxie/beego v1.11.1 |
7 | github.com/dgrijalva/jwt-go v3.2.0+incompatible | 8 | github.com/dgrijalva/jwt-go v3.2.0+incompatible |
8 | github.com/go-redis/redis v6.15.6+incompatible | 9 | github.com/go-redis/redis v6.15.6+incompatible |
@@ -11,7 +12,6 @@ require ( | @@ -11,7 +12,6 @@ require ( | ||
11 | github.com/onsi/ginkgo v1.10.3 // indirect | 12 | github.com/onsi/ginkgo v1.10.3 // indirect |
12 | github.com/onsi/gomega v1.7.1 // indirect | 13 | github.com/onsi/gomega v1.7.1 // indirect |
13 | github.com/satori/go.uuid v1.2.0 | 14 | github.com/satori/go.uuid v1.2.0 |
14 | - github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 // indirect | ||
15 | github.com/sony/sonyflake v1.0.0 | 15 | github.com/sony/sonyflake v1.0.0 |
16 | golang.org/x/crypto v0.0.0-20191119213627-4f8c1d86b1ba // indirect | 16 | golang.org/x/crypto v0.0.0-20191119213627-4f8c1d86b1ba // indirect |
17 | google.golang.org/appengine v1.6.5 // indirect | 17 | google.golang.org/appengine v1.6.5 // indirect |
1 | +github.com/360EntSecGroup-Skylar/excelize/v2 v2.0.2 h1:StMrA6UQ5Cm6206DxXGuV/NMqSIOIDoMXMYt8JPe1lE= | ||
2 | +github.com/360EntSecGroup-Skylar/excelize/v2 v2.0.2/go.mod h1:EfRHD2k+Kd7ijnqlwOrH1IifwgWB9yYJ0pdXtBZmlpU= | ||
1 | github.com/Knetic/govaluate v3.0.0+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= | 3 | github.com/Knetic/govaluate v3.0.0+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= |
2 | -github.com/OwnLocal/goes v1.0.0/go.mod h1:8rIFjBGTue3lCU0wplczcUgt9Gxgrkkrw7etMIcn8TM= | ||
3 | -github.com/astaxie/beego v1.10.0 h1:s0OZ1iUO0rl8+lwWZfPK/0GhQi1tFUcIClTevyz48Pg= | ||
4 | -github.com/astaxie/beego v1.10.0/go.mod h1:0R4++1tUqERR0WYFWdfkcrsyoVBCG4DgpDGokT3yb+U= | ||
5 | github.com/astaxie/beego v1.11.1 h1:6DESefxW5oMcRLFRKi53/6exzup/IR6N4EzzS1n6CnQ= | 4 | github.com/astaxie/beego v1.11.1 h1:6DESefxW5oMcRLFRKi53/6exzup/IR6N4EzzS1n6CnQ= |
6 | github.com/astaxie/beego v1.11.1/go.mod h1:i69hVzgauOPSw5qeyF4GVZhn7Od0yG5bbCGzmhbWxgQ= | 5 | github.com/astaxie/beego v1.11.1/go.mod h1:i69hVzgauOPSw5qeyF4GVZhn7Od0yG5bbCGzmhbWxgQ= |
7 | -github.com/astaxie/beego v1.12.0 h1:MRhVoeeye5N+Flul5PoVfD9CslfdoH+xqC/xvSQ5u2Y= | ||
8 | -github.com/astaxie/beego v1.12.0/go.mod h1:fysx+LZNZKnvh4GED/xND7jWtjCR6HzydR2Hh2Im57o= | ||
9 | github.com/beego/goyaml2 v0.0.0-20130207012346-5545475820dd/go.mod h1:1b+Y/CofkYwXMUU0OhQqGvsY2Bvgr4j6jfT699wyZKQ= | 6 | github.com/beego/goyaml2 v0.0.0-20130207012346-5545475820dd/go.mod h1:1b+Y/CofkYwXMUU0OhQqGvsY2Bvgr4j6jfT699wyZKQ= |
10 | github.com/beego/x2j v0.0.0-20131220205130-a0352aadc542/go.mod h1:kSeGC/p1AbBiEp5kat81+DSQrZenVBZXklMLaELspWU= | 7 | github.com/beego/x2j v0.0.0-20131220205130-a0352aadc542/go.mod h1:kSeGC/p1AbBiEp5kat81+DSQrZenVBZXklMLaELspWU= |
11 | github.com/belogik/goes v0.0.0-20151229125003-e54d722c3aff/go.mod h1:PhH1ZhyCzHKt4uAasyx+ljRCgoezetRNf59CUtwUkqY= | 8 | github.com/belogik/goes v0.0.0-20151229125003-e54d722c3aff/go.mod h1:PhH1ZhyCzHKt4uAasyx+ljRCgoezetRNf59CUtwUkqY= |
@@ -16,10 +13,15 @@ github.com/couchbase/go-couchbase v0.0.0-20181122212707-3e9b6e1258bb/go.mod h1:T | @@ -16,10 +13,15 @@ github.com/couchbase/go-couchbase v0.0.0-20181122212707-3e9b6e1258bb/go.mod h1:T | ||
16 | github.com/couchbase/gomemcached v0.0.0-20181122193126-5125a94a666c/go.mod h1:srVSlQLB8iXBVXHgnqemxUXqN6FCvClgCMPCsjBDR7c= | 13 | github.com/couchbase/gomemcached v0.0.0-20181122193126-5125a94a666c/go.mod h1:srVSlQLB8iXBVXHgnqemxUXqN6FCvClgCMPCsjBDR7c= |
17 | github.com/couchbase/goutils v0.0.0-20180530154633-e865a1461c8a/go.mod h1:BQwMFlJzDjFDG3DJUdU0KORxn88UlsOULuxLExMh3Hs= | 14 | github.com/couchbase/goutils v0.0.0-20180530154633-e865a1461c8a/go.mod h1:BQwMFlJzDjFDG3DJUdU0KORxn88UlsOULuxLExMh3Hs= |
18 | github.com/cupcake/rdb v0.0.0-20161107195141-43ba34106c76/go.mod h1:vYwsqCOLxGiisLwp9rITslkFNpZD5rz43tf41QFkTWY= | 15 | github.com/cupcake/rdb v0.0.0-20161107195141-43ba34106c76/go.mod h1:vYwsqCOLxGiisLwp9rITslkFNpZD5rz43tf41QFkTWY= |
16 | +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
17 | +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
18 | +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
19 | +github.com/deckarep/golang-set v1.7.1 h1:SCQV0S6gTtp6itiFrTqI+pfmJ4LN85S1YzhDf9rTHJQ= | ||
19 | github.com/deckarep/golang-set v1.7.1/go.mod h1:93vsz/8Wt4joVM7c2AVqh+YRMiUSc14yDtF28KmMOgQ= | 20 | github.com/deckarep/golang-set v1.7.1/go.mod h1:93vsz/8Wt4joVM7c2AVqh+YRMiUSc14yDtF28KmMOgQ= |
20 | github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= | 21 | github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= |
21 | github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= | 22 | github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= |
22 | github.com/edsrzf/mmap-go v0.0.0-20170320065105-0bce6a688712/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M= | 23 | github.com/edsrzf/mmap-go v0.0.0-20170320065105-0bce6a688712/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M= |
24 | +github.com/elazarl/go-bindata-assetfs v1.0.0 h1:G/bYguwHIzWq9ZoyUQqrjTmJbbYn3j3CKKpKinvZLFk= | ||
23 | github.com/elazarl/go-bindata-assetfs v1.0.0/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4= | 25 | github.com/elazarl/go-bindata-assetfs v1.0.0/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4= |
24 | github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= | 26 | github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= |
25 | github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= | 27 | github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= |
@@ -39,8 +41,10 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO | @@ -39,8 +41,10 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO | ||
39 | github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= | 41 | github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= |
40 | github.com/lib/pq v1.2.0 h1:LXpIM/LZ5xGFhOpXAQUIMM1HdyqzVYM13zNdjCEEcA0= | 42 | github.com/lib/pq v1.2.0 h1:LXpIM/LZ5xGFhOpXAQUIMM1HdyqzVYM13zNdjCEEcA0= |
41 | github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= | 43 | github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= |
44 | +github.com/mattn/go-sqlite3 v1.10.0 h1:jbhqpg7tQe4SupckyijYiy0mJJ/pRyHvXf7JdWK860o= | ||
42 | github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= | 45 | github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= |
43 | -github.com/mattn/go-sqlite3 v2.0.0+incompatible h1:+afSeuaczjy4ZUN55wuDe1bCaAFBu0hg5Cf2Zw2ar0s= | 46 | +github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw= |
47 | +github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8= | ||
44 | github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= | 48 | github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= |
45 | github.com/onsi/ginkgo v1.10.3 h1:OoxbjfXVZyod1fmWYhI7SEyaD8B00ynP3T+D5GiyHOY= | 49 | github.com/onsi/ginkgo v1.10.3 h1:OoxbjfXVZyod1fmWYhI7SEyaD8B00ynP3T+D5GiyHOY= |
46 | github.com/onsi/ginkgo v1.10.3/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= | 50 | github.com/onsi/ginkgo v1.10.3/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= |
@@ -48,16 +52,19 @@ github.com/onsi/gomega v1.7.1 h1:K0jcRCwNQM3vFGh1ppMtDh/+7ApJrjldlX8fA0jDTLQ= | @@ -48,16 +52,19 @@ github.com/onsi/gomega v1.7.1 h1:K0jcRCwNQM3vFGh1ppMtDh/+7ApJrjldlX8fA0jDTLQ= | ||
48 | github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= | 52 | github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= |
49 | github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= | 53 | github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= |
50 | github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= | 54 | github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= |
55 | +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
56 | +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
51 | github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww= | 57 | github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww= |
52 | github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= | 58 | github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= |
53 | -github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 h1:X+yvsM2yrEktyI+b2qND5gpH8YhURn0k8OCaeRnkINo= | ||
54 | -github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644/go.mod h1:nkxAfR/5quYxwPZhyDxgasBMnRtBZd0FCEpawpjMUFg= | ||
55 | github.com/siddontang/go v0.0.0-20180604090527-bdc77568d726/go.mod h1:3yhqj7WBBfRhbBlzyOC3gUxftwsU0u8gqevxwIHQpMw= | 59 | github.com/siddontang/go v0.0.0-20180604090527-bdc77568d726/go.mod h1:3yhqj7WBBfRhbBlzyOC3gUxftwsU0u8gqevxwIHQpMw= |
56 | github.com/siddontang/ledisdb v0.0.0-20181029004158-becf5f38d373/go.mod h1:mF1DpOSOUiJRMR+FDqaqu3EBqrybQtrDDszLUZ6oxPg= | 60 | github.com/siddontang/ledisdb v0.0.0-20181029004158-becf5f38d373/go.mod h1:mF1DpOSOUiJRMR+FDqaqu3EBqrybQtrDDszLUZ6oxPg= |
57 | github.com/siddontang/rdb v0.0.0-20150307021120-fc89ed2e418d/go.mod h1:AMEsy7v5z92TR1JKMkLLoaOQk++LVnOKL3ScbJ8GNGA= | 61 | github.com/siddontang/rdb v0.0.0-20150307021120-fc89ed2e418d/go.mod h1:AMEsy7v5z92TR1JKMkLLoaOQk++LVnOKL3ScbJ8GNGA= |
58 | github.com/sony/sonyflake v1.0.0 h1:MpU6Ro7tfXwgn2l5eluf9xQvQJDROTBImNCfRXn/YeM= | 62 | github.com/sony/sonyflake v1.0.0 h1:MpU6Ro7tfXwgn2l5eluf9xQvQJDROTBImNCfRXn/YeM= |
59 | github.com/sony/sonyflake v1.0.0/go.mod h1:Jv3cfhf/UFtolOTTRd3q4Nl6ENqM+KfyZ5PseKfZGF4= | 63 | github.com/sony/sonyflake v1.0.0/go.mod h1:Jv3cfhf/UFtolOTTRd3q4Nl6ENqM+KfyZ5PseKfZGF4= |
60 | github.com/ssdb/gossdb v0.0.0-20180723034631-88f6b59b84ec/go.mod h1:QBvMkMya+gXctz3kmljlUCu/yB3GZ6oee+dUozsezQE= | 64 | github.com/ssdb/gossdb v0.0.0-20180723034631-88f6b59b84ec/go.mod h1:QBvMkMya+gXctz3kmljlUCu/yB3GZ6oee+dUozsezQE= |
65 | +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
66 | +github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= | ||
67 | +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= | ||
61 | github.com/syndtr/goleveldb v0.0.0-20181127023241-353a9fca669c/go.mod h1:Z4AUp2Km+PwemOoO/VB5AOx9XSsIItzFjoJlOSiYmn0= | 68 | github.com/syndtr/goleveldb v0.0.0-20181127023241-353a9fca669c/go.mod h1:Z4AUp2Km+PwemOoO/VB5AOx9XSsIItzFjoJlOSiYmn0= |
62 | github.com/wendal/errors v0.0.0-20130201093226-f66c77a7882b/go.mod h1:Q12BUT7DqIlHRmgv3RskH+UCM/4eqVMgI0EMmlSpAXc= | 69 | github.com/wendal/errors v0.0.0-20130201093226-f66c77a7882b/go.mod h1:Q12BUT7DqIlHRmgv3RskH+UCM/4eqVMgI0EMmlSpAXc= |
63 | golang.org/x/crypto v0.0.0-20181127143415-eb0de9b17e85 h1:et7+NAX3lLIk5qUCTA9QelBjGE/NkhzYw/mhnr0s7nI= | 70 | golang.org/x/crypto v0.0.0-20181127143415-eb0de9b17e85 h1:et7+NAX3lLIk5qUCTA9QelBjGE/NkhzYw/mhnr0s7nI= |
@@ -65,6 +72,8 @@ golang.org/x/crypto v0.0.0-20181127143415-eb0de9b17e85/go.mod h1:6SG95UA2DQfeDnf | @@ -65,6 +72,8 @@ golang.org/x/crypto v0.0.0-20181127143415-eb0de9b17e85/go.mod h1:6SG95UA2DQfeDnf | ||
65 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= | 72 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= |
66 | golang.org/x/crypto v0.0.0-20191119213627-4f8c1d86b1ba h1:9bFeDpN3gTqNanMVqNcoR/pJQuP5uroC3t1D7eXozTE= | 73 | golang.org/x/crypto v0.0.0-20191119213627-4f8c1d86b1ba h1:9bFeDpN3gTqNanMVqNcoR/pJQuP5uroC3t1D7eXozTE= |
67 | golang.org/x/crypto v0.0.0-20191119213627-4f8c1d86b1ba/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= | 74 | golang.org/x/crypto v0.0.0-20191119213627-4f8c1d86b1ba/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= |
75 | +golang.org/x/image v0.0.0-20190910094157-69e4b8554b2a h1:gHevYm0pO4QUbwy8Dmdr01R5r1BuKtfYqRqF0h/Cbh0= | ||
76 | +golang.org/x/image v0.0.0-20190910094157-69e4b8554b2a/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= | ||
68 | golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= | 77 | golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= |
69 | golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= | 78 | golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= |
70 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= | 79 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= |
1 | package models | 1 | package models |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | - "errors" | ||
5 | "fmt" | 4 | "fmt" |
6 | "time" | 5 | "time" |
7 | 6 | ||
@@ -43,6 +42,13 @@ func (t *User) IsEnable() bool { | @@ -43,6 +42,13 @@ func (t *User) IsEnable() bool { | ||
43 | return false | 42 | return false |
44 | } | 43 | } |
45 | 44 | ||
45 | +func (t *User) IsDelete() bool { | ||
46 | + if t.DeleteAt.Unix() < 0 { | ||
47 | + return false | ||
48 | + } | ||
49 | + return true | ||
50 | +} | ||
51 | + | ||
46 | func init() { | 52 | func init() { |
47 | orm.RegisterModel(new(User)) | 53 | orm.RegisterModel(new(User)) |
48 | } | 54 | } |
@@ -90,12 +96,13 @@ func UpdateUserById(m *User) (err error) { | @@ -90,12 +96,13 @@ func UpdateUserById(m *User) (err error) { | ||
90 | func GetUserByPhone(phone string) (v *User, err error) { | 96 | func GetUserByPhone(phone string) (v *User, err error) { |
91 | o := orm.NewOrm() | 97 | o := orm.NewOrm() |
92 | v = &User{Phone: phone} | 98 | v = &User{Phone: phone} |
93 | - if err = o.Read(v, "Phone"); err == nil { | 99 | + err = o.QueryTable(&User{}). |
100 | + Filter("phone", phone). | ||
101 | + Filter("delete_at", 0). | ||
102 | + One(v) | ||
103 | + if err == nil { | ||
94 | return v, nil | 104 | return v, nil |
95 | } | 105 | } |
96 | - if v.DeleteAt.Unix() > 0 { | ||
97 | - return nil, errors.New("user is deleted") | ||
98 | - } | ||
99 | return nil, err | 106 | return nil, err |
100 | } | 107 | } |
101 | 108 |
1 | package models | 1 | package models |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | + "errors" | ||
4 | "fmt" | 5 | "fmt" |
5 | "oppmg/common/log" | 6 | "oppmg/common/log" |
6 | "time" | 7 | "time" |
@@ -54,8 +55,10 @@ func init() { | @@ -54,8 +55,10 @@ func init() { | ||
54 | 55 | ||
55 | // AddUserCompany insert a new UserCompany into database and returns | 56 | // AddUserCompany insert a new UserCompany into database and returns |
56 | // last inserted Id on success. | 57 | // last inserted Id on success. |
57 | -func AddUserCompany(m *UserCompany) (id int64, err error) { | ||
58 | - o := orm.NewOrm() | 58 | +func AddUserCompany(m *UserCompany, o orm.Ormer) (id int64, err error) { |
59 | + m.CreateAt = time.Now() | ||
60 | + m.DeleteAt = time.Unix(0, 0) | ||
61 | + m.UpdateAt = time.Now() | ||
59 | id, err = o.Insert(m) | 62 | id, err = o.Insert(m) |
60 | return | 63 | return |
61 | } | 64 | } |
@@ -77,13 +80,15 @@ func UpdateUserCompanyById(m *UserCompany) (err error) { | @@ -77,13 +80,15 @@ func UpdateUserCompanyById(m *UserCompany) (err error) { | ||
77 | 80 | ||
78 | func GetUserCompanyBy(userid int64, companyId int64) (*UserCompany, error) { | 81 | func GetUserCompanyBy(userid int64, companyId int64) (*UserCompany, error) { |
79 | o := orm.NewOrm() | 82 | o := orm.NewOrm() |
80 | - v := &UserCompany{ | ||
81 | - UserId: userid, | ||
82 | - CompanyId: companyId, | ||
83 | - } | ||
84 | - err := o.Read(v, "UserId", "CompanyId") | 83 | + var data []*UserCompany |
84 | + _, err := o.QueryTable(&UserCompany{}).Filter("UserId", userid). | ||
85 | + Filter("CompanyId", companyId). | ||
86 | + All(&data) | ||
85 | if err != nil { | 87 | if err != nil { |
86 | return nil, err | 88 | return nil, err |
87 | } | 89 | } |
88 | - return v, nil | 90 | + if len(data) == 0 { |
91 | + return nil, errors.New("UserCompany not found") | ||
92 | + } | ||
93 | + return data[0], nil | ||
89 | } | 94 | } |
@@ -8,10 +8,10 @@ import ( | @@ -8,10 +8,10 @@ import ( | ||
8 | ) | 8 | ) |
9 | 9 | ||
10 | type UserDepartment struct { | 10 | type UserDepartment struct { |
11 | - Id int `orm:"column(id);auto" description:"主键"` | 11 | + Id int64 `orm:"column(id);auto" description:"主键"` |
12 | UserId int64 `orm:"column(user_id)" description:"用户id"` | 12 | UserId int64 `orm:"column(user_id)" description:"用户id"` |
13 | - CompanyId int `orm:"column(company_id)" description:"公司id"` | ||
14 | - DepartmentId int `orm:"column(department_id)" description:"部门id"` | 13 | + CompanyId int64 `orm:"column(company_id)" description:"公司id"` |
14 | + DepartmentId int64 `orm:"column(department_id)" description:"部门id"` | ||
15 | CreateTime time.Time `orm:"column(create_time);type(timestamp);null" description:"创建时间"` | 15 | CreateTime time.Time `orm:"column(create_time);type(timestamp);null" description:"创建时间"` |
16 | EnableStatus int8 `orm:"column(enable_status)" description:"是否有效"` | 16 | EnableStatus int8 `orm:"column(enable_status)" description:"是否有效"` |
17 | } | 17 | } |
@@ -20,6 +20,34 @@ func (t *UserDepartment) TableName() string { | @@ -20,6 +20,34 @@ func (t *UserDepartment) TableName() string { | ||
20 | return "user_department" | 20 | return "user_department" |
21 | } | 21 | } |
22 | 22 | ||
23 | +//EnableStatus 是否有效 | ||
24 | +const ( | ||
25 | + USER_DEPARTMENT_ENABLE_YES int8 = 1 //有效 | ||
26 | + USER_DEPARTMENT_ENABLE_NO int8 = 2 //无效 | ||
27 | +) | ||
28 | + | ||
29 | +func (t *UserDepartment) IsEnable() bool { | ||
30 | + switch t.EnableStatus { | ||
31 | + case USER_DEPARTMENT_ENABLE_YES: | ||
32 | + return true | ||
33 | + case USER_DEPARTMENT_ENABLE_NO: | ||
34 | + return false | ||
35 | + } | ||
36 | + return false | ||
37 | +} | ||
38 | + | ||
39 | +func (t *UserDepartment) ValidCompanyDepart() error { | ||
40 | + depart, err := GetDepartmentById(t.DepartmentId) | ||
41 | + if err != nil { | ||
42 | + return err | ||
43 | + } | ||
44 | + if depart.CompanyId != t.CompanyId { | ||
45 | + e := fmt.Errorf(" depart.CompanyId != param.CompanyId ") | ||
46 | + return e | ||
47 | + } | ||
48 | + return nil | ||
49 | +} | ||
50 | + | ||
23 | func init() { | 51 | func init() { |
24 | orm.RegisterModel(new(UserDepartment)) | 52 | orm.RegisterModel(new(UserDepartment)) |
25 | } | 53 | } |
@@ -34,7 +62,7 @@ func AddUserDepartment(m *UserDepartment) (id int64, err error) { | @@ -34,7 +62,7 @@ func AddUserDepartment(m *UserDepartment) (id int64, err error) { | ||
34 | 62 | ||
35 | // GetUserDepartmentById retrieves UserDepartment by Id. Returns error if | 63 | // GetUserDepartmentById retrieves UserDepartment by Id. Returns error if |
36 | // Id doesn't exist | 64 | // Id doesn't exist |
37 | -func GetUserDepartmentById(id int) (v *UserDepartment, err error) { | 65 | +func GetUserDepartmentById(id int64) (v *UserDepartment, err error) { |
38 | o := orm.NewOrm() | 66 | o := orm.NewOrm() |
39 | v = &UserDepartment{Id: id} | 67 | v = &UserDepartment{Id: id} |
40 | if err = o.Read(v); err == nil { | 68 | if err = o.Read(v); err == nil { |
@@ -60,7 +88,7 @@ func UpdateUserDepartmentById(m *UserDepartment) (err error) { | @@ -60,7 +88,7 @@ func UpdateUserDepartmentById(m *UserDepartment) (err error) { | ||
60 | 88 | ||
61 | // DeleteUserDepartment deletes UserDepartment by Id and returns error if | 89 | // DeleteUserDepartment deletes UserDepartment by Id and returns error if |
62 | // the record to be deleted doesn't exist | 90 | // the record to be deleted doesn't exist |
63 | -func DeleteUserDepartment(id int) (err error) { | 91 | +func DeleteUserDepartment(id int64) (err error) { |
64 | o := orm.NewOrm() | 92 | o := orm.NewOrm() |
65 | v := UserDepartment{Id: id} | 93 | v := UserDepartment{Id: id} |
66 | // ascertain id exists in the database | 94 | // ascertain id exists in the database |
@@ -8,18 +8,46 @@ import ( | @@ -8,18 +8,46 @@ import ( | ||
8 | ) | 8 | ) |
9 | 9 | ||
10 | type UserPosition struct { | 10 | type UserPosition struct { |
11 | - Id int `orm:"column(id);pk" description:"唯一键值"` | 11 | + Id int64 `orm:"column(id);pk" description:"唯一键值"` |
12 | UserId int64 `orm:"column(user_id)" description:"表user.id 用户编号"` | 12 | UserId int64 `orm:"column(user_id)" description:"表user.id 用户编号"` |
13 | - PositionId int `orm:"column(position_id)" description:"表position.id 职位编号"` | 13 | + PositionId int64 `orm:"column(position_id)" description:"表position.id 职位编号"` |
14 | CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"` | 14 | CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"` |
15 | - CompanyId int `orm:"column(company_id)" description:"表company.id 公司编号"` | ||
16 | - EnableStatus int8 `orm:"column(enable_status);null" description:"是否有效 1:有效 0:无效"` | 15 | + CompanyId int64 `orm:"column(company_id)" description:"表company.id 公司编号"` |
16 | + EnableStatus int8 `orm:"column(enable_status);null" description:"是否有效 1:有效 2:无效"` | ||
17 | } | 17 | } |
18 | 18 | ||
19 | func (t *UserPosition) TableName() string { | 19 | func (t *UserPosition) TableName() string { |
20 | return "user_position" | 20 | return "user_position" |
21 | } | 21 | } |
22 | 22 | ||
23 | +//EnableStatus 是否有效 | ||
24 | +const ( | ||
25 | + USER_POSITION_ENABLE_YES int8 = 1 //有效 | ||
26 | + USER_POSITION_ENABLE_NO int8 = 2 //无效 | ||
27 | +) | ||
28 | + | ||
29 | +func (t *UserPosition) IsEnable() bool { | ||
30 | + switch t.EnableStatus { | ||
31 | + case USER_POSITION_ENABLE_YES: | ||
32 | + return true | ||
33 | + case USER_POSITION_ENABLE_NO: | ||
34 | + return false | ||
35 | + } | ||
36 | + return false | ||
37 | +} | ||
38 | + | ||
39 | +func (t *UserPosition) ValidCompanyPosition() error { | ||
40 | + depart, err := GetPositionById(t.PositionId) | ||
41 | + if err != nil { | ||
42 | + return err | ||
43 | + } | ||
44 | + if depart.CompanyId != t.CompanyId { | ||
45 | + e := fmt.Errorf(" position.CompanyId != param.CompanyId ") | ||
46 | + return e | ||
47 | + } | ||
48 | + return nil | ||
49 | +} | ||
50 | + | ||
23 | func init() { | 51 | func init() { |
24 | orm.RegisterModel(new(UserPosition)) | 52 | orm.RegisterModel(new(UserPosition)) |
25 | } | 53 | } |
@@ -34,7 +62,7 @@ func AddUserPosition(m *UserPosition) (id int64, err error) { | @@ -34,7 +62,7 @@ func AddUserPosition(m *UserPosition) (id int64, err error) { | ||
34 | 62 | ||
35 | // GetUserPositionById retrieves UserPosition by Id. Returns error if | 63 | // GetUserPositionById retrieves UserPosition by Id. Returns error if |
36 | // Id doesn't exist | 64 | // Id doesn't exist |
37 | -func GetUserPositionById(id int) (v *UserPosition, err error) { | 65 | +func GetUserPositionById(id int64) (v *UserPosition, err error) { |
38 | o := orm.NewOrm() | 66 | o := orm.NewOrm() |
39 | v = &UserPosition{Id: id} | 67 | v = &UserPosition{Id: id} |
40 | if err = o.Read(v); err == nil { | 68 | if err = o.Read(v); err == nil { |
@@ -60,7 +88,7 @@ func UpdateUserPositionById(m *UserPosition) (err error) { | @@ -60,7 +88,7 @@ func UpdateUserPositionById(m *UserPosition) (err error) { | ||
60 | 88 | ||
61 | // DeleteUserPosition deletes UserPosition by Id and returns error if | 89 | // DeleteUserPosition deletes UserPosition by Id and returns error if |
62 | // the record to be deleted doesn't exist | 90 | // the record to be deleted doesn't exist |
63 | -func DeleteUserPosition(id int) (err error) { | 91 | +func DeleteUserPosition(id int64) (err error) { |
64 | o := orm.NewOrm() | 92 | o := orm.NewOrm() |
65 | v := UserPosition{Id: id} | 93 | v := UserPosition{Id: id} |
66 | // ascertain id exists in the database | 94 | // ascertain id exists in the database |
models/user_role.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/astaxie/beego/orm" | ||
7 | +) | ||
8 | + | ||
9 | +type UserRole struct { | ||
10 | + Id int `orm:"column(id);pk"` | ||
11 | + RoleId int64 `orm:"column(role_id)"` | ||
12 | + UserId int64 `orm:"column(user_id)"` | ||
13 | + EnableStatus int8 `orm:"column(enable_status)" description:"是否有效"` | ||
14 | + CompanyId int64 `orm:"column(company_id)" description:"表company.id 公司编号"` | ||
15 | +} | ||
16 | + | ||
17 | +func (t *UserRole) TableName() string { | ||
18 | + return "user_role" | ||
19 | +} | ||
20 | + | ||
21 | +//EnableStatus 是否有效 | ||
22 | +const ( | ||
23 | + USER_ROLE_ENABLE_YES int8 = 1 //有效 | ||
24 | + USER_ROLE_ENABLE_NO int8 = 2 //无效 | ||
25 | +) | ||
26 | + | ||
27 | +func (t *UserRole) IsEnable() bool { | ||
28 | + switch t.EnableStatus { | ||
29 | + case USER_ROLE_ENABLE_YES: | ||
30 | + return true | ||
31 | + case USER_ROLE_ENABLE_NO: | ||
32 | + return false | ||
33 | + } | ||
34 | + return false | ||
35 | +} | ||
36 | + | ||
37 | +func (t *UserRole) ValidCompanyRole() error { | ||
38 | + depart, err := GetRoleById(t.RoleId) | ||
39 | + if err != nil { | ||
40 | + return err | ||
41 | + } | ||
42 | + if depart.CompanyId != t.CompanyId { | ||
43 | + e := fmt.Errorf("role.CompanyId != param.CompanyId ") | ||
44 | + return e | ||
45 | + } | ||
46 | + return nil | ||
47 | +} | ||
48 | + | ||
49 | +func init() { | ||
50 | + orm.RegisterModel(new(UserRole)) | ||
51 | +} | ||
52 | + | ||
53 | +// AddUserRole insert a new UserRole into database and returns | ||
54 | +// last inserted Id on success. | ||
55 | +func AddUserRole(m *UserRole) (id int64, err error) { | ||
56 | + o := orm.NewOrm() | ||
57 | + id, err = o.Insert(m) | ||
58 | + return | ||
59 | +} | ||
60 | + | ||
61 | +// GetUserRoleById retrieves UserRole by Id. Returns error if | ||
62 | +// Id doesn't exist | ||
63 | +func GetUserRoleById(id int) (v *UserRole, err error) { | ||
64 | + o := orm.NewOrm() | ||
65 | + v = &UserRole{Id: id} | ||
66 | + if err = o.Read(v); err == nil { | ||
67 | + return v, nil | ||
68 | + } | ||
69 | + return nil, err | ||
70 | +} | ||
71 | + | ||
72 | +// UpdateUserRole updates UserRole by Id and returns error if | ||
73 | +// the record to be updated doesn't exist | ||
74 | +func UpdateUserRoleById(m *UserRole) (err error) { | ||
75 | + o := orm.NewOrm() | ||
76 | + v := UserRole{Id: m.Id} | ||
77 | + // ascertain id exists in the database | ||
78 | + if err = o.Read(&v); err == nil { | ||
79 | + var num int64 | ||
80 | + if num, err = o.Update(m); err == nil { | ||
81 | + fmt.Println("Number of records updated in database:", num) | ||
82 | + } | ||
83 | + } | ||
84 | + return | ||
85 | +} | ||
86 | + | ||
87 | +// DeleteUserRole deletes UserRole by Id and returns error if | ||
88 | +// the record to be deleted doesn't exist | ||
89 | +func DeleteUserRole(id int) (err error) { | ||
90 | + o := orm.NewOrm() | ||
91 | + v := UserRole{Id: id} | ||
92 | + // ascertain id exists in the database | ||
93 | + if err = o.Read(&v); err == nil { | ||
94 | + var num int64 | ||
95 | + if num, err = o.Delete(&UserRole{Id: id}); err == nil { | ||
96 | + fmt.Println("Number of records deleted in database:", num) | ||
97 | + } | ||
98 | + } | ||
99 | + return | ||
100 | +} |
@@ -2,8 +2,8 @@ package protocol | @@ -2,8 +2,8 @@ package protocol | ||
2 | 2 | ||
3 | //RequestPageInfo 分页获取数据 | 3 | //RequestPageInfo 分页获取数据 |
4 | type RequestPageInfo struct { | 4 | type RequestPageInfo struct { |
5 | - PageIndex int `json:"page"` | ||
6 | - PageSize int `json:"pageSize"` | 5 | + PageIndex int `json:"page_index"` |
6 | + PageSize int `json:"page_size"` | ||
7 | } | 7 | } |
8 | 8 | ||
9 | //ResponsePageInfo 分页信息 | 9 | //ResponsePageInfo 分页信息 |
@@ -70,6 +70,7 @@ type RequestPositionDelete struct { | @@ -70,6 +70,7 @@ type RequestPositionDelete struct { | ||
70 | IDs []int64 `json:"ids"` | 70 | IDs []int64 `json:"ids"` |
71 | } | 71 | } |
72 | 72 | ||
73 | +//RequestUserAdd 添加用户 | ||
73 | type RequestUserAdd struct { | 74 | type RequestUserAdd struct { |
74 | Name string `json:"name"` | 75 | Name string `json:"name"` |
75 | CompanyId int64 `json:"company_id"` | 76 | CompanyId int64 `json:"company_id"` |
@@ -79,7 +80,29 @@ type RequestUserAdd struct { | @@ -79,7 +80,29 @@ type RequestUserAdd struct { | ||
79 | Roles []int64 `json:"roles"` | 80 | Roles []int64 `json:"roles"` |
80 | } | 81 | } |
81 | 82 | ||
83 | +//RequestUserEdit 编辑用户 | ||
82 | type RequestUserEdit struct { | 84 | type RequestUserEdit struct { |
83 | ID int64 `json:"id"` | 85 | ID int64 `json:"id"` |
84 | RequestUserAdd | 86 | RequestUserAdd |
85 | } | 87 | } |
88 | + | ||
89 | +//RequestUserList 获取用户列表 | ||
90 | +type RequestUserList struct { | ||
91 | + RequestPageInfo | ||
92 | + NickName string `json:"nick_name"` | ||
93 | +} | ||
94 | + | ||
95 | +//ResponseUserList 响应的用户列表 | ||
96 | +type ResponseUserList struct { | ||
97 | + ResponsePageInfo | ||
98 | + List []UserListItem `json:"list"` | ||
99 | +} | ||
100 | + | ||
101 | +type UserListItem struct { | ||
102 | + Id int64 `json:"id"` | ||
103 | + NickName string `json:"nick_name"` | ||
104 | + Position string `json:"position"` | ||
105 | + Role string `json:"role"` | ||
106 | + Department string `json:"department"` | ||
107 | + Status int8 `json:"status"` | ||
108 | +} |
1 | package protocol | 1 | package protocol |
2 | 2 | ||
3 | -import ( | ||
4 | - "encoding/json" | ||
5 | -) | ||
6 | - | ||
7 | //CustomErrParse 解析自定义错误结构体 | 3 | //CustomErrParse 解析自定义错误结构体 |
8 | type CustomErrParse interface { | 4 | type CustomErrParse interface { |
9 | ParseToMessage() *ResponseMessage | 5 | ParseToMessage() *ResponseMessage |
@@ -72,8 +68,8 @@ func NewErrWithMessage(code string, eRR ...error) *ErrWithMessage { | @@ -72,8 +68,8 @@ func NewErrWithMessage(code string, eRR ...error) *ErrWithMessage { | ||
72 | //Error 实现接口error 中的方法 | 68 | //Error 实现接口error 中的方法 |
73 | //将ErrorCode转为json数据,建议用于日志记录 | 69 | //将ErrorCode转为json数据,建议用于日志记录 |
74 | func (e ErrWithMessage) Error() string { | 70 | func (e ErrWithMessage) Error() string { |
75 | - bt, _ := json.Marshal(e.ErrorCode) | ||
76 | - return string(bt) | 71 | + |
72 | + return e.Errmsg | ||
77 | } | 73 | } |
78 | 74 | ||
79 | //Unwrap 接口实现 | 75 | //Unwrap 接口实现 |
@@ -17,6 +17,10 @@ var errmessge ErrorMap = map[string]string{ | @@ -17,6 +17,10 @@ var errmessge ErrorMap = map[string]string{ | ||
17 | "10025": "该账号已在其他地方登录", | 17 | "10025": "该账号已在其他地方登录", |
18 | "10026": "登录凭证过期", | 18 | "10026": "登录凭证过期", |
19 | "10027": "无操作权限", | 19 | "10027": "无操作权限", |
20 | + //用户相关 | ||
21 | + "10031": "无效角色", | ||
22 | + "10032": "无效部门", | ||
23 | + "10033": "无效职位", | ||
20 | } | 24 | } |
21 | 25 | ||
22 | //错误码转换 ,兼容需要 | 26 | //错误码转换 ,兼容需要 |
@@ -34,6 +34,12 @@ func init() { | @@ -34,6 +34,12 @@ func init() { | ||
34 | beego.NSRouter("/role_group/delete", &controllers.RbacController{}, "post:RoleGroupDelete"), | 34 | beego.NSRouter("/role_group/delete", &controllers.RbacController{}, "post:RoleGroupDelete"), |
35 | beego.NSRouter("/role", &controllers.RbacController{}, "get:RoleList"), | 35 | beego.NSRouter("/role", &controllers.RbacController{}, "get:RoleList"), |
36 | ), | 36 | ), |
37 | + beego.NSNamespace("/user/", | ||
38 | + // beego.NSRouter("/list", &controllers.CompanyController{}, "post:UserList"), | ||
39 | + beego.NSRouter("/add", &controllers.CompanyController{}, "post:UserAdd"), | ||
40 | + beego.NSRouter("/edit", &controllers.CompanyController{}, "post:UserEdit"), | ||
41 | + // beego.NSRouter("/delete", &controllers.CompanyController{}, "post:PositionDelete"), | ||
42 | + ), | ||
37 | beego.NSNamespace("/auth", | 43 | beego.NSNamespace("/auth", |
38 | beego.NSRouter("/change_company", &controllers.AuthController{}, "post:ChangeCompany"), | 44 | beego.NSRouter("/change_company", &controllers.AuthController{}, "post:ChangeCompany"), |
39 | beego.NSRouter("/refresh_token", &controllers.AuthController{}, "get:RefreshToken"), | 45 | beego.NSRouter("/refresh_token", &controllers.AuthController{}, "get:RefreshToken"), |
@@ -43,44 +43,44 @@ func validatePassword(from, to string) bool { | @@ -43,44 +43,44 @@ func validatePassword(from, to string) bool { | ||
43 | 43 | ||
44 | //LoginAuth 登录认证 | 44 | //LoginAuth 登录认证 |
45 | //TODO 登录校验逻辑修改 | 45 | //TODO 登录校验逻辑修改 |
46 | -func LoginAuthByPassword(account, password string) (protocol.LoginAuthToken, error) { | ||
47 | - var ( | ||
48 | - user *models.User | ||
49 | - companys []models.Company | ||
50 | - mcompany models.Company | ||
51 | - loginToken protocol.LoginAuthToken | ||
52 | - err error | ||
53 | - ) | ||
54 | - user, err = models.GetUserByPhone(account) | ||
55 | - if err != nil { | ||
56 | - log.Error(err.Error()) | ||
57 | - return loginToken, protocol.NewErrWithMessage("10021", err) | ||
58 | - } | ||
59 | - if ok := validatePassword(password, user.Passwd); !ok { | ||
60 | - return loginToken, protocol.NewErrWithMessage("10021", err) | ||
61 | - } | ||
62 | - if ok := user.IsEnable(); !ok { | ||
63 | - return loginToken, protocol.NewErrWithMessage("10022") | ||
64 | - } | ||
65 | - companys, err = models.GetCompanyByUser(user.Id) | ||
66 | - if err != nil { | ||
67 | - e := fmt.Errorf("GetCompanyByUser(%d) err:%s", user.Id, err) | ||
68 | - log.Error(e.Error()) | ||
69 | - return loginToken, protocol.NewErrWithMessage("1") | ||
70 | - } | ||
71 | - if len(companys) <= 0 { | ||
72 | - log.Error("can not found company") | ||
73 | - return loginToken, protocol.NewErrWithMessage("1") | ||
74 | - } | ||
75 | - mcompany = companys[0] | ||
76 | - loginToken, err = GenerateAuthToken(user.Id, mcompany.Id) | ||
77 | - if err != nil { | ||
78 | - e := fmt.Errorf("GenerateAuthToken err:%s", err) | ||
79 | - log.Error(e.Error()) | ||
80 | - return loginToken, protocol.NewErrWithMessage("1") | ||
81 | - } | ||
82 | - return loginToken, nil | ||
83 | -} | 46 | +// func LoginAuthByPassword(account, password string) (protocol.LoginAuthToken, error) { |
47 | +// var ( | ||
48 | +// user *models.User | ||
49 | +// companys []models.Company | ||
50 | +// mcompany models.Company | ||
51 | +// loginToken protocol.LoginAuthToken | ||
52 | +// err error | ||
53 | +// ) | ||
54 | +// user, err = models.GetUserByPhone(account) | ||
55 | +// if err != nil { | ||
56 | +// log.Error(err.Error()) | ||
57 | +// return loginToken, protocol.NewErrWithMessage("10021", err) | ||
58 | +// } | ||
59 | +// if ok := validatePassword(password, user.Passwd); !ok { | ||
60 | +// return loginToken, protocol.NewErrWithMessage("10021", err) | ||
61 | +// } | ||
62 | +// if ok := user.IsEnable(); !ok { | ||
63 | +// return loginToken, protocol.NewErrWithMessage("10022") | ||
64 | +// } | ||
65 | +// companys, err = models.GetCompanyByUser(user.Id) | ||
66 | +// if err != nil { | ||
67 | +// e := fmt.Errorf("GetCompanyByUser(%d) err:%s", user.Id, err) | ||
68 | +// log.Error(e.Error()) | ||
69 | +// return loginToken, protocol.NewErrWithMessage("1") | ||
70 | +// } | ||
71 | +// if len(companys) <= 0 { | ||
72 | +// log.Error("can not found company") | ||
73 | +// return loginToken, protocol.NewErrWithMessage("1") | ||
74 | +// } | ||
75 | +// mcompany = companys[0] | ||
76 | +// loginToken, err = GenerateAuthToken(user.Id, mcompany.Id) | ||
77 | +// if err != nil { | ||
78 | +// e := fmt.Errorf("GenerateAuthToken err:%s", err) | ||
79 | +// log.Error(e.Error()) | ||
80 | +// return loginToken, protocol.NewErrWithMessage("1") | ||
81 | +// } | ||
82 | +// return loginToken, nil | ||
83 | +// } | ||
84 | 84 | ||
85 | //ResetLoginToken token存数据库 | 85 | //ResetLoginToken token存数据库 |
86 | func ResetLoginToken(loginToken protocol.LoginAuthToken) error { | 86 | func ResetLoginToken(loginToken protocol.LoginAuthToken) error { |
@@ -236,6 +236,10 @@ func LoginAuthByUCenter(account, password string) (protocol.LoginAuthToken, erro | @@ -236,6 +236,10 @@ func LoginAuthByUCenter(account, password string) (protocol.LoginAuthToken, erro | ||
236 | log.Debug("GetUserByPhone(%s) err:%s", account, err) | 236 | log.Debug("GetUserByPhone(%s) err:%s", account, err) |
237 | return logintoken, protocol.NewErrWithMessage("10021") | 237 | return logintoken, protocol.NewErrWithMessage("10021") |
238 | } | 238 | } |
239 | + if ok := userdata.IsDelete(); ok { | ||
240 | + log.Debug("userdata.IsDelete()==true") | ||
241 | + return logintoken, protocol.NewErrWithMessage("10021") | ||
242 | + } | ||
239 | if ok := userdata.IsEnable(); !ok { | 243 | if ok := userdata.IsEnable(); !ok { |
240 | log.Debug("userdata.IsEnable()==false") | 244 | log.Debug("userdata.IsEnable()==false") |
241 | return logintoken, protocol.NewErrWithMessage("10021") | 245 | return logintoken, protocol.NewErrWithMessage("10021") |
@@ -5,83 +5,343 @@ import ( | @@ -5,83 +5,343 @@ import ( | ||
5 | "oppmg/common/log" | 5 | "oppmg/common/log" |
6 | "oppmg/models" | 6 | "oppmg/models" |
7 | "oppmg/protocol" | 7 | "oppmg/protocol" |
8 | + "oppmg/utils" | ||
9 | + "time" | ||
10 | + | ||
11 | + "github.com/astaxie/beego/orm" | ||
8 | ) | 12 | ) |
9 | 13 | ||
10 | func UserAdd(param protocol.RequestUserAdd) error { | 14 | func UserAdd(param protocol.RequestUserAdd) error { |
11 | var ( | 15 | var ( |
12 | - // user models.User | ||
13 | - // userRoles []models.RoleRelated | ||
14 | - // userPositions []models.UserPosition | ||
15 | - // userDeparts []models.UserPosition | 16 | + userm *models.User |
17 | + err error | ||
16 | ) | 18 | ) |
17 | //校验角色 | 19 | //校验角色 |
18 | - validCompanyRole(param.CompanyId, param.Roles) | 20 | + err = validCompanyRole(param.CompanyId, param.Roles) |
21 | + if err != nil { | ||
22 | + log.Error(err.Error()) | ||
23 | + return protocol.NewErrWithMessage("10031") | ||
24 | + } | ||
19 | //校验部门 | 25 | //校验部门 |
20 | - validCompanyDepart(param.CompanyId, param.Departments) | 26 | + err = validCompanyDepart(param.CompanyId, param.Departments) |
27 | + if err != nil { | ||
28 | + log.Error(err.Error()) | ||
29 | + return protocol.NewErrWithMessage("10032") | ||
30 | + } | ||
21 | //校验职位 | 31 | //校验职位 |
22 | - validCompanyPositions(param.CompanyId, param.Positions) | ||
23 | - //添加用户 | 32 | + err = validCompanyPosition(param.CompanyId, param.Positions) |
33 | + if err != nil { | ||
34 | + log.Error(err.Error()) | ||
35 | + return protocol.NewErrWithMessage("10033") | ||
36 | + } | ||
37 | + userm = &models.User{ | ||
38 | + NickName: param.Name, | ||
39 | + Phone: param.Phone, | ||
40 | + } | ||
41 | + o := orm.NewOrm() | ||
42 | + o.Begin() | ||
43 | + err = registUser(userm, param.CompanyId, o) | ||
44 | + if err != nil { | ||
45 | + o.Rollback() | ||
46 | + log.Error("registUser err:%s", err) | ||
47 | + return protocol.NewErrWithMessage("1") | ||
48 | + } | ||
24 | //添加角色 | 49 | //添加角色 |
50 | + err = editUserRole(userm.Id, param.CompanyId, param.Roles, o) | ||
51 | + if err != nil { | ||
52 | + o.Rollback() | ||
53 | + log.Error("editUserRole err:%s", err) | ||
54 | + return protocol.NewErrWithMessage("1") | ||
55 | + } | ||
25 | //添加部门 | 56 | //添加部门 |
57 | + err = editUserDepart(userm.Id, param.CompanyId, param.Departments, o) | ||
58 | + if err != nil { | ||
59 | + o.Rollback() | ||
60 | + log.Error("editUserDepart err:%s", err) | ||
61 | + return protocol.NewErrWithMessage("1") | ||
62 | + } | ||
26 | //添加职位 | 63 | //添加职位 |
64 | + err = editUserDepart(userm.Id, param.CompanyId, param.Positions, o) | ||
65 | + if err != nil { | ||
66 | + o.Rollback() | ||
67 | + log.Error("editUserDepart err:%s", err) | ||
68 | + return protocol.NewErrWithMessage("1") | ||
69 | + } | ||
70 | + o.Commit() | ||
71 | + return nil | ||
72 | +} | ||
73 | +func validCompanyRole(companyid int64, roleid []int64) error { | ||
74 | + var ( | ||
75 | + err error | ||
76 | + ) | ||
77 | + for _, v := range roleid { | ||
78 | + ur := models.UserRole{ | ||
79 | + CompanyId: companyid, | ||
80 | + RoleId: v, | ||
81 | + EnableStatus: models.USER_ROLE_ENABLE_YES, | ||
82 | + } | ||
83 | + err = ur.ValidCompanyRole() | ||
84 | + if err != nil { | ||
85 | + e := fmt.Errorf("ValidCompanyRole err:%s [company:%d,role:%d]", err, companyid, v) | ||
86 | + log.Error(e.Error()) | ||
87 | + return protocol.NewErrWithMessage("10031") | ||
88 | + } | ||
89 | + | ||
90 | + } | ||
27 | return nil | 91 | return nil |
28 | } | 92 | } |
29 | 93 | ||
30 | -func validCompanyRole(companyId int64, roleIds []int64) error { | ||
31 | - for _, v := range roleIds { | ||
32 | - role, err := models.GetRoleById(v) | 94 | +func validCompanyDepart(companyid int64, departid []int64) error { |
95 | + var ( | ||
96 | + err error | ||
97 | + ) | ||
98 | + for _, v := range departid { | ||
99 | + ud := models.UserDepartment{ | ||
100 | + CompanyId: companyid, | ||
101 | + DepartmentId: v, | ||
102 | + EnableStatus: models.USER_DEPARTMENT_ENABLE_YES, | ||
103 | + } | ||
104 | + err = ud.ValidCompanyDepart() | ||
33 | if err != nil { | 105 | if err != nil { |
34 | - e := fmt.Errorf("GetRoleById(%d) err:%s", v, err) | 106 | + e := fmt.Errorf("ValidCompanyDepart err:%s [company:%d,department:%d]", err, companyid, v) |
35 | log.Error(e.Error()) | 107 | log.Error(e.Error()) |
36 | - return protocol.NewErrWithMessage("1", err) | 108 | + return protocol.NewErrWithMessage("10032") |
37 | } | 109 | } |
38 | - if role.CompanyId != companyId { | ||
39 | - e := fmt.Errorf(" role.CompanyId != param.CompanyId ") | 110 | + |
111 | + } | ||
112 | + return nil | ||
113 | +} | ||
114 | + | ||
115 | +func validCompanyPosition(companyid int64, positionid []int64) error { | ||
116 | + var ( | ||
117 | + err error | ||
118 | + ) | ||
119 | + for _, v := range positionid { | ||
120 | + ud := models.UserPosition{ | ||
121 | + | ||
122 | + CompanyId: companyid, | ||
123 | + PositionId: v, | ||
124 | + EnableStatus: models.USER_DEPARTMENT_ENABLE_YES, | ||
125 | + } | ||
126 | + err = ud.ValidCompanyPosition() | ||
127 | + if err != nil { | ||
128 | + e := fmt.Errorf("ValidCompanyPosition err:%s [company:%d,department:%d]", err, companyid, v) | ||
40 | log.Error(e.Error()) | 129 | log.Error(e.Error()) |
41 | - return protocol.NewErrWithMessage("1", err) | 130 | + return protocol.NewErrWithMessage("10033") |
131 | + } | ||
132 | + | ||
133 | + } | ||
134 | + return nil | ||
135 | +} | ||
136 | + | ||
137 | +//registUser 注册用户 | ||
138 | +func registUser(userIn *models.User, companyid int64, o orm.Ormer) error { | ||
139 | + var ( | ||
140 | + err error | ||
141 | + // usrData *models.User | ||
142 | + ) | ||
143 | + _, err = models.GetUserByPhone(userIn.Phone) | ||
144 | + if err == nil { | ||
145 | + return nil | ||
146 | + } | ||
147 | + if err != nil && err != orm.ErrNoRows { | ||
148 | + return err | ||
149 | + } | ||
150 | + if err == orm.ErrNoRows { | ||
151 | + _, err := models.AddUser(userIn, o) | ||
152 | + if err != nil { | ||
153 | + return err | ||
42 | } | 154 | } |
43 | } | 155 | } |
156 | + musercompany := &models.UserCompany{ | ||
157 | + CompanyId: companyid, | ||
158 | + UserId: userIn.Id, | ||
159 | + } | ||
160 | + _, err = models.AddUserCompany(musercompany, o) | ||
161 | + if err != nil { | ||
162 | + return err | ||
163 | + } | ||
164 | + //更新 | ||
44 | return nil | 165 | return nil |
45 | } | 166 | } |
46 | 167 | ||
47 | -func validCompanyDepart(companyId int64, departIds []int64) error { | ||
48 | - for _, v := range departIds { | ||
49 | - depart, err := models.GetDepartmentById(v) | 168 | +func editUserDepart(userid int64, companyid int64, departids []int64, o orm.Ormer) error { |
169 | + var ( | ||
170 | + oldDepartIds []int64 | ||
171 | + err error | ||
172 | + delDepartIds []int64 | ||
173 | + addDepartIds []int64 | ||
174 | + ) | ||
175 | + dataSql := `SELECT department_id FROM user_department WHERE enable_status=1 AND company_id=? AND user_id=?` | ||
176 | + dataSql2 := `UPDATE user_department SET enable_status = 2 WHERE company_id = ? AND user_id=? AND department_id=?` | ||
177 | + datasql3 := `INSERT INTO user_department (user_id,department_id,company_id,enable_status,create_at) VALUES (?,?,?,?,?)` | ||
178 | + err = utils.ExecuteQueryAllWithOrmer(o, &oldDepartIds, dataSql, companyid, userid) | ||
179 | + if err != nil { | ||
180 | + e := fmt.Errorf("Execute SQL err:%s", err) | ||
181 | + log.Error(e.Error()) | ||
182 | + return e | ||
183 | + } | ||
184 | + delDepartIds = utils.ArrayInt64Diff(oldDepartIds, departids) | ||
185 | + addDepartIds = utils.ArrayInt64Diff(departids, oldDepartIds) | ||
186 | + for _, v := range delDepartIds { | ||
187 | + err = utils.ExecuteSQLWithOrmer(o, dataSql2, companyid, userid, v) | ||
50 | if err != nil { | 188 | if err != nil { |
51 | - e := fmt.Errorf("GetDepartmentById(%d) err:%s", v, err) | 189 | + e := fmt.Errorf("Execute SQL err:%s", err) |
52 | log.Error(e.Error()) | 190 | log.Error(e.Error()) |
53 | - return protocol.NewErrWithMessage("1", err) | 191 | + return e |
54 | } | 192 | } |
55 | - if depart.CompanyId != companyId { | ||
56 | - e := fmt.Errorf(" depart.CompanyId != param.CompanyId ") | 193 | + } |
194 | + nowTime := time.Now().String() | ||
195 | + for _, v := range addDepartIds { | ||
196 | + err = utils.ExecuteSQLWithOrmer(o, datasql3, userid, v, companyid, models.USER_POSITION_ENABLE_YES, nowTime) | ||
197 | + if err != nil { | ||
198 | + e := fmt.Errorf("Execute SQL err:%s", err) | ||
57 | log.Error(e.Error()) | 199 | log.Error(e.Error()) |
58 | - return protocol.NewErrWithMessage("1", err) | 200 | + return e |
59 | } | 201 | } |
60 | } | 202 | } |
61 | return nil | 203 | return nil |
62 | } | 204 | } |
63 | 205 | ||
64 | -func validCompanyPositions(companyId int64, positionIds []int64) error { | ||
65 | - for _, v := range positionIds { | ||
66 | - pos, err := models.GetPositionById(v) | 206 | +func editUserPosition(userid int64, companyid int64, positionids []int64, o orm.Ormer) error { |
207 | + var ( | ||
208 | + oldPositionIds []int64 | ||
209 | + err error | ||
210 | + delPositionIds []int64 | ||
211 | + addPositionIds []int64 | ||
212 | + ) | ||
213 | + dataSql := `SELECT position_id FROM user_position WHERE enable_status=1 AND company_id=? AND user_id=?` | ||
214 | + dataSql2 := `UPDATE user_position SET enable_status = 2 WHERE company_id = ? AND user_id=? AND position_id=?` | ||
215 | + datasql3 := `INSERT INTO user_position (user_id,position_id,company_id,enable_status,create_at) VALUES (?,?,?,?,?)` | ||
216 | + err = utils.ExecuteQueryAllWithOrmer(o, &oldPositionIds, dataSql, companyid, userid) | ||
217 | + if err != nil { | ||
218 | + e := fmt.Errorf("Execute SQL err:%s", err) | ||
219 | + log.Error(e.Error()) | ||
220 | + return e | ||
221 | + } | ||
222 | + delPositionIds = utils.ArrayInt64Diff(oldPositionIds, positionids) | ||
223 | + addPositionIds = utils.ArrayInt64Diff(positionids, oldPositionIds) | ||
224 | + for _, v := range delPositionIds { | ||
225 | + err = utils.ExecuteSQLWithOrmer(o, dataSql2, companyid, userid, v) | ||
67 | if err != nil { | 226 | if err != nil { |
68 | - e := fmt.Errorf("GetDepartmentById(%d) err:%s", v, err) | 227 | + e := fmt.Errorf("Execute SQL err:%s", err) |
69 | log.Error(e.Error()) | 228 | log.Error(e.Error()) |
70 | - return protocol.NewErrWithMessage("1", err) | 229 | + return e |
71 | } | 230 | } |
72 | - if pos.CompanyId != companyId { | ||
73 | - e := fmt.Errorf("pos.CompanyId != pos.CompanyId") | 231 | + } |
232 | + nowTime := time.Now().String() | ||
233 | + for _, v := range addPositionIds { | ||
234 | + err = utils.ExecuteSQLWithOrmer(o, datasql3, userid, v, companyid, models.USER_POSITION_ENABLE_YES, nowTime) | ||
235 | + if err != nil { | ||
236 | + e := fmt.Errorf("Execute SQL err:%s", err) | ||
74 | log.Error(e.Error()) | 237 | log.Error(e.Error()) |
75 | - return protocol.NewErrWithMessage("1", err) | 238 | + return e |
239 | + } | ||
240 | + } | ||
241 | + return nil | ||
242 | +} | ||
243 | +func editUserRole(userid int64, companyid int64, roleids []int64, o orm.Ormer) error { | ||
244 | + var ( | ||
245 | + oldRoleIds []int64 | ||
246 | + err error | ||
247 | + delRoleIds []int64 | ||
248 | + addRoleIds []int64 | ||
249 | + ) | ||
250 | + dataSql := `SELECT role_id FROM user_role WHERE enable_status=1 AND company_id=? AND user_id=?` | ||
251 | + dataSql2 := `UPDATE user_position SET enable_status = 2 WHERE company_id =? AND user_id=? AND role_id=?` | ||
252 | + datasql3 := `INSERT INTO user_role (user_id,role_id,company_id,enable_status) VALUES (?,?,?,?)` | ||
253 | + err = utils.ExecuteQueryAllWithOrmer(o, &oldRoleIds, dataSql, companyid, userid) | ||
254 | + if err != nil { | ||
255 | + e := fmt.Errorf("Execute SQL err:%s", err) | ||
256 | + log.Error(e.Error()) | ||
257 | + return e | ||
258 | + } | ||
259 | + delRoleIds = utils.ArrayInt64Diff(oldRoleIds, roleids) | ||
260 | + addRoleIds = utils.ArrayInt64Diff(roleids, oldRoleIds) | ||
261 | + for _, v := range delRoleIds { | ||
262 | + err = utils.ExecuteSQLWithOrmer(o, dataSql2, companyid, userid, v) | ||
263 | + if err != nil { | ||
264 | + e := fmt.Errorf("Execute SQL err:%s", err) | ||
265 | + log.Error(e.Error()) | ||
266 | + return e | ||
267 | + } | ||
268 | + } | ||
269 | + for _, v := range addRoleIds { | ||
270 | + err = utils.ExecuteSQLWithOrmer(o, datasql3, userid, v, companyid, models.USER_POSITION_ENABLE_YES) | ||
271 | + if err != nil { | ||
272 | + e := fmt.Errorf("Execute SQL err:%s", err) | ||
273 | + log.Error(e.Error()) | ||
274 | + return e | ||
76 | } | 275 | } |
77 | } | 276 | } |
78 | return nil | 277 | return nil |
79 | } | 278 | } |
80 | 279 | ||
81 | func UserEdit(param protocol.RequestUserEdit) error { | 280 | func UserEdit(param protocol.RequestUserEdit) error { |
281 | + var ( | ||
282 | + userm *models.User | ||
283 | + err error | ||
284 | + ) | ||
285 | + //校验角色 | ||
286 | + err = validCompanyRole(param.CompanyId, param.Roles) | ||
287 | + if err != nil { | ||
288 | + log.Error(err.Error()) | ||
289 | + return protocol.NewErrWithMessage("10031") | ||
290 | + } | ||
291 | + //校验部门 | ||
292 | + err = validCompanyDepart(param.CompanyId, param.Departments) | ||
293 | + if err != nil { | ||
294 | + log.Error(err.Error()) | ||
295 | + return protocol.NewErrWithMessage("10032") | ||
296 | + } | ||
297 | + //校验职位 | ||
298 | + err = validCompanyPosition(param.CompanyId, param.Positions) | ||
299 | + if err != nil { | ||
300 | + log.Error(err.Error()) | ||
301 | + return protocol.NewErrWithMessage("10033") | ||
302 | + } | ||
303 | + userm = &models.User{ | ||
304 | + Id: param.ID, | ||
305 | + NickName: param.Name, | ||
306 | + Phone: param.Phone, | ||
307 | + } | ||
308 | + o := orm.NewOrm() | ||
309 | + o.Begin() | ||
310 | + // err = registUser(userm, param.CompanyId, o) | ||
311 | + // if err != nil { | ||
312 | + // o.Rollback() | ||
313 | + // log.Error("registUser err:%s", err) | ||
314 | + // return protocol.NewErrWithMessage("1") | ||
315 | + // } | ||
316 | + //添加角色 | ||
317 | + err = editUserRole(userm.Id, param.CompanyId, param.Roles, o) | ||
318 | + if err != nil { | ||
319 | + o.Rollback() | ||
320 | + log.Error("editUserRole err:%s", err) | ||
321 | + return protocol.NewErrWithMessage("1") | ||
322 | + } | ||
323 | + //添加部门 | ||
324 | + err = editUserDepart(userm.Id, param.CompanyId, param.Departments, o) | ||
325 | + if err != nil { | ||
326 | + o.Rollback() | ||
327 | + log.Error("editUserDepart err:%s", err) | ||
328 | + return protocol.NewErrWithMessage("1") | ||
329 | + } | ||
330 | + //添加职位 | ||
331 | + err = editUserDepart(userm.Id, param.CompanyId, param.Positions, o) | ||
332 | + if err != nil { | ||
333 | + o.Rollback() | ||
334 | + log.Error("editUserDepart err:%s", err) | ||
335 | + return protocol.NewErrWithMessage("1") | ||
336 | + } | ||
337 | + o.Commit() | ||
82 | return nil | 338 | return nil |
83 | } | 339 | } |
84 | 340 | ||
85 | func UserDelete(param protocol.RequestUserAdd) error { | 341 | func UserDelete(param protocol.RequestUserAdd) error { |
86 | return nil | 342 | return nil |
87 | } | 343 | } |
344 | + | ||
345 | +func UserList() error { | ||
346 | + return nil | ||
347 | +} |
@@ -9,6 +9,9 @@ type ArrayCmpare interface { | @@ -9,6 +9,9 @@ type ArrayCmpare interface { | ||
9 | 9 | ||
10 | //ArrayInt64Diff 返回切片的差集:arr1-arr2 | 10 | //ArrayInt64Diff 返回切片的差集:arr1-arr2 |
11 | func ArrayInt64Diff(arr1 []int64, arr2 []int64) []int64 { | 11 | func ArrayInt64Diff(arr1 []int64, arr2 []int64) []int64 { |
12 | + if len(arr2) == 0 { | ||
13 | + return arr1 | ||
14 | + } | ||
12 | setmap := make(map[int64]bool) | 15 | setmap := make(map[int64]bool) |
13 | for i := range arr2 { | 16 | for i := range arr2 { |
14 | setmap[arr1[i]] = true | 17 | setmap[arr1[i]] = true |
utils/exceltool/index.go
0 → 100644
1 | +package exceltool | ||
2 | + | ||
3 | +import ( | ||
4 | + "errors" | ||
5 | + "fmt" | ||
6 | + "math/rand" | ||
7 | + "time" | ||
8 | + | ||
9 | + excelize "github.com/360EntSecGroup-Skylar/excelize/v2" | ||
10 | + "github.com/astaxie/beego/orm" | ||
11 | +) | ||
12 | + | ||
13 | +//(新)ExcelMaker 构建excel文档 | ||
14 | +type ExcelMaker struct { | ||
15 | + Xlsx *excelize.File | ||
16 | + FileName string | ||
17 | +} | ||
18 | + | ||
19 | +//NewExcelMaker .... | ||
20 | +func NewExcelMaker() *ExcelMaker { | ||
21 | + return &ExcelMaker{ | ||
22 | + Xlsx: excelize.NewFile(), | ||
23 | + } | ||
24 | +} | ||
25 | + | ||
26 | +//MakeListExcel 根据列表形式的数据创建excel文档 | ||
27 | +//@sourData []map[string]string; 原始数据,要输入excel文档的数据 | ||
28 | +//@xlsxHeader [][]string{ {"数据字段英文名",""excel字段中文描述"},{"数据字段英文名",""excel字段中文描述"} } | ||
29 | +func (e *ExcelMaker) MakeListExcel(sourData []map[string]string, xlsxHeader [][]string) (err error) { | ||
30 | + if len(xlsxHeader) == 0 { | ||
31 | + return errors.New("xlsHeader 数据格式错误") | ||
32 | + } | ||
33 | + headEn := []string{} //数据字段英文名 | ||
34 | + headCn := []string{} //excel字段中文描述 | ||
35 | + alphaSlice := []string{} //excel列字母索引 | ||
36 | + for key, val := range xlsxHeader { | ||
37 | + if len(val) != 2 { | ||
38 | + return errors.New("xlsHeader 数据格式错误") | ||
39 | + } | ||
40 | + headEn = append(headEn, xlsxHeader[key][0]) | ||
41 | + headCn = append(headCn, xlsxHeader[key][1]) | ||
42 | + alpha, err := excelize.ColumnNumberToName(key) | ||
43 | + if err != nil { | ||
44 | + return err | ||
45 | + } | ||
46 | + alphaSlice = append(alphaSlice, alpha) | ||
47 | + } | ||
48 | + | ||
49 | + //设置excel文档第一行的字段中文描述 | ||
50 | + for index, _ := range headCn { | ||
51 | + //索引转列名,索引从0开始 | ||
52 | + cellAlpha := fmt.Sprintf("%s%d", alphaSlice[index], 1) // 单元格行坐标从1开始,如:a1,指第一行a列。 | ||
53 | + e.Xlsx.SetCellStr("Sheet1", cellAlpha, headCn[index]) | ||
54 | + | ||
55 | + } | ||
56 | + //从excel第二行开始设置实际数据的值 | ||
57 | + for key1, _ := range sourData { | ||
58 | + for i := 0; i < len(headEn); i++ { | ||
59 | + cellAlpha := fmt.Sprintf("%s%d", alphaSlice[i], key1+2) // 单元格行坐标从1开始,如:a1,指第一行a列。 | ||
60 | + e.Xlsx.SetCellStr("Sheet1", cellAlpha, sourData[key1][headEn[i]]) | ||
61 | + } | ||
62 | + } | ||
63 | + e.FileName = GetRandomString(8) + ".xlsx" | ||
64 | + return nil | ||
65 | +} | ||
66 | + | ||
67 | +//MakeListExcel 根据数据创建列表形式的excel文档 | ||
68 | +//@sourData []orm.Params; 原始数据,要输入excel文档的数据 | ||
69 | +//@xlsxHeader [][]string{ {"数据字段英文名",""excel字段中文描述"},{"数据字段英文名",""excel字段中文描述"} } | ||
70 | +func (e *ExcelMaker) MakeListExcelForBeego(sourData []orm.Params, xlsxHeader [][]string) (err error) { | ||
71 | + if len(xlsxHeader) == 0 { | ||
72 | + return errors.New("xlsHeader 数据格式错误") | ||
73 | + } | ||
74 | + headEn := []string{} //数据字段英文名 | ||
75 | + headCn := []string{} //excel字段中文描述 | ||
76 | + alphaSlice := []string{} //excel列字母索引 | ||
77 | + for key, val := range xlsxHeader { | ||
78 | + if len(val) != 2 { | ||
79 | + return errors.New("xlsHeader 数据格式错误") | ||
80 | + } | ||
81 | + headEn = append(headEn, xlsxHeader[key][0]) | ||
82 | + headCn = append(headCn, xlsxHeader[key][1]) | ||
83 | + alpha, err := excelize.ColumnNumberToName(key) | ||
84 | + if err != nil { | ||
85 | + return err | ||
86 | + } | ||
87 | + alphaSlice = append(alphaSlice, alpha) | ||
88 | + } | ||
89 | + | ||
90 | + //设置excel文档第一行的字段中文描述 | ||
91 | + for index, _ := range headCn { | ||
92 | + //索引转列名,索引从0开始 | ||
93 | + cellAlpha := fmt.Sprintf("%s%d", alphaSlice[index], 1) // 单元格行坐标从1开始,如:a1,指第一行a列。 | ||
94 | + e.Xlsx.SetCellStr("Sheet1", cellAlpha, headCn[index]) | ||
95 | + | ||
96 | + } | ||
97 | + //从excel第二行开始设置实际数据的值 | ||
98 | + for key1, _ := range sourData { | ||
99 | + for i := 0; i < len(headEn); i++ { | ||
100 | + cellAlpha := fmt.Sprintf("%s%d", alphaSlice[i], key1+2) // 单元格行坐标从1开始,如:a1,指第一行a列。 | ||
101 | + if sourData[key1][headEn[i]] == nil { | ||
102 | + sourData[key1][headEn[i]] = "" | ||
103 | + } | ||
104 | + e.Xlsx.SetCellStr("Sheet1", cellAlpha, fmt.Sprintf("%s", sourData[key1][headEn[i]])) | ||
105 | + } | ||
106 | + } | ||
107 | + e.FileName = GetRandomString(8) + ".xlsx" | ||
108 | + return nil | ||
109 | +} | ||
110 | + | ||
111 | +//生成随机字符串 | ||
112 | +func GetRandomString(lenght int) string { | ||
113 | + str := "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" | ||
114 | + bytes := []byte(str) | ||
115 | + result := []byte{} | ||
116 | + r := rand.New(rand.NewSource(time.Now().UnixNano())) | ||
117 | + for i := 0; i < lenght; i++ { | ||
118 | + result = append(result, bytes[r.Intn(len(bytes))]) | ||
119 | + } | ||
120 | + return string(result) | ||
121 | +} |
-
请 注册 或 登录 后发表评论