作者 tangxvhui

添加校验

... ... @@ -73,6 +73,10 @@ func (this *TemplateController) TemplateAdd() {
if len(request.Videos) == 0 {
request.Videos = make([]string, 0)
}
if err := checkSelfCheckData(request.SelfCheck); err != nil {
msg = protocol.NewReturnResponse(nil, err)
return
}
request.Videos = arrayFilter(request.Videos, "")
rsp, err := audit.TemplateAdd(uid, companyId, request)
msg = protocol.NewReturnResponse(rsp, err)
... ... @@ -128,6 +132,12 @@ func (this *TemplateController) TemplateUpdate() {
} else {
request.Videos = arrayFilter(request.Videos, "")
}
if err := checkSelfCheckData(request.SelfCheck); err != nil {
msg = protocol.NewReturnResponse(nil, err)
return
}
rsp, err := audit.TemplateUpdate(uid, companyId, request)
msg = protocol.NewReturnResponse(rsp, err)
return
... ... @@ -414,3 +424,19 @@ func arrayFilter(arr1 []string, s string) (rsp []string) {
}
return
}
func checkSelfCheckData(data []protocol.TemplateSelfCheck) error {
var cnt int
for _, v := range data {
s := []rune(v.Title)
if len(s) == 0 || len(s) > 50 {
return protocol.NewErrWithMessage("10127")
}
cnt++
}
if cnt > 30 {
return protocol.NewErrWithMessage("10128")
}
return nil
}
... ...
... ... @@ -124,6 +124,8 @@ var errmessge ErrorMap = map[string]string{
"10124": "公司未启用该模块",
"10125": "参与范围名称不能重复",
"10126": "被转移人员不能为空",
"10127": "自查内容维度名称最多输入50个字符",
"10128": "自查内容维度最多输入30个字段",
}
//错误码转换 ,兼容需要
... ...