template.go 8.5 KB
package controllers

import (
	"encoding/json"
	"oppmg/common/log"
	"oppmg/protocol"
	"oppmg/services/audit"
)

type TemplateController struct {
	BaseController
}

//TemplateAdd 模板新增
//@router /templateAdd [post]
func (this *TemplateController) TemplateAdd() {
	var msg *protocol.ResponseMessage
	defer func() {
		this.ResposeJson(msg)
	}()
	var request *protocol.TemplateAddRequest

	if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil {
		log.Error("json 解析失败", err)
		msg = protocol.BadRequestParam("1")
		return
	}
	uid := this.GetUserId()
	companyId := this.GetCompanyId()
	if companyId <= 0 {
		log.Debug("companyId:%d err", companyId)
		msg = protocol.BadRequestParam("1")
		return
	}
	//if !(request.Type == 1 || request.Type == 2) {
	//	msg = protocol.BadRequestParam("1")
	//	log.Error("type error :%v", request.Type)
	//	return
	//}
	if b, m := this.Valid(request); !b {
		msg = m
		return
	}
	rsp, err := audit.TemplateAdd(uid, companyId, request)
	msg = protocol.NewReturnResponse(rsp, err)
	return
}

//TemplateUpdate 模板更新
//@router /templateUpdate [post]
func (this *TemplateController) TemplateUpdate() {
	var msg *protocol.ResponseMessage
	defer func() {
		this.ResposeJson(msg)
	}()
	var request *protocol.TemplateUpdateRequest

	if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil {
		log.Error("json 解析失败", err)
		msg = protocol.BadRequestParam("1")
		return
	}
	uid := this.GetUserId()
	companyId := this.GetCompanyId()
	if companyId <= 0 {
		log.Debug("companyId:%d err", companyId)
		msg = protocol.BadRequestParam("1")
		return
	}
	if b, m := this.Valid(request); !b {
		msg = m
		return
	}
	rsp, err := audit.TemplateUpdate(uid, companyId, request)
	msg = protocol.NewReturnResponse(rsp, err)
	return
}

//TemplateList 模板列表
//@router /templateList [post]
func (this *TemplateController) TemplateList() {
	var msg *protocol.ResponseMessage
	defer func() {
		this.ResposeJson(msg)
	}()
	var request *protocol.TemplateListRequest

	if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil {
		log.Error("json 解析失败", err)
		msg = protocol.BadRequestParam("1")
		return
	}
	uid := this.GetUserId()
	companyId := this.GetCompanyId()
	if companyId <= 0 {
		log.Debug("companyId:%d err", companyId)
		msg = protocol.BadRequestParam("1")
		return
	}
	if b, m := this.Valid(request); !b {
		msg = m
		return
	}
	rsp, err := audit.TemplateList(uid, companyId, request)
	msg = protocol.NewReturnResponse(rsp, err)
	return
}

//TemplateGet 模板获取
//@router /templateGet [post]
func (this *TemplateController) TemplateGet() {
	var msg *protocol.ResponseMessage
	defer func() {
		this.ResposeJson(msg)
	}()
	var request *protocol.TemplateGetRequest

	if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil {
		log.Error("json 解析失败", err)
		msg = protocol.BadRequestParam("1")
		return
	}
	uid := this.GetUserId()
	companyId := this.GetCompanyId()
	if companyId <= 0 {
		log.Debug("companyId:%d err", companyId)
		msg = protocol.BadRequestParam("1")
		return
	}
	if b, m := this.Valid(request); !b {
		msg = m
		return
	}
	rsp, err := audit.TemplateGet(uid, companyId, request)
	msg = protocol.NewReturnResponse(rsp, err)
}

//TemplateEditVisible 编辑模板可见范围
//@router /templateEditVisible [post]
func (this *TemplateController) TemplateEditVisible() {
	var msg *protocol.ResponseMessage
	defer func() {
		this.ResposeJson(msg)
	}()
	var request *protocol.TemplateEditVisibleRequest

	if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil {
		log.Error("json 解析失败", err)
		msg = protocol.BadRequestParam("1")
		return
	}
	uid := this.GetUserId()
	companyId := this.GetCompanyId()
	if companyId <= 0 {
		log.Debug("companyId:%d err", companyId)
		msg = protocol.BadRequestParam("1")
		return
	}
	if b, m := this.Valid(request); !b {
		msg = m
		return
	}
	rsp, err := audit.TemplateEditVisible(uid, companyId, request)
	msg = protocol.NewReturnResponse(rsp, err)
}

