初始
This commit is contained in:
		| @ -0,0 +1,148 @@ | ||||
| // ========================================================================== | ||||
| // GFast自动生成logic操作代码。 | ||||
| // 生成日期:2023-12-08 10:06:54 | ||||
| // 生成路径: internal/app/system/logic/template_data_source_data.go | ||||
| // 生成人:gfast | ||||
| // desc:模板资料源数据 | ||||
| // company:云南奇讯科技有限公司 | ||||
| // ========================================================================== | ||||
|  | ||||
| package logic | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
| 	"github.com/gogf/gf/v2/frame/g" | ||||
| 	"github.com/gogf/gf/v2/util/gconv" | ||||
| 	"github.com/tiger1103/gfast/v3/api/v1/system" | ||||
| 	"github.com/tiger1103/gfast/v3/internal/app/system/consts" | ||||
| 	"github.com/tiger1103/gfast/v3/internal/app/system/dao" | ||||
| 	"github.com/tiger1103/gfast/v3/internal/app/system/model" | ||||
| 	"github.com/tiger1103/gfast/v3/internal/app/system/model/do" | ||||
| 	"github.com/tiger1103/gfast/v3/internal/app/system/service" | ||||
| 	"github.com/tiger1103/gfast/v3/library/liberr" | ||||
| ) | ||||
|  | ||||
| func init() { | ||||
| 	service.RegisterTemplateDataSourceData(New()) | ||||
| } | ||||
|  | ||||
| func New() *sTemplateDataSourceData { | ||||
| 	return &sTemplateDataSourceData{} | ||||
| } | ||||
|  | ||||
| type sTemplateDataSourceData struct{} | ||||
|  | ||||
| func (s *sTemplateDataSourceData) List(ctx context.Context, req *system.TemplateDataSourceDataSearchReq) (listRes *system.TemplateDataSourceDataSearchRes, err error) { | ||||
| 	listRes = new(system.TemplateDataSourceDataSearchRes) | ||||
| 	err = g.Try(ctx, func(ctx context.Context) { | ||||
| 		m := dao.TemplateDataSourceData.Ctx(ctx).WithAll() | ||||
| 		if req.Id != "" { | ||||
| 			m = m.Where(dao.TemplateDataSourceData.Columns().Id+" = ?", req.Id) | ||||
| 		} | ||||
| 		if req.Type != "" { | ||||
| 			m = m.Where(dao.TemplateDataSourceData.Columns().Type+" = ?", req.Type) | ||||
| 		} | ||||
| 		if req.ProjectId != "" { | ||||
| 			m = m.Where(dao.TemplateDataSourceData.Columns().ProjectId+" = ?", gconv.Int64(req.ProjectId)) | ||||
| 		} | ||||
| 		if req.SourceName != "" { | ||||
| 			m = m.Where(dao.TemplateDataSourceData.Columns().SourceName+" like ?", "%"+req.SourceName+"%") | ||||
| 		} | ||||
| 		if req.SourceId != "" { | ||||
| 			m = m.Where(dao.TemplateDataSourceData.Columns().SourceId+" like ?", "%"+req.SourceId+"%") | ||||
| 		} | ||||
| 		if len(req.DateRange) != 0 { | ||||
| 			m = m.Where(dao.TemplateDataSourceData.Columns().CreatedAt+" >=? AND "+dao.TemplateDataSourceData.Columns().CreatedAt+" <=?", req.DateRange[0], req.DateRange[1]) | ||||
| 		} | ||||
| 		listRes.Total, err = m.Count() | ||||
| 		liberr.ErrIsNil(ctx, err, "获取总行数失败") | ||||
| 		if req.PageNum == 0 { | ||||
| 			req.PageNum = 1 | ||||
| 		} | ||||
| 		listRes.CurrentPage = req.PageNum | ||||
| 		if req.PageSize == 0 { | ||||
| 			req.PageSize = consts.PageSize | ||||
| 		} | ||||
| 		order := "id desc" | ||||
| 		if req.OrderBy != "" { | ||||
| 			order = req.OrderBy | ||||
| 		} | ||||
| 		var res []*model.TemplateDataSourceDataInfoRes | ||||
| 		err = m.Fields(system.TemplateDataSourceDataSearchRes{}).Page(req.PageNum, req.PageSize).Order(order).Scan(&res) | ||||
| 		liberr.ErrIsNil(ctx, err, "获取数据失败") | ||||
| 		listRes.List = make([]*model.TemplateDataSourceDataListRes, len(res)) | ||||
| 		for k, v := range res { | ||||
| 			listRes.List[k] = &model.TemplateDataSourceDataListRes{ | ||||
| 				Id:         v.Id, | ||||
| 				Type:       v.Type, | ||||
| 				TypeId:     v.TypeId, | ||||
| 				ProjectId:  v.ProjectId, | ||||
| 				SourceName: v.SourceName, | ||||
| 				SourceId:   v.SourceId, | ||||
| 				SourcePath: v.SourcePath, | ||||
| 				CreatedAt:  v.CreatedAt, | ||||
| 			} | ||||
| 		} | ||||
| 	}) | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (s *sTemplateDataSourceData) GetById(ctx context.Context, id int64) (res *model.TemplateDataSourceDataInfoRes, err error) { | ||||
| 	err = g.Try(ctx, func(ctx context.Context) { | ||||
| 		err = dao.TemplateDataSourceData.Ctx(ctx).WithAll().Where(dao.TemplateDataSourceData.Columns().Id, id).Scan(&res) | ||||
| 		liberr.ErrIsNil(ctx, err, "获取信息失败") | ||||
| 	}) | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (s *sTemplateDataSourceData) Add(ctx context.Context, req *system.TemplateDataSourceDataAddReq) (err error) { | ||||
| 	err = g.Try(ctx, func(ctx context.Context) { | ||||
| 		_, err = dao.TemplateDataSourceData.Ctx(ctx).Insert(do.TemplateDataSourceData{ | ||||
| 			Type:       req.Type, | ||||
| 			TypeId:     req.TypeId, | ||||
| 			ProjectId:  req.ProjectId, | ||||
| 			SourceName: req.SourceName, | ||||
| 			SourceId:   req.SourceId, | ||||
| 			SourcePath: req.SourcePath, | ||||
| 		}) | ||||
| 		liberr.ErrIsNil(ctx, err, "添加失败") | ||||
| 	}) | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (s *sTemplateDataSourceData) Edit(ctx context.Context, req *system.TemplateDataSourceDataEditReq) (err error) { | ||||
| 	err = g.Try(ctx, func(ctx context.Context) { | ||||
| 		_, err = dao.TemplateDataSourceData.Ctx(ctx).WherePri(req.Id).Update(do.TemplateDataSourceData{ | ||||
| 			Type:       req.Type, | ||||
| 			TypeId:     req.TypeId, | ||||
| 			ProjectId:  req.ProjectId, | ||||
| 			SourceName: req.SourceName, | ||||
| 			SourceId:   req.SourceId, | ||||
| 			SourcePath: req.SourcePath, | ||||
| 		}) | ||||
| 		liberr.ErrIsNil(ctx, err, "修改失败") | ||||
| 	}) | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (s *sTemplateDataSourceData) Delete(ctx context.Context, ids []int64) (err error) { | ||||
| 	err = g.Try(ctx, func(ctx context.Context) { | ||||
| 		_, err = dao.TemplateDataSourceData.Ctx(ctx).Delete(dao.TemplateDataSourceData.Columns().Id+" in (?)", ids) | ||||
| 		liberr.ErrIsNil(ctx, err, "删除失败") | ||||
| 	}) | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func ExposeAdd(ctx context.Context, req *model.TemplateDataSourceDataInfoRes) (err error) { | ||||
| 	err = g.Try(ctx, func(ctx context.Context) { | ||||
| 		_, err = dao.TemplateDataSourceData.Ctx(ctx).Insert(do.TemplateDataSourceData{ | ||||
| 			Type:       req.Type, | ||||
| 			TypeId:     req.TypeId, | ||||
| 			ProjectId:  req.ProjectId, | ||||
| 			SourceName: req.SourceName, | ||||
| 			SourcePath: req.SourcePath, | ||||
| 		}) | ||||
| 		liberr.ErrIsNil(ctx, err, "添加失败") | ||||
| 	}) | ||||
| 	return | ||||
| } | ||||
		Reference in New Issue
	
	Block a user