<?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.xintong.visualinspection.dao.master.ScoreDao" >
    <resultMap id="BaseResultMap" type="com.xintong.visualinspection.bean.Score" >
        <id column="id" property="id" jdbcType="INTEGER" />
        <result column="task_id" property="task_id" jdbcType="INTEGER" />
        <result column="update_time" property="update_time" jdbcType="DATE" />
        <result column="pics" property="pics" jdbcType="VARCHAR" />
        <result column="videos" property="videos" jdbcType="VARCHAR" />
        <result column="check_item_id" property="check_item_id" jdbcType="INTEGER" />
        <result column="check_item_name" property="check_item_name" jdbcType="VARCHAR" />
        <result column="check_item_score" property="check_item_score" jdbcType="INTEGER" />
        <result column="content" property="content" jdbcType="VARCHAR" />
        <result column="checkman" property="checkman" jdbcType="VARCHAR" />
        <result column="checked_person" property="checked_person" jdbcType="INTEGER" />
        <result column="checked_dept" property="checked_dept" jdbcType="INTEGER" />
        <result column="remark" property="remark" jdbcType="VARCHAR" />
    </resultMap>

    <select id="getAll" resultMap="BaseResultMap"  >
        SELECT *
        FROM check_score
    </select>

    <select id="getOne" parameterType="java.lang.Long" resultMap="BaseResultMap" >
        SELECT *
        FROM check_score
        WHERE id = #{id}
    </select>
    
    <select id="getScoreList" parameterType="com.xintong.visualinspection.bean.Score" resultMap="BaseResultMap" >
        SELECT *,
        	  a.score as check_item_score,
        	  a.name as check_item_name
        FROM check_score left join check_item a on check_item_id=a.id
        WHERE 1=1
        	 <if test="task_id != null">AND task_id = #{task_id}</if>
        	 <if test="checked_person != null">AND checked_person = #{checked_person}</if>
        	 <if test="check_item_id != null">AND check_item_id = #{check_item_id}</if>
        	 <if test="checked_dept != null">AND checked_dept = #{checked_dept}</if>
        	 <if test="start_time != null">AND update_time &gt;= #{start_time}</if>
        	 <if test="end_time != null">AND update_time &lt;= #{end_time}</if>
    </select>
    
    <select id="getScoreListByTaskId" parameterType="java.lang.Long" resultMap="BaseResultMap" >
        SELECT *
        FROM check_score
        WHERE task_id = #{task_id}
    </select>

    <insert id="insert" parameterType="com.xintong.visualinspection.bean.Score" >
        INSERT INTO
        check_score
        (task_id,update_time,pics,videos,check_item_id,content,checkman,checked_person,checked_dept,remark)
        VALUES
        (#{task_id}, #{update_time},#{pics},#{videos},#{check_item_id},#{content},#{checkman},#{checked_person},#{checked_dept},#{remark})
    </insert>

    <update id="update" parameterType="com.xintong.visualinspection.bean.Score" >
        UPDATE
        check_score
        SET
        <if test="update_time != null">update_time = #{update_time},</if>
        <if test="pics != null">pics = #{pics},</if>
        <if test="videos != null">videos = #{videos},</if>
        <if test="checkman != null">checkman = #{checkman},</if>
        <if test="checked_person != null">checked_person = #{checked_person},</if>
        remark=#{remark}
        WHERE
        id = #{id}
    </update>

    <delete id="delete" parameterType="java.lang.Long" >
        DELETE FROM
        check_score
        WHERE
        id =#{id}
    </delete>
</mapper>