初始
This commit is contained in:
		| @ -0,0 +1,112 @@ | ||||
| // ========================================================================== | ||||
| // GFast自动生成logic操作代码。 | ||||
| // 生成日期:2023-08-07 10:06:34 | ||||
| // 生成路径: internal/app/system/logic/bus_construction_user_post.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.RegisterBusConstructionUserPost(New()) | ||||
| } | ||||
|  | ||||
| func New() *sBusConstructionUserPost { | ||||
| 	return &sBusConstructionUserPost{} | ||||
| } | ||||
|  | ||||
| type sBusConstructionUserPost struct{} | ||||
|  | ||||
| func (s *sBusConstructionUserPost) List(ctx context.Context, req *system.BusConstructionUserPostSearchReq) (listRes *system.BusConstructionUserPostSearchRes, err error) { | ||||
| 	listRes = new(system.BusConstructionUserPostSearchRes) | ||||
| 	err = g.Try(ctx, func(ctx context.Context) { | ||||
| 		m := dao.BusConstructionUserPost.Ctx(ctx).WithAll() | ||||
| 		if req.Id != "" { | ||||
| 			m = m.Where(dao.BusConstructionUserPost.Columns().Id+" = ?", req.Id) | ||||
| 		} | ||||
| 		if req.ConstructionUserId != "" { | ||||
| 			m = m.Where(dao.BusConstructionUserPost.Columns().ConstructionUserId+" = ?", gconv.Int64(req.ConstructionUserId)) | ||||
| 		} | ||||
| 		if req.PostId != "" { | ||||
| 			m = m.Where(dao.BusConstructionUserPost.Columns().PostId+" = ?", gconv.Int64(req.PostId)) | ||||
| 		} | ||||
| 		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 asc" | ||||
| 		if req.OrderBy != "" { | ||||
| 			order = req.OrderBy | ||||
| 		} | ||||
| 		var res []*model.BusConstructionUserPostInfoRes | ||||
| 		err = m.Fields(system.BusConstructionUserPostSearchRes{}).Page(req.PageNum, req.PageSize).Order(order).Scan(&res) | ||||
| 		liberr.ErrIsNil(ctx, err, "获取数据失败") | ||||
| 		listRes.List = make([]*model.BusConstructionUserPostListRes, len(res)) | ||||
| 		for k, v := range res { | ||||
| 			listRes.List[k] = &model.BusConstructionUserPostListRes{ | ||||
| 				Id:                 v.Id, | ||||
| 				ConstructionUserId: v.ConstructionUserId, | ||||
| 				PostId:             v.PostId, | ||||
| 			} | ||||
| 		} | ||||
| 	}) | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (s *sBusConstructionUserPost) GetById(ctx context.Context, id uint64) (res *model.BusConstructionUserPostInfoRes, err error) { | ||||
| 	err = g.Try(ctx, func(ctx context.Context) { | ||||
| 		err = dao.BusConstructionUserPost.Ctx(ctx).WithAll().Where(dao.BusConstructionUserPost.Columns().Id, id).Scan(&res) | ||||
| 		liberr.ErrIsNil(ctx, err, "获取信息失败") | ||||
| 	}) | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (s *sBusConstructionUserPost) Add(ctx context.Context, req *system.BusConstructionUserPostAddReq) (err error) { | ||||
| 	err = g.Try(ctx, func(ctx context.Context) { | ||||
| 		_, err = dao.BusConstructionUserPost.Ctx(ctx).Insert(do.BusConstructionUserPost{ | ||||
| 			ConstructionUserId: req.ConstructionUserId, | ||||
| 			PostId:             req.PostId, | ||||
| 		}) | ||||
| 		liberr.ErrIsNil(ctx, err, "添加失败") | ||||
| 	}) | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (s *sBusConstructionUserPost) Edit(ctx context.Context, req *system.BusConstructionUserPostEditReq) (err error) { | ||||
| 	err = g.Try(ctx, func(ctx context.Context) { | ||||
| 		_, err = dao.BusConstructionUserPost.Ctx(ctx).WherePri(req.Id).Update(do.BusConstructionUserPost{ | ||||
| 			ConstructionUserId: req.ConstructionUserId, | ||||
| 			PostId:             req.PostId, | ||||
| 		}) | ||||
| 		liberr.ErrIsNil(ctx, err, "修改失败") | ||||
| 	}) | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (s *sBusConstructionUserPost) Delete(ctx context.Context, ids []uint64) (err error) { | ||||
| 	err = g.Try(ctx, func(ctx context.Context) { | ||||
| 		_, err = dao.BusConstructionUserPost.Ctx(ctx).Delete(dao.BusConstructionUserPost.Columns().Id+" in (?)", ids) | ||||
| 		liberr.ErrIsNil(ctx, err, "删除失败") | ||||
| 	}) | ||||
| 	return | ||||
| } | ||||
		Reference in New Issue
	
	Block a user