MerchantMapper.xml 15 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="cn.com.glsx.dj.system.mapper.MerchantMapper" >
  <resultMap id="BaseResultMap" type="cn.com.glsx.dj.system.model.Merchant" >
    <!--
      WARNING - @mbg.generated
    -->
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="merchant_id" property="merchantId" jdbcType="INTEGER" />
    <result column="account_name" property="accountName" jdbcType="VARCHAR" />
    <result column="merchant_name" property="merchantName" jdbcType="VARCHAR" />
    <result column="short_name" property="shortName" jdbcType="VARCHAR" />
    <result column="user_type" property="userType" jdbcType="TINYINT" />
    <result column="merchant_type" property="merchantType"/>
    <result column="contact_name" property="contactName" jdbcType="VARCHAR" />
    <result column="phone" property="phone" jdbcType="VARCHAR" />
    <result column="channel_id" property="channelId"/>
    <result column="address" property="address" jdbcType="VARCHAR" />
    <result column="province_id" property="provinceId" jdbcType="INTEGER" />
    <result column="province_name" property="provinceName" jdbcType="VARCHAR" />
    <result column="city_id" property="cityId" jdbcType="INTEGER" />
    <result column="city_name" property="cityName" jdbcType="VARCHAR" />
    <result column="area_id" property="areaId" jdbcType="INTEGER" />
    <result column="area_name" property="areaName" jdbcType="VARCHAR" />
    <result column="shop_photo" property="shopPhoto" jdbcType="VARCHAR" />
    <result column="business_hours" property="businessHours" jdbcType="VARCHAR" />
    <result column="parent_merchant_id" property="parentMerchantId"/>
    <result column="parent_merchant_name" property="parentMerchantName"/>
    <result column="sap" property="sap"/>
    <result column="region" property="region"/>
    <result column="stay_contact_name" property="stayContactName"/>
    <result column="stay_phone" property="stayPhone"/>
    <result column="created_by" property="createdBy" jdbcType="VARCHAR" />
    <result column="created_date" property="createdDate" jdbcType="TIMESTAMP" />
    <result column="updated_by" property="updatedBy" jdbcType="VARCHAR" />
    <result column="updated_date" property="updatedDate" jdbcType="TIMESTAMP" />
    <result column="deleted_flag" property="deletedFlag" jdbcType="CHAR" />
  </resultMap>
  <resultMap id="DTOResultMap" type="cn.com.glsx.dj.system.dto.MerchantDTO" extends="BaseResultMap">
	<result column="user_id" property="userId"/>
	<result column="rescueTime" property="rescueTime"/>
	<result column="rescueRange" property="rescueRange"/>
	<result column="brand" property="brand"/>
	<result column="collisionPhone" property="collisionPhone"/>
	<result column="lng" property="lng"/>
	<result column="lat" property="lat"/>
    <result column="channel_type" property="channelType"/>
    <result column="enabled_flag" property="enabledFlag"/>
    <result column="beServed" property="beServed"/>
  </resultMap>
  <sql id="Base_Column_List" >
    id, merchant_id, account_name, merchant_name, short_name, user_type,merchant_type, contact_name,
    phone,channel_id, address, province_id, province_name, city_id, city_name, area_id,
    area_name, shop_photo, business_hours,parent_merchant_id,parent_merchant_name,
    sap,region,stay_contact_name,stay_phone,
    created_by, created_date, updated_by, updated_date,deleted_flag
  </sql>

  <select id="list" parameterType="cn.com.glsx.dj.system.dto.MerchantDTO" resultMap="DTOResultMap">
  	select a.id, a.merchant_id, a.account_name, a.merchant_name, a.short_name, a.user_type,a.merchant_type,
  	  a.contact_name,a.phone,a.channel_id, a.address, a.province_id, a.province_name, a.city_id, a.city_name,
  	  a.area_id,a.area_name, a.shop_photo, a.business_hours,a.parent_merchant_id,a.parent_merchant_name,
      a.created_by, a.created_date, a.updated_by, a.updated_date,a.deleted_flag,a.lng,a.lat,a.sap,
      a.region,a.stay_contact_name,a.stay_phone,
      b.id as user_id, b.enabled_flag, c.channel_type
      from dj_system_merchant a
      left join dj_system_user b on b.deleted_flag='N' and b.merchant_id=a.merchant_id and b.user_type=a.user_type
      left join dj_system_channel_config c on c.id = a.channel_id and c.deleted_flag='N'
  	<where>
        a.deleted_flag = 'N'
        <if test="channelId != null">
        	and a.channel_id = #{channelId}
        </if>
        <if test="channelType != null">
            and c.channel_type = #{channelType}
        </if>
  		<if test="merchantId != null">
  			and a.merchant_id = #{merchantId}
  		</if>
  		<if test="merchantIdExcept != null">
            and a.merchant_id != #{merchantIdExcept}
        </if>
  		<if test="parentMerchantId != null">
  			and a.parent_merchant_id = #{parentMerchantId}
  		</if>
  		<if test="userType != null">
  			and a.user_type = #{userType}
  		</if>
  		<if test="merchantType != null">
  			and a.merchant_type = #{merchantType}
  		</if>
  		<if test="merchantTypeList != null">
           and a.merchant_type in
           <foreach collection="merchantTypeList" open="(" close=")" separator="," item="item">
               #{item}
           </foreach>     
        </if>
  		<if test="accountName != null and accountName !=''">
  			and a.account_name like CONCAT('%',#{accountName},'%')
  		</if>
  		<if test="merchantName != null and merchantName !=''">
  			and (
  				a.merchant_name like CONCAT('%',#{merchantName},'%')
  				or a.short_name like CONCAT('%',#{merchantName},'%')
  				)
  		</if>
  		<if test="parentMerchantName != null and parentMerchantName !=''">
  			and a.parent_merchant_name like CONCAT('%',#{parentMerchantName},'%')
  		</if>
  		<if test="shortName != null and shortName !=''">
  			and a.short_name like CONCAT('%',#{shortName},'%')
  		</if>
  		<if test="contactName != null and contactName !=''">
  			and a.contact_name like CONCAT('%',#{contactName},'%')
  		</if>
  		<if test="phone != null and phone !=''">
  			and a.phone like CONCAT('%',#{phone},'%')
  		</if>
        <if test="createdBy != null and createdBy !=''">
            and a.created_by = #{createdBy}
        </if>
        <if test="keyword != null and keyword !=''">
            and (a.merchant_name like CONCAT('%',#{keyword},'%')
            or a.merchant_id = #{keyword})
        </if>
  		<if test="merchantIds != null and merchantIds.size() > 0">
  			and a.merchant_id in
  			<foreach collection="merchantIds" index="index" item="item" open="(" separator="," close=")">
                #{item}
        	</foreach>
  		</if>
        <if test="roleIds != null and roleIds.size() > 0">
            and EXISTS(
                select 1 from dj_system_user_role b
                left join dj_system_user c on b.user_id = c.id
                where a.merchant_id = c.merchant_id and a.deleted_flag = 'N' and b.deleted_flag = 'N' and c.deleted_flag = 'N'
                and b.role_id in
                <foreach collection="roleIds" index="index" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            )
        </if>
        <if test="loginPhone != null and loginPhone!=''">
  			and b.phone = #{loginPhone}
  		</if>
        <if test="carBrandId != null">
            and exists(
                select 1 from dj_system_merchant_car_brand d
                where d.merchant_id = a.merchant_id and d.deleted_flag = 'N'
                and d.brand_id = #{carBrandId}
                <if test="carChildsBrandId != null">
                    and d.childs_brand_id = #{carChildsBrandId}
                </if>
            )
        </if>
        <if test="null != merchantAddressType and merchantAddressType ==1">
        	and (a.address is not null and a.address != '')
        </if>
        <if test="null != merchantAddressType and merchantAddressType ==2">
        	and (a.address is null or a.address = '')
        </if>
        <if test="null != enabledFlag and enabledFlag !=''">
        	and b.enabled_flag = #{enabledFlag}
        </if>
  	</where>
  	order by a.updated_date desc,a.id desc
  </select>

    <select id="listWithServedMark" parameterType="cn.com.glsx.dj.system.dto.MerchantDTO" resultMap="DTOResultMap">
        select a.id, a.merchant_id, a.account_name, a.merchant_name, a.short_name, a.user_type,a.merchant_type,
        a.contact_name,a.phone,a.channel_id, a.address, a.province_id, a.province_name, a.city_id, a.city_name,
        a.area_id,a.area_name, a.shop_photo, a.business_hours,a.parent_merchant_id,a.parent_merchant_name,
        a.region,a.stay_contact_name,a.stay_phone,
        a.created_by, a.created_date, a.updated_by, a.updated_date,a.deleted_flag,a.lng,a.lat,
        b.id as user_id, b.enabled_flag, c.channel_type, IF( d.id IS NULL, FALSE, TRUE ) AS beServed
        from dj_system_merchant a
        left join dj_system_user b on b.deleted_flag='N' and b.merchant_id=a.merchant_id and b.user_type=a.user_type
        left join dj_system_channel_config c on c.id = a.channel_id and c.deleted_flag='N'
        LEFT JOIN (
            SELECT id
            FROM dj_system_merchant
            WHERE merchant_id IN
            <foreach collection="beServedMerchantIds" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        ) d ON a.id = d.id
        <where>
            a.deleted_flag = 'N'
            <if test="channelId != null">
                and a.channel_id = #{channelId}
            </if>
            <if test="channelType != null">
                and c.channel_type = #{channelType}
            </if>
            <if test="merchantId != null">
                and a.merchant_id = #{merchantId}
            </if>
            <if test="merchantIdExcept != null">
                and a.merchant_id != #{merchantIdExcept}
            </if>
            <if test="parentMerchantId != null">
                and a.parent_merchant_id = #{parentMerchantId}
            </if>
            <if test="userType != null">
                and a.user_type = #{userType}
            </if>
            <if test="merchantType != null">
                and a.merchant_type = #{merchantType}
            </if>
            <if test="merchantTypeList != null">
                and a.merchant_type in
                <foreach collection="merchantTypeList" open="(" close=")" separator="," item="item">
                    #{item}
                </foreach>
            </if>
            <if test="accountName != null and accountName !=''">
                and a.account_name like CONCAT('%',#{accountName},'%')
            </if>
            <if test="merchantName != null and merchantName !=''">
                and (
                a.merchant_name like CONCAT('%',#{merchantName},'%')
                or a.short_name like CONCAT('%',#{merchantName},'%')
                )
            </if>
            <if test="parentMerchantName != null and parentMerchantName !=''">
                and a.parent_merchant_name like CONCAT('%',#{parentMerchantName},'%')
            </if>
            <if test="shortName != null and shortName !=''">
                and a.short_name like CONCAT('%',#{shortName},'%')
            </if>
            <if test="contactName != null and contactName !=''">
                and a.contact_name like CONCAT('%',#{contactName},'%')
            </if>
            <if test="phone != null and phone !=''">
                and a.phone like CONCAT('%',#{phone},'%')
            </if>
            <if test="createdBy != null and createdBy !=''">
                and a.created_by = #{createdBy}
            </if>
            <if test="keyword != null and keyword !=''">
                and (a.merchant_name like CONCAT('%',#{keyword},'%')
                or a.merchant_id = #{keyword})
            </if>
            <if test="merchantIds != null and merchantIds.size() > 0">
                and a.merchant_id in
                <foreach collection="merchantIds" index="index" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="roleIds != null and roleIds.size() > 0">
                and EXISTS(
                select 1 from dj_system_user_role b
                left join dj_system_user c on b.user_id = c.id
                where a.merchant_id = c.merchant_id and a.deleted_flag = 'N' and b.deleted_flag = 'N' and c.deleted_flag = 'N'
                and b.role_id in
                <foreach collection="roleIds" index="index" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
                )
            </if>
            <if test="loginPhone != null and loginPhone!=''">
                and b.phone = #{loginPhone}
            </if>
            <if test="carBrandId != null">
                and exists(
                select 1 from dj_system_merchant_car_brand d
                where d.merchant_id = a.merchant_id and d.deleted_flag = 'N'
                and d.brand_id = #{carBrandId}
                <if test="carChildsBrandId != null">
                    and d.childs_brand_id = #{carChildsBrandId}
                </if>
                )
            </if>
            <if test="null != merchantAddressType and merchantAddressType ==1">
                and (a.address is not null and a.address != '')
            </if>
            <if test="null != merchantAddressType and merchantAddressType ==2">
                and (a.address is null or a.address = '')
            </if>
            <if test="null != enabledFlag and enabledFlag !=''">
                and b.enabled_flag = #{enabledFlag}
            </if>
        </where>
        order by beServed,a.updated_date desc,a.id desc
    </select>

	<select id="getListShopByCity" parameterType="java.lang.String"
		resultMap="DTOResultMap">
		SELECT c.merchant_id, c.lat, c.lng,c.merchant_name,
		IFNULL(c.address, '') as address,a.service_hours as rescueTime,a.service_range as rescueRange,
		GROUP_CONCAT(b.vehicle_brand) as brand, CONCAT_WS(',',a.collision_phone,
		a.spare_phones) as collisionPhone
		FROM dj_collision_notice_config a LEFT JOIN
		dj_collision_notice_config_car_brand b ON
		a.merchant_id = b.merchant_id and b.deleted_flag = 'N'
		LEFT JOIN dj_system_merchant c ON
		a.merchant_id = c.merchant_id
		WHERE a.merchant_id in (SELECT merchant_id
		FROM dj_system_merchant WHERE city_name = #{city} ) GROUP BY a.merchant_id;
	</select>

    <select id="listSummary" parameterType="cn.com.glsx.dj.system.dto.MerchantDTO" resultMap="DTOResultMap">
        SELECT dsm.merchant_id, dsm.merchant_name, dscc.channel_type
        FROM dj_system_merchant dsm
        left join dj_system_channel_config dscc on dscc.id = dsm.channel_id and dscc.deleted_flag = 'N'
        where dsm.deleted_flag = 'N'
        <if test="merchantId != null">
            and dsm.merchant_id = #{merchantId}
        </if>
        <if test="merchantIds != null and merchantIds.size() > 0">
            and dsm.merchant_id in
            <foreach collection="merchantIds" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="merchantType != null">
            and dsm.merchant_type = #{merchantType}
        </if>
    </select>
</mapper>