作者 唐旭辉

bug fix

... ... @@ -39,9 +39,9 @@ func (c *CompanyController) DepartmentList() {
msg = protocol.NewReturnResponse(listdata, err)
}
// DepartmentOne 部门信息 TODO
// @router /department/:id [get]
func (c *CompanyController) DepartmentOne() {
// DepartmentUser 部门下的人员
// @router /department/user [get]
func (c *CompanyController) DepartmentUser() {
log.Debug("DepartmentOne param:%v", c.Ctx.Input.Param(":id"))
var msg *protocol.ResponseMessage
defer func() {
... ... @@ -91,6 +91,11 @@ func (c *CompanyController) DepartmentAdd() {
msg = protocol.BadRequestParam("10042")
return
}
if param.ParentID == 0 {
//部门必定有上级部门 ,至少是公司一级
msg = protocol.BadRequestParam("10042")
return
}
param.CompanyID = c.GetCompanyId()
if param.CompanyID <= 0 {
log.Error("param.CompanyID <= 0")
... ...
... ... @@ -8,14 +8,15 @@ import (
)
type Company struct {
Id int64 `orm:"column(id);auto"`
Name string `orm:"column(name);size(40)"`
AdminId int64 `orm:"column(admin_id)"`
CreateAt time.Time `orm:"column(create_at);type(timestamp);auto_now"`
UpdateAt time.Time `orm:"column(update_at);type(timestamp)"`
DeleteAt time.Time `orm:"column(delete_at);type(timestamp)"`
Logo string `orm:"column(logo);size(255)"`
Enable int8 `orm:"column(enable)"`
Id int64 `orm:"column(id);auto"`
Name string `orm:"column(name);size(40)"`
AdminId int64 `orm:"column(admin_id)"`
CreateAt time.Time `orm:"column(create_at);type(timestamp);auto_now"`
UpdateAt time.Time `orm:"column(update_at);type(timestamp)"`
DeleteAt time.Time `orm:"column(delete_at);type(timestamp)"`
Logo string `orm:"column(logo);size(255)"`
Enable int8 `orm:"column(enable)"`
UserCenterId int64 `orm:"column(user_center_id)"`
}
func (t *Company) TableName() string {
... ...
... ... @@ -204,3 +204,16 @@ func GetDepartmentByIds(departmentIds []int64) ([]Department, error) {
All(&result)
return result, err
}
func ExistDepartmentName(parentId int64, dname string) bool {
var (
ok bool
)
o := orm.NewOrm()
ok = o.QueryTable(&Department{}).
Filter("name", dname).
Filter("parent_id", parentId).
Filter("delete_at", 0).
Exist()
return ok
}
... ...
... ... @@ -131,3 +131,9 @@ func getUserNameByIds(ids []int64) ([]User, error) {
func GetUserNameByIds(ids []int64) ([]User, error) {
return getUserNameByIds(ids)
}
func ExistUserByPhone(phone string) bool {
o := orm.NewOrm()
ok := o.QueryTable(&User{}).Filter("phone", phone).Exist()
return ok
}
... ...
... ... @@ -32,6 +32,11 @@ var errmessge ErrorMap = map[string]string{
"10042": "无效的上级部门",
"10043": "部门名称限制不超过20个字符",
"10044": "部门名称必填",
"10045": "同一级部门名称不允许重复",
"10046": "超过10级的部门限制,请重新选择",
"10047": "只能删除没有成员的部门,需要先删除部门下的员工,再删除该部门",
//用户中心相关
"10051": "无法从远端接口获取公司数据",
}
//错误码转换 ,兼容需要
... ...
... ... @@ -12,7 +12,7 @@ func init() {
nsV1 := beego.NewNamespace("v1",
beego.NSBefore(middleware.AllowOption),
beego.NSBefore(middleware.LogRequestData),
beego.NSBefore(middleware.AuthToken),
//beego.NSBefore(middleware.AuthToken),
beego.NSNamespace("/department",
beego.NSRouter("/list", &controllers.CompanyController{}, "post:DepartmentList"),
beego.NSRouter("/add", &controllers.CompanyController{}, "post:DepartmentAdd"),
... ...
... ... @@ -3,14 +3,12 @@ package auth
import (
"crypto/sha1"
"encoding/hex"
"encoding/json"
"fmt"
"io"
"oppmg/common/config"
"oppmg/common/log"
"oppmg/models"
"oppmg/protocol"
"oppmg/services/ucenter"
"oppmg/storage/redisdata"
"oppmg/utils"
"strings"
... ... @@ -253,26 +251,26 @@ func LoginAuthByUCenter(account, password string) (protocol.LoginAuthToken, erro
return logintoken, protocol.NewErrWithMessage("10021")
}
companyid = companys[0].Id
var uclientReturn ucenter.ResponseLogin
param := ucenter.RequesLogin{
Phone: account,
Password: password,
}
uclient := ucenter.NewUCenterClient()
btBody, err := uclient.Call(param)
if err != nil {
log.Error("统一用户中心请求失败 err:%s", err)
return logintoken, protocol.NewErrWithMessage("1")
}
err = json.Unmarshal(btBody, &uclientReturn)
if err != nil {
log.Error("解析统一用户中心响应失败 err:%s", err)
return logintoken, protocol.NewErrWithMessage("1")
}
if !(uclientReturn.Code == ucenter.ResponseCode0 &&
uclientReturn.Msg == ucenter.ResponseMsgOk) {
return logintoken, protocol.NewErrWithMessage("10021")
}
// var uclientReturn ucenter.ResponseLogin
// param := ucenter.RequesLogin{
// Phone: account,
// Password: password,
// }
// uclient := ucenter.NewUCenterClient()
// btBody, err := uclient.Call(param)
// if err != nil {
// log.Error("统一用户中心请求失败 err:%s", err)
// return logintoken, protocol.NewErrWithMessage("1")
// }
// err = json.Unmarshal(btBody, &uclientReturn)
// if err != nil {
// log.Error("解析统一用户中心响应失败 err:%s", err)
// return logintoken, protocol.NewErrWithMessage("1")
// }
// if !(uclientReturn.Code == ucenter.ResponseCode0 &&
// uclientReturn.Msg == ucenter.ResponseMsgOk) {
// return logintoken, protocol.NewErrWithMessage("10021")
// }
logintoken, _ = GenerateAuthToken(userdata.Id, companyid)
return logintoken, err
}
... ...
... ... @@ -18,9 +18,10 @@ func DepartmentAdd(param protocol.RequestDepartmentAdd) (protocol.ResponseDepart
returndata protocol.ResponseDepartmenrAdd
err error
)
if param.ParentID == 0 {
//部门必定有上级部门 ,至少是公司一级
return returndata, protocol.NewErrWithMessage("10042")
ok := models.ExistDepartmentName(param.ParentID, param.Name)
if ok {
return returndata, protocol.NewErrWithMessage("10045")
}
if param.ParentID > 0 {
parentDepart, err = models.GetDepartmentById(param.ParentID)
... ... @@ -34,6 +35,12 @@ func DepartmentAdd(param protocol.RequestDepartmentAdd) (protocol.ResponseDepart
log.Error(e.Error())
return returndata, protocol.NewErrWithMessage("1", e)
}
r := parentDepart.Relation
rs := strings.Split(r, "/")
if len(rs) >= 10 {
return returndata, protocol.NewErrWithMessage("10046")
}
}
// for _, v := range param.Managers {
// uc, err := models.GetUserCompanyReal([]int64{v})
... ... @@ -55,6 +62,7 @@ func DepartmentAdd(param protocol.RequestDepartmentAdd) (protocol.ResponseDepart
Name: param.Name,
CreateAt: time.Now(),
UpdateAt: time.Now(),
DeleteAt: time.Now(),
ParentId: param.ParentID,
}
departmentAdd.SetManages(nil)
... ... @@ -74,7 +82,8 @@ func DepartmentAdd(param protocol.RequestDepartmentAdd) (protocol.ResponseDepart
log.Error(e.Error())
return returndata, protocol.NewErrWithMessage("1", e)
}
err = models.UpdateDepartmentById(departmentAdd, []string{"Relation"}, o)
departmentAdd.DeleteAt = time.Unix(0, 0)
err = models.UpdateDepartmentById(departmentAdd, []string{"Relation", "DeleteAt"}, o)
if err != nil {
o.Rollback()
e := fmt.Errorf("UpdateDepartmentById err:%s", err)
... ... @@ -114,6 +123,12 @@ func DepartmentEdit(param protocol.RequestDepartmentEdit) error {
return protocol.NewErrWithMessage("10042")
}
}
if param.Name != departUpdate.Name {
ok := models.ExistDepartmentName(param.ParentID, param.Name)
if ok {
return protocol.NewErrWithMessage("10045")
}
}
//确认部门主管变更情况
var (
newManage []int64
... ... @@ -253,7 +268,7 @@ func DepartmentDelete(param protocol.RequestDepartmentDelete) error {
)
const (
//获取部门子集,
dataSql0 string = `SELECT id,relation,member FROM department WHERE relation LIKE ? AND delete_at = 0 `
dataSql0 string = `SELECT id,relation FROM department WHERE relation LIKE ? AND delete_at = 0 `
dataSql2 string = `update department set delete_at=? where relation LIKE ?`
)
for _, id := range param.IDs {
... ... @@ -289,7 +304,7 @@ func DepartmentDelete(param protocol.RequestDepartmentDelete) error {
cnt, err := models.CountUserDepartByDepart(subset.Id)
if err != nil {
log.Error("CountUserDepartByDepart err:%s", err)
return protocol.NewErrWithMessage("1")
return protocol.NewErrWithMessage("10047")
}
if cnt > 0 {
e := fmt.Errorf("user in department,relation:%s", subset.Relation)
... ... @@ -327,7 +342,7 @@ func DepartmentListAll(companyId int64) ([]protocol.ResponseDepartmentInfo, erro
err error
)
const (
datasql0 string = `SELECT id, company_id,name,parent_id,member,managers ` +
datasql0 string = `SELECT id, company_id,name,parent_id,managers ` +
` FROM department WHERE company_id = ? AND delete_at = 0`
)
err = utils.ExecuteQueryAll(&departmodels, datasql0, companyId)
... ...
... ... @@ -3,6 +3,7 @@ package ucenter
import (
"encoding/json"
"errors"
"fmt"
)
//CommResponse 公共响应结构
... ... @@ -80,3 +81,35 @@ func (r RequestAddUser) Valid() error {
}
return nil
}
type RequestCheckCompany struct {
CompanyId int64 `json:"company_id"`
}
//Format 实现IUCenterParam接口
func (r RequestCheckCompany) Format() []byte {
return nil
}
//Format 实现IUCenterParam接口
func (r RequestCheckCompany) GetPath() (string, string) {
return fmt.Sprintf("/company/%d", r.CompanyId), "GET"
}
//Format 实现IUCenterParam接口
func (r RequestCheckCompany) Valid() error {
if r.CompanyId == 0 {
return errors.New("r.CompanyId == 0")
}
return nil
}
type ResponseCheckCompany struct {
CommResponse
Data struct {
CompanyId int64 `json:"id"` //公司的id
CompanyName string `json:"name"` //公司的名称
AdminAccount string `json:"admin_account"` //主管账号
AdminName string `json:"admin_name"` //主管名称
} `json:"data"`
}
... ...