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/base" "hongze/hrms_api/models/rcrt" rcrtService "hongze/hrms_api/services/rcrt" "hongze/hrms_api/utils" "strings" ) type HrEmailController struct {} func (e *HrEmailController) List(c *gin.Context) { req := new(rcrt.HrEmailListReq) err := c.BindQuery(&req) if err != nil { errs, ok := err.(validator.ValidationErrors) if !ok { resp.FailData("参数解析失败", "Err:"+err.Error(), c) return } resp.FailData("参数解析失败", errs.Translate(global.Trans), c) return } page := new(base.Page) page.SetPageSize(req.PageSize) page.SetCurrent(req.Current) item := new(rcrt.HrEmail) condition := "1=1" var pars []interface{} var total int64 var tmpList []*rcrt.HrEmailListTmpItem list := make([]*rcrt.HrEmailListItem, 0) if req.HrAdminIds != "" { adminIds := strings.Split(req.HrAdminIds,",") condition += " and a.admin_id in ?" pars = append(pars, adminIds) } total, tmpList, err = item.SelectPage(page, condition, pars) if err != nil { resp.FailMsg("获取失败", "获取失败,Err:"+err.Error(), c) return } if len(tmpList) > 0 { for _, v := range tmpList { tmp := &rcrt.HrEmailListItem{ HrEmailId: v.HrEmailId, AdminId: v.AdminId, Email: v.Email, EmailPwd: v.EmailPwd, AdminName: v.AdminName, CreateTime: utils.TimeTransferString(utils.FormatDateTime, v.CreateTime), ModifyTime: utils.TimeTransferString(utils.FormatDateTime, v.ModifyTime), } list = append(list, tmp) } } page.SetTotal(total) baseData := new(base.BaseData) baseData.SetPage(page) baseData.SetList(list) resp.OkData("获取成功", baseData, c) } func (e *HrEmailController) Add(c *gin.Context) { req := new(rcrt.HrEmailAddReq) err := c.ShouldBind(&req) if err != nil { errs, ok := err.(validator.ValidationErrors) if !ok { resp.FailData("参数解析失败", "Err:"+err.Error(), c) return } resp.FailData("参数解析失败", errs.Translate(global.Trans), c) return } err, errMsg := rcrtService.HrEmailAdd(req) if err != nil { resp.FailMsg(errMsg, err.Error(), c) return } resp.Ok("添加成功", c) return } func (e *HrEmailController) Edit(c *gin.Context) { req := new(rcrt.HrEmailEditReq) err := c.ShouldBind(&req) if err != nil { errs, ok := err.(validator.ValidationErrors) if !ok { resp.FailData("参数解析失败", "Err:"+err.Error(), c) return } resp.FailData("参数解析失败", errs.Translate(global.Trans), c) return } err, errMsg := rcrtService.HrEmailEdit(req) if err != nil { resp.FailMsg(errMsg, err.Error(), c) return } resp.Ok("编辑成功", c) return } // Delete 简历 func (e *HrEmailController) Delete(c *gin.Context) { req := new(rcrt.HrEmailDelReq) err := c.ShouldBind(&req) if err != nil { resp.FailData("参数解析失败", "Err:"+err.Error(), c) return } item := new(rcrt.HrEmail) //判断简历是否存在 hrEmailInfo, err := item.GetHrEmailById(req.HrEmailId) if err != nil { if err == utils.ErrNoRow { resp.Fail("邮箱不存在不存在或者已经被删除", c) return } resp.FailMsg("查询邮箱出错", "Err:"+err.Error(), c) return } err = hrEmailInfo.Delete() if err != nil { resp.FailMsg("删除失败", "删除失败,Err:"+err.Error(), c) return } resp.Ok("删除成功", c) }