sys_post.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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/internal/app/system/service/internal/do"
  16. "github.com/tiger1103/gfast/v3/library/liberr"
  17. )
  18. type IPost interface {
  19. List(ctx context.Context, req *system.PostSearchReq) (res *system.PostSearchRes, err error)
  20. Add(ctx context.Context, req *system.PostAddReq) (err error)
  21. Edit(ctx context.Context, req *system.PostEditReq) (err error)
  22. Delete(ctx context.Context, ids []int) (err error)
  23. }
  24. type postImpl struct {
  25. }
  26. var postService = postImpl{}
  27. func Post() IPost {
  28. return IPost(&postService)
  29. }
  30. // List 岗位列表
  31. func (s *postImpl) List(ctx context.Context, req *system.PostSearchReq) (res *system.PostSearchRes, err error) {
  32. res = new(system.PostSearchRes)
  33. err = g.Try(func() {
  34. m := dao.SysPost.Ctx(ctx)
  35. if req != nil {
  36. if req.PostCode != "" {
  37. m = m.Where("post_code like ?", "%"+req.PostCode+"%")
  38. }
  39. if req.PostName != "" {
  40. m = m.Where("post_name like ?", "%"+req.PostName+"%")
  41. }
  42. if req.Status != "" {
  43. m = m.Where("status", gconv.Uint(req.Status))
  44. }
  45. }
  46. res.Total, err = m.Count()
  47. liberr.ErrIsNil(ctx, err, "获取岗位失败")
  48. if req.PageNum == 0 {
  49. req.PageNum = 1
  50. }
  51. if req.PageSize == 0 {
  52. req.PageSize = consts.PageSize
  53. }
  54. err = m.Page(req.PageNum, req.PageSize).Order("post_sort asc,post_id asc").Scan(&res.PostList)
  55. liberr.ErrIsNil(ctx, err, "获取岗位失败")
  56. })
  57. return
  58. }
  59. func (s *postImpl) Add(ctx context.Context, req *system.PostAddReq) (err error) {
  60. err = g.Try(func() {
  61. _, err = dao.SysPost.Ctx(ctx).Insert(do.SysPost{
  62. PostCode: req.PostCode,
  63. PostName: req.PostName,
  64. PostSort: req.PostSort,
  65. Status: req.Status,
  66. Remark: req.Remark,
  67. CreatedBy: Context().GetUserId(ctx),
  68. })
  69. liberr.ErrIsNil(ctx, err, "添加岗位失败")
  70. })
  71. return
  72. }
  73. func (s *postImpl) Edit(ctx context.Context, req *system.PostEditReq) (err error) {
  74. err = g.Try(func() {
  75. _, err = dao.SysPost.Ctx(ctx).WherePri(req.PostId).Update(do.SysPost{
  76. PostCode: req.PostCode,
  77. PostName: req.PostName,
  78. PostSort: req.PostSort,
  79. Status: req.Status,
  80. Remark: req.Remark,
  81. UpdatedBy: Context().GetUserId(ctx),
  82. })
  83. liberr.ErrIsNil(ctx, err, "修改岗位失败")
  84. })
  85. return
  86. }
  87. func (s *postImpl) Delete(ctx context.Context, ids []int) (err error) {
  88. err = g.Try(func() {
  89. _, err = dao.SysPost.Ctx(ctx).Where(dao.SysPost.Columns().PostId+" in(?)", ids).Delete()
  90. liberr.ErrIsNil(ctx, err, "删除失败")
  91. })
  92. return
  93. }