作者 tangxvhui

下拉选项

... ... @@ -23,10 +23,19 @@ func (c *CommonController) SelectorDepartment() {
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 := servecommon.SelectorDepartment(companyid)
msg = protocol.NewReturnResponse(departs, nil)
departs := servecommon.SelectorDepartment(companyid, param.DepartmentId)
data := protocol.ResponseListData{List: departs}
msg = protocol.NewReturnResponse(data, nil)
return
}
... ...
... ... @@ -13,6 +13,10 @@ type ResponsePageInfo struct {
// ListData interface{} `json:"lists"`
}
type ResponseListData struct {
List interface{} `json:"lists"`
}
// DepartmentBase下拉选择列表-部门
type DepartmentBase struct {
Id int64 `json:"id" orm:"column(id)"`
... ...
... ... @@ -17,11 +17,6 @@ type DepartmentManager struct {
Name string `json:"name"`
}
type DepartmentMember struct {
Id int64 `json:"id"`
Name string `json:"name"`
}
//RequestDepartmentEdit 编辑
type RequestDepartmentEdit struct {
ID int64 `json:"id"`
... ... @@ -35,6 +30,11 @@ type RequestDepartmentDelete struct {
CompanyID int64 `json:"company_id"` //公司
}
type DepartmentMember struct {
Id int64 `json:"id"`
Name string `json:"name"`
}
//ResponseDepartmentInfo ...
type ResponseDepartmentInfo struct {
ID int64 `json:"id"`
... ...
... ... @@ -8,13 +8,21 @@ import (
"oppmg/utils"
)
func SelectorDepartment(companyid int64) []protocol.DepartmentBase {
const dataSql string = `SELECT id,name,parent_id FROM department WHERE company_id = ? AND delete_at = 0`
func SelectorDepartment(companyid int64, departmentid int64) []protocol.DepartmentBase {
var (
err error
departs []protocol.DepartmentBase
cond []interface{}
where string
)
err = utils.ExecuteQueryAll(&departs, dataSql, companyid)
dataSql := `SELECT id,name,parent_id FROM department WHERE company_id = ? AND delete_at = 0 `
cond = append(cond, companyid)
if departmentid >= 0 {
cond = append(cond, departmentid)
where += ` And parent_id=? `
}
err = utils.ExecuteQueryAll(&departs, dataSql+where, cond...)
if err != nil {
e := fmt.Errorf("EXECUTE SQL err:%s", err)
log.Error(e.Error())
... ...
... ... @@ -380,7 +380,7 @@ func GetDepartmentUser(companyid int64, departmentid int64) ([]protocol.DepartUs
department, err = models.GetDepartmentById(departmentid)
if err != nil {
log.Error("获取部门失败:%s", err)
return nil, protocol.NewErrWithMessage("1")
return nil, nil
}
if department.CompanyId != companyid {
log.Error("deparment.CompanyId err")
... ...