CouponMapper.xml 20.5 KB
   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
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
<?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.lyms.platform.permission.dao.master.CouponMapper">

<resultMap type="com.lyms.platform.permission.model.CouponInfo" id="couponInfoMap">
<result column="id" property="id"/>
<result column="sequence_id" property="sequenceId"/>
<result column="create_date" property="createDate"/>
<result column="use_date" property="useDate"/>
<result column="user_id" property="userId"/>
<result column="create_user_Id" property="createUserId"/>
<result column="coupon_template_id" property="couponTemplateId"/>
<result column="create_hospital_id" property="createHospitalId"/>
<result column="used_hospital_id" property="usedHospitalId"/>
<result column="status" property="status"/>
<result column="operator_use_id" property="operatorUseId"/>
<result column="used_id" property="usedId"/>
</resultMap>

<sql id="columnList">
sequence_id,create_date,use_date, operator_use_id, user_id,create_user_id,coupon_template_id,create_hospital_id,used_id,used_hospital_id,status
</sql>

<select id="findList" parameterType="map" resultMap="couponInfoMap">
select id,<include refid="columnList" /> from coupon_info
<where>
<if test="userId != null">
and user_id = #{userId}
</if>
<if test="code != null">
and sequence_id = #{code}
</if>
<if test="hospitalId != null">
and create_hospital_id = #{hospitalId}
</if>
<if test="status != null">
and status = #{status}
</if>
</where>
</select>

