作者 yangfu

评分配置修改

  1 +package v1
  2 +
  3 +import (
  4 + "encoding/json"
  5 + "opp/controllers"
  6 + "opp/protocol"
  7 + "opp/services/config"
  8 +
  9 + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
  10 +)
  11 +
  12 +//BulletinController 公告
  13 +type ConfigController struct {
  14 + controllers.BaseController
  15 +}
  16 +
  17 +//GetConfigScore
  18 +//@router /score/get [post]
  19 +func (this *ConfigController) GetConfigScore() {
  20 + var msg *protocol.ResponseMessage
  21 + defer func() {
  22 + this.Resp(msg)
  23 + }()
  24 + var request *protocol.GetConfigScoreRequest
  25 + if err := json.Unmarshal(this.ByteBody, &request); err != nil {
  26 + log.Error(err)
  27 + msg = protocol.BadRequestParam(1)
  28 + return
  29 + }
  30 + if b, m := this.Valid(request); !b {
  31 + msg = m
  32 + return
  33 + }
  34 + header := controllers.GetRequestHeader(this.Ctx)
  35 + msg = protocol.NewReturnResponse(config.GetConfigScore(header, request))
  36 +}
  1 +package models
  2 +
  3 +import (
  4 + "fmt"
  5 + "time"
  6 +
  7 + "github.com/astaxie/beego/orm"
  8 +)
  9 +
  10 +type SysConfig struct {
  11 + Id int `orm:"column(id);auto" description:"唯一编号"`
  12 + Key string `orm:"column(key);size(50);null" description:"自定义键值 score:评分模式配置"`
  13 + Content string `orm:"column(content);size(1000);null" description:"配置内容 json"`
  14 + CreateAt time.Time `orm:"column(create_at);type(timestamp);null"`
  15 + UpdateAt time.Time `orm:"column(update_at);type(timestamp);null"`
  16 + CompanyId int `orm:"column(company_id);null" description:"公司编号"`
  17 +}
  18 +
  19 +func (t *SysConfig) TableName() string {
  20 + return "sys_config"
  21 +}
  22 +
  23 +func init() {
  24 + orm.RegisterModel(new(SysConfig))
  25 +}
  26 +
  27 +var (
  28 + KeyScore = "score"
  29 +)
  30 +
  31 +// AddSysConfig insert a new SysConfig into database and returns
  32 +// last inserted Id on success.
  33 +func AddSysConfig(m *SysConfig) (id int64, err error) {
  34 + o := orm.NewOrm()
  35 + id, err = o.Insert(m)
  36 + return
  37 +}
  38 +
  39 +// GetSysConfigById retrieves SysConfig by Id. Returns error if
  40 +// Id doesn't exist
  41 +func GetSysConfigById(id int) (v *SysConfig, err error) {
  42 + o := orm.NewOrm()
  43 + v = &SysConfig{Id: id}
  44 + if err = o.Read(v); err == nil {
  45 + return v, nil
  46 + }
  47 + return nil, err
  48 +}
  49 +
  50 +// UpdateSysConfig updates SysConfig by Id and returns error if
  51 +// the record to be updated doesn't exist
  52 +func UpdateSysConfigById(m *SysConfig) (err error) {
  53 + o := orm.NewOrm()
  54 + v := SysConfig{Id: m.Id}
  55 + // ascertain id exists in the database
  56 + if err = o.Read(&v); err == nil {
  57 + var num int64
  58 + if num, err = o.Update(m); err == nil {
  59 + fmt.Println("Number of records updated in database:", num)
  60 + }
  61 + }
  62 + return
  63 +}
  64 +
  65 +// DeleteSysConfig deletes SysConfig by Id and returns error if
  66 +// the record to be deleted doesn't exist
  67 +func DeleteSysConfig(id int) (err error) {
  68 + o := orm.NewOrm()
  69 + v := SysConfig{Id: id}
  70 + // ascertain id exists in the database
  71 + if err = o.Read(&v); err == nil {
  72 + var num int64
  73 + if num, err = o.Delete(&SysConfig{Id: id}); err == nil {
  74 + fmt.Println("Number of records deleted in database:", num)
  75 + }
  76 + }
  77 + return
  78 +}
  79 +
  80 +func GetSysConfigByCompanyId(cid int, key string) (v *SysConfig, err error) {
  81 + o := orm.NewOrm()
  82 + sql := "select * from sys_config where `key`=? and company_id=?"
  83 + if err = o.Raw(sql, key, cid).QueryRow(&v); err == nil {
  84 + return v, nil
  85 + }
  86 + return nil, err
  87 +}
