作者 唐旭辉

提交存储

... ... @@ -34,3 +34,7 @@
| 机会&审批 模板 | 未开始 | | | |
| 机会&审批 模板 | 未开始 | | | |
| 机会&审批 模板 | 未开始 | | | |
| 机会类型设置 | 未开始 | | | |
| 机会类型设置 | 未开始 | | | |
| 机会类型设置 | 未开始 | | | |
| 机会类型设置 | 未开始 | | | |
... ...
... ... @@ -95,3 +95,14 @@ func (c *AuthController) ChangeCompany() {
msg = protocol.NewReturnResponse(logintoken, err)
return
}
func (c *AuthController) Me() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
// userid := c.GetUserId()
// companyid := c.GetCompanyId()
return
}
... ...
... ... @@ -3,11 +3,12 @@ package controllers
import (
"encoding/json"
"fmt"
"github.com/astaxie/beego"
"github.com/astaxie/beego/validation"
"oppmg/common/log"
"oppmg/protocol"
"strconv"
"github.com/astaxie/beego"
"github.com/astaxie/beego/validation"
)
//BaseController 基础
... ... @@ -72,11 +73,13 @@ func (this *BaseController) Valid(obj interface{}) (result bool, msg *protocol.R
valid := validation.Validation{}
result, err = valid.Valid(obj)
if err != nil {
log.Error("参数校验失败:%s", err)
msg = protocol.BadRequestParam("1")
return
}
if !result {
msg = protocol.BadRequestParam("2")
log.Error("校验结果:%v", result)
msg = protocol.BadRequestParam("1")
return
}
... ...
... ... @@ -28,6 +28,7 @@ func (this *BulletinController) BulletinRelease() {
uid := this.GetUserId()
companyId := this.GetCompanyId()
if companyId <= 0 {
log.Debug("companyId:%d err", companyId)
msg = protocol.BadRequestParam("1")
return
}
... ...
... ... @@ -81,8 +81,8 @@ func (c *CompanyController) DepartmentAdd() {
msg = protocol.BadRequestParam("1")
return
}
err := servecompany.DepartmentAdd(param)
msg = protocol.NewReturnResponse(nil, err)
result, err := servecompany.DepartmentAdd(param)
msg = protocol.NewReturnResponse(result, err)
return
}
... ...
... ... @@ -28,36 +28,9 @@ var LogRequestData = func(ctx *context.Context) {
}
}
//CheckSign Before Router
// var CheckSign = func(ctx *context.Context) {
// var (
// headTimeStamp string
// headUuid string
// headAccessToken string
// headSign string
// signHex string
// )
// headTimeStamp = ctx.Input.Header(protocol.HeaderTimestamp)
// headUuid = ctx.Input.Header(protocol.HeaderUUID)
// headSign = ctx.Input.Header(protocol.HeaderSign)
// setsign := fmt.Sprintf("v!(MmM%v%v%vMmM)i^", headTimeStamp, headUuid, headAccessToken)
// sha256 := sha256.New()
// sha256.Write([]byte(setsign))
// signHex = hex.EncodeToString(sha256.Sum(nil))
// if strings.Compare(signHex, headSign) != 0 {
// msg := protocol.BadRequestParam("113")
// ctx.Output.JSON(msg, false, false)
// return
// }
// return
// }
//AuthToken Before Router
var AuthToken = func(ctx *context.Context) {
log.Debug("执行中间件AuthToken")
if beego.BConfig.RunMode != "prod" {
return
}
var (
storetoken redisdata.RedisLoginToken
msg *protocol.ResponseMessage
... ... @@ -94,7 +67,7 @@ var AuthToken = func(ctx *context.Context) {
ctx.Output.JSON(msg, false, false)
return
}
msg = protocol.NewMesage("10024")
msg = protocol.NewMesage("1")
ctx.Output.JSON(msg, false, false)
return
}
... ... @@ -123,4 +96,7 @@ var LogRouter = func(ctx *context.Context) {
return
}
//登录失效
//CheckOperation 检查操作权限,beforeController
var CheckOperation = func(ctx *context.Context) {
}
... ...
... ... @@ -46,3 +46,19 @@ type RequestSwapCompany struct {
type ResponseSwapCompany struct {
LoginAuthToken
}
//ResponseMeInfo 用户个人的me信息
type ResponseMeInfo struct {
NickName string `json:"nick_name"`
Icon string `json:"icon"`
Companyid int64 `json:"company_id"`
Companyname string `json:"company_name"`
Logo string `json:"logo"`
Companys []MeCompany `json:"companys"`
// Menu
}
type MeCompany struct {
Id int64 `json:"id"`
Name string `json:"name"`
}
... ...
... ... @@ -8,6 +8,10 @@ type RequestDepartmentAdd struct {
Managers []int64 `json:"manages"` //主管userid
}
type ResponseDepartmenrAdd struct {
DepartmentId int64 `json:"id"` // 部门id
}
type DepartmentManager struct {
Id int64 `json:"id"`
Name string `json:"name"`
... ...
... ... @@ -29,10 +29,9 @@ type RequestRoleEdit struct {
//ResponseRoleInfo 响应数据
type ResponseRoleInfo struct {
ID int64 `json:"id"`
Name string `json:"name"`
Descript string `json:"descript"`
Types int8 `json:"types"`
ID int64 `json:"id"`
Name string `json:"name"`
Types int8 `json:"type"`
}
//RequestRoleList 分页获取角色列表
... ...
... ... @@ -57,7 +57,7 @@ func init() {
//routerPermission 路由对应的权限
// var routerPermission = map[string]string{
// "get:/v1/company/:companyid/position": "show",
// : "show",
// "post:/v1/company/position": "add",
// "put:/v1/company/position": "edit",
// "delete:/v1/company/position": "delete",
... ...
... ... @@ -227,7 +227,7 @@ func LoginAuthByUCenter(account, password string) (protocol.LoginAuthToken, erro
err error
logintoken protocol.LoginAuthToken
uclientReturn ucenter.ResponseLogin
companyids []int64
companys []companybase
companyid int64
userdata *models.User
)
... ... @@ -240,15 +240,15 @@ func LoginAuthByUCenter(account, password string) (protocol.LoginAuthToken, erro
log.Debug("userdata.IsEnable()==false")
return logintoken, protocol.NewErrWithMessage("10021")
}
if companyids, err = getUserCompanyReal(userdata.Id); err != nil {
if companys, err = getUserCompanyReal(userdata.Id); err != nil {
log.Error("getUserCompanyReal err:%s", err)
return logintoken, protocol.NewErrWithMessage("10021")
}
if len(companyids) == 0 {
if len(companys) == 0 {
log.Debug("no company")
return logintoken, protocol.NewErrWithMessage("10021")
}
companyid = companyids[0]
companyid = companys[0].Id
param := ucenter.RequesLogin{
Phone: account,
Password: password,
... ... @@ -272,23 +272,30 @@ func LoginAuthByUCenter(account, password string) (protocol.LoginAuthToken, erro
return logintoken, err
}
type companybase struct {
Id int64 `orm:"column(id)"`
Name string `orm:"coumn(name)"`
Logo string `orm:"coumn(logo)"`
}
//getUserCompanyReal 获取用户有效的公司id
func getUserCompanyReal(userid int64) (companyids []int64, err error) {
func getUserCompanyReal(userid int64) (companyids []companybase, err error) {
const (
datasql0 string = `SELECT b.company_id FROM user_company AS b
WHERE b.delete_at=0 AND b.enable = 1 AND b.user_id=?`
datasql2 string = `SELECT b.id FROM company AS b
datasql2 string = `SELECT b.id,a.name,a.logo FROM company AS b
WHERE b.delete_at=0 AND b.enable = 1 AND b.id in (%s) `
)
var (
ids []string
companys []companybase
ids []string
)
err = utils.ExecuteQueryAll(&ids, datasql0, userid)
if err != nil {
log.Error("EXECUTE SQL err:%s", err)
return nil, err
}
if len(ids) == 0 {
if len(companys) == 0 {
return nil, nil
}
datasql3 := fmt.Sprintf(datasql2, strings.Join(ids, ","))
... ... @@ -297,5 +304,45 @@ func getUserCompanyReal(userid int64) (companyids []int64, err error) {
log.Error("EXECUTE SQL err:%s", err)
return nil, err
}
return companyids, nil
return companys, nil
}
func UserBaseInfo(userid, companyid int64) (protocol.ResponseMeInfo, error) {
var (
err error
userinfo *models.User
companylist []companybase
meInfo protocol.ResponseMeInfo
currentCompany *models.Company
)
userinfo, err = models.GetUserById(userid)
if err != nil {
log.Error("GetUserById(%d) err:%s", userid, err)
return meInfo, protocol.NewErrWithMessage("1", err)
}
currentCompany, err = models.GetCompanyById(companyid)
if err != nil {
log.Error("GetCompanyById(%d) err:%s", companyid, err)
return meInfo, protocol.NewErrWithMessage("1", err)
}
companylist, err = getUserCompanyReal(userid)
if err != nil {
log.Error("getUserCompanyReal(%d) err:%s", userid, err)
return meInfo, protocol.NewErrWithMessage("1", err)
}
meInfo = protocol.ResponseMeInfo{
NickName: userinfo.NickName,
Icon: userinfo.Icon,
Companyid: currentCompany.Id,
Companyname: currentCompany.Name,
Logo: currentCompany.Logo,
}
for _, v := range companylist {
t := protocol.MeCompany{
Id: v.Id,
Name: v.Name,
}
meInfo.Companys = append(meInfo.Companys, t)
}
return meInfo, nil
}
... ...
... ... @@ -12,9 +12,10 @@ import (
"github.com/astaxie/beego/orm"
)
func DepartmentAdd(param protocol.RequestDepartmentAdd) error {
func DepartmentAdd(param protocol.RequestDepartmentAdd) (protocol.ResponseDepartmenrAdd, error) {
var (
parentDepart *models.Department
returndata protocol.ResponseDepartmenrAdd
err error
)
if param.ParentID > 0 {
... ... @@ -22,12 +23,12 @@ func DepartmentAdd(param protocol.RequestDepartmentAdd) error {
if err != nil {
e := fmt.Errorf("GetDepartmentById(%d) err:%s", param.ParentID, err)
log.Error(e.Error())
return protocol.NewErrWithMessage("1", e)
return returndata, protocol.NewErrWithMessage("1", e)
}
if parentDepart.CompanyId != param.CompanyID {
e := fmt.Errorf("parentDepart.CompanyId != param.CompanyID")
log.Error(e.Error())
return protocol.NewErrWithMessage("1", e)
return returndata, protocol.NewErrWithMessage("1", e)
}
}
for _, v := range param.Managers {
... ... @@ -35,7 +36,7 @@ func DepartmentAdd(param protocol.RequestDepartmentAdd) error {
if err != nil {
e := fmt.Errorf("GetUserCompanyBy(userid,companyid)[%d, %d] err:%s", v, param.CompanyID, err)
log.Error(e.Error())
return protocol.NewErrWithMessage("1", e)
return returndata, protocol.NewErrWithMessage("1", e)
}
}
departmentAdd := &models.Department{
... ... @@ -54,24 +55,25 @@ func DepartmentAdd(param protocol.RequestDepartmentAdd) error {
o.Rollback()
e := fmt.Errorf("AddDepartment err:%s", err)
log.Error(e.Error())
return protocol.NewErrWithMessage("1", e)
return returndata, protocol.NewErrWithMessage("1", e)
}
err = departmentAdd.SetRelation(parentDepart)
if err != nil {
o.Rollback()
e := fmt.Errorf("SetRelation err:%s", err)
log.Error(e.Error())
return protocol.NewErrWithMessage("1", e)
return returndata, protocol.NewErrWithMessage("1", e)
}
err = models.UpdateDepartmentById(departmentAdd, []string{"Relation"}, o)
if err != nil {
o.Rollback()
e := fmt.Errorf("UpdateDepartmentById err:%s", err)
log.Error(e.Error())
return protocol.NewErrWithMessage("1", e)
return returndata, protocol.NewErrWithMessage("1", e)
}
o.Commit()
return nil
returndata.DepartmentId = departmentAdd.Id
return returndata, nil
}
... ...
... ... @@ -41,10 +41,9 @@ func RoleAdd(param protocol.RequestRoleAdd) (*protocol.ResponseRoleInfo, error)
return nil, protocol.NewErrWithMessage("1", err)
}
r := &protocol.ResponseRoleInfo{
ID: roleid,
Name: role.Name,
Descript: role.Descript,
Types: role.Types,
ID: roleid,
Name: role.Name,
Types: role.Types,
}
return r, nil
}
... ... @@ -113,10 +112,9 @@ func RoleEdit(param protocol.RequestRoleEdit) (*protocol.ResponseRoleInfo, error
return nil, protocol.NewErrWithMessage("1", e)
}
r := &protocol.ResponseRoleInfo{
ID: role.Id,
Name: role.Name,
Descript: role.Descript,
Types: role.Types,
ID: role.Id,
Name: role.Name,
Types: role.Types,
}
return r, nil
}
... ...
... ... @@ -66,7 +66,7 @@ token 的响应内容
}
```
- 响应 json
- 正常响应 json
```json
{
... ... @@ -95,7 +95,7 @@ token 的响应内容
```
- 响应 json
- 正常响应 json
```json
{
... ... @@ -126,7 +126,7 @@ token 的响应内容
}
```
- 响应 json
- 正常响应 json
```json
{
... ... @@ -145,6 +145,267 @@ token 的响应内容
---
## 公司部门管理
### 添加部门
- 请求路径:/v1/department/add
- 请求方式:post
- 请求 json:
```json
{
"name": "部门8",
"parent_id": 13,
"manages": [1, 2, 3] //部门主管id列表
}
```
- 正常响应 json
```json
{
"code": 0,
"msg": "成功",
"data": {
"id": 12 //部门id
}
}
```
- 备注;无
---
### 编辑部门
- 请求路径:/v1/department/edit
- 请求方式:post
- 请求 json:
```json
{
"id": 1,
"name": "部门8",
"parent_id": 13,
"manages": [1, 2, 3] //部门主管id列表
}
```
- 响应 json
```json
{
"code": 0,
"msg": "成功",
"data": null
}
```
- 备注;无
---
### 删除部门
- 请求路径:/v1/department/delete
- 请求方式:post
- 请求 json:
```json
{
"ids": [1, 2]
}
```
- 响应 json
```json
{
"code": 0,
"msg": "成功",
"data": null
}
```
- 备注;无
---
## 公司职位管理
### 添加职位
- 请求路径:/v1/position/add
- 请求方式:post
- 请求 json:
```json
{
"name": "职位b-1",
"parent_id": 8
}
```
- 响应 json
```json
{
"code": 0,
"msg": "成功",
"data": {
"id": 2
}
}
```
- 备注;无
---
### 编辑职位
- 请求路径:/v1/position/edit
- 请求方式:post
- 请求 json:
```json
{
"id": 2,
"name": "职位b-1",
"parent_id": 8
}
```
- 响应 json
```json
{
"code": 0,
"msg": "成功",
"data": {
"id": 2
}
}
```
- 备注;无
---
### 删除职位
- 请求路径:/v1/position/delete
- 请求方式:post
- 请求 json:
```json
{
"id": [1, 2, 3]
}
```
- 响应 json
```json
{
"code": 0,
"msg": "成功",
"data":
}
```
- 备注;无
---
## 公司员工角色
### 添加角色
- 请求路径:/v1/rbac/role/add
- 请求方式:post
- 请求 json:
```json
{
"pid": 8,
"name": "角色7"
}
```
- 响应 json
```json
{
"code": 0,
"msg": "成功",
"data": {
"id": 2
}
}
```
- 备注;无
---
### 编辑角色
- 请求路径:/v1/rbac/role/edit
- 请求方式:post
- 请求 json:
```json
{
"id": 7,
"pid": 8,
"name": "角色7"
}
```
- 响应 json
```json
{
"code": 0,
"msg": "成功",
"data": {
"id": 2
}
}
```
### 删除角色
- 请求路径:/v1/rbac/role/delete
- 请求方式:post
- 请求 json:
```json
{
"ids": [1, 23]
}
```
- 响应 json
```json
{
"code": 0,
"msg": "成功",
"data": null
}
```
- 备注;无
---
- 备注;无
---
## 公告
### 添加公告
... ... @@ -155,33 +416,32 @@ token 的响应内容
```json
{
"type":2,
"title":"标题",
"content":"公告内容",
"allow_close":0,
"question_switch":1,
"receiver":["1","2"],
"question":
{
"id":1,
"type":1,
"title":"今天星期几?",
"content":[
{
"id":1,
"content":"星期1"
},
{
"id":2,
"content":"星期2"
}
]
},
"cover":{
"path":"/xx/xx.img",
"w":50,
"h":70
}
"type": 2,
"title": "标题",
"content": "公告内容",
"allow_close": 0,
"question_switch": 1,
"receiver": ["1", "2"],
"question": {
"id": 1,
"type": 1,
"title": "今天星期几?",
"content": [
{
"id": 1,
"content": "星期1"
},
{
"id": 2,
"content": "星期2"
}
]
},
"cover": {
"path": "/xx/xx.img",
"w": 50,
"h": 70
}
}
```
... ... @@ -328,34 +588,33 @@ obj.status 状态 0-所有 1-下架 2-上架
```json
{
"id":3,
"type":2,
"title":"测试公告3",
"content":"今天发布了一则公告3",
"allow_close":0,
"question_switch":1,
"receiver":["1","2","3"],
"question":
{
"id":2,
"type":1,
"title":"今天星期几?",
"content":[
{
"id":1,
"content":"星期2"
},
{
"id":2,
"content":"星期3"
}
]
},
"cover":{
"path":"/xx/xx.img",
"w":50,
"h":70
}
"id": 3,
"type": 2,
"title": "测试公告3",
"content": "今天发布了一则公告3",
"allow_close": 0,
"question_switch": 1,
"receiver": ["1", "2", "3"],
"question": {
"id": 2,
"type": 1,
"title": "今天星期几?",
"content": [
{
"id": 1,
"content": "星期2"
},
{
"id": 2,
"content": "星期3"
}
]
},
"cover": {
"path": "/xx/xx.img",
"w": 50,
"h": 70
}
}
```
... ...