作者 唐旭辉

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

... ... @@ -172,7 +172,11 @@ func (c *CompanyController) PositionAdd() {
msg = protocol.BadRequestParam("1")
return
}
n := []rune(param.Name)
if len(n) > 10 || len(n) == 0 {
msg = protocol.BadRequestParam("10014")
return
}
param.CompanyID = c.GetCompanyId()
positioninfo, err := servecompany.PositionAdd(param)
msg = protocol.NewReturnResponse(positioninfo, err)
... ... @@ -192,6 +196,11 @@ func (c *CompanyController) PositionEdit() {
msg = protocol.BadRequestParam("1")
return
}
n := []rune(param.Name)
if len(n) > 10 || len(n) == 0 {
msg = protocol.BadRequestParam("10014")
return
}
param.CompanyID = c.GetCompanyId()
positioninfo, err := servecompany.PositionEdit(param)
msg = protocol.NewReturnResponse(positioninfo, err)
... ... @@ -416,32 +425,25 @@ func (c *CompanyController) InitCompany() {
msg = protocol.BadRequestParam("1")
return
}
var (
err error
)
if ok := param.IsEnable(); ok {
if len(param.CompanyName) == 0 {
log.Error("公司名称空")
msg = protocol.BadRequestParam("1")
return
}
if len(param.AdminAccount) == 0 {
log.Error("人员账号空")
msg = protocol.BadRequestParam("1")
return
}
if len(param.AdminName) == 0 {
log.Error("人员名称空")
msg = protocol.BadRequestParam("1")
return
}
err = servecompany.InitCompanyInfo(param)
} else if ok := param.IsForbid(); ok {
err = servecompany.ForbidCompany(param.CompanyId)
} else {
err = protocol.NewErrWithMessage("1")
if len(param.CompanyName) == 0 {
log.Error("公司名称空")
msg = protocol.BadRequestParam("1")
return
}
if len(param.AdminAccount) == 0 {
log.Error("人员账号空")
msg = protocol.BadRequestParam("1")
return
}
if len(param.AdminName) == 0 {
log.Error("人员名称空")
msg = protocol.BadRequestParam("1")
return
}
err = servecompany.InitCompanyInfo(param)
msg = protocol.NewReturnResponse(nil, err)
return
}
... ... @@ -468,6 +470,38 @@ func (c *CompanyController) EditCompanyForUCenter() {
return
}
// AllowForidCompanyForUCenter 启用/禁用公司---总后台调用
//@router /ucenter/company/allow_forbid [post]
func (c *CompanyController) AllowForidCompanyForUCenter() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
type Paremeter struct {
Companyid int64 `json:"company_id"`
Status int `json:"status"`
}
var param Paremeter
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
log.Error("json 解析失败 err:%s", err)
msg = protocol.BadRequestParam("1")
return
}
var (
err error
)
switch param.Status {
case 1:
err = servecompany.AllowCompany(param.Companyid)
case 2:
err = servecompany.ForbidCompany(param.Companyid)
default:
err = protocol.NewErrWithMessage("1")
}
msg = protocol.NewReturnResponse(nil, err)
return
}
//GetCompanyForUCenter
//@router /ucenter/company/info [post]
func (c *CompanyController) GetCompanyForUCenter() {
... ...
... ... @@ -82,8 +82,13 @@ func GetCompanyById(id int64) (v *Company, err error) {
// UpdateCompany updates Company by Id and returns error if
// the record to be updated doesn't exist
func UpdateCompanyById(m *Company, col []string) (err error) {
o := orm.NewOrm()
func UpdateCompanyById(m *Company, col []string, om ...orm.Ormer) (err error) {
var o orm.Ormer
if len(om) > 0 {
o = om[0]
} else {
o = orm.NewOrm()
}
var num int64
m.UpdateAt = time.Now()
if num, err = o.Update(m, col...); err == nil {
... ...
... ... @@ -139,19 +139,19 @@ type CenterCompanyInfo struct {
Status int8 `json:"status"` //公司的状态 【1:启用】【2:禁用】
}
func (c CenterCompanyInfo) IsEnable() bool {
if c.Status == 1 {
return true
}
return false
}
func (c CenterCompanyInfo) IsForbid() bool {
if c.Status == 2 {
return true
}
return false
}
// func (c CenterCompanyInfo) IsEnable() bool {
// if c.Status == 1 {
// return true
// }
// return false
// }
// func (c CenterCompanyInfo) IsForbid() bool {
// if c.Status == 2 {
// return true
// }
// return false
// }
// type Request
... ...
... ... @@ -17,6 +17,7 @@ var errmessge ErrorMap = map[string]string{
"10011": "该职位已被使用无法删除",
"10012": "超过10级的职位限制,请重新选择",
"10013": "职位已存在",
"10014": "职位名称最多10个字符",
//安全认证相关
"10021": "账号或密码不正确",
"10022": "账号已被禁用",
... ... @@ -54,6 +55,8 @@ var errmessge ErrorMap = map[string]string{
"10063": "该分类已被使用无法禁用",
"10064": "编码已存在",
"10065": "编码长度最多6个字符",
//公司相关
"12001": "未找到公司信息",
}
//错误码转换 ,兼容需要
... ...
... ... @@ -108,6 +108,7 @@ func init() {
beego.NSRouter("/company/edit", &controllers.CompanyController{}, "post:EditCompanyForUCenter"),
beego.NSRouter("/user/revoke", &controllers.CompanyController{}, "post:UserRevoke"),
beego.NSRouter("/user/changePhone", &controllers.CompanyController{}, "post:UserChangePhone"),
beego.NSRouter("/company/allow_forbid", &controllers.CompanyController{}, "post:AllowForidCompanyForUCenter"),
)
beego.AddNamespace(nsV1)
... ...
... ... @@ -227,6 +227,12 @@ func initDepartment(newCompany *models.Company, newusercompany *models.UserCompa
Filter("is_top", 1).
One(newDepartment)
if err == nil {
newDepartment.Name = newCompany.Name
err = models.UpdateDepartmentById(newDepartment, []string{"Name"}, o)
if err != nil {
log.Error("更新部门关系树数据失败:%s", err)
return nil, err
}
return newDepartment, nil
} else if err == orm.ErrNoRows {
//添加部门
... ... @@ -309,7 +315,7 @@ func initRoleGroup(newCompany *models.Company, o orm.Ormer) (*models.Role, error
Types: models.ROLETYPES_GROUP,
CompanyId: newCompany.Id,
IsDefault: models.ROLE_DEFAULR,
Name: "主管组",
Name: "管理员",
}
_, err = models.AddRole(newRoleGroup, o)
if err != nil {
... ... @@ -405,19 +411,34 @@ func CompanyInfoEdit(companyid int64, logo string) error {
return nil
}
//
func CompanyEditFromUcenter(companyid int64, companyname string) error {
companyinfo, err := models.GetCompanyByUCenter(companyid)
//CompanyEditFromUcenter 总后台调用修改公司名称
func CompanyEditFromUcenter(ucompanyid int64, companyname string) error {
companyinfo, err := models.GetCompanyByUCenter(ucompanyid)
if err != nil {
log.Error("获取公司数据失败")
return protocol.NewErrWithMessage("1")
}
companyinfo.Name = companyname
o := orm.NewOrm()
o.Begin()
err = models.UpdateCompanyById(companyinfo, []string{"Name"})
if err != nil {
o.Rollback()
log.Info("更新公司数据失败:%s", err)
return protocol.NewErrWithMessage("1")
}
_, err = o.QueryTable(&models.Department{}).
Filter("company_id", companyinfo.Id).
Filter("is_top", 1).
Update(orm.Params{
"name": companyname,
})
if err != nil {
o.Rollback()
log.Error("更新部门名称失败:%s", err)
return protocol.NewErrWithMessage("1")
}
o.Commit()
return nil
}
... ... @@ -448,7 +469,7 @@ func ForbidCompany(ucenterCompany int64) error {
companyData, err = models.GetCompanyByUCenter(ucenterCompany)
if err == orm.ErrNoRows {
log.Warn("未查找到公司数据")
return nil
return protocol.NewErrWithMessage("12001")
}
if err != nil && err != orm.ErrNoRows {
log.Error(err.Error())
... ... @@ -465,6 +486,32 @@ func ForbidCompany(ucenterCompany int64) error {
return nil
}
//AllowCompany 启用公司
func AllowCompany(ucenterCompany int64) error {
var (
err error
companyData *models.Company
)
companyData, err = models.GetCompanyByUCenter(ucenterCompany)
if err == orm.ErrNoRows {
log.Warn("未查找到公司数据")
return protocol.NewErrWithMessage("12001")
}
if err != nil && err != orm.ErrNoRows {
log.Error(err.Error())
return protocol.NewErrWithMessage("1")
}
companyData.Enable = models.COMPANY_ENABLE_YES
companyData.UpdateAt = time.Now()
err = models.UpdateCompanyById(companyData, []string{"Enable", "UpdateAt"})
if err != nil {
log.Error("更新公司数据失败:%s", err)
return protocol.NewErrWithMessage("1")
}
return nil
}
func CompanyInfoForUCenter(uCenterid int64) (protocol.ResponseCenterCompany, error) {
var (
err error
... ...