<?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="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"    />
    </resultMap>

    <sql id="selectUserNucleicTimeVo">
        select id, info_id, id_card, collect_place, nucleic_collect_time, nucleic_results_time, nucleic_result, job_style, focus_crowd_style 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>
         </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>
         </trim>
    </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>
</mapper>