luodangjia
2024-06-11 9d2babb8bb99d55d76eab0558fd9f510652b270c
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
<?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.stylefeng.guns.modular.system.dao.SiteMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.stylefeng.guns.modular.system.model.Site">
        <id column="id" property="id"/>
        <result column="name" property="name"/>
        <result column="province" property="province"/>
        <result column="provinceCode" property="provinceCode"/>
        <result column="city" property="city"/>
        <result column="cityCode" property="cityCode"/>
        <result column="district" property="district"/>
        <result column="districtCode" property="districtCode"/>
        <result column="state" property="state"/>
        <result column="insertTime" property="insertTime"/>
        <result column="insertUserId" property="insertUserId"/>
    </resultMap>
 
 
 
 
    <select id="querySite" resultType="map">
        select * from
        (
        select si.id as id, si.`name` as `name`, si.provinceCode as cityCode, si.province as cityName from t_site si
        where si.city like '%市' and si.state = 1 and si.id in
        (
        select ls.siteId
        from t_line_site ls
        left join t_line_company lc on (ls.lineId = lc.lineId)
        where 1 = 1
        <if test="null != companyId">
            and lc.companyId = #{companyId}
        </if>
        )
 
        UNION ALL
        select si.id as id, si.`name` as `name`, si.cityCode as cityCode, si.city as cityName from t_site si
        where si.city not like '%市' and si.state = 1 and si.id in
        (
        select ls.siteId from t_line_site ls
        left join t_line_company lc on (ls.lineId = lc.lineId)
        where 1 = 1
        <if test="null != companyId">
            and lc.companyId = #{companyId}
        </if>
        )
        ) as a where 1 = 1
        <if test="null != startSiteId">
            and a.id in(select siteId from t_line_site where lineId in(select lineId from t_line_site where siteId = #{startSiteId} and type = 1) and type = 2)
        </if>
    </select>
</mapper>