sys_post.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * @desc:岗位处理
  3. * @company:云南奇讯科技有限公司
  4. * @Author: yixiaohu
  5. * @Date: 2022/4/7 23:18
  6. */
  7. package service
  8. import (
  9. "context"
  10. "github.com/gogf/gf/v2/frame/g"
  11. "github.com/gogf/gf/v2/util/gconv"
  12. "github.com/tiger1103/gfast/v3/api/v1/system"
  13. "github.com/tiger1103/gfast/v3/internal/app/system/consts"
  14. "github.com/tiger1103/gfast/v3/internal/app/system/service/internal/dao"
  15. "github.com/tiger1103/gfast/v3/library/liberr"
  16. )
  17. type IPost interface {
  18. List(ctx context.Context, req *system.PostSearchReq) (res *system.PostSearchRes, err error)
  19. }
  20. type postImpl struct {
  21. }
  22. var postService = postImpl{}
  23. func Post() IPost {
  24. return IPost(&postService)
  25. }
  26. // List 岗位列表
  27. func (s *postImpl) List(ctx context.Context, req *system.PostSearchReq) (res *system.PostSearchRes, err error) {
  28. err = g.Try(func() {
  29. m := dao.SysPost.Ctx(ctx)
  30. if req != nil {
  31. if req.PostCode != "" {
  32. m = m.Where("post_code like ?", "%"+req.PostCode+"%")
  33. }
  34. if req.PostName != "" {
  35. m = m.Where("post_name like ?", "%"+req.PostName+"%")
  36. }
  37. if req.Status != "" {
  38. m = m.Where("status", gconv.Uint(req.Status))
  39. }
  40. }
  41. res.Total, err = m.Count()
  42. liberr.ErrIsNil(ctx, err, "获取岗位失败")
  43. if req.PageNum == 0 {
  44. req.PageNum = 1
  45. }
  46. if req.PageSize == 0 {
  47. req.PageSize = consts.PageSize
  48. }
  49. res = new(system.PostSearchRes)
  50. err = m.Page(req.PageNum, req.PageSize).Order("post_sort asc,post_id asc").Scan(&res.PostList)
  51. liberr.ErrIsNil(ctx, err, "获取岗位失败")
  52. })
  53. return
  54. }