<?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.tofly.gpsboot.mapper.maintain.RepairuserMapper">

    <resultMap id="repairuserMap" type="com.tofly.pojo.maintain.Repairuser">
        <id property="id" column="ID"/>
        <result property="respUser" column="RESP_USER"/>
        <result property="repairId" column="REPAIR_ID"/>
        <result property="teamUser" column="TEAM_USER"/>
        <result property="isread" column="ISREAD"/>
        <result property="isrepeat" column="ISREPEAT"/>
        <result property="repeatNum" column="REPEAT_NUM"/>
        <result property="state" column="STATE"/>
        <result property="ratifyTime" column="RATIFY_TIME"/>
        <result property="realTime" column="REAL_TIME"/>
        <result property="regionCode" column="REGION_CODE"/>
        <result property="regionName" column="REGION_NAME"/>
        <result property="address" column="ADDRESS"/>
        <result property="lgtd" column="LGTD"/>
        <result property="lttd" column="LTTD"/>
        <result property="createUser" column="CREATE_USER"/>
        <result property="createTime" column="CREATE_TIME"/>
        <result property="confirmTime" column="CONFIRM_TIME"/>
        <result property="overTime" column="OVER_TIME"/>
        <result property="planNum" column="PLAN_NUM"/>
        <result property="overNum" column="OVER_NUM"/>
        <result property="lngLats" column="LNG_LATS"/>
        <result property="phone" column="PHONE"/>
        <association property="respUserName" column="RESP_USER" select="com.tofly.gpsboot.mapper.plan.HydrantrecordMapper.getRealName"/>
    </resultMap>


    <resultMap id="repairuserVoMap" type="com.tofly.pojo.maintain.vo.RepairuserVo">
        <id property="id" column="ID"/>
        <result property="respUser" column="RESP_USER"/>
        <result property="repairId" column="REPAIR_ID"/>
        <result property="teamUser" column="TEAM_USER"/>
        <result property="isread" column="ISREAD"/>
        <result property="isrepeat" column="ISREPEAT"/>
        <result property="repeatNum" column="REPEAT_NUM"/>
        <result property="state" column="STATE"/>
        <result property="ratifyTime" column="RATIFY_TIME"/>
        <result property="realTime" column="REAL_TIME"/>
        <result property="regionCode" column="REGION_CODE"/>
        <result property="regionName" column="REGION_NAME"/>
        <result property="address" column="ADDRESS"/>
        <result property="lgtd" column="LGTD"/>
        <result property="lttd" column="LTTD"/>
        <result property="createUser" column="CREATE_USER"/>
        <result property="createTime" column="CREATE_TIME"/>
        <result property="confirmTime" column="CONFIRM_TIME"/>
        <result property="overTime" column="OVER_TIME"/>
        <result property="planNum" column="PLAN_NUM"/>
        <result property="overNum" column="OVER_NUM"/>
        <result property="lngLats" column="LNG_LATS"/>
        <result property="phone" column="PHONE"/>
        <association property="respUserName" column="RESP_USER" select="com.tofly.gpsboot.mapper.plan.HydrantrecordMapper.getRealName"/>
        <association property="teamUserName" column="TEAM_USER" select="getTeamUserName"/>
        <association property="isreadName" column="ISREAD" select="getIsreadName"/>
        <association property="isrepeatName" column="ISREPEAT" select="getIsrepeatName"/>
        <association property="stateName" column="STATE" select="getState"/>
        <association property="createUserName" column="CREATE_USER" select="com.tofly.gpsboot.mapper.plan.HydrantrecordMapper.getRealName"/>
    </resultMap>

    <select id="getIsreadName" resultType="java.lang.String">
        select (case #{isread}
                    when '0' then '未查看'
                    when '1' then '已查看'
                    else '' end )
             as isreadName from dual
    </select>

    <select id="getIsrepeatName" resultType="java.lang.String">
        select (case #{isrepeat}
                    when '0' then '未返工'
                    when '1' then '已返工'
                    else '' end )
                as isrepeatName from dual
    </select>


    <select id="getState" resultType="java.lang.String">
        select (case #{state}
                    when '0' then '未派工'
                    when '1' then '未审核'
                    when '2' then '未开始'
                    when '3' then '正在执行'
                    when '4' then '处理完成'
                    when '5' then '已开始未执行'
                    when '6' then '驳回'
                    when '7' then '转移申请'
                    when '8' then '已转移'
                    else '' end )
             as stateName from dual
    </select>

    <select id="getTeamUserName" resultType="java.lang.String"  >
        select
        GROUP_CONCAT(real_name separator  ',')
        from TF_SMPN_USER_X
        where 1=1
        <if test="teamUser != null and teamUser != ''  ">and id in
            <foreach item="nodeCodestr" collection="teamUser.split(',')" open="(" separator="," close=")">
                #{nodeCodestr}
            </foreach>
        </if>


    </select>

    <select id="getrepairuserVoList" resultMap="repairuserVoMap">
        select * from TF_YWPN_REPAIRUSER_W where repair_Id = #{repairId}
    </select>

    <select id="getDeptName" resultType="string">
        select NAME as deptName
        from TF_SMPN_DEPARTMENT_X
        where id =
              (select DEPARTMENT_ID
               from TF_SMPN_USER_X
               where id = #{respUser})
    </select>
</mapper>
