<?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="com.dhcc.finance.main.dao.Oracle.TjkOutcwBalanceMapper">
  <resultMap id="BaseResultMap" type="com.dhcc.finance.main.domain.CwHsOutcwBalance">
    <result column="L_ZTBH" jdbcType="INTEGER" property="lZtbh" />
    <result column="D_DATE" jdbcType="TIMESTAMP" property="dDate" />
    <result column="VC_DYKM" jdbcType="VARCHAR" property="vcDykm" />
    <result column="EN_DEBIT" jdbcType="DECIMAL" property="enDebit" />
    <result column="EN_CREDIT" jdbcType="DECIMAL" property="enCredit" />
    <result column="ITEM1" jdbcType="VARCHAR" property="item1" />
    <result column="NAME1" jdbcType="VARCHAR" property="name1" />
    <result column="ITEM2" jdbcType="VARCHAR" property="item2" />
    <result column="NAME2" jdbcType="VARCHAR" property="name2" />
    <result column="ITEM3" jdbcType="VARCHAR" property="item3" />
    <result column="NAME3" jdbcType="VARCHAR" property="name3" />
    <result column="ITEM4" jdbcType="VARCHAR" property="item4" />
    <result column="NAME4" jdbcType="VARCHAR" property="name4" />
    <result column="ITEM5" jdbcType="VARCHAR" property="item5" />
    <result column="NAME5" jdbcType="VARCHAR" property="name5" />
    <result column="ITEM6" jdbcType="VARCHAR" property="item6" />
    <result column="NAME6" jdbcType="VARCHAR" property="name6" />
    <result column="ITEM7" jdbcType="VARCHAR" property="item7" />
    <result column="NAME7" jdbcType="VARCHAR" property="name7" />
    <result column="ITEM8" jdbcType="VARCHAR" property="item8" />
    <result column="NAME8" jdbcType="VARCHAR" property="name8" />
    <result column="ITEM9" jdbcType="VARCHAR" property="item9" />
    <result column="NAME9" jdbcType="VARCHAR" property="name9" />
    <result column="VC_HTBH" jdbcType="VARCHAR" property="vcHtbh" />
    <result column="EN_DEBIT_BY" jdbcType="DECIMAL" property="enDebitBy" />
    <result column="EN_CREDIT_BY" jdbcType="DECIMAL" property="enCreditBy" />
    <result column="VC_ZQJC" jdbcType="VARCHAR" property="vcZqjc" />
    <result column="VC_JKFS" jdbcType="VARCHAR" property="vcJkfs" />
    <result column="VC_DYKMMC" jdbcType="VARCHAR" property="vcDykmmc" />
    <result column="EN_DEBIT_BN" jdbcType="DECIMAL" property="enDebitBn" />
    <result column="EN_CREDIT_BN" jdbcType="DECIMAL" property="enCreditBn" />
  </resultMap>
  <sql id="Base_Column_List">
    L_ZTBH, D_DATE, case when length(VC_DYKM)>10 then SUBSTR(VC_DYKM,1,10) else VC_DYKM end  VC_DYKM, EN_DEBIT, EN_CREDIT, ITEM1, NAME1, ITEM2, NAME2, ITEM3, 
    NAME3, ITEM4, NAME4, ITEM5, NAME5, ITEM6, NAME6, ITEM7, NAME7, ITEM8, NAME8, ITEM9, 
    NAME9, VC_HTBH, EN_DEBIT_BY, EN_CREDIT_BY, VC_ZQJC, VC_JKFS, VC_DYKMMC, EN_DEBIT_BN, 
    EN_CREDIT_BN
  </sql>
  <select id="selectAllData"  resultMap="BaseResultMap">
  	select L_ZTBH ,min(D_DATE) D_DATE ,VC_DYKM , sum(EN_DEBIT) EN_DEBIT ,  sum(EN_CREDIT) EN_CREDIT , sum(EN_DEBIT_BY) EN_DEBIT_BY ,sum(EN_CREDIT_BY) EN_CREDIT_BY ,
      sum(EN_DEBIT_BN) EN_DEBIT_BN,sum(EN_CREDIT_BN) EN_CREDIT_BN
    from (
    select
    <include refid="Base_Column_List" />
    from tjk_outcw_balance where  to_char(D_DATE,'yyyy-MM-dd')= #{endDate,jdbcType=VARCHAR}  and L_ZTBH in 
     <foreach collection="ztList" open="(" item="item" separator="," close=")">
	  		#{item,jdbcType=VARCHAR}
	  	</foreach>
	  ) a group by  a.L_ZTBH,a.VC_DYKM
  </select>
</mapper>