<?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"/>
<result column="temp_hospital_id" property="tempHospitalId"/>
<result column="temp_status" property="tempStatus"/>
</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,temp_hospital_id,temp_status
</sql>
<select id="findUserCoupon" parameterType="map" resultMap="couponInfoMap">
select * from coupon_info where user_id = #{userId} and sequence_id = #{code}
</select>
<select id="getUserName" parameterType="string" resultType="string">
select name from users where id = #{id}
</select>
<select id="getHospitalName" parameterType="string" resultType="string">
select name from organization where id = #{id}
</select>
<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}, #{tempHospitalId},0)
</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, c.type
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} order by create_date desc limit 0,1
</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>
<update id="invalid2" 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 a.create_date > #{created} 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="findByType" parameterType="map" resultType="string">
select a.sequence_id, c.type 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.used_id = #{usedId} and c.type = #{type} 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.create_date >= #{startDate}
</if>
<if test="endDate != null">
and a.create_date <![CDATA[ < ]]> #{endDate}
</if>
group by b.coupon_order, b.type, a.used_hospital_id
</select>
<select id="findUsedInfo2" 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.create_date >= #{startDate}
</if>
<if test="endDate != null">
and a.create_date <![CDATA[ < ]]> #{endDate}
</if>
group by b.coupon_order, b.type, a.used_hospital_id
</select>
<select id="findUsedUserIds" parameterType="map" resultType="string">
select distinct(b.user_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 b.status = 2
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="findUsedUserIds2" parameterType="map" resultType="string">
select distinct(b.user_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 b.status = 2
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="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 b.status = 2
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="findHospitalUsedInfo2" 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 b.status = 2
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="findSendUserIds" parameterType="map" resultType="string">
select distinct(b.user_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="findSendUserIds2" parameterType="map" resultType="string">
select distinct(b.user_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="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="findHospitalSendInfo2" 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.status = 2
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.create_date >= #{startDate}
</if>
<if test="endDate != null">
and a.create_date <![CDATA[ < ]]> #{endDate}
</if>
order by a.user_id, a.use_date desc
<if test="needPage == true">
limit #{currentPage},#{pageSize}
</if>
</select>
<select id="couponInfo2" 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.status = 2
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>
order by a.user_id, a.use_date desc
<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, 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.status = 2
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.create_date >= #{startDate}
</if>
<if test="endDate != null">
and a.create_date <![CDATA[ < ]]> #{endDate}
</if>
) a
</select>
<select id="findCouponInfoCount2" 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, 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.status = 2
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>
) 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>
<select id="findCouponByCode" parameterType="Map" resultType="Map">
SELECT c.create_hospital_id as createHospitalId,c.user_id as pId,t.coupon_order as couponOrder,m.type,date_format(c.create_date,'%Y-%m-%d') as createDate from coupon_info c
INNER JOIN coupon_template t on c.coupon_template_id = t.id
INNER JOIN coupon_type m on t.type_id = m.id
where c.sequence_id = #{code}
</select>
<update id="updateCouponStatus" parameterType="Map">
update coupon_info set temp_status = 1,temp_hospital_id=#{hospitalId} where sequence_id = #{code}
</update>
<select id="findHospitalInfoById" parameterType="string" resultType="map">
SELECT id, name, province_id, city_id, area_id FROM `organization` where id = #{id} and yn = 1
</select>
<select id="findHospitalInfoByIds" parameterType="list" resultType="map">
SELECT id, name, province_id, city_id, area_id FROM `organization` where id in
<foreach collection="list" item="id" open="(" separator="," close=")">
#{id}
</foreach> and yn = 1
</select>
<select id="findHospitalInfoByIds2" parameterType="map" resultType="map">
SELECT id, name, province_id, city_id, area_id FROM `organization` where id in
<foreach collection="list" item="id" open="(" separator="," close=")">
#{id}
</foreach> and yn = 1
<if test="provinceId != null and provinceId != ''">
and province_id = #{provinceId}
</if>
<if test="cityId != null and cityId != '' ">
and city_id = #{cityId}
</if>
<if test="areaId != null and areaId != ''">
and area_id = #{areaId}
</if>
<if test="streetId != null and streetId != ''">
and street_id = #{streetId}
</if>
</select>
<select id="findUnUsed" parameterType="map" resultType="map">
select count(distinct(user_id)) as un_used_people, count(1) as un_used_coupon_count, b.province_id, b.city_id, b.area_id, b.name as hospitalName, a.create_hospital_id as hospitalId
from coupon_info a, organization b
where a.create_hospital_id = b.id and a.status = 1 and a.create_hospital_id in
<foreach collection="hospitalIds" open="(" close=")" separator="," item="hid">
#{hid}
</foreach>
and user_id in
<foreach collection="userIds" open="(" close=")" separator="," item="uid">
#{uid}
</foreach>
<if test="provinceId != null and provinceId != ''">
and b.province_id = #{provinceId}
</if>
<if test="cityId != null and cityId != '' ">
and b.city_id = #{cityId}
</if>
<if test="areaId != null and areaId != ''">
and b.area_id = #{areaId}
</if>
group by a.create_hospital_id
<if test="page != null and limit != null">
limit #{page}, #{limit}
</if>
</select>
<select id="findUnUsedCount" parameterType="map" resultType="integer">
select count(1) from (
select count(distinct(user_id)) as un_used_people, count(1) as un_used_coupon_count, b.province_id, b.city_id, b.area_id, b.name as hospitalName
from coupon_info a, organization b
where a.create_hospital_id = b.id and a.status = 1 and a.create_hospital_id in
<foreach collection="hospitalIds" open="(" close=")" separator="," item="hid">
#{hid}
</foreach>
and user_id in
<foreach collection="userIds" open="(" close=")" separator="," item="uid">
#{uid}
</foreach>
<if test="provinceId != null and provinceId != ''">
and b.province_id = #{provinceId}
</if>
<if test="cityId != null and cityId != '' ">
and b.city_id = #{cityId}
</if>
<if test="areaId != null and areaId != ''">
and b.area_id = #{areaId}
</if>
group by a.create_hospital_id
) a
</select>
<select id="findUnUsedInfo" parameterType="map" resultType="map">
select a.user_id, b.coupon_order, c.type 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 a.create_hospital_id = #{hospitalId}
and a.user_id in
<foreach collection="userIds" open="(" close=")" separator="," item="uid">
#{uid}
</foreach>
order by a.create_date desc, a.user_id
<if test="page != null and limit != null">
limit #{page}, #{limit}
</if>
</select>
<select id="findUnUsedInfoCount" parameterType="map" resultType="integer">
select count(1) from (
select a.user_id, b.coupon_order, c.type 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 a.create_hospital_id = #{hospitalId}
and a.user_id in
<foreach collection="userIds" open="(" close=")" separator="," item="uid">
#{uid}
</foreach>
) a
</select>
<select id="findUnUsedPeopleInfo" parameterType="map" resultType="string">
select distinct(user_id) from coupon_info a, organization b
where a.create_hospital_id = b.id and a.status = 1 and a.create_hospital_id = #{hospitalId}
and user_id in
<foreach collection="userIds" open="(" close=")" separator="," item="uid">
#{uid}
</foreach>
<if test="provinceId != null and provinceId != ''">
and b.province_id = #{provinceId}
</if>
<if test="cityId != null and cityId != '' ">
and b.city_id = #{cityId}
</if>
<if test="areaId != null and areaId != ''">
and b.area_id = #{areaId}
</if>
<!-- <if test="page != null and limit != null">
limit #{page}, #{limit}
</if>-->
</select>
<select id="findUnUsedPeopleInfoCount" resultType="integer">
select count(1) from (
select distinct(user_id) from coupon_info a, organization b
where a.create_hospital_id = b.id and a.status = 1 and a.create_hospital_id = #{hospitalId}
and user_id in
<foreach collection="userIds" open="(" close=")" separator="," item="uid">
#{uid}
</foreach>
<if test="provinceId != null and provinceId != ''">
and b.province_id = #{provinceId}
</if>
<if test="cityId != null and cityId != '' ">
and b.city_id = #{cityId}
</if>
<if test="areaId != null and areaId != ''">
and b.area_id = #{areaId}
</if>
) a
</select>
<select id="findMulitPatienInfo" parameterType="map" resultType="map">
select count(1) as count, a.user_id as user_id from (
select a.ymd, a.user_id from (
select DATE_FORMAT(a.create_date, '%Y-%m-%d') as ymd, a.user_id
from coupon_info a, coupon_template b, coupon_type c
where a.user_id in
<foreach collection="userIds" open="(" close=")" separator="," item="uid">
#{uid}
</foreach>
<if test="startDate != null">
and a.create_date >= #{startDate}
</if>
<if test="endDate != null">
and a.create_date <![CDATA[ < ]]> #{endDate}
</if>
and a.coupon_template_id = b.id and b.type_id = c.id
and a.${hospitalFlag} = #{hid}
and c.type in
<foreach collection="couponType" open="(" close=")" separator="," item="type">
#{type}
</foreach>
order by a.create_date desc
) a group by a.ymd, a.user_id
) a group by a.user_id
</select>
<select id="findMulitPatienInfoWithSend" parameterType="map" resultType="map">
select count(1) as count, a.user_id as user_id from (
select a.ymd, a.user_id from (
select DATE_FORMAT(a.create_date, '%Y-%m-%d') as ymd, a.user_id
from coupon_info a, coupon_template b, coupon_type c
where a.user_id in
<foreach collection="userIds" open="(" close=")" separator="," item="uid">
#{uid}
</foreach>
<if test="startDate != null">
and a.use_date >= #{startDate}
</if>
<if test="endDate != null">
and a.use_date <![CDATA[ < ]]> #{endDate}
</if>
and a.coupon_template_id = b.id and b.type_id = c.id
and a.${hospitalFlag} = #{hid}
and c.type in
<foreach collection="couponType" open="(" close=")" separator="," item="type">
#{type}
</foreach>
order by a.create_date desc
) a group by a.ymd, a.user_id
) a group by a.user_id
</select>
<select id="findUserSendInfoByUids" resultType="map" parameterType="map">
select a.create_hospital_id, a.user_id, a.create_date, a.send_hospital, b.name as doctoer_name 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, a.create_user_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.create_hospital_id in
<foreach collection="hid" open="(" close=")" separator="," item="hid">
#{hid}
</foreach>
and a.user_id in
<foreach collection="uids" open="(" close=")" separator="," item="uid">
#{uid}
</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 left join users b on a.create_user_id = b.id order by a.create_date desc
<!-- 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="hid" open="(" close=")" separator="," item="hid">
#{hid}
</foreach>
and a.user_id in
<foreach collection="uids" open="(" close=")" separator="," item="uid">
#{uid}
</foreach>-->
</select>
<select id="findUnUsed2" parameterType="map" resultType="map">
select a.user_id, a.create_date, b.coupon_order, c.type, d.city_id, d.area_id, d.name as hospitalName, d.province_id, a.create_hospital_id as hospitalId
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.status = 1 and d.id = a.create_hospital_id
and a.create_hospital_id = #{hid} and a.user_id in
<foreach collection="userIds" open="(" close=")" separator="," item="uid">
#{uid}
</foreach>
order by a.create_date desc, a.user_id
</select>
<select id="findUserTypeInfo" parameterType="map" resultType="map">
select a.user_id, a.create_date, c.type, a.create_hospital_id as hospitalId
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 a.create_hospital_id = #{hospitalId}
and a.user_id in
<foreach collection="userIds" open="(" close=")" separator="," item="uid">
#{uid}
</foreach>
order by a.user_id
</select>
<select id="findUsededId" parameterType="list" resultType="string">
select used_id from coupon_info where used_id in
<foreach collection="list" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</select>
<select id="findAllHospitals" resultType="map">
select id, name, province_id as provinceId, city_id as cityId, area_id as areaId, street_id as streetId
from organization
where yn = 1
</select>
</mapper>