<?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.xrtygis.mapper.GdreturnMapper">

    <resultMap id="gdreturnMap" type="com.tofly.xrtygis.entity.Gdreturn">
        <id property="id" column="ID"/>
        <result property="gdbh" column="GDBH"/>
        <result property="gdType" column="GD_TYPE"/>
        <result property="returnUser" column="RETURN_USER"/>
        <result property="returnTime" column="RETURN_TIME"/>
        <result property="returnInfo" column="RETURN_INFO"/>
        <result property="returnReslut" column="RETURN_RESLUT"/>
        <result property="fyr" column="FYR"/>
        <result property="phone" column="PHONE"/>
        <result property="address" column="ADDRESS"/>
        <association property="gdlxName" column="GD_TYPE"
                     select="com.tofly.xrtygis.mapper.GdreturnMapper.getGdlxById"/>
        <association property="gdReturnUserName" column="RETURN_USER"
                     select="com.tofly.baseapi.mapper.ToflyCodeCommonMapper.getUserName"/>
        <association property="returnReslutName" column="RETURN_RESLUT"
                     select="getReturnReslut"/>
    </resultMap>

    <select id="getReturnReslut" resultType="string">
        select decode(#{reslut} , '0','不满意','1','一般','2','满意','3','非常满意')
        from dual
    </select>
    <update id="updateGdReturnNum">
        UPDATE TF_YWPN_GDINFO_W
        SET GDHF_CS = NVL(GDHF_CS, 0) + 1
        WHERE GDBH = #{gdbh}
    </update>
    <select id="getGdlxById" resultType="string">
        select GDLX_MC
        from TF_YWPN_GDGLTYPEBM_W
        where ID = #{id}
    </select>
    <resultMap id="gdStatisRelMap" type="com.tofly.xrtygis.custom.entity.gs.GdStatisReslut">
        <result property="gdlx" column="GDLX"/>
        <result property="returnGdlx" column="RETURNGDLX"/>
        <result property="gdAllNum" column="ALLNUM"/>
        <result property="shouldReturnNum" column="SHOULD_HF"/>
        <result property="realityReturnNum" column="REALITY_HF"/>
        <result property="veryMyNum" column="VERYMYNUM"/>
        <result property="myNum" column="MYNUM"/>
        <result property="commonNum" column="COMMONNUM"/>
        <result property="noMyNum" column="NOMYNUM"/>
        <association property="gdlxName" column="GDLX"
                     select="com.tofly.xrtygis.mapper.GdreturnMapper.getCodeById"/>
    </resultMap>

    <select id="getGdNum" resultMap="gdStatisRelMap">
        SELECT GDLX, COUNT(1) ALLNUM, sum(case when LCJD = 45 then 1 else 0 end) SHOULD_HF, sum(GDHF_CS) REALITY_HF
        FROM TF_YWPN_GDINFO_W
        WHERE IS_RXLX = '1'
        GROUP BY GDLX
    </select>
    <select id="getReturnNum" resultMap="gdStatisRelMap">
        SELECT GD_TYPE RETURNGDLX,
               sum(case when RETURN_RESLUT = '3' then 1 else 0 end) VERYMYNUM,
               sum(case when RETURN_RESLUT = '2' then 1 else 0 end) MYNUM,
               sum(case when RETURN_RESLUT = '1' then 1 else 0 end) COMMONNUM,
               sum(case when RETURN_RESLUT = '0' then 1 else 0 end) NOMYNUM
        FROM TF_YWPN_GDRETURN_W
        GROUP BY GD_TYPE
    </select>


</mapper>
