Merge branch 'dev' of http://gitlab.fjmaimaimai.com/mmm-go/oppmg into dev
正在显示
12 个修改的文件
包含
192 行增加
和
74 行删除
@@ -28,8 +28,8 @@ log_level = "${LOG_LEVEL||error}" | @@ -28,8 +28,8 @@ log_level = "${LOG_LEVEL||error}" | ||
28 | ##统一用户中心相关配置 | 28 | ##统一用户中心相关配置 |
29 | ucenter_check_alt = "rsF0pL!6DwjBO735" | 29 | ucenter_check_alt = "rsF0pL!6DwjBO735" |
30 | ucenter_base_url = "http://suplus-ucenter-dev.fjmaimaimai.com" | 30 | ucenter_base_url = "http://suplus-ucenter-dev.fjmaimaimai.com" |
31 | -ucenter_app_key = "39aefef9e22744a3b2d2d3791824ae7b" | ||
32 | -ucenter_secret = "39aefef9e22744a3b2d2d3791824ae7b" | 31 | +ucenter_app_key = "0692f2b7e8d6dbd8526579864b87e3bfbc5d5c31" |
32 | +ucenter_secret = "0692f2b7e8d6dbd8526579864b87e3bfbc5d5c31" | ||
33 | # 审批流程修改 消息发布 | 33 | # 审批流程修改 消息发布 |
34 | message_publish = "audit_change" | 34 | message_publish = "audit_change" |
35 | #---自定义配置 结束---- | 35 | #---自定义配置 结束---- |
@@ -28,8 +28,8 @@ log_level = "${LOG_LEVEL||error}" | @@ -28,8 +28,8 @@ log_level = "${LOG_LEVEL||error}" | ||
28 | ##统一用户中心相关配置 | 28 | ##统一用户中心相关配置 |
29 | ucenter_check_alt = "rsF0pL!6DwjBO735" | 29 | ucenter_check_alt = "rsF0pL!6DwjBO735" |
30 | ucenter_base_url = "http://suplus-ucenter-dev.fjmaimaimai.com" | 30 | ucenter_base_url = "http://suplus-ucenter-dev.fjmaimaimai.com" |
31 | -ucenter_app_key = "39aefef9e22744a3b2d2d3791824ae7b" | ||
32 | -ucenter_secret = "39aefef9e22744a3b2d2d3791824ae7b" | 31 | +ucenter_app_key = "0692f2b7e8d6dbd8526579864b87e3bfbc5d5c31" |
32 | +ucenter_secret = "0692f2b7e8d6dbd8526579864b87e3bfbc5d5c31" | ||
33 | # 审批流程修改 消息发布 | 33 | # 审批流程修改 消息发布 |
34 | message_publish = "audit_change" | 34 | message_publish = "audit_change" |
35 | #---自定义配置 结束---- | 35 | #---自定义配置 结束---- |
@@ -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")) |
@@ -78,6 +78,19 @@ func (c *CompanyController) DepartmentAdd() { | @@ -78,6 +78,19 @@ func (c *CompanyController) DepartmentAdd() { | ||
78 | msg = protocol.BadRequestParam("1") | 78 | msg = protocol.BadRequestParam("1") |
79 | return | 79 | return |
80 | } | 80 | } |
81 | + s := []rune(param.Name) | ||
82 | + if len(s) == 0 { | ||
83 | + msg = protocol.BadRequestParam("10044") | ||
84 | + return | ||
85 | + } | ||
86 | + if len(s) > 20 { | ||
87 | + msg = protocol.BadRequestParam("10043") | ||
88 | + return | ||
89 | + } | ||
90 | + if param.ParentID <= 0 { | ||
91 | + msg = protocol.BadRequestParam("10042") | ||
92 | + return | ||
93 | + } | ||
81 | param.CompanyID = c.GetCompanyId() | 94 | param.CompanyID = c.GetCompanyId() |
82 | if param.CompanyID <= 0 { | 95 | if param.CompanyID <= 0 { |
83 | log.Error("param.CompanyID <= 0") | 96 | log.Error("param.CompanyID <= 0") |
@@ -103,6 +116,15 @@ func (c *CompanyController) DepartmentUpdate() { | @@ -103,6 +116,15 @@ func (c *CompanyController) DepartmentUpdate() { | ||
103 | msg = protocol.BadRequestParam("1") | 116 | msg = protocol.BadRequestParam("1") |
104 | return | 117 | return |
105 | } | 118 | } |
119 | + s := []rune(param.Name) | ||
120 | + if len(s) == 0 { | ||
121 | + msg = protocol.BadRequestParam("10044") | ||
122 | + return | ||
123 | + } | ||
124 | + if len(s) > 20 { | ||
125 | + msg = protocol.BadRequestParam("10043") | ||
126 | + return | ||
127 | + } | ||
106 | param.CompanyID = c.GetCompanyId() | 128 | param.CompanyID = c.GetCompanyId() |
107 | if param.ID <= 0 { | 129 | if param.ID <= 0 { |
108 | log.Error(" param.ID <= 0 ") | 130 | log.Error(" param.ID <= 0 ") |
@@ -40,9 +40,7 @@ var AuthToken = func(ctx *context.Context) { | @@ -40,9 +40,7 @@ var AuthToken = func(ctx *context.Context) { | ||
40 | accesstoken := ctx.Input.Header(protocol.HeaderAccessToken) | 40 | accesstoken := ctx.Input.Header(protocol.HeaderAccessToken) |
41 | refreshToken := ctx.Input.Header(protocol.HeaderRefreshToken) | 41 | refreshToken := ctx.Input.Header(protocol.HeaderRefreshToken) |
42 | mtoken, err = serveauth.ValidJWTToken(accesstoken) | 42 | mtoken, err = serveauth.ValidJWTToken(accesstoken) |
43 | - if beego.BConfig.RunMode != "prod" { | ||
44 | - return | ||
45 | - } | 43 | + |
46 | if err == nil { | 44 | if err == nil { |
47 | storetoken, err = redisdata.GetLoginToken(mtoken.UID) | 45 | storetoken, err = redisdata.GetLoginToken(mtoken.UID) |
48 | if err != nil { | 46 | if err != nil { |
@@ -20,7 +20,8 @@ type Department struct { | @@ -20,7 +20,8 @@ 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 | + IsTop int8 `orm:"column(is_top)" ` | ||
24 | } | 25 | } |
25 | 26 | ||
26 | func (t *Department) TableName() string { | 27 | func (t *Department) TableName() string { |
@@ -41,6 +42,9 @@ func (t *Department) GetManagesIds() []int64 { | @@ -41,6 +42,9 @@ func (t *Department) GetManagesIds() []int64 { | ||
41 | } | 42 | } |
42 | 43 | ||
43 | func (t *Department) SetManages(v []int64) { | 44 | func (t *Department) SetManages(v []int64) { |
45 | + if len(v) == 0 { | ||
46 | + v = []int64{} | ||
47 | + } | ||
44 | bt, _ := json.Marshal(v) | 48 | bt, _ := json.Marshal(v) |
45 | t.Manages = string(bt) | 49 | t.Manages = string(bt) |
46 | return | 50 | return |
@@ -58,17 +62,23 @@ func (t *Department) SetRelation(parent *Department) error { | @@ -58,17 +62,23 @@ func (t *Department) SetRelation(parent *Department) error { | ||
58 | return nil | 62 | return nil |
59 | } | 63 | } |
60 | 64 | ||
65 | +//fix:变更主管获取方式 | ||
61 | func (t *Department) GetManages() []protocol.DepartmentManager { | 66 | func (t *Department) GetManages() []protocol.DepartmentManager { |
62 | ids := t.GetManagesIds() | 67 | ids := t.GetManagesIds() |
63 | - users, err := getUserNameByIds(ids) | 68 | + usercompany, err := GetUserCompanyReal(ids) |
64 | if err != nil { | 69 | if err != nil { |
65 | log.Error("GetUserNameByIds err :%s", err) | 70 | log.Error("GetUserNameByIds err :%s", err) |
66 | return nil | 71 | return nil |
67 | } | 72 | } |
68 | managesdata := []protocol.DepartmentManager{} | 73 | managesdata := []protocol.DepartmentManager{} |
69 | - for _, v := range users { | 74 | + for _, v := range usercompany { |
75 | + u, err := GetUserById(v.UserId) | ||
76 | + if err != nil { | ||
77 | + log.Error("GetUserById(%d) err:%s", v.UserId, err) | ||
78 | + continue | ||
79 | + } | ||
70 | m := protocol.DepartmentManager{ | 80 | m := protocol.DepartmentManager{ |
71 | - Id: v.Id, Name: v.NickName, | 81 | + Id: v.Id, Name: u.NickName, |
72 | } | 82 | } |
73 | managesdata = append(managesdata, m) | 83 | managesdata = append(managesdata, m) |
74 | } | 84 | } |
@@ -96,6 +106,13 @@ func (t *Department) GetMembers() []protocol.DepartmentMember { | @@ -96,6 +106,13 @@ func (t *Department) GetMembers() []protocol.DepartmentMember { | ||
96 | return managesdata | 106 | return managesdata |
97 | } | 107 | } |
98 | 108 | ||
109 | +func (t *Department) IsTopDepartment() bool { | ||
110 | + if t.IsTop == 1 { | ||
111 | + return true | ||
112 | + } | ||
113 | + return false | ||
114 | +} | ||
115 | + | ||
99 | // AddDepartment insert a new Department into database and returns | 116 | // AddDepartment insert a new Department into database and returns |
100 | // last inserted Id on success. | 117 | // last inserted Id on success. |
101 | func AddDepartment(m *Department, om ...orm.Ormer) (id int64, err error) { | 118 | func AddDepartment(m *Department, om ...orm.Ormer) (id int64, err error) { |
@@ -110,9 +110,27 @@ func EnableUserCompany(userid int64, companyid int64) error { | @@ -110,9 +110,27 @@ 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{ | 113 | + Filter("company_id", companyid). |
114 | + Update(orm.Params{ | ||
114 | "enable": USERCOMPANY_ENABLE_YES, | 115 | "enable": USERCOMPANY_ENABLE_YES, |
115 | "delete_at": 0, | 116 | "delete_at": 0, |
116 | }) | 117 | }) |
117 | return err | 118 | return err |
118 | } | 119 | } |
120 | + | ||
121 | +func GetUserCompanyReal(ids []int64) ([]UserCompany, error) { | ||
122 | + | ||
123 | + var ( | ||
124 | + err error | ||
125 | + data []UserCompany | ||
126 | + ) | ||
127 | + if len(ids) == 0 { | ||
128 | + return data, nil | ||
129 | + } | ||
130 | + o := orm.NewOrm() | ||
131 | + _, err = o.QueryTable(&UserCompany{}). | ||
132 | + Filter("id__in", ids). | ||
133 | + Filter("delete_at", 0). | ||
134 | + All(&data) | ||
135 | + return data, err | ||
136 | +} |
@@ -63,42 +63,43 @@ func AddUserDepartment(m *UserDepartment) (id int64, err error) { | @@ -63,42 +63,43 @@ func AddUserDepartment(m *UserDepartment) (id int64, err error) { | ||
63 | 63 | ||
64 | // GetUserDepartmentById retrieves UserDepartment by Id. Returns error if | 64 | // GetUserDepartmentById retrieves UserDepartment by Id. Returns error if |
65 | // Id doesn't exist | 65 | // Id doesn't exist |
66 | -func GetUserDepartmentById(id int64) (v *UserDepartment, err error) { | ||
67 | - o := orm.NewOrm() | ||
68 | - v = &UserDepartment{Id: id} | ||
69 | - if err = o.Read(v); err == nil { | ||
70 | - return v, nil | ||
71 | - } | ||
72 | - return nil, err | ||
73 | -} | 66 | +// func GetUserDepartmentById(id int64) (v *UserDepartment, err error) { |
67 | +// o := orm.NewOrm() | ||
68 | +// v = &UserDepartment{Id: id} | ||
69 | +// if err = o.Read(v); err == nil { | ||
70 | +// return v, nil | ||
71 | +// } | ||
72 | +// return nil, err | ||
73 | +// } | ||
74 | 74 | ||
75 | // UpdateUserDepartment updates UserDepartment by Id and returns error if | 75 | // UpdateUserDepartment updates UserDepartment by Id and returns error if |
76 | // the record to be updated doesn't exist | 76 | // the record to be updated doesn't exist |
77 | -func UpdateUserDepartmentById(m *UserDepartment) (err error) { | ||
78 | - o := orm.NewOrm() | ||
79 | - v := UserDepartment{Id: m.Id} | ||
80 | - // ascertain id exists in the database | ||
81 | - if err = o.Read(&v); err == nil { | ||
82 | - var num int64 | ||
83 | - if num, err = o.Update(m); err == nil { | ||
84 | - fmt.Println("Number of records updated in database:", num) | ||
85 | - } | ||
86 | - } | ||
87 | - return | ||
88 | -} | ||
89 | -func GetUserDepartment(userid, companyid int64) ([]*UserDepartment, error) { | ||
90 | - o := orm.NewOrm() | ||
91 | - var ( | ||
92 | - err error | ||
93 | - result []*UserDepartment | ||
94 | - ) | ||
95 | - _, err = o.QueryTable(&UserDepartment{}). | ||
96 | - Filter("user_id", userid). | ||
97 | - Filter("company_id", companyid). | ||
98 | - Filter("enable_status", 1). | ||
99 | - All(&result) | ||
100 | - return result, err | ||
101 | -} | 77 | +// func UpdateUserDepartmentById(m *UserDepartment) (err error) { |
78 | +// o := orm.NewOrm() | ||
79 | +// v := UserDepartment{Id: m.Id} | ||
80 | +// // ascertain id exists in the database | ||
81 | +// if err = o.Read(&v); err == nil { | ||
82 | +// var num int64 | ||
83 | +// if num, err = o.Update(m); err == nil { | ||
84 | +// fmt.Println("Number of records updated in database:", num) | ||
85 | +// } | ||
86 | +// } | ||
87 | +// return | ||
88 | +// } | ||
89 | + | ||
90 | +// func GetUserDepartment(userid, companyid int64) ([]*UserDepartment, error) { | ||
91 | +// o := orm.NewOrm() | ||
92 | +// var ( | ||
93 | +// err error | ||
94 | +// result []*UserDepartment | ||
95 | +// ) | ||
96 | +// _, err = o.QueryTable(&UserDepartment{}). | ||
97 | +// Filter("user_id", userid). | ||
98 | +// Filter("company_id", companyid). | ||
99 | +// Filter("enable_status", 1). | ||
100 | +// All(&result) | ||
101 | +// return result, err | ||
102 | +// } | ||
102 | 103 | ||
103 | func CountUserDepartByDepart(departid int64) (int64, error) { | 104 | func CountUserDepartByDepart(departid int64) (int64, error) { |
104 | var ( | 105 | var ( |
@@ -125,3 +126,16 @@ func GetUserDepartmentIds(companyId, dId int) (v []int64, err error) { | @@ -125,3 +126,16 @@ func GetUserDepartmentIds(companyId, dId int) (v []int64, err error) { | ||
125 | } | 126 | } |
126 | return | 127 | return |
127 | } | 128 | } |
129 | + | ||
130 | +func ExistUserDepart(departid int64, usercompanyid int64) bool { | ||
131 | + var ( | ||
132 | + ok bool | ||
133 | + ) | ||
134 | + o := orm.NewOrm() | ||
135 | + ok = o.QueryTable(&UserDepartment{}). | ||
136 | + Filter("department_id", departid). | ||
137 | + Filter("user_company_id", usercompanyid). | ||
138 | + Filter("delete_at", 0). | ||
139 | + Exist() | ||
140 | + return ok | ||
141 | +} |
@@ -5,7 +5,7 @@ type RequestDepartmentAdd struct { | @@ -5,7 +5,7 @@ type RequestDepartmentAdd struct { | ||
5 | CompanyID int64 `json:"company_id"` //公司 | 5 | CompanyID int64 `json:"company_id"` //公司 |
6 | Name string `json:"name"` //部门名字 | 6 | Name string `json:"name"` //部门名字 |
7 | ParentID int64 `json:"parent_id"` //父级部门Id | 7 | ParentID int64 `json:"parent_id"` //父级部门Id |
8 | - Managers []int64 `json:"manages"` //主管userid | 8 | + |
9 | } | 9 | } |
10 | 10 | ||
11 | type ResponseDepartmenrAdd struct { | 11 | type ResponseDepartmenrAdd struct { |
@@ -13,7 +13,7 @@ type ResponseDepartmenrAdd struct { | @@ -13,7 +13,7 @@ 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 | ||
@@ -25,6 +25,7 @@ type DepartmentMember struct { | @@ -25,6 +25,7 @@ type DepartmentMember struct { | ||
25 | //RequestDepartmentEdit 编辑 | 25 | //RequestDepartmentEdit 编辑 |
26 | type RequestDepartmentEdit struct { | 26 | type RequestDepartmentEdit struct { |
27 | ID int64 `json:"id"` | 27 | ID int64 `json:"id"` |
28 | + Managers []int64 `json:"manages"` //主管user_company_id | ||
28 | RequestDepartmentAdd | 29 | RequestDepartmentAdd |
29 | } | 30 | } |
30 | 31 |
@@ -27,6 +27,11 @@ var errmessge ErrorMap = map[string]string{ | @@ -27,6 +27,11 @@ var errmessge ErrorMap = map[string]string{ | ||
27 | "10037": "用户的部门必填", | 27 | "10037": "用户的部门必填", |
28 | "10038": "用户的角色必填", | 28 | "10038": "用户的角色必填", |
29 | "10039": "用户已存在", | 29 | "10039": "用户已存在", |
30 | + //部门相关 | ||
31 | + "10041": "无效的主管设置", | ||
32 | + "10042": "无效的上级部门", | ||
33 | + "10043": "部门名称限制不超过20个字符", | ||
34 | + "10044": "部门名称必填", | ||
30 | } | 35 | } |
31 | 36 | ||
32 | //错误码转换 ,兼容需要 | 37 | //错误码转换 ,兼容需要 |
@@ -12,7 +12,7 @@ func init() { | @@ -12,7 +12,7 @@ func init() { | ||
12 | nsV1 := beego.NewNamespace("v1", | 12 | nsV1 := beego.NewNamespace("v1", |
13 | beego.NSBefore(middleware.AllowOption), | 13 | beego.NSBefore(middleware.AllowOption), |
14 | beego.NSBefore(middleware.LogRequestData), | 14 | beego.NSBefore(middleware.LogRequestData), |
15 | - //beego.NSBefore(middleware.AuthToken), | 15 | + beego.NSBefore(middleware.AuthToken), |
16 | beego.NSNamespace("/department", | 16 | beego.NSNamespace("/department", |
17 | beego.NSRouter("/list", &controllers.CompanyController{}, "post:DepartmentList"), | 17 | beego.NSRouter("/list", &controllers.CompanyController{}, "post:DepartmentList"), |
18 | beego.NSRouter("/add", &controllers.CompanyController{}, "post:DepartmentAdd"), | 18 | beego.NSRouter("/add", &controllers.CompanyController{}, "post:DepartmentAdd"), |
@@ -226,7 +226,7 @@ func LoginAuthByUCenter(account, password string) (protocol.LoginAuthToken, erro | @@ -226,7 +226,7 @@ func LoginAuthByUCenter(account, password string) (protocol.LoginAuthToken, erro | ||
226 | var ( | 226 | var ( |
227 | err error | 227 | err error |
228 | logintoken protocol.LoginAuthToken | 228 | logintoken protocol.LoginAuthToken |
229 | - uclientReturn ucenter.ResponseLogin | 229 | + |
230 | companys []companybase | 230 | companys []companybase |
231 | companyid int64 | 231 | companyid int64 |
232 | userdata *models.User | 232 | userdata *models.User |
@@ -253,6 +253,7 @@ func LoginAuthByUCenter(account, password string) (protocol.LoginAuthToken, erro | @@ -253,6 +253,7 @@ func LoginAuthByUCenter(account, password string) (protocol.LoginAuthToken, erro | ||
253 | return logintoken, protocol.NewErrWithMessage("10021") | 253 | return logintoken, protocol.NewErrWithMessage("10021") |
254 | } | 254 | } |
255 | companyid = companys[0].Id | 255 | companyid = companys[0].Id |
256 | + var uclientReturn ucenter.ResponseLogin | ||
256 | param := ucenter.RequesLogin{ | 257 | param := ucenter.RequesLogin{ |
257 | Phone: account, | 258 | Phone: account, |
258 | Password: password, | 259 | Password: password, |
@@ -283,27 +284,28 @@ type companybase struct { | @@ -283,27 +284,28 @@ type companybase struct { | ||
283 | } | 284 | } |
284 | 285 | ||
285 | //getUserCompanyReal 获取用户有效的公司id | 286 | //getUserCompanyReal 获取用户有效的公司id |
286 | -func getUserCompanyReal(userid int64) (companyids []companybase, err error) { | 287 | +func getUserCompanyReal(userid int64) ([]companybase, error) { |
287 | const ( | 288 | const ( |
288 | datasql0 string = `SELECT b.company_id FROM user_company AS b | 289 | datasql0 string = `SELECT b.company_id FROM user_company AS b |
289 | WHERE b.delete_at=0 AND b.enable = 1 AND b.user_id=?` | 290 | WHERE b.delete_at=0 AND b.enable = 1 AND b.user_id=?` |
290 | - datasql2 string = `SELECT b.id,a.name,a.logo FROM company AS b | 291 | + datasql2 string = `SELECT b.id,b.name,b.logo FROM company AS b |
291 | WHERE b.delete_at=0 AND b.enable = 1 AND b.id in (%s) ` | 292 | WHERE b.delete_at=0 AND b.enable = 1 AND b.id in (%s) ` |
292 | ) | 293 | ) |
293 | var ( | 294 | var ( |
294 | companys []companybase | 295 | companys []companybase |
295 | ids []string | 296 | ids []string |
297 | + err error | ||
296 | ) | 298 | ) |
297 | err = utils.ExecuteQueryAll(&ids, datasql0, userid) | 299 | err = utils.ExecuteQueryAll(&ids, datasql0, userid) |
298 | if err != nil { | 300 | if err != nil { |
299 | log.Error("EXECUTE SQL err:%s", err) | 301 | log.Error("EXECUTE SQL err:%s", err) |
300 | return nil, err | 302 | return nil, err |
301 | } | 303 | } |
302 | - if len(companys) == 0 { | 304 | + if len(ids) == 0 { |
303 | return nil, nil | 305 | return nil, nil |
304 | } | 306 | } |
305 | datasql3 := fmt.Sprintf(datasql2, strings.Join(ids, ",")) | 307 | datasql3 := fmt.Sprintf(datasql2, strings.Join(ids, ",")) |
306 | - err = utils.ExecuteQueryAll(&companyids, datasql3) | 308 | + err = utils.ExecuteQueryAll(&companys, datasql3) |
307 | if err != nil { | 309 | if err != nil { |
308 | log.Error("EXECUTE SQL err:%s", err) | 310 | log.Error("EXECUTE SQL err:%s", err) |
309 | return nil, err | 311 | return nil, err |
@@ -18,6 +18,10 @@ func DepartmentAdd(param protocol.RequestDepartmentAdd) (protocol.ResponseDepart | @@ -18,6 +18,10 @@ func DepartmentAdd(param protocol.RequestDepartmentAdd) (protocol.ResponseDepart | ||
18 | returndata protocol.ResponseDepartmenrAdd | 18 | returndata protocol.ResponseDepartmenrAdd |
19 | err error | 19 | err error |
20 | ) | 20 | ) |
21 | + if param.ParentID == 0 { | ||
22 | + //部门必定有上级部门 ,至少是公司一级 | ||
23 | + return returndata, protocol.NewErrWithMessage("10042") | ||
24 | + } | ||
21 | if param.ParentID > 0 { | 25 | if param.ParentID > 0 { |
22 | parentDepart, err = models.GetDepartmentById(param.ParentID) | 26 | parentDepart, err = models.GetDepartmentById(param.ParentID) |
23 | if err != nil { | 27 | if err != nil { |
@@ -31,14 +35,21 @@ func DepartmentAdd(param protocol.RequestDepartmentAdd) (protocol.ResponseDepart | @@ -31,14 +35,21 @@ func DepartmentAdd(param protocol.RequestDepartmentAdd) (protocol.ResponseDepart | ||
31 | return returndata, protocol.NewErrWithMessage("1", e) | 35 | return returndata, protocol.NewErrWithMessage("1", e) |
32 | } | 36 | } |
33 | } | 37 | } |
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 | - } | 38 | + // for _, v := range param.Managers { |
39 | + // uc, err := models.GetUserCompanyReal([]int64{v}) | ||
40 | + // if err != nil { | ||
41 | + // e := fmt.Errorf("GetUserCompanyReal([]int64{%d}) err:%s", v, err) | ||
42 | + // log.Error(e.Error()) | ||
43 | + // return returndata, protocol.NewErrWithMessage("1", e) | ||
44 | + // } | ||
45 | + // if len(uc) > 0 { | ||
46 | + // if uc[0].CompanyId != param.CompanyID { | ||
47 | + // e := fmt.Errorf("managers err") | ||
48 | + // log.Error(e.Error()) | ||
49 | + // return returndata, protocol.NewErrWithMessage("1", e) | ||
50 | + // } | ||
51 | + // } | ||
52 | + // } | ||
42 | departmentAdd := &models.Department{ | 53 | departmentAdd := &models.Department{ |
43 | CompanyId: param.CompanyID, | 54 | CompanyId: param.CompanyID, |
44 | Name: param.Name, | 55 | Name: param.Name, |
@@ -46,7 +57,7 @@ func DepartmentAdd(param protocol.RequestDepartmentAdd) (protocol.ResponseDepart | @@ -46,7 +57,7 @@ func DepartmentAdd(param protocol.RequestDepartmentAdd) (protocol.ResponseDepart | ||
46 | UpdateAt: time.Now(), | 57 | UpdateAt: time.Now(), |
47 | ParentId: param.ParentID, | 58 | ParentId: param.ParentID, |
48 | } | 59 | } |
49 | - departmentAdd.SetManages(param.Managers) | 60 | + departmentAdd.SetManages(nil) |
50 | o := orm.NewOrm() | 61 | o := orm.NewOrm() |
51 | o.Begin() | 62 | o.Begin() |
52 | _, err = models.AddDepartment(departmentAdd, o) | 63 | _, err = models.AddDepartment(departmentAdd, o) |
@@ -93,22 +104,46 @@ func DepartmentEdit(param protocol.RequestDepartmentEdit) error { | @@ -93,22 +104,46 @@ func DepartmentEdit(param protocol.RequestDepartmentEdit) error { | ||
93 | log.Error(e.Error()) | 104 | log.Error(e.Error()) |
94 | return protocol.NewErrWithMessage("1", e) | 105 | return protocol.NewErrWithMessage("1", e) |
95 | } | 106 | } |
107 | + //校验数据 | ||
108 | + if ok := departUpdate.IsTopDepartment(); ok { | ||
109 | + //公司一级不能修改上级,不能修改名称 | ||
110 | + param.Name = departUpdate.Name | ||
111 | + param.ParentID = departUpdate.ParentId | ||
112 | + } else { | ||
113 | + if param.ParentID <= 0 { | ||
114 | + return protocol.NewErrWithMessage("10042") | ||
115 | + } | ||
116 | + } | ||
96 | //确认部门主管变更情况 | 117 | //确认部门主管变更情况 |
97 | var ( | 118 | var ( |
98 | - oldmanage []int64 | 119 | + newManage []int64 |
99 | ) | 120 | ) |
100 | - oldmanage = departUpdate.GetManagesIds() | ||
101 | - diffmanage := utils.ArrayInt64Diff(param.Managers, oldmanage) | ||
102 | - for i := range diffmanage { | ||
103 | - _, err = models.GetUserCompanyBy(diffmanage[i], param.CompanyID) | 121 | + //oldmanage = departUpdate.GetManagesIds() |
122 | + //diffmanage := utils.ArrayInt64Diff(param.Managers, oldmanage) | ||
123 | + uc, err := models.GetUserCompanyReal(param.Managers) | ||
104 | if err != nil { | 124 | if err != nil { |
105 | - e := fmt.Errorf("GetUserCompanyBy(userid,companyid)[%d,%d] err:%s", diffmanage[i], param.CompanyID, err) | 125 | + e := fmt.Errorf("GetUserCompanyReal err:%s", err) |
106 | log.Error(e.Error()) | 126 | log.Error(e.Error()) |
107 | - return protocol.NewErrWithMessage("1", e) | 127 | + return protocol.NewErrWithMessage("10041") |
108 | } | 128 | } |
129 | + for i := range uc { | ||
130 | + if uc[i].CompanyId != param.CompanyID { | ||
131 | + e := fmt.Errorf("managers err") | ||
132 | + log.Error(e.Error()) | ||
133 | + return protocol.NewErrWithMessage("10041") | ||
134 | + } | ||
135 | + //检查设置的主管是否是部门下的人员 | ||
136 | + ok := models.ExistUserDepart(param.ID, uc[i].Id) | ||
137 | + if !ok { | ||
138 | + log.Error("false=aExistUserDepart(departid,usercompanyid) [%d,%d]", param.ID, uc[i].Id) | ||
139 | + return protocol.NewErrWithMessage("10041") | ||
109 | } | 140 | } |
110 | - departUpdate.SetManages(param.Managers) | 141 | + newManage = append(newManage, uc[i].Id) |
142 | + } | ||
143 | + departUpdate.SetManages(newManage) | ||
144 | + | ||
111 | departUpdate.Name = param.Name | 145 | departUpdate.Name = param.Name |
146 | + | ||
112 | departUpdate.UpdateAt = time.Now() | 147 | departUpdate.UpdateAt = time.Now() |
113 | err = models.UpdateDepartmentById(departUpdate, []string{"Manages", "Name", "UpdateAt"}) | 148 | err = models.UpdateDepartmentById(departUpdate, []string{"Manages", "Name", "UpdateAt"}) |
114 | if err != nil { | 149 | if err != nil { |
@@ -120,7 +155,9 @@ func DepartmentEdit(param protocol.RequestDepartmentEdit) error { | @@ -120,7 +155,9 @@ func DepartmentEdit(param protocol.RequestDepartmentEdit) error { | ||
120 | var ( | 155 | var ( |
121 | newparent *models.Department | 156 | newparent *models.Department |
122 | ) | 157 | ) |
158 | + | ||
123 | if departUpdate.ParentId != param.ParentID { | 159 | if departUpdate.ParentId != param.ParentID { |
160 | + //检查上级部门是否合法 | ||
124 | newparent, err = models.GetDepartmentById(param.ParentID) | 161 | newparent, err = models.GetDepartmentById(param.ParentID) |
125 | if err != nil { | 162 | if err != nil { |
126 | e := fmt.Errorf("GetDepartmentById(%d) err:%s", param.ParentID, err) | 163 | e := fmt.Errorf("GetDepartmentById(%d) err:%s", param.ParentID, err) |
@@ -188,7 +225,7 @@ func departmentRelationUpdate(departUpdate *models.Department, newparent *models | @@ -188,7 +225,7 @@ func departmentRelationUpdate(departUpdate *models.Department, newparent *models | ||
188 | o.Rollback() | 225 | o.Rollback() |
189 | e := fmt.Errorf("departSubset[i].Id == newparent.Id") | 226 | e := fmt.Errorf("departSubset[i].Id == newparent.Id") |
190 | log.Error(e.Error()) | 227 | log.Error(e.Error()) |
191 | - return protocol.NewErrWithMessage("1", e) | 228 | + return protocol.NewErrWithMessage("10042") |
192 | } | 229 | } |
193 | //重建关系树 | 230 | //重建关系树 |
194 | s := strings.TrimPrefix(departSubset[i].Relation, oldRelation) | 231 | s := strings.TrimPrefix(departSubset[i].Relation, oldRelation) |
@@ -227,6 +264,10 @@ func DepartmentDelete(param protocol.RequestDepartmentDelete) error { | @@ -227,6 +264,10 @@ func DepartmentDelete(param protocol.RequestDepartmentDelete) error { | ||
227 | log.Error(e.Error()) | 264 | log.Error(e.Error()) |
228 | return protocol.NewErrWithMessage("1", e) | 265 | return protocol.NewErrWithMessage("1", e) |
229 | } | 266 | } |
267 | + //一级部门不能删除 | ||
268 | + if ok := p.IsTopDepartment(); ok { | ||
269 | + continue | ||
270 | + } | ||
230 | if p.CompanyId != param.CompanyID { | 271 | if p.CompanyId != param.CompanyID { |
231 | e := fmt.Errorf("CompanyID err") | 272 | e := fmt.Errorf("CompanyID err") |
232 | log.Error(e.Error()) | 273 | log.Error(e.Error()) |
@@ -286,7 +327,7 @@ func DepartmentListAll(companyId int64) ([]protocol.ResponseDepartmentInfo, erro | @@ -286,7 +327,7 @@ func DepartmentListAll(companyId int64) ([]protocol.ResponseDepartmentInfo, erro | ||
286 | err error | 327 | err error |
287 | ) | 328 | ) |
288 | const ( | 329 | const ( |
289 | - datasql0 string = `SELECT id, company_id,name,parent_id,managers,delete_at ` + | 330 | + datasql0 string = `SELECT id, company_id,name,parent_id,member,managers ` + |
290 | ` FROM department WHERE company_id = ? AND delete_at = 0` | 331 | ` FROM department WHERE company_id = ? AND delete_at = 0` |
291 | ) | 332 | ) |
292 | err = utils.ExecuteQueryAll(&departmodels, datasql0, companyId) | 333 | err = utils.ExecuteQueryAll(&departmodels, datasql0, companyId) |
-
请 注册 或 登录 后发表评论