421 lines
16 KiB
Go
421 lines
16 KiB
Go
package approval
|
||
|
||
import (
|
||
"context"
|
||
"errors"
|
||
"fmt"
|
||
"strconv"
|
||
"strings"
|
||
|
||
"github.com/fonchain_enterprise/fonchain-main/api/account"
|
||
api "github.com/fonchain_enterprise/fonchain-main/api/approval"
|
||
"github.com/fonchain_enterprise/fonchain-main/api/e_card"
|
||
"github.com/fonchain_enterprise/fonchain-main/api/position"
|
||
"github.com/fonchain_enterprise/fonchain-main/api/recruit"
|
||
"github.com/fonchain_enterprise/fonchain-main/pkg/e"
|
||
"github.com/fonchain_enterprise/fonchain-main/pkg/model/login"
|
||
"github.com/fonchain_enterprise/fonchain-main/pkg/model/union"
|
||
"github.com/fonchain_enterprise/fonchain-main/pkg/serializer"
|
||
"github.com/fonchain_enterprise/fonchain-main/pkg/service"
|
||
account2 "github.com/fonchain_enterprise/fonchain-main/pkg/service/account"
|
||
"github.com/fonchain_enterprise/fonchain-main/pkg/utils/employee"
|
||
"github.com/gin-gonic/gin"
|
||
"github.com/gin-gonic/gin/binding"
|
||
)
|
||
|
||
const InitPassword = "Aa123456"
|
||
|
||
func offerApproveSetStatusEnter(c *gin.Context, userInfo login.Info, req *api.StatusRequest, detail *api.CreateRequest) (err error) {
|
||
if req.Status == e.ApprovalWorkStatusFail {
|
||
if detail.Employ.ResumeID != "" {
|
||
err = rejectOfferApprove(userInfo, req.ID, req.Reply)
|
||
if err != nil {
|
||
//service.Error(c, e.Error, err)
|
||
return err
|
||
}
|
||
}
|
||
} else if req.Status == e.ApprovalWorkStatusOk {
|
||
fmt.Println("进入offer审批通过-----:", req, detail)
|
||
if detail.Status == e.ApprovalWorkStatusOk {
|
||
if detail.Employ.ResumeID != "" {
|
||
// 老的人才招聘流程
|
||
fmt.Println("进入老的人才招聘流程-----:")
|
||
err = passOfferApproveNotFinish(userInfo, detail.ID)
|
||
if err != nil {
|
||
service.Error(c, e.Error, err)
|
||
return err
|
||
}
|
||
} else {
|
||
// 新的人才招聘流程,岗位待人数直接-1
|
||
fmt.Println("进入新的人才招聘流程,人数直接减一-----:")
|
||
err = PositionPostCountNumMinus(userInfo, detail.ID, detail.Employ)
|
||
if err != nil {
|
||
service.Error(c, e.Error, err)
|
||
return err
|
||
}
|
||
}
|
||
}
|
||
fmt.Println("offer审批通过结束-----:", req, detail)
|
||
if detail.Status == e.ApprovalWorkStatusOk && detail.Employ.ConfirmDate != "" {
|
||
fmt.Println("进入创建账号和员工档案-----:", req, detail)
|
||
err = createUsersAndFiles(c, detail)
|
||
if err != nil {
|
||
return errors.New("创建用户及员工档案失败!" + err.Error())
|
||
}
|
||
fmt.Println("员工档案创建成功-----:", req, detail)
|
||
|
||
if err != nil {
|
||
return
|
||
}
|
||
|
||
return nil
|
||
}
|
||
}
|
||
return nil
|
||
}
|
||
func createUsersAndFiles(c *gin.Context, detail *api.CreateRequest) error {
|
||
registerUser := union.User{
|
||
Domain: "fontree",
|
||
NickName: detail.Employ.Name,
|
||
TelNum: detail.Employ.Mobile,
|
||
Status: "notactive",
|
||
EnterDate: detail.Employ.ConfirmDate,
|
||
PositionUsers: nil,
|
||
JobNum: detail.Employ.EmployeeNo,
|
||
Password: e.DEFAULT_PWD,
|
||
Source: "entryApplication",
|
||
}
|
||
registerUser.Operator = &account.Operator{
|
||
ID: uint32(detail.NowUserId),
|
||
Name: detail.NowUserName,
|
||
}
|
||
registerUser.PositionUsers = make([]*position.PositionUser, 0)
|
||
positionId, err := strconv.ParseUint(detail.Employ.PositionId, 10, 64)
|
||
if err != nil {
|
||
fmt.Println("转换失败:", err)
|
||
return err
|
||
}
|
||
departmentId, err := strconv.ParseUint(detail.Employ.DepartmentId, 10, 64)
|
||
if err != nil {
|
||
fmt.Println("转换失败:", err)
|
||
return err
|
||
}
|
||
registerUser.PositionUsers = append(registerUser.PositionUsers, &position.PositionUser{PositionID: positionId, DepartmentID: departmentId})
|
||
|
||
err, user := account2.UserRegisters(c, registerUser)
|
||
if err != nil {
|
||
return err
|
||
}
|
||
ResumeProto := []*recruit.ResumeProto{
|
||
{
|
||
ResumeFile: detail.Employ.ResumeFile,
|
||
InterviewFile: detail.Employ.InterviewFile,
|
||
EmployeeType: detail.Employ.EmployeeType,
|
||
},
|
||
}
|
||
rep := &recruit.ResumeQueryListVo{
|
||
Resumes: ResumeProto,
|
||
}
|
||
//创建员工档案
|
||
err = employee.CreateAnEmployeeProfile(c, user.ID, registerUser, rep, registerUser.Operator)
|
||
if err != nil {
|
||
return err
|
||
}
|
||
|
||
// 生成员工电子名片
|
||
var addChainRequest *e_card.AddChainRequest
|
||
addChainRequest, err = account2.GetECardInfo(user.ID, "审批-人员增补申请")
|
||
if err != nil {
|
||
return err
|
||
}
|
||
|
||
fmt.Println("++++++++++++++++++++ addChainRequest =============================")
|
||
fmt.Printf("addChainRequest : %+v\n", addChainRequest)
|
||
|
||
_, err = service.ECardProvider.AddChain(context.Background(), addChainRequest)
|
||
|
||
return nil
|
||
}
|
||
|
||
func createOfferApprove(c *gin.Context, userInfo login.Info, res *api.ApprovalResponse, departmentID int64) (err error) {
|
||
|
||
createReq := api.DetailRequest{ID: res.ID}
|
||
createDetail, detailErr := service.ApprovalProvider.Detail(c, &createReq)
|
||
if detailErr != nil {
|
||
return detailErr
|
||
}
|
||
|
||
dealProcessForm := new(recruit.DealProcessProto)
|
||
dealProcessForm.Id = int64(createDetail.ID) // 审批申请的ID
|
||
dealProcessForm.Type = "offer-approve" // 人才招聘 的 类型
|
||
dealProcessForm.Command = "offer-submit"
|
||
dealProcessForm.User = &recruit.UserProto{ // 登录用户
|
||
Id: int64(userInfo.ID),
|
||
Nickname: userInfo.NickName,
|
||
}
|
||
// TODO 已确认 字段
|
||
dealProcessForm.Entity = &recruit.EntityProto{ // 入职信息
|
||
Offer: &recruit.OfferProto{
|
||
Applier: userInfo.NickName, // 申请人 昵称
|
||
Post: createDetail.Employ.Post,
|
||
ResumeFile: createDetail.Employ.ResumeFile,
|
||
BelongDepartment: createDetail.Employ.BelongDepartment,
|
||
Name: createDetail.Employ.Name,
|
||
Mobile: createDetail.Employ.Mobile,
|
||
EmployeeType: createDetail.Employ.EmployeeType,
|
||
EmployeeNo: createDetail.Employ.EmployeeNo,
|
||
InterviewFile: createDetail.Employ.InterviewFile,
|
||
EntryTime: createDetail.Employ.EntryTime,
|
||
ApproveCountLast: int32(len(createDetail.WorkFlows)),
|
||
},
|
||
}
|
||
|
||
dealProcessForm.Entity.Offer.ResumeId, _ = strconv.ParseInt(createDetail.Employ.ResumeID, 10, 64)
|
||
|
||
approver := make([]string, 0)
|
||
for i := 0; i < len(createDetail.WorkFlows); i++ {
|
||
approver = append(approver, createDetail.WorkFlows[i].Name)
|
||
dealProcessForm.Entity.Offer.ApproverIds = append(dealProcessForm.Entity.Offer.ApproverIds, int64(createDetail.WorkFlows[i].UserID)) // 审批人 ID
|
||
}
|
||
copyUsers := make([]string, 0)
|
||
for i := 0; i < len(createDetail.CopyUsers); i++ {
|
||
copyUsers = append(copyUsers, createDetail.CopyUsers[i].Name)
|
||
dealProcessForm.Entity.Offer.CopiedIds = append(dealProcessForm.Entity.Offer.CopiedIds, int64(createDetail.CopyUsers[i].ID)) // 抄送人 ID
|
||
}
|
||
dealProcessForm.Entity.Offer.Approver = strings.Join(approver, ",") // 审批人 名称
|
||
dealProcessForm.Entity.Offer.Copied = strings.Join(copyUsers, ",") // 抄送人 名称
|
||
|
||
//for i := 0; i < len(userInfo.PositionUsers); i++ {
|
||
// if departmentID == int64(userInfo.PositionUsers[i].DepartmentId) {
|
||
// dealProcessForm.Entity.Offer.BelongDepartment = userInfo.PositionUsers[i].DepartmentName // 申请人的 部门
|
||
// //dealProcessForm.Entity.Offer.ApplierPosition = userInfo.PositionUsers[i].PositionName // 申请人的 岗位
|
||
// }
|
||
//}
|
||
|
||
fmt.Println("++++++++++++++++++++ dealProcessForm =============================")
|
||
fmt.Printf("dealProcessForm : %+v\n", dealProcessForm)
|
||
fmt.Println("++++++++++++++++++++ dealProcessForm =============================")
|
||
|
||
dealProcessFormResp := new(recruit.ResultVo)
|
||
dealProcessFormResp, err = service.GrpcRecruitClientImpl.OfferSubmit(context.Background(), dealProcessForm)
|
||
if err != nil {
|
||
fmt.Println("++++++++++++++++++++ offer-submit =============================")
|
||
fmt.Printf("offer-submit : %+v\n", err)
|
||
fmt.Printf("dealProcessFormResp : %+v\n", dealProcessFormResp)
|
||
fmt.Println("++++++++++++++++++++ offer-submit =============================")
|
||
//service.Error(c, e.Error, errors.New(e.ErrorCreateOffer))
|
||
return errors.New(e.ErrorCreateOffer)
|
||
}
|
||
return returnRecruitError(dealProcessFormResp)
|
||
}
|
||
|
||
// offer审批通过,但不是最终通过,仅仅是个状态
|
||
func passOfferApproveNotFinish(userInfo login.Info, approvalID uint64) (err error) {
|
||
dealProcessForm := new(recruit.DealProcessProto)
|
||
dealProcessForm.Entity = new(recruit.EntityProto)
|
||
dealProcessForm.Entity.Detail = new(recruit.DetailProto)
|
||
dealProcessForm.User = &recruit.UserProto{ // 登录用户
|
||
Id: int64(userInfo.ID),
|
||
Nickname: userInfo.NickName,
|
||
}
|
||
dealProcessForm.Id = int64(approvalID) // 审批申请的ID
|
||
dealProcessForm.Type = "offer-approve" // 人才招聘 的 类型
|
||
dealProcessForm.Command = "offer-approval-pass"
|
||
|
||
dealProcessForm.Entity.Detail.Approver = int64(userInfo.ID)
|
||
dealProcessForm.Entity.Detail.Result = "offer审核通过"
|
||
|
||
dealProcessFormResp := new(recruit.ResultVo)
|
||
dealProcessFormResp, err = service.GrpcRecruitClientImpl.OfferPass(context.Background(), dealProcessForm)
|
||
if err != nil {
|
||
fmt.Println("++++++++++++++++++++ PostSubmit =============================")
|
||
fmt.Printf("PostSubmit : %+v\n", err)
|
||
fmt.Printf("dealProcessFormResp : %+v\n", dealProcessFormResp)
|
||
fmt.Println("++++++++++++++++++++ PostSubmit =============================")
|
||
//service.Error(c, e.Error, errors.New(e.ErrorCreateTalents))
|
||
return errors.New(e.ErrorCreateTalents)
|
||
}
|
||
return returnRecruitError(dealProcessFormResp)
|
||
}
|
||
|
||
// offer审批通过,但不是最终通过,仅仅是个状态
|
||
func PositionPostCountNumMinus(userInfo login.Info, approvalID uint64, detail *api.Employ) (err error) {
|
||
req := new(recruit.PositionFastAcceptReq)
|
||
|
||
aplyDepartmentId, err := strconv.ParseInt(detail.DepartmentId, 10, 32)
|
||
if err != nil {
|
||
fmt.Println("aplyDepartmentId转换错误:", err)
|
||
return
|
||
}
|
||
|
||
applyPositionId, err := strconv.ParseInt(detail.PositionId, 10, 32)
|
||
if err != nil {
|
||
fmt.Println("applyPositionId转换错误:", err)
|
||
return
|
||
}
|
||
|
||
req.ApplyDepartmentId = aplyDepartmentId
|
||
req.ApplyPositionId = applyPositionId
|
||
req.UpdatedId = int64(userInfo.ID)
|
||
req.UpdatedName = userInfo.NickName
|
||
|
||
resp := new(recruit.ResultVo)
|
||
resp, err = service.GrpcRecruitClientImpl.PositionFastAccept(context.Background(), req)
|
||
if err != nil {
|
||
fmt.Println("++++++++++++++++++++ PositionFastAccept =============================")
|
||
fmt.Printf("err : %+v\n", err)
|
||
fmt.Printf("resp : %+v\n", resp)
|
||
fmt.Println("++++++++++++++++++++ PositionFastAccept =============================")
|
||
//service.Error(c, e.Error, errors.New(e.ErrorCreateTalents))
|
||
return errors.New(err.Error())
|
||
}
|
||
return returnRecruitError(resp)
|
||
}
|
||
func PassOfferApprove(userInfo login.Info, approvalID uint64) (err error) {
|
||
dealProcessForm := new(recruit.DealProcessProto)
|
||
dealProcessForm.Entity = new(recruit.EntityProto)
|
||
dealProcessForm.Entity.Detail = new(recruit.DetailProto)
|
||
dealProcessForm.User = &recruit.UserProto{ // 登录用户
|
||
Id: int64(userInfo.ID),
|
||
Nickname: userInfo.NickName,
|
||
}
|
||
dealProcessForm.Id = int64(approvalID) // 审批申请的ID
|
||
dealProcessForm.Type = "offer-approve" // 人才招聘 的 类型
|
||
dealProcessForm.Command = "offer-pass"
|
||
|
||
dealProcessForm.Entity.Detail.Approver = int64(userInfo.ID)
|
||
dealProcessForm.Entity.Detail.Result = "通过"
|
||
|
||
dealProcessFormResp := new(recruit.ResultVo)
|
||
dealProcessFormResp, err = service.GrpcRecruitClientImpl.OfferPass(context.Background(), dealProcessForm)
|
||
if err != nil {
|
||
fmt.Println("++++++++++++++++++++ PostSubmit =============================")
|
||
fmt.Printf("PostSubmit : %+v\n", err)
|
||
fmt.Printf("dealProcessFormResp : %+v\n", dealProcessFormResp)
|
||
fmt.Println("++++++++++++++++++++ PostSubmit =============================")
|
||
//service.Error(c, e.Error, errors.New(e.ErrorCreateTalents))
|
||
return errors.New(e.ErrorCreateTalents)
|
||
}
|
||
return returnRecruitError(dealProcessFormResp)
|
||
}
|
||
|
||
func rejectOfferApprove(userInfo login.Info, approvalID uint64, reason string) (err error) {
|
||
dealProcessForm := new(recruit.DealProcessProto)
|
||
dealProcessForm.Entity = new(recruit.EntityProto)
|
||
dealProcessForm.Entity.Detail = new(recruit.DetailProto)
|
||
dealProcessForm.User = &recruit.UserProto{ // 登录用户
|
||
Id: int64(userInfo.ID),
|
||
Nickname: userInfo.NickName,
|
||
}
|
||
dealProcessForm.Id = int64(approvalID) // 审批申请的ID
|
||
dealProcessForm.Type = "offer-approve" // 人才招聘 的 类型
|
||
dealProcessForm.Command = "offer-reject"
|
||
|
||
dealProcessForm.Entity.Detail.Approver = int64(userInfo.ID)
|
||
dealProcessForm.Entity.Detail.Result = "不通过"
|
||
dealProcessForm.Entity.Detail.RejectReason = reason
|
||
|
||
dealProcessFormResp := new(recruit.ResultVo)
|
||
dealProcessFormResp, err = service.GrpcRecruitClientImpl.OfferReject(context.Background(), dealProcessForm)
|
||
if err != nil {
|
||
fmt.Println("++++++++++++++++++++ PostSubmit =============================")
|
||
fmt.Printf("PostSubmit : %+v\n", err)
|
||
fmt.Printf("dealProcessFormResp : %+v\n", dealProcessFormResp)
|
||
fmt.Println("++++++++++++++++++++ PostSubmit =============================")
|
||
//service.Error(c, e.Error, errors.New(e.ErrorCreateTalents))
|
||
return errors.New(e.ErrorCreateTalents)
|
||
}
|
||
return returnRecruitError(dealProcessFormResp)
|
||
}
|
||
|
||
func checkOfferApprove(userInfo login.Info, approvalID uint64) (err error) {
|
||
dealProcessForm := new(recruit.DealProcessProto)
|
||
dealProcessForm.Entity = new(recruit.EntityProto)
|
||
dealProcessForm.Entity.Copied = new(recruit.CopiedProto)
|
||
dealProcessForm.User = &recruit.UserProto{ // 登录用户
|
||
Id: int64(userInfo.ID),
|
||
Nickname: userInfo.NickName,
|
||
}
|
||
dealProcessForm.Id = int64(approvalID) // 审批申请的ID
|
||
dealProcessForm.Type = "offer-approve" // 人才招聘 的 类型
|
||
dealProcessForm.Command = "offer-check"
|
||
|
||
dealProcessForm.Entity.Copied.Copied = int64(userInfo.ID)
|
||
|
||
dealProcessFormResp := new(recruit.ResultVo)
|
||
dealProcessFormResp, err = service.GrpcRecruitClientImpl.OfferCheck(context.Background(), dealProcessForm)
|
||
if err != nil {
|
||
fmt.Println("++++++++++++++++++++ PostSubmit =============================")
|
||
fmt.Printf("PostSubmit : %+v\n", err)
|
||
fmt.Printf("dealProcessFormResp : %+v\n", dealProcessFormResp)
|
||
fmt.Println("++++++++++++++++++++ PostSubmit =============================")
|
||
//service.Error(c, e.Error, errors.New(e.ErrorCreateTalents))
|
||
return errors.New(e.ErrorCreateTalents)
|
||
}
|
||
return returnRecruitError(dealProcessFormResp)
|
||
}
|
||
|
||
func CloseEmploy(c *gin.Context) {
|
||
var req api.CloseEmployReq
|
||
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
||
service.Error(c, e.Error, err)
|
||
return
|
||
}
|
||
|
||
_, err := service.ApprovalProvider.CloseEmploy(context.Background(), &req)
|
||
if err != nil {
|
||
service.ResponseMsg(c, e.SUCCESS, serializer.Response{
|
||
Msg: err.Error(),
|
||
Status: e.Failed,
|
||
})
|
||
return
|
||
}
|
||
|
||
service.ResponseMsg(c, e.SUCCESS, serializer.Response{
|
||
Msg: e.GetMsg(e.SUCCESS),
|
||
Status: e.Ok,
|
||
})
|
||
}
|
||
|
||
func rollbackOffer(userInfo login.Info, approvalID uint64) (err error) {
|
||
dealProcessForm := new(recruit.DealProcessProto)
|
||
dealProcessForm.Id = int64(approvalID) // 审批申请的ID
|
||
dealProcessForm.Command = "offer-rollback"
|
||
dealProcessForm.Type = "offer-approve" // 人才招聘 的 类型
|
||
dealProcessForm.User = &recruit.UserProto{ // 登录用户
|
||
Id: int64(userInfo.ID),
|
||
Nickname: userInfo.NickName,
|
||
}
|
||
dealProcessFormResp, err := service.GrpcRecruitClientImpl.OfferRollback(context.Background(), dealProcessForm)
|
||
if err != nil {
|
||
fmt.Println("++++++++++++++++++++ Offer Rollback =============================")
|
||
fmt.Printf("Offer Rollback : %+v\n", err)
|
||
fmt.Printf("dealProcessFormResp : %+v\n", dealProcessFormResp)
|
||
fmt.Println("++++++++++++++++++++ Offer Rollback =============================")
|
||
//service.Error(c, e.Error, errors.New(e.ErrorRollbackOffer))
|
||
return errors.New(e.ErrorRollbackOffer)
|
||
}
|
||
return returnRecruitError(dealProcessFormResp)
|
||
}
|
||
|
||
func resumeHireJudge(userInfo login.Info, resumeID int64) (err error) {
|
||
dealProcessForm := new(recruit.DealProcessProto)
|
||
dealProcessForm.Id = resumeID // 审批申请的ID
|
||
dealProcessForm.Command = "resume-hire-judge"
|
||
dealProcessForm.Type = "resume-approve" // 人才招聘 的 类型
|
||
dealProcessForm.User = &recruit.UserProto{ // 登录用户
|
||
Id: int64(userInfo.ID),
|
||
Nickname: userInfo.NickName,
|
||
}
|
||
dealProcessFormResp, err := service.GrpcRecruitClientImpl.ResumeHireJudge(context.Background(), dealProcessForm)
|
||
if err != nil {
|
||
fmt.Println("++++++++++++++++++++ ResumeHireJudge =============================")
|
||
fmt.Printf("ResumeHireJudge : %+v\n", err)
|
||
fmt.Printf("dealProcessFormResp : %+v\n", dealProcessFormResp)
|
||
fmt.Println("++++++++++++++++++++ ResumeHireJudge =============================")
|
||
//service.Error(c, e.Error, errors.New(e.ErrorResumeHireJudge))
|
||
return errors.New(e.ErrorResumeHireJudge)
|
||
}
|
||
return returnRecruitError(dealProcessFormResp)
|
||
}
|