Przeglądaj źródła

客户信息查询优化

zangguocen 4 lat temu
rodzic
commit
4ba4757fc3

+ 25 - 2
yijia-customer/src/main/java/com/yijia/customer/controller/CustomerManageController.java

@@ -1,8 +1,15 @@
 package com.yijia.customer.controller;
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
+import com.yijia.common.constant.HttpStatus;
 import com.yijia.common.core.domain.entity.SysDept;
 import com.yijia.common.core.domain.model.LoginUser;
+import com.yijia.common.core.page.PageDomain;
+import com.yijia.common.core.page.TableSupport;
 import com.yijia.common.utils.SecurityUtils;
+import com.yijia.common.utils.StringUtils;
 import com.yijia.common.utils.poi.ExcelUtil;
+import com.yijia.common.utils.sql.SqlUtil;
 import com.yijia.customer.domain.CustomerManage;
 import com.yijia.customer.service.ICustomerManageService;
 import com.yijia.system.service.ISysDeptService;
@@ -53,9 +60,25 @@ public class CustomerManageController extends BaseController
             customerManage.setStationIdList(list);
             customerManage.setStationId(null);
         }
-        startPage();
+        PageDomain pageDomain = TableSupport.buildPageRequest();
+        Integer pageNum = pageDomain.getPageNum();
+        Integer pageSize = pageDomain.getPageSize();
+        if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize))
+        {
+           if(pageNum>0){
+               pageNum =(pageNum-1)*pageSize;
+           }
+            customerManage.setPageNumLimit(pageNum);
+            customerManage.setPageSizeLimit(pageSize);
+        }
         List<CustomerManage> customerManageList = customerManageService.selectCustomerManage(customerManage);
-        return getDataTable(customerManageList);
+        List<CustomerManage> pagelist = customerManageService.selectCustomerManagePage(customerManage);
+        TableDataInfo rspData = new TableDataInfo();
+        rspData.setCode(HttpStatus.SUCCESS);
+        rspData.setMsg("查询成功");
+        rspData.setRows(customerManageList);
+        rspData.setTotal(pagelist.size());
+        return rspData;
     }
 
     /**

+ 15 - 8
yijia-customer/src/main/java/com/yijia/customer/mapper/CustomerManageMapper.java

@@ -7,15 +7,15 @@ import com.yijia.customer.domain.CustomerManage;
 
 /**
  * 客户管理Mapper接口
- * 
+ *
  * @author yijia
  * @date 2020-12-21
  */
-public interface CustomerManageMapper 
+public interface CustomerManageMapper
 {
     /**
      * 查询客户管理
-     * 
+     *
      * @param id 客户管理ID
      * @return 客户管理
      */
@@ -23,7 +23,7 @@ public interface CustomerManageMapper
 
     /**
      * 查询客户管理列表
-     * 
+     *
      * @param customerManage 客户管理
      * @return 客户管理集合
      */
@@ -31,7 +31,7 @@ public interface CustomerManageMapper
 
     /**
      * 新增客户管理
-     * 
+     *
      * @param customerManage 客户管理
      * @return 结果
      */
@@ -39,7 +39,7 @@ public interface CustomerManageMapper
 
     /**
      * 修改客户管理
-     * 
+     *
      * @param customerManage 客户管理
      * @return 结果
      */
@@ -47,7 +47,7 @@ public interface CustomerManageMapper
 
     /**
      * 删除客户管理
-     * 
+     *
      * @param id 客户管理ID
      * @return 结果
      */
@@ -55,7 +55,7 @@ public interface CustomerManageMapper
 
     /**
      * 批量删除客户管理
-     * 
+     *
      * @param ids 需要删除的数据ID
      * @return 结果
      */
@@ -67,4 +67,11 @@ public interface CustomerManageMapper
      * @return
      */
     public List<CustomerManage> selectCustomerManage(CustomerManage customerManage);
+
+    /**
+     * 查询客户信息分页
+     * @param customerManage
+     * @return
+     */
+    public List<CustomerManage> selectCustomerManagePage(CustomerManage customerManage);
 }

+ 15 - 8
yijia-customer/src/main/java/com/yijia/customer/service/ICustomerManageService.java

@@ -7,15 +7,15 @@ import com.yijia.customer.domain.CustomerManage;
 
 /**
  * 客户管理Service接口
- * 
+ *
  * @author yijia
  * @date 2020-12-21
  */
