forked from CCSENS_TECHNOLOGY/braintraining
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
135 lines
4.8 KiB
135 lines
4.8 KiB
<?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.ccsens.braintraining.persist.dao.RaffleDao">
|
|
|
|
<resultMap id="ActiveMap" type="com.ccsens.braintraining.bean.vo.RaffleVo$Active">
|
|
<id column="activeId"/>
|
|
<association property="active" javaType="com.ccsens.braintraining.bean.vo.RaffleVo$Intro">
|
|
<id property="activeId" column="activeId"/>
|
|
<result property="title" column="title"/>
|
|
<result property="subtitle" column="subtitle"/>
|
|
<result property="freeTimes" column="freeTimes"/>
|
|
<result property="startTime" column="startTime"/>
|
|
<result property="endTime" column="endTime"/>
|
|
</association>
|
|
<collection property="prizes" ofType="com.ccsens.braintraining.bean.vo.RaffleVo$Prize">
|
|
<id property="prizeId" column="prizeId"/>
|
|
<result property="name" column="prizeName"/>
|
|
<result property="icon" column="prizeIcon"/>
|
|
</collection>
|
|
<collection property="tasks" ofType="com.ccsens.braintraining.bean.vo.RaffleVo$Task">
|
|
<id property="taskId" column="taskId"/>
|
|
<result property="name" column="taskName"/>
|
|
<result property="icon" column="taskIcon"/>
|
|
<result property="type" column="type"/>
|
|
<result property="finishStatus" column="finishStatus"/>
|
|
</collection>
|
|
</resultMap>
|
|
<update id="decreasePrize">
|
|
UPDATE t_raffle_prize
|
|
SET remain = remain - 1
|
|
WHERE
|
|
id = #{prizeId}
|
|
</update>
|
|
|
|
<select id="queryActiveNow" resultMap="ActiveMap">
|
|
SELECT
|
|
a.id AS activeId,
|
|
a.title,
|
|
a.subtitle,
|
|
a.free_times AS freeTimes,
|
|
a.start_time AS startTime,
|
|
a.end_time AS endTime,
|
|
p.id AS prizeId,
|
|
p.NAME AS prizeName,
|
|
p.icon AS prizeIcon,
|
|
t.id AS taskId,
|
|
t.NAME AS taskName,
|
|
t.icon AS taskIcon,
|
|
t.type,
|
|
IF( t2.id IS NULL, 0, t2.finish_type + 1 ) AS finishStatus
|
|
FROM
|
|
(select * from t_raffle_active WHERE equipment_id = #{equipmentId} AND start_time <= UNIX_TIMESTAMP(now()) * 1000 AND end_time >= UNIX_TIMESTAMP(now()) * 1000 AND rec_status = 0 order by id desc limit 1) a
|
|
LEFT JOIN t_raffle_prize p ON a.id = p.active_id
|
|
AND p.total > 0
|
|
AND p.rec_status = 0
|
|
LEFT JOIN t_raffle_task t ON a.id = t.active_id
|
|
AND t.rec_status = 0
|
|
LEFT JOIN t_raffle_times t2 ON t.id = t2.task_id
|
|
<choose>
|
|
<when test="userId != null and userId != 0">AND t2.user_id = #{userId}</when>
|
|
<otherwise>AND t2.id is null</otherwise>
|
|
</choose>
|
|
AND t2.rec_status = 0
|
|
|
|
</select>
|
|
<select id="queryPrizeRecord" resultType="com.ccsens.braintraining.bean.vo.RaffleVo$PrizeRecord">
|
|
SELECT
|
|
p.NAME AS prizeName,
|
|
u.NAME AS userName
|
|
FROM
|
|
t_raffle_record r,
|
|
t_raffle_prize p,
|
|
t_user u
|
|
WHERE
|
|
r.prize_id = p.id
|
|
AND r.user_id = u.id
|
|
AND p.active_id = #{activeId}
|
|
AND p.type > 0
|
|
AND r.rec_status = 0
|
|
AND p.rec_status = 0
|
|
AND u.rec_status = 0
|
|
ORDER BY
|
|
r.id DESC
|
|
</select>
|
|
<select id="countTimes" resultType="java.lang.Integer">
|
|
SELECT
|
|
sum( IFNULL(a.free_times,0) + IFNULL(t.addTimes,0) - IFNULL(r.usedTimes,0) )
|
|
FROM
|
|
t_raffle_active a,
|
|
(
|
|
SELECT
|
|
sum( t1.increase_times ) AS addTimes
|
|
FROM
|
|
t_raffle_task t1,
|
|
t_raffle_times t2
|
|
WHERE
|
|
t1.id = t2.task_id
|
|
AND t1.active_id = #{activeId}
|
|
AND t2.user_id = #{userId}
|
|
AND t1.rec_status = 0
|
|
AND t2.rec_status = 0
|
|
) t,
|
|
(
|
|
SELECT
|
|
count(*) AS usedTimes
|
|
FROM
|
|
t_raffle_record r,
|
|
t_raffle_prize p
|
|
WHERE
|
|
r.prize_id = p.id
|
|
AND p.active_id = #{activeId}
|
|
AND r.user_id = #{userId}
|
|
AND r.rec_status = 0
|
|
AND p.rec_status = 0
|
|
) r
|
|
WHERE
|
|
a.id = #{activeId}
|
|
AND a.rec_status = 0
|
|
</select>
|
|
<select id="queryRemainPrize" resultType="com.ccsens.braintraining.bean.vo.RaffleVo$PrizeRemain">
|
|
SELECT
|
|
id AS prizeId,
|
|
NAME,
|
|
icon,
|
|
remain
|
|
FROM
|
|
t_raffle_prize
|
|
WHERE
|
|
active_id = #{activeId}
|
|
AND remain > 0
|
|
AND rec_status = 0
|
|
ORDER BY
|
|
id
|
|
</select>
|
|
</mapper>
|