作者 唐旭辉

新增接口-启用禁用公司-总后台使用

@@ -172,7 +172,11 @@ func (c *CompanyController) PositionAdd() { @@ -172,7 +172,11 @@ func (c *CompanyController) PositionAdd() {
172 msg = protocol.BadRequestParam("1") 172 msg = protocol.BadRequestParam("1")
173 return 173 return
174 } 174 }
175 - 175 + n := []rune(param.Name)
  176 + if len(n) > 10 || len(n) == 0 {
  177 + msg = protocol.BadRequestParam("10014")
  178 + return
  179 + }
176 param.CompanyID = c.GetCompanyId() 180 param.CompanyID = c.GetCompanyId()
177 positioninfo, err := servecompany.PositionAdd(param) 181 positioninfo, err := servecompany.PositionAdd(param)
178 msg = protocol.NewReturnResponse(positioninfo, err) 182 msg = protocol.NewReturnResponse(positioninfo, err)
@@ -192,6 +196,11 @@ func (c *CompanyController) PositionEdit() { @@ -192,6 +196,11 @@ func (c *CompanyController) PositionEdit() {
192 msg = protocol.BadRequestParam("1") 196 msg = protocol.BadRequestParam("1")
193 return 197 return
194 } 198 }
  199 + n := []rune(param.Name)
  200 + if len(n) > 10 || len(n) == 0 {
  201 + msg = protocol.BadRequestParam("10014")
  202 + return
  203 + }
195 param.CompanyID = c.GetCompanyId() 204 param.CompanyID = c.GetCompanyId()
196 positioninfo, err := servecompany.PositionEdit(param) 205 positioninfo, err := servecompany.PositionEdit(param)
197 msg = protocol.NewReturnResponse(positioninfo, err) 206 msg = protocol.NewReturnResponse(positioninfo, err)
@@ -416,11 +425,9 @@ func (c *CompanyController) InitCompany() { @@ -416,11 +425,9 @@ func (c *CompanyController) InitCompany() {
416 msg = protocol.BadRequestParam("1") 425 msg = protocol.BadRequestParam("1")
417 return 426 return
418 } 427 }
419 -  
420 var ( 428 var (
421 err error 429 err error
422 ) 430 )
423 - if ok := param.IsEnable(); ok {  
424 if len(param.CompanyName) == 0 { 431 if len(param.CompanyName) == 0 {
425 log.Error("公司名称空") 432 log.Error("公司名称空")
426 msg = protocol.BadRequestParam("1") 433 msg = protocol.BadRequestParam("1")
@@ -437,11 +444,6 @@ func (c *CompanyController) InitCompany() { @@ -437,11 +444,6 @@ func (c *CompanyController) InitCompany() {
437 return 444 return
438 } 445 }
439 err = servecompany.InitCompanyInfo(param) 446 err = servecompany.InitCompanyInfo(param)
440 - } else if ok := param.IsForbid(); ok {  
441 - err = servecompany.ForbidCompany(param.CompanyId)  
442 - } else {  
443 - err = protocol.NewErrWithMessage("1")  
444 - }  
445 msg = protocol.NewReturnResponse(nil, err) 447 msg = protocol.NewReturnResponse(nil, err)
446 return 448 return
447 } 449 }
@@ -468,6 +470,38 @@ func (c *CompanyController) EditCompanyForUCenter() { @@ -468,6 +470,38 @@ func (c *CompanyController) EditCompanyForUCenter() {
468 return 470 return
469 } 471 }
470 472
  473 +// AllowForidCompanyForUCenter 启用/禁用公司---总后台调用
  474 +//@router /ucenter/company/allow_forbid [post]
  475 +func (c *CompanyController) AllowForidCompanyForUCenter() {
  476 + var msg *protocol.ResponseMessage
  477 + defer func() {
  478 + c.ResposeJson(msg)
  479 + }()
  480 + type Paremeter struct {
  481 + Companyid int64 `json:"company_id"`
  482 + Status int `json:"status"`
  483 + }
  484 + var param Paremeter
  485 + if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
  486 + log.Error("json 解析失败 err:%s", err)
  487 + msg = protocol.BadRequestParam("1")
  488 + return
  489 + }
  490 + var (
  491 + err error
  492 + )
  493 + switch param.Status {
  494 + case 1:
  495 + err = servecompany.AllowCompany(param.Companyid)
  496 + case 2:
  497 + err = servecompany.ForbidCompany(param.Companyid)
  498 + default:
  499 + err = protocol.NewErrWithMessage("1")
  500 + }
  501 + msg = protocol.NewReturnResponse(nil, err)
  502 + return
  503 +}
  504 +
