jinpengyong
2020-12-01 dc9091d686b412eab84d461d13d0611f79e65810
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?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.OrganizationMapper">
    <resultMap id="BaseResultMap" type="com.moral.entity.Organization">
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="name" jdbcType="VARCHAR" property="name"/>
        <result column="rank" jdbcType="INTEGER" property="rank"/>
        <result column="province_code" jdbcType="INTEGER" property="provinceCode"/>
        <result column="city_code" jdbcType="INTEGER" property="cityCode"/>
        <result column="area_code" jdbcType="INTEGER" property="areaCode"/>
        <result column="town_code" jdbcType="BIGINT" property="townCode"/>
        <result column="village_code" jdbcType="BIGINT" property="villageCode"/>
        <result column="address" jdbcType="VARCHAR" property="address"/>
        <result column="telephone" jdbcType="VARCHAR" property="telephone"/>
        <result column="email" jdbcType="VARCHAR" property="email"/>
        <result column="is_delete" jdbcType="CHAR" property="isDelete"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="expire_time" jdbcType="TIMESTAMP" property="expireTime"/>
        <result column="description" jdbcType="VARCHAR" property="description"/>
        <!-- 与省市县一对一的关系 -->
        <association property="areaNames" javaType="com.moral.entity.AreaNames">
            <result column="province_name" property="provinceName" jdbcType="VARCHAR"/>
            <result column="city_name" property="cityName" jdbcType="VARCHAR"/>
            <result column="area_name" property="areaName" jdbcType="VARCHAR"/>
            <result column="town_name" property="townName" jdbcType="VARCHAR"/>
            <result column="village_name" property="villageName" jdbcType="VARCHAR"/>
        </association>
    </resultMap>
 
 
    <select id="getOrganizationByMac" resultMap="BaseResultMap">
        SELECT *
        FROM organization o
        <if test="provinceCode != null" >
        ,province p
        </if>
        <if test="cityCode != null" >
        ,city c
        </if>
        <if test="areaCode != null" >
        ,area a
        </if>
        <if test="townCode != null" >
        ,town t
        </if>
        <if test="villageCode != null" >
        ,village v
        </if>
             <where>
                 <if test="provinceCode != null" >
                   AND o.province_code = p.province_code
                 </if>
                 <if test="cityCode != null" >
                  AND o.city_code = c.city_code
                 </if>
                 <if test="areaCode != null" >
                  AND o.area_code = a.area_code
                 </if>
                 <if test="townCode != null" >
                  AND o.town_code = t.town_code
                 </if>
                 <if test="villageCode != null" >
                  AND o.village_code = v.village_code
                 </if>
                 AND o.id =
                 (select org.id
                 from organization org,
                 monitor_point m,
                 device d
                 where m.id = d.monitor_point_id
                 and m.organization_id = org.id
                 AND d.mac = #{mac})
             </where>
    </select>
 
    <select id="getOrganizationInfoByMac" resultMap="BaseResultMap">
        select org.*
        from organization org,
             monitor_point m,
             device d
        where m.id = d.monitor_point_id
          and m.organization_id = org.id
          and d.mac = #{mac}
    </select>
 
</mapper>