作者 tangxvhui

Merge branch 'dev' into test

... ... @@ -73,6 +73,13 @@ func (this *TemplateController) TemplateAdd() {
if len(request.Videos) == 0 {
request.Videos = make([]string, 0)
}
if len(request.SelfCheck) > 0 {
err := auditFlowMustActionTypeOr(request.AuditFlowConfig)
if err != nil {
msg = protocol.NewReturnResponse(nil, err)
return
}
}
if err := checkSelfCheckData(request.SelfCheck); err != nil {
msg = protocol.NewReturnResponse(nil, err)
return
... ... @@ -133,6 +140,13 @@ func (this *TemplateController) TemplateUpdate() {
request.Videos = arrayFilter(request.Videos, "")
}
if len(request.SelfCheck) > 0 {
err := auditFlowMustActionTypeOr(request.AuditFlowConfig)
if err != nil {
msg = protocol.NewReturnResponse(nil, err)
return
}
}
if err := checkSelfCheckData(request.SelfCheck); err != nil {
msg = protocol.NewReturnResponse(nil, err)
return
... ... @@ -425,18 +439,48 @@ func arrayFilter(arr1 []string, s string) (rsp []string) {
return
}
//checkSelfCheckData 校验自查内容数据
func checkSelfCheckData(data []protocol.TemplateSelfCheck) error {
var cnt int
for _, v := range data {
var (
cnt int
)
titleMap := make(map[string]int)
for i, v := range data {
s := []rune(v.Title)
if len(s) == 0 || len(s) > 50 {
return protocol.NewErrWithMessage("10127")
}
if _, ok := titleMap[v.Title]; ok {
return protocol.NewErrWithMessage("10130")
} else {
titleMap[v.Title] = 1
}
cnt++
childTitleMap := make(map[string]int)
for _, vv := range data[i].Child {
ss := []rune(vv.Title)
if len(ss) == 0 || len(ss) > 50 {
return protocol.NewErrWithMessage("10127")
}
if _, ok := childTitleMap[vv.Title]; ok {
return protocol.NewErrWithMessage("10130")
} else {
titleMap[vv.Title] = 1
}
cnt++
}
}
if cnt > 30 {
return protocol.NewErrWithMessage("10128")
}
return nil
}
func auditFlowMustActionTypeOr(auditflow protocol.AuditFlowConfig) error {
for _, v := range auditflow.ProcessConfig {
if v.AcitonType != models.ActionTypeOr {
return protocol.NewErrWithMessage("10129")
}
}
return nil
}
... ...
... ... @@ -126,6 +126,8 @@ var errmessge ErrorMap = map[string]string{
"10126": "被转移人员不能为空",
"10127": "自查内容维度名称最多输入50个字符",
"10128": "自查内容维度最多输入30个字段",
"10129": "存在自查内容时只能进行或签设置",
"10130": "同一级的自查内容不能重复",
}
//错误码转换 ,兼容需要
... ...
... ... @@ -131,11 +131,13 @@ func TemplateAdd(uid, companyId int64, request *protocol.TemplateAddRequest) (rs
}
}
//添加自查内容
err = addSelfCheckData(templateId, request.SelfCheck, orm)
if err != nil {
log.Error("模板设置,添加自查内容失败,err:%s", err)
orm.Rollback()
return nil, protocol.NewErrWithMessage("1")
if len(request.SelfCheck) > 0 {
err = addSelfCheckData(templateId, request.SelfCheck, orm)
if err != nil {
log.Error("模板设置,添加自查内容失败,err:%s", err)
orm.Rollback()
return nil, protocol.NewErrWithMessage("1")
}
}
orm.Commit()
rsp = &protocol.TemplateAddResponse{}
... ... @@ -208,6 +210,18 @@ func editSelfCheckData(templateId int64, data []protocol.TemplateSelfCheck, om o
return nil
}
//editSelfCheckData2 编辑自查内容
func editSelfCheckData2(templateId int64, data []protocol.TemplateSelfCheck, om orm2.Ormer) error {
// var (
// updateId []int64
// deleteId []int64
// updateSelfCheck []models.AuditCheck
// newSelfCheckData []models.AuditCheck
// )
return nil
}
func getSelfCheckData(templateId int64) []protocol.TemplateSelfCheck {
var (
data []protocol.TemplateSelfCheck
... ... @@ -366,12 +380,15 @@ func TemplateUpdate(uid, companyId int64, request *protocol.TemplateUpdateReques
}
}
}
err = editSelfCheckData(template.Id, request.SelfCheck, orm)
if err != nil {
log.Error("更新audit_check数据失败:err:%s", err)
orm.Rollback()
return rsp, protocol.NewErrWithMessage("1")
if len(request.SelfCheck) > 0 {
err = editSelfCheckData(template.Id, request.SelfCheck, orm)
if err != nil {
log.Error("更新audit_check数据失败:err:%s", err)
orm.Rollback()
return rsp, protocol.NewErrWithMessage("1")
}
}
orm.Commit()
rsp = &protocol.TemplateUpdateResponse{}
return
... ...