作者 唐旭辉

接口完成提交

### 接口完成进度
| 功能 | 完成状态 | 时间 | 接口路径 | 请求方式 |
| -------------- | ------------------ | --------------- | -------------------------- | -------- |
| 登录 | 进行中 | | |
| 短信验证码 | 未开始 | | |
| 获取 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 |
| 公告管理 | 未开始 | | | |
| 公告管理 | 未开始 | | | |
| 公告管理 | 未开始 | | | |
| 机会&审批 模板 | 未开始 | | | |
| 机会&审批 模板 | 未开始 | | | |
| 机会&审批 模板 | 未开始 | | | |
| 机会&审批 模板 | 未开始 | | | |
| 功能 | 完成状态 | 时间 | 接口路径 | 请求方式 |
| -------------- | ------------------ | --------------- | --------------------------------- | -------- |
| 登录 | 进行中 | | |
| 短信验证码 | 未开始 | | |
| 获取 token | 未开始 | | |
| 刷新 token | 未开始 | | |
| 获取角色列表 | 进行中 | | /v1/rbac/:companyid/role | get |
| 添加角色 | 完成 | 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.12.5 | /v1/company/:companyid/department | get |
| 添加部门 | 完成 | 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 |
| 获取职位列表 | 进行中 | | /v1/company/:companyid/position | get |
| 添加职位 | 完成 | 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 |
| 公告管理 | 未开始 | | | |
| 公告管理 | 未开始 | | | |
| 公告管理 | 未开始 | | | |
| 机会&审批 模板 | 未开始 | | | |
| 机会&审批 模板 | 未开始 | | | |
| 机会&审批 模板 | 未开始 | | | |
| 机会&审批 模板 | 未开始 | | | |
... ...
... ... @@ -2,7 +2,7 @@
config_name = "dev"
#----beego的默认配置 开始---
#端口号
httpport = 8081
httpport = 8080
#开启应用内监控
EnableAdmin = false
AdminPort = 8088
... ...
... ... @@ -3,7 +3,6 @@ package controllers
import (
"encoding/json"
"fmt"
"net/http"
"oppmg/common/log"
"oppmg/protocol"
"strconv"
... ... @@ -18,11 +17,13 @@ type BaseController struct {
}
//Options 实现beego.ControllerInterface 的接口
func (this *BaseController) Options() {
this.Ctx.Abort(http.StatusBadRequest, "")
}
// func (this *BaseController) Options() {
// this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", "*")
// this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
// this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Headers", "*")
// this.Ctx.Output.SetStatus(http.StatusOK)
// return
// }
//Prepare 实现beego.ControllerInterface 的接口
func (this *BaseController) Prepare() {
... ...
... ... @@ -5,6 +5,7 @@ import (
"oppmg/common/log"
"oppmg/protocol"
servecompany "oppmg/services/company"
"strconv"
)
type CompanyController struct {
... ... @@ -16,6 +17,63 @@ func (c *CompanyController) URLMapping() {
//c.Mapping("AccessToken", c.AccessToken)
}
// DepartmentAdd 部门列表
// @router /:companyid/department [get]
func (c *CompanyController) DepartmentList() {
log.Debug("DepartmentList param:%v", c.Ctx.Input.Param(":companyid"))
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
var (
param string
companyid int64
err error
)
param = c.Ctx.Input.Param(":companyid")
companyid, err = strconv.ParseInt(param, 10, 64)
if err != nil {
msg = protocol.BadRequestParam("1")
return
}
if companyid <= 0 {
msg = protocol.BadRequestParam("1")
return
}
departs, err := servecompany.DepartmentListAll(companyid)
listdata := protocol.ResponseDepartmentList{
List: departs,
}
msg = protocol.NewReturnResponse(listdata, err)
}
// DepartmentAdd 部门列表
// @router /department/:id [get]
func (c *CompanyController) DepartmentOne() {
log.Debug("DepartmentOne param:%v", c.Ctx.Input.Param(":id"))
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
var (
param string
id int64
err error
)
param = c.Ctx.Input.Param(":id")
id, err = strconv.ParseInt(param, 10, 64)
if err != nil {
msg = protocol.BadRequestParam("1")
return
}
if id <= 0 {
msg = protocol.BadRequestParam("1")
return
}
msg = protocol.NewReturnResponse(nil, nil)
}
// DepartmentAdd 添加部门
// @router /department [post]
func (c *CompanyController) DepartmentAdd() {
... ... @@ -137,3 +195,16 @@ func (c *CompanyController) PositionDelete() {
msg = protocol.NewReturnResponse(nil, err)
return
}
// PositionList 获取职位列表
// @router /:companyid/position [delete]
func (c *CompanyController) PositionList() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
var err error
msg = protocol.NewReturnResponse(nil, err)
return
}
... ...
... ... @@ -161,4 +161,15 @@ func (c *RbacController) RoleGroupDelete() {
return
}
// RoleGroupDelete
// RoleList
// @router /:companyid/role [get]
func (c *RbacController) RoleList() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
var err error
msg = protocol.NewReturnResponse(nil, err)
return
}
... ...
... ... @@ -21,6 +21,7 @@ func main() {
beego.BConfig.WebConfig.DirectoryIndex = true
beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
}
log.Debug("应用启动")
beego.Run()
}
... ...
... ... @@ -8,6 +8,8 @@ import (
"oppmg/protocol"
"strings"
"github.com/astaxie/beego/plugins/cors"
"github.com/astaxie/beego/context"
)
... ... @@ -58,3 +60,20 @@ var AppSwitch = func(ctx *context.Context) {
return
}
//AllowOption 允许跨域请求
var AllowOption = func(ctx *context.Context) {
if ctx.Request.Method != "OPTIONS" {
return
}
f := cors.Allow(&cors.Options{
AllowOrigins: []string{"*"}, //允许的请求来源
AllowMethods: []string{"POST", "GET", "OPTIONS", "PUT", "DELETE"}, //允许的请求类型
AllowHeaders: []string{"*"}, //允许的头部信息
ExposeHeaders: []string{"Content-Length"}, //允许暴露的头信息
AllowCredentials: false, //不允许共享AuthTuffic证书
})
f(ctx)
ctx.Output.Body([]byte("{}"))
return
}
... ...
... ... @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"oppmg/common/log"
"oppmg/protocol"
"time"
"github.com/astaxie/beego/orm"
... ... @@ -35,7 +36,7 @@ func (t *Department) GetManagesIds() []int64 {
var r []int64
err := json.Unmarshal([]byte(t.Manages), &r)
if err != nil {
log.Error(err.Error())
log.Warn(err.Error())
}
return r
}
... ... @@ -58,6 +59,23 @@ func (t *Department) SetRelation(parent *Department) error {
return nil
}
func (t *Department) GetManages() []protocol.DepartmentManager {
ids := t.GetManagesIds()
users, err := getUserNameByIds(ids)
if err != nil {
log.Error("GetUserNameByIds err :%s", err)
return nil
}
var managesdata []protocol.DepartmentManager
for _, v := range users {
m := protocol.DepartmentManager{
Id: v.Id, Name: v.NickName,
}
managesdata = append(managesdata, m)
}
return managesdata
}
// AddDepartment insert a new Department into database and returns
// last inserted Id on success.
func AddDepartment(m *Department, om ...orm.Ormer) (id int64, err error) {
... ...
... ... @@ -2,6 +2,7 @@ package models
import (
"fmt"
"strings"
"time"
"github.com/astaxie/beego/orm"
... ... @@ -19,6 +20,7 @@ type User struct {
LastLoginTime time.Time `orm:"column(last_login_time);type(timestamp)" description:"最后一次登录时间"`
CreateAt time.Time `orm:"column(create_at);type(timestamp);auto_now_add" description:"创建时间"`
EnableStatus int8 `orm:"column(enable_status)" description:"是否有效"`
DeleteAt time.Time `orm:"column(delete_time);type(timestamp)"`
}
func (t *User) TableName() string {
... ... @@ -92,3 +94,26 @@ func GetUserByPhone(phone string) (v *User, err error) {
}
return nil, err
}
func getUserNameByIds(ids []int64) ([]User, error) {
var (
users []User
err error
)
if len(ids) == 0 {
return users, nil
}
const (
dataSql string = `SELECT id,nick_name FROM user WHERE id IN (?) AND delete_at =0`
)
var s []string
for _, v := range ids {
s = append(s, fmt.Sprint(v))
}
o := orm.NewOrm()
_, err = o.Raw(dataSql, strings.Join(s, ",")).QueryRows(&users)
if err != nil {
return nil, err
}
return users, nil
}
... ...
... ... @@ -8,20 +8,9 @@ type RequestDepartmentAdd struct {
Managers []int64 `json:"manages"` //主管userid
}
//ResponseDepartmentInfo ...
type ResponseDepartmentInfo struct {
ID int64 `json:"id`
CompanyID int64 `json:"company_id"` //公司
Name string `json:"name"` //部门名字
ParantID int64 `json:"parant_id"` //父级部门Id
Manages []DepartmentManager `json:"manages"` //部门管理员
Member int `json:"member"` //成员数
ParantName string `json:"parant_name"` //父级部门名字
}
type DepartmentManager struct {
UserId int `json:"user_id"`
Name string `json:"name`
Id int64 `json:"id"`
Name string `json:"name`
}
//RequestDepartmentEdit 编辑
... ... @@ -36,6 +25,16 @@ type RequestDepartmentDelete struct {
CompanyID int64 `json:"company_id"` //公司
}
//ResponseDepartmentInfo ...
type ResponseDepartmentInfo struct {
ID int64 `json:"id"`
CompanyID int64 `json:"company_id"` //公司
Name string `json:"name"` //部门名字
ParantID int64 `json:"parant_id"` //父级部门Id
Manages []DepartmentManager `json:"manages"` //部门管理员
Member int `json:"member"` //成员数
}
//ResponseDepartmentList ....
type ResponseDepartmentList struct {
List []ResponseDepartmentInfo
... ... @@ -81,10 +80,4 @@ type RequestUserAdd struct {
type RequestUserEdit struct {
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"`
}
... ...
... ... @@ -2,7 +2,7 @@ package protocol
var errmessge ErrorMap = map[string]string{
"00000": "成功",
"1": "系统异常",
"1": "无效请求",
"101": "clientId或clientSecret无效",
"113": "签名验证失败",
//角色相关
... ...
... ... @@ -10,13 +10,18 @@ import (
func init() {
nsV1 := beego.NewNamespace("v1",
beego.NSBefore(middleware.AllowOption),
beego.NSBefore(middleware.LogRequestData, middleware.AuthToken),
beego.NSNamespace("/company",
beego.NSRouter("/:companyid/department", &controllers.CompanyController{}, "get:DepartmentList"),
beego.NSRouter("/department/:id", &controllers.CompanyController{}, "get:DepartmentOne"),
beego.NSRouter("/department", &controllers.CompanyController{}, "post:DepartmentAdd"),
beego.NSRouter("/department", &controllers.CompanyController{}, "put:DepartmentUpdate"),
beego.NSRouter("/department", &controllers.CompanyController{}, "delete:DepartmentDelete"),
beego.NSRouter("/:companyid/position", &controllers.CompanyController{}, "get:PositionList"),
beego.NSRouter("/position", &controllers.CompanyController{}, "post:PositionAdd"),
beego.NSRouter("/position", &controllers.CompanyController{}, "put:PositionEdit"),
beego.NSRouter("/position", &controllers.CompanyController{}, "delete:PositionDelete"),
),
beego.NSNamespace("/rbac",
beego.NSRouter("/role", &controllers.RbacController{}, "post:RoleAdd"),
... ... @@ -25,6 +30,7 @@ func init() {
beego.NSRouter("/role_group", &controllers.RbacController{}, "post:RoleGroupAdd"),
beego.NSRouter("/role_group", &controllers.RbacController{}, "put:RoleGroupUpdate"),
beego.NSRouter("/role_group", &controllers.RbacController{}, "delete:RoleGroupDelete"),
beego.NSRouter("/:companyid/role", &controllers.RbacController{}, "get:RoleList"),
),
)
... ...
... ... @@ -326,8 +326,34 @@ func DepartmentDelete(param protocol.RequestDepartmentDelete) error {
return nil
}
func DepartmentListAll(companyId int64) (protocol.ResponseDepartmentList, error) {
//DepartmentListAll 获取公司的部门
func DepartmentListAll(companyId int64) ([]protocol.ResponseDepartmentInfo, error) {
var (
departs []protocol.ResponseDepartmentInfo
departmodels []*models.Department
err error
)
const (
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)
if err != nil {
e := fmt.Errorf("EXECUTE SQL err:%s", err)
log.Error(e.Error())
return nil, protocol.NewErrWithMessage("1", err)
}
for _, v := range departmodels {
depart := protocol.ResponseDepartmentInfo{
ID: v.Id, CompanyID: v.CompanyId,
Name: v.Name, Member: v.Member,
ParantID: v.ParentId,
}
var manage []protocol.DepartmentManager
manage = v.GetManages()
depart.Manages = manage
departs = append(departs, depart)
}
r := protocol.ResponseDepartmentList{}
return r, nil
return departs, nil
}
... ...