<insert id="save" parameterType="com.lyms.platform.permission.model.CouponInfo">
insert into coupon_info(id, <include refid="columnList" />) values(#{id},#{sequenceId},#{createDate},#{useDate},#{operatorUseId},#{userId},#{createUserId},#{couponTemplateId},#{createHospitalId},#{usedId},#{usedHospitalId},#{status})
</insert>

<select id="findTemp" parameterType="map" resultType="map">
select b.id, b.id as coupon_template_id, b.actual_start, b.actual_end, b.unit_type, c.send_type, c.type from
hospital_coupon_template_group a, coupon_template b, coupon_type c
where a.hospital_id = #{hospitalId} and a.coupon_template_group_id = b.group_id and b.type_id = c.id and c.type in
<foreach collection="types" open="(" close=")" separator="," item="type">
#{type}
</foreach>
order by b.coupon_order
</select>

<select id="findTopName" parameterType="string" resultType="map">
select b.name, a.coupon_desc, a.img_base64
from hospital_coupon_template_group a, coupon_template_group b
where a.coupon_template_group_id = b.id and a.hospital_id = #{hospital_id}
</select>

<select id="findInfo" parameterType="map" resultType="map">
select a.create_date, b.name, b.title, b.show_start, b.show_end, b.unit_type, b.content, a.sequence_id, a.status
from coupon_info a, coupon_template b, coupon_type c, hospital_coupon_template_group d
where a.user_id = #{userId} and a.create_hospital_id = #{hospitalId} and a.coupon_template_id = b.id and b.type_id=c.id and d.hospital_id = #{hospitalId}
order by c.type desc, b.coupon_order desc
</select>

<select id="findValidateParam" parameterType="map" resultType="map">
select b.actual_start, b.actual_end, b.unit_type, a.create_hospital_id, c.type, c.area_type
from coupon_info a, coupon_template b, coupon_type c
where a.sequence_id = #{code}
and a.coupon_template_id = b.id and b.type_id = c.id and c.type = #{type}
</select>

<update id="use" parameterType="map">
update coupon_info
set use_date = #{useDate}, operator_use_id = #{operatorUseId}, used_hospital_id = #{hospitalId}, status = #{status}, used_id = #{usedId}
where sequence_id = #{code}
</update>

<update id="update" parameterType="map">
update coupon_info
set use_date = #{useDate}, operator_use_id = #{operatorUseId}, used_hospital_id = #{hospitalId}, status = #{status}
where user_id = #{userId}
</update>

<select id="findTypes" parameterType="map" resultType="integer">
select c.type
from hospital_coupon_template_group a,coupon_template b, coupon_type c
where a.hospital_id = #{hospitalId} and a.coupon_template_group_id = b.group_id and b.type_id = c.id
</select>

<select id="findOrgUsers" parameterType="string" resultType="map">
select name
from users
where org_id = #{id} and yn=1 and enable = 1
</select>

<select id="findOrgAreas" parameterType="string" resultType="map">
select area_name as name
from coupon_hospial_area
where hospital_id = #{id}
</select>

<select id="findUrl" parameterType="string" resultType="map">
SELECT create_hospital_id, user_id FROM coupon_info where sequence_id = #{id}
</select>

<update id="invalid" parameterType="map">
update coupon_info a inner join (
select a.id
from coupon_info a, coupon_template b, coupon_type c
where a.coupon_template_id = b.id and b.type_id = c.id and a.status=1 and c.type in
<foreach collection="couponTypes" open="(" close=")" separator="," item="type">
#{type}
</foreach>
and a.user_id = #{personId}
) b on a.id = b.id set a.status = 3
</update>

<select id="findByUsedId" parameterType="string" resultType="string">
select sequence_id from coupon_info where used_id = #{id} limit 0,1
</select>

<select id="findCityId" parameterType="string" resultType="string">
select city_id from organization where id = #{hospitalId}
</select>

<select id="queryCouponItemsByType" parameterType="java.util.Map" resultType="java.util.Map">
SELECT t.name,t.title,t.coupon_order from hospital_coupon_template_group h
left join coupon_type ct on h.coupon_template_group_id=ct.template_group_id
INNER JOIN coupon_template t on t.type_id=ct.id
where h.hospital_id=#{hospitalId} and ct.type=#{type} order by t.coupon_order ASC
</select>

<select id="findReport" parameterType="map" resultType="map">
select a.people_send_count, a.coupon_send_count, a.create_hospital_id, a.user_used_count, a.coupon_used_count, a.used_hospital_id, b.province_id, b.city_id, b.area_id, b.name from(
select a.people_send_count, a.coupon_send_count, a.create_hospital_id, b.user_used_count, b.coupon_used_count, b.used_hospital_id
from (
select count(distinct(a.user_id)) as people_send_count, count(1) as coupon_send_count, a.create_hospital_id
from coupon_info a, coupon_template b, coupon_type c, organization d, hospital_coupon_template_group e
where a.create_hospital_id = d.id and a.create_hospital_id in
<foreach collection="hospitalId" open="(" close=")" separator="," item="hid">
#{hid}
</foreach>
and a.coupon_template_id = b.id and b.type_id = c.id and c.type in
<foreach collection="couponType" open="(" close=")" separator="," item="type">
#{type}
</foreach>
<if test="startDate != null">
and a.create_date >= #{startDate}
</if>
<if test="endDate != null">
and a.create_date <![CDATA[ < ]]> #{endDate}
</if>
<if test="tempId != null and tempId != ''">
and e.coupon_template_group_id = #{tempId}
</if>
and a.create_hospital_id = e.hospital_id
group by a.create_hospital_id
) a left join (
select count(distinct(a.user_id)) as user_used_count, count(1) as coupon_used_count, a.used_hospital_id
from coupon_info a, coupon_template b, coupon_type c
where a.used_hospital_id in
<foreach collection="hospitalId" open="(" close=")" separator="," item="hid">
#{hid}
</foreach>
and a.status = 2 and a.coupon_template_id = b.id and b.type_id = c.id and c.type in
<foreach collection="couponType" open="(" close=")" separator="," item="type">
#{type}
</foreach>
group by a.used_hospital_id
) b
on a.create_hospital_id = b.used_hospital_id
union
select a.people_send_count, a.coupon_send_count, a.create_hospital_id, b.user_used_count, b.coupon_used_count, b.used_hospital_id
from (
select count(distinct(a.user_id)) as people_send_count, count(1) as coupon_send_count, a.create_hospital_id
from coupon_info a, coupon_template b, coupon_type c, organization d, hospital_coupon_template_group e
where a.create_hospital_id = d.id and a.create_hospital_id in
<foreach collection="hospitalId" open="(" close=")" separator="," item="hid">
#{hid}
</foreach>
and a.coupon_template_id = b.id and b.type_id = c.id and c.type in
<foreach collection="couponType" open="(" close=")" separator="," item="type">
#{type}
</foreach>
<if test="startDate != null">
and a.create_date >= #{startDate}
</if>
<if test="endDate != null">
and a.create_date <![CDATA[ < ]]> #{endDate}
</if>
<if test="tempId != null and tempId != ''">
and e.coupon_template_group_id = #{tempId}
</if>
and a.create_hospital_id = e.hospital_id
group by a.create_hospital_id
) a right join (
select count(distinct(a.user_id)) as user_used_count, count(1) as coupon_used_count, a.used_hospital_id
from coupon_info a, coupon_template b, coupon_type c
where a.used_hospital_id in
<foreach collection="hospitalId" open="(" close=")" separator="," item="hid">
#{hid}
</foreach>
and a.status = 2 and a.coupon_template_id = b.id and b.type_id = c.id and c.type in
<foreach collection="couponType" open="(" close=")" separator="," item="type">
#{type}
</foreach>
group by a.used_hospital_id
) b
on a.create_hospital_id = b.used_hospital_id
)a, organization b
where a.create_hospital_id = b.id or a.used_hospital_id = b.id
</select>

<select id="findUsedInfo" parameterType="map" resultType="map">
select count(1) as type_used_count, b.coupon_order, b.type, a.used_hospital_id
from coupon_info a, (
select a.id, a.coupon_order, b.type, d.hospital_id
from coupon_template a, coupon_type b, hospital_coupon_template_group d
where a.group_id = d.coupon_template_group_id and b.id = a.type_id and d.hospital_id in
<foreach collection="hospitalId" open="(" close=")" separator="," item="hid">
#{hid}
</foreach>
and b.type in
<foreach collection="couponType" open="(" close=")" separator="," item="type">
#{type}
</foreach>
) b
where a.used_hospital_id = b.hospital_id and a.coupon_template_id = b.id and a.status = 2
<if test="startDate != null">
and a.use_date >= #{startDate}
</if>
<if test="endDate != null">
and a.use_date <![CDATA[ < ]]> #{endDate}
</if>
group by b.coupon_order, b.type, a.used_hospital_id
</select>

<select id="findHospitalUsedInfo" parameterType="map" resultType="map">
select a.id, count(distinct(b.user_id)) as user_used_count, count(1) as coupon_used_count, a.area_id, a.city_id, a.province_id
from organization a, coupon_info b, coupon_template c, coupon_type d
where a.id = b.used_hospital_id and b.coupon_template_id = c.id and c.type_id = d.id
and a.id = #{hid}
and d.type in
<foreach collection="couponType" open="(" close=")" separator="," item="type">
#{type}
</foreach>
<if test="startDate != null">
and b.use_date >= #{startDate}
</if>
<if test="endDate != null">
and b.use_date <![CDATA[ < ]]> #{endDate}
</if>
</select>

<select id="findHospitalSendInfo" parameterType="map" resultType="map">
select a.id, count(distinct(b.user_id)) as people_send_count, count(1) as coupon_send_count, a.area_id, a.city_id, a.province_id
from organization a, coupon_info b, coupon_template c, coupon_type d
where a.id = b.create_hospital_id and b.coupon_template_id = c.id and c.type_id = d.id
and a.id = #{hid}
and d.type in
<foreach collection="couponType" open="(" close=")" separator="," item="type">
#{type}
</foreach>
<if test="startDate != null">
and b.create_date >= #{startDate}
</if>
<if test="endDate != null">
and b.create_date <![CDATA[ < ]]> #{endDate}
</if>
</select>

<select id="findHospitalNameById" parameterType="string" resultType="string">
select name from organization where id = #{id}
</select>

<select id="findHospitals" parameterType="map" resultType="map">
select a.coupon_template_group_id as id, b.name
from hospital_coupon_template_group a, coupon_template_group b
where a.coupon_template_group_id = b.id and a.hospital_id in
<foreach collection="hospitalIds" open="(" close=")" separator="," item="hid">
#{hid}
</foreach>
group by a.coupon_template_group_id,b.name
</select>
<select id="findHospitalName" parameterType="map" resultType="map">
select name from organization where id = #{hospitalId}
</select>

<select id="findUserName" parameterType="string" resultType="string">
select name from users where id = #{id}
</select>

<select id="findPhone" parameterType="string" resultType="string">
select phone from users where id = #{id}
</select>

<select id="couponInfo" parameterType="map" resultType="map">
select a.used_hospital_id, c.type, b.coupon_order, a.sequence_id, d.name as send_hospital, a.use_date, a.used_id, a.operator_use_id
from coupon_info a, coupon_template b, coupon_type c, organization d
where a.coupon_template_id = b.id and b.type_id = c.id and a.create_hospital_id = d.id
and a.used_hospital_id in
<foreach collection="hospitalId" open="(" close=")" separator="," item="hid">
#{hid}
</foreach>
and c.type in
<foreach collection="couponType" open="(" close=")" separator="," item="type">
#{type}
</foreach>
<if test="coupon_order != null">
and b.coupon_order = #{coupon_order}
</if>
<if test="startDate != null">
and a.use_date >= #{startDate}
</if>
<if test="endDate != null">
and a.use_date <![CDATA[ < ]]> #{endDate}
</if>
<if test="needPage == true">
limit #{currentPage},#{pageSize}
</if>
</select>

<select id="findCouponInfoCount" parameterType="map" resultType="integer">
select count(1) from (
select a.used_hospital_id, c.type, b.coupon_order, a.sequence_id, d.name as send_hospital, a.use_date, a.used_id
from coupon_info a, coupon_template b, coupon_type c, organization d
where a.coupon_template_id = b.id and b.type_id = c.id and a.create_hospital_id = d.id
and a.used_hospital_id in
<foreach collection="hospitalId" open="(" close=")" separator="," item="hid">
#{hid}
</foreach>
and c.type in
<foreach collection="couponType" open="(" close=")" separator="," item="type">
#{type}
</foreach>
<if test="startDate != null">
and a.use_date >= #{startDate}
</if>
<if test="endDate != null">
and a.use_date <![CDATA[ < ]]> #{endDate}
</if>
) a
</select>

<select id="doHospitalFilter" parameterType="map" resultType="string">
select a.id from organization a, hospital_coupon_template_group b
where a.id = b.hospital_id and a.id in
<foreach collection="hospitalId" open="(" close=")" separator="," item="hid">
#{hid}
</foreach>
<if test="provinceId != null and provinceId != ''">
and a.province_id = #{provinceId}
</if>
<if test="cityId != null and cityId != '' ">
and a.city_id = #{cityId}
</if>
<if test="areaId != null and areaId != ''">
and a.area_id = #{areaId}
</if>
<if test="tempId != null and tempId != ''">
and b.coupon_template_group_id = #{tempId}
</if>
</select>

<select id="findHospitalNames" parameterType="list" resultType="map">
select id, name from organization where id in
<foreach collection="list" open="(" close=")" separator="," item="hid">
#{hid}
</foreach>
</select>
<select id="findCouponTitleByTemp" parameterType="map" resultType="string">
select concat(b.type, "_", a.coupon_order)
from coupon_template a, coupon_type b, (
select distinct(b.coupon_template_group_id)
from organization a, hospital_coupon_template_group b
where a.id = b.hospital_id
and b.coupon_template_group_id = #{tempId}
and a.id in
<foreach collection="hospitalId" open="(" close=")" separator="," item="hid">
#{hid}
</foreach>
<if test="provinceId != null and provinceId != ''">
and a.province_id = #{provinceId}
</if>
<if test="cityId != null and cityId != '' ">
and a.city_id = #{cityId}
</if>
<if test="areaId != null and areaId != ''">
and a.area_id = #{areaId}
</if>
) c
where a.type_id = b.id
and a.group_id = c.coupon_template_group_id
and b.type in
<foreach collection="couponType" open="(" close=")" separator="," item="type">
#{type}
</foreach>
</select>

<select id="findUserSendInfo" parameterType="map" resultType="map">
select distinct(a.create_hospital_id), a.user_id, DATE_FORMAT(a.create_date, '%Y-%m-%d') as create_date, d.name as send_hospital, e.name as doctoer_name
from
coupon_info a, coupon_template b, coupon_type c, organization d, users e
where a.coupon_template_id = b.id and b.type_id = c.id and a.create_hospital_id = d.id and a.create_user_id = e.id
and a.create_hospital_id in
<foreach collection="hospitalId" open="(" close=")" separator="," item="hid">
#{hid}
</foreach>
and c.type in
<foreach collection="couponType" open="(" close=")" separator="," item="type">
#{type}
</foreach>
<if test="startDate != null">
and a.create_date >= #{startDate}
</if>
<if test="endDate != null">
and a.create_date <![CDATA[ < ]]> #{endDate}
</if>
<if test="needPage == true">
limit #{currentPage},#{pageSize}
</if>
</select>

<select id="findUserSendInfoCount" parameterType="map" resultType="integer">
select count(1) from (
select distinct(a.create_hospital_id), a.user_id, DATE_FORMAT(a.create_date, '%Y-%m-%d') as create_date, d.name as send_hospital, e.name as doctoer_name
from
coupon_info a, coupon_template b, coupon_type c, organization d, users e
where a.coupon_template_id = b.id and b.type_id = c.id and a.create_hospital_id = d.id and a.create_user_id = e.id
and a.create_hospital_id in
<foreach collection="hospitalId" open="(" close=")" separator="," item="hid">
#{hid}
</foreach>
and c.type in
<foreach collection="couponType" open="(" close=")" separator="," item="type">
#{type}
</foreach>
<if test="startDate != null">
and a.create_date >= #{startDate}
</if>
<if test="endDate != null">
and a.create_date <![CDATA[ < ]]> #{endDate}
</if>
) a
</select>

</mapper>