cv.go 3.7 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. "hongze/hrms_api/models/system"
  10. rcrtService "hongze/hrms_api/services/rcrt"
  11. "hongze/hrms_api/utils"
  12. "strings"
  13. "time"
  14. )
  15. type CvController struct {}
  16. func (cv *CvController) List(c *gin.Context) {
  17. req := new(rcrt.CvListReq)
  18. err := c.BindQuery(&req)
  19. if err != nil {
  20. errs, ok := err.(validator.ValidationErrors)
  21. if !ok {
  22. resp.FailData("参数解析失败", "Err:"+err.Error(), c)
  23. return
  24. }
  25. resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
  26. return
  27. }
  28. page := new(base.Page)
  29. page.SetPageSize(req.PageSize)
  30. page.SetCurrent(req.Current)
  31. item := new(rcrt.Cv)
  32. condition := "cv.status=0"
  33. var pars []interface{}
  34. var total int64
  35. var tmpList []*rcrt.CvListTmpItem
  36. var list []*rcrt.CvListItem
  37. if req.CreateTime != "" {
  38. createTime, _ := time.Parse(utils.FormatDate, req.CreateTime)
  39. nextTime := createTime.AddDate(0,0,1)
  40. condition += " and cv.receive_time >= ? and cv.receive_time < ?"
  41. pars = append(pars, req.CreateTime, nextTime)
  42. }
  43. if req.HrAdminIds != "" {
  44. adminIds := strings.Split(req.HrAdminIds,",")
  45. condition += " and a.admin_id in ?"
  46. pars = append(pars, adminIds)
  47. }
  48. page.AddOrderItem(base.OrderItem{Column: "cv.receive_time", Asc: false})
  49. page.AddOrderItem(base.OrderItem{Column: "cv.cv_id", Asc: false})
  50. total, tmpList, err = item.SelectPage(page, condition, pars)
  51. if err != nil {
  52. resp.FailMsg("获取失败", "获取失败,Err:"+err.Error(), c)
  53. return
  54. }
  55. if len(tmpList) > 0 {
  56. for _, v := range tmpList {
  57. tmp := &rcrt.CvListItem{
  58. CvId: v.CvId,
  59. CvTitle: v.CvTitle,
  60. CvName: v.CvName,
  61. CvFileName: v.CvFileName,
  62. CvUrl: v.CvUrl,
  63. HrEmailId: v.HrEmailId,
  64. Status: v.Status,
  65. ResultAdminId: v.ResultAdminId,
  66. HrEmail: v.HrEmail,
  67. HrName: v.HrName,
  68. HrAdminId: v.HrAdminId,
  69. Position: v.Position,
  70. CreateTime: utils.TimeTransferString(utils.FormatDateTime, v.ReceiveTime),
  71. ModifyTime: utils.TimeTransferString(utils.FormatDateTime, v.ModifyTime),
  72. }
  73. list = append(list, tmp)
  74. }
  75. }
  76. page.SetTotal(total)
  77. baseData := new(base.BaseData)
  78. baseData.SetPage(page)
  79. baseData.SetList(list)
  80. resp.OkData("获取成功", baseData, c)
  81. }
  82. // SetResult 设置初筛结果
  83. func (cv *CvController) SetResult(c *gin.Context) {
  84. req := new(rcrt.CvResultReq)
  85. err := c.ShouldBind(&req)
  86. if err != nil {
  87. errs, ok := err.(validator.ValidationErrors)
  88. if !ok {
  89. resp.FailData("参数解析失败", "Err:"+err.Error(), c)
  90. return
  91. }
  92. resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
  93. return
  94. }
  95. claims, _ := c.Get("adminInfo")
  96. adminInfo := claims.(*system.SysAdmin)
  97. err, errMsg := rcrtService.SetCvResult(adminInfo, 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 (cv *CvController) Delete(c *gin.Context) {
  107. req := new(rcrt.CvDelReq)
  108. err := c.ShouldBind(&req)
  109. if err != nil {
  110. resp.FailData("参数解析失败", "Err:"+err.Error(), c)
  111. return
  112. }
  113. item := new(rcrt.Cv)
  114. //判断简历是否存在
  115. cvInfo, err := item.GetCvByCvId(req.CvId)
  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. if cvInfo.Status != 0 {
  125. //resp.Fail("简历状态已更新,请刷新", c)
  126. resp.Ok("删除成功", c)
  127. return
  128. }
  129. err = cvInfo.Delete()
  130. if err != nil {
  131. resp.FailMsg("删除失败", "删除失败,Err:"+err.Error(), c)
  132. return
  133. }
  134. resp.Ok("删除成功", c)
  135. }