<?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.securitycontrol.system.base.mapper.ITeamQuEvalMapper">
    <!--新增/修改班组质量评价-->
    <insert id="addOrUpdateTeamEval">
        <if test="type == 1">
            INSERT INTO tb_team_eval
            <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="evalId != null and evalId != ''">id,</if>
                <if test="teamId != null and teamId!=''">team_id,</if>
                <if test="teamName != null and teamName!=''">team_name,</if>
                <if test="content != null and content!=''">content,</if>
                <if test="teamLeader != null and teamLeader!=''">leader,</if>
                <if test="score != null and score!=''">score,</if>
                <if test="evalTime != null and evalTime!=''">eval_time,</if>
                <if test="evaluator != null and evaluator!=''">evaluator,</if>
                del_falge,
            </trim>
            <trim prefix="values (" suffix=")" suffixOverrides=",">
                <if test="evalId != null and evalId != ''">#{evalId},</if>
                <if test="teamId != null and teamId!=''">#{teamId},</if>
                <if test="teamName != null and teamName!=''">#{teamName},</if>
                <if test="content != null and content!=''">#{content},</if>
                <if test="teamLeader != null and teamLeader != ''">#{teamLeader},</if>
                <if test="score != null and score!=''">#{score},</if>
                <if test="evalTime != null and evalTime!=''">#{evalTime},</if>
                <if test="evaluator != null and evaluator!=''">#{evaluator},</if>
                0,
            </trim>
        </if>
        <if test="type == 2">
            UPDATE tb_team_eval
            <set>
                <if test="teamId != null and teamId != ''">team_id = #{teamId},</if>
                <if test="teamName != null and teamName != ''">team_name = #{teamName},</if>
                <if test="content != null and content != ''">content = #{content},</if>
                <if test="teamLeader != null and teamLeader != ''">leader = #{teamLeader},</if>
                <if test="score != null and score != ''">score = #{score},</if>
                <if test="evalTime != null and evalTime != ''">eval_time = #{evalTime},</if>
                <if test="evaluator != null and evaluator != ''">evaluator = #{evaluator},</if>
            </set>
            WHERE id = #{evalId}
        </if>
    </insert>
    <!--删除质量评价详情-->
    <delete id="delTeamEvalById">
        DELETE FROM tb_team_eval WHERE id = #{evalId}
    </delete>

    <!--获取班组质量评价列表-->
    <select id="getTeamQuEvalLists" resultType="com.securitycontrol.entity.system.base.vo.TeamQuEvalVo">
        SELECT tte.id AS evalId,
        twt.team_name AS teamName,
        twt.team_leader AS teamLeader,
        twt.team_leader_phone AS teamLeaderPhone,
        tte.eval_time AS evalTime,
        tte.evaluator,
        tte.score,
        tte.content,
        tte.team_id AS teamId
        FROM tb_team_eval tte
        LEFT JOIN tb_work_team twt ON tte.team_id = twt.team_id
        <where>
            <if test="teamName!=null and teamName!=''">
                AND INSTR(twt.team_name,#{teamName}) > 0
            </if>
            <if test="teamLeader!=null and teamLeader!=''">
                AND INSTR(twt.team_leader,#{teamLeader}) > 0
            </if>
            <if test="evalTime!=null and evalTime!=''">
                AND tte.eval_time BETWEEN CONCAT(#{evalTime},' 00:00:00') AND CONCAT(#{evalTime},' 23:59:59')
            </if>
        </where>
    </select>
    <!--班组质量评价详情-->
    <select id="getTeamEvalById" resultType="com.securitycontrol.entity.system.base.vo.TeamQuEvalVo">
        SELECT tte.id AS evalId,
        twt.team_name AS teamName,
        twt.team_leader AS teamLeader,
        twt.team_leader_phone AS teamLeaderPhone,
        tte.eval_time AS evalTime,
        tte.evaluator,
        tte.score,
        tte.content
        FROM tb_team_eval tte
        LEFT JOIN tb_work_team twt ON tte.team_id = twt.team_id
        WHERE tte.id = #{evalId}
    </select>
</mapper>