<?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.cool.store.mapper.AssessmentDataMapper">
  <resultMap id="BaseResultMap" type="com.cool.store.entity.AssessmentDataDO">
    <!--
      WARNING - @mbg.generated
    -->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="template_id" jdbcType="BIGINT" property="templateId" />
    <result column="shop_id" jdbcType="BIGINT" property="shopId" />
    <result column="assessment_user_id" jdbcType="VARCHAR" property="assessmentUserId" />
    <result column="qualified" jdbcType="TINYINT" property="qualified" />
    <result column="score" jdbcType="BIGINT" property="score" />
    <result column="reason" jdbcType="VARCHAR" property="reason" />
    <result column="comments" jdbcType="VARCHAR" property="comments" />
  </resultMap>
  <insert id="batchInsert">
    insert into xfsg_assessment_data (template_id, shop_id,
      assessment_user_id)
    values
    <foreach collection="assessmentDataList" item="item" separator=",">
      ( #{item.templateId}, #{item.shopId},
      #{item.assessmentUserId})
      </foreach>
  </insert>
  <insert id="batchInsertOrUpdate">
    insert into xfsg_assessment_data
    (
    template_id,
    shop_id,
    assessment_user_id,
    qualified,
    score,
    reason,
    comments,
    picture,
    video
    ) values
    <foreach collection="assessmentDataList" item="item" separator=",">
      ( #{item.templateId},
       #{item.shopId},
      #{item.assessmentUserId},
      #{item.qualified},
      #{item.score},
      #{item.reason},
      #{item.comments},
      #{item.picture},
      #{item.video}
      )
    </foreach>
    ON DUPLICATE KEY UPDATE qualified=values(qualified), score=values(score), reason=values(reason)
    , comments=values(comments), picture=values(picture), video=values(video)
  </insert>
  <update id="batchUpdate">
      update xfsg_assessment_data
      <set>
          qualified = CASE template_id
          <foreach collection="AssessmentDataDOS" separator=" " item="item">
              WHEN #{item.templateId} THEN #{item.qualified}
          </foreach>
          END,
          reason = CASE template_id
          <foreach collection="AssessmentDataDOS" separator=" " item="item">
              WHEN #{item.templateId} THEN #{item.reason}
          </foreach>
          END,
          comments = CASE template_id
          <foreach collection="AssessmentDataDOS" separator=" " item="item">
              WHEN #{item.templateId} THEN #{item.comments}
          </foreach>
          END
      </set>
      where template_id in (
      <foreach collection="AssessmentDataDOS" item="item" separator=",">
          #{item.templateId}
      </foreach>
      )
  </update>

  <select id="selectListByShopId" resultType="com.cool.store.entity.AssessmentDataDO">
    select *
    from xfsg_assessment_data
    where shop_id = #{shopId} and template_id >=#{templateIdMin} and template_id &lt;= #{templateIdMax}
  </select>
</mapper>