作者 唐旭辉

新增下拉选择框接口

... ... @@ -87,3 +87,23 @@ func (c *CommonController) SelectorPosition() {
msg = protocol.NewReturnResponse(departs, nil)
return
}
func (c *CommonController) SelectorUserAndDepart() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
type Parameter struct {
DepartmentId int64 `json:"department_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()
departs, err := servecommon.SelectorUserAndDepartment(param.DepartmentId, companyid)
msg = protocol.NewReturnResponse(departs, err)
return
}
... ...
... ... @@ -90,8 +90,8 @@ var AllowOption = func(ctx *context.Context) {
AllowAllOrigins: true, //允许的请求来源
})
f(ctx)
ctx.Output.Body([]byte("{}"))
ctx.Output.SetStatus(204)
ctx.Output.Body([]byte("{}"))
return
}
... ...
... ... @@ -17,7 +17,7 @@ type ResponsePageInfo struct {
type DepartmentBase struct {
Id int64 `json:"id" orm:"column(id)"`
Name string `json:"name" orm:"column(name)"`
ParentId int64 `json:"parent_id" orm:"column(parent_id)"`
ParentId int64 `json:"parentId" orm:"column(parent_id)"`
}
//RoleBase 下拉选择列表-角色
... ... @@ -33,7 +33,7 @@ type RoleBase struct {
type PositionBase struct {
Id int64 `json:"id" orm:"column(id)"`
Name string `json:"name" orm:"column(name)"`
ParentId int64 `json:"parent_id" orm:"column(parent_id)"`
ParentId int64 `json:"parentId" orm:"column(parent_id)"`
}
//DepartUserBase 下拉选择列表-部门下的人员
... ... @@ -41,3 +41,9 @@ type DepartUserBase struct {
UserCompanyId int64 `json:"id" orm:"column(user_company_id)"`
Name string `json:"name" orm:"-"`
}
//部门和人员混合
type DepartAndUser struct {
Departments []DepartmentBase `json:"departments"`
Members []DepartmentMember `json:"members"`
}
... ...
... ... @@ -64,6 +64,7 @@ func init() {
beego.NSRouter("/department", &controllers.CommonController{}, "post:SelectorDepartment"),
beego.NSRouter("/role", &controllers.CommonController{}, "post:SelectorRole"),
beego.NSRouter("/position", &controllers.CommonController{}, "post:SelectorPosition"),
beego.NSRouter("/user_and_department", &controllers.CommonController{}, "post:SelectorUserAndDepart"),
),
beego.NSNamespace("/template",
beego.NSRouter("/add", &controllers.TemplateController{}, "post:TemplateAdd"),
... ...
... ... @@ -105,3 +105,43 @@ func SelectorPosition(companyid int64) []protocol.PositionBase {
return positions
}
func SelectorUserAndDepartment(departid int64, companyId int64) (*protocol.DepartAndUser, error) {
var (
mDepart *models.Department
departsUser protocol.DepartAndUser
departbase []protocol.DepartmentBase
departMember []protocol.DepartmentMember
err error
where string
cond []interface{}
)
if departid > 0 {
mDepart, err = models.GetDepartmentById(departid)
if err != nil {
log.Error("GetDepartmentById err:%s", err)
return nil, protocol.NewErrWithMessage("1")
}
if mDepart.CompanyId != companyId {
log.Error("companyid err")
return nil, protocol.NewErrWithMessage("1")
}
departMember = mDepart.GetMembers()
departsUser.Members = departMember
}
datasql0 := `SELECT id, company_id,name,parent_id ` +
` FROM department WHERE company_id = ? AND delete_at = 0 `
cond = append(cond, companyId)
if departid >= 0 {
cond = append(cond, departid)
where += ` AND parent_id =? `
}
err = utils.ExecuteQueryAll(&departbase, datasql0+where, cond...)
if err != nil {
e := fmt.Errorf("EXECUTE SQL err:%s", err)
log.Error(e.Error())
return nil, protocol.NewErrWithMessage("1", err)
}
departsUser.Departments = departbase
return &departsUser, nil
}
... ...