xuekang
2024-05-13 15a0280ae9e7db96fdf0744c722d214d2cb5a0e5
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
<?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.nuvole.four.mapper.SysOrgMapper">
  <resultMap id="BaseResultMap" type="com.nuvole.four.domain.SysOrg">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="org_code" jdbcType="VARCHAR" property="orgCode" />
    <result column="user_org_code" jdbcType="VARCHAR" property="userOrgCode" />
    <result column="pid" jdbcType="BIGINT" property="pid" />
    <result column="lv" jdbcType="INTEGER" property="lv" />
    <result column="sort_no" jdbcType="INTEGER" property="sortNo" />
    <result column="state" jdbcType="INTEGER" property="state" />
    <result column="note" jdbcType="VARCHAR" property="note" />
    <result column="lon" jdbcType="VARCHAR" property="lon" />
    <result column="lat" jdbcType="VARCHAR" property="lat" />
    <result column="phone" jdbcType="VARCHAR" property="phone" />
    <result column="open_time" jdbcType="VARCHAR" property="openTime" />
    <result column="address" jdbcType="VARCHAR" property="address" />
  </resultMap>
  <resultMap id="xqMap" type="HashMap">
    <result column="id" property="key" jdbcType="BIGINT"/>
    <result column="name" property="value" jdbcType="VARCHAR" />
  </resultMap>
  <sql id="Base_Column_List">
    id, name, org_code, user_org_code, pid, lv, sort_no, state, note, lon, lat,phone,open_time, address
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from sys_org
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from sys_org
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <insert id="insert" parameterType="com.nuvole.four.domain.SysOrg">
    insert into sys_org (id, name, org_code,
      user_org_code, pid, lv,
      sort_no, state, note,
      lon, lat,phone,open_time, address)
    values (#{id,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR}, #{orgCode,jdbcType=VARCHAR},
      #{userOrgCode,jdbcType=VARCHAR}, #{pid,jdbcType=BIGINT}, #{lv,jdbcType=INTEGER},
      #{sortNo,jdbcType=INTEGER}, #{state,jdbcType=INTEGER}, #{note,jdbcType=VARCHAR},
      #{lon,jdbcType=VARCHAR}, #{lat,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR}, #{openTime,jdbcType=VARCHAR}, #{address,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.nuvole.four.domain.SysOrg">
    insert into sys_org
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="name != null">
        name,
      </if>
      <if test="orgCode != null">
        org_code,
      </if>
      <if test="userOrgCode != null">
        user_org_code,
      </if>
      <if test="pid != null">
        pid,
      </if>
      <if test="lv != null">
        lv,
      </if>
      <if test="sortNo != null">
        sort_no,
      </if>
      <if test="state != null">
        state,
      </if>
      <if test="note != null">
        note,
      </if>
      <if test="lon != null">
        lon,
      </if>
      <if test="lat != null">
        lat,
      </if>
      <if test="phone != null">
        phone,
      </if>
      <if test="openTime != null">
        open_time,
      </if>
       <if test="address != null">
        address,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=BIGINT},
      </if>
      <if test="name != null">
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="orgCode != null">
        #{orgCode,jdbcType=VARCHAR},
      </if>
      <if test="userOrgCode != null">
        #{userOrgCode,jdbcType=VARCHAR},
      </if>
      <if test="pid != null">
        #{pid,jdbcType=BIGINT},
      </if>
      <if test="lv != null">
        #{lv,jdbcType=INTEGER},
      </if>
      <if test="sortNo != null">
        #{sortNo,jdbcType=INTEGER},
      </if>
      <if test="state != null">
        #{state,jdbcType=INTEGER},
      </if>
      <if test="note != null">
        #{note,jdbcType=VARCHAR},
      </if>
      <if test="lon != null">
        #{lon,jdbcType=VARCHAR},
      </if>
      <if test="lat != null">
        #{lat,jdbcType=VARCHAR},
      </if>
      <if test="phone != null">
        #{phone,jdbcType=VARCHAR},
      </if> <if test="openTime != null">
        #{openTime,jdbcType=VARCHAR},
      </if> <if test="address != null">
        #{address,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.nuvole.four.domain.SysOrg">
    update sys_org
    <set>
      <if test="name != null">
        name = #{name,jdbcType=VARCHAR},
      </if>
      <if test="orgCode != null">
        org_code = #{orgCode,jdbcType=VARCHAR},
      </if>
      <if test="userOrgCode != null">
        user_org_code = #{userOrgCode,jdbcType=VARCHAR},
      </if>
      <if test="pid != null">
        pid = #{pid,jdbcType=BIGINT},
      </if>
      <if test="lv != null">
        lv = #{lv,jdbcType=INTEGER},
      </if>
      <if test="sortNo != null">
        sort_no = #{sortNo,jdbcType=INTEGER},
      </if>
      <if test="state != null">
        state = #{state,jdbcType=INTEGER},
      </if>
      <if test="note != null">
        note = #{note,jdbcType=VARCHAR},
      </if>
      <if test="lon != null">
        lon = #{lon,jdbcType=VARCHAR},
      </if>
      <if test="lat != null">
        lat = #{lat,jdbcType=VARCHAR},
      </if>
      <if test="phone != null">
        phone = #{phone,jdbcType=VARCHAR},
      </if>
      <if test="openTime != null">
        open_time = #{openTime,jdbcType=VARCHAR},
      </if>
      <if test="address != null">
        address = #{address,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.nuvole.four.domain.SysOrg">
    update sys_org
    set name = #{name,jdbcType=VARCHAR},
      org_code = #{orgCode,jdbcType=VARCHAR},
      user_org_code = #{userOrgCode,jdbcType=VARCHAR},
      pid = #{pid,jdbcType=BIGINT},
      lv = #{lv,jdbcType=INTEGER},
      sort_no = #{sortNo,jdbcType=INTEGER},
      state = #{state,jdbcType=INTEGER},
      note = #{note,jdbcType=VARCHAR},
      lon = #{lon,jdbcType=VARCHAR},
      lat = #{lat,jdbcType=VARCHAR},
      phone = #{phone,jdbcType=VARCHAR},
      open_time = #{openTime,jdbcType=VARCHAR},
      address = #{address,jdbcType=VARCHAR}
    where id = #{id,jdbcType=BIGINT}
  </update>
 
 
  <select id="selectAll" parameterType="map" resultMap="BaseResultMap">
    select <include refid="Base_Column_List" /> from sys_org
    <where>
      <choose>
        <when test="pid != null">
          and pid = #{pid}
        </when>
        <otherwise>
          <if test="id != null">
            and id = #{id}
          </if>
        </otherwise>
      </choose>
      <if test="name!=null and name!=''">
        and name like CONCAT('%',#{name},'%')
      </if>
      <if test="userOrgCode!=null and userOrgCode!=''">
        and user_org_code like CONCAT(CONCAT('%',#{userOrgCode},'%'))
      </if>
      <if test="state!=null">
        and state = #{state}
      </if>
    </where>
  </select>
 
  <select id="selectAllOfMap" parameterType="map" resultType="map">
    select <include refid="Base_Column_List" /> from sys_org
  </select>
 
 
  <select id="getOrgByCode" parameterType="string" resultMap="BaseResultMap">
    select <include refid="Base_Column_List"></include>
    from sys_org
    where org_code=#{code}
  </select>
  <select id="getBranchByOrgCode" resultType="map">
    select (SELECT COUNT(u.id) from sys_user u where u.org_id = org.id
    <if test="userType != null">
      and user_type = #{userType}
    </if>
    ) managerNum,
    org.id as id,
    org.name as name,
    org.org_code as orgCode,
    org.user_org_code as userOrgCode,
    org.pid as pid,
    org.lv as lv,
    org.sort_no as sortNo,
    org.state as state,
    org.note as note,
    org.lon as lon,
    org.lat as lat,
    org.phone as phone,
    org.open_time as openTime,
    org.address as address
    from sys_org org
    LEFT JOIN sys_org o2 on o2.id = org.pid
    LEFT JOIN sys_org o1 on o1.id = o2.pid
    where org.lv=3
    <if test="code !=null and code !=''">
        and org.org_code like CONCAT( #{code},'%')
    </if>
    <if test="keyText !=null and keyText !=''">
      and (
      org.address like concat('%',#{keyText},'%')
      or org.`name` like concat('%',#{keyText},'%')
      or o1.`name` like concat('%',#{keyText},'%')
      or o2.`name` like concat('%',#{keyText},'%')
      )
    </if>
  </select>
 
  <select id="selectOrgByCode" parameterType="string" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List"/>
    from sys_org where user_org_code = #{code}
  </select>
 
  <insert id="batchImportOrg" parameterType="list">
    insert into sys_org
    (id,name,org_code,user_org_code,pid,lv,sort_no,state,note)
    values
    <foreach collection="list" index="i" item="n" separator=",">
      (
      #{n.id},
      #{n.name},
      #{n.orgCode},
      #{n.userOrgCode},
      #{n.pid},
      #{n.lv},
      #{n.sortNo},
      #{n.state},
      #{n.note}
      )
    </foreach>
  </insert>
  <select id="getListForRoleUser" parameterType="map" resultMap="BaseResultMap">
    select <include refid="Base_Column_List"></include>
     from sys_org
 
    <where>
        and state = 1
      <choose>
        <when test="pid != null">
          and pid = #{pid}
        </when>
        <otherwise>
          and id = #{orgId}
        </otherwise>
      </choose>
    </where>
  </select>
  <!--  此方法为机构级联选择期公用方法,慎重修改  -->
  <select id="getOrgForSelector" parameterType="long" resultMap="BaseResultMap">
    select <include refid="Base_Column_List"/>
    from sys_org
    <where>
        and state = 1
        <if test="pid != null">
          and pid = #{pid}
        </if>
        <if test="rootId != null">
          and id = #{rootId}
        </if>
        <if test="pid == null and rootId==null">
          and pid = 0
        </if>
    </where>
    order by sort_no
  </select>
 
  <select id="getByOrgCode" parameterType="com.nuvole.four.domain.SysOrg" resultType="integer">
    select count(id) from sys_org
    <where>
      <if test="userOrgCode != null">
        and user_org_code = #{userOrgCode}
      </if>
      <if test="id != null">
        and id != #{id}
      </if>
    </where>
  </select>
 
</mapper>