<?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.ylm.exam.dao.QuestionDAO">
<!--<cache type="com.ylm.day.util.RedisCache"/>-->
<resultMap id="questionMap" type="com.ylm.exam.entity.Question">
<id column="que_id" property="id"></id>
<result column="que_content" property="content"></result>
<result column="que_answer" property="answer"></result>
</resultMap>
<resultMap id="questionDetailMap" extends="questionMap" type="com.ylm.exam.entity.Question">
<association property="type" column="type_id" select="com.ylm.exam.dao.QuestionTypeDAO.selectTypeById"></association>
<collection property="optionList" column="que_id" select="com.ylm.exam.dao.OptionDAO.selectAllByQuestionId"></collection>
<collection property="signList" column="que_id" select="com.ylm.exam.dao.SignDAO.selectAllByQuestionId"></collection>
</resultMap>
<sql id="selectColumns">
que_id, type_id, que_content, que_answer
</sql>
<select id="findAll" resultMap="questionMap">
SELECT
<include refid="selectColumns"></include>
FROM question
limit #{f}, #{m}
</select>
<select id="findById" resultMap="questionDetailMap">
SELECT
<include refid="selectColumns"></include>
FROM question
WHERE que_id = #{id}
</select>
<select id="findBookByTypeId" resultMap="bookMap">
SELECT book_id,book_name,book_author,update_time,type_id FROM book
<where>
<if test="typeId != 0">
type_id = #{typeId}
</if>
</where>
limit #{f},#{m}
</select>
<select id="findCountByTypeId" resultType="java.lang.Integer">
SELECT count(1) FROM book
<where>
<if test="typeId != 0">
type_id = #{typeId}
</if>
</where>
</select>
<insert id="insert" keyProperty="id" useGeneratedKeys="true">
INSERT INTO question(type_id, que_content, que_answer)
VALUES (#{typeId}, #{content}, #{answerStr})
</insert>
<select id="findCondition" resultMap="employeeMap">
SELECT id, name, email, phone, money, dept_id FROM employee
<where>
<if test="name != null">
AND name LIKE #{name}"%"
</if>
<if test="email != null">
AND email = #{email}
</if>
<if test="phone != null">
OR phone = #{phone}
</if>
<if test="money != null">
OR money = #{money}
</if>
</where>
</select>
<update id="updateSelective">
UPDATE employee
<set>
<if test="name != null">
name = #{name},
</if>
<if test="email != null">
email = #{email},
</if>
<if test="phone != null">
phone = #{phone},
</if>
<if test="money != null">
money = #{money},
</if>
<if test="department != null and department.id != null">
dept_id = #{department.id},
</if>
</set>
WHERE id = #{id}
</update>
<insert id="insertSelective">
INSERT INTO employee
<trim prefix="(" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="name != null">
name,
</if>
<if test="email != null">
email,
</if>
<if test="phone != null">
phone,
</if>
<if test="money != null">
money,
</if>
<if test="department != null and department.id != null">
dept_id,
</if>
</trim>
<trim prefix=") VALUES (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id},
</if>
<if test="name != null">
#{name},
</if>
<if test="email != null">
#{email},
</if>
<if test="phone != null">
#{phone},
</if>
<if test="money != null">
#{money},
</if>
<if test="department != null and department.id != null">
#{department.id},
</if>
</trim>
</insert>
<select id="selectByIds" resultMap="employeeMap">
SELECT * FROM employee WHERE id in
<foreach collection="list" item="emp" open="(" close=")" separator=",">
#{emp.id}
</foreach>
</select>
</mapper>