linwe
2024-06-24 60e1a68fa319cd9e92d632bf678b31af20973508
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?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="org.springblade.modules.grid.mapper.GridmanMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="gridmanResultMap" type="org.springblade.modules.grid.entity.GridmanEntity">
        <result column="id" property="id"/>
        <result column="grid_id" property="gridId"/>
        <result column="user_id" property="userId"/>
        <result column="gridman_name" property="gridmanName"/>
        <result column="mobile" property="mobile"/>
        <result column="remark" property="remark"/>
        <result column="create_time" property="createTime"/>
        <result column="create_user" property="createUser"/>
        <result column="update_time" property="updateTime"/>
        <result column="update_user" property="updateUser"/>
        <result column="is_deleted" property="isDeleted"/>
    </resultMap>
 
    <!--自定义分页查询-->
    <select id="selectGridmanPage" resultType="org.springblade.modules.grid.vo.GridmanVO">
        select
        jgm.*,
        jg.grid_name gridName,jg.community_code communityCode,
        br.name as communityName,
        br.town_name as townName
        from jczz_gridman jgm
        left join jczz_grid jg on jg.grid_code = jgm.grid_code and jg.is_deleted = 0
        left join blade_region br on br.code = jg.community_code
        where jgm.is_deleted = 0
        <if test="gridman.gridmanName!=null and gridman.gridmanName!=''">
            and jgm.gridman_name like concat('%',#{gridman.gridmanName},'%')
        </if>
        <if test="gridman.mobile!=null and gridman.mobile!=''">
            and jgm.mobile like concat('%',#{gridman.mobile},'%')
        </if>
        <if test="gridman.gridId!=null">
            and jg.id = #{gridman.gridId}
        </if>
        <if test="gridman.communityCode!=null and gridman.communityCode!=''">
            and jg.community_code like concat('%',#{gridman.communityCode},'%')
        </if>
        <if test="gridman.communityName!=null and gridman.communityName!=''">
            and br.name like concat('%',#{gridman.communityName},'%')
        </if>
        <if test="gridman.townName!=null and gridman.townName!=''">
            and br.town_name like concat('%',#{gridman.townName},'%')
        </if>
        <if test="isAdministrator==2">
            <choose>
                <when test="regionChildCodesList !=null and regionChildCodesList.size()>0">
                    and jg.community_code in
                    <foreach collection="regionChildCodesList" item="code" open="(" close=")" separator=",">
                        #{code}
                    </foreach>
                </when>
                <otherwise>
                    and jg.community_code in ('')
                </otherwise>
            </choose>
        </if>
    </select>
 
    <!--自定义分页查询-->
    <select id="getGridmanList" resultType="org.springblade.modules.grid.vo.GridmanVO">
        select
        jgm.*
        from jczz_gridman jgm
        where jgm.is_deleted = 0
        <if test="gridman.gridmanName!=null and gridman.gridmanName!=''">
            and jgm.gridman_name like concat('%',#{gridman.gridmanName},'%')
        </if>
        <if test="gridman.mobile!=null and gridman.mobile!=''">
            and jgm.mobile like concat('%',#{gridman.mobile},'%')
        </if>
    </select>
 
    <select id="getGridStatistics" resultType="java.lang.Integer">
        SELECT count(1) number
        FROM jczz_gridman jgm
        LEFT JOIN jczz_grid jg ON jg.grid_code = jgm.grid_code
        <where>
            jg.community_code in
            <foreach collection="communityCodeList" item="code" open="(" close=")" separator=",">
                #{code}
            </foreach>
            AND jg.is_deleted = 0
            <if test="userId!=null and roleType == '1'">
                and jgm.user_id= #{userId}
            </if>
        </where>
    </select>
 
    <select id="getCompanyStatistics" resultType="java.lang.Integer">
        SELECT
        count(1)
        FROM
        jczz_property_company_district jpcd
        LEFT JOIN jczz_district jd ON jd.id = jpcd.district_id
        <where>
            jd.community_code in
            <foreach collection="communityCodeList" item="code" open="(" close=")" separator=",">
                #{code}
            </foreach>
            and jpcd.is_deleted= 0
            <if test="userId!=null and roleType == '1'">
                AND jd.aoi_code in (
                SELECT distinct
                jda.aoi_code
                FROM
                jczz_grid jg
                LEFT JOIN jczz_gridman jgm ON jg.grid_code = jgm.grid_code
                LEFT JOIN jczz_doorplate_address jda ON jda.address_code = jg.house_code
                WHERE
                jgm.user_id = #{userId}
                AND jg.is_deleted = 0
                AND jda.aoi_code IS NOT NULL
                )
            </if>
        </where>
    </select>
 
    <select id="getOwnersCommitteeStatistics" resultType="java.lang.Integer">
        SELECT
        count(1)
        FROM jczz_owners_committee joc LEFT JOIN
        jczz_district jd ON jd.id = joc.area_id
        <where>
            jd.community_code in
            <foreach collection="communityCodeList" item="code" open="(" close=")" separator=",">
                #{code}
            </foreach>
            and joc.delete_flag= 0
            <if test="userId!=null and roleType == '1'">
                AND jd.aoi_code in (
                SELECT distinct
                jda.aoi_code
                FROM
                jczz_grid jg
                LEFT JOIN jczz_gridman jgm ON jg.grid_code = jgm.grid_code
                LEFT JOIN jczz_doorplate_address jda ON jda.address_code = jg.house_code
                WHERE
                jgm.user_id = #{userId}
                AND jg.is_deleted = 0
                AND jda.aoi_code IS NOT NULL
                )
            </if>
        </where>
    </select>
 
 
    <!--网格员表 自定义详情-->
    <select id="getDetail" resultType="org.springblade.modules.grid.vo.GridmanVO">
        select
        jgm.*,jg.community_code communityCode
        from jczz_gridman jgm
        left join jczz_grid jg on jg.grid_code = jgm.grid_code and jg.is_deleted = 0
        where jgm.is_deleted = 0
        and jgm.id = #{gridman.id}
    </select>
 
    <!--查询网格id-->
    <select id="getGridIdByUserId" resultType="java.lang.Integer">
        select
        jgm.grid_id
        from jczz_gridman jgm
        where jgm.is_deleted = 0
        and jgm.user_id = #{userId}
        limit 1
    </select>
 
    <select id="getGridManByCode" resultType="org.springblade.modules.system.entity.User">
        SELECT
            bu.*
        FROM
            blade_user bu
            LEFT JOIN jczz_gridman jgm ON bu.id = jgm.user_id
            LEFT JOIN jczz_grid jg ON jgm.grid_code = jg.grid_code
        WHERE
            jg.community_code IN
            (
            SELECT jg.community_code FROM jczz_grid jg LEFT JOIN jczz_grid_range jgr ON jgr.grid_id = jg.id
            WHERE jgr.house_code = #{houseCode}
            )
            AND bu.is_deleted = 0
    </select>
</mapper>