浏览代码

岗位管理

yxh 4 年之前
父节点
当前提交
d7b2b46e2b

+ 33 - 0
api/v1/system/sys_post.go

@@ -26,3 +26,36 @@ type PostSearchRes struct {
 	commonApi.ListRes
 	PostList []*entity.SysPost `json:"postList"`
 }
+
+type PostAddReq struct {
+	g.Meta   `path:"/post/add" tags:"岗位管理" method:"post" summary:"添加岗位"`
+	PostCode string `p:"postCode" v:"required#岗位编码不能为空"`
+	PostName string `p:"postName" v:"required#岗位名称不能为空"`
+	PostSort int    `p:"postSort" v:"required#岗位排序不能为空"`
+	Status   uint   `p:"status" v:"required#状态不能为空"`
+	Remark   string `p:"remark"`
+}
+
+type PostAddRes struct {
+}
+
+type PostEditReq struct {
+	g.Meta   `path:"/post/edit" tags:"岗位管理" method:"put" summary:"修改岗位"`
+	PostId   int64  `p:"postId" v:"required#id必须"`
+	PostCode string `p:"postCode" v:"required#岗位编码不能为空"`
+	PostName string `p:"postName" v:"required#岗位名称不能为空"`
+	PostSort int    `p:"postSort" v:"required#岗位排序不能为空"`
+	Status   uint   `p:"status" v:"required#状态不能为空"`
+	Remark   string `p:"remark"`
+}
+
+type PostEditRes struct {
+}
+
+type PostDeleteReq struct {
+	g.Meta `path:"/post/delete" tags:"岗位管理" method:"delete" summary:"删除岗位"`
+	Ids    []int `p:"ids"`
+}
+
+type PostDeleteRes struct {
+}

+ 19 - 0
internal/app/system/controller/sys_post.go

@@ -19,7 +19,26 @@ type postController struct {
 	BaseController
 }
 
+// List 岗位列表
 func (c *postController) List(ctx context.Context, req *system.PostSearchReq) (res *system.PostSearchRes, err error) {
 	res, err = service.Post().List(ctx, req)
 	return
 }
+
+// Add 添加岗位
+func (c *postController) Add(ctx context.Context, req *system.PostAddReq) (res *system.PostAddRes, err error) {
+	err = service.Post().Add(ctx, req)
+	return
+}
+
+// Edit 修改岗位
+func (c *postController) Edit(ctx context.Context, req *system.PostEditReq) (res *system.PostEditRes, err error) {
+	err = service.Post().Edit(ctx, req)
+	return
+}
+
+// Delete 删除岗位
+func (c *postController) Delete(ctx context.Context, req *system.PostDeleteReq) (res *system.PostDeleteRes, err error) {
+	err = service.Post().Delete(ctx, req.Ids)
+	return
+}

+ 1 - 0
internal/app/system/router/router.go

@@ -26,6 +26,7 @@ func BindController(group *ghttp.RouterGroup) {
 			controller.Menu,
 			controller.Role,
 			controller.Dept,
+			controller.Post,
 			controller.DictData,
 		)
 	})

+ 1 - 1
internal/app/system/service/sys_dept.go

@@ -108,7 +108,7 @@ func (s *deptImpl) Edit(ctx context.Context, req *system.DeptEditReq) (err error
 			Phone:     req.Phone,
 			Email:     req.Email,
 			Status:    req.Status,
-			CreatedBy: Context().GetUserId(ctx),
+			UpdatedBy: Context().GetUserId(ctx),
 		})
 		liberr.ErrIsNil(ctx, err, "修改部门失败")
 		// 删除缓存

+ 43 - 1
internal/app/system/service/sys_post.go

@@ -14,11 +14,15 @@ import (
 	"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/service/internal/dao"
+	"github.com/tiger1103/gfast/v3/internal/app/system/service/internal/do"
 	"github.com/tiger1103/gfast/v3/library/liberr"
 )
 
 type IPost interface {
 	List(ctx context.Context, req *system.PostSearchReq) (res *system.PostSearchRes, err error)
+	Add(ctx context.Context, req *system.PostAddReq) (err error)
+	Edit(ctx context.Context, req *system.PostEditReq) (err error)
+	Delete(ctx context.Context, ids []int) (err error)
 }
 
 type postImpl struct {
@@ -32,6 +36,7 @@ func Post() IPost {
 
 // List 岗位列表
 func (s *postImpl) List(ctx context.Context, req *system.PostSearchReq) (res *system.PostSearchRes, err error) {
+	res = new(system.PostSearchRes)
 	err = g.Try(func() {
 		m := dao.SysPost.Ctx(ctx)
 		if req != nil {
@@ -53,9 +58,46 @@ func (s *postImpl) List(ctx context.Context, req *system.PostSearchReq) (res *sy
 		if req.PageSize == 0 {
 			req.PageSize = consts.PageSize
 		}
-		res = new(system.PostSearchRes)
 		err = m.Page(req.PageNum, req.PageSize).Order("post_sort asc,post_id asc").Scan(&res.PostList)
 		liberr.ErrIsNil(ctx, err, "获取岗位失败")
 	})
 	return
 }
+
+func (s *postImpl) Add(ctx context.Context, req *system.PostAddReq) (err error) {
+	err = g.Try(func() {
+		_, err = dao.SysPost.Ctx(ctx).Insert(do.SysPost{
+			PostCode:  req.PostCode,
+			PostName:  req.PostName,
+			PostSort:  req.PostSort,
+			Status:    req.Status,
+			Remark:    req.Remark,
+			CreatedBy: Context().GetUserId(ctx),
+		})
+		liberr.ErrIsNil(ctx, err, "添加岗位失败")
+	})
+	return
+}
+
+func (s *postImpl) Edit(ctx context.Context, req *system.PostEditReq) (err error) {
+	err = g.Try(func() {
+		_, err = dao.SysPost.Ctx(ctx).WherePri(req.PostId).Update(do.SysPost{
+			PostCode:  req.PostCode,
+			PostName:  req.PostName,
+			PostSort:  req.PostSort,
+			Status:    req.Status,
+			Remark:    req.Remark,
+			UpdatedBy: Context().GetUserId(ctx),
+		})
+		liberr.ErrIsNil(ctx, err, "修改岗位失败")
+	})
+	return
+}
+
+func (s *postImpl) Delete(ctx context.Context, ids []int) (err error) {
+	err = g.Try(func() {
+		_, err = dao.SysPost.Ctx(ctx).Where(dao.SysPost.Columns().PostId+" in(?)", ids).Delete()
+		liberr.ErrIsNil(ctx, err, "删除失败")
+	})
+	return
+}