作者 yangfu

模板删除修改

@@ -34,6 +34,10 @@ func init() { @@ -34,6 +34,10 @@ func init() {
34 orm.RegisterModel(new(AuditForm)) 34 orm.RegisterModel(new(AuditForm))
35 } 35 }
36 36
  37 +var (
  38 + DeleteAuditFormBy = `delete FROM audit_form where audit_template_id=? and company_id=?`
  39 +)
  40 +
37 // AddAuditForm insert a new AuditForm into database and returns 41 // AddAuditForm insert a new AuditForm into database and returns
38 // last inserted Id on success. 42 // last inserted Id on success.
39 func AddAuditForm(m *AuditForm) (id int64, err error) { 43 func AddAuditForm(m *AuditForm) (id int64, err error) {
@@ -116,6 +116,7 @@ type TemplateList struct { @@ -116,6 +116,7 @@ type TemplateList struct {
116 Name string `json:"name"` 116 Name string `json:"name"`
117 Icon string `json:"icon"` 117 Icon string `json:"icon"`
118 Code string `json:"code"` 118 Code string `json:"code"`
  119 + Sort int `json:"sort"`
119 Templates []*TemplateItem `json:"templates"` 120 Templates []*TemplateItem `json:"templates"`
120 } 121 }
121 122
@@ -59,6 +59,7 @@ var errmessge ErrorMap = map[string]string{ @@ -59,6 +59,7 @@ var errmessge ErrorMap = map[string]string{
59 "10063": "该分类已被使用无法禁用", 59 "10063": "该分类已被使用无法禁用",
60 "10064": "编码已存在", 60 "10064": "编码已存在",
61 "10065": "编码长度最多6个字符", 61 "10065": "编码长度最多6个字符",
  62 + "10067": "一级分类不存在",
62 //公司相关 63 //公司相关
63 "12001": "未找到公司信息", 64 "12001": "未找到公司信息",
64 65
@@ -209,6 +209,7 @@ func TemplateList(uid, companyId int64, request *protocol.TemplateListRequest) ( @@ -209,6 +209,7 @@ func TemplateList(uid, companyId int64, request *protocol.TemplateListRequest) (
209 Name: t.Name, 209 Name: t.Name,
210 Icon: t.Icon, 210 Icon: t.Icon,
211 Code: t.Code, 211 Code: t.Code,
  212 + Sort: t.SortNum,
212 } 213 }
213 rsp.List = append(rsp.List, item) 214 rsp.List = append(rsp.List, item)
214 if templates, err = models.GetAuditTemplateByTypeId(t.Id); err != nil { 215 if templates, err = models.GetAuditTemplateByTypeId(t.Id); err != nil {
@@ -336,6 +337,7 @@ func TemplateGet(uid, companyId int64, request *protocol.TemplateGetRequest) (rs @@ -336,6 +337,7 @@ func TemplateGet(uid, companyId int64, request *protocol.TemplateGetRequest) (rs
336 Name: template.Name, 337 Name: template.Name,
337 Doc: template.Doc, 338 Doc: template.Doc,
338 Icon: template.Icon, 339 Icon: template.Icon,
  340 + Code: template.Code,
339 } 341 }
340 rsp.Example = template.Example 342 rsp.Example = template.Example
341 343
@@ -385,6 +387,11 @@ func TemplateDelete(uid, companyId int64, request *protocol.TemplateDeleteReques @@ -385,6 +387,11 @@ func TemplateDelete(uid, companyId int64, request *protocol.TemplateDeleteReques
385 log.Error(err.Error()) 387 log.Error(err.Error())
386 return 388 return
387 } 389 }
  390 + orm := orm2.NewOrm()
  391 + if err = utils.ExecuteSQLWithOrmer(orm, models.DeleteAuditFormBy, request.TemplateId, companyId); err != nil {
  392 + log.Error(err.Error())
  393 + return
  394 + }
388 rsp = &protocol.TemplateDeleteResponse{} 395 rsp = &protocol.TemplateDeleteResponse{}
389 return 396 return
390 } 397 }
@@ -473,11 +480,15 @@ func TemplateDeleteCategory(uid, companyId int64, request *protocol.TemplateDele @@ -473,11 +480,15 @@ func TemplateDeleteCategory(uid, companyId int64, request *protocol.TemplateDele
473 var ( 480 var (
474 chanceType *models.ChanceType 481 chanceType *models.ChanceType
475 num int 482 num int
476 - sql1 string = `select count(0) from from audit_template where chance_type_id =? limit 1` 483 + sql1 string = `select count(0) from audit_template where chance_type_id =? limit 1`
477 sql2 string = `select count(0) from chance where chance_type_id = ? limit 1` 484 sql2 string = `select count(0) from chance where chance_type_id = ? limit 1`
478 ) 485 )
  486 + rsp = &protocol.TemplateDeleteCategoryResponse{}
479 if chanceType, err = models.GetChanceTypeById(request.ChanceTypeId); err != nil { 487 if chanceType, err = models.GetChanceTypeById(request.ChanceTypeId); err != nil {
480 log.Error(err.Error()) 488 log.Error(err.Error())
  489 + if err == orm2.ErrNoRows {
  490 + err = protocol.NewErrWithMessage("10067")
  491 + }
481 return 492 return
482 } 493 }
483 if chanceType.CompanyId != int(companyId) { 494 if chanceType.CompanyId != int(companyId) {
@@ -501,7 +512,6 @@ func TemplateDeleteCategory(uid, companyId int64, request *protocol.TemplateDele @@ -501,7 +512,6 @@ func TemplateDeleteCategory(uid, companyId int64, request *protocol.TemplateDele
501 log.Error(err.Error()) 512 log.Error(err.Error())
502 return 513 return
503 } 514 }
504 - rsp = &protocol.TemplateDeleteCategoryResponse{}  
505 return 515 return
506 } 516 }
507 517