正在显示
5 个修改的文件
包含
57 行增加
和
26 行删除
@@ -21,7 +21,7 @@ func (c *CompanyController) URLMapping() { | @@ -21,7 +21,7 @@ func (c *CompanyController) URLMapping() { | ||
21 | } | 21 | } |
22 | 22 | ||
23 | // DepartmentList 部门列表 | 23 | // DepartmentList 部门列表 |
24 | -// @router /department [get] | 24 | +// @router /department [post] |
25 | func (c *CompanyController) DepartmentList() { | 25 | func (c *CompanyController) DepartmentList() { |
26 | var msg *protocol.ResponseMessage | 26 | var msg *protocol.ResponseMessage |
27 | defer func() { | 27 | defer func() { |
@@ -39,7 +39,7 @@ func (c *CompanyController) DepartmentList() { | @@ -39,7 +39,7 @@ func (c *CompanyController) DepartmentList() { | ||
39 | msg = protocol.NewReturnResponse(listdata, err) | 39 | msg = protocol.NewReturnResponse(listdata, err) |
40 | } | 40 | } |
41 | 41 | ||
42 | -// DepartmentOne 部门信息 | 42 | +// DepartmentOne 部门信息 TODO |
43 | // @router /department/:id [get] | 43 | // @router /department/:id [get] |
44 | func (c *CompanyController) DepartmentOne() { | 44 | func (c *CompanyController) DepartmentOne() { |
45 | log.Debug("DepartmentOne param:%v", c.Ctx.Input.Param(":id")) | 45 | log.Debug("DepartmentOne param:%v", c.Ctx.Input.Param(":id")) |
@@ -20,7 +20,7 @@ type Department struct { | @@ -20,7 +20,7 @@ type Department struct { | ||
20 | Relation string `orm:"column(relation);size(1024)" description:"父子级关系树"` | 20 | Relation string `orm:"column(relation);size(1024)" description:"父子级关系树"` |
21 | DeleteAt time.Time `orm:"column(delete_at);type(timestamp)" description:"删除时间"` | 21 | DeleteAt time.Time `orm:"column(delete_at);type(timestamp)" description:"删除时间"` |
22 | UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"` | 22 | UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"` |
23 | - Manages string `orm:"column(managers)" description:"部门负责人id列表 json 数组 []"` | 23 | + Manages string `orm:"column(managers)" description:"部门负责人id列表 json 数组 []"` //存user_company_id |
24 | } | 24 | } |
25 | 25 | ||
26 | func (t *Department) TableName() string { | 26 | func (t *Department) TableName() string { |
@@ -41,6 +41,9 @@ func (t *Department) GetManagesIds() []int64 { | @@ -41,6 +41,9 @@ func (t *Department) GetManagesIds() []int64 { | ||
41 | } | 41 | } |
42 | 42 | ||
43 | func (t *Department) SetManages(v []int64) { | 43 | func (t *Department) SetManages(v []int64) { |
44 | + if len(v) == 0 { | ||
45 | + v = []int64{} | ||
46 | + } | ||
44 | bt, _ := json.Marshal(v) | 47 | bt, _ := json.Marshal(v) |
45 | t.Manages = string(bt) | 48 | t.Manages = string(bt) |
46 | return | 49 | return |
@@ -58,17 +61,23 @@ func (t *Department) SetRelation(parent *Department) error { | @@ -58,17 +61,23 @@ func (t *Department) SetRelation(parent *Department) error { | ||
58 | return nil | 61 | return nil |
59 | } | 62 | } |
60 | 63 | ||
64 | +//fix:变更主管获取方式 | ||
61 | func (t *Department) GetManages() []protocol.DepartmentManager { | 65 | func (t *Department) GetManages() []protocol.DepartmentManager { |
62 | ids := t.GetManagesIds() | 66 | ids := t.GetManagesIds() |
63 | - users, err := getUserNameByIds(ids) | 67 | + usercompany, err := GetUserCompanyReal(ids) |
64 | if err != nil { | 68 | if err != nil { |
65 | log.Error("GetUserNameByIds err :%s", err) | 69 | log.Error("GetUserNameByIds err :%s", err) |
66 | return nil | 70 | return nil |
67 | } | 71 | } |
68 | managesdata := []protocol.DepartmentManager{} | 72 | managesdata := []protocol.DepartmentManager{} |
69 | - for _, v := range users { | 73 | + for _, v := range usercompany { |
74 | + u, err := GetUserById(v.UserId) | ||
75 | + if err != nil { | ||
76 | + log.Error("GetUserById(%d) err:%s", v.UserId, err) | ||
77 | + continue | ||
78 | + } | ||
70 | m := protocol.DepartmentManager{ | 79 | m := protocol.DepartmentManager{ |
71 | - Id: v.Id, Name: v.NickName, | 80 | + Id: v.Id, Name: u.NickName, |
72 | } | 81 | } |
73 | managesdata = append(managesdata, m) | 82 | managesdata = append(managesdata, m) |
74 | } | 83 | } |
@@ -110,9 +110,23 @@ func EnableUserCompany(userid int64, companyid int64) error { | @@ -110,9 +110,23 @@ func EnableUserCompany(userid int64, companyid int64) error { | ||
110 | o := orm.NewOrm() | 110 | o := orm.NewOrm() |
111 | _, err := o.QueryTable(&UserCompany{}). | 111 | _, err := o.QueryTable(&UserCompany{}). |
112 | Filter("user_id", userid). | 112 | Filter("user_id", userid). |
113 | - Filter("company_id", companyid).Update(orm.Params{ | ||
114 | - "enable": USERCOMPANY_ENABLE_YES, | ||
115 | - "delete_at": 0, | ||
116 | - }) | 113 | + Filter("company_id", companyid). |
114 | + Update(orm.Params{ | ||
115 | + "enable": USERCOMPANY_ENABLE_YES, | ||
116 | + "delete_at": 0, | ||
117 | + }) | ||
117 | return err | 118 | return err |
118 | } | 119 | } |
120 | + | ||
121 | +func GetUserCompanyReal(ids []int64) ([]UserCompany, error) { | ||
122 | + var ( | ||
123 | + err error | ||
124 | + data []UserCompany | ||
125 | + ) | ||
126 | + o := orm.NewOrm() | ||
127 | + _, err = o.QueryTable(&UserCompany{}). | ||
128 | + Filter("id__in", ids). | ||
129 | + Filter("delete_at", 0). | ||
130 | + All(&data) | ||
131 | + return data, err | ||
132 | +} |
@@ -2,10 +2,10 @@ package protocol | @@ -2,10 +2,10 @@ package protocol | ||
2 | 2 | ||
3 | //RequestDepartmentAdd 部门设置 | 3 | //RequestDepartmentAdd 部门设置 |
4 | type RequestDepartmentAdd struct { | 4 | type RequestDepartmentAdd struct { |
5 | - CompanyID int64 `json:"company_id"` //公司 | ||
6 | - Name string `json:"name"` //部门名字 | ||
7 | - ParentID int64 `json:"parent_id"` //父级部门Id | ||
8 | - Managers []int64 `json:"manages"` //主管userid | 5 | + CompanyID int64 `json:"company_id"` //公司 |
6 | + Name string `json:"name"` //部门名字 | ||
7 | + ParentID int64 `json:"parent_id"` //父级部门Id | ||
8 | + | ||
9 | } | 9 | } |
10 | 10 | ||
11 | type ResponseDepartmenrAdd struct { | 11 | type ResponseDepartmenrAdd struct { |
@@ -13,13 +13,14 @@ type ResponseDepartmenrAdd struct { | @@ -13,13 +13,14 @@ type ResponseDepartmenrAdd struct { | ||
13 | } | 13 | } |
14 | 14 | ||
15 | type DepartmentManager struct { | 15 | type DepartmentManager struct { |
16 | - Id int64 `json:"id"` | 16 | + Id int64 `json:"id"` //user_company表的id |
17 | Name string `json:"name"` | 17 | Name string `json:"name"` |
18 | } | 18 | } |
19 | 19 | ||
20 | //RequestDepartmentEdit 编辑 | 20 | //RequestDepartmentEdit 编辑 |
21 | type RequestDepartmentEdit struct { | 21 | type RequestDepartmentEdit struct { |
22 | - ID int64 `json:"id"` | 22 | + ID int64 `json:"id"` |
23 | + Managers []int64 `json:"manages"` //主管user_company_id | ||
23 | RequestDepartmentAdd | 24 | RequestDepartmentAdd |
24 | } | 25 | } |
25 | 26 |
@@ -31,14 +31,21 @@ func DepartmentAdd(param protocol.RequestDepartmentAdd) (protocol.ResponseDepart | @@ -31,14 +31,21 @@ func DepartmentAdd(param protocol.RequestDepartmentAdd) (protocol.ResponseDepart | ||
31 | return returndata, protocol.NewErrWithMessage("1", e) | 31 | return returndata, protocol.NewErrWithMessage("1", e) |
32 | } | 32 | } |
33 | } | 33 | } |
34 | - for _, v := range param.Managers { | ||
35 | - _, err = models.GetUserCompanyBy(v, param.CompanyID) | ||
36 | - if err != nil { | ||
37 | - e := fmt.Errorf("GetUserCompanyBy(userid,companyid)[%d, %d] err:%s", v, param.CompanyID, err) | ||
38 | - log.Error(e.Error()) | ||
39 | - return returndata, protocol.NewErrWithMessage("1", e) | ||
40 | - } | ||
41 | - } | 34 | + // for _, v := range param.Managers { |
35 | + // uc, err := models.GetUserCompanyReal([]int64{v}) | ||
36 | + // if err != nil { | ||
37 | + // e := fmt.Errorf("GetUserCompanyReal([]int64{%d}) err:%s", v, err) | ||
38 | + // log.Error(e.Error()) | ||
39 | + // return returndata, protocol.NewErrWithMessage("1", e) | ||
40 | + // } | ||
41 | + // if len(uc) > 0 { | ||
42 | + // if uc[0].CompanyId != param.CompanyID { | ||
43 | + // e := fmt.Errorf("managers err") | ||
44 | + // log.Error(e.Error()) | ||
45 | + // return returndata, protocol.NewErrWithMessage("1", e) | ||
46 | + // } | ||
47 | + // } | ||
48 | + // } | ||
42 | departmentAdd := &models.Department{ | 49 | departmentAdd := &models.Department{ |
43 | CompanyId: param.CompanyID, | 50 | CompanyId: param.CompanyID, |
44 | Name: param.Name, | 51 | Name: param.Name, |
@@ -46,7 +53,7 @@ func DepartmentAdd(param protocol.RequestDepartmentAdd) (protocol.ResponseDepart | @@ -46,7 +53,7 @@ func DepartmentAdd(param protocol.RequestDepartmentAdd) (protocol.ResponseDepart | ||
46 | UpdateAt: time.Now(), | 53 | UpdateAt: time.Now(), |
47 | ParentId: param.ParentID, | 54 | ParentId: param.ParentID, |
48 | } | 55 | } |
49 | - departmentAdd.SetManages(param.Managers) | 56 | + departmentAdd.SetManages(nil) |
50 | o := orm.NewOrm() | 57 | o := orm.NewOrm() |
51 | o.Begin() | 58 | o.Begin() |
52 | _, err = models.AddDepartment(departmentAdd, o) | 59 | _, err = models.AddDepartment(departmentAdd, o) |
@@ -286,7 +293,7 @@ func DepartmentListAll(companyId int64) ([]protocol.ResponseDepartmentInfo, erro | @@ -286,7 +293,7 @@ func DepartmentListAll(companyId int64) ([]protocol.ResponseDepartmentInfo, erro | ||
286 | err error | 293 | err error |
287 | ) | 294 | ) |
288 | const ( | 295 | const ( |
289 | - datasql0 string = `SELECT id, company_id,name,parent_id,member,managers,delete_at ` + | 296 | + datasql0 string = `SELECT id, company_id,name,parent_id,member,managers ` + |
290 | ` FROM department WHERE company_id = ? AND delete_at = 0` | 297 | ` FROM department WHERE company_id = ? AND delete_at = 0` |
291 | ) | 298 | ) |
292 | err = utils.ExecuteQueryAll(&departmodels, datasql0, companyId) | 299 | err = utils.ExecuteQueryAll(&departmodels, datasql0, companyId) |
-
请 注册 或 登录 后发表评论