package com.leanwo.activiti.delegate.base;

import javax.inject.Named;

import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.JavaDelegate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.leanwo.activiti.dto.base.DocumentInfoDto;
import com.leanwo.activiti.service.base.DocumentOperationService;
import com.leanwo.activiti.service.base.impl.UserPreference;
import com.leanwo.activiti.util.SpringUtil;

/**
 * 单据审批不通过后，执行本程序，主要包括如下流程：
 * <ul>
 * 	<li>
 * 设置单据状态为审批不通过
 * </li>
 * </ul>
 * @author Jack
 * @version 20101016
 *
 */
@Named
public class DocumentRejectedService implements JavaDelegate {
	private static Logger logger = LoggerFactory.getLogger(DocumentRejectedService.class);

	
	@Override
	public void execute(DelegateExecution execution)  {
		logger.debug("PASS = "+ execution.getVariable(UserPreference.COMMAND));
		Long recordId = (Long) execution.getVariable(UserPreference.RECORD_ID);	
		Long accountId = (Long) execution.getVariable(UserPreference.ACCOUNT_ID);
		String className = (String) execution.getVariable(UserPreference.CLASS_NAME);

		DocumentInfoDto documentInfoDto = new DocumentInfoDto();
		documentInfoDto.setRecordId(recordId);
		documentInfoDto.setClassName(className);
		
		DocumentOperationService documentOperationService = (DocumentOperationService) SpringUtil.getSingleBean(DocumentOperationService.class);
		documentOperationService.rejectDocument(accountId,documentInfoDto);
		
	}
}
