<?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.ruoyi.system.mapper.UserNucleicTimeMapper">
    
    <resultMap type="UserNucleicTime" id="UserNucleicTimeResult">
        <result property="id"    column="id"    />
        <result property="infoId"    column="info_id"    />
        <result property="idCard"    column="id_card"    />
        <result property="deptId"    column="dept_id"    />
        <result property="collectPlace"    column="collect_place"    />
        <result property="nucleicCollectTime"    column="nucleic_collect_time"    />
        <result property="nucleicResultsTime"    column="nucleic_results_time"    />
        <result property="nucleicResult"    column="nucleic_result"    />
        <result property="jobStyle"    column="job_style"    />
        <result property="focusCrowdStyle"    column="focus_crowd_style"    />
        <result property="name"    column="name"    />
        <result property="phoneNum"    column="phone_num"    />
    </resultMap>

    <sql id="selectUserNucleicTimeVo">
        select id, info_id, id_card,dept_id, collect_place, nucleic_collect_time, nucleic_results_time, nucleic_result, job_style, focus_crowd_style,name, phone_num  from user_nucleic_time
    </sql>

    <select id="selectUserNucleicTimeList" parameterType="UserNucleicTime" resultMap="UserNucleicTimeResult">
        <include refid="selectUserNucleicTimeVo"/>
        <where>  
        </where>
    </select>
    
    <select id="selectUserNucleicTimeById" parameterType="Long" resultMap="UserNucleicTimeResult">
        <include refid="selectUserNucleicTimeVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertUserNucleicTime" parameterType="UserNucleicTime">
        insert into user_nucleic_time
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="infoId != null">info_id,</if>
            <if test="collectPlace != null">collect_place,</if>
            <if test="nucleicCollectTime != null">nucleic_collect_time,</if>
            <if test="nucleicResultsTime != null">nucleic_results_time,</if>
            <if test="nucleicResult != null">nucleic_result,</if>

            <if test="idCard != null">id_card,</if>
            <if test="jobStyle != null">job_style,</if>
            <if test="focusCrowdStyle != null">focus_crowd_style,</if>
            <if test="name != null">name,</if>
            <if test="phoneNum != null">phone_num,</if>
            <if test="deptId != null">dept_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="infoId != null">#{infoId},</if>
            <if test="collectPlace != null">#{collectPlace},</if>
            <if test="nucleicCollectTime != null">#{nucleicCollectTime},</if>
            <if test="nucleicResultsTime != null">#{nucleicResultsTime},</if>
            <if test="nucleicResult != null">#{nucleicResult},</if>
            <if test="idCard != null">#{idCard},</if>
            <if test="jobStyle != null">#{jobStyle},</if>
            <if test="focusCrowdStyle != null">#{focusCrowdStyle},</if>
            <if test="name != null">#{name},</if>
            <if test="phoneNum != null">#{phoneNum},</if>
            <if test="deptId != null">#{deptId},</if>

         </trim>
    </insert>

    <insert id="insertUserNucleicTimeList">
        insert into user_nucleic_time (
        info_id,
        id_card,
        collect_place,
        nucleic_collect_time,
        nucleic_results_time,
        nucleic_result,
        job_style,
        focus_crowd_style,
        name,
        phone_num,
        dept_id)
        values
        <foreach item="userNucleicTime" collection="userNucleicTimeList" separator=",">
            (#{userNucleicTime.infoId},
            #{userNucleicTime.idCard},
            #{userNucleicTime.collectPlace},
            #{userNucleicTime.nucleicCollectTime},
            #{userNucleicTime.nucleicResultsTime},
            #{userNucleicTime.nucleicResult},
            #{userNucleicTime.jobStyle},
            #{userNucleicTime.focusCrowdStyle},
            #{userNucleicTime.name},
            #{userNucleicTime.phoneNum},
            #{userNucleicTime.deptId})
        </foreach>
    </insert>

    <update id="updateUserNucleicTime" parameterType="UserNucleicTime">
        update user_nucleic_time
        <trim prefix="SET" suffixOverrides=",">
            <if test="infoId != null">info_id = #{infoId},</if>
            <if test="collectPlace != null">collect_place = #{collectPlace},</if>
            <if test="nucleicCollectTime != null">nucleic_collect_time = #{nucleicCollectTime},</if>
            <if test="nucleicResultsTime != null">nucleic_results_time = #{nucleicResultsTime},</if>
            <if test="nucleicResult != null">nucleic_result = #{nucleicResult},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteUserNucleicTimeById" parameterType="Long">
        delete from user_nucleic_time where id = #{id}
    </delete>

    <delete id="deleteUserNucleicTimeByIds" parameterType="String">
        delete from user_nucleic_time where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <select id="getIndexDataMonth"  resultType="java.lang.Integer">
        select ifnull(count(s1.id_card),0) from (
        SELECT id_card FROM `user_nucleic_time` where DATE_FORMAT(nucleic_collect_time,'%Y-%m') = DATE_FORMAT(#{monthTime},'%Y-%m') GROUP BY id_card) s1
    </select>
    <select id="getIndexDataWeek" resultType="java.lang.Integer">
    select ifnull(count(s1.id_card),0) from (
    SELECT id_card FROM `user_nucleic_time` where DATE_FORMAT(nucleic_collect_time,'%x-%v') = DATE_FORMAT(now(),'%x-%v') GROUP BY id_card) s1
    </select>
    <select id="getIndexDataLastWeek" resultType="java.lang.Integer">
                select ifnull(count(s1.id_card),0) from (
        SELECT id_card FROM `user_nucleic_time` where YEARWEEK(DATE_FORMAT(nucleic_collect_time,'%Y-%m-%d')) = YEARWEEK(DATE_FORMAT(now(),'%Y-%m-%d')) -1 GROUP BY id_card) s1
    </select>

    <select id="getJobStyle" resultMap="UserNucleicTimeResult">
        <include refid="selectUserNucleicTimeVo"/>
        where DATE_FORMAT(nucleic_collect_time,'%x-%v') = DATE_FORMAT(now(),'%x-%v')
    </select>
    <select id="getHeSuanCount" resultType="java.lang.Integer">
        select ifnull(count(1),0) from `user_nucleic_time` where dept_id = #{deptId}
    </select>

    <select id="selectHomeList" resultMap="UserNucleicTimeResult">
        select id_card, collect_place, nucleic_collect_time, nucleic_results_time, nucleic_result, job_style, focus_crowd_style,name, phone_num
        from user_nucleic_time
        where nucleic_collect_time > #{startTime} and #{endTime}>=nucleic_collect_time
    </select>
</mapper>