package jp.mosp.common.action;

import java.util.Date;
import java.util.List;

import jp.mosp.common.part.KintaiCompilePart;
import jp.mosp.common.part.PartManager;
import jp.mosp.common.part.VariousPart;
import jp.mosp.kintai.dto.MSyukkinboDto;
import jp.mosp.payroll.dao.MKintaiDao;
import jp.mosp.payroll.dao.MKintaiKinmuDao;
import jp.mosp.payroll.dto.CompileAmendmentDto;
import jp.mosp.payroll.dto.MKintaiDto;

public abstract class KintaiCompileAction extends AttendanceTotalAction {

	// 僼傿乕儖僪
	private MKintaiDao	kintaiDao;
	private MKintaiKinmuDao kinmuDao;

	/**
	 * 
	 * @throws Exception
	 */
	private void prepareMkintaiDao() throws Exception {
		// DAO弨旛
		if (VariousPart.chkExistObject(kintaiDao)) {
			return;
		}
		kintaiDao = PartManager.kintaicompile(partInfo()).getMKintaiDao();
	}

	/**
	 * 
	 * @return
	 * @throws Exception
	 */
	protected MKintaiDao kintaiDao() throws Exception {
		prepareMkintaiDao();
		return kintaiDao;
	}

	/**
	 * 
	 * @throws Exception
	 */
	private void prepareMkintaiKinmuDao() throws Exception {
		// DAO弨旛
		if (VariousPart.chkExistObject(kinmuDao)) {
			return;
		}
		kinmuDao = PartManager.kintaicompile(partInfo()).getMKintaiKinmuDao();
	}

	/**
	 * 
	 * @return
	 * @throws Exception
	 */
	protected MKintaiKinmuDao kinmuDao() throws Exception {
		prepareMkintaiKinmuDao();
		return kinmuDao;
	}

	/**
	 * 枹彸擣桳柍専嶕
	 * @param dto 			懳徾DTO
	 * @param targetMonth 	慖戰擭寧
	 * @return true乧枹彸擣柍偟丄false乧枹彸擣桳傝
	 * @throws Exception
	 */
	protected boolean checkApproval(CompileAmendmentDto dto, Date targetMonth) throws Exception {
		// 弌嬑曤偺庢摼偲弨旛
		getAttendanceList(dto.getKCode(), targetMonth);
		// 彸擣丒枹彸擣審悢嶌惉
		int[] number = KintaiCompilePart.makeApprovalNumber(attendanceList);
		// 枹彸擣審悢
		if (number[1] == 0 && number[2] > 0) {
			return true;
		}
		return false;
	}

	/**
	 * 嬑懹寧廤寁
	 * @param kCode			懳徾幮堳僐乕僪
	 * @param targetMonth	懳徾擭寧
	 * @return	mKintaiDto	廤寁嵪傒DTO
	 * @throws Exception
	 */
	protected MKintaiDto getCompiledInfo(
			String kCode,
			Date targetMonth,
			List<MSyukkinboDto> attendanceList
	) throws Exception {
		return PartManager.kintaicompile(partInfo()).getCompiledInfo(
				kCode,
				targetMonth,
				attendanceList
		);
	}

}
