description.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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/rcrt"
  8. "hongze/hrms_api/models/system"
  9. "hongze/hrms_api/utils"
  10. )
  11. type DescriptionController struct {}
  12. func (d *DescriptionController) Add(c *gin.Context) {
  13. req := new(rcrt.DescriptionAddReq)
  14. err := c.ShouldBind(&req)
  15. if err != nil {
  16. errs, ok := err.(validator.ValidationErrors)
  17. if !ok {
  18. resp.FailData("参数解析失败", "Err:"+err.Error(), c)
  19. return
  20. }
  21. errDataMap := errs.Translate(global.Trans)
  22. var errMsg string
  23. for _, v := range errDataMap {
  24. errMsg = v
  25. break
  26. }
  27. resp.Fail("参数解析失败"+errMsg, c)
  28. return
  29. }
  30. claims, _ := c.Get("adminInfo")
  31. adminInfo := claims.(*system.SysAdmin)
  32. item := new(rcrt.Description)
  33. item.Content = req.Content
  34. item.AdminId = adminInfo.AdminId
  35. item.RealName = adminInfo.RealName
  36. err = item.Add()
  37. if err != nil {
  38. resp.FailMsg("操作失败", err.Error(), c)
  39. return
  40. }
  41. resp.Ok("操作成功", c)
  42. return
  43. }
  44. func (d *DescriptionController) GetLatest(c *gin.Context) {
  45. item := new(rcrt.Description)
  46. item, err := item.GetLatest()
  47. var data rcrt.DescriptionLatestResp
  48. if err != nil {
  49. if err == utils.ErrNoRow {
  50. resp.OkData("查询成功", data, c)
  51. return
  52. }
  53. resp.FailMsg("查询失败", err.Error(), c)
  54. return
  55. }
  56. data.Content = item.Content
  57. data.AdminId = item.AdminId
  58. data.RealName = item.RealName
  59. data.ModifyTime = item.ModifyTime.Format(utils.FormatDateTime)
  60. resp.OkData("查询成功", data, c)
  61. return
  62. }