Pu Zhibing
2 天以前 949bf4798368d0fce115993427e03758d4b3c897
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?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.TSiteMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.stylefeng.guns.modular.system.model.TSite">
        <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>
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, name, province, provinceCode, city, cityCode, district, districtCode, state, insertTime, insertUserId
    </sql>
 
    <!--根据条件查询站点列表-->
    <select id="getSiteList" resultType="map" parameterType="com.baomidou.mybatisplus.plugins.Page">
        SELECT * FROM (SELECT uu.`name` as insertUser,IFNULL(ls.num,0) as lineNum,ss.* FROM t_site as ss
        LEFT JOIN sys_user as uu on uu.id = ss.insertUserId
        LEFT JOIN (SELECT COUNT(a.id) as num,siteId FROM t_line_site a left join t_line b on (a.lineId = b.id) where b.state != 3 GROUP BY a.siteId) as ls on ls.siteId = ss.id) as o
        <where>
            o.state != 3
            <if test="beginTime != null and beginTime != '' and endTime != null and endTime != ''">
                AND (o.insertTime between CONCAT(#{beginTime},' 00:00:00') and CONCAT(#{endTime},' 23:59:59'))
            </if>
            <if test="name != null and name != ''">
                and o.name LIKE CONCAT('%',#{name},'%')
            </if>
            <if test="insertUser != null and insertUser != ''">
                and o.insertUser LIKE CONCAT('%',#{insertUser},'%')
            </if>
            <if test="city != null and city != ''">
                and (o.province LIKE CONCAT('%',#{city},'%') or o.city LIKE CONCAT('%',#{city},'%') or o.district LIKE CONCAT('%',#{city},'%'))
            </if>
            <if test="state != null and state != ''">
                and o.state = #{state}
            </if>
        </where>
        order by o.id desc
    </select>
    
    
    <select id="query" resultType="TSite">
        select
        id as id,
        name as name,
        province as province,
        provinceCode as provinceCode,
        city as city,
        cityCode as cityCode,
        district as district,
        districtCode as districtCode,
        state as state,
        insertTime as insertTime,
        insertUserId as insertUserId
        from t_site where state != 3
        <choose>
            <when test="null != provinceCode">
                and provinceCode = #{provinceCode}
            </when>
            <otherwise>
                and provinceCode is null
            </otherwise>
        </choose>
        <choose>
            <when test="null != cityCode">
                and cityCode = #{cityCode}
            </when>
            <otherwise>
                and cityCode is null
            </otherwise>
        </choose>
        <choose>
            <when test="null != districtCode">
                and districtCode = #{districtCode}
            </when>
            <otherwise>
                and districtCode is null
            </otherwise>
        </choose>
    </select>
    <select id="getCompanySiteList" resultType="java.util.Map">
        SELECT * FROM (SELECT uu.`name` as insertUser,IFNULL(ls.num,0) as lineNum,ss.* FROM t_site as ss
        RIGHT JOIN (select * from sys_user  where id=#{id}) as uu on uu.id = ss.insertUserId
        LEFT JOIN (SELECT COUNT(a.id) as num,siteId FROM t_line_site a left join t_line b on (a.lineId = b.id) where b.state != 3 GROUP BY a.siteId) as ls on ls.siteId = ss.id) as o
        <where>
            o.state != 3
            <if test="beginTime != null and beginTime != '' and endTime != null and endTime != ''">
                AND (o.insertTime between CONCAT(#{beginTime},' 00:00:00') and CONCAT(#{endTime},' 23:59:59'))
            </if>
            <if test="name != null and name != ''">
                and o.name LIKE CONCAT('%',#{name},'%')
            </if>
            <if test="insertUser != null and insertUser != ''">
                and o.insertUser LIKE CONCAT('%',#{insertUser},'%')
            </if>
            <if test="city != null and city != ''">
                and (o.province LIKE CONCAT('%',#{city},'%') or o.city LIKE CONCAT('%',#{city},'%') or o.district LIKE CONCAT('%',#{city},'%'))
            </if>
            <if test="state != null and state != ''">
                and o.state = #{state}
            </if>
        </where>
        order by o.id desc
    </select>
</mapper>