正在显示
9 个修改的文件
包含
117 行增加
和
41 行删除
@@ -39,9 +39,9 @@ func (c *CompanyController) DepartmentList() { | @@ -39,9 +39,9 @@ func (c *CompanyController) DepartmentList() { | ||
39 | msg = protocol.NewReturnResponse(listdata, err) | 39 | msg = protocol.NewReturnResponse(listdata, err) |
40 | } | 40 | } |
41 | 41 | ||
42 | -// DepartmentOne 部门信息 TODO | ||
43 | -// @router /department/:id [get] | ||
44 | -func (c *CompanyController) DepartmentOne() { | 42 | +// DepartmentUser 部门下的人员 |
43 | +// @router /department/user [get] | ||
44 | +func (c *CompanyController) DepartmentUser() { | ||
45 | log.Debug("DepartmentOne param:%v", c.Ctx.Input.Param(":id")) | 45 | log.Debug("DepartmentOne param:%v", c.Ctx.Input.Param(":id")) |
46 | var msg *protocol.ResponseMessage | 46 | var msg *protocol.ResponseMessage |
47 | defer func() { | 47 | defer func() { |
@@ -91,6 +91,11 @@ func (c *CompanyController) DepartmentAdd() { | @@ -91,6 +91,11 @@ func (c *CompanyController) DepartmentAdd() { | ||
91 | msg = protocol.BadRequestParam("10042") | 91 | msg = protocol.BadRequestParam("10042") |
92 | return | 92 | return |
93 | } | 93 | } |
94 | + if param.ParentID == 0 { | ||
95 | + //部门必定有上级部门 ,至少是公司一级 | ||
96 | + msg = protocol.BadRequestParam("10042") | ||
97 | + return | ||
98 | + } | ||
94 | param.CompanyID = c.GetCompanyId() | 99 | param.CompanyID = c.GetCompanyId() |
95 | if param.CompanyID <= 0 { | 100 | if param.CompanyID <= 0 { |
96 | log.Error("param.CompanyID <= 0") | 101 | log.Error("param.CompanyID <= 0") |
@@ -8,14 +8,15 @@ import ( | @@ -8,14 +8,15 @@ import ( | ||
8 | ) | 8 | ) |
9 | 9 | ||
10 | type Company struct { | 10 | type Company struct { |
11 | - Id int64 `orm:"column(id);auto"` | ||
12 | - Name string `orm:"column(name);size(40)"` | ||
13 | - AdminId int64 `orm:"column(admin_id)"` | ||
14 | - CreateAt time.Time `orm:"column(create_at);type(timestamp);auto_now"` | ||
15 | - UpdateAt time.Time `orm:"column(update_at);type(timestamp)"` | ||
16 | - DeleteAt time.Time `orm:"column(delete_at);type(timestamp)"` | ||
17 | - Logo string `orm:"column(logo);size(255)"` | ||
18 | - Enable int8 `orm:"column(enable)"` | 11 | + Id int64 `orm:"column(id);auto"` |
12 | + Name string `orm:"column(name);size(40)"` | ||
13 | + AdminId int64 `orm:"column(admin_id)"` | ||
14 | + CreateAt time.Time `orm:"column(create_at);type(timestamp);auto_now"` | ||
15 | + UpdateAt time.Time `orm:"column(update_at);type(timestamp)"` | ||
16 | + DeleteAt time.Time `orm:"column(delete_at);type(timestamp)"` | ||
17 | + Logo string `orm:"column(logo);size(255)"` | ||
18 | + Enable int8 `orm:"column(enable)"` | ||
19 | + UserCenterId int64 `orm:"column(user_center_id)"` | ||
19 | } | 20 | } |
20 | 21 | ||
21 | func (t *Company) TableName() string { | 22 | func (t *Company) TableName() string { |
@@ -204,3 +204,16 @@ func GetDepartmentByIds(departmentIds []int64) ([]Department, error) { | @@ -204,3 +204,16 @@ func GetDepartmentByIds(departmentIds []int64) ([]Department, error) { | ||
204 | All(&result) | 204 | All(&result) |
205 | return result, err | 205 | return result, err |
206 | } | 206 | } |
207 | + | ||
208 | +func ExistDepartmentName(parentId int64, dname string) bool { | ||
209 | + var ( | ||
210 | + ok bool | ||
211 | + ) | ||
212 | + o := orm.NewOrm() | ||
213 | + ok = o.QueryTable(&Department{}). | ||
214 | + Filter("name", dname). | ||
215 | + Filter("parent_id", parentId). | ||
216 | + Filter("delete_at", 0). | ||
217 | + Exist() | ||
218 | + return ok | ||
219 | +} |
@@ -131,3 +131,9 @@ func getUserNameByIds(ids []int64) ([]User, error) { | @@ -131,3 +131,9 @@ func getUserNameByIds(ids []int64) ([]User, error) { | ||
131 | func GetUserNameByIds(ids []int64) ([]User, error) { | 131 | func GetUserNameByIds(ids []int64) ([]User, error) { |
132 | return getUserNameByIds(ids) | 132 | return getUserNameByIds(ids) |
133 | } | 133 | } |
134 | + | ||
135 | +func ExistUserByPhone(phone string) bool { | ||
136 | + o := orm.NewOrm() | ||
137 | + ok := o.QueryTable(&User{}).Filter("phone", phone).Exist() | ||
138 | + return ok | ||
139 | +} |
@@ -32,6 +32,11 @@ var errmessge ErrorMap = map[string]string{ | @@ -32,6 +32,11 @@ var errmessge ErrorMap = map[string]string{ | ||
32 | "10042": "无效的上级部门", | 32 | "10042": "无效的上级部门", |
33 | "10043": "部门名称限制不超过20个字符", | 33 | "10043": "部门名称限制不超过20个字符", |
34 | "10044": "部门名称必填", | 34 | "10044": "部门名称必填", |
35 | + "10045": "同一级部门名称不允许重复", | ||
36 | + "10046": "超过10级的部门限制,请重新选择", | ||
37 | + "10047": "只能删除没有成员的部门,需要先删除部门下的员工,再删除该部门", | ||
38 | + //用户中心相关 | ||
39 | + "10051": "无法从远端接口获取公司数据", | ||
35 | } | 40 | } |
36 | 41 | ||
37 | //错误码转换 ,兼容需要 | 42 | //错误码转换 ,兼容需要 |
@@ -12,7 +12,7 @@ func init() { | @@ -12,7 +12,7 @@ func init() { | ||
12 | nsV1 := beego.NewNamespace("v1", | 12 | nsV1 := beego.NewNamespace("v1", |
13 | beego.NSBefore(middleware.AllowOption), | 13 | beego.NSBefore(middleware.AllowOption), |
14 | beego.NSBefore(middleware.LogRequestData), | 14 | beego.NSBefore(middleware.LogRequestData), |
15 | - beego.NSBefore(middleware.AuthToken), | 15 | + //beego.NSBefore(middleware.AuthToken), |
16 | beego.NSNamespace("/department", | 16 | beego.NSNamespace("/department", |
17 | beego.NSRouter("/list", &controllers.CompanyController{}, "post:DepartmentList"), | 17 | beego.NSRouter("/list", &controllers.CompanyController{}, "post:DepartmentList"), |
18 | beego.NSRouter("/add", &controllers.CompanyController{}, "post:DepartmentAdd"), | 18 | beego.NSRouter("/add", &controllers.CompanyController{}, "post:DepartmentAdd"), |
@@ -3,14 +3,12 @@ package auth | @@ -3,14 +3,12 @@ package auth | ||
3 | import ( | 3 | import ( |
4 | "crypto/sha1" | 4 | "crypto/sha1" |
5 | "encoding/hex" | 5 | "encoding/hex" |
6 | - "encoding/json" | ||
7 | "fmt" | 6 | "fmt" |
8 | "io" | 7 | "io" |
9 | "oppmg/common/config" | 8 | "oppmg/common/config" |
10 | "oppmg/common/log" | 9 | "oppmg/common/log" |
11 | "oppmg/models" | 10 | "oppmg/models" |
12 | "oppmg/protocol" | 11 | "oppmg/protocol" |
13 | - "oppmg/services/ucenter" | ||
14 | "oppmg/storage/redisdata" | 12 | "oppmg/storage/redisdata" |
15 | "oppmg/utils" | 13 | "oppmg/utils" |
16 | "strings" | 14 | "strings" |
@@ -253,26 +251,26 @@ func LoginAuthByUCenter(account, password string) (protocol.LoginAuthToken, erro | @@ -253,26 +251,26 @@ func LoginAuthByUCenter(account, password string) (protocol.LoginAuthToken, erro | ||
253 | return logintoken, protocol.NewErrWithMessage("10021") | 251 | return logintoken, protocol.NewErrWithMessage("10021") |
254 | } | 252 | } |
255 | companyid = companys[0].Id | 253 | companyid = companys[0].Id |
256 | - var uclientReturn ucenter.ResponseLogin | ||
257 | - param := ucenter.RequesLogin{ | ||
258 | - Phone: account, | ||
259 | - Password: password, | ||
260 | - } | ||
261 | - uclient := ucenter.NewUCenterClient() | ||
262 | - btBody, err := uclient.Call(param) | ||
263 | - if err != nil { | ||
264 | - log.Error("统一用户中心请求失败 err:%s", err) | ||
265 | - return logintoken, protocol.NewErrWithMessage("1") | ||
266 | - } | ||
267 | - err = json.Unmarshal(btBody, &uclientReturn) | ||
268 | - if err != nil { | ||
269 | - log.Error("解析统一用户中心响应失败 err:%s", err) | ||
270 | - return logintoken, protocol.NewErrWithMessage("1") | ||
271 | - } | ||
272 | - if !(uclientReturn.Code == ucenter.ResponseCode0 && | ||
273 | - uclientReturn.Msg == ucenter.ResponseMsgOk) { | ||
274 | - return logintoken, protocol.NewErrWithMessage("10021") | ||
275 | - } | 254 | + // var uclientReturn ucenter.ResponseLogin |
255 | + // param := ucenter.RequesLogin{ | ||
256 | + // Phone: account, | ||
257 | + // Password: password, | ||
258 | + // } | ||
259 | + // uclient := ucenter.NewUCenterClient() | ||
260 | + // btBody, err := uclient.Call(param) | ||
261 | + // if err != nil { | ||
262 | + // log.Error("统一用户中心请求失败 err:%s", err) | ||
263 | + // return logintoken, protocol.NewErrWithMessage("1") | ||
264 | + // } | ||
265 | + // err = json.Unmarshal(btBody, &uclientReturn) | ||
266 | + // if err != nil { | ||
267 | + // log.Error("解析统一用户中心响应失败 err:%s", err) | ||
268 | + // return logintoken, protocol.NewErrWithMessage("1") | ||
269 | + // } | ||
270 | + // if !(uclientReturn.Code == ucenter.ResponseCode0 && | ||
271 | + // uclientReturn.Msg == ucenter.ResponseMsgOk) { | ||
272 | + // return logintoken, protocol.NewErrWithMessage("10021") | ||
273 | + // } | ||
276 | logintoken, _ = GenerateAuthToken(userdata.Id, companyid) | 274 | logintoken, _ = GenerateAuthToken(userdata.Id, companyid) |
277 | return logintoken, err | 275 | return logintoken, err |
278 | } | 276 | } |
@@ -18,9 +18,10 @@ func DepartmentAdd(param protocol.RequestDepartmentAdd) (protocol.ResponseDepart | @@ -18,9 +18,10 @@ func DepartmentAdd(param protocol.RequestDepartmentAdd) (protocol.ResponseDepart | ||
18 | returndata protocol.ResponseDepartmenrAdd | 18 | returndata protocol.ResponseDepartmenrAdd |
19 | err error | 19 | err error |
20 | ) | 20 | ) |
21 | - if param.ParentID == 0 { | ||
22 | - //部门必定有上级部门 ,至少是公司一级 | ||
23 | - return returndata, protocol.NewErrWithMessage("10042") | 21 | + |
22 | + ok := models.ExistDepartmentName(param.ParentID, param.Name) | ||
23 | + if ok { | ||
24 | + return returndata, protocol.NewErrWithMessage("10045") | ||
24 | } | 25 | } |
25 | if param.ParentID > 0 { | 26 | if param.ParentID > 0 { |
26 | parentDepart, err = models.GetDepartmentById(param.ParentID) | 27 | parentDepart, err = models.GetDepartmentById(param.ParentID) |
@@ -34,6 +35,12 @@ func DepartmentAdd(param protocol.RequestDepartmentAdd) (protocol.ResponseDepart | @@ -34,6 +35,12 @@ func DepartmentAdd(param protocol.RequestDepartmentAdd) (protocol.ResponseDepart | ||
34 | log.Error(e.Error()) | 35 | log.Error(e.Error()) |
35 | return returndata, protocol.NewErrWithMessage("1", e) | 36 | return returndata, protocol.NewErrWithMessage("1", e) |
36 | } | 37 | } |
38 | + | ||
39 | + r := parentDepart.Relation | ||
40 | + rs := strings.Split(r, "/") | ||
41 | + if len(rs) >= 10 { | ||
42 | + return returndata, protocol.NewErrWithMessage("10046") | ||
43 | + } | ||
37 | } | 44 | } |
38 | // for _, v := range param.Managers { | 45 | // for _, v := range param.Managers { |
39 | // uc, err := models.GetUserCompanyReal([]int64{v}) | 46 | // uc, err := models.GetUserCompanyReal([]int64{v}) |
@@ -55,6 +62,7 @@ func DepartmentAdd(param protocol.RequestDepartmentAdd) (protocol.ResponseDepart | @@ -55,6 +62,7 @@ func DepartmentAdd(param protocol.RequestDepartmentAdd) (protocol.ResponseDepart | ||
55 | Name: param.Name, | 62 | Name: param.Name, |
56 | CreateAt: time.Now(), | 63 | CreateAt: time.Now(), |
57 | UpdateAt: time.Now(), | 64 | UpdateAt: time.Now(), |
65 | + DeleteAt: time.Now(), | ||
58 | ParentId: param.ParentID, | 66 | ParentId: param.ParentID, |
59 | } | 67 | } |
60 | departmentAdd.SetManages(nil) | 68 | departmentAdd.SetManages(nil) |
@@ -74,7 +82,8 @@ func DepartmentAdd(param protocol.RequestDepartmentAdd) (protocol.ResponseDepart | @@ -74,7 +82,8 @@ func DepartmentAdd(param protocol.RequestDepartmentAdd) (protocol.ResponseDepart | ||
74 | log.Error(e.Error()) | 82 | log.Error(e.Error()) |
75 | return returndata, protocol.NewErrWithMessage("1", e) | 83 | return returndata, protocol.NewErrWithMessage("1", e) |
76 | } | 84 | } |
77 | - err = models.UpdateDepartmentById(departmentAdd, []string{"Relation"}, o) | 85 | + departmentAdd.DeleteAt = time.Unix(0, 0) |
86 | + err = models.UpdateDepartmentById(departmentAdd, []string{"Relation", "DeleteAt"}, o) | ||
78 | if err != nil { | 87 | if err != nil { |
79 | o.Rollback() | 88 | o.Rollback() |
80 | e := fmt.Errorf("UpdateDepartmentById err:%s", err) | 89 | e := fmt.Errorf("UpdateDepartmentById err:%s", err) |
@@ -114,6 +123,12 @@ func DepartmentEdit(param protocol.RequestDepartmentEdit) error { | @@ -114,6 +123,12 @@ func DepartmentEdit(param protocol.RequestDepartmentEdit) error { | ||
114 | return protocol.NewErrWithMessage("10042") | 123 | return protocol.NewErrWithMessage("10042") |
115 | } | 124 | } |
116 | } | 125 | } |
126 | + if param.Name != departUpdate.Name { | ||
127 | + ok := models.ExistDepartmentName(param.ParentID, param.Name) | ||
128 | + if ok { | ||
129 | + return protocol.NewErrWithMessage("10045") | ||
130 | + } | ||
131 | + } | ||
117 | //确认部门主管变更情况 | 132 | //确认部门主管变更情况 |
118 | var ( | 133 | var ( |
119 | newManage []int64 | 134 | newManage []int64 |
@@ -253,7 +268,7 @@ func DepartmentDelete(param protocol.RequestDepartmentDelete) error { | @@ -253,7 +268,7 @@ func DepartmentDelete(param protocol.RequestDepartmentDelete) error { | ||
253 | ) | 268 | ) |
254 | const ( | 269 | const ( |
255 | //获取部门子集, | 270 | //获取部门子集, |
256 | - dataSql0 string = `SELECT id,relation,member FROM department WHERE relation LIKE ? AND delete_at = 0 ` | 271 | + dataSql0 string = `SELECT id,relation FROM department WHERE relation LIKE ? AND delete_at = 0 ` |
257 | dataSql2 string = `update department set delete_at=? where relation LIKE ?` | 272 | dataSql2 string = `update department set delete_at=? where relation LIKE ?` |
258 | ) | 273 | ) |
259 | for _, id := range param.IDs { | 274 | for _, id := range param.IDs { |
@@ -289,7 +304,7 @@ func DepartmentDelete(param protocol.RequestDepartmentDelete) error { | @@ -289,7 +304,7 @@ func DepartmentDelete(param protocol.RequestDepartmentDelete) error { | ||
289 | cnt, err := models.CountUserDepartByDepart(subset.Id) | 304 | cnt, err := models.CountUserDepartByDepart(subset.Id) |
290 | if err != nil { | 305 | if err != nil { |
291 | log.Error("CountUserDepartByDepart err:%s", err) | 306 | log.Error("CountUserDepartByDepart err:%s", err) |
292 | - return protocol.NewErrWithMessage("1") | 307 | + return protocol.NewErrWithMessage("10047") |
293 | } | 308 | } |
294 | if cnt > 0 { | 309 | if cnt > 0 { |
295 | e := fmt.Errorf("user in department,relation:%s", subset.Relation) | 310 | e := fmt.Errorf("user in department,relation:%s", subset.Relation) |
@@ -327,7 +342,7 @@ func DepartmentListAll(companyId int64) ([]protocol.ResponseDepartmentInfo, erro | @@ -327,7 +342,7 @@ func DepartmentListAll(companyId int64) ([]protocol.ResponseDepartmentInfo, erro | ||
327 | err error | 342 | err error |
328 | ) | 343 | ) |
329 | const ( | 344 | const ( |
330 | - datasql0 string = `SELECT id, company_id,name,parent_id,member,managers ` + | 345 | + datasql0 string = `SELECT id, company_id,name,parent_id,managers ` + |
331 | ` FROM department WHERE company_id = ? AND delete_at = 0` | 346 | ` FROM department WHERE company_id = ? AND delete_at = 0` |
332 | ) | 347 | ) |
333 | err = utils.ExecuteQueryAll(&departmodels, datasql0, companyId) | 348 | err = utils.ExecuteQueryAll(&departmodels, datasql0, companyId) |
@@ -3,6 +3,7 @@ package ucenter | @@ -3,6 +3,7 @@ package ucenter | ||
3 | import ( | 3 | import ( |
4 | "encoding/json" | 4 | "encoding/json" |
5 | "errors" | 5 | "errors" |
6 | + "fmt" | ||
6 | ) | 7 | ) |
7 | 8 | ||
8 | //CommResponse 公共响应结构 | 9 | //CommResponse 公共响应结构 |
@@ -80,3 +81,35 @@ func (r RequestAddUser) Valid() error { | @@ -80,3 +81,35 @@ func (r RequestAddUser) Valid() error { | ||
80 | } | 81 | } |
81 | return nil | 82 | return nil |
82 | } | 83 | } |
84 | + | ||
85 | +type RequestCheckCompany struct { | ||
86 | + CompanyId int64 `json:"company_id"` | ||
87 | +} | ||
88 | + | ||
89 | +//Format 实现IUCenterParam接口 | ||
90 | +func (r RequestCheckCompany) Format() []byte { | ||
91 | + return nil | ||
92 | +} | ||
93 | + | ||
94 | +//Format 实现IUCenterParam接口 | ||
95 | +func (r RequestCheckCompany) GetPath() (string, string) { | ||
96 | + return fmt.Sprintf("/company/%d", r.CompanyId), "GET" | ||
97 | +} | ||
98 | + | ||
99 | +//Format 实现IUCenterParam接口 | ||
100 | +func (r RequestCheckCompany) Valid() error { | ||
101 | + if r.CompanyId == 0 { | ||
102 | + return errors.New("r.CompanyId == 0") | ||
103 | + } | ||
104 | + return nil | ||
105 | +} | ||
106 | + | ||
107 | +type ResponseCheckCompany struct { | ||
108 | + CommResponse | ||
109 | + Data struct { | ||
110 | + CompanyId int64 `json:"id"` //公司的id | ||
111 | + CompanyName string `json:"name"` //公司的名称 | ||
112 | + AdminAccount string `json:"admin_account"` //主管账号 | ||
113 | + AdminName string `json:"admin_name"` //主管名称 | ||
114 | + } `json:"data"` | ||
115 | +} |
-
请 注册 或 登录 后发表评论