<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
	namespace="cn.com.countrygarden.bi.main.dao.investment.InvestProjectAccountMapper">
	<!-- 通用查询映射结果 -->
	<resultMap id="BaseResultMap"
		type="cn.com.countrygarden.bi.main.model.investment.InvestProjectAccount">
		<id column="id" property="id" />
		<result column="invest_region_investment_id"
			property="investRegionInvestmentId" />
		<result column="invest_project_investment_id"
			property="investProjectInvestmentId" />
		<result column="follow_capital_account"
			property="followCapitalAccount" />
		<result column="follow_capital_account_time"
			property="followCapitalAccountTime" />
		<result column="flag" property="flag" />
		<result column="create_by" property="createBy" />
		<result column="create_time" property="createTime" />
		<result column="update_by" property="updateBy" />
		<result column="update_time" property="updateTime" />
	</resultMap>

	<select id="findFollowCapitalAccountSum" parameterType="Integer"
		resultType="java.math.BigDecimal">
		select sum(follow_capital_account) from
		invest_project_account where
		invest_region_investment_id=#{id}

	</select>

	<select id="findInvestProjectAccount" resultMap="BaseResultMap">
		select
		a.id,
		a.invest_region_investment_id,
		a.invest_project_investment_id,
		a.follow_capital_account,
		a.follow_capital_account_time from
		invest_project_account a
		left join invest_project_investment i ON i.id
		=
		a.invest_project_investment_id
		where
		a.invest_region_investment_id=#{id} and i.project_name=#{projectName}

	</select>
	<select id="findInvestProjectAccountSum" resultType="BigDecimal">
		SELECT
		sum(follow_capital_account)
		FROM
		invest_project_account
		WHERE
		invest_region_investment_id=#{investRegionInvestmentId} and
		invest_project_investment_id IN (
		SELECT
		id
		FROM
		invest_project_investment
		WHERE
		project_name = #{projectName})

	</select>

	<select id="findInvestProjectAccountInvestProjectInvestmentId"
		resultType="Integer">
		SELECT
		DISTINCT
		i.id
		FROM
		invest_project_investment i
		LEFT JOIN invest_project_account a ON a.invest_project_investment_id =
		i.id
		WHERE
		a.invest_region_investment_id = #{investRegionInvestmentId}
		AND i.project_name = #{projectName}

	</select>
</mapper>