CustomerLabelMapper.xml 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.yijia.label.mapper.CustomerLabelMapper">
  6. <resultMap type="CustomerLabel" id="CustomerLabelResult">
  7. <result property="id" column="id" />
  8. <result property="phone" column="phone" />
  9. <result property="labelId" column="label_id" />
  10. <result property="stationId" column="station_id" />
  11. <result property="createBy" column="create_by" />
  12. <result property="createTime" column="create_time" />
  13. <result property="updateBy" column="update_by" />
  14. <result property="updateTime" column="update_time" />
  15. <result property="delFlag" column="del_flag" />
  16. <result property="customerName" column="customer_name" />
  17. </resultMap>
  18. <sql id="selectCustomerLabelVo">
  19. select id, phone, label_id, station_id, create_by, create_time, update_by, update_time, del_flag from customer_label
  20. </sql>
  21. <select id="selectCustomerLabelList" parameterType="CustomerLabel" resultMap="CustomerLabelResult">
  22. <include refid="selectCustomerLabelVo"/>
  23. <where>
  24. <if test="phone != null and phone != ''"> and phone like concat('%', #{phone}, '%')</if>
  25. <if test="labelId != null "> and label_id = #{labelId}</if>
  26. <if test="stationId != null "> and station_id = #{stationId}</if>
  27. <if test="delFlag != null "> and del_flag = #{delFlag}</if>
  28. </where>
  29. </select>
  30. <select id="selectNotCustomerLabelInfo" parameterType="CustomerLabel" resultMap="CustomerLabelResult">
  31. SELECT * FROM(
  32. SELECT DISTINCT ( m.phone_number ) AS phone,customer_name,pay_date
  33. FROM customer_manage m
  34. LEFT JOIN app_user_info a ON m.mina_user_id = a.user_id
  35. LEFT JOIN ( SELECT max( pay_date ) AS pay_date, po.consumer_id FROM pay_order po
  36. <where>
  37. <if test="stationId != null "> and po.station_id = #{stationId}</if>
  38. </where>
  39. GROUP BY consumer_id ) c ON c.consumer_id = a.user_id
  40. <where>
  41. <if test="stationId != null "> and m.station_id = #{stationId}</if>
  42. <if test="phone != null and phone != ''"> and m.phone_number like concat('%', #{phone}, '%')</if>
  43. <if test="customerName != null and customerName != ''"> and m.customer_name like concat('%', #{customerName}, '%')</if>
  44. </where>
  45. AND m.phone_number NOT IN ( SELECT phone FROM customer_label b
  46. <where>
  47. <if test="stationId != null "> and b.station_id = #{stationId}</if>
  48. <if test="delFlag != null "> and del_flag = #{delFlag}</if>
  49. <if test="phone != null and phone != ''"> and b.phone like concat('%', #{phone}, '%')</if>
  50. </where>
  51. )) po
  52. ORDER BY po.pay_date DESC
  53. </select>
  54. <select id="selectPhonelist" parameterType="CustomerLabel" resultMap="CustomerLabelResult">
  55. SELECT DISTINCT phone,label_id,c.station_id,m.customer_name from customer_label c
  56. left join customer_manage m on c.phone = m.phone_number and c.station_id = m.station_id
  57. <where>
  58. <if test="stationId != null "> and c.station_id = #{stationId}</if>
  59. <if test="labelId != null "> and label_id = #{labelId}</if>
  60. <if test="delFlag != null "> and del_flag = #{delFlag}</if>
  61. <if test="phone != null and phone != ''"> and c.phone like concat('%', #{phone}, '%')</if>
  62. <if test="customerName != null and customerName != ''"> and m.customer_name like concat('%', #{customerName}, '%')</if>
  63. </where>
  64. </select>
  65. <select id="selectCustomerLabelById" parameterType="Integer" resultMap="CustomerLabelResult">
  66. <include refid="selectCustomerLabelVo"/>
  67. where id = #{id}
  68. </select>
  69. <select id="selectCustomerLabelInfo" parameterType="CustomerLabel" resultMap="CustomerLabelResult">
  70. <include refid="selectCustomerLabelVo"/>
  71. <where>
  72. <if test="phone != null and phone != ''"> and phone = #{phone}</if>
  73. <if test="labelId != null "> and label_id = #{labelId}</if>
  74. <if test="stationId != null "> and station_id = #{stationId}</if>
  75. <if test="delFlag != null "> and del_flag = #{delFlag}</if>
  76. </where>
  77. limit 1
  78. </select>
  79. <insert id="insertCustomerLabel" parameterType="CustomerLabel" useGeneratedKeys="true" keyProperty="id">
  80. insert into customer_label
  81. <trim prefix="(" suffix=")" suffixOverrides=",">
  82. <if test="phone != null">phone,</if>
  83. <if test="labelId != null">label_id,</if>
  84. <if test="stationId != null">station_id,</if>
  85. <if test="createBy != null">create_by,</if>
  86. <if test="createTime != null">create_time,</if>
  87. <if test="updateBy != null">update_by,</if>
  88. <if test="updateTime != null">update_time,</if>
  89. <if test="delFlag != null">del_flag,</if>
  90. </trim>
  91. <trim prefix="values (" suffix=")" suffixOverrides=",">
  92. <if test="phone != null">#{phone},</if>
  93. <if test="labelId != null">#{labelId},</if>
  94. <if test="stationId != null">#{stationId},</if>
  95. <if test="createBy != null">#{createBy},</if>
  96. <if test="createTime != null">#{createTime},</if>
  97. <if test="updateBy != null">#{updateBy},</if>
  98. <if test="updateTime != null">#{updateTime},</if>
  99. <if test="delFlag != null">#{delFlag},</if>
  100. </trim>
  101. </insert>
  102. <update id="updateCustomerLabel" parameterType="CustomerLabel">
  103. update customer_label
  104. <trim prefix="SET" suffixOverrides=",">
  105. <if test="phone != null">phone = #{phone},</if>
  106. <if test="labelId != null">label_id = #{labelId},</if>
  107. <if test="stationId != null">station_id = #{stationId},</if>
  108. <if test="createBy != null">create_by = #{createBy},</if>
  109. <if test="createTime != null">create_time = #{createTime},</if>
  110. <if test="updateBy != null">update_by = #{updateBy},</if>
  111. <if test="updateTime != null">update_time = #{updateTime},</if>
  112. <if test="delFlag != null">del_flag = #{delFlag},</if>
  113. </trim>
  114. where id = #{id}
  115. </update>
  116. <delete id="deleteCustomerLabelById" parameterType="Integer">
  117. delete from customer_label where id = #{id}
  118. </delete>
  119. <delete id="deleteCustomerLabelByIds" parameterType="String">
  120. delete from customer_label where id in
  121. <foreach item="id" collection="array" open="(" separator="," close=")">
  122. #{id}
  123. </foreach>
  124. </delete>
  125. </mapper>