作者 唐旭辉

修改部门主管添加方式

... ... @@ -21,7 +21,7 @@ func (c *CompanyController) URLMapping() {
}
// DepartmentList 部门列表
// @router /department [get]
// @router /department [post]
func (c *CompanyController) DepartmentList() {
var msg *protocol.ResponseMessage
defer func() {
... ... @@ -39,7 +39,7 @@ func (c *CompanyController) DepartmentList() {
msg = protocol.NewReturnResponse(listdata, err)
}
// DepartmentOne 部门信息
// DepartmentOne 部门信息 TODO
// @router /department/:id [get]
func (c *CompanyController) DepartmentOne() {
log.Debug("DepartmentOne param:%v", c.Ctx.Input.Param(":id"))
... ...
... ... @@ -20,7 +20,7 @@ type Department struct {
Relation string `orm:"column(relation);size(1024)" description:"父子级关系树"`
DeleteAt time.Time `orm:"column(delete_at);type(timestamp)" description:"删除时间"`
UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"`
Manages string `orm:"column(managers)" description:"部门负责人id列表 json 数组 []"`
Manages string `orm:"column(managers)" description:"部门负责人id列表 json 数组 []"` //存user_company_id
}
func (t *Department) TableName() string {
... ... @@ -41,6 +41,9 @@ func (t *Department) GetManagesIds() []int64 {
}
func (t *Department) SetManages(v []int64) {
if len(v) == 0 {
v = []int64{}
}
bt, _ := json.Marshal(v)
t.Manages = string(bt)
return
... ... @@ -58,17 +61,23 @@ func (t *Department) SetRelation(parent *Department) error {
return nil
}
//fix:变更主管获取方式
func (t *Department) GetManages() []protocol.DepartmentManager {
ids := t.GetManagesIds()
users, err := getUserNameByIds(ids)
usercompany, err := GetUserCompanyReal(ids)
if err != nil {
log.Error("GetUserNameByIds err :%s", err)
return nil
}
managesdata := []protocol.DepartmentManager{}
for _, v := range users {
for _, v := range usercompany {
u, err := GetUserById(v.UserId)
if err != nil {
log.Error("GetUserById(%d) err:%s", v.UserId, err)
continue
}
m := protocol.DepartmentManager{
Id: v.Id, Name: v.NickName,
Id: v.Id, Name: u.NickName,
}
managesdata = append(managesdata, m)
}
... ...
... ... @@ -110,9 +110,23 @@ func EnableUserCompany(userid int64, companyid int64) error {
o := orm.NewOrm()
_, err := o.QueryTable(&UserCompany{}).
Filter("user_id", userid).
Filter("company_id", companyid).Update(orm.Params{
"enable": USERCOMPANY_ENABLE_YES,
"delete_at": 0,
})
Filter("company_id", companyid).
Update(orm.Params{
"enable": USERCOMPANY_ENABLE_YES,
"delete_at": 0,
})
return err
}
func GetUserCompanyReal(ids []int64) ([]UserCompany, error) {
var (
err error
data []UserCompany
)
o := orm.NewOrm()
_, err = o.QueryTable(&UserCompany{}).
Filter("id__in", ids).
Filter("delete_at", 0).
All(&data)
return data, err
}
... ...
... ... @@ -2,10 +2,10 @@ package protocol
//RequestDepartmentAdd 部门设置
type RequestDepartmentAdd struct {
CompanyID int64 `json:"company_id"` //公司
Name string `json:"name"` //部门名字
ParentID int64 `json:"parent_id"` //父级部门Id
Managers []int64 `json:"manages"` //主管userid
CompanyID int64 `json:"company_id"` //公司
Name string `json:"name"` //部门名字
ParentID int64 `json:"parent_id"` //父级部门Id
}
type ResponseDepartmenrAdd struct {
... ... @@ -13,13 +13,14 @@ type ResponseDepartmenrAdd struct {
}
type DepartmentManager struct {
Id int64 `json:"id"`
Id int64 `json:"id"` //user_company表的id
Name string `json:"name"`
}
//RequestDepartmentEdit 编辑
type RequestDepartmentEdit struct {
ID int64 `json:"id"`
ID int64 `json:"id"`
Managers []int64 `json:"manages"` //主管user_company_id
RequestDepartmentAdd
}
... ...
... ... @@ -31,14 +31,21 @@ func DepartmentAdd(param protocol.RequestDepartmentAdd) (protocol.ResponseDepart
return returndata, protocol.NewErrWithMessage("1", e)
}
}
for _, v := range param.Managers {
_, err = models.GetUserCompanyBy(v, param.CompanyID)
if err != nil {
e := fmt.Errorf("GetUserCompanyBy(userid,companyid)[%d, %d] err:%s", v, param.CompanyID, err)
log.Error(e.Error())
return returndata, protocol.NewErrWithMessage("1", e)
}
}
// for _, v := range param.Managers {
// uc, err := models.GetUserCompanyReal([]int64{v})
// if err != nil {
// e := fmt.Errorf("GetUserCompanyReal([]int64{%d}) err:%s", v, err)
// log.Error(e.Error())
// return returndata, protocol.NewErrWithMessage("1", e)
// }
// if len(uc) > 0 {
// if uc[0].CompanyId != param.CompanyID {
// e := fmt.Errorf("managers err")
// log.Error(e.Error())
// return returndata, protocol.NewErrWithMessage("1", e)
// }
// }
// }
departmentAdd := &models.Department{
CompanyId: param.CompanyID,
Name: param.Name,
... ... @@ -46,7 +53,7 @@ func DepartmentAdd(param protocol.RequestDepartmentAdd) (protocol.ResponseDepart
UpdateAt: time.Now(),
ParentId: param.ParentID,
}
departmentAdd.SetManages(param.Managers)
departmentAdd.SetManages(nil)
o := orm.NewOrm()
o.Begin()
_, err = models.AddDepartment(departmentAdd, o)
... ... @@ -286,7 +293,7 @@ func DepartmentListAll(companyId int64) ([]protocol.ResponseDepartmentInfo, erro
err error
)
const (
datasql0 string = `SELECT id, company_id,name,parent_id,member,managers,delete_at ` +
datasql0 string = `SELECT id, company_id,name,parent_id,member,managers ` +
` FROM department WHERE company_id = ? AND delete_at = 0`
)
err = utils.ExecuteQueryAll(&departmodels, datasql0, companyId)
... ...