package com.engine.htsc.payment.dao;

import org.apache.ibatis.jdbc.SQL;

/**
 * author：k1810012
 * 总部通用付款sql
 */
public class PaymentDao {

	/**
	 * 获取部门负责人sql
	 *
	 * @return sql语句
	 */
	public String getDivisonHead(String deptIds) {
		return new SQL() {{
			SELECT("deptleaders");
			FROM("hrmdepartmentdefined");
			WHERE("deptid in (" + deptIds + ")");
		}}.toString();
	}

	/**
	 * 获取第n级会计科目code
	 *
	 * @param code 预算科目
	 * @return sql
	 */
	public String getAccountCode(String code) {
		return new SQL() {{
			SELECT("t1.HJKMBM,t1.HJKMMC");
			FROM("UF_KJKMPZ t1");
			LEFT_OUTER_JOIN("UF_KJKMPZ_DT1 t2 on t1.id=t2.mainid");
			WHERE("t2.yskm='" + code + "'");
		}}.toString();

	}

	/**
	 * 获取表基础数据
	 *
	 * @param modeTableName     建模表
	 * @param workFlowTableName 流程表
	 * @param id                需要更新的id
	 * @return sql
	 */
	public String getBaseInfo(String modeTableName, String workFlowTableName, String id) {
		return new SQL() {{
			SELECT("t2.SFQDZ,t1.ID,t1.REQUTID,t1.fkzt,t2.ywht,t2.fklx,t2.NGR,t2.SZBM,t2.LCBH,t2.REQUESTID,t2.DJZS,t2.LCBT,t2.NGSJ,t3.REQUESTNAME");
			FROM(modeTableName + " t1");
			LEFT_OUTER_JOIN(workFlowTableName + " t2 on t1.REQUTID=t2.REQUESTID");
			LEFT_OUTER_JOIN("WORKFLOW_REQUESTBASE t3 on t1.REQUTID=t3.REQUESTID");
			WHERE("t1.ID=" + id);
		}}.toString();
	}

	/**
	 * 获取表基础数据(差旅)
	 *
	 * @param modeTableName     建模表
	 * @param workFlowTableName 流程表
	 * @param id                需要更新的id
	 * @return sql
	 */
	public String getBaseInfoForCl(String modeTableName, String workFlowTableName, String id) {
		return new SQL() {{
			SELECT("t2.SFQDZ,t1.ID,t1.fkzt,t1.REQUTID,1 as ywht,t2.fklx,t2.NGR,t2.SZBM,t2.LCBH,t2.REQUESTID,t2.DJZS,t2.bt as lcbt,t2.NGSJ,t3.REQUESTNAME");
			FROM(modeTableName + " t1");
			LEFT_OUTER_JOIN(workFlowTableName + " t2 on t1.REQUTID=t2.REQUESTID");
			LEFT_OUTER_JOIN("WORKFLOW_REQUESTBASE t3 on t1.REQUTID=t3.REQUESTID");
			WHERE("t1.ID=" + id);
		}}.toString();
	}

	/**
	 * 建模id获取对应的付款流程表明
	 *
	 * @param modeTableName 建模表
	 * @param id            id
	 * @return sql
	 */
	public String getFormTableByModeOrderId(String modeTableName, String id) {
		return new SQL() {{
			SELECT("t1.FORMID");
			FROM("workflow_base t1");
			LEFT_OUTER_JOIN("WORKFLOW_REQUESTBASE t2 on t1.ID=t2.WORKFLOWID");
			LEFT_OUTER_JOIN(modeTableName + " t3 on t3.REQUTID=t2.REQUESTID");
			WHERE("t3.ID=" + id);
		}}.toString();
	}

	/**
	 * 查询明细8和dt12, 会计详情
	 *
	 * @param mainTableName 主表
	 * @param requestId     流程id
	 * @return sql
	 */
	public String getSubjectInfoFromDt8AndDt12(String mainTableName, String requestId) {
		return new SQL() {{
			SELECT("t2.YSKM,t2.YSKMMC,t2.HJKM,t2.FYSJCDBM,t2.JE,t2.SY,t2.ZHRMB");
			FROM(mainTableName + " t1");
			LEFT_OUTER_JOIN(mainTableName + "_DT12 t2 on t1.ID=t2.MAINID");
			WHERE("t1.REQUESTID=" + requestId);
			ORDER_BY("t2.ID");
		}}.toString();
	}

	/**
	 * 查询明细11, 支付明细
	 *
	 * @param mainTableName 主表
	 * @param requestId     流程id
	 * @return sql
	 */
	public String getPayInfoFromDt11(String mainTableName, String requestId) {
		return new SQL() {{
			SELECT("t2.YXZFJE,t2.XJZFJE,t2.KHXMC,t2.YXZH,t2.SKDW");
			FROM(mainTableName + " t1");
			LEFT_OUTER_JOIN(mainTableName + "_DT11 t2 on t1.ID=t2.MAINID");
			WHERE("t1.REQUESTID=" + requestId);
		}}.toString();
	}

	/**
	 * 获取付款类型
	 *
	 * @param modeTableName     建模表
	 * @param workFlowTableName 流程表
	 * @param id                需要更新的id
	 * @return sql
	 */
	public String getPaymentType(String modeTableName, String workFlowTableName, String id) {
		return new SQL() {{
			SELECT("t1.ID,t1.REQUTID,t2.fklx");
			FROM(modeTableName + " t1");
			LEFT_OUTER_JOIN(workFlowTableName + " t2 on t1.REQUTID=t2.REQUESTID");
			LEFT_OUTER_JOIN("WORKFLOW_REQUESTBASE t3 on t1.REQUTID=t3.REQUESTID");
			WHERE("t1.ID=" + id);
		}}.toString();
	}

	/**
	 * 获取采购商城基础数据
	 *
	 * @param modeTableName     建模表
	 * @param workFlowTableName 流程表
	 * @param id                需要更新的id
	 * @return sql
	 */
	public String getBaseInfoSettlePayment(String modeTableName, String workFlowTableName, String id) {
		return new SQL() {{
			SELECT("t1.ID,t1.REQUTID,t2.fklx,t2.NGR,t2.SZBM,t2.LCBH,t2.REQUESTID,t2.DJZS,t2.LCBT,t2.NGRQ,t3.REQUESTNAME");
			FROM(modeTableName + " t1");
			LEFT_OUTER_JOIN(workFlowTableName + " t2 on t1.REQUTID=t2.REQUESTID");
			LEFT_OUTER_JOIN("WORKFLOW_REQUESTBASE t3 on t1.REQUTID=t3.REQUESTID");
			WHERE("t1.ID=" + id);
		}}.toString();
	}

	/**
	 * 查询采购商城明细8和dt12, 会计详情
	 *
	 * @param mainTableName 主表
	 * @param requestId     流程id
	 * @return sql
	 */
	public String getSettleSubjectInfoFromDt8AndDt12(String mainTableName, String requestId) {
		return new SQL() {{
			SELECT("t2.YSKM,t2.HJKM,t2.FYSJCDBM,t2.JE,t2.SY");
			FROM(mainTableName + " t1");
			LEFT_OUTER_JOIN(mainTableName + "_DT12 t2 on t1.ID=t2.MAINID");
			WHERE("t1.REQUESTID=" + requestId);
			ORDER_BY("t2.ID");
		}}.toString();
	}
}
