...
|
...
|
@@ -297,6 +297,111 @@ func TemplateEditSort(uid, companyId int64, request *protocol.TemplateEditSortRe |
|
|
return
|
|
|
}
|
|
|
|
|
|
//获取模板详情
|
|
|
func TemplateGet(uid, companyId int64, request *protocol.TemplateGetRequest) (rsp *protocol.TemplateGetResponse, err error) {
|
|
|
var (
|
|
|
template *models.AuditTemplate
|
|
|
auditForm []*models.AuditForm
|
|
|
)
|
|
|
rsp = &protocol.TemplateGetResponse{}
|
|
|
if template, err = models.GetAuditTemplateById(int64(request.Id)); err != nil {
|
|
|
log.Error("template_id:%v 不存在 ,err:%v", request.Id, err.Error())
|
|
|
return
|
|
|
}
|
|
|
|
|
|
{
|
|
|
rsp.Template = protocol.Template{
|
|
|
Id: template.Id,
|
|
|
ChanceTypeId: template.ChanceTypeId,
|
|
|
Name: template.Name,
|
|
|
Doc: template.Doc,
|
|
|
Icon: template.Icon,
|
|
|
}
|
|
|
rsp.Example = template.Example
|
|
|
|
|
|
if auditForm, err = models.GetAuditFormByTemplateId(int(template.Id)); err != nil {
|
|
|
if err == sql.ErrNoRows {
|
|
|
err = nil
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
for i := range auditForm {
|
|
|
input := auditForm[i]
|
|
|
rsp.Template.InputList = append(rsp.Template.InputList, &protocol.InputElement{
|
|
|
Id: input.Id,
|
|
|
Sort: input.SortNum,
|
|
|
Lable: input.InputType,
|
|
|
Required: int(input.Required),
|
|
|
SectionType: input.Section,
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//模板删除
|
|
|
func TemplateDelete(uid, companyId int64, request *protocol.TemplateDeleteRequest) (rsp *protocol.TemplateDeleteResponse, err error) {
|
|
|
var (
|
|
|
template *models.AuditTemplate
|
|
|
num int
|
|
|
sql1 string = `select count(0) from chance where chance_type_id = ? limit 1`
|
|
|
)
|
|
|
if template, err = models.GetAuditTemplateById(int64(request.TemplateId)); err != nil {
|
|
|
log.Error(err.Error())
|
|
|
return
|
|
|
}
|
|
|
if template.CompanyId != int(companyId) {
|
|
|
err = protocol.NewErrWithMessage("10027")
|
|
|
return
|
|
|
}
|
|
|
//2.判断是否有对应已经发布的机会
|
|
|
if err = utils.ExecuteQueryOne(&num, sql1, request.TemplateId); err == nil && num > 0 {
|
|
|
err = protocol.NewErrWithMessage("10062")
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//删除数据
|
|
|
if err = models.DeleteAuditTemplate(int64(request.TemplateId)); err != nil {
|
|
|
log.Error(err.Error())
|
|
|
return
|
|
|
}
|
|
|
rsp = &protocol.TemplateDeleteResponse{}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//模板启用
|
|
|
func TemplateEditEnable(uid, companyId int64, request *protocol.TemplateEditEnableRequest) (rsp *protocol.TemplateEditEnableResponse, err error) {
|
|
|
var (
|
|
|
template *models.AuditTemplate
|
|
|
num int
|
|
|
sql1 string = `select count(0) from chance where chance_type_id = ? limit 1`
|
|
|
)
|
|
|
if template, err = models.GetAuditTemplateById(int64(request.TemplateId)); err != nil {
|
|
|
log.Error(err.Error())
|
|
|
return
|
|
|
}
|
|
|
if template.EnableStatus == request.Enabled {
|
|
|
return
|
|
|
}
|
|
|
if template.CompanyId != int(companyId) {
|
|
|
err = protocol.NewErrWithMessage("10027")
|
|
|
return
|
|
|
}
|
|
|
//2.判断是否有对应已经发布的机会
|
|
|
if request.Enabled == 0 {
|
|
|
if err = utils.ExecuteQueryOne(&num, sql1, request.TemplateId); err == nil && num > 0 {
|
|
|
err = protocol.NewErrWithMessage("10063")
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
rsp = &protocol.TemplateEditEnableResponse{}
|
|
|
if err = utils.UpdateTableByMap(template, map[string]interface{}{"EnableStatus": request.Enabled}); err != nil {
|
|
|
log.Error(err.Error())
|
|
|
return
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//操作一级分类
|
|
|
func TemplateOperateCategory(uid, companyId int64, request *protocol.TemplateOperateCategoryRequest) (rsp *protocol.TemplateOperateCategoryResponse, err error) {
|
|
|
var (
|
...
|
...
|
@@ -312,7 +417,7 @@ func TemplateOperateCategory(uid, companyId int64, request *protocol.TemplateOpe |
|
|
err = protocol.NewErrWithMessage("10027")
|
|
|
log.Error("template_id:%v companyId:%v want:%v not equal.", request.Id, companyId, chanceType.CompanyId)
|
|
|
}
|
|
|
if err = utils.UpdateTableByMap(chanceType, map[string]interface{}{"Name": request.Name, "Icon": request.Icon, "UpdateAt": time.Now()}); err != nil {
|
|
|
if err = utils.UpdateTableByMap(chanceType, map[string]interface{}{"Name": request.Name, "Icon": request.Icon, "SortNum": chanceType.SortNum, "UpdateAt": time.Now()}); err != nil {
|
|
|
log.Error(err.Error())
|
|
|
return
|
|
|
}
|
...
|
...
|
@@ -332,44 +437,70 @@ func TemplateOperateCategory(uid, companyId int64, request *protocol.TemplateOpe |
|
|
return
|
|
|
}
|
|
|
|
|
|
//获取模板详情
|
|
|
func TemplateGet(uid, companyId int64, request *protocol.TemplateGetRequest) (rsp *protocol.TemplateGetResponse, err error) {
|
|
|
//删除一级分类
|
|
|
func TemplateDeleteCategory(uid, companyId int64, request *protocol.TemplateDeleteCategoryRequest) (rsp *protocol.TemplateDeleteCategoryResponse, err error) {
|
|
|
var (
|
|
|
template *models.AuditTemplate
|
|
|
auditForm []*models.AuditForm
|
|
|
chanceType *models.ChanceType
|
|
|
num int
|
|
|
sql1 string = `select count(0) from from audit_template where chance_type_id =? limit 1`
|
|
|
sql2 string = `select count(0) from chance where chance_type_id = ? limit 1`
|
|
|
)
|
|
|
rsp = &protocol.TemplateGetResponse{}
|
|
|
if template, err = models.GetAuditTemplateById(int64(request.Id)); err != nil {
|
|
|
log.Error("template_id:%v 不存在 ,err:%v", request.Id, err.Error())
|
|
|
if chanceType, err = models.GetChanceTypeById(request.ChanceTypeId); err != nil {
|
|
|
log.Error(err.Error())
|
|
|
return
|
|
|
}
|
|
|
if chanceType.CompanyId != int(companyId) {
|
|
|
err = protocol.NewErrWithMessage("10027")
|
|
|
return
|
|
|
}
|
|
|
|
|
|
{
|
|
|
rsp.Template = protocol.Template{
|
|
|
Id: template.Id,
|
|
|
ChanceTypeId: template.ChanceTypeId,
|
|
|
Name: template.Name,
|
|
|
Doc: template.Doc,
|
|
|
Icon: template.Icon,
|
|
|
}
|
|
|
rsp.Example = template.Example
|
|
|
//1.判断分类下面是否有模板
|
|
|
if err = utils.ExecuteQueryOne(&num, sql1, request.ChanceTypeId); err == nil && num > 0 {
|
|
|
err = protocol.NewErrWithMessage("10061")
|
|
|
return
|
|
|
}
|
|
|
//2.判断是否有对应已经发布的机会
|
|
|
if err = utils.ExecuteQueryOne(&num, sql2, request.ChanceTypeId); err == nil && num > 0 {
|
|
|
err = protocol.NewErrWithMessage("10062")
|
|
|
return
|
|
|
}
|
|
|
|
|
|
if auditForm, err = models.GetAuditFormByTemplateId(int(template.Id)); err != nil {
|
|
|
if err == sql.ErrNoRows {
|
|
|
err = nil
|
|
|
}
|
|
|
//删除数据
|
|
|
if err = models.DeleteChanceType(request.ChanceTypeId); err != nil {
|
|
|
log.Error(err.Error())
|
|
|
return
|
|
|
}
|
|
|
rsp = &protocol.TemplateDeleteCategoryResponse{}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//一级分类排序
|
|
|
func CategoryEditSort(uid, companyId int64, request *protocol.CategoryEditSortRequest) (rsp *protocol.CategoryEditSortResponse, err error) {
|
|
|
var (
|
|
|
template *models.ChanceType
|
|
|
)
|
|
|
orm := orm2.NewOrm()
|
|
|
for i := range request.List {
|
|
|
item := request.List[i]
|
|
|
if template, err = models.GetChanceTypeById(item.Id); err != nil {
|
|
|
log.Error(err.Error())
|
|
|
continue
|
|
|
}
|
|
|
if template.CompanyId != int(companyId) {
|
|
|
log.Debug(fmt.Sprintf("template.companyId input:%v want:%v not equal.", companyId, template.CompanyId))
|
|
|
err = protocol.NewErrWithMessage("10027")
|
|
|
return
|
|
|
}
|
|
|
for i := range auditForm {
|
|
|
input := auditForm[i]
|
|
|
rsp.Template.InputList = append(rsp.Template.InputList, &protocol.InputElement{
|
|
|
Id: input.Id,
|
|
|
Sort: input.SortNum,
|
|
|
Lable: input.InputType,
|
|
|
Required: int(input.Required),
|
|
|
SectionType: input.Section,
|
|
|
})
|
|
|
if item.SortNum == template.SortNum {
|
|
|
continue
|
|
|
}
|
|
|
if err = utils.UpdateTableByMapWithOrmer(orm, template, map[string]interface{}{"SortNum": item.SortNum}); err != nil {
|
|
|
log.Error(err.Error())
|
|
|
orm.Rollback()
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
orm.Commit()
|
|
|
rsp = &protocol.CategoryEditSortResponse{}
|
|
|
return
|
|
|
} |
...
|
...
|
|