123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613 |
- package rcrt
- import (
- "encoding/json"
- "errors"
- "hongze/hrms_api/models/base"
- "hongze/hrms_api/models/rcrt"
- "hongze/hrms_api/models/system"
- "hongze/hrms_api/utils"
- "strings"
- "time"
- )
- // 设置一面面试结果
- func SetProcessFirstRecommend(adminInfo *system.SysAdmin, req *rcrt.ProcessFirstRecommendReq) (err error, errMsg string) {
- process := new(rcrt.Process)
- //判断流程是否存在
- processInfo, err := process.GetProcessByProcessId(req.ProcessId)
- if err != nil {
- if err == utils.ErrNoRow {
- errMsg = "流程不存在或者已经被删除"
- err = errors.New(errMsg + "Err:" + err.Error())
- return
- }
- errMsg = "查询招聘流程出错"
- err = errors.New(errMsg + "Err:" + err.Error())
- return
- }
- //判断招聘流程状态
- if processInfo.Status >= utils.RcrtProcessStatusWaitSecondResult {
- errMsg = "一面信息已确认,不允许修改"
- err = errors.New(errMsg)
- return
- }
- //更新招聘流程
- updateStr := []string{"first_admin_id", "first_time", "first_recommend", "first_detail", "first_remark", "first_result_admin_id", "status", "first_result", "first_result_time"}
- processInfo.FirstTime, _ = time.ParseInLocation(utils.FormatDate, req.FirstTime, time.Local)
- processInfo.FirstDetail = req.FirstDetail
- processInfo.FirstRecommend = req.FirstRecommend
- processInfo.FirstRemark = req.FirstRemark
- processInfo.FirstAdminId = adminInfo.AdminId
- //根据一面建议结果,来处理
- if req.FirstRecommend == 1 {
- processInfo.Status = utils.RcrtProcessStatusWaitSecondResult
- } else {
- processInfo.Status = utils.RcrtProcessStatusOut
- }
- processInfo.FirstResult = req.FirstRecommend
- processInfo.FirstResultAdminId = adminInfo.AdminId
- processInfo.FirstResultTime = time.Now()
- err = processInfo.Update(updateStr)
- if err != nil {
- errMsg = "更新招聘流程出错"
- err = errors.New(errMsg + "Err:" + err.Error())
- return
- }
- //添加淘汰简历
- if req.FirstRecommend != 1 {
- //如果更新简历为淘汰状态,则新增淘汰简历
- outCv := new(rcrt.OutCv)
- //判断淘汰简历是否已存在
- _, err = outCv.GetOutCvByCvId(processInfo.CvId)
- if err != nil {
- if err == utils.ErrNoRow {
- err = nil
- } else {
- errMsg = "查询淘汰简历出错"
- err = errors.New(errMsg + "Err:" + err.Error())
- return
- }
- } else {
- //该流程已存在
- errMsg = "该淘汰简历已存在"
- err = errors.New(errMsg)
- return
- }
- cv := new(rcrt.Cv)
- //判断简历是否存在
- cvInfo, tErr := cv.GetCvByCvId(processInfo.CvId)
- if tErr != nil {
- if tErr == utils.ErrNoRow {
- errMsg = "简历不存在或者已经被删除"
- err = errors.New(errMsg + "Err:" + tErr.Error())
- return
- }
- errMsg = "查询简历出错"
- err = errors.New(errMsg + "Err:" + tErr.Error())
- return
- }
- //新增淘汰简历
- var processStage int8
- if processInfo.ThirdResultAdminId > 0 {
- processStage = 3
- } else if processInfo.SecondAdminId > 0 {
- processStage = 2
- } else if processInfo.FirstAdminId > 0 {
- processStage = 1
- }
- outCv.CvId = cvInfo.CvId
- outCv.CvName = cvInfo.CvName
- outCv.CvTitle = cvInfo.CvTitle
- outCv.CvUrl = cvInfo.CvUrl
- outCv.CvFileName = cvInfo.CvFileName
- outCv.Position = cvInfo.Position
- outCv.AdminId = adminInfo.AdminId
- outCv.OutStage = 2
- outCv.OutTime = time.Now()
- outCv.ProcessId = processInfo.ProcessId
- outCv.ProcessStage = processStage
- outCv.Enabled = 1
- err = outCv.Add()
- if err != nil {
- errMsg = "添加淘汰简历出错"
- err = errors.New(errMsg + "Err:" + err.Error())
- return
- }
- }
- return
- }
- // 设置二面面试结果
- func SetProcessSecondRecommend(adminInfo *system.SysAdmin, req *rcrt.ProcessSecondRecommendReq) (err error, errMsg string) {
- process := new(rcrt.Process)
- //判断流程是否存在
- processInfo, err := process.GetProcessByProcessId(req.ProcessId)
- if err != nil {
- if err == utils.ErrNoRow {
- errMsg = "流程不存在或者已经被删除"
- err = errors.New(errMsg + "Err:" + err.Error())
- return
- }
- errMsg = "查询招聘流程出错"
- err = errors.New(errMsg + "Err:" + err.Error())
- return
- }
- //判断招聘流程状态
- if processInfo.Status >= utils.RcrtProcessStatusWaitThirdResult {
- errMsg = "二面信息已确认,不允许修改"
- err = errors.New(errMsg)
- return
- }
- //更新招聘流程
- updateStr := []string{"second_admin_id", "second_time", "second_recommend", "second_video_url", "person_test"}
- processInfo.SecondTime, _ = time.ParseInLocation(utils.FormatDate, req.SecondTime, time.Local)
- processInfo.SecondVideoUrl = req.SecondVideoUrl
- processInfo.SecondRecommend = req.SecondRecommend
- processInfo.SecondAdminId = adminInfo.AdminId
- processInfo.PersonTest = req.PersonTest
- err = processInfo.Update(updateStr)
- if err != nil {
- errMsg = "更新招聘流程出错"
- err = errors.New(errMsg + "Err:" + err.Error())
- return
- }
- return
- }
- // 确认一面结果/确认二面结果
- func SetProcessResult(adminInfo *system.SysAdmin, req *rcrt.ProcessResultReq) (err error, errMsg string) {
- process := new(rcrt.Process)
- //判断流程是否存在
- processInfo, err := process.GetProcessByProcessId(req.ProcessId)
- if err != nil {
- if err == utils.ErrNoRow {
- errMsg = "流程不存在或者已经被删除"
- err = errors.New(errMsg + "Err:" + err.Error())
- return
- }
- errMsg = "查询招聘流程出错"
- err = errors.New(errMsg + "Err:" + err.Error())
- return
- }
- //判断招聘流程状态
- if processInfo.Status != utils.RcrtProcessStatusWaitSecondResult && processInfo.Status != utils.RcrtProcessStatusWaitFirstResult && processInfo.Status != utils.RcrtProcessStatusWaitThirdResult {
- errMsg = "不是待确认状态,不允许修改"
- err = errors.New(errMsg)
- return
- }
- //更新招聘流程
- var updateStr []string
- var outStage int8
- if processInfo.Status == utils.RcrtProcessStatusWaitFirstResult {
- if req.Stage > 0 && req.Stage != 1 {
- errMsg = "操作失败:只允许一面确认操作"
- err = errors.New(errMsg)
- return
- }
- updateStr = []string{"first_result_admin_id", "status", "first_result", "first_result_time"}
- if req.Status == 1 {
- processInfo.Status = utils.RcrtProcessStatusWaitSecondResult
- } else {
- outStage = 2
- processInfo.Status = utils.RcrtProcessStatusOut
- }
- processInfo.FirstResult = req.Status
- processInfo.FirstResultAdminId = adminInfo.AdminId
- processInfo.FirstResultTime = time.Now()
- } else if processInfo.Status == utils.RcrtProcessStatusWaitSecondResult {
- if req.Stage > 0 && req.Stage != 2 {
- errMsg = "操作失败:只允许二面确认操作"
- err = errors.New(errMsg)
- return
- }
- updateStr = []string{"second_result_admin_id", "status", "second_result", "second_result_time"}
- if req.Status == 1 {
- processInfo.Status = utils.RcrtProcessStatusWaitThirdResult
- } else {
- outStage = 3
- processInfo.Status = utils.RcrtProcessStatusOut
- }
- processInfo.SecondResult = req.Status
- processInfo.SecondResultAdminId = adminInfo.AdminId
- processInfo.SecondResultTime = time.Now()
- } else {
- if req.Stage > 0 && req.Stage != 3 {
- errMsg = "操作失败:只允许三面确认操作"
- err = errors.New(errMsg)
- return
- }
- updateStr = []string{"third_result_admin_id", "status", "third_result", "third_result_time"}
- if req.Status == 1 {
- processInfo.Status = utils.RcrtProcessStatusWPass
- } else {
- outStage = 4
- processInfo.Status = utils.RcrtProcessStatusOut
- }
- processInfo.ThirdResult = req.Status
- processInfo.ThirdResultAdminId = adminInfo.AdminId
- processInfo.ThirdResultTime = time.Now()
- }
- err = processInfo.Update(updateStr)
- if err != nil {
- errMsg = "更新招聘流程出错"
- err = errors.New(errMsg + "Err:" + err.Error())
- return
- }
- //添加淘汰简历
- if req.Status == 2 {
- //如果更新简历为淘汰状态,则新增淘汰简历
- outCv := new(rcrt.OutCv)
- //判断淘汰简历是否已存在
- _, err = outCv.GetOutCvByCvId(processInfo.CvId)
- if err != nil {
- if err == utils.ErrNoRow {
- err = nil
- } else {
- errMsg = "查询淘汰简历出错"
- err = errors.New(errMsg + "Err:" + err.Error())
- return
- }
- } else {
- //该流程已存在
- errMsg = "该淘汰简历已存在"
- err = errors.New(errMsg)
- return
- }
- cv := new(rcrt.Cv)
- //判断简历是否存在
- cvInfo, tErr := cv.GetCvByCvId(processInfo.CvId)
- if tErr != nil {
- if tErr == utils.ErrNoRow {
- errMsg = "简历不存在或者已经被删除"
- err = errors.New(errMsg + "Err:" + tErr.Error())
- return
- }
- errMsg = "查询简历出错"
- err = errors.New(errMsg + "Err:" + tErr.Error())
- return
- }
- var processStage int8
- if processInfo.ThirdResultAdminId > 0 {
- processStage = 3
- } else if processInfo.SecondAdminId > 0 {
- processStage = 2
- } else if processInfo.FirstAdminId > 0 {
- processStage = 1
- }
- //新增招聘流程
- outCv.CvId = cvInfo.CvId
- outCv.CvName = cvInfo.CvName
- outCv.CvTitle = cvInfo.CvTitle
- outCv.CvUrl = cvInfo.CvUrl
- outCv.CvFileName = cvInfo.CvFileName
- outCv.Position = cvInfo.Position
- outCv.AdminId = adminInfo.AdminId
- outCv.OutStage = outStage
- outCv.ProcessId = processInfo.ProcessId
- outCv.ProcessStage = processStage
- outCv.Enabled = 1
- outCv.OutTime = time.Now()
- outCv.ProcessId = processInfo.ProcessId
- err = outCv.Add()
- if err != nil {
- errMsg = "添加淘汰简历出错"
- err = errors.New(errMsg + "Err:" + err.Error())
- return
- }
- }
- return
- }
- // SetProcessCancel 取消面试
- func SetProcessCancel(adminInfo *system.SysAdmin, req *rcrt.ProcessDelReq) (err error, errMsg string) {
- //查询流程简历是否存在
- process := new(rcrt.Process)
- //判断流程是否存在
- processInfo, err := process.GetProcessByProcessId(req.ProcessId)
- if err != nil {
- if err == utils.ErrNoRow {
- errMsg = "流程不存在或者已经被删除"
- err = errors.New(errMsg + "Err:" + err.Error())
- return
- }
- errMsg = "查询招聘流程出错"
- err = errors.New(errMsg + "Err:" + err.Error())
- return
- }
- //判断招聘流程状态
- if processInfo.Status == utils.RcrtProcessStatusOut {
- errMsg = "该简历已被淘汰,无法取消"
- err = errors.New(errMsg)
- return
- } else if processInfo.Status == utils.RcrtProcessStatusWPass {
- errMsg = "该简历已通过,无法取消"
- err = errors.New(errMsg)
- return
- }
- updateStr := []string{"status"}
- processInfo.Status = utils.RcrtProcessStatusOut
- //更新流程简历为
- err = processInfo.Update(updateStr)
- if err != nil {
- errMsg = "更新招聘流程出错"
- err = errors.New(errMsg + "Err:" + err.Error())
- return
- }
- //添加到淘汰简历列表
- //如果更新简历为淘汰状态,则新增淘汰简历
- outCv := new(rcrt.OutCv)
- //判断淘汰简历是否已存在
- _, err = outCv.GetOutCvByCvId(processInfo.CvId)
- if err != nil {
- if err == utils.ErrNoRow {
- err = nil
- } else {
- errMsg = "查询淘汰简历出错"
- err = errors.New(errMsg + "Err:" + err.Error())
- return
- }
- } else {
- //该流程已存在
- errMsg = "该淘汰简历已存在"
- err = errors.New(errMsg)
- return
- }
- var processStage int8
- if processInfo.ThirdResultAdminId > 0 {
- processStage = 3
- } else if processInfo.SecondAdminId > 0 {
- processStage = 2
- } else if processInfo.FirstAdminId > 0 {
- processStage = 1
- }
- cv := new(rcrt.Cv)
- //判断简历是否存在
- cvInfo, tErr := cv.GetCvByCvId(processInfo.CvId)
- if tErr != nil {
- if tErr == utils.ErrNoRow {
- errMsg = "简历不存在或者已经被删除"
- err = errors.New(errMsg + "Err:" + tErr.Error())
- return
- }
- errMsg = "查询简历出错"
- err = errors.New(errMsg + "Err:" + tErr.Error())
- return
- }
- //新增招聘流程
- outCv.CvId = cvInfo.CvId
- outCv.CvName = cvInfo.CvName
- outCv.CvTitle = cvInfo.CvTitle
- outCv.CvUrl = cvInfo.CvUrl
- outCv.CvFileName = cvInfo.CvFileName
- outCv.Position = cvInfo.Position
- outCv.AdminId = adminInfo.AdminId
- outCv.OutStage = 0
- outCv.ProcessId = processInfo.ProcessId
- outCv.OutTime = time.Now()
- outCv.ProcessId = processInfo.ProcessId
- outCv.ProcessStage = processStage
- outCv.Enabled = 1
- err = outCv.Add()
- if err != nil {
- errMsg = "添加淘汰简历出错"
- err = errors.New(errMsg + "Err:" + err.Error())
- return
- }
- return
- }
- // ResetProcess 重置面试流程
- func ResetProcess(adminInfo *system.SysAdmin, cvId, processId int64, stage int8) (err error, errMsg string) {
- process := new(rcrt.Process)
- var processInfo *rcrt.Process
- isUpdateProcessInfo := false //是否更新流程简历
- if processId > 0 {
- isUpdateProcessInfo = true
- //判断流程是否存在
- processInfo, err = process.GetProcessByProcessId(processId)
- if err != nil {
- if err == utils.ErrNoRow {
- errMsg = "流程不存在或者已经被删除"
- err = errors.New(errMsg + "Err:" + err.Error())
- return
- }
- errMsg = "查询招聘流程出错"
- err = errors.New(errMsg + "Err:" + err.Error())
- return
- }
- } else {
- cv := new(rcrt.Cv)
- //判断简历是否存在
- cvInfo, tmpErr := cv.GetCvByCvId(cvId)
- if tmpErr != nil {
- if err == utils.ErrNoRow {
- errMsg = "简历不存在或者已经被删除"
- err = errors.New(errMsg + "Err:" + tmpErr.Error())
- return
- }
- errMsg = "查询简历出错"
- err = errors.New(errMsg + "Err:" + tmpErr.Error())
- return
- }
- //判断简历状态
- if cvInfo.Status == 0 {
- errMsg = "简历状态异常, 不允许重复设置"
- err = errors.New(errMsg)
- return
- }
- //更新简历
- cvInfo.Status = 1
- cvInfo.ResultAdminId = adminInfo.AdminId
- err = cvInfo.Update([]string{"status", "result_admin_id"})
- if err != nil {
- errMsg = "更新简历出错"
- err = errors.New(errMsg + "Err:" + err.Error())
- return
- }
- {
- outCv := new(rcrt.OutCv)
- outCvInfo, tmpErr := outCv.GetOutCvByCvId(cvId)
- if tmpErr != nil {
- if tmpErr != utils.ErrNoRow {
- errMsg = "查询淘汰简历出错"
- err = errors.New(errMsg + "Err:" + tmpErr.Error())
- return
- }
- }
- //更新淘汰简历
- if outCvInfo != nil {
- outCvInfo.Enabled = 0
- err = outCvInfo.Update([]string{"enabled"})
- if err != nil {
- errMsg = "更新淘汰简历出错"
- err = errors.New(errMsg + "Err:" + err.Error())
- return
- }
- }
- }
- //新增/查找对应的流程数据
- {
- process := new(rcrt.Process)
- //判断简历流程是否已存在
- processInfo, err = process.GetProcessByCvId(cvId)
- if err != nil {
- if err != utils.ErrNoRow {
- errMsg = "查询招聘流程出错"
- err = errors.New(errMsg + "Err:" + err.Error())
- return
- }
- //新增招聘流程
- processInfo = &rcrt.Process{
- CvId: cvId,
- CvName: cvInfo.CvName,
- HrEmailId: cvInfo.HrEmailId,
- CvUrl: cvInfo.CvUrl,
- CvTitle: cvInfo.CvTitle,
- CvFileName: cvInfo.CvFileName,
- }
- err = processInfo.Add()
- if err != nil {
- errMsg = "重置招聘流程出错"
- err = errors.New(errMsg + "Err:" + err.Error())
- return
- }
- } else {
- isUpdateProcessInfo = true
- }
- }
- }
- // 判断是否需要变更流程简历
- if isUpdateProcessInfo {
- //判断招聘流程状态
- if processInfo.Status != utils.RcrtProcessStatusWaitSecondResult && processInfo.Status != utils.RcrtProcessStatusWaitThirdResult && processInfo.Status != utils.RcrtProcessStatusOut {
- errMsg = "不是待二面结果、待三面结果、已淘汰状态,不允许重置"
- err = errors.New(errMsg)
- return
- }
- //更新招聘流程
- updateStr := []string{"status"}
- processInfo.Status = stage - 1
- switch stage {
- case 1:
- if processInfo.FirstAdminId == 0 {
- errMsg = `当前状态异常,不允许重置`
- err = errors.New(errMsg)
- return
- }
- processInfo.FirstResult = 0
- processInfo.FirstRecommend = 0
- updateStr = append(updateStr, "first_result", "first_recommend")
- case 2:
- if processInfo.SecondAdminId == 0 {
- errMsg = `当前状态异常,不允许重置`
- err = errors.New(errMsg)
- return
- }
- processInfo.SecondResult = 0
- updateStr = append(updateStr, "second_result")
- case 3:
- if processInfo.ThirdResultAdminId == 0 {
- errMsg = `当前状态异常,不允许重置`
- err = errors.New(errMsg)
- return
- }
- processInfo.ThirdResult = 0
- updateStr = append(updateStr, "third_result")
- }
- err = processInfo.Update(updateStr)
- if err != nil {
- errMsg = "重置招聘流程出错"
- err = errors.New(errMsg + "Err:" + err.Error())
- return
- }
- }
- return
- }
- func DealPersonTest() (err error) {
- page := new(base.Page)
- page.SetPageSize(1000)
- page.SetCurrent(1)
- item := new(rcrt.Process)
- var pars []interface{}
- condition := ` p.first_detail like "%性格%"`
- var tmpList []*rcrt.ProcessListTmpItem
- _, tmpList, err = item.SelectPage(page, condition, pars)
- if err != nil {
- err = errors.New("获取失败,Err:"+err.Error())
- return
- }
- if len(tmpList) == 0 {
- return
- }
- for _, v1 := range tmpList {
- tmpItem := new(rcrt.Process)
- tmpItem = &v1.Process
- contentMap := make(map[string]interface{})
- newFirstDetail := v1.FirstDetail
- newPersonTest := ""
- //json转为map数据结构
- err = json.Unmarshal([]byte(v1.FirstDetail), &contentMap)
- for k2, v2 := range contentMap {
- if k2 == "性格" {
- switch v2.(type) {
- case string:
- newPersonTest = v2.(string)
- }
- break
- }
- }
- if newPersonTest != "" {
- pos := strings.Index(newFirstDetail, `"性格`)
- newFirstDetail = string([]byte(newFirstDetail)[0:pos-1])
- newFirstDetail +="}"
- //更新性格字段和一面详情字段, 更新性格字段为v2
- updateStr := []string{"first_detail", "person_test"}
- tmpItem.FirstDetail = newFirstDetail
- tmpItem.PersonTest = newPersonTest
- err = tmpItem.Update(updateStr)
- if err != nil {
- err = errors.New("更新性格字段失败,Err:"+err.Error())
- return
- }
- }
- }
- return
- }
|