sys_post.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. // ============================================================================
  2. // This is auto-generated by gf cli tool only once. Fill this file as you wish.
  3. // ============================================================================
  4. package sys_post
  5. import (
  6. "database/sql"
  7. "gfast/library/service"
  8. "github.com/gogf/gf/database/gdb"
  9. "github.com/gogf/gf/errors/gerror"
  10. "github.com/gogf/gf/frame/g"
  11. "github.com/gogf/gf/os/gtime"
  12. )
  13. // Fill with you ideas below.
  14. type Post struct {
  15. Entity
  16. SearchValue interface{} `json:"searchValue"`
  17. Remark string `json:"remark"`
  18. DataScope interface{} `json:"dataScope"`
  19. Params struct{} `json:"params"`
  20. Flag bool `json:"flag"`
  21. }
  22. type SearchParams struct {
  23. PageNum int `p:"page"` //当前页码
  24. PageSize int `p:"pageSize"` //每页数
  25. PostCode string `p:"postCode"` //岗位编码
  26. PostName string `p:"postName"` //岗位名称
  27. Status string `p:"status"` //状态
  28. }
  29. type AddParams struct {
  30. PostCode string `p:"postCode" v:"required#岗位编码不能为空"`
  31. PostName string `p:"postName" v:"required#岗位名称不能为空"`
  32. PostSort int `p:"postSort" v:"required#岗位排序不能为空"`
  33. Status string `p:"status" v:"required#状态不能为空"`
  34. Remark string `p:"remark"`
  35. }
  36. type EditParams struct {
  37. PostId int64 `p:"postId" v:"required#id必须"`
  38. AddParams
  39. }
  40. func List(req *SearchParams) (total, page int, list gdb.Result, err error) {
  41. model := g.DB().Table(Table)
  42. if req != nil {
  43. if req.PostCode != "" {
  44. model.Where("post_code like ?", "%"+req.PostCode+"%")
  45. }
  46. if req.PostName != "" {
  47. model.Where("post_name like ?", "%"+req.PostName+"%")
  48. }
  49. if req.Status != "" {
  50. model.Where("status", req.Status)
  51. }
  52. }
  53. total, err = model.Count()
  54. if err != nil {
  55. g.Log().Error(err)
  56. err = gerror.New("获取总行数失败")
  57. }
  58. if req.PageNum == 0 {
  59. req.PageNum = 1
  60. }
  61. page = req.PageNum
  62. if req.PageSize == 0 {
  63. req.PageSize = service.AdminPageNum
  64. }
  65. list, err = model.Page(page, req.PageSize).All()
  66. //g.Log().Println(list)
  67. if err != nil {
  68. g.Log().Error(err)
  69. err = gerror.New("获取数据失败")
  70. return
  71. }
  72. return
  73. }
  74. //获取正常状态的岗位
  75. func GetUsedPost() (list []*Entity, err error) {
  76. list, err = Model.Where(Columns.Status, 1).Order(Columns.PostSort + " ASC, " + Columns.PostId + " ASC ").All()
  77. if err != nil {
  78. g.Log().Error(err)
  79. err = gerror.New("获取岗位数据失败")
  80. }
  81. return
  82. }
  83. /**
  84. 添加
  85. */
  86. func Add(addParams *AddParams) (result sql.Result, err error) {
  87. //g.Log().Println(addParams)
  88. entity := &Entity{
  89. PostCode: addParams.PostCode,
  90. PostName: addParams.PostName,
  91. PostSort: addParams.PostSort,
  92. Status: addParams.Status,
  93. Remark: addParams.Remark,
  94. CreateBy: "",
  95. CreateTime: gtime.Now(),
  96. }
  97. return entity.Save()
  98. }
  99. func Edit(editParams *EditParams) (result sql.Result, err error) {
  100. entity := &Entity{
  101. PostId: editParams.PostId,
  102. PostCode: editParams.PostCode,
  103. PostName: editParams.PostName,
  104. PostSort: editParams.PostSort,
  105. Status: editParams.Status,
  106. Remark: editParams.Remark,
  107. UpdateBy: "",
  108. UpdateTime: gtime.Now(),
  109. }
  110. return entity.Update()
  111. }
  112. func GetOneById(id int64) (*Entity, error) {
  113. return Model.One(g.Map{
  114. "post_id": id,
  115. })
  116. }
  117. func DeleteByIds(ids []int) error {
  118. _, err := Model.Delete("post_id IN(?)", ids)
  119. if err != nil {
  120. g.Log().Error(err)
  121. return gerror.New("删除失败")
  122. }
  123. return nil
  124. }