ZhuDongming
2019-08-19 5ed2476ff6672d9935682c4f360aa5c76d25d7f0
src/main/resources/mapper/DeviceMapper.xml
@@ -1,344 +1,421 @@
<?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.moral.mapper.DeviceMapper" >
  <resultMap id="BaseResultMap" type="com.moral.entity.Device" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="name" property="name" jdbcType="VARCHAR" />
    <result column="address" property="address" jdbcType="VARCHAR" />
    <result column="longitude" property="longitude" jdbcType="REAL" />
    <result column="latitude" property="latitude" jdbcType="REAL" />
    <result column="mac" property="mac" jdbcType="VARCHAR" />
    <result column="state" property="state" jdbcType="CHAR" />
    <result column="operate_user_id" property="operateUserId" jdbcType="INTEGER" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
    <result column="install_time" property="installTime" jdbcType="TIMESTAMP" />
    <result column="monitor_point_id" property="monitorPointId" jdbcType="INTEGER" />
    <result column="device_version_id" property="deviceVersionId" jdbcType="INTEGER" />
  </resultMap>
  <sql id="Example_Where_Clause" >
    <where >
      <foreach collection="oredCriteria" item="criteria" separator="or" >
        <if test="criteria.valid" >
          <trim prefix="(" suffix=")" prefixOverrides="and" >
            <foreach collection="criteria.criteria" item="criterion" >
              <choose >
                <when test="criterion.noValue" >
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue" >
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue" >
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue" >
                  and ${criterion.condition}
                  <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause" >
    <where >
      <foreach collection="example.oredCriteria" item="criteria" separator="or" >
        <if test="criteria.valid" >
          <trim prefix="(" suffix=")" prefixOverrides="and" >
            <foreach collection="criteria.criteria" item="criterion" >
              <choose >
                <when test="criterion.noValue" >
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue" >
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue" >
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue" >
                  and ${criterion.condition}
                  <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List" >
    id, name, address, longitude, latitude, mac, state, operate_user_id, create_time,
    install_time, monitor_point_id, device_version_id
  </sql>
  <select id="selectByExample" resultMap="BaseResultMap" parameterType="com.moral.entity.DeviceExample" >
    select
    <if test="distinct" >
      distinct
    </if>
    <include refid="Base_Column_List" />
    from device
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null" >
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select
    <include refid="Base_Column_List" />
    from device
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from device
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <delete id="deleteByExample" parameterType="com.moral.entity.DeviceExample" >
    delete from device
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.moral.entity.Device" >
    insert into device (id, name, address,
      longitude, latitude, mac,
      state, operate_user_id, create_time,
      install_time, monitor_point_id, device_version_id
      )
    values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{address,jdbcType=VARCHAR},
      #{longitude,jdbcType=REAL}, #{latitude,jdbcType=REAL}, #{mac,jdbcType=VARCHAR},
      #{state,jdbcType=CHAR}, #{operateUserId,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP},
      #{installTime,jdbcType=TIMESTAMP}, #{monitorPointId,jdbcType=INTEGER}, #{deviceVersionId,jdbcType=INTEGER}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.moral.entity.Device" >
    insert into device
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="name != null" >
        name,
      </if>
      <if test="address != null" >
        address,
      </if>
      <if test="longitude != null" >
        longitude,
      </if>
      <if test="latitude != null" >
        latitude,
      </if>
      <if test="mac != null" >
        mac,
      </if>
      <if test="state != null" >
        state,
      </if>
      <if test="operateUserId != null" >
        operate_user_id,
      </if>
      <if test="createTime != null" >
        create_time,
      </if>
      <if test="installTime != null" >
        install_time,
      </if>
      <if test="monitorPointId != null" >
        monitor_point_id,
      </if>
      <if test="deviceVersionId != null" >
        device_version_id,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=INTEGER},
      </if>
      <if test="name != null" >
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="address != null" >
        #{address,jdbcType=VARCHAR},
      </if>
      <if test="longitude != null" >
        #{longitude,jdbcType=REAL},
      </if>
      <if test="latitude != null" >
        #{latitude,jdbcType=REAL},
      </if>
      <if test="mac != null" >
        #{mac,jdbcType=VARCHAR},
      </if>
      <if test="state != null" >
        #{state,jdbcType=CHAR},
      </if>
      <if test="operateUserId != null" >
        #{operateUserId,jdbcType=INTEGER},
      </if>
      <if test="createTime != null" >
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="installTime != null" >
        #{installTime,jdbcType=TIMESTAMP},
      </if>
      <if test="monitorPointId != null" >
        #{monitorPointId,jdbcType=INTEGER},
      </if>
      <if test="deviceVersionId != null" >
        #{deviceVersionId,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.moral.entity.DeviceExample" resultType="java.lang.Integer" >
    select count(*) from device
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map" >
    update device
    <set >
      <if test="record.id != null" >
        id = #{record.id,jdbcType=INTEGER},
      </if>
      <if test="record.name != null" >
        name = #{record.name,jdbcType=VARCHAR},
      </if>
      <if test="record.address != null" >
        address = #{record.address,jdbcType=VARCHAR},
      </if>
      <if test="record.longitude != null" >
        longitude = #{record.longitude,jdbcType=REAL},
      </if>
      <if test="record.latitude != null" >
        latitude = #{record.latitude,jdbcType=REAL},
      </if>
      <if test="record.mac != null" >
        mac = #{record.mac,jdbcType=VARCHAR},
      </if>
      <if test="record.state != null" >
        state = #{record.state,jdbcType=CHAR},
      </if>
      <if test="record.operateUserId != null" >
        operate_user_id = #{record.operateUserId,jdbcType=INTEGER},
      </if>
      <if test="record.createTime != null" >
        create_time = #{record.createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.installTime != null" >
        install_time = #{record.installTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.monitorPointId != null" >
        monitor_point_id = #{record.monitorPointId,jdbcType=INTEGER},
      </if>
      <if test="record.deviceVersionId != null" >
        device_version_id = #{record.deviceVersionId,jdbcType=INTEGER},
      </if>
    </set>
    <if test="_parameter != null" >
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map" >
    update device
    set id = #{record.id,jdbcType=INTEGER},
      name = #{record.name,jdbcType=VARCHAR},
      address = #{record.address,jdbcType=VARCHAR},
      longitude = #{record.longitude,jdbcType=REAL},
      latitude = #{record.latitude,jdbcType=REAL},
      mac = #{record.mac,jdbcType=VARCHAR},
      state = #{record.state,jdbcType=CHAR},
      operate_user_id = #{record.operateUserId,jdbcType=INTEGER},
      create_time = #{record.createTime,jdbcType=TIMESTAMP},
      install_time = #{record.installTime,jdbcType=TIMESTAMP},
      monitor_point_id = #{record.monitorPointId,jdbcType=INTEGER},
      device_version_id = #{record.deviceVersionId,jdbcType=INTEGER}
    <if test="_parameter != null" >
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.moral.entity.Device" >
    update device
    <set >
      <if test="name != null" >
        name = #{name,jdbcType=VARCHAR},
      </if>
      <if test="address != null" >
        address = #{address,jdbcType=VARCHAR},
      </if>
      <if test="longitude != null" >
        longitude = #{longitude,jdbcType=REAL},
      </if>
      <if test="latitude != null" >
        latitude = #{latitude,jdbcType=REAL},
      </if>
      <if test="mac != null" >
        mac = #{mac,jdbcType=VARCHAR},
      </if>
      <if test="state != null" >
        state = #{state,jdbcType=CHAR},
      </if>
      <if test="operateUserId != null" >
        operate_user_id = #{operateUserId,jdbcType=INTEGER},
      </if>
      <if test="createTime != null" >
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="installTime != null" >
        install_time = #{installTime,jdbcType=TIMESTAMP},
      </if>
      <if test="monitorPointId != null" >
        monitor_point_id = #{monitorPointId,jdbcType=INTEGER},
      </if>
      <if test="deviceVersionId != null" >
        device_version_id = #{deviceVersionId,jdbcType=INTEGER},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.moral.entity.Device" >
    update device
    set name = #{name,jdbcType=VARCHAR},
      address = #{address,jdbcType=VARCHAR},
      longitude = #{longitude,jdbcType=REAL},
      latitude = #{latitude,jdbcType=REAL},
      mac = #{mac,jdbcType=VARCHAR},
      state = #{state,jdbcType=CHAR},
      operate_user_id = #{operateUserId,jdbcType=INTEGER},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      install_time = #{installTime,jdbcType=TIMESTAMP},
      monitor_point_id = #{monitorPointId,jdbcType=INTEGER},
      device_version_id = #{deviceVersionId,jdbcType=INTEGER}
    where id = #{id,jdbcType=INTEGER}
  </update>
     <select id="getDeviceStates" resultType="map">
      SELECT
         COUNT( d.state ) count,
         d.state
      FROM
         device d
      <if test="orgIds != null and orgIds.size > 0">
         ,monitor_point mp,
         monitor_point_organization mpo
      WHERE
         d.monitor_point_id = mp.id
         AND mp.id = mpo.monitor_point_id
         AND mpo.organization_id IN
         <foreach collection="orgIds" item="listItem" open="(" separator="," close=")" >
            #{listItem}
         </foreach>
      </if>
      GROUP BY d.state
   </select>
