邱宇豪
2023-11-08 e816947467e787e97db94e447d089c9c8c7a5b03
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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
<?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.thhy.secure.modules.biz.encourage.mapper.TEncourageMapper">
  <resultMap id="BaseResultMap" type="com.thhy.secure.modules.biz.encourage.entity.TEncourage">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Jun 05 14:42:58 CST 2023.
    -->
    <id column="encourage_id" jdbcType="VARCHAR" property="encourageId" />
    <result column="encourage_name" jdbcType="VARCHAR" property="encourageName" />
    <result column="matter" jdbcType="VARCHAR" property="matter" />
    <result column="matter_type" jdbcType="INTEGER" property="matterType" />
    <result column="integral" jdbcType="INTEGER" property="integral" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="create_user" jdbcType="VARCHAR" property="createUser" />
    <result column="is_use" jdbcType="INTEGER" property="isUse" />
    <result column="company_id" jdbcType="VARCHAR" property="companyId" />
  </resultMap>
 
  <insert id="encourageInsert">
    insert into t_encourage
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="encourageId != null">
        encourage_id,
      </if>
      <if test="encourageName != null">
        encourage_name,
      </if>
      <if test="matter != null">
        matter,
      </if>
      <if test="matterType != null">
        matter_type,
      </if>
      <if test="integral != null">
        integral,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="createUser != null">
        create_user,
      </if>
      <if test="isUse != null">
        is_use,
      </if>
      <if test="companyId != null">
        company_id,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="encourageId != null">
        #{encourageId,jdbcType=VARCHAR},
      </if>
      <if test="encourageName != null">
        #{encourageName,jdbcType=VARCHAR},
      </if>
      <if test="matter != null">
        #{matter,jdbcType=VARCHAR},
      </if>
      <if test="matterType != null">
        #{matterType,jdbcType=INTEGER},
      </if>
      <if test="integral != null">
        #{integral,jdbcType=INTEGER},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createUser != null">
        #{createUser,jdbcType=VARCHAR},
      </if>
      <if test="isUse != null">
        #{isUse,jdbcType=INTEGER},
      </if>
      <if test="companyId != null">
        #{companyId,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
 
  <select id="encourageList" resultType="com.thhy.secure.modules.biz.encourage.entity.TEncourage">
    select
    encourage_id as encourageId,
    encourage_name  as encourageName,
    matter,
    matter_type as matterType,
    integral
     from t_encourage
    where is_use=1
    <if test="companyId!=null and companyId!='' ">
        and company_id=#{companyId}
    </if>
    <if test="encourageName!=null and encourageName!='' ">
      and encourage_name like concat('%',#{encourageName},'%')
    </if>
    order by create_time desc
  </select>
  <select id="encourageInfo" resultType="com.thhy.secure.modules.biz.encourage.entity.TEncourage">
select
    encourage_id as encourageId,
    encourage_name  as encourageName,
    matter,
    matter_type as matterType,
    integral
     from t_encourage
    where is_use=1 and encourage_id=#{encourageId}
  </select>
 
 
  <update id="encourageUpdate" >
    update t_encourage
    <set>
      <if test="encourageName != null">
        encourage_name = #{encourageName,jdbcType=VARCHAR},
      </if>
      <if test="matter != null">
        matter = #{matter,jdbcType=VARCHAR},
      </if>
      <if test="matterType != null">
        matter_type = #{matterType,jdbcType=INTEGER},
      </if>
      <if test="integral != null">
        integral = #{integral,jdbcType=INTEGER},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createUser != null">
        create_user = #{createUser,jdbcType=VARCHAR},
      </if>
      <if test="isUse != null">
        is_use = #{isUse,jdbcType=INTEGER},
      </if>
      <if test="companyId != null">
        company_id = #{companyId,jdbcType=VARCHAR},
      </if>
    </set>
    where encourage_id = #{encourageId,jdbcType=VARCHAR}
  </update>
  <update id="encourageDel" >
    update  t_encourage set
    is_use=2
    where  encourage_id = #{encourageId,jdbcType=VARCHAR}
  </update>
 
  <insert id="encourageRecordInsert">
    insert into t_encourage_record
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="encourageRecordId != null">
        encourage_record_id,
      </if>
      <if test="userId != null">
        user_id,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="createUser != null">
        create_user,
      </if>
      <if test="isUse != null">
        is_use,
      </if>
      <if test="encourageId != null">
        encourage_id,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="encourageRecordId != null">
        #{encourageRecordId,jdbcType=VARCHAR},
      </if>
      <if test="userId != null">
        #{userId,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createUser != null">
        #{createUser,jdbcType=VARCHAR},
      </if>
      <if test="isUse != null">
        #{isUse,jdbcType=INTEGER},
      </if>
      <if test="encourageId != null">
        #{encourageId,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <select id="encourageRecordList"  resultType="com.thhy.secure.modules.biz.encourage.entity.TEncourageRecord">
       SELECT
    ter.encourage_record_id as encourageRecordId,
    te.encourage_name as encourageName,
    te.integral,
    te.matter_type as matterType,
    ter.create_time as createTime,
    spu.real_name as realName
FROM
    t_encourage_record ter
    LEFT JOIN t_encourage te ON ter.encourage_id = te.encourage_id
    LEFT JOIN sys_plat_user spu ON ter.user_id = spu.user_id
    where  1=1
    <if test="companyId!=null and companyId!='' ">
        and te.company_id=#{companyId}
    </if>
    <if test="realName!=null and realName!='' ">
        and spu.real_name like concat('%',#{realName},'%')
    </if>
    <if test="strTime!=null and strTime!='' and endTime!=null and endTime!=''  ">
      and ter.create_time between #{strTime} and #{endTime}
    </if>
    order by ter.create_time desc
  </select>
  <select id="encourageRecordWebList"  resultType="com.thhy.secure.modules.biz.encourage.entity.TEncourageRecord">
       SELECT
    ter.encourage_record_id as encourageRecordId,
    te.encourage_name as encourageName,
    te.integral,
    te.matter_type as matterType,
    ter.create_time as createTime,
    spu.real_name as realName,
    su.real_name as realNames,
      te.matter as matter
FROM
    t_encourage_record ter
    LEFT JOIN t_encourage te ON ter.encourage_id = te.encourage_id
    LEFT JOIN sys_plat_user spu ON ter.user_id = spu.user_id
    LEFT JOIN sys_users su ON ter.create_user = su.user_id
    where  1=1
    <if test="companyId!=null and companyId!='' ">
        and te.company_id=#{companyId}
    </if>
    <if test="realName!=null and realName!='' ">
        and spu.real_name like concat('%',#{realName},'%')
    </if>
    <if test="strTime!=null and strTime!='' and endTime!=null and endTime!=''  ">
      and ter.create_time between #{strTime} and #{endTime}
    </if>
    order by ter.create_time desc
  </select>
 
  <select id="encourageRecordLists" resultType="com.thhy.secure.modules.biz.encourage.entity.dto.EncourageRecordDto">
        SELECT
    ter.encourage_record_id as encourageRecordId,
    te.encourage_name as encourageName,
    te.integral,
    te.matter_type as matterType,
    ter.create_time as createTime
FROM
    t_encourage_record ter
    LEFT JOIN t_encourage te ON ter.encourage_id = te.encourage_id
    where  1=1
    <if test="userId!=null and userId!='' ">
        and ter.user_id=#{userId}
    </if>
    <if test="strTime!=null and strTime!='' and endTime!=null and endTime!=''  ">
      and ter.create_time between #{strTime} and #{endTime}
    </if>
    order by ter.create_time desc
  </select>
  <select id="encourage" resultType="java.lang.Integer">
SELECT
    sum(te.integral) as integral
FROM
    t_encourage_record ter
    LEFT JOIN t_encourage te ON ter.encourage_id = te.encourage_id
    where  te.matter_type=1
    <if test="userId!=null and userId!='' ">
        and ter.user_id=#{userId}
    </if>
    <if test="strTime!=null and strTime!='' and endTime!=null and endTime!=''  ">
      and ter.create_time between #{strTime} and #{endTime}
    </if>
  </select>
  <select id="encourages" resultType="java.lang.Integer">
SELECT
    sum(te.integral) as integral
FROM
    t_encourage_record ter
    LEFT JOIN t_encourage te ON ter.encourage_id = te.encourage_id
    where  te.matter_type=1
    <if test="userId!=null and userId!='' ">
        and ter.user_id=#{userId}
    </if>
  </select>
  <select id="punish" resultType="java.lang.Integer">
SELECT
    sum(te.integral) as integral
FROM
    t_encourage_record ter
    LEFT JOIN t_encourage te ON ter.encourage_id = te.encourage_id
    where  te.matter_type=2
    <if test="userId!=null and userId!='' ">
        and ter.user_id=#{userId}
    </if>
    <if test="strTime!=null and strTime!='' and endTime!=null and endTime!=''  ">
      and ter.create_time between #{strTime} and #{endTime}
    </if>
  </select>
  <select id="punishs" resultType="java.lang.Integer">
SELECT
    sum(te.integral) as integral
FROM
    t_encourage_record ter
    LEFT JOIN t_encourage te ON ter.encourage_id = te.encourage_id
    where  te.matter_type=2
    <if test="userId!=null and userId!='' ">
        and ter.user_id=#{userId}
    </if>
  </select>
  <select id="userPlatId" parameterType="java.lang.String" resultType="java.lang.String">
    select plat_id from sys_users
    where  user_id=#{userId}
  </select>
 
  <select id="platUserInfo" parameterType="java.lang.String" resultType="com.thhy.secure.modules.biz.encourage.entity.PlatUserDto">
        SELECT
    spu.job_num AS jobNum,
    spu.sex,
    spu.photo,
    spu.phone,
    spu.id_no AS idNo,
    spu.has_cert AS hasCert,
    spu.employed_time AS employedTime,
    spu.come_factory_time AS comeFactoryTime,
    spu.leave_factory_time AS leaveFactoryTime,
    sc.shortname AS jg,
    spu.`status`,
    spu.real_name AS realName,
    sp.pos_name AS posName,
    sd.depart_name  AS departName,
    sdi.dict_name  AS zzmm,
    group_concat( sg.group_name ) AS groupName
FROM
    sys_plat_user spu
    LEFT JOIN sys_plat_position_user ppu ON spu.user_id = ppu.user_id
    LEFT JOIN sys_position sp ON ppu.position_id = sp.pos_id
    LEFT JOIN sys_depart_user du ON spu.user_id = du.user_id
    LEFT JOIN sys_depart sd ON du.depart_id = sd.depart_id
    LEFT JOIN sys_dict sdi ON spu.zzmm = sdi.dict_id
    LEFT JOIN sys_group_user sgu ON spu.user_id = sgu.user_id
    LEFT JOIN sys_group sg ON sgu.group_id = sg.group_id
    LEFT JOIN sys_city sc ON spu.jg = sc.id
    where  spu.user_id=#{platId}
GROUP BY
    spu.user_id,sp.pos_name,sd.depart_name
  </select>
 
    <select id="encourageSecurityCode" resultType="com.thhy.secure.modules.biz.encourage.entity.dto.SecurityCodeDto">
        SELECT
    spu.user_id as userId,
    spu.real_name as realName,
    sp.pos_name as posName,
    sp.company_id as companyId,
    100 as an
FROM
    sys_plat_user spu
    LEFT JOIN sys_plat_position_user ppu ON spu.user_id = ppu.user_id
    LEFT JOIN sys_position sp ON sp.pos_id = ppu.position_id
    where sp.company_id=#{companyId} and
    spu.user_type=2
    <if test="realName!=null and realName!='' ">
        and spu.real_name like concat('%',#{realName},'%')
    </if>
    </select>
    <select id="encourageSecurityCodeJia" resultType="java.lang.Double">
        SELECT
    IF(SUM(te.integral)!='',SUM(te.integral),'0.0') as jia
FROM
    sys_plat_user spu
    LEFT JOIN sys_plat_position_user ppu ON spu.user_id = ppu.user_id
    LEFT JOIN sys_position sp ON sp.pos_id = ppu.position_id
    left join t_encourage_record er on ppu.user_id=er.user_id
    left join t_encourage te on te.encourage_id=er.encourage_id
    where sp.company_id=#{companyId} and spu.user_id=#{userId} and
    te.matter_type=1 GROUP BY spu.user_id
    </select>
    <select id="encourageSecurityCodeJian" resultType="java.lang.Double">
    SELECT
    IF(SUM(te.integral)!='',SUM(te.integral),'0.0') as jian
FROM
    sys_plat_user spu
    LEFT JOIN sys_plat_position_user ppu ON spu.user_id = ppu.user_id
    LEFT JOIN sys_position sp ON sp.pos_id = ppu.position_id
    left join t_encourage_record er on ppu.user_id=er.user_id
    left join t_encourage te on te.encourage_id=er.encourage_id
    where sp.company_id=#{companyId} and spu.user_id=#{userId} and
    te.matter_type=2 GROUP BY spu.user_id
    </select>
 
 
</mapper>