McVisitUserMapper.xml 18 KB
<?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.chinagas.modules.schsf.mapper.McVisitUserMapper">

    <resultMap type="com.chinagas.modules.schsf.domain.McVisitUser" id="McVisitUserResult">
        <result property="id"    column="id"    />
        <result property="userCode"    column="user_code"    />
        <result property="userName"    column="user_name"    />
        <result property="userPhone"    column="user_phone"    />
        <result property="residenceType"    column="residence_type"    />
        <result property="familyMembers"    column="family_members"    />
        <result property="incomeSource"    column="income_source"    />
        <result property="houseCondition"    column="house_condition"    />
        <result property="originalAppliances"    column="original_appliances"    />
        <result property="decorationStatus"    column="decoration_status"    />
        <result property="currentCookingEnergy"    column="current_cooking_energy"    />
        <result property="currentHeatingEnergy"    column="current_heating_energy"    />
        <result property="isIntent"    column="is_intent"    />
        <result property="regionName"    column="region_name"    />
        <result property="regionCode"    column="region_code"    />
        <result property="budgetOwner"    column="budget_owner"    />
        <result property="companyName"    column="company_name"    />
        <result property="companyCode"    column="company_code"    />
        <result property="province"    column="province"    />
        <result property="city"    column="city"    />
        <result property="district"    column="district"    />
        <result property="street"    column="street"    />
        <result property="detailedAddress"    column="detailed_address"    />
        <result property="township"    column="township"    />
        <result property="village"    column="village"    />
        <result property="vlgOrCmty"    column="vlg_or_cmty"    />
        <result property="userAge"    column="user_age"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="defFlag"    column="def_flag"    />
    </resultMap>

    <sql id="selectMcVisitUserVo">
        select id, user_code, user_name, user_phone, residence_type, family_members, income_source, house_condition, original_appliances, decoration_status, current_cooking_energy, current_heating_energy, is_intent, region_name, region_code, budget_owner, company_name, company_code, province, city, district, street, detailed_address, township, village, vlg_or_cmty, user_age, create_time, create_by, def_flag from mc_visit_user
    </sql>

    <select id="selectMcVisitUserList" parameterType="com.chinagas.modules.schsf.domain.McVisitUser" resultMap="McVisitUserResult">
        <include refid="selectMcVisitUserVo"/>
        <where>
            <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="userPhone != null  and userPhone != ''"> and user_phone = #{userPhone}</if>
            <if test="residenceType != null  and residenceType != ''"> and residence_type = #{residenceType}</if>
            <if test="familyMembers != null  and familyMembers != ''"> and family_members = #{familyMembers}</if>
            <if test="incomeSource != null  and incomeSource != ''"> and income_source = #{incomeSource}</if>
            <if test="houseCondition != null  and houseCondition != ''"> and house_condition = #{houseCondition}</if>
            <if test="originalAppliances != null  and originalAppliances != ''"> and original_appliances = #{originalAppliances}</if>
            <if test="decorationStatus != null  and decorationStatus != ''"> and decoration_status = #{decorationStatus}</if>
            <if test="currentCookingEnergy != null  and currentCookingEnergy != ''"> and current_cooking_energy = #{currentCookingEnergy}</if>
            <if test="currentHeatingEnergy != null  and currentHeatingEnergy != ''"> and current_heating_energy = #{currentHeatingEnergy}</if>
            <if test="isIntent != null  and isIntent != ''"> and is_intent = #{isIntent}</if>
            <if test="regionName != null  and regionName != ''"> and region_name like concat('%', #{regionName}, '%')</if>
            <if test="regionCode != null  and regionCode != ''"> and region_code = #{regionCode}</if>
            <if test="budgetOwner != null  and budgetOwner != ''"> and budget_owner = #{budgetOwner}</if>
            <if test="companyName != null  and companyName != ''"> and company_name like concat('%', #{companyName}, '%')</if>
            <if test="companyCode != null  and companyCode != ''"> and company_code = #{companyCode}</if>
            <if test="province != null  and province != ''"> and province = #{province}</if>
            <if test="city != null  and city != ''"> and city = #{city}</if>
            <if test="district != null  and district != ''"> and district = #{district}</if>
            <if test="street != null  and street != ''"> and street = #{street}</if>
            <if test="detailedAddress != null  and detailedAddress != ''"> and detailed_address = #{detailedAddress}</if>
            <if test="township != null  and township != ''"> and township = #{township}</if>
            <if test="village != null  and village != ''"> and village = #{village}</if>
            <if test="vlgOrCmty != null  and vlgOrCmty != ''"> and vlg_or_cmty = #{vlgOrCmty}</if>
            <if test="userAge != null  and userAge != ''"> and user_age = #{userAge}</if>
            <if test="defFlag != null  and defFlag != ''"> and def_flag = #{defFlag}</if>
        </where>
    </select>

    <select id="selectMcVisitUserById" parameterType="Long" resultMap="McVisitUserResult">
        <include refid="selectMcVisitUserVo"/>
        where id = #{id}
    </select>

    <insert id="insertMcVisitUser" parameterType="com.chinagas.modules.schsf.domain.McVisitUser">
        insert into mc_visit_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="userCode != null and userCode != ''">user_code,</if>
            <if test="userName != null and userName != ''">user_name,</if>
            <if test="userPhone != null and userPhone != ''">user_phone,</if>
            <if test="residenceType != null and residenceType != ''">residence_type,</if>
            <if test="familyMembers != null">family_members,</if>
            <if test="incomeSource != null">income_source,</if>
            <if test="houseCondition != null">house_condition,</if>
            <if test="originalAppliances != null">original_appliances,</if>
            <if test="decorationStatus != null">decoration_status,</if>
            <if test="currentCookingEnergy != null">current_cooking_energy,</if>
            <if test="currentHeatingEnergy != null">current_heating_energy,</if>
            <if test="isIntent != null">is_intent,</if>
            <if test="regionName != null and regionName != ''">region_name,</if>
            <if test="regionCode != null and regionCode != ''">region_code,</if>
            <if test="budgetOwner != null and budgetOwner != ''">budget_owner,</if>
            <if test="companyName != null and companyName != ''">company_name,</if>
            <if test="companyCode != null and companyCode != ''">company_code,</if>
            <if test="province != null">province,</if>
            <if test="city != null">city,</if>
            <if test="district != null">district,</if>
            <if test="street != null">street,</if>
            <if test="detailedAddress != null">detailed_address,</if>
            <if test="township != null">township,</if>
            <if test="village != null">village,</if>
            <if test="vlgOrCmty != null">vlg_or_cmty,</if>
            <if test="userAge != null">user_age,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null and createBy != ''">create_by,</if>
            <if test="defFlag != null and defFlag != ''">def_flag,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="userCode != null and userCode != ''">#{userCode},</if>
            <if test="userName != null and userName != ''">#{userName},</if>
            <if test="userPhone != null and userPhone != ''">#{userPhone},</if>
            <if test="residenceType != null and residenceType != ''">#{residenceType},</if>
            <if test="familyMembers != null">#{familyMembers},</if>
            <if test="incomeSource != null">#{incomeSource},</if>
            <if test="houseCondition != null">#{houseCondition},</if>
            <if test="originalAppliances != null">#{originalAppliances},</if>
            <if test="decorationStatus != null">#{decorationStatus},</if>
            <if test="currentCookingEnergy != null">#{currentCookingEnergy},</if>
            <if test="currentHeatingEnergy != null">#{currentHeatingEnergy},</if>
            <if test="isIntent != null">#{isIntent},</if>
            <if test="regionName != null and regionName != ''">#{regionName},</if>
            <if test="regionCode != null and regionCode != ''">#{regionCode},</if>
            <if test="budgetOwner != null and budgetOwner != ''">#{budgetOwner},</if>
            <if test="companyName != null and companyName != ''">#{companyName},</if>
            <if test="companyCode != null and companyCode != ''">#{companyCode},</if>
            <if test="province != null">#{province},</if>
            <if test="city != null">#{city},</if>
            <if test="district != null">#{district},</if>
            <if test="street != null">#{street},</if>
            <if test="detailedAddress != null">#{detailedAddress},</if>
            <if test="township != null">#{township},</if>
            <if test="village != null">#{village},</if>
            <if test="vlgOrCmty != null">#{vlgOrCmty},</if>
            <if test="userAge != null">#{userAge},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null and createBy != ''">#{createBy},</if>
            <if test="defFlag != null and defFlag != ''">#{defFlag},</if>
         </trim>
    </insert>

    <update id="updateMcVisitUser" parameterType="com.chinagas.modules.schsf.domain.McVisitUser">
        update mc_visit_user
        <trim prefix="SET" suffixOverrides=",">
            <if test="userCode != null and userCode != ''">user_code = #{userCode},</if>
            <if test="userName != null and userName != ''">user_name = #{userName},</if>
            <if test="userPhone != null and userPhone != ''">user_phone = #{userPhone},</if>
            <if test="residenceType != null and residenceType != ''">residence_type = #{residenceType},</if>
            <if test="familyMembers != null">family_members = #{familyMembers},</if>
            <if test="incomeSource != null">income_source = #{incomeSource},</if>
            <if test="houseCondition != null">house_condition = #{houseCondition},</if>
            <if test="originalAppliances != null">original_appliances = #{originalAppliances},</if>
            <if test="decorationStatus != null">decoration_status = #{decorationStatus},</if>
            <if test="currentCookingEnergy != null">current_cooking_energy = #{currentCookingEnergy},</if>
            <if test="currentHeatingEnergy != null">current_heating_energy = #{currentHeatingEnergy},</if>
            <if test="isIntent != null">is_intent = #{isIntent},</if>
            <if test="regionName != null and regionName != ''">region_name = #{regionName},</if>
            <if test="regionCode != null and regionCode != ''">region_code = #{regionCode},</if>
            <if test="budgetOwner != null and budgetOwner != ''">budget_owner = #{budgetOwner},</if>
            <if test="companyName != null and companyName != ''">company_name = #{companyName},</if>
            <if test="companyCode != null and companyCode != ''">company_code = #{companyCode},</if>
            <if test="province != null">province = #{province},</if>
            <if test="city != null">city = #{city},</if>
            <if test="district != null">district = #{district},</if>
            <if test="street != null">street = #{street},</if>
            <if test="detailedAddress != null">detailed_address = #{detailedAddress},</if>
            <if test="township != null">township = #{township},</if>
            <if test="village != null">village = #{village},</if>
            <if test="vlgOrCmty != null">vlg_or_cmty = #{vlgOrCmty},</if>
            <if test="userAge != null">user_age = #{userAge},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null and createBy != ''">create_by = #{createBy},</if>
            <if test="defFlag != null and defFlag != ''">def_flag = #{defFlag},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteMcVisitUserById" parameterType="Long">
        delete from mc_visit_user where id = #{id}
    </delete>

    <delete id="deleteMcVisitUserByIds" parameterType="String">
        delete from mc_visit_user where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <select id="selectMcVisitUserByVlgOrCmtys" resultMap="McVisitUserResult"  parameterType="com.chinagas.modules.schsf.domain.McVisitUser">
        SELECT user_code, user_name, user_phone, residence_type, family_members, income_source, house_condition, original_appliances, decoration_status, current_cooking_energy, current_heating_energy, is_intent, region_name, region_code, budget_owner, company_name, company_code , province, city,district,street,detailed_address, fridge_status, ac_status, tv_status, washer_status,water_heater_status, pv_system_status, township, village, vlg_or_cmty, user_age, create_time, create_by, def_flag
        FROM mc_visit_user
        where 1=1
            <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="userPhone != null  and userPhone != ''"> and user_phone = #{userPhone}</if>
            <if test="residenceType != null  and residenceType != ''"> and residence_type = #{residenceType}</if>
            <if test="familyMembers != null  and familyMembers != ''"> and family_members = #{familyMembers}</if>
            <if test="incomeSource != null  and incomeSource != ''"> and income_source = #{incomeSource}</if>
            <if test="houseCondition != null  and houseCondition != ''"> and house_condition = #{houseCondition}</if>
            <if test="originalAppliances != null  and originalAppliances != ''"> and original_appliances = #{originalAppliances}</if>
            <if test="decorationStatus != null  and decorationStatus != ''"> and decoration_status = #{decorationStatus}</if>
            <if test="currentCookingEnergy != null  and currentCookingEnergy != ''"> and current_cooking_energy = #{currentCookingEnergy}</if>
            <if test="currentHeatingEnergy != null  and currentHeatingEnergy != ''"> and current_heating_energy = #{currentHeatingEnergy}</if>
            <if test="isIntent != null  and isIntent != ''"> and is_intent = #{isIntent}</if>
            <if test="regionName != null  and regionName != ''"> and region_name like concat('%', #{regionName}, '%')</if>
            <if test="regionCode != null  and regionCode != ''"> and region_code = #{regionCode}</if>
            <if test="budgetOwner != null  and budgetOwner != ''"> and budget_owner = #{budgetOwner}</if>
            <if test="companyName != null  and companyName != ''"> and company_name like concat('%', #{companyName}, '%')</if>
            <if test="companyCode != null  and companyCode != ''"> and company_code = #{companyCode}</if>
            <if test="province != null  and province != ''"> and province = #{province}</if>
            <if test="city != null  and city != ''"> and city = #{city}</if>
            <if test="district != null  and district != ''"> and district = #{district}</if>
            <if test="street != null  and street != ''"> and street = #{street}</if>
            <if test="detailedAddress != null  and detailedAddress != ''"> and detailed_address = #{detailedAddress}</if>
            <if test="township != null  and township != ''"> and township = #{township}</if>
            <if test="village != null  and village != ''"> and village = #{village}</if>
            <if test="vlgOrCmty != null  and vlgOrCmty != ''"> and vlg_or_cmty = #{vlgOrCmty}</if>
            <if test="userAge != null  and userAge != ''"> and user_age = #{userAge}</if>
            <if test="defFlag != null  and defFlag != ''"> and def_flag = #{defFlag}</if>
        UNION
        SELECT DISTINCT v.user_code, v.user_name, v.user_phone,null ,v.family_members,null,v.house_condition,
        null,null ,v.current_cooking_energy,v.current_heating_energy,v.is_intent,v.region_name,null,null,v.company_name,v.company_code,
        v.user_province as province,v.user_city as city,v.user_district as district,v.user_street as street,v.user_detailed_address as detailed_address,
        v.fridge_status, ac_status,v.tv_status, v.washer_status,v.water_heater_status,v.pv_system_status,null ,null ,v.vlg_or_cmty ,null ,null,null,null
        FROM mc_visit v
        INNER JOIN (
            SELECT DISTINCT u.user_name, u.user_phone,max(u.id) as id
            FROM mc_visit u
            WHERE 1=1
            and not exists( select id from mc_visit_user t where t.user_phone=u.user_phone)
            GROUP BY u.user_name, u.user_phone
        ) tb  on v.id= tb.id
        WHERE 1=1
        <if test="companyCode != null  and companyCode != ''"> and v.company_code = #{companyCode}</if>
        <if test="vlgOrCmty != null  and vlgOrCmty != ''"> and v.vlg_or_cmty = #{vlgOrCmty}</if>
    </select>
</mapper>