正在显示
8 个修改的文件
包含
367 行增加
和
1 行删除
controllers/config.go
0 → 100644
1 | +package controllers | ||
2 | + | ||
3 | +import ( | ||
4 | + "encoding/json" | ||
5 | + "oppmg/common/log" | ||
6 | + "oppmg/protocol" | ||
7 | + "oppmg/services/config" | ||
8 | +) | ||
9 | + | ||
10 | +//BulletinController 公告 | ||
11 | +type ConfigController struct { | ||
12 | + BaseController | ||
13 | +} | ||
14 | + | ||
15 | +//ConfigScore 评分配置模式 | ||
16 | +//@router /configScore [post] | ||
17 | +func (this *ConfigController) ConfigScore() { | ||
18 | + var msg *protocol.ResponseMessage | ||
19 | + defer func() { | ||
20 | + this.ResposeJson(msg) | ||
21 | + }() | ||
22 | + var request *protocol.ConfigScoreRequest | ||
23 | + if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil { | ||
24 | + log.Error("json 解析失败", err) | ||
25 | + msg = protocol.BadRequestParam("1") | ||
26 | + return | ||
27 | + } | ||
28 | + uid := this.GetUserId() | ||
29 | + companyId := this.GetCompanyId() | ||
30 | + if companyId <= 0 { | ||
31 | + log.Debug("companyId:%d err", companyId) | ||
32 | + msg = protocol.BadRequestParam("1") | ||
33 | + return | ||
34 | + } | ||
35 | + if b, m := this.Valid(request); !b { | ||
36 | + msg = m | ||
37 | + return | ||
38 | + } | ||
39 | + rsp, err := config.ConfigScore(uid, companyId, request) | ||
40 | + msg = protocol.NewReturnResponse(rsp, err) | ||
41 | + return | ||
42 | +} | ||
43 | + | ||
44 | +//GetConfigScore 获取评分配置模式 | ||
45 | +//@router /getConfigScore [post] | ||
46 | +func (this *ConfigController) GetConfigScore() { | ||
47 | + var msg *protocol.ResponseMessage | ||
48 | + defer func() { | ||
49 | + this.ResposeJson(msg) | ||
50 | + }() | ||
51 | + var request *protocol.GetConfigScoreRequest | ||
52 | + if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil { | ||
53 | + log.Error("json 解析失败", err) | ||
54 | + msg = protocol.BadRequestParam("1") | ||
55 | + return | ||
56 | + } | ||
57 | + uid := this.GetUserId() | ||
58 | + companyId := this.GetCompanyId() | ||
59 | + if companyId <= 0 { | ||
60 | + log.Debug("companyId:%d err", companyId) | ||
61 | + msg = protocol.BadRequestParam("1") | ||
62 | + return | ||
63 | + } | ||
64 | + if b, m := this.Valid(request); !b { | ||
65 | + msg = m | ||
66 | + return | ||
67 | + } | ||
68 | + rsp, err := config.GetConfigScore(uid, companyId, request) | ||
69 | + msg = protocol.NewReturnResponse(rsp, err) | ||
70 | + return | ||
71 | + | ||
72 | +} |
models/sys_config.go
0 → 100644
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 | +} |
@@ -134,7 +134,7 @@ type TemplateItem struct { | @@ -134,7 +134,7 @@ type TemplateItem struct { | ||
134 | type VisibleObject struct { | 134 | type VisibleObject struct { |
135 | Id int `json:"id"` | 135 | Id int `json:"id"` |
136 | Name string `json:"name"` | 136 | Name string `json:"name"` |
137 | - Type int `json:"type"` //0:指定人员 1:部门 | 137 | + Type int `json:"type"` //0:指定人员 1:部门 2.公司所有人 |
138 | } | 138 | } |
139 | 139 | ||
140 | /*TemplateEditVisible */ | 140 | /*TemplateEditVisible */ |
@@ -20,6 +20,7 @@ type BulletinReleaseRequest struct { | @@ -20,6 +20,7 @@ type BulletinReleaseRequest struct { | ||
20 | //AllowCondition int `json:"allow_condition"` | 20 | //AllowCondition int `json:"allow_condition"` |
21 | QuestionSwitch int `json:"question_switch"` | 21 | QuestionSwitch int `json:"question_switch"` |
22 | Receiver []VisibleObject `json:"receiver"` | 22 | Receiver []VisibleObject `json:"receiver"` |
23 | + SendToAll int `json:"send_to_all"` //所有人 1:是 0:否 | ||
23 | Question Question `json:"question"` | 24 | Question Question `json:"question"` |
24 | Cover Cover `json:"cover"` | 25 | Cover Cover `json:"cover"` |
25 | IsPublish int `json:"is_publish"` //是否直接发布 0:否 1:直接发布 | 26 | IsPublish int `json:"is_publish"` //是否直接发布 0:否 1:直接发布 |
protocol/config.go
0 → 100644
1 | +package protocol | ||
2 | + | ||
3 | +/*ConfigScore 评分配置模式*/ | ||
4 | +type ConfigScoreRequest struct { | ||
5 | + Id int `json:"id"` | ||
6 | + ScoreConfig | ||
7 | +} | ||
8 | +type ScoreConfig struct { | ||
9 | + DiscoveryScore *DiscoveryScore `json:"discoveryScore"` | ||
10 | + SumScore *SumScore `json:"sumScore"` | ||
11 | + BasicScore *ScoreRange `json:"basicScore"` | ||
12 | + ExtraScore *ScoreRange `json:"extraScore"` | ||
13 | + ValueScore *ScoreRange `json:"valueScore"` | ||
14 | +} | ||
15 | +type ConfigScoreResponse struct { | ||
16 | +} | ||
17 | + | ||
18 | +/*GetConfigScore */ | ||
19 | +type GetConfigScoreRequest struct { | ||
20 | +} | ||
21 | +type GetConfigScoreResponse struct { | ||
22 | + ScoreConfig | ||
23 | +} | ||
24 | + | ||
25 | +//发现评分计算规则 | ||
26 | +type DiscoveryScore struct { | ||
27 | + BasicFactor float64 `json:"basicFactor"` //基础分系数 | ||
28 | + ExtraFactor float64 `json:"extraFactor"` //附加分系数 | ||
29 | + ValueFactor float64 `json:"valueFactor"` //价值分系数 | ||
30 | +} | ||
31 | + | ||
32 | +//总分计算规则 | ||
33 | +type SumScore struct { | ||
34 | + DiscoveryFactor float64 `json:"discoveryFactor"` //发现分系数 | ||
35 | + CatchFactor float64 `json:"catchFactor"` //抓住分系数 | ||
36 | +} | ||
37 | +type ScoreRange struct { | ||
38 | + Min float64 `json:"min"` //最小分 | ||
39 | + Max float64 `json:"max"` //最大分 | ||
40 | + Step float64 `json:"step"` //步长 | ||
41 | +} |
@@ -60,6 +60,10 @@ var errmessge ErrorMap = map[string]string{ | @@ -60,6 +60,10 @@ var errmessge ErrorMap = map[string]string{ | ||
60 | "10065": "编码长度最多6个字符", | 60 | "10065": "编码长度最多6个字符", |
61 | //公司相关 | 61 | //公司相关 |
62 | "12001": "未找到公司信息", | 62 | "12001": "未找到公司信息", |
63 | + | ||
64 | + //评分配置相关 | ||
65 | + "12101": "分值范围不符合要求", | ||
66 | + "12102": "评分规则不符合要求", | ||
63 | } | 67 | } |
64 | 68 | ||
65 | //错误码转换 ,兼容需要 | 69 | //错误码转换 ,兼容需要 |
@@ -92,6 +92,10 @@ func init() { | @@ -92,6 +92,10 @@ func init() { | ||
92 | beego.NSNamespace("/my", | 92 | beego.NSNamespace("/my", |
93 | beego.NSRouter("/reset_password", &controllers.MyController{}, "post:ResetPassword"), | 93 | beego.NSRouter("/reset_password", &controllers.MyController{}, "post:ResetPassword"), |
94 | ), | 94 | ), |
95 | + beego.NSNamespace("/config", | ||
96 | + beego.NSRouter("/score", &controllers.ConfigController{}, "post:ConfigScore"), | ||
97 | + beego.NSRouter("/score/get", &controllers.ConfigController{}, "post:GetConfigScore"), | ||
98 | + ), | ||
95 | ) | 99 | ) |
96 | 100 | ||
97 | nsAuth := beego.NewNamespace("/auth", | 101 | nsAuth := beego.NewNamespace("/auth", |
services/config/config.go
0 → 100644
1 | +package config | ||
2 | + | ||
3 | +import ( | ||
4 | + "encoding/json" | ||
5 | + "github.com/astaxie/beego/orm" | ||
6 | + "oppmg/common/log" | ||
7 | + "oppmg/models" | ||
8 | + "oppmg/protocol" | ||
9 | + "oppmg/utils" | ||
10 | + "time" | ||
11 | +) | ||
12 | + | ||
13 | +//评分配置模式 | ||
14 | +func ConfigScore(uid, companyId int64, request *protocol.ConfigScoreRequest) (rsp *protocol.ConfigScoreResponse, err error) { | ||
15 | + var ( | ||
16 | + scoreConfig *models.SysConfig | ||
17 | + mapUpdate = make(map[string]interface{}) | ||
18 | + data []byte | ||
19 | + ) | ||
20 | + rsp = &protocol.ConfigScoreResponse{} | ||
21 | + if data, err = json.Marshal(request.ScoreConfig); err != nil { | ||
22 | + log.Error(err.Error()) | ||
23 | + return | ||
24 | + } | ||
25 | + | ||
26 | + //更新 | ||
27 | + if request.Id > 0 { | ||
28 | + if scoreConfig, err = models.GetSysConfigById(request.Id); err != nil { | ||
29 | + log.Error(err.Error()) | ||
30 | + return | ||
31 | + } | ||
32 | + if scoreConfig.CompanyId != int(companyId) { | ||
33 | + err = protocol.NewErrWithMessage("10027") //无权限 | ||
34 | + return | ||
35 | + } | ||
36 | + goto UPDATE | ||
37 | + //更新 | ||
38 | + return | ||
39 | + } | ||
40 | + if !(checkScoreRange(request.BasicScore) && checkScoreRange(request.ExtraScore) && checkScoreRange(request.ValueScore)) { | ||
41 | + err = protocol.NewErrWithMessage("12101") | ||
42 | + return | ||
43 | + } | ||
44 | + if request.DiscoveryScore != nil { | ||
45 | + c := request.DiscoveryScore | ||
46 | + if !(checkFactor(c.BasicFactor) && checkFactor(c.ExtraFactor) && checkFactor(c.ValueFactor)) { | ||
47 | + err = protocol.NewErrWithMessage("12102") | ||
48 | + return | ||
49 | + } | ||
50 | + } else { | ||
51 | + err = protocol.NewErrWithMessage("12102") | ||
52 | + return | ||
53 | + } | ||
54 | + if request.SumScore != nil { | ||
55 | + if !(checkSumScoreFactor(request.SumScore.DiscoveryFactor) && checkSumScoreFactor(request.SumScore.CatchFactor)) { | ||
56 | + err = protocol.NewErrWithMessage("12102") | ||
57 | + return | ||
58 | + } | ||
59 | + } else { | ||
60 | + err = protocol.NewErrWithMessage("12102") | ||
61 | + return | ||
62 | + } | ||
63 | + if scoreConfig, err = models.GetSysConfigByCompanyId(int(companyId), models.KeyScore); err != nil { | ||
64 | + if err == orm.ErrNoRows { | ||
65 | + err = nil | ||
66 | + //新增一个配置 | ||
67 | + scoreConfig = &models.SysConfig{ | ||
68 | + Key: models.KeyScore, | ||
69 | + Content: string(data), | ||
70 | + CreateAt: time.Now(), | ||
71 | + UpdateAt: time.Now(), | ||
72 | + CompanyId: int(companyId), | ||
73 | + } | ||
74 | + if _, err = models.AddSysConfig(scoreConfig); err != nil { | ||
75 | + log.Error(err.Error()) | ||
76 | + return | ||
77 | + } | ||
78 | + return | ||
79 | + } | ||
80 | + log.Error(err.Error()) | ||
81 | + return | ||
82 | + } else { | ||
83 | + goto UPDATE | ||
84 | + } | ||
85 | +UPDATE: | ||
86 | + { | ||
87 | + mapUpdate["Content"] = string(data) | ||
88 | + mapUpdate["UpdateAt"] = time.Now() | ||
89 | + if err = utils.UpdateTableByMap(scoreConfig, mapUpdate); err != nil { | ||
90 | + log.Error(err.Error()) | ||
91 | + return | ||
92 | + } | ||
93 | + } | ||
94 | + return | ||
95 | +} | ||
96 | + | ||
97 | +//获取评分配置 | ||
98 | +func GetConfigScore(uid, companyId int64, request *protocol.GetConfigScoreRequest) (rsp *protocol.GetConfigScoreResponse, err error) { | ||
99 | + var ( | ||
100 | + scoreConfig *models.SysConfig | ||
101 | + ) | ||
102 | + rsp = &protocol.GetConfigScoreResponse{} | ||
103 | + if scoreConfig, err = models.GetSysConfigByCompanyId(int(companyId), models.KeyScore); err != nil { | ||
104 | + log.Error(err.Error()) | ||
105 | + return | ||
106 | + } | ||
107 | + if err = json.Unmarshal([]byte(scoreConfig.Content), &rsp); err != nil { | ||
108 | + log.Error(err.Error()) | ||
109 | + return | ||
110 | + } | ||
111 | + return | ||
112 | +} | ||
113 | + | ||
114 | +//检查分值范围 | ||
115 | +func checkScoreRange(scoreRange *protocol.ScoreRange) (result bool) { | ||
116 | + //err = protocol.NewErrWithMessage("12101") | ||
117 | + result = false | ||
118 | + if scoreRange.Min < 0 { | ||
119 | + return | ||
120 | + } | ||
121 | + if scoreRange.Min >= scoreRange.Max { | ||
122 | + return | ||
123 | + } | ||
124 | + if scoreRange.Step < 0.1 { | ||
125 | + return | ||
126 | + } | ||
127 | + if scoreRange.Step < scoreRange.Min || scoreRange.Step > scoreRange.Max { | ||
128 | + return | ||
129 | + } | ||
130 | + result = true | ||
131 | + //err =nil | ||
132 | + return | ||
133 | +} | ||
134 | + | ||
135 | +//检查发现分计算规则 | ||
136 | +func checkFactor(factor float64) (result bool) { | ||
137 | + result = false | ||
138 | + //err = protocol.NewErrWithMessage("12102") | ||
139 | + if factor < 0.1 || factor > 1 { | ||
140 | + return | ||
141 | + } | ||
142 | + result = true | ||
143 | + //err = nil | ||
144 | + return | ||
145 | +} | ||
146 | + | ||
147 | +//检查总分计算规则 | ||
148 | +func checkSumScoreFactor(factor float64) (result bool) { | ||
149 | + result = false | ||
150 | + //err = protocol.NewErrWithMessage("12102") | ||
151 | + if factor < 0.1 || factor > 10 { | ||
152 | + return | ||
153 | + } | ||
154 | + result = true | ||
155 | + //err = nil | ||
156 | + return | ||
157 | +} |
-
请 注册 或 登录 后发表评论