作者 唐旭辉

角管理相关

### 接口完成进度
| 功能 | 完成状态 | 时间 | 接口路径 | 请求方式 |
| -------------- | ------------------ | -------------- | -------------------------- | -------- |
| 登录 | 进行中 | | |
| 短信验证码 | 未开始 | | |
| 获取 token | 未开始 | | |
| 刷新 token | 未开始 | | |
| 添加角色 | 完成 | 2019.11.26 | /v1/rbac/role | post |
| 编辑角色 | 完成 | 2019.11.26 | /v1/rbac/role | put |
| 删除角色 | 完成 | 2019.11.26 | /v1/rbac/role | delete |
| 添加部门 | 完成 | 2019.11.28 | /v1/company/department | post |
| 编辑部门 | 完成 | 2019.11.29 | /v1/company/department | put |
| ~~删除部门~~ | ~~完成(待变更)~~ | ~~2019.11.29~~ | ~~/v1/company/department~~ | delete |
| 删除部门 | 完成 | 2019.12.2 | /v1/company/department | delete |
| 添加职位 | 完成 | 2019.12.2 | /v1/company/position | post |
| 编辑职位 | 完成 | 2019.12.2 | /v1/company/position | put |
| 删除职位 | 完成 | 2019.12.2 | /v1/company/position | delete |
| 添加员工 | 未开始 | | /v1/company/user | post |
| 编辑员工 | 未开始 | | /v1/company/user | put |
| 删除员工 | 未开始 | | /v1/company/user | delete |
| 公告管理 | 未开始 | | | |
| 公告管理 | 未开始 | | | |
| 公告管理 | 未开始 | | | |
| 机会&审批 模板 | 未开始 | | | |
| 机会&审批 模板 | 未开始 | | | |
| 机会&审批 模板 | 未开始 | | | |
| 机会&审批 模板 | 未开始 | | | |
| 功能 | 完成状态 | 时间 | 接口路径 | 请求方式 |
| -------------- | ------------------ | --------------- | -------------------------- | -------- |
| 登录 | 进行中 | | |
| 短信验证码 | 未开始 | | |
| 获取 token | 未开始 | | |
| 刷新 token | 未开始 | | |
| 添加角色 | 完成 | 2019.11.26 | /v1/rbac/role | post |
| 编辑角色 | 完成 | 2019.11.26 | /v1/rbac/role | put |
| ~~删除角色~~ | ~~完成(待变更)~~ | ~~ 2019.11.26~~ | /v1/rbac/role | delete |
| 删除角色 | 完成 | 2019.12.04 | /v1/rbac/role | delete |
| 添加角色组 | 完成 | 2019.12.04 | /v1/rbac/role_group | post |
| 编辑角色组 | 完成 | 2019.12.04 | /v1/rbac/role_group | put |
| 删除角色组 | 完成 | 2019.12.04 | /v1/rbac/role_group | delete |
| 添加部门 | 完成 | 2019.11.28 | /v1/company/department | post |
| 编辑部门 | 完成 | 2019.11.29 | /v1/company/department | put |
| ~~删除部门~~ | ~~完成(待变更)~~ | ~~2019.11.29~~ | ~~/v1/company/department~~ | delete |
| 删除部门 | 完成 | 2019.12.2 | /v1/company/department | delete |
| 添加职位 | 完成 | 2019.12.2 | /v1/company/position | post |
| 编辑职位 | 完成 | 2019.12.2 | /v1/company/position | put |
| 删除职位 | 完成 | 2019.12.2 | /v1/company/position | delete |
| 添加员工 | 未开始 | | /v1/company/user | post |
| 编辑员工 | 未开始 | | /v1/company/user | put |
| 删除员工 | 未开始 | | /v1/company/user | delete |
| 公告管理 | 未开始 | | | |
| 公告管理 | 未开始 | | | |
| 公告管理 | 未开始 | | | |
| 机会&审批 模板 | 未开始 | | | |
| 机会&审批 模板 | 未开始 | | | |
| 机会&审批 模板 | 未开始 | | | |
| 机会&审批 模板 | 未开始 | | | |
... ...
... ... @@ -3,6 +3,7 @@ package controllers
import (
"encoding/json"
"oppmg/common/log"
"oppmg/models"
"oppmg/protocol"
serverbac "oppmg/services/rbac"
)
... ... @@ -17,7 +18,7 @@ func (c *RbacController) URLMapping() {
}
// RoleAdd 添加部门
// @router /department [post]
// @router /role [post]
func (c *RbacController) RoleAdd() {
var msg *protocol.ResponseMessage
defer func() {
... ... @@ -40,7 +41,7 @@ func (c *RbacController) RoleAdd() {
}
// RoleUpdate 编辑部门
// @router /department [put]
// @router /role [put]
func (c *RbacController) RoleUpdate() {
var msg *protocol.ResponseMessage
defer func() {
... ... @@ -64,7 +65,7 @@ func (c *RbacController) RoleUpdate() {
}
// RoleDelete 删除角色
// @router /department [delete]
// @router /role[delete]
func (c *RbacController) RoleDelete() {
var msg *protocol.ResponseMessage
defer func() {
... ... @@ -86,3 +87,78 @@ func (c *RbacController) RoleDelete() {
msg = protocol.NewReturnResponse(nil, err)
return
}
// RoleGroupAdd 角色组
// @router /role_group [post]
func (c *RbacController) RoleGroupAdd() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
var param protocol.RequestRoleAdd
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
log.Error("json 解析失败 err:%s", err)
msg = protocol.BadRequestParam("1")
return
}
if param.CompanyID <= 0 {
log.Error("param.CompanyID <= 0")
msg = protocol.BadRequestParam("1")
return
}
param.Pid = 0
param.Types = models.ROLETYPES_GROUP
roleinfo, err := serverbac.RoleAdd(param)
msg = protocol.NewReturnResponse(roleinfo, err)
return
}
// RoleGroupEdit 角色组
// @router /role_group [put]
func (c *RbacController) RoleGroupUpdate() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
var param protocol.RequestRoleEdit
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
log.Error("json 解析失败 err:%s", err)
msg = protocol.BadRequestParam("1")
return
}
if param.CompanyID <= 0 {
log.Error("param.CompanyID <= 0")
msg = protocol.BadRequestParam("1")
return
}
param.Pid = 0
param.Types = models.ROLETYPES_GROUP
roleinfo, err := serverbac.RoleEdit(param)
msg = protocol.NewReturnResponse(roleinfo, err)
return
}
// RoleGroupEdit 角色组
// @router /role_group [delete]
func (c *RbacController) RoleGroupDelete() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
var param protocol.RequestRoleDelete
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
log.Error("json 解析失败 err:%s", err)
msg = protocol.BadRequestParam("1")
return
}
if param.CompanyID <= 0 {
log.Error("param.CompanyID <= 0")
msg = protocol.BadRequestParam("1")
return
}
err := serverbac.RoleGroupDelete(param)
msg = protocol.NewReturnResponse(nil, err)
return
}
// RoleGroupDelete
... ...
... ... @@ -9,11 +9,11 @@ import (
)
type Role struct {
Id int `orm:"column(id);auto"`
Id int64 `orm:"column(id);auto"`
Name string `orm:"column(name);size(30)"`
Pid int `orm:"column(pid)"`
Pid int64 `orm:"column(pid)"`
Types int8 `orm:"column(types)"`
CompanyId int `orm:"column(company_id)"`
CompanyId int64 `orm:"column(company_id)"`
Descript string `orm:"column(descript)"`
CreateAt time.Time `orm:"column(create_at);type(timestamp)"`
DeleteAt time.Time `orm:"column(delete_at);type(timestamp)"`
... ... @@ -58,6 +58,9 @@ func (t *Role) ValidatePid() (*Role, error) {
if err != nil {
return nil, err
}
if roledata.DeleteAt.Unix() != 0 {
return nil, errors.New("roledata.DeleteAt !=0")
}
if roledata.Types != ROLETYPES_GROUP {
return nil, errors.New("roledata.Types != ROLETYPES_GROUP")
}
... ... @@ -78,7 +81,7 @@ func AddRole(m *Role) (id int64, err error) {
// GetRoleById retrieves Role by Id. Returns error if
// Id doesn't exist
func GetRoleById(id int) (v *Role, err error) {
func GetRoleById(id int64) (v *Role, err error) {
o := orm.NewOrm()
v = &Role{Id: id}
if err = o.Read(v); err == nil {
... ... @@ -104,7 +107,7 @@ func UpdateRoleById(m *Role, col []string) (err error) {
// DeleteRole deletes Role by Id and returns error if
// the record to be deleted doesn't exist
func DeleteRoleByID(id int) (err error) {
func DeleteRoleByID(id int64) (err error) {
o := orm.NewOrm()
v := Role{Id: id}
// ascertain id exists in the database
... ... @@ -118,7 +121,7 @@ func DeleteRoleByID(id int) (err error) {
return
}
func DeleteRoleByPid(pid int) (err error) {
func DeleteRoleByPid(pid int64) (err error) {
o := orm.NewOrm()
var num int64
deleteAt := time.Now()
... ... @@ -128,3 +131,15 @@ func DeleteRoleByPid(pid int) (err error) {
log.Debug("Number of records updated in database:%d", num)
return
}
func CountRoleByPid(pid int64) (int64, error) {
o := orm.NewOrm()
var (
cnt int64
err error
)
cnt, err = o.QueryTable(&Role{}).
Filter("delete_at", 0).
Filter("pid", pid).Count()
return cnt, err
}
... ...
package models
import (
"fmt"
"github.com/astaxie/beego/orm"
)
type RoleRelated struct {
Id int `orm:"column(id);pk"`
RoleId int64 `orm:"column(role_id)"`
UserId int64 `orm:"column(user_id)"`
}
func (t *RoleRelated) TableName() string {
return "role_related"
}
func init() {
orm.RegisterModel(new(RoleRelated))
}
// AddRoleRelated insert a new RoleRelated into database and returns
// last inserted Id on success.
func AddRoleRelated(m *RoleRelated) (id int64, err error) {
o := orm.NewOrm()
id, err = o.Insert(m)
return
}
// GetRoleRelatedById retrieves RoleRelated by Id. Returns error if
// Id doesn't exist
func GetRoleRelatedById(id int) (v *RoleRelated, err error) {
o := orm.NewOrm()
v = &RoleRelated{Id: id}
if err = o.Read(v); err == nil {
return v, nil
}
return nil, err
}
// UpdateRoleRelated updates RoleRelated by Id and returns error if
// the record to be updated doesn't exist
func UpdateRoleRelatedById(m *RoleRelated) (err error) {
o := orm.NewOrm()
v := RoleRelated{Id: m.Id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Update(m); err == nil {
fmt.Println("Number of records updated in database:", num)
}
}
return
}
// DeleteRoleRelated deletes RoleRelated by Id and returns error if
// the record to be deleted doesn't exist
func DeleteRoleRelated(id int) (err error) {
o := orm.NewOrm()
v := RoleRelated{Id: id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Delete(&RoleRelated{Id: id}); err == nil {
fmt.Println("Number of records deleted in database:", num)
}
}
return
}
func CountRoleRelatedByUser(roleid int64) (int64, error) {
var (
cnt int64
err error
)
o := orm.NewOrm()
cnt, err = o.QueryTable(&RoleRelated{}).
Filter("role_id", roleid).
Count()
return cnt, err
}
... ...
package models
import (
"errors"
"fmt"
"reflect"
"strings"
"time"
"github.com/astaxie/beego/orm"
... ... @@ -34,8 +31,14 @@ func init() {
// AddUser insert a new User into database and returns
// last inserted Id on success.
func AddUser(m *User) (id int64, err error) {
o := orm.NewOrm()
func AddUser(m *User, om ...orm.Ormer) (id int64, err error) {
var o orm.Ormer
if len(om) > 0 {
o = om[0]
} else {
o = orm.NewOrm()
}
id, err = o.Insert(m)
return
}
... ... @@ -51,84 +54,6 @@ func GetUserById(id int64) (v *User, err error) {
return nil, err
}
// GetAllUser retrieves all User matches certain condition. Returns empty list if
// no records exist
func GetAllUser(query map[string]string, fields []string, sortby []string, order []string,
offset int64, limit int64) (ml []interface{}, err error) {
o := orm.NewOrm()
qs := o.QueryTable(new(User))
// query k=v
for k, v := range query {
// rewrite dot-notation to Object__Attribute
k = strings.Replace(k, ".", "__", -1)
if strings.Contains(k, "isnull") {
qs = qs.Filter(k, (v == "true" || v == "1"))
} else {
qs = qs.Filter(k, v)
}
}
// order by:
var sortFields []string
if len(sortby) != 0 {
if len(sortby) == len(order) {
// 1) for each sort field, there is an associated order
for i, v := range sortby {
orderby := ""
if order[i] == "desc" {
orderby = "-" + v
} else if order[i] == "asc" {
orderby = v
} else {
return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
}
sortFields = append(sortFields, orderby)
}
qs = qs.OrderBy(sortFields...)
} else if len(sortby) != len(order) && len(order) == 1 {
// 2) there is exactly one order, all the sorted fields will be sorted by this order
for _, v := range sortby {
orderby := ""
if order[0] == "desc" {
orderby = "-" + v
} else if order[0] == "asc" {
orderby = v
} else {
return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
}
sortFields = append(sortFields, orderby)
}
} else if len(sortby) != len(order) && len(order) != 1 {
return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
}
} else {
if len(order) != 0 {
return nil, errors.New("Error: unused 'order' fields")
}
}
var l []User
qs = qs.OrderBy(sortFields...)
if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
if len(fields) == 0 {
for _, v := range l {
ml = append(ml, v)
}
} else {
// trim unused fields
for _, v := range l {
m := make(map[string]interface{})
val := reflect.ValueOf(v)
for _, fname := range fields {
m[fname] = val.FieldByName(fname).Interface()
}
ml = append(ml, m)
}
}
return ml, nil
}
return nil, err
}
// UpdateUser updates User by Id and returns error if
// the record to be updated doesn't exist
func UpdateUserById(m *User) (err error) {
... ...
package models
import (
"fmt"
"time"
"github.com/astaxie/beego/orm"
)
type UserDepartment struct {
Id int `orm:"column(id);auto" description:"主键"`
UserId int64 `orm:"column(user_id)" description:"用户id"`
CompanyId int `orm:"column(company_id)" description:"公司id"`
DepartmentId int `orm:"column(department_id)" description:"部门id"`
CreateTime time.Time `orm:"column(create_time);type(timestamp);null" description:"创建时间"`
EnableStatus int8 `orm:"column(enable_status)" description:"是否有效"`
}
func (t *UserDepartment) TableName() string {
return "user_department"
}
func init() {
orm.RegisterModel(new(UserDepartment))
}
// AddUserDepartment insert a new UserDepartment into database and returns
// last inserted Id on success.
func AddUserDepartment(m *UserDepartment) (id int64, err error) {
o := orm.NewOrm()
id, err = o.Insert(m)
return
}
// GetUserDepartmentById retrieves UserDepartment by Id. Returns error if
// Id doesn't exist
func GetUserDepartmentById(id int) (v *UserDepartment, err error) {
o := orm.NewOrm()
v = &UserDepartment{Id: id}
if err = o.Read(v); err == nil {
return v, nil
}
return nil, err
}
// UpdateUserDepartment updates UserDepartment by Id and returns error if
// the record to be updated doesn't exist
func UpdateUserDepartmentById(m *UserDepartment) (err error) {
o := orm.NewOrm()
v := UserDepartment{Id: m.Id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Update(m); err == nil {
fmt.Println("Number of records updated in database:", num)
}
}
return
}
// DeleteUserDepartment deletes UserDepartment by Id and returns error if
// the record to be deleted doesn't exist
func DeleteUserDepartment(id int) (err error) {
o := orm.NewOrm()
v := UserDepartment{Id: id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Delete(&UserDepartment{Id: id}); err == nil {
fmt.Println("Number of records deleted in database:", num)
}
}
return
}
... ...
package models
import (
"fmt"
"time"
"github.com/astaxie/beego/orm"
)
type UserPosition struct {
Id int `orm:"column(id);pk" description:"唯一键值"`
UserId int64 `orm:"column(user_id)" description:"表user.id 用户编号"`
PositionId int `orm:"column(position_id)" description:"表position.id 职位编号"`
CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"`
CompanyId int `orm:"column(company_id)" description:"表company.id 公司编号"`
EnableStatus int8 `orm:"column(enable_status);null" description:"是否有效 1:有效 0:无效"`
}
func (t *UserPosition) TableName() string {
return "user_position"
}
func init() {
orm.RegisterModel(new(UserPosition))
}
// AddUserPosition insert a new UserPosition into database and returns
// last inserted Id on success.
func AddUserPosition(m *UserPosition) (id int64, err error) {
o := orm.NewOrm()
id, err = o.Insert(m)
return
}
// GetUserPositionById retrieves UserPosition by Id. Returns error if
// Id doesn't exist
func GetUserPositionById(id int) (v *UserPosition, err error) {
o := orm.NewOrm()
v = &UserPosition{Id: id}
if err = o.Read(v); err == nil {
return v, nil
}
return nil, err
}
// UpdateUserPosition updates UserPosition by Id and returns error if
// the record to be updated doesn't exist
func UpdateUserPositionById(m *UserPosition) (err error) {
o := orm.NewOrm()
v := UserPosition{Id: m.Id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Update(m); err == nil {
fmt.Println("Number of records updated in database:", num)
}
}
return
}
// DeleteUserPosition deletes UserPosition by Id and returns error if
// the record to be deleted doesn't exist
func DeleteUserPosition(id int) (err error) {
o := orm.NewOrm()
v := UserPosition{Id: id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Delete(&UserPosition{Id: id}); err == nil {
fmt.Println("Number of records deleted in database:", num)
}
}
return
}
... ...
... ... @@ -70,19 +70,21 @@ type RequestPositionDelete struct {
}
type RequestUserAdd struct {
Name string `json:"name"`
CompanyId int64 `json:"company_id"`
Phone string `json:"phone`
Departments []int `json:"departments"`
Positions []int `json:"positions"`
Roles []int `json:"roles"`
Name string `json:"name"`
CompanyId int64 `json:"company_id"`
Phone string `json:"phone`
Departments []int64 `json:"departments"`
Positions []int64 `json:"positions"`
Roles []int64 `json:"roles"`
}
type RequestUserEdit struct {
Name string `json:"name"`
CompanyId int64 `json:"company_id"`
Phone string `json:"phone`
Departments []int `json:"departments"`
Positions []int `json:"positions"`
Roles []int `json:"roles"`
ID int64 `json:"id"`
RequestUserAdd
// Name string `json:"name"`
// CompanyId int64 `json:"company_id"`
// Phone string `json:"phone`
// Departments []int `json:"departments"`
// Positions []int `json:"positions"`
// Roles []int `json:"roles"`
}
... ...
... ... @@ -5,4 +5,7 @@ var errmessge ErrorMap = map[string]string{
"1": "系统异常",
"101": "clientId或clientSecret无效",
"113": "签名验证失败",
//角色相关
"30001": "请先删除该分组下的其他角色",
"30002": "请先删除该角色下的人员",
}
... ...
package protocol
//RequestRoleAdd 添加角色信息操作入参
//RequestRoleAdd 添加角色信息
type RequestRoleAdd struct {
CompanyID int `json:"company"`
Pid int `json:"pid"`
CompanyID int64 `json:"company"`
Pid int64 `json:"pid"`
Name string `json:"name"`
Types int8 `json:"types"`
Descript string `json:"descript"`
... ... @@ -11,13 +11,13 @@ type RequestRoleAdd struct {
//RequestRoleDelete 删除一个角色数据
type RequestRoleDelete struct {
CompanyID int `json:"company_id"`
RoleID int `json:"role_id"`
CompanyID int64 `json:"company_id"`
RoleID int64 `json:"role_id"`
}
//RequestRoleEdit 编辑角色信息入参
type RequestRoleEdit struct {
ID int `json:"id"`
ID int64 `json:"id"`
RequestRoleAdd
}
... ... @@ -29,8 +29,8 @@ type RequestRoleOne struct {
//ResponseRoleInfo 响应数据
type ResponseRoleInfo struct {
ID int `json:"id"`
Pid int `json:"pid"`
ID int64 `json:"id"`
Pid int64 `json:"pid"`
ParentName string `json:"parent_name"`
Name string `json:"name"`
Descript string `json:"descript"`
... ...
... ... @@ -22,6 +22,9 @@ func init() {
beego.NSRouter("/role", &controllers.RbacController{}, "post:RoleAdd"),
beego.NSRouter("/role", &controllers.RbacController{}, "put:RoleUpdate"),
beego.NSRouter("/role", &controllers.RbacController{}, "delete:RoleDelete"),
beego.NSRouter("/role_group", &controllers.RbacController{}, "post:RoleGroupAdd"),
beego.NSRouter("/role_group", &controllers.RbacController{}, "put:RoleGroupUpdate"),
beego.NSRouter("/role_group", &controllers.RbacController{}, "delete:RoleGroupDelete"),
),
)
... ...
package auth
import (
"crypto/sha1"
"encoding/hex"
"fmt"
"io"
"oppmg/common/config"
"oppmg/common/log"
"oppmg/models"
"oppmg/protocol"
"oppmg/utils"
"strings"
"time"
"github.com/astaxie/beego/orm"
)
//GetAccessToken 获取accessToken
func GetAccessToken(param protocol.RequestCheckSmsCode) (*protocol.DataUserInfo, error) {
data := &protocol.DataUserInfo{}
err := protocol.NewErrWithMessage("00000")
log.Info("log 打印")
log.Info("%+v", config.MConfig)
return data, err
}
//ValidatePassword ...
//from:待校验的密码;to:比对用的密文
func validatePassword(from, to string) bool {
//密码加密方式sha1
h := sha1.New()
io.WriteString(h, from)
str := hex.EncodeToString(h.Sum(nil))
if strings.Compare(str, to) == 0 {
return true
}
return false
}
//LoginAuth 登录认证
func LoginAuthByPassword(account, password string) error {
var (
user *models.User
uAuth *models.UserAuth
err error
)
user, err = models.GetUserByPhone(account)
if err != nil {
log.Error(err.Error())
return protocol.NewErrWithMessage("1", err)
}
if ok := validatePassword(password, user.Passwd); !ok {
return protocol.NewErrWithMessage("1", err)
}
uAuth, err = models.ReadUserAuthByDevice(user.Id, models.DEVICE_TYPE_WEB)
if err != nil && err != orm.ErrNoRows {
e := fmt.Errorf("ReadUserAuthByDevice(%d,%d) err:%s", user.Id, models.DEVICE_TYPE_WEB, err)
log.Error(e.Error())
return protocol.NewErrWithMessage("1", e)
}
var (
authcode string
authcodeExp time.Time
)
authcode = utils.GenerateIDByUUID()
authcodeExp = time.Now().Add(time.Duration(models.AUTHCODE_TIME) * time.Second)
if err == orm.ErrNoRows {
uAuth := &models.UserAuth{
UserId: user.Id,
AuthCode: authcode,
AuthCodeExp: authcodeExp,
CreateAt: time.Now(),
}
_, err = models.AddUserAuth(uAuth)
if err != nil {
e := fmt.Errorf("AddUserAuth err:%s", err)
log.Error(e.Error())
return protocol.NewErrWithMessage("1", e)
}
}
if err == nil {
uAuth.AuthCode = authcode
uAuth.AuthCodeExp = authcodeExp
uAuth.UpdateAt = time.Now()
err = models.UpdateUserAuthById(uAuth)
if err != nil {
e := fmt.Errorf("UpdateUserAuthById err:%s", err)
log.Error(e.Error())
return protocol.NewErrWithMessage("1", e)
}
}
return nil
}
//RefreshAccessToken 刷新token
func RefreshAccessToken(account string, token string) error {
return nil
}
// func buildNewUserAuth(uid int64,) *models.UserAuth {
// m:=&models.UserAuth{
// User
// }
// return nil
// }
... ...
... ... @@ -304,7 +304,7 @@ func DepartmentDelete(param protocol.RequestDepartmentDelete) error {
log.Error(e.Error())
return protocol.NewErrWithMessage("1", e)
}
if _, ok := toDelete[subset.Id]; ok {
if _, ok := toDelete[subset.Id]; ok && subset.Id != pos.Id {
delete(toDelete, subset.Id)
}
}
... ...
package company
func userAdd() error {
import (
"fmt"
"oppmg/common/log"
"oppmg/models"
"oppmg/protocol"
)
func UserAdd(param protocol.RequestUserAdd) error {
var (
// user models.User
// userRoles []models.RoleRelated
// userPositions []models.UserPosition
// userDeparts []models.UserPosition
)
//校验角色
validCompanyRole(param.CompanyId, param.Roles)
//校验部门
validCompanyDepart(param.CompanyId, param.Departments)
//校验职位
validCompanyPositions(param.CompanyId, param.Positions)
//添加用户
//添加角色
//添加部门
//添加职位
return nil
}
func validCompanyRole(companyId int64, roleIds []int64) error {
for _, v := range roleIds {
role, err := models.GetRoleById(v)
if err != nil {
e := fmt.Errorf("GetRoleById(%d) err:%s", v, err)
log.Error(e.Error())
return protocol.NewErrWithMessage("1", err)
}
if role.CompanyId != companyId {
e := fmt.Errorf(" role.CompanyId != param.CompanyId ")
log.Error(e.Error())
return protocol.NewErrWithMessage("1", err)
}
}
return nil
}
func validCompanyDepart(companyId int64, departIds []int64) error {
for _, v := range departIds {
depart, err := models.GetDepartmentById(v)
if err != nil {
e := fmt.Errorf("GetDepartmentById(%d) err:%s", v, err)
log.Error(e.Error())
return protocol.NewErrWithMessage("1", err)
}
if depart.CompanyId != companyId {
e := fmt.Errorf(" depart.CompanyId != param.CompanyId ")
log.Error(e.Error())
return protocol.NewErrWithMessage("1", err)
}
}
return nil
}
func validCompanyPositions(companyId int64, positionIds []int64) error {
for _, v := range positionIds {
pos, err := models.GetPositionById(v)
if err != nil {
e := fmt.Errorf("GetDepartmentById(%d) err:%s", v, err)
log.Error(e.Error())
return protocol.NewErrWithMessage("1", err)
}
if pos.CompanyId != companyId {
e := fmt.Errorf("pos.CompanyId != pos.CompanyId")
log.Error(e.Error())
return protocol.NewErrWithMessage("1", err)
}
}
return nil
}
func UserEdit(param protocol.RequestUserEdit) error {
return nil
}
func userEdit() error {
func UserDelete(param protocol.RequestUserAdd) error {
return nil
}
... ...
package filesave
import (
"fmt"
"github.com/sony/sonyflake"
)
var sf = sonyflake.NewSonyflake(sonyflake.Settings{})
func GenerateIDBySonyflake() int64 {
num, _ := sf.NextID()
return int64(num)
}
func GenerateNewName() string {
id := GenerateIDBySonyflake()
return fmt.Sprint(id)
}
... ...
... ... @@ -40,7 +40,7 @@ func RoleAdd(param protocol.RequestRoleAdd) (*protocol.ResponseRoleInfo, error)
return nil, protocol.NewErrWithMessage("1", err)
}
r := &protocol.ResponseRoleInfo{
ID: int(roleid),
ID: roleid,
Name: role.Name,
Descript: role.Descript,
Pid: role.Pid,
... ... @@ -63,12 +63,18 @@ func RoleDelete(param protocol.RequestRoleDelete) error {
return protocol.NewErrWithMessage("1", e)
}
//
if role.Types == models.ROLETYPES_GROUP {
if err := models.DeleteRoleByPid(param.RoleID); err != nil {
e := fmt.Errorf("DeleteRoleByPid err:%s", err)
log.Error(e.Error())
return protocol.NewErrWithMessage("1", e)
}
if role.Types != models.ROLETYPES_ROLE {
e := fmt.Errorf("role.types err")
log.Error(e.Error())
return protocol.NewErrWithMessage("1")
}
cnt, err := models.CountRoleRelatedByUser(param.RoleID)
if err != nil {
log.Error(err.Error())
return protocol.NewErrWithMessage("1")
}
if cnt > 0 {
return protocol.NewErrWithMessage("30001")
}
if err := models.DeleteRoleByID(param.RoleID); err != nil {
e := fmt.Errorf("DeleteRole err:%s", err)
... ... @@ -119,40 +125,55 @@ func RoleEdit(param protocol.RequestRoleEdit) (*protocol.ResponseRoleInfo, error
return r, nil
}
func RoleGroupDelete(param protocol.RequestRoleDelete) error {
var (
roleinfo *models.Role
err error
cnt int64
)
roleinfo, err = models.GetRoleById(param.RoleID)
if err != nil {
e := fmt.Errorf("GetRoleById(%d) err:%s", param.RoleID, err)
log.Error(e.Error())
return protocol.NewErrWithMessage("1", e)
}
if roleinfo.CompanyId != param.CompanyID {
e := fmt.Errorf("roleinfo.CompanyId(%d) != param.CompanyID(%d)", roleinfo.CompanyId, param.CompanyID)
log.Error(e.Error())
return protocol.NewErrWithMessage("1", e)
}
if roleinfo.Types != models.ROLETYPES_GROUP {
e := fmt.Errorf("it is not group")
log.Error(e.Error())
return protocol.NewErrWithMessage("1", e)
}
cnt, err = models.CountRoleByPid(roleinfo.Id)
if err != nil {
log.Error(err.Error())
return protocol.NewErrWithMessage("1")
}
if cnt > 0 {
return protocol.NewErrWithMessage("30001")
}
err = models.DeleteRoleByID(param.RoleID)
if err != nil {
e := fmt.Errorf("DeleteRoleByID(%d) err:%s", param.RoleID, err)
log.Error(e.Error())
return protocol.NewErrWithMessage("1", e)
}
return nil
}
//CanSetRole 操作员是否可以操作角色
func CanSetRole(adminId int64, groupId int64) bool {
return false
}
func RoleGetOne(param protocol.RequestRoleOne) (*protocol.ResponseRoleInfo, error) {
// roledata, err := models.GetRoleById(param.RoleID)
return nil, nil
}
// func RoleGetByPage(param protocol.RequestRoleList) (*protocol.ResponseRoleList, error) {
// var (
// where string = `a.company_id=? and a.delete_at=0`
// dataSql string = `SELECT a.id,a.name,a.descript,a.create_at,a.update_at
// FROM role AS a
// where ` + where
// countSql string = `SELECT COUNT(*) FROM role as a where ` + where
// )
// var (
// roleList []protocol.ResponseRoleInfo
// pageinfo protocol.ResponsePageInfo
// err error
// )
// pagequery := utils.NewQueryDataByPage(countSql, dataSql)
// pagequery.LimitPage(param.PageIndex, param.PageSize)
// pagequery.AddParam(param.CompanyId)
// pageinfo, err = pagequery.Query(&roleList)
// if err != nil {
// e := fmt.Errorf("SQL EXECUTE err:%s", err)
// log.Error(e.Error())
// return nil, protocol.NewErrWithMessage("1", e)
// }
// r := &protocol.ResponseRoleList{
// ResponsePageInfo: pageinfo,
// Data: roleList,
// }
// return r, nil
// }
func GetRoleGroup() error {
return nil
}
... ...
... ... @@ -45,7 +45,7 @@ func ExecuteQueryAll(result interface{}, sqlstr string, param ...interface{}) er
PrintLogSql(sqlstr, param...)
var err error
o := orm.NewOrm()
err = ExecuteQueryOneWithOrmer(o, result, sqlstr, param)
err = ExecuteQueryAllWithOrmer(o, result, sqlstr, param)
return err
}
... ...