<?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.willalp.event.mapper.HsWelfareApplyRecordMapper">

    <resultMap type="com.willalp.event.domain.HsWelfareApplyRecord" id="HsWelfareApplyRecordResult">
        <result property="id" column="id"/>
        <result property="source" column="source"/>
        <result property="userCode" column="user_code"/>
        <result property="userName" column="user_name"/>
        <result property="address" column="address"/>
        <result property="nowStatus" column="now_status"/>
        <result property="isDelete" column="is_delete"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <sql id="selectHsWelfareApplyRecordVo">
        select id,
               source,
               user_code,
               user_name,
               address,
               now_status,
               is_delete,
               create_by,
               create_time,
               update_by,
               update_time,
               remark
        from hs_welfare_apply_record
    </sql>
    <update id="doUnregistered">
        update hs_welfare_apply_record
        set now_status = '3'
        WHERE source = #{source}
    </update>

    <select id="selectHsWelfareApplyRecordList" parameterType="HsWelfareApplyRecord"
            resultMap="HsWelfareApplyRecordResult">
        <include refid="selectHsWelfareApplyRecordVo"/>
        <where>
            is_delete = 0
            <if test="source != null  and source != ''">
                and source = #{source}
            </if>
            <if test="userCode != null  and userCode != ''">
                and user_code = #{userCode}
            </if>
            <if test="userName != null  and userName != ''">
                and user_name like concat('%', #{userName}, '%')
            </if>
            <if test="address != null  and address != ''">
                and address = #{address}
            </if>
            <if test="nowStatus != null  and nowStatus != ''">
                and now_status = #{nowStatus}
            </if>
            <if test="isDelete != null ">
                and is_delete = #{isDelete}
            </if>
        </where>
    </select>
    <select id="stat" resultType="com.willalp.event.domain.vo.WelfareApplyStatVo">
        SELECT sdd.dict_label        address,
               sum(now_status = '2') applyNum
        FROM `hs_welfare_apply_record` hwar
                 LEFT JOIN sys_dict_data sdd ON sdd.dict_value = hwar.address
            AND dict_type = 'welfare_apply_addr'
        WHERE hwar.is_delete = 0
          AND hwar.now_status = '2'
          AND hwar.source = #{source}
        GROUP BY address
    </select>
    <select id="importInitDataTemp" resultType="com.willalp.event.domain.HsWelfareApplyRecord">
        SELECT user_code, user_name
        FROM hs_org_personnel_files
        WHERE is_delete = 0
    </select>

</mapper>
