<?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.project.BiEmergencyMapper">
    <resultMap id="BaseResultMap" type="cn.com.countrygarden.bi.main.model.project.BiEmergency">
        <!--
          WARNING - @mbg.generated
        -->
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="old_id" jdbcType="VARCHAR" property="oldId"/>
        <result column="org_name" jdbcType="VARCHAR" property="orgName"/>
        <result column="comm_name" jdbcType="VARCHAR" property="commName"/>
        <result column="department_name" jdbcType="VARCHAR" property="departmentName"/>
        <result column="happen_time" jdbcType="VARCHAR" property="happenTime"/>
        <result column="functionary_name" jdbcType="VARCHAR" property="functionaryName"/>
        <result column="functionary_call" jdbcType="VARCHAR" property="functionaryCall"/>
        <result column="level_two" jdbcType="VARCHAR" property="levelTwo"/>
        <result column="level_one" jdbcType="VARCHAR" property="levelOne"/>
        <result column="theme" jdbcType="VARCHAR" property="theme"/>
        <result column="is_casualties" jdbcType="VARCHAR" property="isCasualties"/>
        <result column="casualties_name" jdbcType="VARCHAR" property="casualtiesName"/>
        <result column="casualties_other" jdbcType="VARCHAR" property="casualtiesOther"/>
        <result column="is_property" jdbcType="VARCHAR" property="isProperty"/>
        <result column="loss_party" jdbcType="VARCHAR" property="lossParty"/>
        <result column="future" jdbcType="VARCHAR" property="future"/>
        <result column="sketch" jdbcType="VARCHAR" property="sketch"/>
        <result column="measure" jdbcType="VARCHAR" property="measure"/>
        <result column="risk" jdbcType="VARCHAR" property="risk"/>
        <result column="correlation" jdbcType="VARCHAR" property="correlation"/>
    </resultMap>


    <select id="search" resultMap="BaseResultMap">
        SELECT DISTINCT *
        FROM bi_emergency be
        <where>
            <if test="commName != null and commName !='' ">
                AND be.comm_name like  CONCAT('%',#{commName},'%')
            </if>
            <if test="strTime != null and strTime !=''">
                AND be.happen_time &gt;= STR_TO_DATE(#{strTime},'%Y-%m-%d')
            </if>
            <if test="endTime != null and endTime !=''">
                AND be.happen_time &lt;= STR_TO_DATE(#{endTime},'%Y-%m-%d')
            </if>
        </where>
        <if test="timeSort == 1">
          order by be.happen_time desc
        </if>
        <if test="timeSort == 2">
          order by be.happen_time asc
        </if>
    </select>
</mapper>