123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937 |
- package v1_0
- import (
- "adm-gateway/errors"
- param_v1 "adm-gateway/param/v1"
- "adm-gateway/parser"
- "adm-gateway/pb"
- v1 "adm-gateway/pb/v1"
- "fmt"
- "net/http"
- "strings"
- "git.getensh.com/common/gopkgsv2/id"
- "github.com/aliyun/aliyun-oss-go-sdk/oss"
- "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"
- )
- // 1. 数据管理表 t_adm_data_management
- // DataList godoc
- // @Summary 数据管理
- // @Description 数据管理
- // @Tags data_management,v1.0
- // @Accept json
- // @Produce json
- // @Param token header string true "jwt token"
- // @Param table_name query string false "表名"
- // @Param desc query string false "描述"
- // @Param level query string false "所属层"
- // @Param page query int32 false "页码"
- // @Param page_size query int32 false "每页数量,默认10"
- // @Success 200 {object} param_v1.GetDataListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1.0/data_management [get]
- func (c *Controller) DataList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GetDataListRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, &req.GetDataListQuery, 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.GetDataListResponse{}
- r := v1.DataListRequest{
- TableName: req.TableName,
- Desc: req.Desc,
- Level: req.Level,
- Page: req.Page,
- PageSize: req.PageSize,
- }
- reply, err := pb.Management.DataList(ctx.Request.Context(), &r)
- if err != nil {
- s, _ := json.MarshalToString(r)
- logger.Error("func",
- zap.String("call", "pb.management.DataList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if reply.List == nil {
- reply.List = make([]*v1.DataList, 0)
- }
- resp.Data = reply
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- // SearchData godoc
- // @Summary 模糊搜索
- // @Description 模糊搜索
- // @Tags data_management,v1.0
- // @Accept json
- // @Produce json
- // @Param token header string true "jwt token"
- // @Param table_name query string false "表名"
- // @Success 200 {object} param_v1.SearchDataResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1.0/data_management/search [get]
- func (c *Controller) SearchData(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.SearchDataRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, &req.SearchDataQuery, 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.SearchDataResponse{}
- r := v1.SearchDataRequest{
- TableName: req.TableName,
- }
- reply, err := pb.Management.SearchData(ctx.Request.Context(), &r)
- if err != nil {
- s, _ := json.MarshalToString(r)
- logger.Error("func",
- zap.String("call", "pb.management.SearchData"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if reply.List == nil {
- reply.List = make([]*v1.SearchData, 0)
- }
- resp.Data = reply
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- // SearchLevel godoc
- // @Summary 所属层搜索
- // @Description 所属层搜索
- // @Tags data_management,v1.0
- // @Accept json
- // @Produce json
- // @Param token header string true "jwt token"
- // @Param level query string false "所属层"
- // @Success 200 {object} param_v1.SearchLevelResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1.0/data_management/search_level [get]
- func (c *Controller) SearchLevel(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.SearchLevelRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, &req.SearchLevelQuery, 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.SearchLevelResponse{}
- r := v1.SearchLevelRequest{
- Level: req.Level,
- }
- reply, err := pb.Management.SearchLevel(ctx.Request.Context(), &r)
- if err != nil {
- s, _ := json.MarshalToString(r)
- logger.Error("func",
- zap.String("call", "pb.management.SearchLevel"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = reply.List
- if resp.Data == nil {
- resp.Data = make([]string, 0)
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- // 2.数据关系表 t_adm_task_data_relation
- // Relation godoc
- // @Summary 任务关系
- // @Description 任务关系
- // @Tags data_management,v1.0
- // @Accept json
- // @Produce json
- // @Param token header string true "jwt token"
- // @Param source_code query string false "数据源"
- // @Success 200 {object} param_v1.GetRelationResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1.0/data_management/relation [get]
- func (c *Controller) Relation(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GetRelationRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, &req.GetRelationQuery, 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.GetRelationResponse{}
- r := v1.RelationRequest{
- SourceCode: req.SourceCode,
- }
- reply, err := pb.Management.Relation(ctx.Request.Context(), &r)
- if err != nil {
- s, _ := json.MarshalToString(r)
- logger.Error("func",
- zap.String("call", "pb.management.Relation"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if reply.List == nil {
- reply.List = make([]*v1.Relation, 0)
- }
- resp.Data = reply
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- // Switch godoc
- // @Summary 任务开关
- // @Description 任务开关
- // @Tags data_management,v1.0
- // @Accept json
- // @Produce json
- // @Param token header string true "jwt token"
- // @Param body body param_v1.GetSwitchBody true "body"
- // @Success 200 {object} param_v1.GetSwitchResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1.0/data_management/relation/ [put]
- func (c *Controller) Switch(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GetSwitchRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, nil, &req.GetSwitchBody)
- 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.GetSwitchResponse{}
- //resp.Code = 0
- //resp.Message = "成功"
- r := v1.SwitchRequest{
- TaskId: req.TaskId,
- IsOn: req.IsOn,
- }
- _, err := pb.Management.Switch(ctx.Request.Context(), &r)
- if err != nil {
- s, _ := json.MarshalToString(r)
- logger.Error("func",
- zap.String("call", "pb.management.Switch"),
- 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)
- }
- // 3.任务管理表 t_adm_tasks_management
- // TaskList godoc
- // @Summary 任务管理
- // @Description 任务管理
- // @Tags task_management,v1.0
- // @Accept json
- // @Produce json
- // @Param token header string true "jwt token"
- // @Param task_name query string false "任务名"
- // @Param desc query string false "描述"
- // @Param page query int32 false "页码"
- // @Param page_size query int32 false "每页数量,默认10"
- // @Success 200 {object} param_v1.GetTaskListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1.0/task_management [get]
- func (c *Controller) TaskList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GetTaskListRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, &req.GetTaskListQuery, 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.GetTaskListResponse{}
- r := v1.TaskListRequest{
- TaskName: req.TaskName,
- Desc: req.Desc,
- Page: req.Page,
- PageSize: req.PageSize,
- }
- reply, err := pb.Management.TaskList(ctx.Request.Context(), &r)
- if err != nil {
- s, _ := json.MarshalToString(r)
- logger.Error("func",
- zap.String("call", "pb.management.TaskList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if reply.List == nil {
- reply.List = make([]*v1.TaskList, 0)
- }
- resp.Data = reply
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- // SearchTask godoc
- // @Summary 模糊搜索
- // @Description 模糊搜索
- // @Tags task_management,v1.0
- // @Accept json
- // @Produce json
- // @Param token header string true "jwt token"
- // @Param task_name query string false "任务名"
- // @Success 200 {object} param_v1.SearchTaskResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1.0/task_management/search [get]
- func (c *Controller) SearchTask(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.SearchTaskRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, &req.SearchTaskQuery, 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.SearchTaskResponse{}
- r := v1.SearchTaskRequest{
- TaskName: req.TaskName,
- }
- reply, err := pb.Management.SearchTask(ctx.Request.Context(), &r)
- if err != nil {
- s, _ := json.MarshalToString(r)
- logger.Error("func",
- zap.String("call", "pb.management.SearchData"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if reply.List == nil {
- reply.List = make([]*v1.SearchTask, 0)
- }
- resp.Data = reply
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- // 4.依赖表 t_adm_task_dependency
- // Dependency godoc
- // @Summary 依赖表
- // @Description 依赖表
- // @Tags task_management,v1.0
- // @Accept json
- // @Produce json
- // @Param token header string true "jwt token"
- // @Param task_id query int64 false "任务id"
- // @Param type query int32 true "源表或依赖表"
- // @Success 200 {object} param_v1.GetDependencyResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1.0/task_management/dependency [get]
- func (c *Controller) Dependency(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GetDependencyRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, &req.GetDependencyQuery, 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.GetDependencyResponse{}
- r := v1.DependencyRequest{
- TaskId: req.TaskId,
- Type: req.Type,
- }
- reply, err := pb.Management.Dependency(ctx.Request.Context(), &r)
- if err != nil {
- s, _ := json.MarshalToString(r)
- logger.Error("func",
- zap.String("call", "pb.management.Dependency"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if reply.List == nil {
- reply.List = make([]*v1.Dependency, 0)
- }
- resp.Data = reply
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- // DataSourceRelation godoc
- // @Summary 血缘关系
- // @Description 血缘关系
- // @Tags task_management,v1.0
- // @Accept json
- // @Produce json
- // @Param token header string true "jwt token"
- // @Param task_id query int64 false "任务id"
- // @Param source_code query string false "source code"
- // @Success 200 {object} param_v1.GetDataSourceRelationResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1.0/task_management/relation [get]
- func (c *Controller) DataSourceRelation(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GetDataSourceRelationRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, &req.GetDataSourceRelationQuery, 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.GetDataSourceRelationResponse{}
- r := v1.DataSourceRelationRequest{
- TaskId: req.TaskId,
- SourceCode: req.SourceCode,
- }
- reply, err := pb.Management.DataSourceRelation(ctx.Request.Context(), &r)
- if err != nil {
- s, _ := json.MarshalToString(r)
- logger.Error("func",
- zap.String("call", "pb.management.DataSourceRelation"),
- 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)
- }
- // 手动任务列表 t_adm_offline_task
- // ManualTask godoc
- // @Summary 手动任务
- // @Description 手动任务
- // @Tags manualTask,v1.0
- // @Accept json
- // @Produce json
- // @Param token header string true "jwt token"
- // @Param source query string false "源表"
- // @Param task_name query string false "任务"
- // @Param manual_task_name query string false "手动任务名"
- // @Param time1 query int64 false "时间1"
- // @Param time2 query int64 false "时间2"
- // @Param page query int32 false "页码"
- // @Param page_size query int32 false "每页数量,默认10"
- // @Success 200 {object} param_v1.GetManualTaskResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1.0/manual_task [get]
- func (c *Controller) ManualTask(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GetManualTaskRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, &req.GetManualTaskQuery, 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.GetManualTaskResponse{}
- r := v1.ManualTaskRequest{
- Source: req.Source,
- TaskName: req.TaskName,
- ManualTaskName: req.ManualTaskName,
- Time1: req.Time1,
- Time2: req.Time2,
- Page: req.Page,
- PageSize: req.PageSize,
- }
- reply, err := pb.Management.ManualTask(ctx.Request.Context(), &r)
- if err != nil {
- s, _ := json.MarshalToString(r)
- logger.Error("func",
- zap.String("call", "pb.management.ManualTask"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if reply.List == nil {
- reply.List = make([]*v1.ManualTask, 0)
- }
- resp.Data = reply
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- // Source godoc
- // @Summary 源表搜索
- // @Description 源表搜索
- // @Tags manualTask,v1.0
- // @Accept json
- // @Produce json
- // @Param token header string true "jwt token"
- // @Param source_name query string false "源表"
- // @Success 200 {object} param_v1.SourceResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1.0/manual_task/source [get]
- func (c *Controller) Source(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.SourceRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, &req.SourceQuery, 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.SourceResponse{}
- r := v1.SourceRequest{
- SourceName: req.SourceName,
- }
- reply, err := pb.Management.Source(ctx.Request.Context(), &r)
- if err != nil {
- s, _ := json.MarshalToString(r)
- logger.Error("func",
- zap.String("call", "pb.management.Source"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if reply.List == nil {
- reply.List = make([]*v1.Source, 0)
- }
- resp.Data = reply
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- // Task godoc
- // @Summary 任务列表
- // @Description 任务列表
- // @Tags manualTask,v1.0
- // @Accept json
- // @Produce json
- // @Param token header string true "jwt token"
- // @Param source_request query string false "源表名"
- // @Success 200 {object} param_v1.TaskResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1.0/manual_task/task [get]
- func (c *Controller) Task(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.TaskRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, &req.TaskQuery, 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.TaskResponse{}
- r := v1.TaskRequest{
- SourceRequest: req.SourceRequest,
- }
- reply, err := pb.Management.Task(ctx.Request.Context(), &r)
- if err != nil {
- s, _ := json.MarshalToString(r)
- logger.Error("func",
- zap.String("call", "pb.management.Task"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if reply.List == nil {
- reply.List = make([]*v1.Task, 0)
- }
- resp.Data = reply
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- // Create godoc
- // @Summary 创建手动任务
- // @Description 创建手动任务
- // @Tags manualTask,v1.0
- // @Accept json
- // @Produce json
- // @Param token header string true "jwt token"
- // @Param body body param_v1.CreateBody true "body"
- // @Success 200 {object} param_v1.CreateResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1.0/manual_task/create [post]
- func (c *Controller) Create(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.CreateRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, nil, &req.CreateBody)
- 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.CreateResponse{}
- r := v1.CreateRequest{
- TaskName: req.TaskName,
- Type: req.Type,
- Source: req.Source,
- Sql: req.Sql,
- TaskIds: req.TaskIds,
- }
- _, err := pb.Management.Create(ctx.Request.Context(), &r)
- if err != nil {
- s, _ := json.MarshalToString(r)
- logger.Error("func",
- zap.String("call", "pb.management.Create"),
- 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)
- }
- // UploadFile godoc
- // @Summary 上传文件创建
- // @Description 上传文件创建
- // @Tags manualTask,v1.0
- // @Accept json
- // @Produce json
- // @Param token header string true "jwt token"
- // @Param file formData file true "上传文件"
- // @Param task_name formData string true "手动任务"
- // @Success 200 {string} param_v1.UploadFileResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1.0/manual_task/create/upload [post]
- func (c *Controller) UploadFile(ctx *gin.Context) {
- // 业务处理
- uploadFileTask := func() error {
- // 上传文件 得到url
- file, err := ctx.FormFile("file")
- if err != nil {
- return errors.SystemError
- }
- if strings.Index(file.Filename, "xlsx") == -1 && strings.Index(file.Filename, "xlx") == -1 {
- return errors.FileTypeError
- }
- id, _ := id.GetUniqueID()
- fileName := fmt.Sprintf("file-upload-%s-%d.xlsx", ctx.PostForm("task_name"), id)
- resp := ¶m_v1.UploadFileResponse{}
- r := v1.UploadFileRequest{
- TaskName: ctx.PostForm("task_name"),
- }
- reply, err := pb.Management.UploadFile(ctx.Request.Context(), &r)
- if err != nil {
- s, _ := json.MarshalToString(r)
- logger.Error("func",
- zap.String("call", "pb.management.UploadFile"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- client, err := oss.New(
- parser.Conf.Oss.EndPoint,
- parser.Conf.Oss.AccessKey,
- parser.Conf.Oss.AccessSecret,
- )
- if err != nil {
- return err
- }
- bucket, err := client.Bucket(parser.Conf.Oss.Bucket)
- if err != nil {
- return err
- }
- reader, _ := file.Open()
- err = bucket.PutObject(fileName, reader)
- if err != nil {
- return err
- }
- reply.Url = "https://" + parser.Conf.Oss.Bucket + "." + parser.Conf.Oss.EndPoint + "/" + fileName
- resp.Data = reply
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, uploadFileTask)
- }
- // TableStruct godoc
- // @Summary 查看表结构
- // @Description 查看表结构
- // @Tags data_management,v1.0
- // @Accept json
- // @Produce json
- // @Param token header string true "jwt token"
- // @Param table_name query string false "表名"
- // @Success 200 {object} param_v1.TableStructResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1.0/data_management/table_struct [get]
- func (c *Controller) TableStruct(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.TableStructRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, &req.TableStructQuery, 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.TableStructResponse{}
- r := v1.TableStructRequest{
- TableName: req.TableName,
- }
- reply, err := pb.Management.TableStruct(ctx.Request.Context(), &r)
- if err != nil {
- s, _ := json.MarshalToString(r)
- logger.Error("func",
- zap.String("call", "pb.management.TableStruct"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if reply.List == nil {
- reply.List = make([]*v1.TableStruct, 0)
- }
- resp.Data = reply
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
|