<?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.repair.mapper.RepairDispatchRecordMapper">
    <resultMap type="com.repair.model.vo.RepairCardNumberVo" id="repairCardNumberMap">
        <result property="userId" column="users_id"/>
        <result property="cardNumber" column="card_number"/>
    </resultMap>

    <select id="queryRepairCardNumber" resultType="com.repair.model.vo.RepairCardNumberVo" resultMap="repairCardNumberMap">
        SELECT ru.card_number,rdr.users_id FROM repair_dispatch_record rdr
        left join repair_user ru on ru.deleted = 0 and ru.id = rdr.users_id
        <where>
            and rdr.deleted = 0 and rdr.is_lose_efficacy = 0
            <if test="recordId != null and recordId != ''">
                and rdr.record_id = #{recordId}
            </if>
        </where>
    </select>

    <!--查看当员工是否存在待接单或者维修中的数据-->
    <resultMap type="com.repair.model.vo.DisReceCountVo" id="disReceCountMap">
        <result property="disCount" column="dis_count"/>
        <result property="recCount" column="rec_count"/>
    </resultMap>
    <select id="queryDisReceCount" resultType="com.repair.model.vo.DisReceCountVo" resultMap="disReceCountMap">
        select (select Count(*) from repair_dispatch_record
        where deleted = 0 and is_lose_efficacy = 0 and users_id = #{userId}) as dis_count,
        (select Count(*) as count from repair_receiving
        where deleted = 0 and is_lose_efficacy = 0 and user_id = #{userId}) as rec_count
    </select>

</mapper>