@@ -39,6 +39,7 @@ const ( @@ -39,6 +39,7 @@ const (
39 ReviewStatusReturn = 2 //退回 39 ReviewStatusReturn = 2 //退回
40 ReviewStatusPass = 3 //通过 40 ReviewStatusPass = 3 //通过
41 ReviewStatusSubmit = 4 //提交 41 ReviewStatusSubmit = 4 //提交
  42 + ReviewStatusAuditg = 5 //审批中
42 ) 43 )
43 44
44 //公开状态 45 //公开状态
  1 +package protocol
  2 +
  3 +/*GetConfigScore */
  4 +type GetConfigScoreRequest struct {
  5 +}
  6 +type GetConfigScoreResponse struct {
  7 + ScoreConfig
  8 +}
  9 +
  10 +type ScoreConfig struct {
  11 + DiscoveryScore *DiscoveryScore `json:"discoveryScore"`
  12 + SumScore *SumScore `json:"-"` //sumScore
  13 + BasicScore *ScoreRange `json:"basicScore"`
  14 + ExtraScore *ScoreRange `json:"extraScore"`
  15 + ValueScore *ScoreRange `json:"valueScore"`
  16 +}
  17 +
  18 +//发现评分计算规则
  19 +type DiscoveryScore struct {
  20 + BasicFactor float64 `json:"basicFactor"` //基础分系数
  21 + ExtraFactor float64 `json:"extraFactor"` //附加分系数
  22 + ValueFactor float64 `json:"valueFactor"` //价值分系数
  23 +}
  24 +
  25 +//总分计算规则
  26 +type SumScore struct {
  27 + DiscoveryFactor float64 `json:"discoveryFactor"` //发现分系数
  28 + CatchFactor float64 `json:"catchFactor"` //抓住分系数
  29 +}
  30 +type ScoreRange struct {
  31 + Min float64 `json:"min"` //最小分
  32 + Max float64 `json:"max"` //最大分
  33 + Step float64 `json:"step"` //步长
  34 +}
@@ -215,6 +215,14 @@ func init() { @@ -215,6 +215,14 @@ func init() {
215 MethodParams: param.Make(), 215 MethodParams: param.Make(),
216 Params: nil}) 216 Params: nil})
217 217
  218 + beego.GlobalControllerRouter["opp/controllers/v1:ConfigController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ConfigController"],
  219 + beego.ControllerComments{
  220 + Method: "GetConfigScore",
  221 + Router: `/score/get`,
  222 + AllowHTTPMethods: []string{"post"},
  223 + MethodParams: param.Make(),
  224 + Params: nil})
  225 +
218 beego.GlobalControllerRouter["opp/controllers/v1:DepartmentController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:DepartmentController"], 226 beego.GlobalControllerRouter["opp/controllers/v1:DepartmentController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:DepartmentController"],
219 beego.ControllerComments{ 227 beego.ControllerComments{
220 Method: "Departments", 228 Method: "Departments",
@@ -22,6 +22,7 @@ func init() { @@ -22,6 +22,7 @@ func init() {
22 beego.NSNamespace("chance", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.ChanceController{})), 22 beego.NSNamespace("chance", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.ChanceController{})),
23 beego.NSNamespace("message", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.MessageController{})), 23 beego.NSNamespace("message", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.MessageController{})),
24 beego.NSNamespace("department", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.DepartmentController{})), 24 beego.NSNamespace("department", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.DepartmentController{})),
  25 + beego.NSNamespace("config", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.ConfigController{})),
25 ) 26 )
26 beego.AddNamespace(nsV1) 27 beego.AddNamespace(nsV1)
27 28
@@ -506,6 +506,13 @@ func ChanceApproveProcess(header *protocol.RequestHeader, chance *models.Chance) @@ -506,6 +506,13 @@ func ChanceApproveProcess(header *protocol.RequestHeader, chance *models.Chance)
506 } 506 }
507 } 507 }
508 } 508 }
  509 + //兼容审批流 待审核1->审批中5
  510 + //chanceProcessItemReviewStatus:=func(item *protocol.ProcessItem ) *protocol.ProcessItem {
  511 + // if item.ReviewStatus==protocol.ReviewStatusAuditging{
  512 + // item.ReviewStatus= protocol.ReviewStatusAuditg
  513 + // }
  514 + // return item
  515 + //}
509 for i := range processList { 516 for i := range processList {
510 p := processList[i] 517 p := processList[i]
511 item := newProcessItem(p) 518 item := newProcessItem(p)
  1 +package config
  2 +
  3 +import (
  4 + "encoding/json"
  5 + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
  6 + "opp/models"
  7 + "opp/protocol"
  8 +)
  9 +
  10 +func GetConfigScore(header *protocol.RequestHeader, request *protocol.GetConfigScoreRequest) (rsp *protocol.GetConfigScoreResponse, err error) {
  11 + var (
  12 + scoreConfig *models.SysConfig
  13 + )
  14 + rsp = &protocol.GetConfigScoreResponse{}
  15 + if scoreConfig, err = models.GetSysConfigByCompanyId(int(header.CompanyId), models.KeyScore); err != nil {
  16 + log.Error(err.Error())
  17 + return
  18 + }
  19 + if err = json.Unmarshal([]byte(scoreConfig.Content), &rsp); err != nil {
  20 + log.Error(err.Error())
  21 + return
  22 + }
  23 + return
  24 +}