hr_email.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package rcrt
  2. import (
  3. "errors"
  4. "hongze/hrms_api/models/rcrt"
  5. "hongze/hrms_api/utils"
  6. )
  7. func HrEmailAdd(req *rcrt.HrEmailAddReq) (err error, errMsg string) {
  8. item := new(rcrt.HrEmail)
  9. //判断邮箱是否已绑定
  10. _, err = item.GetHrEmailByEmail(req.Email)
  11. if err != nil {
  12. if err ==utils.ErrNoRow {
  13. err = nil
  14. }else{
  15. errMsg = "查询hr邮箱出错"
  16. err = errors.New(errMsg+"Err:" + err.Error())
  17. return
  18. }
  19. }else{
  20. //该流程已存在
  21. errMsg = "该邮箱已存在"
  22. err = errors.New(errMsg)
  23. return
  24. }
  25. // todo 校验邮箱密码是否正确
  26. //添加邮箱
  27. item.Email = req.Email
  28. item.AdminId = req.AdminId
  29. item.EmailPwd = req.EmailPwd
  30. err = item.Add()
  31. if err !=nil {
  32. errMsg = "添加邮箱出错"
  33. err = errors.New(errMsg+"Err:" + err.Error())
  34. return
  35. }
  36. return
  37. }
  38. func HrEmailEdit(req *rcrt.HrEmailEditReq) (err error, errMsg string) {
  39. item := new(rcrt.HrEmail)
  40. //判断邮箱是否存在
  41. info, err := item.GetHrEmailById(req.HrEmailId)
  42. if err != nil {
  43. if err == utils.ErrNoRow {
  44. errMsg = "该邮箱不存在或者已经被删除"
  45. err = errors.New(errMsg+"Err:" + err.Error())
  46. return
  47. }
  48. errMsg = "查询邮箱出错"
  49. err = errors.New(errMsg+"Err:" + err.Error())
  50. return
  51. }
  52. //判断邮箱是否已绑定
  53. var updateStr []string
  54. if info.Email != req.Email {
  55. _, err = item.GetHrEmailByEmail(req.Email)
  56. if err != nil {
  57. if err ==utils.ErrNoRow {
  58. err = nil
  59. }else{
  60. errMsg = "查询hr邮箱出错"
  61. err = errors.New(errMsg+"Err:" + err.Error())
  62. return
  63. }
  64. }else{
  65. //该流程已存在
  66. errMsg = "该邮箱已存在"
  67. err = errors.New(errMsg)
  68. return
  69. }
  70. // todo 校验邮箱密码是否正确
  71. updateStr = append(updateStr, "email")
  72. }
  73. if info.EmailPwd != req.EmailPwd {
  74. updateStr = append(updateStr, "email_pwd")
  75. }
  76. if info.AdminId != req.AdminId {
  77. updateStr = append(updateStr, "admin_id")
  78. }
  79. if len(updateStr) == 0 {
  80. return
  81. }
  82. //添加邮箱
  83. info.Email = req.Email
  84. info.AdminId = req.AdminId
  85. info.EmailPwd = req.EmailPwd
  86. err = info.Update(updateStr)
  87. if err !=nil {
  88. errMsg = "更新邮箱出错"
  89. err = errors.New(errMsg+"Err:" + err.Error())
  90. return
  91. }
  92. return
  93. }