471 //GetCompanyForUCenter 505 //GetCompanyForUCenter
472 //@router /ucenter/company/info [post] 506 //@router /ucenter/company/info [post]
473 func (c *CompanyController) GetCompanyForUCenter() { 507 func (c *CompanyController) GetCompanyForUCenter() {
@@ -82,8 +82,13 @@ func GetCompanyById(id int64) (v *Company, err error) { @@ -82,8 +82,13 @@ func GetCompanyById(id int64) (v *Company, err error) {
82 82
83 // UpdateCompany updates Company by Id and returns error if 83 // UpdateCompany updates Company by Id and returns error if
84 // the record to be updated doesn't exist 84 // the record to be updated doesn't exist
85 -func UpdateCompanyById(m *Company, col []string) (err error) {  
86 - o := orm.NewOrm() 85 +func UpdateCompanyById(m *Company, col []string, om ...orm.Ormer) (err error) {
  86 + var o orm.Ormer
  87 + if len(om) > 0 {
  88 + o = om[0]
  89 + } else {
  90 + o = orm.NewOrm()
  91 + }
87 var num int64 92 var num int64
88 m.UpdateAt = time.Now() 93 m.UpdateAt = time.Now()
89 if num, err = o.Update(m, col...); err == nil { 94 if num, err = o.Update(m, col...); err == nil {
@@ -139,19 +139,19 @@ type CenterCompanyInfo struct { @@ -139,19 +139,19 @@ type CenterCompanyInfo struct {
139 Status int8 `json:"status"` //公司的状态 【1:启用】【2:禁用】 139 Status int8 `json:"status"` //公司的状态 【1:启用】【2:禁用】
140 } 140 }
141 141
142 -func (c CenterCompanyInfo) IsEnable() bool {  
143 - if c.Status == 1 {  
144 - return true  
145 - }  
146 - return false  
147 -}  
148 -  
149 -func (c CenterCompanyInfo) IsForbid() bool {  
150 - if c.Status == 2 {  
151 - return true  
152 - }  
153 - return false  
154 -} 142 +// func (c CenterCompanyInfo) IsEnable() bool {
  143 +// if c.Status == 1 {
  144 +// return true
  145 +// }
  146 +// return false
  147 +// }
  148 +
  149 +// func (c CenterCompanyInfo) IsForbid() bool {
  150 +// if c.Status == 2 {
  151 +// return true
  152 +// }
  153 +// return false
  154 +// }
155 155
156 // type Request 156 // type Request
157 157
@@ -17,6 +17,7 @@ var errmessge ErrorMap = map[string]string{ @@ -17,6 +17,7 @@ var errmessge ErrorMap = map[string]string{
17 "10011": "该职位已被使用无法删除", 17 "10011": "该职位已被使用无法删除",
18 "10012": "超过10级的职位限制,请重新选择", 18 "10012": "超过10级的职位限制,请重新选择",
19 "10013": "职位已存在", 19 "10013": "职位已存在",
  20 + "10014": "职位名称最多10个字符",
20 //安全认证相关 21 //安全认证相关
21 "10021": "账号或密码不正确", 22 "10021": "账号或密码不正确",
22 "10022": "账号已被禁用", 23 "10022": "账号已被禁用",
@@ -54,6 +55,8 @@ var errmessge ErrorMap = map[string]string{ @@ -54,6 +55,8 @@ var errmessge ErrorMap = map[string]string{
54 "10063": "该分类已被使用无法禁用", 55 "10063": "该分类已被使用无法禁用",
55 "10064": "编码已存在", 56 "10064": "编码已存在",
56 "10065": "编码长度最多6个字符", 57 "10065": "编码长度最多6个字符",
  58 + //公司相关
  59 + "12001": "未找到公司信息",
57 } 60 }
58 61
59 //错误码转换 ,兼容需要 62 //错误码转换 ,兼容需要
@@ -108,6 +108,7 @@ func init() { @@ -108,6 +108,7 @@ func init() {
108 beego.NSRouter("/company/edit", &controllers.CompanyController{}, "post:EditCompanyForUCenter"), 108 beego.NSRouter("/company/edit", &controllers.CompanyController{}, "post:EditCompanyForUCenter"),
109 beego.NSRouter("/user/revoke", &controllers.CompanyController{}, "post:UserRevoke"), 109 beego.NSRouter("/user/revoke", &controllers.CompanyController{}, "post:UserRevoke"),
110 beego.NSRouter("/user/changePhone", &controllers.CompanyController{}, "post:UserChangePhone"), 110 beego.NSRouter("/user/changePhone", &controllers.CompanyController{}, "post:UserChangePhone"),
  111 + beego.NSRouter("/company/allow_forbid", &controllers.CompanyController{}, "post:AllowForidCompanyForUCenter"),
111 ) 112 )
112 113
113 beego.AddNamespace(nsV1) 114 beego.AddNamespace(nsV1)
@@ -227,6 +227,12 @@ func initDepartment(newCompany *models.Company, newusercompany *models.UserCompa @@ -227,6 +227,12 @@ func initDepartment(newCompany *models.Company, newusercompany *models.UserCompa
227 Filter("is_top", 1). 227 Filter("is_top", 1).
228 One(newDepartment) 228 One(newDepartment)
229 if err == nil { 229 if err == nil {
  230 + newDepartment.Name = newCompany.Name
  231 + err = models.UpdateDepartmentById(newDepartment, []string{"Name"}, o)
  232 + if err != nil {
  233 + log.Error("更新部门关系树数据失败:%s", err)
  234 + return nil, err
  235 + }
230 return newDepartment, nil 236 return newDepartment, nil
231 } else if err == orm.ErrNoRows { 237 } else if err == orm.ErrNoRows {
232 //添加部门 238 //添加部门
@@ -309,7 +315,7 @@ func initRoleGroup(newCompany *models.Company, o orm.Ormer) (*models.Role, error @@ -309,7 +315,7 @@ func initRoleGroup(newCompany *models.Company, o orm.Ormer) (*models.Role, error
309 Types: models.ROLETYPES_GROUP, 315 Types: models.ROLETYPES_GROUP,
310 CompanyId: newCompany.Id, 316 CompanyId: newCompany.Id,
311 IsDefault: models.ROLE_DEFAULR, 317 IsDefault: models.ROLE_DEFAULR,
312 - Name: "主管组", 318 + Name: "管理员",
313 } 319 }
314 _, err = models.AddRole(newRoleGroup, o) 320 _, err = models.AddRole(newRoleGroup, o)
315 if err != nil { 321 if err != nil {
@@ -405,19 +411,34 @@ func CompanyInfoEdit(companyid int64, logo string) error { @@ -405,19 +411,34 @@ func CompanyInfoEdit(companyid int64, logo string) error {
405 return nil 411 return nil
406 } 412 }
407 413
408 -//  
409 -func CompanyEditFromUcenter(companyid int64, companyname string) error {  
410 - companyinfo, err := models.GetCompanyByUCenter(companyid) 414 +//CompanyEditFromUcenter 总后台调用修改公司名称
  415 +func CompanyEditFromUcenter(ucompanyid int64, companyname string) error {
  416 + companyinfo, err := models.GetCompanyByUCenter(ucompanyid)
411 if err != nil { 417 if err != nil {
412 log.Error("获取公司数据失败") 418 log.Error("获取公司数据失败")
413 return protocol.NewErrWithMessage("1") 419 return protocol.NewErrWithMessage("1")
414 } 420 }
415 companyinfo.Name = companyname 421 companyinfo.Name = companyname
  422 + o := orm.NewOrm()
  423 + o.Begin()
416 err = models.UpdateCompanyById(companyinfo, []string{"Name"}) 424 err = models.UpdateCompanyById(companyinfo, []string{"Name"})
417 if err != nil { 425 if err != nil {
  426 + o.Rollback()
418 log.Info("更新公司数据失败:%s", err) 427 log.Info("更新公司数据失败:%s", err)
419 return protocol.NewErrWithMessage("1") 428 return protocol.NewErrWithMessage("1")
420 } 429 }
  430 + _, err = o.QueryTable(&models.Department{}).
  431 + Filter("company_id", companyinfo.Id).
  432 + Filter("is_top", 1).
  433 + Update(orm.Params{
  434 + "name": companyname,
  435 + })
  436 + if err != nil {
  437 + o.Rollback()
  438 + log.Error("更新部门名称失败:%s", err)
  439 + return protocol.NewErrWithMessage("1")
  440 + }
  441 + o.Commit()
421 return nil 442 return nil
422 } 443 }
423 444
@@ -448,7 +469,7 @@ func ForbidCompany(ucenterCompany int64) error { @@ -448,7 +469,7 @@ func ForbidCompany(ucenterCompany int64) error {
448 companyData, err = models.GetCompanyByUCenter(ucenterCompany) 469 companyData, err = models.GetCompanyByUCenter(ucenterCompany)
449 if err == orm.ErrNoRows { 470 if err == orm.ErrNoRows {
450 log.Warn("未查找到公司数据") 471 log.Warn("未查找到公司数据")
451 - return nil 472 + return protocol.NewErrWithMessage("12001")
452 } 473 }
453 if err != nil && err != orm.ErrNoRows { 474 if err != nil && err != orm.ErrNoRows {
454 log.Error(err.Error()) 475 log.Error(err.Error())
@@ -465,6 +486,32 @@ func ForbidCompany(ucenterCompany int64) error { @@ -465,6 +486,32 @@ func ForbidCompany(ucenterCompany int64) error {
465 return nil 486 return nil
466 } 487 }
467 488
  489 +//AllowCompany 启用公司
  490 +func AllowCompany(ucenterCompany int64) error {
  491 + var (
  492 + err error
  493 + companyData *models.Company
  494 + )
  495 + companyData, err = models.GetCompanyByUCenter(ucenterCompany)
  496 + if err == orm.ErrNoRows {
  497 + log.Warn("未查找到公司数据")
  498 + return protocol.NewErrWithMessage("12001")
  499 + }
  500 + if err != nil && err != orm.ErrNoRows {
  501 + log.Error(err.Error())
  502 + return protocol.NewErrWithMessage("1")
  503 + }
  504 +
  505 + companyData.Enable = models.COMPANY_ENABLE_YES
  506 + companyData.UpdateAt = time.Now()
  507 + err = models.UpdateCompanyById(companyData, []string{"Enable", "UpdateAt"})
  508 + if err != nil {
  509 + log.Error("更新公司数据失败:%s", err)
  510 + return protocol.NewErrWithMessage("1")
  511 + }
  512 + return nil
  513 +}
  514 +
468 func CompanyInfoForUCenter(uCenterid int64) (protocol.ResponseCenterCompany, error) { 515 func CompanyInfoForUCenter(uCenterid int64) (protocol.ResponseCenterCompany, error) {
469 var ( 516 var (
470 err error 517 err error