123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293 |
- package v1_0
- import (
- "adm-gateway/errors"
- param_v1 "adm-gateway/param/v1"
- "adm-gateway/pb"
- v1 "adm-gateway/pb/v1"
- "fmt"
- "net/http"
- "github.com/gin-gonic/gin"
- "git.getensh.com/common/gopkgsv2/logger"
- "git.getensh.com/common/gopkgsv2/tasker/httptasker"
- "git.getensh.com/common/gopkgsv2/util"
- "go.uber.org/zap"
- )
- // DataImportTemplate godoc
- // @Summary 数据导入模板
- // @Description 数据导入模板
- // @Tags data_import,v1.0
- // @Accept json
- // @Produce json
- // @Param token header string true "jwt token"
- // @Param template_name query string false "模板名"
- // @Param page query int32 false "页码"
- // @Param page_size query int32 false "每页数量,默认10"
- // @Success 200 {object} param_v1.DataImportTemplateResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1.0/data_import/data_import_template [get]
- func (c *Controller) DataImportTemplate(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.DataImportTemplateRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, &req.DataImportTemplateQuery, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- resp := ¶m_v1.DataImportTemplateResponse{}
- r := v1.DataImportTemplateRequest{
- TemplateName: req.TemplateName,
- Page: req.Page,
- PageSize: req.PageSize,
- }
- reply, err := pb.Management.DataImportTemplate(ctx.Request.Context(), &r)
- if err != nil {
- s, _ := json.MarshalToString(r)
- logger.Error("func",
- zap.String("call", "pb.management.DataImportTemplate"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = reply
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- // CreateTemplate godoc
- // @Summary 新建模板
- // @Description 新建模板
- // @Tags data_import,v1.0
- // @Accept json
- // @Produce json
- // @Param token header string true "jwt token"
- // @Param body body param_v1.CreateTemplateBody true "body"
- // @Success 200 {object} param_v1.CreateTemplateResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1.0/data_import/create_template [post]
- func (c *Controller) CreateTemplate(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.CreateTemplateRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, nil, &req.CreateTemplateBody)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- resp := ¶m_v1.CreateTemplateResponse{}
- r := v1.CreateTemplateRequest{
- TemplateName: req.TemplateName,
- Request: req.Request,
- TaskName: req.TaskName,
- }
- _, err := pb.Management.CreateTemplate(ctx.Request.Context(), &r)
- if err != nil {
- s, _ := json.MarshalToString(r)
- logger.Error("func",
- zap.String("call", "pb.management.CreateTemplate"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- // EditTemplate godoc
- // @Summary 修改模板
- // @Description 修改模板
- // @Tags data_import,v1.0
- // @Accept json
- // @Produce json
- // @Param token header string true "jwt token"
- // @Param body body param_v1.EditTemplateBody true "body"
- // @Success 200 {object} param_v1.EditTemplateResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1.0/data_import/edit_template [put]
- func (c *Controller) EditTemplate(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.EditTemplateRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, nil, &req.EditTemplateBody)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- resp := ¶m_v1.EditTemplateResponse{}
- r := v1.EditTemplateRequest{
- Id: req.Id,
- TemplateName: req.TemplateName,
- Request: req.Request,
- TaskName: req.TaskName,
- }
- _, err := pb.Management.EditTemplate(ctx.Request.Context(), &r)
- if err != nil {
- s, _ := json.MarshalToString(r)
- logger.Error("func",
- zap.String("call", "pb.management.EditTemplate"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- // DeleteTemplate godoc
- // @Summary 删除模板
- // @Description 删除模板
- // @Tags data_import,v1.0
- // @Accept json
- // @Produce json
- // @Param token header string true "jwt token"
- // @Param id path int64 true "id"
- // @Success 200 {object} param_v1.DeleteTemplateResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1.0/data_import/delete_template/{id} [delete]
- func (c *Controller) DeleteTemplate(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.DeleteTemplateRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, &req.DeleteTemplatePath, nil, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- resp := ¶m_v1.DeleteTemplateResponse{}
- r := v1.DeleteTemplateRequest{
- Id: req.Id,
- }
- _, err := pb.Management.DeleteTemplate(ctx.Request.Context(), &r)
- fmt.Println(err)
- if err != nil {
- s, _ := json.MarshalToString(r)
- logger.Error("func",
- zap.String("call", "pb.management.DeleteTemplate"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- // DataImport godoc
- // @Summary 数据导入
- // @Description 数据导入
- // @Tags data_import,v1.0
- // @Accept json
- // @Produce json
- // @Param token header string true "jwt token"
- // @Param body body param_v1.DataImportBody true "body"
- // @Success 200 {object} param_v1.DataImportResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1.0/data_import/data_import [post]
- func (c *Controller) DataImport(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.DataImportRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, nil, &req.DataImportBody)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- resp := ¶m_v1.DataImportResponse{}
- r := v1.DataImportRequest{
- Id: req.Id,
- RequestList: req.RequestList,
- }
- _, err := pb.Management.DataImport(ctx.Request.Context(), &r)
- if err != nil {
- s, _ := json.MarshalToString(r)
- logger.Error("func",
- zap.String("call", "pb.management.DataImport"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
|