作者 唐旭辉

机会管理 进行中

... ... @@ -3,8 +3,10 @@ package controllers
import (
"encoding/json"
"oppmg/common/log"
"oppmg/models"
"oppmg/protocol"
serveaudit "oppmg/services/audit"
servecommon "oppmg/services/common"
)
type AuditController struct {
... ... @@ -31,10 +33,29 @@ func (c *AuditController) AuditList() {
return
}
// func (c *AuditController) Test() {
// data, err := serverbac.GetUserPermission(11)
// fmt.Println(err)
// bt, err := json.Marshal(data)
// fmt.Println(err)
// fmt.Println(string(bt))
// }
//AuditListBefore
//@router /v1/audit/list/before
func (c *AuditController) AuditListBefore() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
// uid := c.GetUserId()
companyId := c.GetCompanyId()
templatelist := servecommon.SelectGetTemplateList(companyId)
chanceTypeList := servecommon.SeleteGetChanceTypeList(companyId)
departmentList := servecommon.SelectorDepartment(companyId, -1)
publicStatus := models.ChancePublishStatusMap
enableStatus := models.ChanceEnableStatusMap
reviewStatus := models.ChanceReviewStatusMap
data := map[string]interface{}{
"template": templatelist,
"chance_type": chanceTypeList,
"public_status": publicStatus,
"enable_status": enableStatus,
"review_status": reviewStatus,
"department": departmentList,
}
msg = protocol.NewReturnResponse(data, nil)
return
}
... ...
... ... @@ -8,7 +8,7 @@ import (
)
type Chance struct {
Id int `orm:"column(id);pk" description:"id 主键"`
Id int64 `orm:"column(id);pk" description:"id 主键"`
UserId int64 `orm:"column(user_id)" description:"表user_company.id id"`
DepartmentId int64 `orm:"column(department_id)" description:"表department.id 部门id (提交机会指定的部门)"`
ChanceTypeId int `orm:"column(chance_type_id)" description:"表chance_type.id 机会类型 "`
... ... @@ -90,7 +90,7 @@ func AddChance(m *Chance) (id int64, err error) {
// GetChanceById retrieves Chance by Id. Returns error if
// Id doesn't exist
func GetChanceById(id int) (v *Chance, err error) {
func GetChanceById(id int64) (v *Chance, err error) {
o := orm.NewOrm()
v = &Chance{Id: id}
if err = o.Read(v); err == nil {
... ...
package models
import (
"time"
"github.com/astaxie/beego/orm"
)
type ChanceData struct {
Id int `orm:"column(id);pk" description:"唯一编号"`
ChanceId int64 `orm:"column(chance_id);null" description:"表chance.id 机会编号"`
Images string `orm:"column(images);null" description:"图片 json"`
Speechs string `orm:"column(speechs);null" description:"语音 json"`
Videos string `orm:"column(videos);null" description:"视频 json"`
CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"`
UpdateAt time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间"`
}
func (t *ChanceData) TableName() string {
return "chance_data"
}
func init() {
orm.RegisterModel(new(ChanceData))
}
type ChanceDataImage struct {
Path string `json:"path"`
W int `json:"w"`
H int `json:"h"`
}
type ChanceDataSpeechs struct {
Path string `json:"path"`
Duration int `json:"duration"`
}
type ChanceDataVideos struct {
Path string
Cover ChanceDataImage `json:"cover"`
Duration int `json:"duration"`
}
... ...
package protocol
import "sort"
import (
"sort"
)
//输入框类型
const (
... ... @@ -11,17 +13,16 @@ const (
//InputElement 自定义表单项
type InputElement struct {
Id int `json:"id"`
Sort int `json:"sort"` //排序
Lable string `json:"lable"` //标题
InputType string `json:"inputType"` //输入类型
Required int `json:"required"` //是否必填
CurrentValue string `json:"-"` //"当前填写的值"
SectionType int8 `json:"sectionType"`
ValueList string `json:"-"` //输入候选值 value_list
Placeholder string `json:"-"` //帮助用户填写输入字段的提示 Placeholder
Disable bool `json:"-"` //"显示隐藏",
Id int `json:"id"`
Sort int `json:"sort"` //排序
Lable string `json:"lable"` //标题
InputType string `json:"inputType"` //输入类型
Required int `json:"required"` //是否必填
// CurrentValue string `json:"-"` //"当前填写的值"
SectionType int8 `json:"sectionType"`
// ValueList string `json:"-"` //输入候选值 value_list
// Placeholder string `json:"-"` //帮助用户填写输入字段的提示 Placeholder
// Disable bool `json:"-"` //"显示隐藏",
}
//自定义表单
... ... @@ -246,7 +247,7 @@ type ResponseAuditList struct {
}
type RspAuditList struct {
Id int64 `json:"id"` //机会的id
Id string `json:"id"` //机会的id
Code string `json:"code"`
ChanceType string `json:"chance_type"` //一级分类
TemplateName string `json:"template_name"` //二级分类
... ... @@ -260,3 +261,9 @@ type RspAuditList struct {
EnableStatus int `json:"enable_status"`
EnableStatusName string `json:"enable_status_name"`
}
type ChanceFlowLog struct {
CreateTime string `json:"create_time"`
Content string `json:"content"`
UserrName string `json:"user_name"`
}
... ...
... ... @@ -67,13 +67,13 @@ type RoleHasUser struct {
//下拉选择框的内容模板 -机会二级分类
type TemplateBase struct {
TemplateId int64 `orm:"column(template_id)"`
ChanceTypeId int64 `orm:"column(chance_type_id)"`
Name string `orm:"column(name)"`
TemplateId int64 `orm:"column(template_id)" json:"template_id"`
ChanceTypeId int64 `orm:"column(chance_type_id)" json:"chance_type_id"`
Name string `orm:"column(name)" json:"name"`
}
//下拉选择框的内容机会分类 - 机会一级分类
type ChanceTypeBase struct {
ChanceTypeId int64 `orm:"column(chance_type_id)"`
Name string `orm:"column(name)"`
ChanceTypeId int64 `orm:"column(chance_type_id)" json:"chance_type_id"`
Name string `orm:"column(name)" json:"name"`
}
... ...
... ... @@ -99,6 +99,7 @@ func init() {
),
beego.NSNamespace("/audit",
beego.NSRouter("/list", &controllers.AuditController{}, "post:AuditList"),
beego.NSRouter("/list/before", &controllers.AuditController{}, "post:AuditListBefore"),
),
)
... ...
package audit
import (
"encoding/json"
"fmt"
"oppmg/common/log"
"oppmg/models"
... ... @@ -115,7 +116,7 @@ func GetAuditList(param protocol.RequestAuditList, companyid int64, userid int64
for _, v := range data {
t := v.CreateAt.Unix()
item := protocol.RspAuditList{
Id: v.Id,
Id: fmt.Sprint(v.Id),
EnableStatus: v.EnableStatus,
EnableStatusName: models.ChanceEnableStatusMap[v.EnableStatus],
PublishStatus: v.PublishStatus,
... ... @@ -148,4 +149,50 @@ func GetAuditList(param protocol.RequestAuditList, companyid int64, userid int64
return returnData, nil
}
// 机会管理的列表搜索项数据
type ResponseChanceInfo struct {
BaseContent []protocol.InputElement `json:"base_content"`
ExtraContent []protocol.InputElement `json:"extra_content"`
ImageData []models.ChanceDataImage `json:"image_data"`
VideoData []models.ChanceDataVideos `json:"video_data"`
SpeechData []models.ChanceDataSpeechs `json:"speech_data"`
FlowLog []protocol.ChanceFlowLog `json:"flow_log"`
}
//机会详情
func GetChanceDetail(chanceid int64, companyid int64) (ResponseChanceInfo, error) {
var (
chanceInfo *models.Chance
err error
returnData = ResponseChanceInfo{
BaseContent: make([]protocol.InputElement, 0),
ExtraContent: make([]protocol.InputElement, 0),
ImageData: make([]models.ChanceDataImage, 0),
VideoData: make([]models.ChanceDataVideos, 0),
SpeechData: make([]models.ChanceDataSpeechs, 0),
FlowLog: make([]protocol.ChanceFlowLog, 0),
}
)
chanceInfo, err = models.GetChanceById(chanceid)
if err != nil {
log.Error("获取机会详情失败:%s", err)
return returnData, protocol.NewErrWithMessage("1")
}
if chanceInfo.CompanyId != companyid {
log.Error("机会的公司不匹配")
return returnData, protocol.NewErrWithMessage("1")
}
var (
chanceContent []protocol.InputElement
)
json.Unmarshal([]byte(chanceInfo.Content), &chanceContent)
for i := range chanceContent {
if chanceContent[i].SectionType == 1 {
returnData.BaseContent = append(returnData.BaseContent, chanceContent[i])
}
if chanceContent[i].SectionType == 2 {
returnData.ExtraContent = append(returnData.ExtraContent, chanceContent[i])
}
}
return returnData, nil
}
... ...
... ... @@ -159,22 +159,28 @@ func SelectorUserAndDepartment(departid int64, companyId int64) (*protocol.Depar
}
//获取机会二级分类
func SelectGetTemplateList() []protocol.TemplateBase {
func SelectGetTemplateList(companyid int64) []protocol.TemplateBase {
datasql := `SELECT id AS template_id,chance_type_id,name
FROM audit_template
where company_id = ? AND enable_status = 1`
data := make([]protocol.TemplateBase, 0)
utils.ExecuteQueryAll(&data, datasql)
err := utils.ExecuteQueryAll(&data, datasql, companyid)
if err != nil {
log.Error("EXECUTE SQL ERR :%s", err)
}
return data
}
//获取机会一级级分类
func SeleteGetChanceTypeList() []protocol.ChanceTypeBase {
func SeleteGetChanceTypeList(companyid int64) []protocol.ChanceTypeBase {
datasql := ` SELECT id AS chance_type_id,name
FROM chance_type
WHERE company_id = ?`
data := make([]protocol.ChanceTypeBase, 0)
utils.ExecuteQueryAll(&data, datasql)
err := utils.ExecuteQueryAll(&data, datasql, companyid)
if err != nil {
log.Error("EXECUTE SQL ERR :%s", err)
}
return data
}
... ...
... ... @@ -141,13 +141,18 @@ func RoleMenuEdit(companyid int64, roleId int64, menuids []int64) error {
return protocol.NewErrWithMessage("1")
}
}
opptionbt, _ := json.Marshal(&PermissionOptionBase{Check: 1})
for _, v := range addMenu {
m := models.RoleMenu{
RoleId: roleId,
MenuId: v.Id,
Code: v.Code,
Opption: string(opptionbt),
RoleId: roleId,
MenuId: v.Id,
Code: v.Code,
}
if fn, ok := CodePermissionObject[v.Code]; ok {
obj := fn()
optionbt, _ := json.Marshal(obj)
m.Opption = string(optionbt)
}
if _, err = o.Insert(&m); err != nil {
log.Error("添加角色和菜单关系失败:%s", err)
... ...
... ... @@ -20,7 +20,9 @@ var (
)
func NewPermissionOptionBase() PermissionOptionObject {
return &PermissionOptionBase{}
return &PermissionOptionBase{
Check: 1,
}
}
func (p *PermissionOptionBase) ValidDefault(obj UserObject) bool {
... ... @@ -120,6 +122,7 @@ var (
func NewOptionOpportunity() PermissionOptionObject {
return &OptionOpportunity{
Check: OpportunityCheckLv4,
CheckMap: make(map[int]int),
CheckOption: CheckOpp{
Departments: []CheckDeparment{},
... ...