//TemplateEditSort 编辑模板排序
//@router /templateEditSort [post]
func (this *TemplateController) TemplateEditSort() {
	var msg *protocol.ResponseMessage
	defer func() {
		this.ResposeJson(msg)
	}()
	var request *protocol.TemplateEditSortRequest

	if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil {
		log.Error("json 解析失败", err)
		msg = protocol.BadRequestParam("1")
		return
	}
	uid := this.GetUserId()
	companyId := this.GetCompanyId()
	if companyId <= 0 {
		log.Debug("companyId:%d err", companyId)
		msg = protocol.BadRequestParam("1")
		return
	}
	if b, m := this.Valid(request); !b {
		msg = m
		return
	}
	rsp, err := audit.TemplateEditSort(uid, companyId, request)
	msg = protocol.NewReturnResponse(rsp, err)
}

//TemplateOperateCategory 编辑一级分类
//@router /templateOperateCategory [post]
func (this *TemplateController) TemplateOperateCategory() {
	var msg *protocol.ResponseMessage
	defer func() {
		this.ResposeJson(msg)
	}()
	var request *protocol.TemplateOperateCategoryRequest

	if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil {
		log.Error("json 解析失败", err)
		msg = protocol.BadRequestParam("1")
		return
	}
	uid := this.GetUserId()
	companyId := this.GetCompanyId()
	if companyId <= 0 {
		log.Debug("companyId:%d err", companyId)
		msg = protocol.BadRequestParam("1")
		return
	}
	if b, m := this.Valid(request); !b {
		msg = m
		return
	}
	rsp, err := audit.TemplateOperateCategory(uid, companyId, request)
	msg = protocol.NewReturnResponse(rsp, err)
}

//TemplateDeleteCategory 删除一级分类
//@router /templateDeleteCategory [post]
func (this *TemplateController) TemplateDeleteCategory() {
	var msg *protocol.ResponseMessage
	defer func() {
		this.ResposeJson(msg)
	}()
	var request *protocol.TemplateDeleteCategoryRequest

	if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil {
		log.Error("json 解析失败", err)
		msg = protocol.BadRequestParam("1")
		return
	}
	uid := this.GetUserId()
	companyId := this.GetCompanyId()
	if companyId <= 0 {
		log.Debug("companyId:%d err", companyId)
		msg = protocol.BadRequestParam("1")
		return
	}
	if b, m := this.Valid(request); !b {
		msg = m
		return
	}
	rsp, err := audit.TemplateDeleteCategory(uid, companyId, request)
	msg = protocol.NewReturnResponse(rsp, err)
}

//TemplateDelete  模板删除
//@router /templateDelete [post]
func (this *TemplateController) TemplateDelete() {
	var msg *protocol.ResponseMessage
	defer func() {
		this.ResposeJson(msg)
	}()
	var request *protocol.TemplateDeleteRequest

	if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil {
		log.Error("json 解析失败", err)
		msg = protocol.BadRequestParam("1")
		return
	}
	uid := this.GetUserId()
	companyId := this.GetCompanyId()
	if companyId <= 0 {
		log.Debug("companyId:%d err", companyId)
		msg = protocol.BadRequestParam("1")
		return
	}
	if b, m := this.Valid(request); !b {
		msg = m
		return
	}
	rsp, err := audit.TemplateDelete(uid, companyId, request)
	msg = protocol.NewReturnResponse(rsp, err)
}

//TemplateEditEnable  模板启用
//@router /templateEditEnable [post]
func (this *TemplateController) TemplateEditEnable() {
	var msg *protocol.ResponseMessage
	defer func() {
		this.ResposeJson(msg)
	}()
	var request *protocol.TemplateEditEnableRequest

	if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil {
		log.Error("json 解析失败", err)
		msg = protocol.BadRequestParam("1")
		return
	}
	uid := this.GetUserId()
	companyId := this.GetCompanyId()
	if companyId <= 0 {
		log.Debug("companyId:%d err", companyId)
		msg = protocol.BadRequestParam("1")
		return
	}
	if b, m := this.Valid(request); !b {
		msg = m
		return
	}
	rsp, err := audit.TemplateEditEnable(uid, companyId, request)
	msg = protocol.NewReturnResponse(rsp, err)
}

//CategoryEditSort 一级分类排序
//@router /categoryEditSort [post]
func (this *TemplateController) CategoryEditSort() {
	var msg *protocol.ResponseMessage
	defer func() {
		this.ResposeJson(msg)
	}()
	var request *protocol.CategoryEditSortRequest

	if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil {
		log.Error("json 解析失败", err)
		msg = protocol.BadRequestParam("1")
		return
	}
	uid := this.GetUserId()
	companyId := this.GetCompanyId()
	if companyId <= 0 {
		log.Debug("companyId:%d err", companyId)
		msg = protocol.BadRequestParam("1")
		return
	}
	if b, m := this.Valid(request); !b {
		msg = m
		return
	}
	rsp, err := audit.CategoryEditSort(uid, companyId, request)
	msg = protocol.NewReturnResponse(rsp, err)
}