CustomerDeviceMapper.xml 7.44 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.customer.mapper.CustomerDeviceMapper" >
  <resultMap id="BaseResultMap" type="cn.com.glsx.dj.customer.model.CustomerDevice" >
    <!--
      WARNING - @mbg.generated
    -->
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="user_id" property="userId" jdbcType="INTEGER" />
    <result column="employee_name" property="employeeName"/>
    <result column="merchant_id" property="merchantId" jdbcType="INTEGER" />
    <result column="merchant_name" property="merchantName" jdbcType="VARCHAR" />
    <result column="imei" property="imei" jdbcType="VARCHAR" />
    <result column="device_type_id" property="deviceTypeId" jdbcType="INTEGER" />
    <result column="source" property="source" jdbcType="TINYINT" />
    <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" />

    <result column="name" property="name" jdbcType="VARCHAR" />
    <result column="phone" property="phone" jdbcType="INTEGER" />
    <result column="stand_no" property="standNo" jdbcType="VARCHAR" />
    <result column="d_d_code" property="DDCode" jdbcType="INTEGER"/>
    <result column="plate_num" property="plateNum" jdbcType="VARCHAR"/>

    <result column="vehicle_brand_id" property="vehicleBrandId" jdbcType="INTEGER" />
	<result column="vehicle_brand" property="vehicleBrand" jdbcType="VARCHAR" />
	<result column="vehicle_childs_brand_id" property="vehicleChildsBrandId" jdbcType="INTEGER" />
	<result column="vehicle_childs_brand_name" property="vehicleChildsBrandName" jdbcType="VARCHAR" />
	<result column="vehicle_series_id" property="vehicleSeriesId" jdbcType="INTEGER" />
	<result column="vehicle_series_name" property="vehicleSeriesName" jdbcType="VARCHAR" />
	<result column="vehicle_type_id" property="vehicleTypeId" jdbcType="INTEGER" />
	<result column="vehicle_type_name" property="vehicleTypeName" jdbcType="VARCHAR" />
	<result column="has_order" property="hasOrder" jdbcType="TINYINT" />
	<result column="install_mileage" property="installMileage"/>
	<result column="next_maintain_mileage" property="nextMaintainMileage"/>
	<result column="next_maintain_time" property="nextMaintainTime"/>
	<result column="last_maintain_mileage" property="lastMaintainMileage"/>
	<result column="last_maintain_time" property="lastMaintainTime"/>
	<result column="is_auth" property="isAuth"/>
	<result column="is_shop_change"  property="isShopChange"/>
	<result column="is_auth_phone"  property="isAuthPhone"/>
	<result column="iccid" property="iccid"/>
	<result column="dispatch_order_code" property="dispatchOrderCode"/>
	<result column="gender" property="gender"/>
	<result column="is_change" property="isChange"/>
  </resultMap>
  <resultMap id="DTOResultMap" type="cn.com.glsx.dj.customer.dto.CustomerDeviceDTO" extends="BaseResultMap"></resultMap>
  <sql id="Base_Column_List" >
    <!--
      WARNING - @mbg.generated
    -->
    id, user_id,employee_name, merchant_id, merchant_name, imei, device_type_id, source, created_by,
    created_date, updated_by, updated_date, deleted_flag,is_auth,is_shop_change,
    name,phone,stand_no,d_d_code,plate_num,has_order,is_auth_phone,
    vehicle_brand_id,vehicle_brand,vehicle_childs_brand_id,vehicle_childs_brand_name,vehicle_series_id,
    vehicle_series_name,vehicle_type_id,vehicle_type_name,gender,is_change,
    install_mileage,next_maintain_mileage,next_maintain_time,last_maintain_mileage,last_maintain_time,iccid, dispatch_order_code
  </sql>
  <select id="list" parameterType="cn.com.glsx.dj.customer.dto.CustomerDeviceDTO" resultMap="DTOResultMap">
  	select <include refid="Base_Column_List" />
    from dj_customer_device
    <where>
    	deleted_flag = 'N'
    	<if test="userId != null">
    		and user_id = #{userId}
    	</if>
		<if test="isAuth != null">
			and is_auth = #{isAuth}
		</if>
    	<if test="employeeName != null and employeeName !=''">
    		and employee_name like CONCAT('%',#{employeeName},'%')
    	</if>
    	<if test="merchantId != null">
    		and merchant_id = #{merchantId}
    	</if>
    	<if test="merchantName != null and merchantName !=''">
    		and merchant_name like CONCAT('%',#{merchantName},'%')
    	</if>
		<if test="standNo != null and standNo !=''">
			and stand_no  = #{standNo}
		</if>
		<if test="name != null and name !=''">
			and name = #{name}
		</if>
    	<if test="imei != null and imei !=''">
    		and imei = #{imei}
    	</if>
    	<if test="deviceTypeId != null">
    		and device_type_id = #{deviceTypeId}
    	</if>
    	<if test="createdBy != null and createdBy !=''">
    		and created_by like CONCAT('%',#{createdBy},'%')
    	</if>
    	<if test="startDate != null">
    		<![CDATA[  and created_date >= #{startDate} ]]>
    	</if>
    	<if test="endDate != null">
    		<![CDATA[  and created_date <= #{endDate} ]]>
    	</if>
    	<if test="merchantIds != null and merchantIds.size > 0 ">
			and merchant_id in
        	<foreach item="item" index="index" collection="merchantIds" open="(" separator="," close=")">
        		#{item}
        	</foreach>
		</if>
		<if test="dispatchOrderCode != null and dispatchOrderCode  != ''">
			and dispatch_order_code = #{dispatchOrderCode}
		</if>
		<if test="source != null">
			and source = #{source}
		</if>
		<if test="isBind != null and isBind == 0">
			and stand_no is null
		</if>
		<if test="isBind != null and isBind == 1">
			and stand_no is not null
		</if>
    </where>
    order by updated_date desc
  </select>

  <select id="getNotdidi"  resultMap="BaseResultMap">
  	select <include refid="Base_Column_List"/>
    from dj_customer_device
    <where>
    	deleted_flag = 'N'
		and (
		d_d_code is NULL
		and IFNULL(is_auth_phone,0) != '1'
		and IFNULL(is_shop_change,0) != '1'
		)
		or IFNULL(is_auth_phone,0) != '1'
    </where>
    order by id desc
  </select>

	<select id="listAll"  resultMap="BaseResultMap">
		select <include refid="Base_Column_List"/>
		from dj_customer_device
		<where>
			deleted_flag = 'N'
		</where>
		order by id desc
	</select>


	<select id="getCountCustomerAndOrder" parameterType="java.util.List" resultType="java.lang.Integer">
  	SELECT  COUNT(DISTINCT a.sub_device_sn)
		FROM (
			SELECT DISTINCT sub_device_sn
			FROM dj_insure_order
				<where>
					insurance_status = 1 AND deleted_flag = 'N'
					and merchant_id in
					<foreach item="merchantId" index="index" collection="merchantIds" open="(" separator="," close=")">
						 #{merchantId}
					</foreach>
				</where>



			UNION ALL
			SELECT DISTINCT imei AS sub_device_sn
			FROM dj_customer_device
				<where>
					deleted_flag = 'N'
					and merchant_id in
					<foreach item="merchantId" index="index" collection="merchantIds" open="(" separator="," close=")">
						 #{merchantId}
					</foreach>
				</where>
			) a
  </select>

	<delete id="deleteById" parameterType="java.lang.Integer">
		DELETE  FROM dj_customer_device WHERE id = #{id}
	</delete>

	<update id="updateGenderAndIsChangeById" parameterType="cn.com.glsx.dj.customer.model.CustomerDevice" >
		update dj_customer_device
		<set>
				gender =#{gender},is_change =#{isChange},
		</set>
		<where>
			deleted_flag = 'N'
			and id = #{id}
		</where>
	</update>

</mapper>