作者 唐旭辉

bug修复以及新增接口

... ... @@ -284,7 +284,7 @@ func (c *RbacController) RoleMenuEdit() {
return
}
//RoleMenuEdit 设置
//RoleMenuOpportunity 机会管理高级设置
//@router /role/menu/opportunity
func (c *RbacController) RoleMenuOpportunity() {
var msg *protocol.ResponseMessage
... ... @@ -292,8 +292,7 @@ func (c *RbacController) RoleMenuOpportunity() {
c.ResposeJson(msg)
}()
type Parameter struct {
RoleId int64 `json:"role_id"`
MenuIds []int64 `json:"menu_ids"`
RoleId int64 `json:"role_id"`
}
var param Parameter
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
... ... @@ -302,7 +301,30 @@ func (c *RbacController) RoleMenuOpportunity() {
return
}
companyid := c.GetCompanyId()
err := serverbac.RoleMenuEdit(companyid, param.RoleId, param.MenuIds)
data, err := serverbac.GetSetOpportunity(param.RoleId, companyid)
msg = protocol.NewReturnResponse(data, err)
return
}
//RoleMenuOpportunity 机会管理高级设置
//@router /role/menu/opportunity/edit
func (c *RbacController) RoleMenuOpportunityEdit() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
type Parameter struct {
RoleId int64 `json:"role_id"`
Option serverbac.OptionOpportunity `json:"option"`
}
var param Parameter
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
log.Error("json 解析失败 err:%s", err)
msg = protocol.BadRequestParam("1")
return
}
companyid := c.GetCompanyId()
err := serverbac.UpdateSetOpportunity(param.Option, param.RoleId, companyid)
msg = protocol.NewReturnResponse(nil, err)
return
}
... ...
... ... @@ -76,9 +76,15 @@ func DeleteBulletinQuestion(id int) (err error) {
func GetBulletinQuestionByBulletinId(id int) (v *BulletinQuestion, err error) {
o := orm.NewOrm()
sql := "select * from bulletin_question where bulletin_id=?"
if err = o.Raw(sql, id).QueryRow(&v); err == nil {
return v, nil
// sql := "select * from bulletin_question where bulletin_id=?"
// if err = o.Raw(sql, id).QueryRow(&v); err == nil {
// return v, nil
// }
v = &BulletinQuestion{}
err = o.QueryTable(v).Filter("bulletin_id", id).One(v)
if err != nil {
return nil, err
}
return nil, err
return v, err
}
... ...
... ... @@ -60,7 +60,7 @@ func GetMenuByCode(code string) (*Menu, error) {
Filter("code", code).
One(menuinfo)
if err != nil {
return menuinfo, nil
return nil, err
}
return nil, err
return menuinfo, nil
}
... ...
package models
import (
"fmt"
"github.com/astaxie/beego/orm"
)
... ... @@ -36,24 +38,22 @@ func GetRoleMenuByRole(roleid int64) ([]RoleMenu, error) {
}
func GetRoleMenuByCode(roleId int64, code string) (*RoleMenu, error) {
data := []*RoleMenu{}
var data RoleMenu
o := orm.NewOrm()
_, err := o.QueryTable(&Role{}).
err := o.QueryTable(&RoleMenu{}).
Filter("role_id", roleId).
Filter("code", code).
All(&data)
One(&data)
fmt.Println(err)
if err != nil {
return nil, err
}
if len(data) > 0 {
return data[0], nil
}
return &RoleMenu{}, nil
return &data, nil
}
func AddRoleMenu(m *RoleMenu, om ...orm.Ormer) (id int64, err error) {
var o orm.Ormer
if len(om) == 0 {
if len(om) > 0 {
o = om[0]
} else {
o = orm.NewOrm()
... ...
... ... @@ -54,7 +54,7 @@ func init() {
// last inserted Id on success.
func AddUserRole(m *UserRole, om ...orm.Ormer) (id int64, err error) {
var o orm.Ormer
if len(om) == 0 {
if len(om) > 0 {
o = om[0]
} else {
o = orm.NewOrm()
... ...
... ... @@ -51,12 +51,13 @@ type BulletinListResponse struct {
}
type BulletinItem struct {
Id int `json:"id"`
Type int8 `json:"type"`
Title string `json:"title"`
Status int8 `json:"status"`
Receiver []VisibleObject `json:"receiver" valid:"Required"`
CreateAt string `json:"time"`
Id int `json:"id"`
Type int8 `json:"type"`
Title string `json:"title"`
Status int8 `json:"status"`
QuestionSwitch int8 `json:"question_switch"`
Receiver []VisibleObject `json:"receiver" valid:"Required"`
CreateAt string `json:"time"`
}
/*GetBulletin */
... ...
... ... @@ -42,6 +42,8 @@ func init() {
beego.NSRouter("/menu/list", &controllers.RbacController{}, "post:MenuList"),
beego.NSRouter("/role/menu", &controllers.RbacController{}, "post:RoleHasMenu"),
beego.NSRouter("/role/menu/edit", &controllers.RbacController{}, "post:RoleMenuEdit"),
beego.NSRouter("/role/menu/opportunity", &controllers.RbacController{}, "post:RoleMenuOpportunity"),
beego.NSRouter("/role/menu/opportunity/edit", &controllers.RbacController{}, "post:RoleMenuOpportunityEdit"),
),
beego.NSNamespace("/user",
beego.NSRouter("/list", &controllers.CompanyController{}, "post:UserList"),
... ...
... ... @@ -3,7 +3,6 @@ package bulletin
import (
"encoding/json"
"fmt"
orm2 "github.com/astaxie/beego/orm"
"oppmg/common/log"
"oppmg/models"
"oppmg/protocol"
... ... @@ -12,6 +11,8 @@ import (
"strconv"
"strings"
"time"
orm2 "github.com/astaxie/beego/orm"
)
//发布公告
... ... @@ -182,11 +183,12 @@ func BulletinList(uid, companyId int64, request *protocol.BulletinListRequest) (
for i := range list {
bulletin := list[i]
item := &protocol.BulletinItem{
Id: bulletin.Id,
Type: bulletin.Type,
Title: bulletin.Title,
Status: int8(bulletin.Status),
CreateAt: bulletin.CreateAt.Format("2006-01-02 15:04:05"),
Id: bulletin.Id,
Type: bulletin.Type,
Title: bulletin.Title,
QuestionSwitch: bulletin.QuestionSwitch,
Status: int8(bulletin.Status),
CreateAt: bulletin.CreateAt.Format("2006-01-02 15:04:05"),
}
if e := json.Unmarshal([]byte(bulletin.Receiver), &item.Receiver); e != nil {
log.Error(e.Error())
... ... @@ -256,6 +258,9 @@ func GetBulletin(id int, companyId int64, request *protocol.GetBulletinRequest)
AllowClose: int(bulletin.AllowClose),
//AllowCondition: int(bulletin.AllowCondition),
Cover: protocol.Cover(bulletin.Cover),
Question: protocol.Question{
Content: []protocol.QuestionContent{},
},
}
if bulletin.QuestionSwitch == 1 {
if question, err = models.GetBulletinQuestionByBulletinId(bulletin.Id); err != nil {
... ... @@ -324,26 +329,48 @@ func UpdateBulletin(companyId int64, request *protocol.UpdateBulletinRequest) (r
}
if bulletin.QuestionSwitch == 1 {
if bulletinQuestion, err = models.GetBulletinQuestionByBulletinId(bulletin.Id); err != nil {
bulletinQuestion, err = models.GetBulletinQuestionByBulletinId(bulletin.Id)
if err != nil && err != orm2.ErrNoRows {
log.Error(err.Error())
return
}
if bulletinQuestion.BulletinId != bulletin.Id {
err = protocol.NewErrWithMessage("1")
log.Error("UpdateBulletin:BulletinId not equal:(%v!=%v)", bulletinQuestion.BulletinId, bulletin.Id)
return
}
if questionContent, err = json.Marshal(request.Question.Content); err != nil {
log.Error(err.Error())
return
if err == nil {
//更新
if bulletinQuestion.BulletinId != bulletin.Id {
err = protocol.NewErrWithMessage("1")
log.Error("UpdateBulletin:BulletinId not equal:(%v!=%v)", bulletinQuestion.BulletinId, bulletin.Id)
return
}
if questionContent, err = json.Marshal(request.Question.Content); err != nil {
log.Error(err.Error())
return
}
bulletinQuestion.Title = request.Title
bulletinQuestion.Content = string(questionContent)
bulletinQuestion.Type = int8(request.Question.Type)
bulletinQuestion.UpdateAt = time.Now()
if err = models.UpdateBulletinQuestionById(bulletinQuestion); err != nil {
log.Error(err.Error())
return
}
}
bulletinQuestion.Content = string(questionContent)
bulletinQuestion.Type = int8(request.Question.Type)
bulletinQuestion.UpdateAt = time.Now()
if err = models.UpdateBulletinQuestionById(bulletinQuestion); err != nil {
log.Error(err.Error())
return
if err == orm2.ErrNoRows {
//添加
bulletinQuestion = &models.BulletinQuestion{
BulletinId: bulletin.Id,
Type: int8(request.Question.Type),
Title: request.Title,
Content: string(questionContent),
CreateAt: time.Now(),
UpdateAt: time.Now(),
}
_, err = models.AddBulletinQuestion(bulletinQuestion)
if err != nil {
log.Error("添加问题失败:%s", err)
return
}
}
}
return
}
... ...
... ... @@ -62,9 +62,9 @@ func FilterRoleAll(adminid int64, companyid int64, list []protocol.RoleBase) []p
}
}
for k, v := range list {
if v.Types == models.ROLETYPES_ROLE && v.IsDefault == models.ROLE_DEFAULR {
continue
}
// if v.Types == models.ROLETYPES_ROLE && v.IsDefault == models.ROLE_DEFAULR {
// continue
// }
if companyInfo.AdminId != adminid {
//非主管理员
if v.Id == admingoroupId || v.ParentId == admingoroupId {
... ...
... ... @@ -63,7 +63,7 @@ OptionOpportunity
type CheckDeparment struct {
Id int64 `json:"id"`
Name string `json:"name,omitempty"`
Wait int `json:"wail"`
Wait int `json:"wait"`
OpenAll int `json:"open_all"`
OpenDepart int `json:"open_depart"`
}
... ... @@ -75,11 +75,11 @@ type CheckOpp struct {
//OptionOpportunity 机会管理 高级权限设置
type OptionOpportunity struct {
Check int `json:"check"`
CheckOption CheckOpp
EditSorce int `json:"edit_sorce"`
EditPublicStatus int `json:"edit_public_status"`
CloseChance int `json:"close_chance"`
Check int `json:"check"`
CheckOption CheckOpp `json:"check_option"`
EditSorce int `json:"edit_sorce"`
EditPublicStatus int `json:"edit_public_status"`
CloseChance int `json:"close_chance"`
}
/*
... ...