作者 yangfu

模板删除修改

... ... @@ -34,6 +34,10 @@ func init() {
orm.RegisterModel(new(AuditForm))
}
var (
DeleteAuditFormBy = `delete FROM audit_form where audit_template_id=? and company_id=?`
)
// AddAuditForm insert a new AuditForm into database and returns
// last inserted Id on success.
func AddAuditForm(m *AuditForm) (id int64, err error) {
... ...
... ... @@ -116,6 +116,7 @@ type TemplateList struct {
Name string `json:"name"`
Icon string `json:"icon"`
Code string `json:"code"`
Sort int `json:"sort"`
Templates []*TemplateItem `json:"templates"`
}
... ...
... ... @@ -59,6 +59,7 @@ var errmessge ErrorMap = map[string]string{
"10063": "该分类已被使用无法禁用",
"10064": "编码已存在",
"10065": "编码长度最多6个字符",
"10067": "一级分类不存在",
//公司相关
"12001": "未找到公司信息",
... ...
... ... @@ -209,6 +209,7 @@ func TemplateList(uid, companyId int64, request *protocol.TemplateListRequest) (
Name: t.Name,
Icon: t.Icon,
Code: t.Code,
Sort: t.SortNum,
}
rsp.List = append(rsp.List, item)
if templates, err = models.GetAuditTemplateByTypeId(t.Id); err != nil {
... ... @@ -336,6 +337,7 @@ func TemplateGet(uid, companyId int64, request *protocol.TemplateGetRequest) (rs
Name: template.Name,
Doc: template.Doc,
Icon: template.Icon,
Code: template.Code,
}
rsp.Example = template.Example
... ... @@ -385,6 +387,11 @@ func TemplateDelete(uid, companyId int64, request *protocol.TemplateDeleteReques
log.Error(err.Error())
return
}
orm := orm2.NewOrm()
if err = utils.ExecuteSQLWithOrmer(orm, models.DeleteAuditFormBy, request.TemplateId, companyId); err != nil {
log.Error(err.Error())
return
}
rsp = &protocol.TemplateDeleteResponse{}
return
}
... ... @@ -473,11 +480,15 @@ func TemplateDeleteCategory(uid, companyId int64, request *protocol.TemplateDele
var (
chanceType *models.ChanceType
num int
sql1 string = `select count(0) from from audit_template where chance_type_id =? limit 1`
sql1 string = `select count(0) from audit_template where chance_type_id =? limit 1`
sql2 string = `select count(0) from chance where chance_type_id = ? limit 1`
)
rsp = &protocol.TemplateDeleteCategoryResponse{}
if chanceType, err = models.GetChanceTypeById(request.ChanceTypeId); err != nil {
log.Error(err.Error())
if err == orm2.ErrNoRows {
err = protocol.NewErrWithMessage("10067")
}
return
}
if chanceType.CompanyId != int(companyId) {
... ... @@ -501,7 +512,6 @@ func TemplateDeleteCategory(uid, companyId int64, request *protocol.TemplateDele
log.Error(err.Error())
return
}
rsp = &protocol.TemplateDeleteCategoryResponse{}
return
}
... ...