<?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.fuxi.ws.data.dao.WQuestionnaireMapper">
  <resultMap id="BaseResultMap" type="com.fuxi.ws.data.entity.WQuestionnaire">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Sep 06 16:48:56 CST 2016.
    -->
    <id column="QtID" jdbcType="INTEGER" property="qtid" />
    <result column="QtName" jdbcType="NVARCHAR" property="qtname" />
    <result column="BeginTime" jdbcType="TIMESTAMP" property="begintime" />
    <result column="EndTime" jdbcType="TIMESTAMP" property="endtime" />
    <result column="TicketID" jdbcType="BIGINT" property="ticketid" />
    <result column="Integration" jdbcType="INTEGER" property="integration" />
    <result column="Deposit" jdbcType="INTEGER" property="deposit" />
    <result column="HasFraction" jdbcType="TINYINT" property="hasfraction" />
    <result column="HasPage" jdbcType="TINYINT" property="haspage" />
    <result column="Memo" jdbcType="NVARCHAR" property="memo" />
    <result column="Creater" jdbcType="VARCHAR" property="creater" />
    <result column="Created" jdbcType="TIMESTAMP" property="created" />
    <result column="Modifier" jdbcType="VARCHAR" property="modifier" />
    <result column="Modified" jdbcType="TIMESTAMP" property="modified" />
    <result column="Status" jdbcType="TINYINT" property="status" />
    <result column="ShareSummary" jdbcType="VARCHAR" property="sharesummary" />
    <result column="ShareImage" jdbcType="VARCHAR" property="shareimage" />
    <result column="ShareTitle" jdbcType="VARCHAR" property="sharetitle" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Sep 06 16:48:56 CST 2016.
    -->
    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Sep 06 16:48:56 CST 2016.
    -->
    QtID, QtName, BeginTime, EndTime, TicketID, Integration, Deposit, HasFraction, HasPage, 
    Memo, Creater, Created, Modifier, Modified, Status, ShareSummary, ShareImage, ShareTitle
  </sql>
  <select id="selectByExample" parameterType="com.fuxi.ws.data.entity.WQuestionnaireExample" resultMap="BaseResultMap">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Sep 06 16:48:56 CST 2016.
    -->
    select
    <if test="distinct">
      distinct
    </if>
    'false' as QUERYID,
    <include refid="Base_Column_List" />
    from W_Questionnaire
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Sep 06 16:48:56 CST 2016.
    -->
    select 
    <include refid="Base_Column_List" />
    from W_Questionnaire
    where QtID = #{qtid,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Sep 06 16:48:56 CST 2016.
    -->
    delete from W_Questionnaire
    where QtID = #{qtid,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.fuxi.ws.data.entity.WQuestionnaire">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Sep 06 16:48:56 CST 2016.
    -->
    insert into W_Questionnaire (QtID, QtName, BeginTime, 
      EndTime, TicketID, Integration, 
      Deposit, HasFraction, HasPage, 
      Memo, Creater, Created, 
      Modifier, Modified, Status, 
      ShareSummary, ShareImage, ShareTitle
      )
    values (#{qtid,jdbcType=INTEGER}, #{qtname,jdbcType=NVARCHAR}, #{begintime,jdbcType=TIMESTAMP}, 
      #{endtime,jdbcType=TIMESTAMP}, #{ticketid,jdbcType=BIGINT}, #{integration,jdbcType=INTEGER}, 
      #{deposit,jdbcType=INTEGER}, #{hasfraction,jdbcType=TINYINT}, #{haspage,jdbcType=TINYINT}, 
      #{memo,jdbcType=NVARCHAR}, #{creater,jdbcType=VARCHAR}, #{created,jdbcType=TIMESTAMP}, 
      #{modifier,jdbcType=VARCHAR}, #{modified,jdbcType=TIMESTAMP}, #{status,jdbcType=TINYINT}, 
      #{sharesummary,jdbcType=VARCHAR}, #{shareimage,jdbcType=VARCHAR}, #{sharetitle,jdbcType=VARCHAR}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.fuxi.ws.data.entity.WQuestionnaire">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Sep 06 16:48:56 CST 2016.
    -->
    insert into W_Questionnaire
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="qtid != null">
        QtID,
      </if>
      <if test="qtname != null">
        QtName,
      </if>
      <if test="begintime != null">
        BeginTime,
      </if>
      <if test="endtime != null">
        EndTime,
      </if>
      <if test="ticketid != null">
        TicketID,
      </if>
      <if test="integration != null">
        Integration,
      </if>
      <if test="deposit != null">
        Deposit,
      </if>
      <if test="hasfraction != null">
        HasFraction,
      </if>
      <if test="haspage != null">
        HasPage,
      </if>
      <if test="memo != null">
        Memo,
      </if>
      <if test="creater != null">
        Creater,
      </if>
      <if test="created != null">
        Created,
      </if>
      <if test="modifier != null">
        Modifier,
      </if>
      <if test="modified != null">
        Modified,
      </if>
      <if test="status != null">
        Status,
      </if>
      <if test="sharesummary != null">
        ShareSummary,
      </if>
      <if test="shareimage != null">
        ShareImage,
      </if>
      <if test="sharetitle != null">
        ShareTitle,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="qtid != null">
        #{qtid,jdbcType=INTEGER},
      </if>
      <if test="qtname != null">
        #{qtname,jdbcType=NVARCHAR},
      </if>
      <if test="begintime != null">
        #{begintime,jdbcType=TIMESTAMP},
      </if>
      <if test="endtime != null">
        #{endtime,jdbcType=TIMESTAMP},
      </if>
      <if test="ticketid != null">
        #{ticketid,jdbcType=BIGINT},
      </if>
      <if test="integration != null">
        #{integration,jdbcType=INTEGER},
      </if>
      <if test="deposit != null">
        #{deposit,jdbcType=INTEGER},
      </if>
      <if test="hasfraction != null">
        #{hasfraction,jdbcType=TINYINT},
      </if>
      <if test="haspage != null">
        #{haspage,jdbcType=TINYINT},
      </if>
      <if test="memo != null">
        #{memo,jdbcType=NVARCHAR},
      </if>
      <if test="creater != null">
        #{creater,jdbcType=VARCHAR},
      </if>
      <if test="created != null">
        #{created,jdbcType=TIMESTAMP},
      </if>
      <if test="modifier != null">
        #{modifier,jdbcType=VARCHAR},
      </if>
      <if test="modified != null">
        #{modified,jdbcType=TIMESTAMP},
      </if>
      <if test="status != null">
        #{status,jdbcType=TINYINT},
      </if>
      <if test="sharesummary != null">
        #{sharesummary,jdbcType=VARCHAR},
      </if>
      <if test="shareimage != null">
        #{shareimage,jdbcType=VARCHAR},
      </if>
      <if test="sharetitle != null">
        #{sharetitle,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.fuxi.ws.data.entity.WQuestionnaireExample" resultType="java.lang.Integer">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Sep 06 16:48:56 CST 2016.
    -->
    select count(*) from W_Questionnaire
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByPrimaryKeySelective" parameterType="com.fuxi.ws.data.entity.WQuestionnaire">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Sep 06 16:48:56 CST 2016.
    -->
    update W_Questionnaire
    <set>
      <if test="qtname != null">
        QtName = #{qtname,jdbcType=NVARCHAR},
      </if>
      <if test="begintime != null">
        BeginTime = #{begintime,jdbcType=TIMESTAMP},
      </if>
      <if test="endtime != null">
        EndTime = #{endtime,jdbcType=TIMESTAMP},
      </if>
      <if test="ticketid != null">
        TicketID = #{ticketid,jdbcType=BIGINT},
      </if>
      <if test="integration != null">
        Integration = #{integration,jdbcType=INTEGER},
      </if>
      <if test="deposit != null">
        Deposit = #{deposit,jdbcType=INTEGER},
      </if>
      <if test="hasfraction != null">
        HasFraction = #{hasfraction,jdbcType=TINYINT},
      </if>
      <if test="haspage != null">
        HasPage = #{haspage,jdbcType=TINYINT},
      </if>
      <if test="memo != null">
        Memo = #{memo,jdbcType=NVARCHAR},
      </if>
      <if test="creater != null">
        Creater = #{creater,jdbcType=VARCHAR},
      </if>
      <if test="created != null">
        Created = #{created,jdbcType=TIMESTAMP},
      </if>
      <if test="modifier != null">
        Modifier = #{modifier,jdbcType=VARCHAR},
      </if>
      <if test="modified != null">
        Modified = #{modified,jdbcType=TIMESTAMP},
      </if>
      <if test="status != null">
        Status = #{status,jdbcType=TINYINT},
      </if>
      <if test="sharesummary != null">
        ShareSummary = #{sharesummary,jdbcType=VARCHAR},
      </if>
      <if test="shareimage != null">
        ShareImage = #{shareimage,jdbcType=VARCHAR},
      </if>
      <if test="sharetitle != null">
        ShareTitle = #{sharetitle,jdbcType=VARCHAR},
      </if>
    </set>
    where QtID = #{qtid,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.fuxi.ws.data.entity.WQuestionnaire">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Sep 06 16:48:56 CST 2016.
    -->
    update W_Questionnaire
    set QtName = #{qtname,jdbcType=NVARCHAR},
      BeginTime = #{begintime,jdbcType=TIMESTAMP},
      EndTime = #{endtime,jdbcType=TIMESTAMP},
      TicketID = #{ticketid,jdbcType=BIGINT},
      Integration = #{integration,jdbcType=INTEGER},
      Deposit = #{deposit,jdbcType=INTEGER},
      HasFraction = #{hasfraction,jdbcType=TINYINT},
      HasPage = #{haspage,jdbcType=TINYINT},
      Memo = #{memo,jdbcType=NVARCHAR},
      Creater = #{creater,jdbcType=VARCHAR},
      Created = #{created,jdbcType=TIMESTAMP},
      Modifier = #{modifier,jdbcType=VARCHAR},
      Modified = #{modified,jdbcType=TIMESTAMP},
      Status = #{status,jdbcType=TINYINT},
      ShareSummary = #{sharesummary,jdbcType=VARCHAR},
      ShareImage = #{shareimage,jdbcType=VARCHAR},
      ShareTitle = #{sharetitle,jdbcType=VARCHAR}
    where QtID = #{qtid,jdbcType=INTEGER}
  </update>

	<select id="questionList" resultType="java.util.LinkedHashMap">
		SELECT a.QtID, a.QtName,CONVERT(varchar(10),a.BeginTime, 121) + '<![CDATA[<br/>]]>'
		+ CONVERT(varchar(10), a.BeginTime, 108) AS BeginTime,
		CONVERT(varchar(10),a.EndTime, 121) + '<![CDATA[<br/>]]>'
		+ CONVERT(varchar(10), a.EndTime, 108) AS EndTime,
		a.TicketID, a.Integration, a.Deposit, a.Status, b.TicketName,
		case when a.BeginTime<![CDATA[<]]>getdate() then 1 else 0 end as Started
		FROM W_Questionnaire AS a Left JOIN
		W_Ticket AS b ON a.TicketID = b.TicketID
		order by a.Created desc
	</select>
	
	<select id="questionResult" resultType="java.util.LinkedHashMap">
		SELECT a.QtID, a.QtDtlID,a.TestContext, a.AnswerType,b.OptionContext, b.OptionImg,
			(select COUNT(c.vipid) from W_VipAnswer c where a.QtID = c.QtID AND a.QtDtlID = c.QtDtlID) as AnswererCunt,
			(select COUNT(d.vipid) from W_VipAnswer d where a.QtID = d.QtID AND a.QtDtlID = d.QtDtlID AND b.OptionID = d.OptionID) as ResultCunt
		FROM  W_QuestionDtl AS a INNER JOIN
		W_QuestionOption AS b ON a.QtID = b.QtID AND a.QtDtlID = b.QtDtlID
		Where a.QtID = #{qtid,jdbcType=INTEGER}
		order by  a.ListIdx, b.OptionID
	</select>
</mapper>