123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282 |
- <?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.yijia.customer.mapper.CustomerManageMapper">
- <resultMap type="CustomerManage" id="CustomerManageResult">
- <result property="id" column="id" />
- <result property="memberId" column="member_id" />
- <result property="customerName" column="customer_name" />
- <result property="commendMan" column="commend_man" />
- <result property="phoneNumber" column="phone_number" />
- <result property="carNumber" column="car_number" />
- <result property="balance" column="balance" />
- <result property="integral" column="integral" />
- <result property="specialCarType" column="special_car_type" />
- <result property="regtime" column="regtime" />
- <result property="stationId" column="station_id" />
- <result property="stationName" column="station_name" />
- <result property="cyAmt" column="cy_amt" />
- <result property="qyAmt" column="qy_amt" />
- <result property="minaUserId" column="mina_user_id" />
- <result property="oilName" column="oil_name" />
- <result property="grade" column="grade" />
- <result property="liters" column="liters" />
- <result property="amt" column="amt" />
- <result property="unionId" column="union_id" />
- <result property="payDate" column="pay_date" />
- <result property="fyAmt" column="fy_amt" />
- <result property="lngAmt" column="lng_amt" />
- <result property="cngAmt" column="cng_amt" />
- </resultMap>
- <sql id="selectCustomerManageVo">
- select m.id, m.member_id, m.customer_name, m.commend_man, m.phone_number, m.car_number, m.balance,
- m.integral, m.special_car_type, m.regtime, m.station_id, m.mina_user_id, m.oil_name, m.grade,
- m.liters, m.amt, m.union_id ,d.dept_name as station_name
- from customer_manage m join sys_dept d on m.station_id = d.dept_id
- </sql>
- <select id="selectCustomerManageList" parameterType="CustomerManage" resultMap="CustomerManageResult">
- <include refid="selectCustomerManageVo"/>
- <where>
- <if test="memberId != null and memberId != ''"> and member_id = #{memberId}</if>
- <if test="customerName != null and customerName != ''"> and customer_name like concat('%', #{customerName}, '%')</if>
- <if test="commendMan != null and commendMan != ''"> and commend_man = #{commendMan}</if>
- <if test="phoneNumber != null and phoneNumber != ''"> and phone_number like concat('%', #{phoneNumber}, '%')</if>
- <if test="carNumber != null and carNumber != ''"> and car_number = #{carNumber}</if>
- <if test="balance != null "> and m.balance = #{balance}</if>
- <if test="integral != null "> and integral = #{integral}</if>
- <if test="specialCarType != null and specialCarType != ''"> and special_car_type = #{specialCarType}</if>
- <if test="regtime != null "> and regtime = #{regtime}</if>
- <if test="stationId != null "> and station_id = #{stationId}</if>
- <if test="minaUserId != null "> and mina_user_id = #{minaUserId}</if>
- <if test="oilName != null and oilName != ''"> and oil_name like concat('%', #{oilName}, '%')</if>
- <if test="grade != null and grade != ''"> and grade like concat('%', #{grade},'%')</if>
- <if test="liters != null "> and liters = #{liters}</if>
- <if test="amt != null "> and amt = #{amt}</if>
- <if test="unionId != null and unionId != ''"> and union_id = #{unionId}</if>
- <if test="stationIdList != null ">
- and station_id in
- <foreach item="item" index="index" collection="stationIdList"
- open="(" separator="," close=")">
- #{item}
- </foreach>
- </if>
- <if test="stationId != null ">
- and station_id = #{stationId}
- </if>
- </where>
- order by id desc
- </select>
- <select id="selectCustomerManageById" parameterType="Long" resultMap="CustomerManageResult">
- <include refid="selectCustomerManageVo"/>
- where id = #{id}
- </select>
- <insert id="insertCustomerManage" parameterType="CustomerManage" useGeneratedKeys="true" keyProperty="id">
- insert into customer_manage
- <trim prefix="(" suffix=")" suffixOverrides=",">
- <if test="memberId != null">member_id,</if>
- <if test="customerName != null">customer_name,</if>
- <if test="commendMan != null">commend_man,</if>
- <if test="phoneNumber != null">phone_number,</if>
- <if test="carNumber != null">car_number,</if>
- <if test="balance != null">balance,</if>
- <if test="integral != null">integral,</if>
- <if test="specialCarType != null">special_car_type,</if>
- <if test="regtime != null">regtime,</if>
- <if test="stationId != null">station_id,</if>
- <if test="minaUserId != null">mina_user_id,</if>
- <if test="oilName != null">oil_name,</if>
- <if test="grade != null">grade,</if>
- <if test="liters != null">liters,</if>
- <if test="amt != null">amt,</if>
- <if test="unionId != null">union_id,</if>
- </trim>
- <trim prefix="values (" suffix=")" suffixOverrides=",">
- <if test="memberId != null">#{memberId},</if>
- <if test="customerName != null">#{customerName},</if>
- <if test="commendMan != null">#{commendMan},</if>
- <if test="phoneNumber != null">#{phoneNumber},</if>
- <if test="carNumber != null">#{carNumber},</if>
- <if test="balance != null">#{balance},</if>
- <if test="integral != null">#{integral},</if>
- <if test="specialCarType != null">#{specialCarType},</if>
- <if test="regtime != null">#{regtime},</if>
- <if test="stationId != null">#{stationId},</if>
- <if test="blogUserId != null">#{blogUserId},</if>
- <if test="minaUserId != null">#{minaUserId},</if>
- <if test="oilName != null">#{oilName},</if>
- <if test="grade != null">#{grade},</if>
- <if test="liters != null">#{liters},</if>
- <if test="amt != null">#{amt},</if>
- <if test="unionId != null">#{unionId},</if>
- </trim>
- </insert>
- <update id="updateCustomerManage" parameterType="CustomerManage">
- update customer_manage
- <trim prefix="SET" suffixOverrides=",">
- <if test="memberId != null">member_id = #{memberId},</if>
- <if test="customerName != null">customer_name = #{customerName},</if>
- <if test="commendMan != null">commend_man = #{commendMan},</if>
- <if test="phoneNumber != null">phone_number = #{phoneNumber},</if>
- <if test="carNumber != null">car_number = #{carNumber},</if>
- <if test="balance != null">balance = #{balance},</if>
- <if test="integral != null">integral = #{integral},</if>
- <if test="specialCarType != null">special_car_type = #{specialCarType},</if>
- <if test="regtime != null">regtime = #{regtime},</if>
- <if test="stationId != null">station_id = #{stationId},</if>
- <if test="minaUserId != null">mina_user_id = #{minaUserId},</if>
- <if test="oilName != null">oil_name = #{oilName},</if>
- <if test="grade != null">grade = #{grade},</if>
- <if test="liters != null">liters = #{liters},</if>
- <if test="amt != null">amt = #{amt},</if>
- <if test="unionId != null">union_id = #{unionId},</if>
- </trim>
- where id = #{id}
- </update>
- <delete id="deleteCustomerManageById" parameterType="Long">
- delete from customer_manage where id = #{id}
- </delete>
- <delete id="deleteCustomerManageByIds" parameterType="String">
- delete from customer_manage where id in
- <foreach item="id" collection="array" open="(" separator="," close=")">
- #{id}
- </foreach>
- </delete>
- <select id="selectCustomerManage" parameterType="CustomerManage" resultMap="CustomerManageResult">
- SELECT b.union_id,b.station_id,a.qy_amt,a.cy_amt,a.fy_amt,a.lng_amt, a.cng_amt,b.member_id, b.customer_name,
- b.phone_number, b.car_number,b.mina_user_id,b.oil_name,b.grade,c.points AS integral,d.dept_name as station_name
- from (SELECT member_id,customer_name,phone_number,car_number, mina_user_id,station_id,
- union_id,GROUP_CONCAT(DISTINCT ( oil_name )) oil_name,GROUP_CONCAT(DISTINCT ( grade )) AS grade,created_date
- FROM (
- SELECT max( created_date ) created_date, po.consumer_id FROM pay_order po
- <where>
- <if test="stationIdList != null ">
- and po.station_id in
- <foreach item="item" index="index" collection="stationIdList"
- open="(" separator="," close=")">
- #{item}
- </foreach>
- </if>
- <if test="stationId != null ">
- and po.station_id = #{stationId}
- </if>
- <if test="oilName != null and oilName != ''"> and po.oil_name like concat('%', #{oilName}, '%')</if>
- and status ="1"
- </where>
- GROUP BY po.consumer_id order by created_date desc ) p
- INNER JOIN customer_manage m ON m.mina_user_id = p.consumer_id
- <where>
- <if test="stationIdList != null ">
- and m.station_id in
- <foreach item="item" index="index" collection="stationIdList"
- open="(" separator="," close=")">
- #{item}
- </foreach>
- </if>
- <if test="stationId != null ">
- and m.station_id = #{stationId}
- </if>
- <if test="customerName != null and customerName != ''">
- and m.customer_name like concat('%', #{customerName}, '%')
- </if>
- <if test="commendMan != null and commendMan != ''">
- and m.commend_man = #{commendMan}
- </if>
- <if test="phoneNumber != null and phoneNumber != ''">
- and m.phone_number like concat('%', #{phoneNumber}, '%')
- </if>
- <if test="oilName != null and oilName != ''"> and m.oil_name like concat('%', #{oilName}, '%')</if>
- </where>
- GROUP BY member_id,customer_name, phone_number,car_number, mina_user_id, station_id, union_id,created_date
- order by max( created_date ) desc
- limit #{pageNumLimit},#{pageSizeLimit}
- ) b
- LEFT JOIN
- (SELECT union_id, customer_name, station_id,
- sum( CASE card_oils_type WHEN '1' THEN amt ELSE 0 END ) qy_amt,
- sum( CASE card_oils_type WHEN '2' THEN amt ELSE 0 END ) cy_amt,
- sum( CASE card_oils_type WHEN '3' THEN amt ELSE 0 END ) fy_amt,
- sum( CASE card_oils_type WHEN '4' THEN amt ELSE 0 END ) lng_amt,
- sum( CASE card_oils_type WHEN '5' THEN amt ELSE 0 END ) cng_amt
- FROM customer_electronic_card
- <where>
- <if test="stationIdList != null ">
- and station_id in
- <foreach item="item" index="index" collection="stationIdList"
- open="(" separator="," close=")">
- #{item}
- </foreach>
- </if>
- <if test="stationId != null ">
- and station_id = #{stationId}
- </if>
- </where>
- GROUP BY union_id, customer_name, station_id) a
- ON a.union_id = b.union_id AND a.station_id = b.station_id
- LEFT JOIN customer_points c ON b.union_id = c.union_id AND b.station_id = c.station_id
- <if test="stationIdList != null ">
- and c.station_id in
- <foreach item="item" index="index" collection="stationIdList"
- open="(" separator="," close=")">
- #{item}
- </foreach>
- </if>
- <if test="stationId != null ">
- and c.station_id = #{stationId}
- </if>
- LEFT JOIN sys_dept d ON b.station_id = d.dept_id
- ORDER BY created_date desc
- </select>
- <select id="selectCustomerManagePage" parameterType="CustomerManage" resultMap="CustomerManageResult">
- SELECT customer_name,mina_user_id
- FROM (SELECT max( created_date ) created_date, po.consumer_id FROM pay_order po
- <where>
- <if test="stationIdList != null ">
- and po.station_id in
- <foreach item="item" index="index" collection="stationIdList"
- open="(" separator="," close=")">
- #{item}
- </foreach>
- </if>
- <if test="stationId != null ">
- and po.station_id = #{stationId}
- </if>
- <if test="oilName != null and oilName != ''"> and po.oil_name like concat('%', #{oilName}, '%')</if>
- and status ="1"
- </where>
- GROUP BY po.consumer_id order by created_date desc ) p
- INNER JOIN customer_manage m ON m.mina_user_id = p.consumer_id
- <where>
- <if test="stationIdList != null ">
- and m.station_id in
- <foreach item="item" index="index" collection="stationIdList"
- open="(" separator="," close=")">
- #{item}
- </foreach>
- </if>
- <if test="stationId != null ">
- and m.station_id = #{stationId}
- </if>
- <if test="customerName != null and customerName != ''">
- and m.customer_name like concat('%', #{customerName}, '%')
- </if>
- <if test="commendMan != null and commendMan != ''">
- and m.commend_man = #{commendMan}
- </if>
- <if test="phoneNumber != null and phoneNumber != ''">
- and m.phone_number like concat('%', #{phoneNumber}, '%')
- </if>
- <if test="oilName != null and oilName != ''"> and m.oil_name like concat('%', #{oilName}, '%')</if>
- </where>
- GROUP BY customer_name, mina_user_id, phone_number, member_id
- </select>
- </mapper>
|