IncomeStatisticParkDaySMapper.xml 10.1 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.zteits.order.mapper.smapper.IncomeStatisticParkDaySMapper">
    <resultMap id="BaseResultMap" type="com.zteits.order.domain.IncomeStatisticParkDay">
        <id column="id" jdbcType="BIGINT" property="id" />
        <result column="static_date" jdbcType="DATE" property="staticDate" />
        <result column="static_date_str" jdbcType="VARCHAR" property="staticDateStr" />
        <result column="org_id" jdbcType="INTEGER" property="orgId" />
        <result column="area_id" jdbcType="VARCHAR" property="areaId" />
        <result column="area_name" jdbcType="VARCHAR" property="areaName" />
        <result column="pl_no" jdbcType="VARCHAR" property="plNo" />
        <result column="pl_name" jdbcType="VARCHAR" property="plName" />
        <result column="charger_num" jdbcType="INTEGER" property="chargerNum" />
        <result column="berth_num" jdbcType="INTEGER" property="berthNum" />
        <result column="order_num" jdbcType="INTEGER" property="orderNum" />
        <result column="total_fee" jdbcType="BIGINT" property="totalFee" />
        <result column="act_fee" jdbcType="BIGINT" property="actFee" />
        <result column="dicount_fee" jdbcType="BIGINT" property="dicountFee" />
        <result column="arrearage_fee" jdbcType="BIGINT" property="arrearageFee" />
        <result column="refund_fee" jdbcType="BIGINT" property="refundFee" />
        <result column="ali_fee" jdbcType="BIGINT" property="aliFee" />
        <result column="ali_charge_num" jdbcType="INTEGER" property="aliChargeNum" />
        <result column="wx_fee" jdbcType="BIGINT" property="wxFee" />
        <result column="wx_charge_num" jdbcType="INTEGER" property="wxChargeNum" />
        <result column="cash_fee" jdbcType="BIGINT" property="cashFee" />
        <result column="cash_charge_num" jdbcType="INTEGER" property="cashChargeNum" />
        <result column="balance_fee" jdbcType="BIGINT" property="balanceFee" />
        <result column="balance_charge_num" jdbcType="INTEGER" property="balanceChargeNum" />
        <result column="data_state" jdbcType="INTEGER" property="dataState" />
        <result column="create_emp_id" jdbcType="VARCHAR" property="createEmpId" />
        <result column="create_emp_name" jdbcType="VARCHAR" property="createEmpName" />
        <result column="create_date" jdbcType="TIMESTAMP" property="createDate" />
        <result column="modfiy_emp_id" jdbcType="VARCHAR" property="modfiyEmpId" />
        <result column="modfiy_emp_name" jdbcType="VARCHAR" property="modfiyEmpName" />
        <result column="modfiy_date" jdbcType="TIMESTAMP" property="modfiyDate" />
        <result column="remark" jdbcType="VARCHAR" property="remark" />
         <result column="pl_type" jdbcType="INTEGER" property="plType" />
    </resultMap>
    <sql id="Base_Column_List">
        id, static_date,static_date_str, org_id, area_id, area_name, pl_no, pl_name,charger_num, order_num, total_fee,
        act_fee, dicount_fee, arrearage_fee, refund_fee, ali_fee, ali_charge_num, wx_fee,
        wx_charge_num, cash_fee, cash_charge_num, balance_fee, balance_charge_num, data_state,
        create_emp_id, create_emp_name, create_date, modfiy_emp_id, modfiy_emp_name, modfiy_date,
        remark,pl_type
    </sql>

    <select id="queryIncomeStatisticForParkDay" parameterType="com.zteits.clouds.api.dto.order.income.param.IncomeStatisticRequest"
     resultType="com.zteits.order.domain.IncomeStatisticParkDay">
        SELECT

        <if test="groupType != null and groupType ==1">
            a.static_date as staticDate,
        </if>
        <if test="groupType != null and groupType ==2">
            a.pl_no AS plNo,
            max(a.pl_name) as plName,
        </if>
        <if test="groupType != null and groupType ==3">
            a.static_date as staticDate,
            a.pl_no AS plNo,
            max(a.pl_name) as plName,
        </if>

        SUM(a.order_num) as orderNum,
        MAX(a.charger_num) as chargerNum,
        SUM(a.total_fee) as totalFee,
        sum(a.act_fee) as actFee,
        sum(a.dicount_fee) as dicountFee,
        sum(a.arrearage_fee) as arrearageFee,
        sum(a.refund_fee) as refundFee,
        sum(a.ali_fee) as aliFee,
        sum(a.ali_charge_num) as aliChargeNum,
        sum(a.wx_fee) as wxFee,
        sum(a.wx_charge_num) as wxChargeNum,
        sum(a.cash_fee) as cashFee,
        sum(a.cash_charge_num) as cashChargeNum,
        sum(a.balance_fee) as balanceFee,
        sum(a.balance_charge_num) as balanceChargeNum
        FROM
        income_statistic_park_day a
        where a.data_state=1
        AND a.static_date BETWEEN #{beginTime} AND #{endTime}
        <if test="plAreaBlockIds != null and plNos.size >0">
            AND a.area_id IN
            <foreach collection="plAreaBlockIds" open="(" close=")" item="plAreaBlockId" separator=",">
                #{plAreaBlockId}
            </foreach>
        </if>
        <if test="plNos != null and plNos.size >0">
            AND a.pl_no IN
            <foreach collection="plNos" open="(" close=")" item="plNo" separator=",">
                #{plNo}
            </foreach>
        </if>
        <if test="groupType != null and groupType ==1">
            GROUP BY a.static_date
        </if>
        <if test="groupType != null and groupType ==2">
            GROUP BY a.pl_no
        </if>
        <if test="groupType != null and groupType ==3">
            GROUP BY a.pl_no,a.static_date
        </if>
		<choose>
	        <when test="baseRequest != null and baseRequest.sortName != null and baseRequest.sortOrder != null
	        	and baseRequest.sortName != '' and baseRequest.sortOrder != ''">
	            ORDER BY ${baseRequest.sortName} ${baseRequest.sortOrder}
	        </when>
	        <otherwise>
	            ORDER BY MAX(a.static_date) DESC
	        </otherwise>
    	</choose>




    </select>
    <!-- 停车收入按日(income_statistic_park_day) -->
    <select id="queryIncomeStatisticParkDayTotal" resultMap="BaseResultMap" parameterType="com.zteits.clouds.api.dto.order.income.param.IncomeParkAndVipReq">
       SELECT
			a.pl_type,
		    sum(IFNULL(a.act_fee,0)) - sum(IFNULL(a.refund_fee,0))  as act_fee
		FROM
			income_statistic_park_day a
		where 1=1
		  and a.data_state=1
		  and a.static_date =#{reportDate}
		  and a.pl_no in
            <foreach collection="plNos" open="(" close=")" item="plNo" separator=",">
                #{plNo}
            </foreach>
		 group by a.pl_type
    </select>
    <!--停车收入按周-->
    <select id="queryIncomeStatisticParkWeekTotal" resultMap="BaseResultMap">
    SELECT
			a.pl_type,
		    sum(IFNULL(a.act_fee,0)) - sum(IFNULL(a.refund_fee,0)) as act_fee
		FROM
			income_statistic_park_day a
		where 1=1
		  and a.data_state=1
		  <![CDATA[and a.static_date >=#{startReportDate}]]>
		  <![CDATA[and a.static_date <=#{endReportDate}]]>
		  and a.pl_no in
            <foreach collection="plNos" open="(" close=")" item="plNo" separator=",">
                #{plNo}
            </foreach>
		 group by a.pl_type
    </select>



    <!-- 停车收入按周 -->
    <select id="queryParkIncomeForkWeek" resultMap="BaseResultMap" parameterType="com.zteits.clouds.api.dto.order.income.param.IncomeStatisticRequest">
		 SELECT
	        c.pl_no,
		    c.pl_name,
		    c.act_fee,
		    c.ali_fee,
		    c.balance_fee,
		    c.cash_fee,
		    c.pl_type,
		    c.static_date_str,
		    c.wx_fee,
            c.refund_fee,
            c.total_fee,
		    bb.berth_num,
		    bb.charger_num

		FROM
		    income_statistic_park_day bb,
		    (
		        SELECT
		            a.pl_no,
		            a.pl_name,
		            a.pl_type,
		            MAX(a.static_date_str) static_date_str,
		            sum(IFNULL(a.act_fee, 0)) AS act_fee,
		            sum(IFNULL(a.wx_fee, 0)) AS wx_fee,
		            sum(IFNULL(a.ali_fee, 0)) AS ali_fee,
		            sum(IFNULL(a.balance_fee, 0)) AS balance_fee,
                    sum(IFNULL(a.refund_fee, 0)) AS refund_fee,
                    sum(IFNULL(a.total_fee, 0)) AS total_fee,
		            sum(IFNULL(a.cash_fee, 0)) AS cash_fee
		        FROM
		            income_statistic_park_day a
		        WHERE
		            1 = 1
		        AND a.data_state = 1
		        and a.static_date between #{beginTime} and #{endTime}
		        <if test="plNos != null and plNos.size >0">
	                and a.pl_no in
		            <foreach collection="plNos" open="(" close=")" item="plNo" separator=",">
		                #{plNo}
		            </foreach>
		        </if>
		        GROUP BY
		            a.pl_no,
		            a.pl_name,
		            a.pl_type

		    ) c
		WHERE
		    c.pl_no = bb.pl_no
		    and c.static_date_str=bb.static_date_str
		order by c.act_fee desc,convert(c.pl_name USING gbk) asc
    </select>

     <!-- 报表统计中获取停车场泊位数 -->
    <select id="queryBerthNumForReportForDay" resultType="com.zteits.clouds.api.dto.order.income.dto.ReportParkBerthNumDTO"
        parameterType="com.zteits.clouds.api.dto.order.income.param.IncomeStatisticRequest">
         SELECT
            a.pl_no AS plNo,
            a.pl_type AS plType,
            a.berth_num AS berthNum
        FROM
            income_statistic_park_day a
        WHERE
            1 = 1
            and a.data_state=1
            <if test="plNos != null and plNos.size >0">
                AND a.pl_no IN
                <foreach collection="plNos" open="(" close=")" item="plNo" separator=",">
                    #{plNo}
                </foreach>
            </if>
        AND a.static_date BETWEEN #{beginTime} AND #{endTime}
        AND NOT EXISTS (
            SELECT
                1
            FROM
                income_statistic_park_day b
            WHERE 1=1
	            and b.data_state=1
	            <if test="plNos != null and plNos.size >0">
	                AND b.pl_no IN
	                <foreach collection="plNos" open="(" close=")" item="plNo" separator=",">
	                    #{plNo}
	                </foreach>
	            </if>
                AND b.static_date BETWEEN #{beginTime} AND #{endTime}
                AND b.pl_no = a.pl_no
                AND b.static_date > a.static_date
        )

    </select>

</mapper>