作者 唐旭辉

日常提交

@@ -17,7 +17,7 @@ mysql_host = "${MYSQL_HOST||115.29.205.99}" @@ -17,7 +17,7 @@ mysql_host = "${MYSQL_HOST||115.29.205.99}"
17 mysql_port = "${MYSQL_PORT||3306}" 17 mysql_port = "${MYSQL_PORT||3306}"
18 mysql_db_name = "${MYSQL_DB_NAME||opportunity}" 18 mysql_db_name = "${MYSQL_DB_NAME||opportunity}"
19 ##redis相关配置 19 ##redis相关配置
20 -redis_add = "${REDIS_HOST||121.0.0.1}" 20 +redis_add = "${REDIS_HOST||127.0.0.1}"
21 redis_add_port = "${REDIS_PORT||6379}" 21 redis_add_port = "${REDIS_PORT||6379}"
22 redis_auth = "" 22 redis_auth = ""
23 ##log相关配置 23 ##log相关配置
@@ -7,7 +7,6 @@ import ( @@ -7,7 +7,6 @@ import (
7 servecompany "oppmg/services/company" 7 servecompany "oppmg/services/company"
8 "oppmg/storage/redisdata" 8 "oppmg/storage/redisdata"
9 "oppmg/utils" 9 "oppmg/utils"
10 - "strconv"  
11 "strings" 10 "strings"
12 ) 11 )
13 12
@@ -39,32 +38,6 @@ func (c *CompanyController) DepartmentList() { @@ -39,32 +38,6 @@ func (c *CompanyController) DepartmentList() {
39 msg = protocol.NewReturnResponse(listdata, err) 38 msg = protocol.NewReturnResponse(listdata, err)
40 } 39 }
41 40
42 -// DepartmentUser 部门下的人员  
43 -// @router /department/user [get]  
44 -func (c *CompanyController) DepartmentUser() {  
45 - log.Debug("DepartmentOne param:%v", c.Ctx.Input.Param(":id"))  
46 - var msg *protocol.ResponseMessage  
47 - defer func() {  
48 - c.ResposeJson(msg)  
49 - }()  
50 - var (  
51 - param string  
52 - id int64  
53 - err error  
54 - )  
55 - param = c.Ctx.Input.Param(":id")  
56 - id, err = strconv.ParseInt(param, 10, 64)  
57 - if err != nil {  
58 - msg = protocol.BadRequestParam("1")  
59 - return  
60 - }  
61 - if id <= 0 {  
62 - msg = protocol.BadRequestParam("1")  
63 - return  
64 - }  
65 - msg = protocol.NewReturnResponse(nil, nil)  
66 -}  
67 -  
68 // DepartmentAdd 添加部门 41 // DepartmentAdd 添加部门
69 // @router /department/add [post] 42 // @router /department/add [post]
70 func (c *CompanyController) DepartmentAdd() { 43 func (c *CompanyController) DepartmentAdd() {
@@ -350,12 +323,16 @@ func (c *CompanyController) UserDelete() { @@ -350,12 +323,16 @@ func (c *CompanyController) UserDelete() {
350 } 323 }
351 324
352 //UserEdit 禁用、启用用户 TODO 325 //UserEdit 禁用、启用用户 TODO
353 -//@Router /user/enable [post]  
354 -func (c *CompanyController) UserEnable() { 326 +//@Router /user/forbid [post]
  327 +func (c *CompanyController) UserForbid() {
355 var msg *protocol.ResponseMessage 328 var msg *protocol.ResponseMessage
356 defer func() { 329 defer func() {
357 c.ResposeJson(msg) 330 c.ResposeJson(msg)
358 }() 331 }()
  332 + type Parameter struct {
  333 + UserCompanyIds []int64 `json:"ids"`
  334 + Status int `json:"status"` // [1:执行禁用操作][2:执行启用操作]
  335 + }
359 var param protocol.RequestUserEdit 336 var param protocol.RequestUserEdit
360 if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil { 337 if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
361 log.Error("json 解析失败 err:%s", err) 338 log.Error("json 解析失败 err:%s", err)
@@ -363,10 +340,7 @@ func (c *CompanyController) UserEnable() { @@ -363,10 +340,7 @@ func (c *CompanyController) UserEnable() {
363 return 340 return
364 } 341 }
365 342
366 - param.CompanyId = c.GetCompanyId()  
367 - err := servecompany.UserEdit(param)  
368 - redisdata.DeleteLoginToken(0)  
369 - msg = protocol.NewReturnResponse(nil, err) 343 + msg = protocol.NewReturnResponse(nil, nil)
370 return 344 return
371 } 345 }
372 346
@@ -411,8 +385,9 @@ func (c *CompanyController) InitCompany() { @@ -411,8 +385,9 @@ func (c *CompanyController) InitCompany() {
411 return 385 return
412 } 386 }
413 387
414 -//GetDepartmentUser 获取部门下成员  
415 -func (c *CommonController) GetDepartmentUser() { 388 +//DepartmentUser 获取部门下成员
  389 +//@router /department/user [post]
  390 +func (c *CompanyController) DepartmentUser() {
416 var msg *protocol.ResponseMessage 391 var msg *protocol.ResponseMessage
417 defer func() { 392 defer func() {
418 c.ResposeJson(msg) 393 c.ResposeJson(msg)
@@ -426,7 +401,8 @@ func (c *CommonController) GetDepartmentUser() { @@ -426,7 +401,8 @@ func (c *CommonController) GetDepartmentUser() {
426 msg = protocol.BadRequestParam("1") 401 msg = protocol.BadRequestParam("1")
427 return 402 return
428 } 403 }
429 -  
430 - msg = protocol.NewReturnResponse(nil, nil) 404 + companyid := c.GetCompanyId()
  405 + resultdata, err := servecompany.GetDepartmentUser(companyid, param.DepartmentId)
  406 + msg = protocol.NewReturnResponse(resultdata, err)
431 return 407 return
432 } 408 }
@@ -18,7 +18,7 @@ func init() { @@ -18,7 +18,7 @@ func init() {
18 beego.NSRouter("/add", &controllers.CompanyController{}, "post:DepartmentAdd"), 18 beego.NSRouter("/add", &controllers.CompanyController{}, "post:DepartmentAdd"),
19 beego.NSRouter("/edit", &controllers.CompanyController{}, "post:DepartmentUpdate"), 19 beego.NSRouter("/edit", &controllers.CompanyController{}, "post:DepartmentUpdate"),
20 beego.NSRouter("/delete", &controllers.CompanyController{}, "post:DepartmentDelete"), 20 beego.NSRouter("/delete", &controllers.CompanyController{}, "post:DepartmentDelete"),
21 - // beego.NSRouter("/user", &controllers.CompanyController{}, "post:DepartmentDelete"), 21 + beego.NSRouter("/user", &controllers.CompanyController{}, "post:DepartmentUser"),
22 ), 22 ),
23 beego.NSNamespace("position", 23 beego.NSNamespace("position",
24 beego.NSRouter("/list", &controllers.CompanyController{}, "post:PositionList"), 24 beego.NSRouter("/list", &controllers.CompanyController{}, "post:PositionList"),
@@ -414,5 +414,5 @@ func GetDepartmentUser(companyid int64, departmentid int64) ([]protocol.DepartUs @@ -414,5 +414,5 @@ func GetDepartmentUser(companyid int64, departmentid int64) ([]protocol.DepartUs
414 } 414 }
415 returnData = append(returnData, d) 415 returnData = append(returnData, d)
416 } 416 }
417 - return nil, nil 417 + return returnData, nil
418 } 418 }
@@ -459,6 +459,7 @@ func UserList(param protocol.RequestUserList) (protocol.ResponseUserList, error) @@ -459,6 +459,7 @@ func UserList(param protocol.RequestUserList) (protocol.ResponseUserList, error)
459 return responseData, nil 459 return responseData, nil
460 } 460 }
461 461
  462 +//GetUserDepartment 获取用户的部门
462 func GetUserDepartment(usercompanyid int64) []protocol.DepartmentBase { 463 func GetUserDepartment(usercompanyid int64) []protocol.DepartmentBase {
463 const datasql string = `SELECT b.name,b.parent_id,b.id FROM user_department AS a 464 const datasql string = `SELECT b.name,b.parent_id,b.id FROM user_department AS a
464 JOIN department AS b ON a.department_id = b.id 465 JOIN department AS b ON a.department_id = b.id
@@ -475,6 +476,7 @@ func GetUserDepartment(usercompanyid int64) []protocol.DepartmentBase { @@ -475,6 +476,7 @@ func GetUserDepartment(usercompanyid int64) []protocol.DepartmentBase {
475 return data 476 return data
476 } 477 }
477 478
  479 +//GetUserPosition 获取用户的职业
478 func GetUserPosition(usercompanyid int64) []protocol.PositionBase { 480 func GetUserPosition(usercompanyid int64) []protocol.PositionBase {
479 const datasql string = `SELECT b.name,b.parent_id,b.id FROM user_position AS a 481 const datasql string = `SELECT b.name,b.parent_id,b.id FROM user_position AS a
480 JOIN position AS b ON a.position_id = b.id 482 JOIN position AS b ON a.position_id = b.id
@@ -491,6 +493,7 @@ func GetUserPosition(usercompanyid int64) []protocol.PositionBase { @@ -491,6 +493,7 @@ func GetUserPosition(usercompanyid int64) []protocol.PositionBase {
491 return data 493 return data
492 } 494 }
493 495
  496 +//GetUserRole 获取用户的角色
494 func GetUserRole(usercompanyid int64) []protocol.RoleBase { 497 func GetUserRole(usercompanyid int64) []protocol.RoleBase {
495 const datasql string = `SELECT b.name,b.pid,b.id FROM user_role AS a 498 const datasql string = `SELECT b.name,b.pid,b.id FROM user_role AS a
496 JOIN role AS b ON a.role_id = b.id 499 JOIN role AS b ON a.role_id = b.id
@@ -506,3 +509,29 @@ func GetUserRole(usercompanyid int64) []protocol.RoleBase { @@ -506,3 +509,29 @@ func GetUserRole(usercompanyid int64) []protocol.RoleBase {
506 } 509 }
507 return data 510 return data
508 } 511 }
  512 +
  513 +//启用、禁用用户
  514 +func UserForbid(userCompanyIds []int64, companyid int64, enable int8) error {
  515 + if len(userCompanyIds) == 0 {
  516 + return nil
  517 + }
  518 + if !(enable == models.USERCOMPANY_ENABLE_NO || enable == models.USERCOMPANY_ENABLE_YES) {
  519 + log.Error("enable err")
  520 + return protocol.NewErrWithMessage("1")
  521 + }
  522 + o := orm.NewOrm()
  523 + num, err := o.QueryTable(&models.UserCompany{}).
  524 + Filter("delete_at", 0).
  525 + Filter("company_id", companyid).
  526 + Filter("id__in", userCompanyIds).
  527 + Update(orm.Params{
  528 + "enable": enable,
  529 + "update_at": time.Now(),
  530 + })
  531 + if err != nil {
  532 + log.Error("更新user_company失败:%s", err)
  533 + protocol.NewErrWithMessage("1")
  534 + }
  535 + log.Info("更新记录数:%d", num)
  536 + return nil
  537 +}