<?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.bonus.core.customer.mapper.CustInfoMapper">
    <!--根据人员id集合获取人员信息-->
    <select id="selectOne" resultType="com.bonus.domain.CustInfo">
        select cust_id, cust_name, cust_num, cust_photo_url, mobile, pwd
        from cust_info
        <where>
            cust_state = 1
            <if test="custId != null">
                and cust_id = #{custId}
            </if>
            <if test="custName != null and custName != ''">
                and cust_name = #{custName}
            </if>
            <if test="custNum != null and custNum != ''">
                and cust_num = #{custNum}
            </if>
            <if test="mobile != null and mobile != ''">
                and mobile = #{mobile}
            </if>
            <if test="idCard != null and idCard != ''">
                and id_card = #{idCard}
            </if>
        </where>
    </select>

    <update id="updateById">
        update cust_info
        set cust_name = #{custName}, cust_num = #{custNum}, mobile = #{mobile}, id_card = #{idCard}, pwd = #{pwd}
        where cust_id = #{custId}
    </update>

    <!-- 用户详细信息,返回字段 -->
    <sql id="detailInfo">
        ci.cust_id,
        ci.cust_num,
        ci.cust_name,
        ci.mobile,
        ci.email,
        ci.sex,
        --         ci.age,
        ci.id_card,
        ci.birthday,
        ci.cust_photo_url,
        ci.org_id,
        ci.cust_third_id,
        ci.org_num,
        ci.org_full_name,
        ci.place_id,
        place.place_num,
        place.place_full_name,
        ci.psn_type,
        ci.psn_type_name,
        ci.home_addr,
        ci.qq,
        ci.wechat,
        ci.company_wechat,
        ci.dingtalk,
        ci.emer_contact_person,
        ci.emer_contact_num,
        ci.emer_contact_card,
        ci.job,
        ci.job_rank,
        ci.job_level,
        ci.job_title,
        ci.job_title_rank,
        ci.auth_strength,
        ci.entry_date,
        ci.signing_date,
        ci.expiry_date,
        --         ci.cust_type,
        ci.birthday,
        cd.label_ids,
        cd.label_names,
        cd.taste_ids,
        cd.taste_names,
        ai.end_date accEndDate,
        ci.doctor_num,
        ci.hospital_num
    </sql>

    <select id="queryCustInfoDetail" resultType="com.bonus.core.customer.vo.CustInfoVo">
        select
        <include refid="detailInfo"/>
        ,
        ci.marital_status,
        ci.cost_center_id,
        A.name costCenterName,
        ci.ethnicity_code,
        ci.native_place,
        ci.position,
        ci.bank_card_num,
        ci.head_portrait_url,
        ci.extend_date,
        ci.extend_date_time,
        ci.extend_str1,
        ci.extend_str2
        from cust_info ci
        left join cust_diet_like cd on ci.cust_id = cd.cust_id and cd.if_del = 2
        left join acc_info ai on ci.cust_id = ai.cust_id
        LEFT JOIN cust_place place ON ci.place_id = place.place_id
        LEFT JOIN cust_cost_center A ON A.cost_center_id = ci.cost_center_id
        where ci.cust_id = #{info.custId}
        and ci.cust_state = #{info.custState}
    </select>

    <!-- 查询用户详细信息 -->
    <select id="queryCustInfo" resultType="com.bonus.core.customer.vo.CustInfoVo">
        select ci.cust_limit_id,
        <if test="info.serialNum != null and info.serialNum != ''">
            ac.serial_num,
            ac.card_status,
        </if>
        ci.alipay_contract_num,
        <include refid="detailInfo"/>
        from cust_info ci
        left join cust_diet_like cd on ci.cust_id = cd.cust_id and cd.if_del = 2
        left join acc_info ai on ci.cust_id = ai.cust_id
        <if test="info.serialNum != null and info.serialNum != ''">
            left join acc_card ac on ci.cust_id = ac.cust_id and  ac.card_status in(1,4)
        </if>

        LEFT JOIN cust_place place ON ci.place_id = place.place_id
        where 1 = 1
        <if test="info.custId != null">
            and ci.cust_id = #{info.custId}
        </if>
        <if test="info.custLimitId != null">
            and ci.cust_limit_id = #{info.custLimitId}
        </if>
        <if test="info.serialNum != null and info.serialNum != ''">
            and ac.serial_num = #{info.serialNum}
        </if>
        <if test="info.custState != null">
            and ci.cust_state = #{info.custState}
        </if>
    </select>

    <select id="getCustPayVO" resultType="com.bonus.core.customer.vo.CustPayVO">
        SELECT a.cust_id,
        a.psn_type,
        a.psn_type_name,
        a.org_id,
        a.org_num,
        a.cust_third_id,
        a.alipay_contract_num,
        a.cust_state,
        a.cust_num,
        a.cust_name,
        a.org_full_name,
        a.cust_photo_url,
        a.head_portrait_url,
        a.mobile,
        b.serial_num,
        b.third_serial_num,
        b.card_status,
        b.validity_date
        FROM
        cust_info a
        LEFT JOIN acc_card b ON b.cust_id = a.cust_id and b.card_status in (1, 4)
        <if test="custPayDTO.openid != null and custPayDTO.openid != ''">
            LEFT JOIN cust_casual c ON c.cust_id = a.cust_id
        </if>
        <where>
            <if test="custPayDTO.serialNum != null and custPayDTO.serialNum != ''">
                AND b.serial_num = #{custPayDTO.serialNum}
            </if>
            <if test="custPayDTO.openid != null and custPayDTO.openid != ''">
                AND c.openid = #{custPayDTO.openid}
            </if>
            <if test="custPayDTO.custId != null">
                AND a.cust_id = #{custPayDTO.custId}
            </if>
        </where>
    </select>

</mapper>








































