CouponMapper.xml 10.1 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
<?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, b.coupon_order
</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.used_hospital_id, b.user_used_count, b.coupon_used_count, c.province_id, c.city_id, c.area_id, c.name
from (
select count(distinct(a.user_id)) as people_send_count, count(1) as coupon_send_count, a.used_hospital_id
from coupon_info a, coupon_template b, coupon_type c, organization d, hospital_coupon_template_group e
where a.status = #{status} and a.used_hospital_id = d.id and a.used_hospital_id in
<foreach collection="hospitalIds" 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="couponTypes" 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>
<if test="provinceId != null and provinceId != ''">
and d.province_id = #{provinceId}
</if>
<if test="cityId != null and cityId != '' ">
and d.city_id = #{cityId}
</if>
<if test="areaId != null and areaId != ''">
and d.area_id = #{areaId}
</if>
<if test="tempId != null and tempId != ''">
and e.coupon_template_group_id = #{tempId}
</if>
and a.used_hospital_id = e.hospital_id
group by a.used_hospital_id
) a, (
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 used_hospital_id in
<foreach collection="hospitalIds" open="(" close=")" separator="," item="hid">
#{hid}
</foreach>
and status = #{status} and a.coupon_template_id = b.id and b.type_id = c.id and c.type in
<foreach collection="couponTypes" open="(" close=")" separator="," item="type">
#{type}
</foreach>
group by used_hospital_id
) b, organization c
where a.used_hospital_id = b.used_hospital_id and a.used_hospital_id = c.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="hospitalIds" open="(" close=")" separator="," item="hid">
#{hid}
</foreach>
and b.type in
<foreach collection="couponTypes" 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 = #{status}
group by b.coupon_order, b.type, a.used_hospital_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, organization b
where a.hospital_id = b.id and a.hospital_id in
<foreach collection="hospitalIds" open="(" close=")" separator="," item="hid">
#{hid}
</foreach>
</select>

</mapper>