WDailyFundsMapper.xml 5.42 KB
<?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.hotent.chkpower.dao.WDailyFundsDao">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.hotent.chkpower.model.WDailyFunds">
        <id column="ID_" property="id" />
    <result column="REF_ID_" property="refId" />
    <result column="F_date" property="fDate" />
    <result column="F_org_name" property="fOrgName" />
    <result column="F_org_id" property="fOrgId" />
    <result column="F_org_type" property="fOrgType" />
    <result column="F_yesterday_account_balance" property="fYesterdayAccountBalance" />
    <result column="F_today_account_balance" property="fTodayAccountBalance" />
    <result column="F_account_balance_difference" property="fAccountBalanceDifference" />
    <result column="F_today_net_cash_flow" property="fTodayNetCashFlow" />
    <result column="F_today_freeze_amount" property="fTodayFreezeAmount" />
    <result column="F_today_freezing" property="fTodayFreezing" />
    <result column="F_insp_status_name" property="fInspStatusName" />
    <result column="F_insp_time" property="fInspTime" />
    <result column="F_insp_notes" property="fInspNotes" />
    <result column="F_insp_by" property="fInspBy" />
    <result column="F_insp_id" property="fInspId" />
    <result column="F_create_by" property="fCreateBy" />
    <result column="F_create_id" property="fCreateId" />
    <result column="F_create_time" property="fCreateTime" />
    <result column="F_update_by" property="fUpdateBy" />
    <result column="F_update_id" property="fUpdateId" />
    <result column="F_update_time" property="fUpdateTime" />
    <result column="F_form_data_rev_" property="fFormDataRev" />
    <result column="F_order_no" property="fOrderNo" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        ID_, REF_ID_, F_date, F_org_name, F_org_id, F_org_type, F_yesterday_account_balance, F_today_account_balance, F_account_balance_difference, F_today_net_cash_flow, F_today_freeze_amount, F_today_freezing, F_insp_status_name, F_insp_time, F_insp_notes, F_insp_by, F_insp_id, F_create_by, F_create_id, F_create_time, F_update_by, F_update_id, F_update_time, F_form_data_rev_, F_order_no
    </sql>

	<select id="selectPage" resultMap="BaseResultMap">
		select
			<include refid="Base_Column_List"/>
		from
			w_daily_funds
		${ew.customSqlSegment}
	</select>

	<select id="selectList" resultMap="BaseResultMap">
		select
			<include refid="Base_Column_List"/>
		from
			w_daily_funds
		${ew.customSqlSegment}
	</select>

	<select id="selectById" resultMap="BaseResultMap">
		select
			<include refid="Base_Column_List"/>
		from
			w_daily_funds
		where
		    ID_ = #{id}
	</select>

    <insert id="insertInitWDailyFunds">
        INSERT into w_daily_funds(ID_,F_date,F_org_id,F_org_name,F_org_type,F_order_no,F_insp_status_name)
        SELECT REPLACE(UUID(), '-', '') as ID_,DATE_FORMAT(#{fDate,jdbcType=TIMESTAMP}, '%Y-%m-%d 00:00:00') as F_date,org.ID_ as F_org_id,org.NAME_  as F_org_name,orgParams.VALUE_ as F_org_type,org.ORDER_NO_ as F_order_no,'待复核' as F_insp_status_name
        FROM uc_org  org
        JOIN uc_org_params orgParams  on orgParams.ORG_ID_= org.ID_
    </insert>

    <select id="selectWDailyFundsCount" resultType="java.lang.Integer">
        SELECT COUNT(ID_) FROM w_daily_funds WHERE DATE(F_date) = DATE(#{fDate,jdbcType=TIMESTAMP})
    </select>

    <select id="selectWDailyFundsNews" resultType="com.hotent.chkpower.model.WDailyFunds">
        SELECT funds.F_date,funds.id_,funds.F_org_id,funds.F_org_name ,
        jrye.F_today_account_balance,zrye.F_yesterday_account_balance,(IFNULL(jrye.F_today_account_balance,0) - IFNULL(zrye.F_yesterday_account_balance,0)) as F_account_balance_difference
        ,jxjl.F_today_net_cash_flow,jrye.F_today_freeze_amount,jrye.F_today_freezing
        FROM w_daily_funds  funds
        LEFT JOIN (
            SELECT F_org_id,SUM(F_account_balance) AS F_today_account_balance,SUM(F_freeze_amount) as F_today_freeze_amount,SUM(F_freezing) AS F_today_freezing
            FROM w_current
            WHERE DATE(F_date) =DATE(#{fDate,jdbcType=TIMESTAMP})
            GROUP BY F_org_id
        )  jrye on jrye.F_org_id = funds.F_org_id
        LEFT JOIN (
            SELECT F_org_id,SUM(F_account_balance) AS F_yesterday_account_balance
            FROM w_current
            WHERE DATE(F_date) =(SELECT DATE_SUB(DATE(#{fDate,jdbcType=TIMESTAMP}), INTERVAL 1 DAY))
            GROUP BY F_org_id
        )  zrye on zrye.F_org_id = funds.F_org_id
        LEFT JOIN (
            SELECT F_org_id, SUM(F_total_net_cash_flow) as F_today_net_cash_flow
            FROM w_finance WHERE DATE(F_date) =DATE(#{fDate,jdbcType=TIMESTAMP})
            GROUP BY F_org_id
        ) jxjl  on jxjl.F_org_id = funds.F_org_id
        WHERE DATE(funds.F_date) =DATE(#{fDate,jdbcType=TIMESTAMP})
        <if test="wCurrentList != null and wCurrentList.size() > 0">
            and  funds.F_org_id  in
            <foreach collection="wCurrentList" separator="," item="item" open="(" close=")">
                #{item.F_org_id}
            </foreach>
        </if>
    </select>

<!--    <select id="getDailyFundsByDateList" resultType="java.util.HashMap">-->
<!--        SELECT * FROM w_daily_funds-->
<!--        WHERE F_org_type =#{fOrgType} and DATE(F_date) =DATE(#{fDate})-->
<!--        ORDER BY F_order_no asc-->
<!--    </select>-->
</mapper>