作者 唐旭辉

增加接口 获取部门详情

... ... @@ -137,6 +137,28 @@ func (c *CompanyController) DepartmentDelete() {
return
}
//DepartmentInfo 部门详情
//@router /department/info
func (c *CompanyController) DepartmentInfo() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
type Parameter struct {
DepartmentId int64 `json:"id"`
}
var param Parameter
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
log.Error("json 解析失败 err:%s", err)
msg = protocol.BadRequestParam("1")
return
}
companyID := c.GetCompanyId()
detail, err := servecompany.GetDepartmentDetail(companyID, param.DepartmentId)
msg = protocol.NewReturnResponse(detail, err)
return
}
// PositionAdd 添加职位
// @router /position/add [post]
func (c *CompanyController) PositionAdd() {
... ...
... ... @@ -37,13 +37,12 @@ type DepartmentMember struct {
//ResponseDepartmentInfo ...
type ResponseDepartmentInfo struct {
ID int64 `json:"id"`
CompanyID int64 `json:"company_id"` //公司
Name string `json:"name"` //部门名字
ParantID int64 `json:"parentId"` //父级部门Id
ParentName string `json:"parentName"`
Manages []DepartmentManager `json:"manages"` //部门管理员
Member int64 `json:"member"` //成员数
ID int64 `json:"id"`
CompanyID int64 `json:"company_id"` //公司
Name string `json:"name"` //部门名字
ParantID int64 `json:"parentId"` //父级部门Id
Manages []DepartmentManager `json:"manages"` //部门管理员
Member int64 `json:"member"` //成员数
}
//ResponseDepartmentList ....
... ... @@ -51,6 +50,15 @@ type ResponseDepartmentList struct {
List []ResponseDepartmentInfo `json:"lists"`
}
// 部门详情
type ResponseDepartmentDetail struct {
ID int64 `json:"id"`
Name string `json:"name"` //部门名字
ParantID int64 `json:"parentId"` //父级部门Id
ParentName string `json:"parentName"`
Manages []DepartmentManager `json:"manages"` //部门管理员
}
//RequestPositionAdd 添加职位
type RequestPositionAdd struct {
CompanyID int64 `json:"company_id"`
... ...
... ... @@ -21,6 +21,7 @@ func init() {
beego.NSRouter("/edit", &controllers.CompanyController{}, "post:DepartmentUpdate"),
beego.NSRouter("/delete", &controllers.CompanyController{}, "post:DepartmentDelete"),
beego.NSRouter("/user", &controllers.CompanyController{}, "post:DepartmentUser"),
beego.NSRouter("/info", &controllers.CompanyController{}, "post:DepartmentInfo"),
),
beego.NSNamespace("/company",
beego.NSRouter("/current/edit", &controllers.CompanyController{}, "post:CurrentCompanyEdit"),
... ...
... ... @@ -351,8 +351,7 @@ func DepartmentListAll(companyId int64) ([]protocol.ResponseDepartmentInfo, erro
depart := protocol.ResponseDepartmentInfo{
ID: v.Id, CompanyID: v.CompanyId,
Name: v.Name, Member: cnt,
ParantID: v.ParentId,
ParentName: v.Name,
ParantID: v.ParentId,
}
var manage []protocol.DepartmentManager
manage = v.GetManages()
... ... @@ -402,3 +401,35 @@ func GetDepartmentUser(companyid int64, departmentid int64) ([]protocol.DepartUs
}
return returnData, nil
}
func GetDepartmentDetail(companyid int64, departmentId int64) (*protocol.ResponseDepartmentDetail, error) {
var (
departinfo *models.Department
err error
parentDepart = &models.Department{}
)
departinfo, err = models.GetDepartmentById(departmentId)
if err != nil {
log.Error("获取部门失败:%s", err)
return nil, protocol.NewErrWithMessage("1")
}
if departinfo.CompanyId != companyid {
log.Error("部门所属的公司id不匹配")
return nil, protocol.NewErrWithMessage("1")
}
if departinfo.ParentId != 0 {
parentDepart, err = models.GetDepartmentById(departinfo.ParentId)
if err != nil {
log.Error("获取父级部门失败:%s", err)
}
}
rspData := &protocol.ResponseDepartmentDetail{
ID: departinfo.Id,
Name: departinfo.Name,
ParantID: departinfo.ParentId,
ParentName: parentDepart.Name,
Manages: departinfo.GetManages(),
}
return rspData, nil
}
... ...