hr_email.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. package rcrt
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "github.com/go-playground/validator/v10"
  5. "hongze/hrms_api/controller/resp"
  6. "hongze/hrms_api/global"
  7. "hongze/hrms_api/models/base"
  8. "hongze/hrms_api/models/rcrt"
  9. rcrtService "hongze/hrms_api/services/rcrt"
  10. "hongze/hrms_api/utils"
  11. "strings"
  12. )
  13. type HrEmailController struct {}
  14. func (e *HrEmailController) List(c *gin.Context) {
  15. req := new(rcrt.HrEmailListReq)
  16. err := c.BindQuery(&req)
  17. if err != nil {
  18. errs, ok := err.(validator.ValidationErrors)
  19. if !ok {
  20. resp.FailData("参数解析失败", "Err:"+err.Error(), c)
  21. return
  22. }
  23. resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
  24. return
  25. }
  26. page := new(base.Page)
  27. page.SetPageSize(req.PageSize)
  28. page.SetCurrent(req.Current)
  29. item := new(rcrt.HrEmail)
  30. condition := "1=1"
  31. var pars []interface{}
  32. var total int64
  33. var tmpList []*rcrt.HrEmailListTmpItem
  34. list := make([]*rcrt.HrEmailListItem, 0)
  35. if req.HrAdminIds != "" {
  36. adminIds := strings.Split(req.HrAdminIds,",")
  37. condition += " and a.admin_id in ?"
  38. pars = append(pars, adminIds)
  39. }
  40. total, tmpList, err = item.SelectPage(page, condition, pars)
  41. if err != nil {
  42. resp.FailMsg("获取失败", "获取失败,Err:"+err.Error(), c)
  43. return
  44. }
  45. if len(tmpList) > 0 {
  46. for _, v := range tmpList {
  47. tmp := &rcrt.HrEmailListItem{
  48. HrEmailId: v.HrEmailId,
  49. AdminId: v.AdminId,
  50. Email: v.Email,
  51. EmailPwd: v.EmailPwd,
  52. AdminName: v.AdminName,
  53. CreateTime: utils.TimeTransferString(utils.FormatDateTime, v.CreateTime),
  54. ModifyTime: utils.TimeTransferString(utils.FormatDateTime, v.ModifyTime),
  55. }
  56. list = append(list, tmp)
  57. }
  58. }
  59. page.SetTotal(total)
  60. baseData := new(base.BaseData)
  61. baseData.SetPage(page)
  62. baseData.SetList(list)
  63. resp.OkData("获取成功", baseData, c)
  64. }
  65. func (e *HrEmailController) Add(c *gin.Context) {
  66. req := new(rcrt.HrEmailAddReq)
  67. err := c.ShouldBind(&req)
  68. if err != nil {
  69. errs, ok := err.(validator.ValidationErrors)
  70. if !ok {
  71. resp.FailData("参数解析失败", "Err:"+err.Error(), c)
  72. return
  73. }
  74. resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
  75. return
  76. }
  77. err, errMsg := rcrtService.HrEmailAdd(req)
  78. if err != nil {
  79. resp.FailMsg(errMsg, err.Error(), c)
  80. return
  81. }
  82. resp.Ok("添加成功", c)
  83. return
  84. }
  85. func (e *HrEmailController) Edit(c *gin.Context) {
  86. req := new(rcrt.HrEmailEditReq)
  87. err := c.ShouldBind(&req)
  88. if err != nil {
  89. errs, ok := err.(validator.ValidationErrors)
  90. if !ok {
  91. resp.FailData("参数解析失败", "Err:"+err.Error(), c)
  92. return
  93. }
  94. resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
  95. return
  96. }
  97. err, errMsg := rcrtService.HrEmailEdit(req)
  98. if err != nil {
  99. resp.FailMsg(errMsg, err.Error(), c)
  100. return
  101. }
  102. resp.Ok("编辑成功", c)
  103. return
  104. }
  105. // Delete 简历
  106. func (e *HrEmailController) Delete(c *gin.Context) {
  107. req := new(rcrt.HrEmailDelReq)
  108. err := c.ShouldBind(&req)
  109. if err != nil {
  110. resp.FailData("参数解析失败", "Err:"+err.Error(), c)
  111. return
  112. }
  113. item := new(rcrt.HrEmail)
  114. //判断简历是否存在
  115. hrEmailInfo, err := item.GetHrEmailById(req.HrEmailId)
  116. if err != nil {
  117. if err == utils.ErrNoRow {
  118. resp.Fail("邮箱不存在不存在或者已经被删除", c)
  119. return
  120. }
  121. resp.FailMsg("查询邮箱出错", "Err:"+err.Error(), c)
  122. return
  123. }
  124. err = hrEmailInfo.Delete()
  125. if err != nil {
  126. resp.FailMsg("删除失败", "删除失败,Err:"+err.Error(), c)
  127. return
  128. }
  129. resp.Ok("删除成功", c)
  130. }