<?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.leromro.core.mapper.OrgStatDataMapper">
    
    <resultMap type="OrgStatData" id="OrgStatDataResult">
        <result property="orgStatDataId"    column="org_stat_data_id"    />
        <result property="deptId"    column="dept_id"    />
        <result property="statDate"    column="stat_date"    />
        <result property="clientTotal"    column="client_total"    />
        <result property="volunteetTotal"    column="volunteet_total"    />
        <result property="todayClientAdd"    column="today_client_add"    />
        <result property="todayVolunteetAdd"    column="today_volunteet_add"    />
        <result property="todayOrderTotal"    column="today_order_total"    />
        <result property="allOrderTotal"    column="all_order_total"    />
        <result property="todayOrderAmount"    column="today_order_amount"    />
        <result property="allOrderAmount"    column="all_order_amount"    />
        <result property="todayOrderCancelTotal"    column="today_order_cancel_total"    />
        <result property="allOrderCancelTotal"    column="all_order_cancel_total"    />
        <result property="todayOrderFinishTotal"    column="today_order_finish_total"    />
        <result property="allOrderFinishTotal"    column="all_order_finish_total"    />
        <result property="provinceCode"    column="province_code"    />
        <result property="provinceName"    column="province_name"    />
        <result property="cityCode"    column="city_code"    />
        <result property="cityName"    column="city_name"    />
        <result property="districtCode"    column="district_code"    />
        <result property="districtName"    column="district_name"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectOrgStatDataVo">
        select org_stat_data_id, dept_id, stat_date, client_total, volunteet_total, today_client_add, today_volunteet_add, today_order_total, all_order_total, today_order_amount, all_order_amount, today_order_cancel_total, all_order_cancel_total, today_order_finish_total, all_order_finish_total, province_code, province_name, city_code, city_name, district_code, district_name, create_time, create_by, update_time, update_by, remark from l_org_stat_data
    </sql>

    <select id="selectOrgStatDataList" parameterType="OrgStatData" resultMap="OrgStatDataResult">
        <include refid="selectOrgStatDataVo"/>
        <where>  
            <if test="deptId != null  and deptId != ''"> and dept_id = #{deptId}</if>
            <if test="statDate != null "> and stat_date = #{statDate}</if>
            <if test="clientTotal != null "> and client_total = #{clientTotal}</if>
            <if test="volunteetTotal != null "> and volunteet_total = #{volunteetTotal}</if>
            <if test="todayClientAdd != null "> and today_client_add = #{todayClientAdd}</if>
            <if test="todayVolunteetAdd != null "> and today_volunteet_add = #{todayVolunteetAdd}</if>
            <if test="todayOrderTotal != null "> and today_order_total = #{todayOrderTotal}</if>
            <if test="allOrderTotal != null "> and all_order_total = #{allOrderTotal}</if>
            <if test="todayOrderAmount != null "> and today_order_amount = #{todayOrderAmount}</if>
            <if test="allOrderAmount != null "> and all_order_amount = #{allOrderAmount}</if>
            <if test="todayOrderCancelTotal != null "> and today_order_cancel_total = #{todayOrderCancelTotal}</if>
            <if test="allOrderCancelTotal != null "> and all_order_cancel_total = #{allOrderCancelTotal}</if>
            <if test="todayOrderFinishTotal != null "> and today_order_finish_total = #{todayOrderFinishTotal}</if>
            <if test="allOrderFinishTotal != null "> and all_order_finish_total = #{allOrderFinishTotal}</if>
            <if test="provinceCode != null  and provinceCode != ''"> and province_code = #{provinceCode}</if>
            <if test="provinceName != null  and provinceName != ''"> and province_name like concat('%', #{provinceName}, '%')</if>
            <if test="cityCode != null  and cityCode != ''"> and city_code = #{cityCode}</if>
            <if test="cityName != null  and cityName != ''"> and city_name like concat('%', #{cityName}, '%')</if>
            <if test="districtCode != null  and districtCode != ''"> and district_code = #{districtCode}</if>
            <if test="districtName != null  and districtName != ''"> and district_name like concat('%', #{districtName}, '%')</if>
        </where>
    </select>
    
    <select id="selectOrgStatDataByOrgStatDataId" parameterType="Long" resultMap="OrgStatDataResult">
        <include refid="selectOrgStatDataVo"/>
        where org_stat_data_id = #{orgStatDataId}
    </select>
    <select id="getCurrentOrgMonthStatDataList" resultType="com.leromro.core.domain.OrgStatData">
        select * from l_org_stat_data
    </select>

    <insert id="insertOrgStatData" parameterType="OrgStatData" useGeneratedKeys="true" keyProperty="orgStatDataId">
        insert into l_org_stat_data
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deptId != null">dept_id,</if>
            <if test="statDate != null">stat_date,</if>
            <if test="clientTotal != null">client_total,</if>
            <if test="volunteetTotal != null">volunteet_total,</if>
            <if test="todayClientAdd != null">today_client_add,</if>
            <if test="todayVolunteetAdd != null">today_volunteet_add,</if>
            <if test="todayOrderTotal != null">today_order_total,</if>
            <if test="allOrderTotal != null">all_order_total,</if>
            <if test="todayOrderAmount != null">today_order_amount,</if>
            <if test="allOrderAmount != null">all_order_amount,</if>
            <if test="todayOrderCancelTotal != null">today_order_cancel_total,</if>
            <if test="allOrderCancelTotal != null">all_order_cancel_total,</if>
            <if test="todayOrderFinishTotal != null">today_order_finish_total,</if>
            <if test="allOrderFinishTotal != null">all_order_finish_total,</if>
            <if test="provinceCode != null">province_code,</if>
            <if test="provinceName != null">province_name,</if>
            <if test="cityCode != null">city_code,</if>
            <if test="cityName != null">city_name,</if>
            <if test="districtCode != null">district_code,</if>
            <if test="districtName != null">district_name,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="deptId != null">#{deptId},</if>
            <if test="statDate != null">#{statDate},</if>
            <if test="clientTotal != null">#{clientTotal},</if>
            <if test="volunteetTotal != null">#{volunteetTotal},</if>
            <if test="todayClientAdd != null">#{todayClientAdd},</if>
            <if test="todayVolunteetAdd != null">#{todayVolunteetAdd},</if>
            <if test="todayOrderTotal != null">#{todayOrderTotal},</if>
            <if test="allOrderTotal != null">#{allOrderTotal},</if>
            <if test="todayOrderAmount != null">#{todayOrderAmount},</if>
            <if test="allOrderAmount != null">#{allOrderAmount},</if>
            <if test="todayOrderCancelTotal != null">#{todayOrderCancelTotal},</if>
            <if test="allOrderCancelTotal != null">#{allOrderCancelTotal},</if>
            <if test="todayOrderFinishTotal != null">#{todayOrderFinishTotal},</if>
            <if test="allOrderFinishTotal != null">#{allOrderFinishTotal},</if>
            <if test="provinceCode != null">#{provinceCode},</if>
            <if test="provinceName != null">#{provinceName},</if>
            <if test="cityCode != null">#{cityCode},</if>
            <if test="cityName != null">#{cityName},</if>
            <if test="districtCode != null">#{districtCode},</if>
            <if test="districtName != null">#{districtName},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateOrgStatData" parameterType="OrgStatData">
        update l_org_stat_data
        <trim prefix="SET" suffixOverrides=",">
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="statDate != null">stat_date = #{statDate},</if>
            <if test="clientTotal != null">client_total = #{clientTotal},</if>
            <if test="volunteetTotal != null">volunteet_total = #{volunteetTotal},</if>
            <if test="todayClientAdd != null">today_client_add = #{todayClientAdd},</if>
            <if test="todayVolunteetAdd != null">today_volunteet_add = #{todayVolunteetAdd},</if>
            <if test="todayOrderTotal != null">today_order_total = #{todayOrderTotal},</if>
            <if test="allOrderTotal != null">all_order_total = #{allOrderTotal},</if>
            <if test="todayOrderAmount != null">today_order_amount = #{todayOrderAmount},</if>
            <if test="allOrderAmount != null">all_order_amount = #{allOrderAmount},</if>
            <if test="todayOrderCancelTotal != null">today_order_cancel_total = #{todayOrderCancelTotal},</if>
            <if test="allOrderCancelTotal != null">all_order_cancel_total = #{allOrderCancelTotal},</if>
            <if test="todayOrderFinishTotal != null">today_order_finish_total = #{todayOrderFinishTotal},</if>
            <if test="allOrderFinishTotal != null">all_order_finish_total = #{allOrderFinishTotal},</if>
            <if test="provinceCode != null">province_code = #{provinceCode},</if>
            <if test="provinceName != null">province_name = #{provinceName},</if>
            <if test="cityCode != null">city_code = #{cityCode},</if>
            <if test="cityName != null">city_name = #{cityName},</if>
            <if test="districtCode != null">district_code = #{districtCode},</if>
            <if test="districtName != null">district_name = #{districtName},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where org_stat_data_id = #{orgStatDataId}
    </update>

    <delete id="deleteOrgStatDataByOrgStatDataId" parameterType="Long">
        delete from l_org_stat_data where org_stat_data_id = #{orgStatDataId}
    </delete>

    <delete id="deleteOrgStatDataByOrgStatDataIds" parameterType="String">
        delete from l_org_stat_data where org_stat_data_id in 
        <foreach item="orgStatDataId" collection="array" open="(" separator="," close=")">
            #{orgStatDataId}
        </foreach>
    </delete>
</mapper>