<?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.InvestProjectProfitMapper">
	<!-- 通用查询映射结果 -->
	<resultMap id="BaseResultMap"
		type="cn.com.countrygarden.bi.main.model.investment.InvestProjectProfit">
		<id column="id" property="id" />
		<result column="project_name" property="projectName" />
		<result column="project_id" property="projectId" />
		<result column="person_investment_id"
			property="personInvestmentId" />
		<result column="property_distribution_capital"
			property="propertyDistributionCapital" />
		<result column="property_distribution_capital_account"
			property="propertyDistributionCapitalAccount" />
		<result column="issued_capital" property="issuedCapital" />
		<result column="issued_capital_account"
			property="issuedCapitalAccount" />
		<result column="unissued_capital" property="unissuedCapital" />
		<result column="unissued_capital_account"
			property="unissuedCapitalAccount" />
		<result column="region_follow_capital"
			property="regionFollowCapital" />
		<result column="region_follow_capital_account"
			property="regionFollowCapitalAccount" />
		<result column="cash_return_capital"
			property="cashReturnCapital" />
		<result column="cash_return_capital_account"
			property="cashReturnCapitalAccount" />
		<result column="profit_distribution_capital"
			property="profitDistributionCapital" />
		<result column="profit_distribution_capital_account"
			property="profitDistributionCapitalAccount" />
		<result column="principal_return_capital"
			property="principalReturnCapital" />
		<result column="principal_return_capital_account"
			property="principalReturnCapitalAccount" />
		<result column="principal_notrecovered_capital"
			property="principalNotrecoveredCapital" />
		<result column="principal_notrecovered_capital_account"
			property="principalNotrecoveredCapitalAccount" />
		<result column="create_by" property="createBy" />
		<result column="create_time" property="createTime" />
		<result column="update_by" property="updateBy" />
		<result column="update_time" property="updateTime" />
		<result column="flag" property="flag" />
	</resultMap>
	<select id="findInvestProjectProfitVo" parameterType="String"
		resultType="cn.com.countrygarden.bi.main.dto.investment.InvestProjectProfitVo">
		select
		sum(p.property_distribution_capital)
		propertyDistributionCapitalTotal,
		sum(p.unissued_capital)
		unissuedCapitalTotal,sum(p.unissued_capital_account)
		unissuedCapitalAccountTotal,
		sum(p.property_distribution_capital_account)
		propertyDistributionCapitalAccountTotal,
		sum(p.region_follow_capital)
		regionFollowCapitalTotal,sum(p.region_follow_capital_account)
		regionFollowCapitalAccountTotal, sum(p.principal_return_capital)
		principalReturnCapitalTotal,
		sum(p.principal_return_capital_account)
		principalReturnCapitalAccountTotal,
		sum(p.profit_distribution_capital)
		profitDistributionCapitalTotal,
		sum(p.profit_distribution_capital_account)
		profitDistributionCapitalAccountTotal,
		sum(p.issued_capital)
		issuedCapitalTotal,sum(p.issued_capital_account)
		issuedCapitalAccountTotal,
		sum(p.cash_return_capital)
		cashReturnCapitalTotal,sum(p.cash_return_capital_account)
		cashReturnCapitalAccountTotal,
		sum(p.principal_notrecovered_capital)
		principalNotrecoveredCapitalTotal,
		sum(p.principal_notrecovered_capital_account)
		principalNotrecoveredCapitalAccountTotal
		from invest_project_profit p
		LEFT JOIN invest_region_investment i on i.id=p.person_investment_id
		where 1=1
		<if test="personInvestmentId!=null and personInvestmentId!=''">
			and p.person_investment_id=#{personInvestmentId}
		</if>
		<if test="regionId!=null and regionId!=''">
			and i.region_id=#{regionId}
		</if>

	</select>

	<select id="findInvestProjectProfit" parameterType="String"
		resultType="int">

		select count(id) from invest_project_profit where
		person_investment_id=#{personInvestmentId}
	</select>

	<delete id="deleteInvestProjectProfitIds" parameterType="String">
		delete from `invest_project_profit` where person_investment_id in
		<foreach collection="investRegionInvestmentIds" index="index"
			item="investRegionInvestmentIds" open="(" separator="," close=")">
			#{investRegionInvestmentIds}
		</foreach>

	</delete>

	<delete id="deleteinvestProjectProfit" parameterType="String">
		delete from
		`invest_project_profit` where
		person_investment_id=#{personInvestmentId}
	</delete>
</mapper>