<?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.insuranceOrder.InsuranceOrderMapper">
    <resultMap id="BaseResultMap" type="cn.com.countrygarden.bi.main.model.insuranceOrder.InsuranceOrder">
        <id column="id" property="id" />
        <result column="region_code" property="regionCode" />
        <result column="region_name" property="regionName" />
        <result column="project_code" property="projectCode" />
        <result column="project_name" property="projectName" />
        <result column="month_date" property="monthDate" />
        <result column="insurance_number" property="insuranceNumber" />
        <result column="product_name" property="productName" />
        <result column="agent_name" property="agentName" />
        <result column="post" property="post" />
        <result column="policyholder" property="policyholder" />
        <result column="insured" property="insured" />
        <result column="premium" property="premium" />
        <result column="transaction_date" property="transactionDate" />
        <result column="enable" property="enable" />
        <result column="create_time" property="createTime" />
        <result column="create_by" property="createBy" />
        <result column="create_name" property="createName" />
        <result column="update_time" property="updateTime" />
        <result column="update_by" property="updateBy" />
        <result column="brokerage_fees" property="brokerageFees" />
    </resultMap>

    <select id="queryPageList" resultType="cn.com.countrygarden.bi.main.model.insuranceOrder.InsuranceOrder">
               SELECT id AS id,month_date AS monthDate,insurance_number AS insuranceNumber,product_name AS productName,agent_name AS agentName,
              post AS post,region_code AS regionCode,region_name AS regionName,project_code AS projectCode,project_name AS projectName,policyholder AS policyholder,
              insured AS insured,premium AS premium,transaction_date AS transactionDate,create_time AS createTime,create_by AS createBy,
              update_time AS updateTime,update_by AS updateBy,create_name as createName,brokerage_fees as brokerageFees
             FROM insurance_order
            WHERE `enable`=1
        <if test="insuranceOrder.regionCode!=null and insuranceOrder.regionCode!=''">
            and region_code=#{insuranceOrder.regionCode}
        </if>
        <if test="insuranceOrder.projectCode!=null and insuranceOrder.projectCode!=''">
            and project_code=#{insuranceOrder.projectCode}
        </if>
        <if test="insuranceOrder.insuranceNumber!=null and insuranceOrder.insuranceNumber!=''">
            and insurance_number like concat('%',#{insuranceOrder.insuranceNumber},'%')
        </if>
        <if test="insuranceOrder.productName!=null and insuranceOrder.productName!=''">
            and product_name like concat('%',#{insuranceOrder.productName},'%')
        </if>
        <if test="insuranceOrder.monthDate!=null and insuranceOrder.monthDate!=''">
            and month_date=#{insuranceOrder.monthDate}
        </if>
        <if test="insuranceOrder.transactionDate1!=null and insuranceOrder.transactionDate1!='' and insuranceOrder.transactionDate2!=null and insuranceOrder.transactionDate2!=''">
            and transaction_date BETWEEN #{insuranceOrder.transactionDate1} and #{insuranceOrder.transactionDate2}
        </if>
        <if test="organCodeString!=null and organCodeString.size()!=0">
            and (region_code in
            <foreach collection="organCodeString" item="organCodeString" index="index" open="(" close=")" separator=",">
                #{organCodeString}
            </foreach>
        </if>
        <if test="commIdString!=null and commIdString.size()!=0">
            or project_code in
            <foreach collection="commIdString" item="commIdString" index="index" open="(" close=")" separator=",">
                #{commIdString}
            </foreach>
            )
        </if>
           ORDER BY create_time DESC
    </select>

    <select id="queryPageListOrg" resultType="cn.com.countrygarden.bi.main.model.insuranceOrder.InsuranceOrder">
        SELECT id AS id,month_date AS monthDate,insurance_number AS insuranceNumber,product_name AS productName,agent_name AS agentName,
        post AS post,region_code AS regionCode,region_name AS regionName,project_code AS projectCode,project_name AS projectName,policyholder AS policyholder,
        insured AS insured,premium AS premium,transaction_date AS transactionDate,create_time AS createTime,create_by AS createBy,
        update_time AS updateTime,update_by AS updateBy,create_name as createName,brokerage_fees as brokerageFees
        FROM insurance_order
        WHERE `enable`=1
        <if test="insuranceOrder.regionCode!=null and insuranceOrder.regionCode!=''">
            and region_code=#{insuranceOrder.regionCode}
        </if>
        <if test="insuranceOrder.projectCode!=null and insuranceOrder.projectCode!=''">
            and project_code=#{insuranceOrder.projectCode}
        </if>
        <if test="insuranceOrder.insuranceNumber!=null and insuranceOrder.insuranceNumber!=''">
            and insurance_number like concat('%',#{insuranceOrder.insuranceNumber},'%')
        </if>
        <if test="insuranceOrder.productName!=null and insuranceOrder.productName!=''">
            and product_name like concat('%',#{insuranceOrder.productName},'%')
        </if>
        <if test="insuranceOrder.monthDate!=null and insuranceOrder.monthDate!=''">
            and month_date=#{insuranceOrder.monthDate}
        </if>
        <if test="insuranceOrder.transactionDate1!=null and insuranceOrder.transactionDate1!='' and insuranceOrder.transactionDate2!=null and insuranceOrder.transactionDate2!=''">
            and transaction_date BETWEEN #{insuranceOrder.transactionDate1} and #{insuranceOrder.transactionDate2}
        </if>
        <if test="organCodeString!=null and organCodeString.size()!=0">
            and region_code in
            <foreach collection="organCodeString" item="organCodeString" index="index" open="(" close=")" separator=",">
                #{organCodeString}
            </foreach>
        </if>
        ORDER BY create_time DESC
    </select>

    <select id="queryPageListComm" resultType="cn.com.countrygarden.bi.main.model.insuranceOrder.InsuranceOrder">
        SELECT id AS id,month_date AS monthDate,insurance_number AS insuranceNumber,product_name AS productName,agent_name AS agentName,
        post AS post,region_code AS regionCode,region_name AS regionName,project_code AS projectCode,project_name AS projectName,policyholder AS policyholder,
        insured AS insured,premium AS premium,transaction_date AS transactionDate,create_time AS createTime,create_by AS createBy,
        update_time AS updateTime,update_by AS updateBy,create_name as createName,brokerage_fees as brokerageFees
        FROM insurance_order
        WHERE `enable`=1
        <if test="insuranceOrder.regionCode!=null and insuranceOrder.regionCode!=''">
            and region_code=#{insuranceOrder.regionCode}
        </if>
        <if test="insuranceOrder.projectCode!=null and insuranceOrder.projectCode!=''">
            and project_code=#{insuranceOrder.projectCode}
        </if>
        <if test="insuranceOrder.insuranceNumber!=null and insuranceOrder.insuranceNumber!=''">
            and insurance_number like concat('%',#{insuranceOrder.insuranceNumber},'%')
        </if>
        <if test="insuranceOrder.productName!=null and insuranceOrder.productName!=''">
            and product_name like concat('%',#{insuranceOrder.productName},'%')
        </if>
        <if test="insuranceOrder.monthDate!=null and insuranceOrder.monthDate!=''">
            and month_date=#{insuranceOrder.monthDate}
        </if>
        <if test="insuranceOrder.transactionDate1!=null and insuranceOrder.transactionDate1!='' and insuranceOrder.transactionDate2!=null and insuranceOrder.transactionDate2!=''">
            and transaction_date BETWEEN #{insuranceOrder.transactionDate1} and #{insuranceOrder.transactionDate2}
        </if>
        <if test="commIdString!=null and commIdString.size()!=0">
            and project_code in
            <foreach collection="commIdString" item="commIdString" index="index" open="(" close=")" separator=",">
                #{commIdString}
            </foreach>
        </if>
        ORDER BY create_time DESC
    </select>

    <update id="update">
              UPDATE  insurance_order
              <set>
                  <if test="monthDate!=null and monthDate!=''">month_date=#{monthDate},</if>
                  <if test="insuranceNumber!=null and insuranceNumber!=''">insurance_number=#{insuranceNumber},</if>
                  <if test="productName!=null and productName!=''">product_name=#{productName},</if>
                  <if test="agentName!=null and agentName!=''">agent_name=#{agentName},</if>
                  <if test="post!=null and post!=''">post=#{post},</if>
                  <if test="regionCode!=null and regionCode!=''">region_code=#{regionCode},</if>
                  <if test="regionName!=null and regionName!=''">region_name=#{regionName},</if>
                  <if test="projectCode!=null ">project_code=#{projectCode},</if>
                  <if test="projectName!=null">project_name=#{projectName},</if>
                  <if test="policyholder!=null and policyholder!=''">policyholder=#{policyholder},</if>
                  <if test="insured!=null and insured!=''">insured=#{insured},</if>
                  <if test="premium!=null">premium=#{premium},</if>
                  <if test="transactionDate!=null and transactionDate!=''">transaction_date=#{transactionDate},</if>
                  <if test="updateTime!=null">update_time=#{updateTime},</if>
                  <if test="updateBy!=null and updateBy!=''">update_by=#{updateBy},</if>
                  <if test="brokerageFees!=null">brokerage_fees=#{brokerageFees},</if>
              </set>
                WHERE id = #{id};
    </update>

    <update id="deleteupdate">
         UPDATE  insurance_order SET
          enable=0,
          update_time = #{updateTime},
          update_by=#{updateBy}
          WHERE id = #{id};
    </update>

    <select id="evaluationrddInsuranceOrder" resultType="cn.com.countrygarden.bi.main.dto.insuranceOrder.InsuranceOrderVO">
        SELECT id AS id,month_date AS monthDate,insurance_number AS insuranceNumber,product_name AS productName,agent_name AS agentName,
        post AS post,region_code AS regionCode,region_name AS regionName,project_code AS projectCode,project_name AS projectName,policyholder AS policyholder,
        insured AS insured,premium AS premium,transaction_date AS transactionDate,create_time AS createTime,create_by AS createBy,update_time AS updateTime,update_by AS updateBy
        ,brokerage_fees as brokerageFees
        FROM insurance_order
        WHERE `enable`=1
        <if test="rids!=null and rids.size()!=0">
            and id in
            <foreach collection="rids" item="rids" index="index" open="(" close=")" separator=",">
                #{rids}
            </foreach>
        </if>
        <if test="insuranceOrder.regionCode!=null and insuranceOrder.regionCode!=''">
            and region_code=#{insuranceOrder.regionCode}
        </if>
        <if test="insuranceOrder.projectCode!=null and insuranceOrder.projectCode!=''">
            and project_code=#{insuranceOrder.projectCode}
        </if>
        <if test="insuranceOrder.insuranceNumber!=null and insuranceOrder.insuranceNumber!=''">
            and insurance_number like concat('%',#{insuranceOrder.insuranceNumber},'%')
        </if>
        <if test="insuranceOrder.productName!=null and insuranceOrder.productName!=''">
            and product_name like concat('%',#{insuranceOrder.productName},'%')
        </if>
        <if test="insuranceOrder.monthDate!=null and insuranceOrder.monthDate!=''">
            and month_date=#{insuranceOrder.monthDate}
        </if>
        <if test="insuranceOrder.transactionDate1!=null and insuranceOrder.transactionDate1!='' and insuranceOrder.transactionDate2!=null and insuranceOrder.transactionDate2!=''">
            and transaction_date BETWEEN #{insuranceOrder.transactionDate1} and #{insuranceOrder.transactionDate2}
        </if>
        <if test="organCodeString!=null and organCodeString.size()!=0">
            and (region_code in
            <foreach collection="organCodeString" item="organCodeString" index="index" open="(" close=")" separator=",">
                #{organCodeString}
            </foreach>
        </if>
        <if test="commIdString!=null and commIdString.size()!=0">
            or project_code in
            <foreach collection="commIdString" item="commIdString" index="index" open="(" close=")" separator=",">
                #{commIdString}
            </foreach>
            )
        </if>

        ORDER BY create_time DESC
    </select>

    <select id="selectuserRoles" resultType="cn.com.countrygarden.bi.main.model.sys.UserRoles">
    SELECT id as id,role_code as roleCode,user_code as userCode,created_date as createdDate
    ,created_by as createdBy,updated_date as updatedDate,updated_by as updatedBy
    FROM user_roles
    WHERE user_code=#{userCode}
    ORDER BY id
    </select>

    <select id="selectEdit" resultType="cn.com.countrygarden.bi.main.model.insuranceOrder.InsuranceOrder">
        <![CDATA[
         SELECT id AS id,month_date AS monthDate,insurance_number AS insuranceNumber,product_name AS productName,agent_name AS agentName,
              post AS post,region_code AS regionCode,region_name AS regionName,project_code AS projectCode,project_name AS projectName,policyholder AS policyholder,
              insured AS insured,premium AS premium,transaction_date AS transactionDate,create_time AS createTime,create_by AS createBy,
              update_time AS updateTime,update_by AS updateBy,create_name as createName,brokerage_fees as brokerageFees
             FROM insurance_order
            WHERE `enable`=1 and id<>#{insuranceOrder.id} and insurance_number=#{insuranceOrder.insuranceNumber}

             ]]>
    </select>

    <select id="evaluationrddInsuranceOrderCodeString" resultType="cn.com.countrygarden.bi.main.dto.insuranceOrder.InsuranceOrderVO">
        SELECT id AS id,month_date AS monthDate,insurance_number AS insuranceNumber,product_name AS productName,agent_name AS agentName,
        post AS post,region_code AS regionCode,region_name AS regionName,project_code AS projectCode,project_name AS projectName,policyholder AS policyholder,
        insured AS insured,premium AS premium,transaction_date AS transactionDate,create_time AS createTime,create_by AS createBy,update_time AS updateTime,update_by AS updateBy
        ,brokerage_fees as brokerageFees
        FROM insurance_order
        WHERE `enable`=1
        <if test="rids!=null and rids.size()!=0">
            and id in
            <foreach collection="rids" item="rids" index="index" open="(" close=")" separator=",">
                #{rids}
            </foreach>
        </if>
        <if test="insuranceOrder.regionCode!=null and insuranceOrder.regionCode!=''">
            and region_code=#{insuranceOrder.regionCode}
        </if>
        <if test="insuranceOrder.projectCode!=null and insuranceOrder.projectCode!=''">
            and project_code=#{insuranceOrder.projectCode}
        </if>
        <if test="insuranceOrder.insuranceNumber!=null and insuranceOrder.insuranceNumber!=''">
            and insurance_number like concat('%',#{insuranceOrder.insuranceNumber},'%')
        </if>
        <if test="insuranceOrder.productName!=null and insuranceOrder.productName!=''">
            and product_name like concat('%',#{insuranceOrder.productName},'%')
        </if>
        <if test="insuranceOrder.monthDate!=null and insuranceOrder.monthDate!=''">
            and month_date=#{insuranceOrder.monthDate}
        </if>
        <if test="insuranceOrder.transactionDate1!=null and insuranceOrder.transactionDate1!='' and insuranceOrder.transactionDate2!=null and insuranceOrder.transactionDate2!=''">
            and transaction_date BETWEEN #{insuranceOrder.transactionDate1} and #{insuranceOrder.transactionDate2}
        </if>
        <if test="organCodeString!=null and organCodeString.size()!=0">
            and region_code in
            <foreach collection="organCodeString" item="organCodeString" index="index" open="(" close=")" separator=",">
                #{organCodeString}
            </foreach>
        </if>
        ORDER BY create_time DESC
    </select>

    <select id="evaluationrddInsuranceOrderComm" resultType="cn.com.countrygarden.bi.main.dto.insuranceOrder.InsuranceOrderVO">
        SELECT id AS id,month_date AS monthDate,insurance_number AS insuranceNumber,product_name AS productName,agent_name AS agentName,
        post AS post,region_code AS regionCode,region_name AS regionName,project_code AS projectCode,project_name AS projectName,policyholder AS policyholder,
        insured AS insured,premium AS premium,transaction_date AS transactionDate,create_time AS createTime,create_by AS createBy,update_time AS updateTime,update_by AS updateBy
        ,brokerage_fees as brokerageFees
        FROM insurance_order
        WHERE `enable`=1
        <if test="rids!=null and rids.size()!=0">
            and id in
            <foreach collection="rids" item="rids" index="index" open="(" close=")" separator=",">
                #{rids}
            </foreach>
        </if>
        <if test="insuranceOrder.regionCode!=null and insuranceOrder.regionCode!=''">
            and region_code=#{insuranceOrder.regionCode}
        </if>
        <if test="insuranceOrder.projectCode!=null and insuranceOrder.projectCode!=''">
            and project_code=#{insuranceOrder.projectCode}
        </if>
        <if test="insuranceOrder.insuranceNumber!=null and insuranceOrder.insuranceNumber!=''">
            and insurance_number like concat('%',#{insuranceOrder.insuranceNumber},'%')
        </if>
        <if test="insuranceOrder.productName!=null and insuranceOrder.productName!=''">
            and product_name like concat('%',#{insuranceOrder.productName},'%')
        </if>
        <if test="insuranceOrder.monthDate!=null and insuranceOrder.monthDate!=''">
            and month_date=#{insuranceOrder.monthDate}
        </if>
        <if test="insuranceOrder.transactionDate1!=null and insuranceOrder.transactionDate1!='' and insuranceOrder.transactionDate2!=null and insuranceOrder.transactionDate2!=''">
            and transaction_date BETWEEN #{insuranceOrder.transactionDate1} and #{insuranceOrder.transactionDate2}
        </if>
        <if test="commIdString!=null and commIdString.size()!=0">
            and project_code in
            <foreach collection="commIdString" item="commIdString" index="index" open="(" close=")" separator=",">
                #{commIdString}
            </foreach>
        </if>
        ORDER BY create_time DESC
    </select>

</mapper>