作者 yangfu

评分配置修改

package v1
import (
"encoding/json"
"opp/controllers"
"opp/protocol"
"opp/services/config"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
)
//BulletinController 公告
type ConfigController struct {
controllers.BaseController
}
//GetConfigScore
//@router /score/get [post]
func (this *ConfigController) GetConfigScore() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.GetConfigScoreRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(config.GetConfigScore(header, request))
}
... ...
package models
import (
"fmt"
"time"
"github.com/astaxie/beego/orm"
)
type SysConfig struct {
Id int `orm:"column(id);auto" description:"唯一编号"`
Key string `orm:"column(key);size(50);null" description:"自定义键值 score:评分模式配置"`
Content string `orm:"column(content);size(1000);null" description:"配置内容 json"`
CreateAt time.Time `orm:"column(create_at);type(timestamp);null"`
UpdateAt time.Time `orm:"column(update_at);type(timestamp);null"`
CompanyId int `orm:"column(company_id);null" description:"公司编号"`
}
func (t *SysConfig) TableName() string {
return "sys_config"
}
func init() {
orm.RegisterModel(new(SysConfig))
}
var (
KeyScore = "score"
)
// AddSysConfig insert a new SysConfig into database and returns
// last inserted Id on success.
func AddSysConfig(m *SysConfig) (id int64, err error) {
o := orm.NewOrm()
id, err = o.Insert(m)
return
}
// GetSysConfigById retrieves SysConfig by Id. Returns error if
// Id doesn't exist
func GetSysConfigById(id int) (v *SysConfig, err error) {
o := orm.NewOrm()
v = &SysConfig{Id: id}
if err = o.Read(v); err == nil {
return v, nil
}
return nil, err
}
// UpdateSysConfig updates SysConfig by Id and returns error if
// the record to be updated doesn't exist
func UpdateSysConfigById(m *SysConfig) (err error) {
o := orm.NewOrm()
v := SysConfig{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
}
// DeleteSysConfig deletes SysConfig by Id and returns error if
// the record to be deleted doesn't exist
func DeleteSysConfig(id int) (err error) {
o := orm.NewOrm()
v := SysConfig{Id: id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Delete(&SysConfig{Id: id}); err == nil {
fmt.Println("Number of records deleted in database:", num)
}
}
return
}
func GetSysConfigByCompanyId(cid int, key string) (v *SysConfig, err error) {
o := orm.NewOrm()
sql := "select * from sys_config where `key`=? and company_id=?"
if err = o.Raw(sql, key, cid).QueryRow(&v); err == nil {
return v, nil
}
return nil, err
}
... ...
... ... @@ -39,6 +39,7 @@ const (
ReviewStatusReturn = 2 //退回
ReviewStatusPass = 3 //通过
ReviewStatusSubmit = 4 //提交
ReviewStatusAuditg = 5 //审批中
)
//公开状态
... ...
package protocol
/*GetConfigScore */
type GetConfigScoreRequest struct {
}
type GetConfigScoreResponse struct {
ScoreConfig
}
type ScoreConfig struct {
DiscoveryScore *DiscoveryScore `json:"discoveryScore"`
SumScore *SumScore `json:"-"` //sumScore
BasicScore *ScoreRange `json:"basicScore"`
ExtraScore *ScoreRange `json:"extraScore"`
ValueScore *ScoreRange `json:"valueScore"`
}
//发现评分计算规则
type DiscoveryScore struct {
BasicFactor float64 `json:"basicFactor"` //基础分系数
ExtraFactor float64 `json:"extraFactor"` //附加分系数
ValueFactor float64 `json:"valueFactor"` //价值分系数
}
//总分计算规则
type SumScore struct {
DiscoveryFactor float64 `json:"discoveryFactor"` //发现分系数
CatchFactor float64 `json:"catchFactor"` //抓住分系数
}
type ScoreRange struct {
Min float64 `json:"min"` //最小分
Max float64 `json:"max"` //最大分
Step float64 `json:"step"` //步长
}
... ...
... ... @@ -215,6 +215,14 @@ func init() {
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:ConfigController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ConfigController"],
beego.ControllerComments{
Method: "GetConfigScore",
Router: `/score/get`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:DepartmentController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:DepartmentController"],
beego.ControllerComments{
Method: "Departments",
... ...
... ... @@ -22,6 +22,7 @@ func init() {
beego.NSNamespace("chance", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.ChanceController{})),
beego.NSNamespace("message", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.MessageController{})),
beego.NSNamespace("department", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.DepartmentController{})),
beego.NSNamespace("config", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.ConfigController{})),
)
beego.AddNamespace(nsV1)
... ...
... ... @@ -506,6 +506,13 @@ func ChanceApproveProcess(header *protocol.RequestHeader, chance *models.Chance)
}
}
}
//兼容审批流 待审核1->审批中5
//chanceProcessItemReviewStatus:=func(item *protocol.ProcessItem ) *protocol.ProcessItem {
// if item.ReviewStatus==protocol.ReviewStatusAuditging{
// item.ReviewStatus= protocol.ReviewStatusAuditg
// }
// return item
//}
for i := range processList {
p := processList[i]
item := newProcessItem(p)
... ...
package config
import (
"encoding/json"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"opp/models"
"opp/protocol"
)
func GetConfigScore(header *protocol.RequestHeader, request *protocol.GetConfigScoreRequest) (rsp *protocol.GetConfigScoreResponse, err error) {
var (
scoreConfig *models.SysConfig
)
rsp = &protocol.GetConfigScoreResponse{}
if scoreConfig, err = models.GetSysConfigByCompanyId(int(header.CompanyId), models.KeyScore); err != nil {
log.Error(err.Error())
return
}
if err = json.Unmarshal([]byte(scoreConfig.Content), &rsp); err != nil {
log.Error(err.Error())
return
}
return
}
... ...