Beispiel #1
0
func (c App) DoAddLeave(reason string, leave_type int, startdate, enddate time.Time, address string, onway_date int, filepath string) revel.Result {

	leave := new(models.Leave)
	leave.UserId = c.User.Id
	leave.Status = utils.LEAVE_STATUS_ASKING
	leave.LeaveType = leave_type
	leave.Reason = reason
	leave.Address = address
	leave.OnwayDate = onway_date
	leave.Filepath = filepath
	leave.Startdate = startdate
	leave.Enddate = enddate
	leave.Duration = fmt.Sprintf("%.1f", enddate.Sub(startdate).Seconds()/86400)
	leave.CreatedAt = time.Now()
	leave.UpdatedAt = leave.CreatedAt
	revel.INFO.Println("DoAddLeave", startdate, enddate)

	leave.FlowId = c.getLeaveFlowId(c.UserProfile, leave)
	leave.StepId = "0" //第0步,
	err := c.getLeaveInchargeProfile(c.UserProfile, leave, true)

	if err != nil {
		c.Flash.Error(err.Error())
		c.FlashParams()
		return c.Redirect("/app/addLeave")
	}

	app.Engine.Insert(leave)

	transfer := new(models.LeaveTransfer)
	transfer.LeaveId = leave.Id
	transfer.AssignFr = leave.UserId
	transfer.AssignTo = leave.InChargeUserId
	transfer.IsAgree = 0
	transfer.CreatedAt = time.Now()
	transfer.UpdatedAt = transfer.CreatedAt

	app.Engine.Insert(transfer)
	//获取处理负责人

	return c.Redirect("/app/listLeave")
}
Beispiel #2
0
/**
根据假条,获取下一审批人ID,第一个参数为发起人信息
*/
func (c App) getLeaveInchargeProfile(up *models.UserProfiles, leave *models.Leave, isAgree bool) error {
	currentStepId, err := strconv.Atoi(leave.StepId)
	if err != nil {
		return err
	}

	nextStepId := currentStepId + 1
	flowId := leave.FlowId

	steps, exists := app.Flows[flowId]
	if !exists {
		return errors.New("处理流程" + flowId + "不存在")
	}

	nextStep, exists := steps.Steps[fmt.Sprintf("%d", nextStepId)]
	if !exists {
		return errors.New("处理已结束")
	}

	leave.InChargeUserId, err = c.getLeaveInchargeUserId(up, flowId, fmt.Sprintf("%d", nextStepId))
	if err != nil {
		return err
	}

	//当前一步,维护状态用
	currentStep, exists := steps.Steps[fmt.Sprintf("%d", currentStepId)]

	if isAgree {
		if currentStepId != 0 && !exists {
			leave.Status = utils.LEAVE_STATUS_CANCEL_OK //销假成功,结束了
		} else if nextStep.Type == "2" && currentStep.Type == "1" {
			leave.Status = utils.LEAVE_STATUS_ASK_OK //请假成功,该消假了
		} else if nextStep.Type == "1" {
			leave.Status = utils.LEAVE_STATUS_ASKING //请假中
		} else if currentStep.Type == "2" {
			leave.Status = utils.LEAVE_STATUS_CANCELING //销假中
		}
	} else {
		if leave.Status != utils.LEAVE_STATUS_CANCEL_FAIL {
			leave.Status = utils.LEAVE_STATUS_ASK_FAIL
		} else {
			leave.Status = utils.LEAVE_STATUS_CANCEL_FAIL
		}
	}
	leave.StepId = fmt.Sprintf("%d", nextStepId)
	leave.UpdatedAt = time.Now()

	return nil
}