12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- package rcrt
- import (
- "github.com/gin-gonic/gin"
- "github.com/go-playground/validator/v10"
- "hongze/hrms_api/controller/resp"
- "hongze/hrms_api/global"
- "hongze/hrms_api/models/rcrt"
- "hongze/hrms_api/models/system"
- "hongze/hrms_api/utils"
- )
- type DescriptionController struct {}
- func (d *DescriptionController) Add(c *gin.Context) {
- req := new(rcrt.DescriptionAddReq)
- err := c.ShouldBind(&req)
- if err != nil {
- errs, ok := err.(validator.ValidationErrors)
- if !ok {
- resp.FailData("参数解析失败", "Err:"+err.Error(), c)
- return
- }
- errDataMap := errs.Translate(global.Trans)
- var errMsg string
- for _, v := range errDataMap {
- errMsg = v
- break
- }
- resp.Fail("参数解析失败"+errMsg, c)
- return
- }
- claims, _ := c.Get("adminInfo")
- adminInfo := claims.(*system.SysAdmin)
- item := new(rcrt.Description)
- item.Content = req.Content
- item.AdminId = adminInfo.AdminId
- item.RealName = adminInfo.RealName
- err = item.Add()
- if err != nil {
- resp.FailMsg("操作失败", err.Error(), c)
- return
- }
- resp.Ok("操作成功", c)
- return
- }
- func (d *DescriptionController) GetLatest(c *gin.Context) {
- item := new(rcrt.Description)
- item, err := item.GetLatest()
- var data rcrt.DescriptionLatestResp
- if err != nil {
- if err == utils.ErrNoRow {
- resp.OkData("查询成功", data, c)
- return
- }
- resp.FailMsg("查询失败", err.Error(), c)
- return
- }
- data.Content = item.Content
- data.AdminId = item.AdminId
- data.RealName = item.RealName
- data.ModifyTime = item.ModifyTime.Format(utils.FormatDateTime)
- resp.OkData("查询成功", data, c)
- return
- }
|