正在显示
11 个修改的文件
包含
161 行增加
和
92 行删除
| @@ -29,7 +29,7 @@ | @@ -29,7 +29,7 @@ | ||
| 29 | |我审核的机会| | | v1/chance/chances| | 29 | |我审核的机会| | | v1/chance/chances| |
| 30 | |机会详情| | | v1/chance/detail| | 30 | |机会详情| | | v1/chance/detail| |
| 31 | |待抓住机会列表| | |v1/chance/chances| | 31 | |待抓住机会列表| | |v1/chance/chances| |
| 32 | -|提交机会| | |v1/chance/public| | 32 | +|提交机会| | |v1/chance/submit| |
| 33 | |部门列表-全部| | |v1/department/departments| | 33 | |部门列表-全部| | |v1/department/departments| |
| 34 | |部门列表-用户| | |v1/department/userDepartments| | 34 | |部门列表-用户| | |v1/department/userDepartments| |
| 35 | |配置-机会类型| | |v1/config/chanceType| | 35 | |配置-机会类型| | |v1/config/chanceType| |
controllers/v1/department.go
0 → 100644
| 1 | +package v1 | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "encoding/json" | ||
| 5 | + "opp/controllers" | ||
| 6 | + "opp/protocol" | ||
| 7 | + "opp/services/department" | ||
| 8 | + | ||
| 9 | + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" | ||
| 10 | +) | ||
| 11 | + | ||
| 12 | +type DepartmentController struct { | ||
| 13 | + controllers.BaseController | ||
| 14 | +} | ||
| 15 | + | ||
| 16 | +//Departments | ||
| 17 | +//@router /departments [post] | ||
| 18 | +func (this *DepartmentController) Departments() { | ||
| 19 | + var msg *protocol.ResponseMessage | ||
| 20 | + defer func() { | ||
| 21 | + this.Resp(msg) | ||
| 22 | + }() | ||
| 23 | + var request *protocol.DepartmentsRequest | ||
| 24 | + if err := json.Unmarshal(this.ByteBody, &request); err != nil { | ||
| 25 | + log.Error(err) | ||
| 26 | + msg = protocol.BadRequestParam(1) | ||
| 27 | + return | ||
| 28 | + } | ||
| 29 | + if b, m := this.Valid(request); !b { | ||
| 30 | + msg = m | ||
| 31 | + return | ||
| 32 | + } | ||
| 33 | + header := controllers.GetRequestHeader(this.Ctx) | ||
| 34 | + msg = protocol.NewReturnResponse(department.Departments(header, request)) | ||
| 35 | +} |
| @@ -4,6 +4,7 @@ import "opp/models" | @@ -4,6 +4,7 @@ import "opp/models" | ||
| 4 | 4 | ||
| 5 | type IDepartmentRepository interface { | 5 | type IDepartmentRepository interface { |
| 6 | GetDepartmentById(companyId int) (v *models.Department, err error) | 6 | GetDepartmentById(companyId int) (v *models.Department, err error) |
| 7 | + GetDepartmentByCompanyId(companyId int64) (v []*models.Department, err error) | ||
| 7 | } | 8 | } |
| 8 | 9 | ||
| 9 | var _ IDepartmentRepository = (*DepartmentRepository)(nil) | 10 | var _ IDepartmentRepository = (*DepartmentRepository)(nil) |
| @@ -14,6 +15,10 @@ func (r *DepartmentRepository) GetDepartmentById(id int) (v *models.Department, | @@ -14,6 +15,10 @@ func (r *DepartmentRepository) GetDepartmentById(id int) (v *models.Department, | ||
| 14 | return models.GetDepartmentById(id) | 15 | return models.GetDepartmentById(id) |
| 15 | } | 16 | } |
| 16 | 17 | ||
| 18 | +func (r *DepartmentRepository) GetDepartmentByCompanyId(companyId int64) (v []*models.Department, err error) { | ||
| 19 | + return models.GetDepartmentByCompanyId(companyId) | ||
| 20 | +} | ||
| 21 | + | ||
| 17 | type IUserDepartmentRepository interface { | 22 | type IUserDepartmentRepository interface { |
| 18 | GetUserDepartment(userId int64, companyId int64, v interface{}) (err error) | 23 | GetUserDepartment(userId int64, companyId int64, v interface{}) (err error) |
| 19 | } | 24 | } |
| 1 | package models | 1 | package models |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | - "errors" | ||
| 5 | "fmt" | 4 | "fmt" |
| 6 | - "reflect" | ||
| 7 | - "strings" | ||
| 8 | "time" | 5 | "time" |
| 9 | 6 | ||
| 10 | "github.com/astaxie/beego/orm" | 7 | "github.com/astaxie/beego/orm" |
| @@ -20,7 +17,7 @@ type Department struct { | @@ -20,7 +17,7 @@ type Department struct { | ||
| 20 | DeleteAt time.Time `orm:"column(delete_at);type(timestamp)" description:"删除时间"` | 17 | DeleteAt time.Time `orm:"column(delete_at);type(timestamp)" description:"删除时间"` |
| 21 | UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"` | 18 | UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"` |
| 22 | Member int `orm:"column(member)" description:"成员数量"` | 19 | Member int `orm:"column(member)" description:"成员数量"` |
| 23 | - Admin int `orm:"column(admin);null" description:"部门负责人id"` | 20 | + Managers string `orm:"column(managers);null" description:"部门负责人id列表 json 数组 [ ]"` |
| 24 | } | 21 | } |
| 25 | 22 | ||
| 26 | func (t *Department) TableName() string { | 23 | func (t *Department) TableName() string { |
| @@ -50,84 +47,6 @@ func GetDepartmentById(id int) (v *Department, err error) { | @@ -50,84 +47,6 @@ func GetDepartmentById(id int) (v *Department, err error) { | ||
| 50 | return nil, err | 47 | return nil, err |
| 51 | } | 48 | } |
| 52 | 49 | ||
| 53 | -// GetAllDepartment retrieves all Department matches certain condition. Returns empty list if | ||
| 54 | -// no records exist | ||
| 55 | -func GetAllDepartment(query map[string]string, fields []string, sortby []string, order []string, | ||
| 56 | - offset int64, limit int64) (ml []interface{}, err error) { | ||
| 57 | - o := orm.NewOrm() | ||
| 58 | - qs := o.QueryTable(new(Department)) | ||
| 59 | - // query k=v | ||
| 60 | - for k, v := range query { | ||
| 61 | - // rewrite dot-notation to Object__Attribute | ||
| 62 | - k = strings.Replace(k, ".", "__", -1) | ||
| 63 | - if strings.Contains(k, "isnull") { | ||
| 64 | - qs = qs.Filter(k, (v == "true" || v == "1")) | ||
| 65 | - } else { | ||
| 66 | - qs = qs.Filter(k, v) | ||
| 67 | - } | ||
| 68 | - } | ||
| 69 | - // order by: | ||
| 70 | - var sortFields []string | ||
| 71 | - if len(sortby) != 0 { | ||
| 72 | - if len(sortby) == len(order) { | ||
| 73 | - // 1) for each sort field, there is an associated order | ||
| 74 | - for i, v := range sortby { | ||
| 75 | - orderby := "" | ||
| 76 | - if order[i] == "desc" { | ||
| 77 | - orderby = "-" + v | ||
| 78 | - } else if order[i] == "asc" { | ||
| 79 | - orderby = v | ||
| 80 | - } else { | ||
| 81 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
| 82 | - } | ||
| 83 | - sortFields = append(sortFields, orderby) | ||
| 84 | - } | ||
| 85 | - qs = qs.OrderBy(sortFields...) | ||
| 86 | - } else if len(sortby) != len(order) && len(order) == 1 { | ||
| 87 | - // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
| 88 | - for _, v := range sortby { | ||
| 89 | - orderby := "" | ||
| 90 | - if order[0] == "desc" { | ||
| 91 | - orderby = "-" + v | ||
| 92 | - } else if order[0] == "asc" { | ||
| 93 | - orderby = v | ||
| 94 | - } else { | ||
| 95 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
| 96 | - } | ||
| 97 | - sortFields = append(sortFields, orderby) | ||
| 98 | - } | ||
| 99 | - } else if len(sortby) != len(order) && len(order) != 1 { | ||
| 100 | - return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
| 101 | - } | ||
| 102 | - } else { | ||
| 103 | - if len(order) != 0 { | ||
| 104 | - return nil, errors.New("Error: unused 'order' fields") | ||
| 105 | - } | ||
| 106 | - } | ||
| 107 | - | ||
| 108 | - var l []Department | ||
| 109 | - qs = qs.OrderBy(sortFields...) | ||
| 110 | - if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
| 111 | - if len(fields) == 0 { | ||
| 112 | - for _, v := range l { | ||
| 113 | - ml = append(ml, v) | ||
| 114 | - } | ||
| 115 | - } else { | ||
| 116 | - // trim unused fields | ||
| 117 | - for _, v := range l { | ||
| 118 | - m := make(map[string]interface{}) | ||
| 119 | - val := reflect.ValueOf(v) | ||
| 120 | - for _, fname := range fields { | ||
| 121 | - m[fname] = val.FieldByName(fname).Interface() | ||
| 122 | - } | ||
| 123 | - ml = append(ml, m) | ||
| 124 | - } | ||
| 125 | - } | ||
| 126 | - return ml, nil | ||
| 127 | - } | ||
| 128 | - return nil, err | ||
| 129 | -} | ||
| 130 | - | ||
| 131 | // UpdateDepartment updates Department by Id and returns error if | 50 | // UpdateDepartment updates Department by Id and returns error if |
| 132 | // the record to be updated doesn't exist | 51 | // the record to be updated doesn't exist |
| 133 | func UpdateDepartmentById(m *Department) (err error) { | 52 | func UpdateDepartmentById(m *Department) (err error) { |
| @@ -157,3 +76,16 @@ func DeleteDepartment(id int) (err error) { | @@ -157,3 +76,16 @@ func DeleteDepartment(id int) (err error) { | ||
| 157 | } | 76 | } |
| 158 | return | 77 | return |
| 159 | } | 78 | } |
| 79 | + | ||
| 80 | +func GetDepartmentByCompanyId(companyId int64) (v []*Department, err error) { | ||
| 81 | + o := orm.NewOrm() | ||
| 82 | + sql := ` | ||
| 83 | +select * | ||
| 84 | +from department | ||
| 85 | +where company_id =? and delete_at =0 | ||
| 86 | +order by parent_id,id` | ||
| 87 | + if _, err = o.Raw(sql, companyId).QueryRows(&v); err == nil { | ||
| 88 | + return | ||
| 89 | + } | ||
| 90 | + return | ||
| 91 | +} |
| @@ -13,11 +13,6 @@ type UserBaseInfoAggregation struct { | @@ -13,11 +13,6 @@ type UserBaseInfoAggregation struct { | ||
| 13 | UserCompany *models.UserCompany | 13 | UserCompany *models.UserCompany |
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | -type Department struct { | ||
| 17 | - DepartmentId int `orm:"column(department_id)` | ||
| 18 | - Name string `orm:"column(name)` | ||
| 19 | -} | ||
| 20 | - | ||
| 21 | type Position struct { | 16 | type Position struct { |
| 22 | PositionId int `orm:"column(position_id)` | 17 | PositionId int `orm:"column(position_id)` |
| 23 | Name string `orm:"column(name)` | 18 | Name string `orm:"column(name)` |
protocol/department.go
0 → 100644
| 1 | +package protocol | ||
| 2 | + | ||
| 3 | +const ( | ||
| 4 | + DepartmentAll = iota + 1 //公司所有部门 | ||
| 5 | + DepartmentUser //用户所有部门 | ||
| 6 | +) | ||
| 7 | + | ||
| 8 | +/*Departments */ | ||
| 9 | +type DepartmentsRequest struct { | ||
| 10 | + Type int `json:"type" valid:"Required"` //1:公司所有部门 2:用户所在部门 | ||
| 11 | +} | ||
| 12 | +type DepartmentsResponse struct { | ||
| 13 | + Departments []*Department `json:"departments,omitempty"` | ||
| 14 | +} | ||
| 15 | + | ||
| 16 | +type Department struct { | ||
| 17 | + DepartmentId int `orm:"column(department_id) json:"id"` | ||
| 18 | + Name string `orm:"column(name) json:"name"` | ||
| 19 | + PId int `orm:"column(pid) json:"-"` | ||
| 20 | + Departments []*Department `json:"departments,omitempty"` | ||
| 21 | +} |
| @@ -15,8 +15,9 @@ var errmessge ErrorMap = map[int]string{ | @@ -15,8 +15,9 @@ var errmessge ErrorMap = map[int]string{ | ||
| 15 | 2021: "登录失败,手机号或密码错误", | 15 | 2021: "登录失败,手机号或密码错误", |
| 16 | 2025: "短信验证码验证失败", | 16 | 2025: "短信验证码验证失败", |
| 17 | 2026: "新密码与确认密码不一致", | 17 | 2026: "新密码与确认密码不一致", |
| 18 | - 2027:"密码必须至少有6个字符", | ||
| 19 | - 2028:"请输入正确的旧密码", | 18 | + 2027: "密码必须至少有6个字符", |
| 19 | + 2028: "请输入正确的旧密码", | ||
| 20 | + 2029: "当前手机号已存在,请重新输入", | ||
| 20 | 4139: "authCode无效或过期", | 21 | 4139: "authCode无效或过期", |
| 21 | 4140: "refreshToken过期,需要重新登录授权", | 22 | 4140: "refreshToken过期,需要重新登录授权", |
| 22 | 4141: "accessToken过期或无效,需要进行重新获取令牌", | 23 | 4141: "accessToken过期或无效,需要进行重新获取令牌", |
| @@ -119,6 +119,14 @@ func init() { | @@ -119,6 +119,14 @@ func init() { | ||
| 119 | MethodParams: param.Make(), | 119 | MethodParams: param.Make(), |
| 120 | Params: nil}) | 120 | Params: nil}) |
| 121 | 121 | ||
| 122 | + beego.GlobalControllerRouter["opp/controllers/v1:DepartmentController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:DepartmentController"], | ||
| 123 | + beego.ControllerComments{ | ||
| 124 | + Method: "Departments", | ||
| 125 | + Router: `/departments`, | ||
| 126 | + AllowHTTPMethods: []string{"post"}, | ||
| 127 | + MethodParams: param.Make(), | ||
| 128 | + Params: nil}) | ||
| 129 | + | ||
| 122 | beego.GlobalControllerRouter["opp/controllers/v1:MessageController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:MessageController"], | 130 | beego.GlobalControllerRouter["opp/controllers/v1:MessageController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:MessageController"], |
| 123 | beego.ControllerComments{ | 131 | beego.ControllerComments{ |
| 124 | Method: "MessageCenter", | 132 | Method: "MessageCenter", |
| @@ -19,6 +19,7 @@ func init() { | @@ -19,6 +19,7 @@ func init() { | ||
| 19 | beego.NSNamespace("user", beego.NSInclude(&v1.UserController{})), | 19 | beego.NSNamespace("user", beego.NSInclude(&v1.UserController{})), |
| 20 | beego.NSNamespace("chance", beego.NSInclude(&v1.ChanceController{})), | 20 | beego.NSNamespace("chance", beego.NSInclude(&v1.ChanceController{})), |
| 21 | beego.NSNamespace("message", beego.NSInclude(&v1.MessageController{})), | 21 | beego.NSNamespace("message", beego.NSInclude(&v1.MessageController{})), |
| 22 | + beego.NSNamespace("department", beego.NSInclude(&v1.DepartmentController{})), | ||
| 22 | ) | 23 | ) |
| 23 | beego.AddNamespace(nsV1) | 24 | beego.AddNamespace(nsV1) |
| 24 | beego.SetStaticPath("/file/opp", beego.AppConfig.String("source_path")) | 25 | beego.SetStaticPath("/file/opp", beego.AppConfig.String("source_path")) |
services/department/department.go
0 → 100644
| 1 | +package department | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" | ||
| 5 | + "opp/internal/repository" | ||
| 6 | + "opp/models" | ||
| 7 | + "opp/protocol" | ||
| 8 | +) | ||
| 9 | + | ||
| 10 | +func Departments(header *protocol.RequestHeader, request *protocol.DepartmentsRequest) (rsp *protocol.DepartmentsResponse, err error) { | ||
| 11 | + var ( | ||
| 12 | + departments []*models.Department | ||
| 13 | + ) | ||
| 14 | + rsp = &protocol.DepartmentsResponse{} | ||
| 15 | + switch request.Type { | ||
| 16 | + case protocol.DepartmentAll: | ||
| 17 | + if departments, err = repository.Department.GetDepartmentByCompanyId(header.CompanyId); err != nil { | ||
| 18 | + log.Error(err) | ||
| 19 | + return | ||
| 20 | + } | ||
| 21 | + //rsp.Departments = | ||
| 22 | + for i := range departments { | ||
| 23 | + var newD *protocol.Department = &protocol.Department{ | ||
| 24 | + DepartmentId: departments[i].Id, | ||
| 25 | + Name: departments[i].Name, | ||
| 26 | + } | ||
| 27 | + if departments[i].ParentId == 0 { | ||
| 28 | + rsp.Departments = append(rsp.Departments, newD) | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + } | ||
| 32 | + case protocol.DepartmentUser: | ||
| 33 | + if err = repository.UserDepartment.GetUserDepartment(header.Uid, header.CompanyId, &rsp.Departments); err != nil { | ||
| 34 | + log.Error(err) | ||
| 35 | + return | ||
| 36 | + } | ||
| 37 | + default: | ||
| 38 | + break | ||
| 39 | + } | ||
| 40 | + return | ||
| 41 | +} | ||
| 42 | + | ||
| 43 | +// | ||
| 44 | +//func setDepartment(departments *[]models.Department)[]*protocol.Department{ | ||
| 45 | +// var departments []*protocol.Department | ||
| 46 | +// for i :=range dfrom{ | ||
| 47 | +// | ||
| 48 | +// var newD *protocol.Department = &protocol.Department{ | ||
| 49 | +// DepartmentId:dfrom[i].Id, | ||
| 50 | +// Name:dfrom[i].Name, | ||
| 51 | +// } | ||
| 52 | +// | ||
| 53 | +// } | ||
| 54 | +// | ||
| 55 | +// if dfrom.ParentId ==0{ | ||
| 56 | +// | ||
| 57 | +// } | ||
| 58 | +// if len(department)>0{ | ||
| 59 | +// for i:=range department{ | ||
| 60 | +// if department[i].DepartmentId == dfrom.ParentId{ | ||
| 61 | +// department[i].Departments = append(department[i].Departments,newD) | ||
| 62 | +// return nil | ||
| 63 | +// } | ||
| 64 | +// return setDepartment(department[i].Departments,dfrom) | ||
| 65 | +// } | ||
| 66 | +// } | ||
| 67 | +// return nil | ||
| 68 | +//} |
| @@ -47,6 +47,9 @@ func ChangePhone(header *protocol.RequestHeader, request *protocol.ChangePhoneRe | @@ -47,6 +47,9 @@ func ChangePhone(header *protocol.RequestHeader, request *protocol.ChangePhoneRe | ||
| 47 | log.Error(err) | 47 | log.Error(err) |
| 48 | return | 48 | return |
| 49 | } | 49 | } |
| 50 | + if _, err = repository.User.GetUsersByMobile(request.Phone); err == nil { | ||
| 51 | + err = protocol.NewErrWithMessage(2029) | ||
| 52 | + } | ||
| 50 | if !result { | 53 | if !result { |
| 51 | err = protocol.NewErrWithMessage(1012) | 54 | err = protocol.NewErrWithMessage(1012) |
| 52 | } | 55 | } |
| @@ -68,7 +71,7 @@ func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswo | @@ -68,7 +71,7 @@ func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswo | ||
| 68 | if !strings.EqualFold(request.NewPwd, request.ConfirmPwd) { | 71 | if !strings.EqualFold(request.NewPwd, request.ConfirmPwd) { |
| 69 | err = protocol.NewErrWithMessage(2026) | 72 | err = protocol.NewErrWithMessage(2026) |
| 70 | } | 73 | } |
| 71 | - if len(request.NewPwd)<6 { | 74 | + if len(request.NewPwd) < 6 { |
| 72 | err = protocol.NewErrWithMessage(2027) | 75 | err = protocol.NewErrWithMessage(2027) |
| 73 | } | 76 | } |
| 74 | err = utils.UpdateTableByMap(&models.User{Id: user.Id}, map[string]interface{}{"Passwd": request.NewPwd}) | 77 | err = utils.UpdateTableByMap(&models.User{Id: user.Id}, map[string]interface{}{"Passwd": request.NewPwd}) |
| @@ -84,7 +87,7 @@ func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePass | @@ -84,7 +87,7 @@ func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePass | ||
| 84 | if !strings.EqualFold(request.NewPwd, request.ConfirmPwd) { | 87 | if !strings.EqualFold(request.NewPwd, request.ConfirmPwd) { |
| 85 | err = protocol.NewErrWithMessage(2026) | 88 | err = protocol.NewErrWithMessage(2026) |
| 86 | } | 89 | } |
| 87 | - if len(request.NewPwd)<6 { | 90 | + if len(request.NewPwd) < 6 { |
| 88 | err = protocol.NewErrWithMessage(2027) | 91 | err = protocol.NewErrWithMessage(2027) |
| 89 | } | 92 | } |
| 90 | if user, err = repository.User.GetUsersById(header.Uid); err != nil { | 93 | if user, err = repository.User.GetUsersById(header.Uid); err != nil { |
-
请 注册 或 登录 后发表评论