<?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.moral.mapper.DeviceMapper">
   <resultMap id="ResultMap" type="com.moral.entity.Device">
      <id column="id" jdbcType="INTEGER" property="id" />
      <result column="name" jdbcType="VARCHAR" property="name" />
      <result column="address" jdbcType="VARCHAR" property="address" />
      <result column="longitude" jdbcType="DOUBLE" property="longitude" />
      <result column="latitude" jdbcType="DOUBLE" property="latitude" />
      <result column="mac" jdbcType="VARCHAR" property="mac" />
      <result column="operate_user_id" jdbcType="INTEGER" property="operateUserId" />
      <result column="state" jdbcType="CHAR" property="state" />
      <result column="is_delete" jdbcType="CHAR" property="isDelete" />
      <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
      <result column="install_time" jdbcType="TIMESTAMP" property="installTime" />
      <result column="monitor_point_id" jdbcType="INTEGER" property="monitorPointId" />
      <result column="device_version_id" jdbcType="INTEGER" property="deviceVersionId" />
      <result column="profession_id" jdbcType="INTEGER" property="professionId" />
   </resultMap>
   <resultMap id="BaseResultMap" type="com.moral.entity.Device" extends="ResultMap">
      <association property="operateUser" javaType="com.moral.entity.OperateUser">
         <result column="operate_user_id" property="id" jdbcType="INTEGER" />
         <result column="operate_user_name" property="name" jdbcType="VARCHAR" />
      </association>
      <association property="deviceVersion" javaType="com.moral.entity.DeviceVersion">
         <result column="device_version_id" property="id" jdbcType="INTEGER" />
         <result column="device_version_value" property="version" jdbcType="INTEGER" />
         <result column="device_version_name" property="name" jdbcType="VARCHAR" />
      </association>
      <association property="monitorPoint" javaType="com.moral.entity.MonitorPoint">
         <result column="monitor_point_id" property="id" jdbcType="INTEGER" />
         <result column="monitor_point_name" property="name" jdbcType="VARCHAR" />
         <result column="province_code" property="provinceCode" jdbcType="VARCHAR" />
      </association>
      <association property="profession" javaType="com.moral.entity.Profession">
         <result column="profession_id" property="id" jdbcType="INTEGER" />
         <result column="profession_name" property="name" jdbcType="VARCHAR" />
      </association>
   </resultMap>
   <resultMap id="PropertyResultMap" type="com.moral.entity.Device" extends="BaseResultMap">
      <association property="deviceProperty" javaType="com.moral.entity.DeviceProperty">
         <result column="id" property="id" jdbcType="INTEGER" />
         <result column="device_tech" property="deviceTech" jdbcType="TINYINT" />
         <result column="device_cat" property="deviceCat" jdbcType="TINYINT" />
         <result column="device_source" property="deviceSource" jdbcType="VARCHAR" />
         <result column="ext_c" property="extC" jdbcType="VARCHAR" />
         <result column="ext_d" property="extD" jdbcType="VARCHAR" />
      </association>
   </resultMap>
   <resultMap id="BaseResultWithOrgIdsMap" type="com.moral.entity.Device" extends="BaseResultMap">
      <collection property="organizationIds" column="id" select="selectOrganizationIds"></collection>
   </resultMap>
   <sql id="Example_Where_Clause">
      <where>
         <foreach collection="oredCriteria" item="criteria" separator="or">
            <if test="criteria.valid">
               <trim prefix="(" prefixOverrides="and" suffix=")">
                  <foreach collection="criteria.criteria" item="criterion">
                     <choose>
                        <when test="criterion.noValue">
                           and ${criterion.condition}
                        </when>
                        <when test="criterion.singleValue">
                           and ${criterion.condition} #{criterion.value}
                        </when>
                        <when test="criterion.betweenValue">
                           and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                        </when>
                        <when test="criterion.listValue">
                           and ${criterion.condition}
                           <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                              #{listItem}
                           </foreach>
                        </when>
                     </choose>
                  </foreach>
               </trim>
            </if>
         </foreach>
      </where>
   </sql>
  <sql id="Base_Column_List">
    id, name, address, longitude, latitude, mac, operate_user_id, state, is_delete, create_time,
    install_time, monitor_point_id, device_version_id
  </sql>
   <select id="countByTimes"   resultType="java.util.Map">
      select DATE_FORMAT(create_time,#{format}) as time, COUNT(*) as count from device
      where create_time >= #{start}
      and create_time
      <![CDATA[
      <=
      ]]> #{end}
      and is_delete <![CDATA[
      <>
      ]]> 1
      GROUP BY DATE_FORMAT(create_time,#{format}) ;
   </select>
  <select id="selectWithRelationData" parameterType="tk.mybatis.mapper.entity.Example" resultMap="BaseResultMap">
    select
   dev.*,
   ouser.name as operate_user_name,
   dvn.name as device_version_name,
   mpt.name as monitor_point_name
    from device dev
   left join operate_user ouser on dev.operate_user_id = ouser.id
   left join device_version dvn on dev.device_version_id = dvn.id
   left join monitor_point mpt on dev.monitor_point_id = mpt.id
   where dev.id in (
     select id from device
     <if test="_parameter != null">
        <include refid="Example_Where_Clause" />
     </if>
     <if test="orderByClause != null">
        order by ${orderByClause}
     </if>
     )
  </select>
   <select id="getDeviceStatesByAccount" resultType="java.util.Map">
      SELECT
         COUNT( d.state ) count,
         d.state
      FROM
         device d
      <if test="orgIds != null and orgIds.size &gt; 0">
         ,monitor_point mp
      WHERE
         d.monitor_point_id = mp.id
         AND mp.organization_id IN
         <foreach close=")" collection="orgIds" item="listItem" open="(" separator=",">
            #{listItem}
         </foreach>
      </if>
      GROUP BY d.state
   </select>
   <select id="getSensorsByDevice" resultType="java.util.Map">
      SELECT
         s.`key`,
         s.`name`
      FROM
         sensor s,
         device d,
         device_version_sensor dvs
      WHERE
         d.mac = #{mac}
         AND d.device_version_id = dvs.version_id
         AND dvs.sensor_id = s.id
      ORDER BY
         s.id
   </select>
   <select id="getDeviceVersionIdByMonitorPoint" resultType="java.util.Map">
      SELECT
         device_version_id deviceVersionId
      FROM
         device
      WHERE
         monitor_point_id = #{monitorPoint}
      GROUP BY
         device_version_id
   </select>
   <select id="getDeviceVersionIdByAreaCode" resultType="java.lang.Integer">
      SELECT DISTINCT
         d.device_version_id
      FROM
         monitor_point mp,
         device d
      WHERE
         mp.area_code = #{areaCode}
         AND d.monitor_point_id = mp.id
      <if test="orgIds != null and orgIds.size() > 0">
         AND mp.organization_id IN
         <foreach  collection="orgIds" open="(" separator="," close=")" item="listItem">
            #{listItem}
         </foreach>
      </if>
   </select>
   <select id="getDeviceMacByMonitorPointAndDeviceVersion" resultType="java.lang.String">
      SELECT
         mac
      FROM
         device
      WHERE
         monitor_point_id = #{monitorPointId}
         AND device_version_id = #{deviceVersionId}
   </select>
   <select id="selectByOrgIdAndDevName" resultMap="BaseResultMap">
      SELECT dev.*,dve.version as device_version_value from device dev
      left join monitor_point mpt on dev.monitor_point_id = mpt.id
      left join device_version dve on dev.device_version_id = dve.id
      <where>
      <if test="@com.moral.common.bean.Constants@isNotSpecialOrgId(orgId)">
         (
         1 > 1
         <if test="orgIds!=null and orgIds.size() > 0">
            or mpt.organization_id in
            <foreach collection="orgIds" item="tempOrgId" open="(" close=")" separator=",">
               #{tempOrgId,jdbcType=INTEGER}
            </foreach>
         </if>
         )
      </if>
         and dev.is_delete = 0
         <if test="devState!=null">
            and dev.state = #{devState}
         </if>
         <if test="name!=null and ''!=name">
            and
            (
            dev.name like CONCAT('%',#{name},'%')
            or dev.mac like CONCAT('%',#{name},'%')
            or mpt.name like CONCAT('%',#{name},'%')
            )
         </if>
      </where>
   </select>
   <select id="selectByOrgIdAndMpId" resultMap="BaseResultMap">
      SELECT dev.*,dve.version as device_version_value from device dev
      left join monitor_point mpt on dev.monitor_point_id = mpt.id
      left join device_version dve on dev.device_version_id = dve.id
      <where>
         <if test="@com.moral.common.bean.Constants@isNotSpecialOrgId(orgId)">
            (
            1 > 1
            <if test="orgIds!=null and orgIds.size() > 0">
               or mpt.organization_id in
               <foreach collection="orgIds" item="tempOrgId" open="(" close=")" separator=",">
                  #{tempOrgId,jdbcType=INTEGER}
               </foreach>
            </if>
            )
         </if>
         and dev.monitor_point_id = #{mpId}
         and dev.is_delete = 0
      </where>
   </select>
   <select id="selectByMap" parameterType="java.util.Map" resultMap="BaseResultMap">
      SELECT dev.*,dve.version as device_version_value from device dev
      left join monitor_point  mpt on dev.monitor_point_id = mpt.id
        left join device_version dve on dev.device_version_id = dve.id
      <where>
         <if test="@com.moral.common.bean.Constants@isNotSpecialOrgId(orgId)">
            (
            1 > 1
            <if test="orgIds!=null and orgIds.size() > 0">
               or mpt.organization_id in
               <foreach collection="orgIds" item="tempOrgId" open="(" close=")" separator=",">
                  #{tempOrgId,jdbcType=INTEGER}
               </foreach>
            </if>
            )
         </if>
         <![CDATA[
         AND dev.longitude < #{mapBounds.Ge,jdbcType=NUMERIC}
            AND dev.longitude > #{mapBounds.Le,jdbcType=NUMERIC}
            AND dev.latitude  < #{mapBounds.Fe,jdbcType=NUMERIC}
            AND dev.latitude  > #{mapBounds.Ke,jdbcType=NUMERIC}
            ]]>
           <if test="regionCode != null">
           AND mpt.${regionType}_code = #{regionCode}
           </if>
         AND dev.is_delete =0
      </where>
   </select>
   <!-- resultMap引用 -->
   <select id="selectOrganizationIds" resultType="java.lang.Integer">
      call proc_organizationIds_GetByDeviceId(#{id,jdbcType=INTEGER});
   </select>
   <select id="selectWithOrgIdsByMac" parameterType="java.lang.String" resultMap="BaseResultWithOrgIdsMap">
      select
      dev.*,
      mpt.name as monitor_point_name,
      pro.name as profession_name,
      dvn.version as device_version_value
      from device dev
      left join device_version dvn on dev.device_version_id = dvn.id
        left join monitor_point  mpt on dev.monitor_point_id = mpt.id
        left join profession  pro on pro.id = dev.profession_id
      where dev.mac = #{mac,jdbcType=VARCHAR}
      limit 0,1
   </select>
   <select id="getDeviceCountByRegion" resultType="java.lang.Integer">
      SELECT
         COUNT( * )
      FROM
         device d
      WHERE
         d.is_delete = 0
         AND d.monitor_point_id IN (
            SELECT
               mp.id
            FROM
               monitor_point mp
            WHERE
               mp.is_delete = 0
               <if test="provinceCode != null">
               AND mp.province_code = #{provinceCode}
               </if>
               <if test="cityCode != null">
               AND mp.city_code = #{cityCode}
               </if>
               <if test="areaCode != null">
               AND mp.area_code = #{areaCode}
               </if>
               <if test="townCode != null">
               AND mp.town_code = #{townCode}
               </if>
               <if test="villageCode != null">
               AND mp.village_code = #{villageCode}
               </if>
         )
         <if test="professionId != null">
         AND d.profession_id = #{professionId}
         </if>
   </select>
   <select id="getDevicesByProfession" resultType="com.moral.entity.Device">
      SELECT
         *
      FROM
         device d
      WHERE
         d.is_delete = 0
         AND d.monitor_point_id IN (
            SELECT
               mp.id
            FROM
               monitor_point mp
            WHERE
               mp.is_delete = 0
               <if test="provinceCode != null">
               AND mp.province_code = #{provinceCode}
               </if>
               <if test="cityCode != null">
               AND mp.city_code = #{cityCode}
               </if>
               <if test="areaCode != null">
               AND mp.area_code = #{areaCode}
               </if>
               <if test="monitorPointId != null">
               AND mp.id = #{monitorPointId}
               </if>
               <if test="townCode != null">
               AND mp.town_code = #{townCode}
               </if>
               <if test="villageCode != null">
               AND mp.village_code = #{villageCode}
               </if>
         )
         <if test="professionId != null">
         AND d.profession_id = #{professionId}
         </if>
   </select>
   <select id="getDevicesByOrganizationId" resultMap="ResultMap">
      SELECT
         d.*
      FROM
         device d,
         monitor_point mp
      WHERE
         d.monitor_point_id = mp.id
         AND d.is_delete = 0
         AND mp.is_delete = 0
         AND mp.organization_id = #{organizationId}
   </select>
   <select id="getDevicesStateByRegion" resultType="map">
      SELECT
         d.id deviceId,d.mac,d.state,d.name deviceName,
         mp.id,mp.name
      FROM
         device d ,
         monitor_point mp
      <where>
         d.monitor_point_id = mp.id
         AND d.is_delete = 0
         AND mp.is_delete = 0
         AND mp.${regionType}_code = #{regionCode}
      <if test="orgIds != null and orgIds.size &gt; 0">
         AND mp.organization_id IN
         <foreach  collection="orgIds" open="(" separator="," close=")" item="listItem">
            #{listItem}
         </foreach>
      </if>
      </where>
   </select>
   <select id="getDeviceList" resultMap="PropertyResultMap">
      select
         dev.*,
         ouser.name as operate_user_name,
         dvn.name as device_version_name,
         mpt.name as monitor_point_name,
         mpt.province_code,
         dp.device_tech,
         dp.device_cat,
         dp.device_source,
         dp.ext_c,
         dp.ext_d
      from device dev
      left join operate_user ouser on dev.operate_user_id = ouser.id
      left join device_version dvn on dev.device_version_id = dvn.id
      left join monitor_point mpt on dev.monitor_point_id = mpt.id
      left join device_property dp on dev.id = dp.id
      where dev.id in (
         select id from device
         <if test="_parameter != null">
            <include refid="Example_Where_Clause" />
         </if>
         <if test="orderByClause != null">
            order by ${orderByClause}
         </if>
      )
   </select>
   <select id="getLimitDataByDevice" resultType="String">
      SELECT limit_val FROM view_device_density WHERE mac = #{mac}
   </select>
</mapper>