-public interface ICustomerManageService 
+public interface ICustomerManageService
 {
     /**
      * 查询客户管理
-     * 
+     *
      * @param id 客户管理ID
      * @return 客户管理
      */
@@ -23,7 +23,7 @@ public interface ICustomerManageService
 
     /**
      * 查询客户管理列表
-     * 
+     *
      * @param customerManage 客户管理
      * @return 客户管理集合
      */
@@ -31,7 +31,7 @@ public interface ICustomerManageService
 
     /**
      * 新增客户管理
-     * 
+     *
      * @param customerManage 客户管理
      * @return 结果
      */
@@ -39,7 +39,7 @@ public interface ICustomerManageService
 
     /**
      * 修改客户管理
-     * 
+     *
      * @param customerManage 客户管理
      * @return 结果
      */
@@ -47,7 +47,7 @@ public interface ICustomerManageService
 
     /**
      * 批量删除客户管理
-     * 
+     *
      * @param ids 需要删除的客户管理ID
      * @return 结果
      */
@@ -55,7 +55,7 @@ public interface ICustomerManageService
 
     /**
      * 删除客户管理信息
-     * 
+     *
      * @param id 客户管理ID
      * @return 结果
      */
@@ -67,4 +67,11 @@ public interface ICustomerManageService
      * @return 客户管理
      */
     public List<CustomerManage> selectCustomerManage(CustomerManage customerManage);
+
+    /**
+     * 查询分页
+     * @param customerManage
+     * @return
+     */
+    public List<CustomerManage> selectCustomerManagePage(CustomerManage customerManage);
 }

+ 5 - 0
yijia-customer/src/main/java/com/yijia/customer/service/impl/CustomerManageServiceImpl.java

@@ -136,4 +136,9 @@ public class CustomerManageServiceImpl implements ICustomerManageService
 
         return customerManageMapper.selectCustomerManage(customerManage);
     }
+
+    @Override
+    public List<CustomerManage> selectCustomerManagePage(CustomerManage customerManage) {
+        return customerManageMapper.selectCustomerManagePage(customerManage);
+    }
 }

+ 58 - 22
yijia-customer/src/main/resources/mapper/customer/CustomerManageMapper.xml

@@ -152,33 +152,44 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </delete>
 
     <select id="selectCustomerManage" parameterType="CustomerManage" resultMap="CustomerManageResult">
-        SELECT a.union_id,a.customer_name,a.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,p.points AS integral,d.dept_name as station_name
-        FROM
-        (SELECT member_id,customer_name,phone_number,car_number, mina_user_id,station_id,
+        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
-        FROM customer_manage
+        FROM (
+        SELECT max( created_date ) created_date, po.consumer_id FROM pay_order po
         <where>
             <if test="stationIdList != null ">
-                and station_id in
+                and po.station_id in
                 <foreach item="item" index="index" collection="stationIdList"
                          open="(" separator="," close=")">
                     #{item}
                 </foreach>
             </if>
             <if test="stationId != null ">
-                and station_id  = #{stationId}
+                and po.station_id  = #{stationId}
+            </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="carNumber != null  and carNumber != ''"> and car_number like concat('%', #{carNumber}, '%')</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="phoneNumber != null  and phoneNumber != ''"> and phone_number like concat('%', #{phoneNumber}, '%')</if>
-            <if test="customerName != null  and customerName != ''"> and customer_name  like concat('%', #{customerName}, '%')</if>
         </where>
         GROUP BY member_id,customer_name, phone_number,car_number,  mina_user_id, station_id, union_id
-        ) b LEFT JOIN
-        (SELECT   union_id,  customer_name, station_id,
+         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,
@@ -199,11 +210,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         </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 p ON b.union_id = p.union_id
-        AND b.station_id = p.station_id
-        LEFT JOIN sys_dept d ON b.station_id = d.dept_id
-        LEFT JOIN (
-        SELECT max( pay_date ) pay_date, po.consumer_id FROM pay_order po
+        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
+    </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
@@ -215,8 +237,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="stationId != null ">
                 and po.station_id  = #{stationId}
             </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>
         </where>
-        GROUP BY po.consumer_id ) px ON b.mina_user_id = px.consumer_id
-        ORDER BY   px.pay_date DESC
+        GROUP BY customer_name, mina_user_id, phone_number, member_id
     </select>
 </mapper>