作者 唐旭辉

Merge branch 'dev' of http://gitlab.fjmaimaimai.com/mmm-go/oppmg into dev

# Conflicts:
#	services/company/department.go
... ... @@ -83,7 +83,7 @@ func (this *TemplateController) TemplateList() {
defer func() {
this.ResposeJson(msg)
}()
var request *protocol.TemplateUpdateRequest
var request *protocol.TemplateListRequest
if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil {
log.Error("json 解析失败", err)
... ... @@ -101,11 +101,40 @@ func (this *TemplateController) TemplateList() {
msg = m
return
}
rsp, err := audit.TemplateUpdate(uid, companyId, request)
rsp, err := audit.TemplateList(uid, companyId, request)
msg = protocol.NewReturnResponse(rsp, err)
return
}
//TemplateGet
//@router /templateGet [post]
func (this *TemplateController) TemplateGet() {
var msg *protocol.ResponseMessage
defer func() {
this.ResposeJson(msg)
}()
var request *protocol.TemplateGetRequest
if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil {
log.Error("json 解析失败", err)
msg = protocol.BadRequestParam("1")
return
}
uid := this.GetUserId()
companyId := this.GetCompanyId()
if companyId <= 0 {
log.Debug("companyId:%d err", companyId)
msg = protocol.BadRequestParam("1")
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
rsp, err := audit.TemplateGet(uid, companyId, request)
msg = protocol.NewReturnResponse(rsp, err)
}
//TemplateEditVisible
//@router /templateEditVisible [post]
func (this *TemplateController) TemplateEditVisible() {
... ...
... ... @@ -84,6 +84,27 @@ func (t *Department) GetManages() []protocol.DepartmentManager {
return managesdata
}
func (t *Department) GetMembers() []protocol.DepartmentMember {
ids, err := GetUserDepartmentIds(int(t.CompanyId), int(t.Id))
if err != nil {
log.Error(err.Error())
return nil
}
users, err := getUserNameByIds(ids)
if err != nil {
log.Error("GetUserNameByIds err :%s", err)
return nil
}
managesdata := []protocol.DepartmentMember{}
for _, v := range users {
m := protocol.DepartmentMember{
Id: v.Id, Name: v.NickName,
}
managesdata = append(managesdata, m)
}
return managesdata
}
// AddDepartment insert a new Department into database and returns
// last inserted Id on success.
func AddDepartment(m *Department, om ...orm.Ormer) (id int64, err error) {
... ...
... ... @@ -112,3 +112,16 @@ func CountUserDepartByDepart(departid int64) (int64, error) {
Count()
return cnt, err
}
func GetUserDepartmentIds(companyId, dId int) (v []int64, err error) {
o := orm.NewOrm()
sql := `
select user_id from user_company where company_id=? and id in (
select user_company_id from user_department where company_id=? and department_id=? and enable=1
)
`
if _, err = o.Raw(sql, companyId, companyId, dId).QueryRows(&v); err != nil {
return
}
return
}
... ...
... ... @@ -17,6 +17,11 @@ 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"`
... ... @@ -37,6 +42,7 @@ type ResponseDepartmentInfo struct {
Name string `json:"name"` //部门名字
ParantID int64 `json:"parant_id"` //父级部门Id
Manages []DepartmentManager `json:"manages"` //部门管理员
Members []DepartmentMember `json:"members"` //部门成员
Member int64 `json:"member"` //成员数
}
... ...
... ... @@ -56,6 +56,14 @@ func init() {
beego.NSRouter("/role", &controllers.CommonController{}, "post:SelectorRole"),
beego.NSRouter("/position", &controllers.CommonController{}, "post:SelectorPosition"),
),
beego.NSNamespace("/template",
beego.NSRouter("/add", &controllers.TemplateController{}, "post:TemplateAdd"),
beego.NSRouter("/list", &controllers.TemplateController{}, "post:TemplateList"),
beego.NSRouter("/get", &controllers.TemplateController{}, "post:TemplateGet"),
beego.NSRouter("/update", &controllers.TemplateController{}, "post:TemplateUpdate"),
beego.NSRouter("/editVisible", &controllers.TemplateController{}, "post:TemplateEditVisible"),
beego.NSRouter("/operateCategory", &controllers.TemplateController{}, "post:TemplateOperateCategory"),
),
)
nsAuth := beego.NewNamespace("/auth",
... ...
... ... @@ -315,6 +315,7 @@ func DepartmentListAll(companyId int64) ([]protocol.ResponseDepartmentInfo, erro
var manage []protocol.DepartmentManager
manage = v.GetManages()
depart.Manages = manage
depart.Members = v.GetMembers()
departs = append(departs, depart)
}
... ...