客户库存盘点明细
This commit is contained in:
		
							parent
							
								
									5f171c3112
								
							
						
					
					
						commit
						fc7e6b2b5e
					
				|  | @ -90,6 +90,7 @@ public class StockExcel { | |||
|     @ApiOperation(value = "导出客户库存盘点明细") | ||||
|     @GetMapping(value = "/exportClientStockReport") | ||||
|     public void exportClientStockReport( | ||||
|             @ApiParam(required = true, value = "客户是否盘点过 1.是 0.否") @RequestParam(required = true) String existFlag, | ||||
|             @ApiParam(required = true, value = "开始日期") @RequestParam(required = true) String startDate, | ||||
|             @ApiParam(required = true, value = "结束日期") @RequestParam(required = true) String endDate, | ||||
|             @ApiParam(required = false, value = "客户id") @RequestParam(required = false) String clientId, | ||||
|  | @ -113,7 +114,11 @@ public class StockExcel { | |||
|         params.put("uecode", uecode); | ||||
|         params.put("clientName", clientName); | ||||
|         params.put("staffName", staffName); | ||||
|         List list = clientStockReportService.findList(params, ".getClientStockReportSql"); | ||||
|         String sqlId = ".getClientStockReportSql"; | ||||
|         if ("0".equals(existFlag)) { | ||||
|             sqlId = ".getNoClientStockSql"; | ||||
|         } | ||||
|         List list = clientStockReportService.findList(params, sqlId); | ||||
|         EasyPoiUtils.exportExcel(list, ClientStockReport.class, "客户库存盘点明细导出", response); | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
|  | @ -132,6 +132,7 @@ public class StockReportController extends BaseController { | |||
|     @ApiOperation("客户库存盘点明细") | ||||
|     @PostMapping(value = "/getClientStockReport") | ||||
|     public Map<String, Object> getClientStockReport( | ||||
|             @ApiParam(required = true, value = "客户是否盘点过 1.是 0.否") @RequestParam(required = true) String existFlag, | ||||
|             @ApiParam(required = true, value = "开始日期") @RequestParam(required = true) String startDate, | ||||
|             @ApiParam(required = true, value = "结束日期") @RequestParam(required = true) String endDate, | ||||
|             @ApiParam(required = false, value = "客户id") @RequestParam(required = false) String clientId, | ||||
|  | @ -160,7 +161,11 @@ public class StockReportController extends BaseController { | |||
|         params.put("staffName", staffName); | ||||
|         params.put("page", pageNum); | ||||
|         params.put("pageSize", pageSize); | ||||
|         return toPage(clientStockReportService.pageList(params, ".getClientStockReportSql")); | ||||
|         String sqlId = ".getClientStockReportSql"; | ||||
|         if ("0".equals(existFlag)) { | ||||
|             sqlId = ".getNoClientStockSql"; | ||||
|         } | ||||
|         return toPage(clientStockReportService.pageList(params, sqlId)); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|  |  | |||
|  | @ -26,82 +26,8 @@ | |||
|             TO_CHAR(TO_DATE(SUBSTR(#{endDate},1,10),'yyyy-MM-dd'),'yyyy-MM-dd') | ||||
|         </if> | ||||
|     </sql> | ||||
| 
 | ||||
|     <!-- 客户库存盘点明细 --> | ||||
|     <select id="getClientStockReportSql" resultType="com.yb.lb.webapp.stock.entity.ClientStockReport" parameterType="map"> | ||||
|         SELECT | ||||
|         t0.id "clientId", | ||||
|         t0.uecode "uecode", | ||||
|         t0.distributor_name "clientName", | ||||
|         csui.name "staffName", | ||||
|         cmai.area_name "areaName", | ||||
|         NVL(t1.bill_date, '---') "billDate", | ||||
|         NVL(t1.count_num, 0) "countNum", | ||||
|         NVL(t1.goods_num, 0) "goodsNum", | ||||
|         NVL(t2.bill_num, 0) "billNum" | ||||
|         FROM (        SELECT | ||||
|         cdui.id, | ||||
|         cdui.uecode, | ||||
|         cdui.distributor_name, | ||||
|         cdui.ancestors, | ||||
|         cdui.marketing_area_id, | ||||
|         cdui.region, | ||||
|         cdui.service_id, | ||||
|         cdui.company_id | ||||
|         FROM ( | ||||
|         SELECT client_id | ||||
|         FROM crm_inventory_info | ||||
|         WHERE confirm_status = '1' AND company_id = #{companyId} | ||||
|         <include refid="dateSel" /> | ||||
|         GROUP BY client_id | ||||
|         ) table_client | ||||
|         LEFT JOIN crm_distributor_user_info cdui ON table_client.client_id = cdui.id | ||||
|         WHERE cdui.status = '1' AND cdui.documents_status = '1' | ||||
|         AND cdui.uecode IS NOT NULL AND cdui.company_id = #{companyId} | ||||
|         ) t0 | ||||
|         LEFT JOIN ( | ||||
|         SELECT * | ||||
|         FROM ( | ||||
|         SELECT tt1.*, | ||||
|         ROW_NUMBER() OVER ( PARTITION BY tt1.client_id ORDER BY tt1.bill_date DESC, tt1.create_time DESC ) AS rn | ||||
|         FROM ( | ||||
|         SELECT a.bill_no, | ||||
|         a.bill_date, | ||||
|         a.client_id, | ||||
|         a.create_time, | ||||
|         b.count_num, | ||||
|         b.goods_num | ||||
|         FROM crm_inventory_info a | ||||
|         LEFT JOIN client_pd_num_view b ON a.id = b.bill_id | ||||
|         WHERE a.confirm_status = '1' AND a.company_id = #{companyId} | ||||
|         <include refid="dateSel_a" /> | ||||
|         ) tt1 | ||||
|         ) temp | ||||
|         WHERE rn = 1 | ||||
|         ) t1 ON t0.id = t1.client_id | ||||
|         LEFT JOIN (SELECT client_id, COUNT(1) bill_num | ||||
|         FROM crm_inventory_info | ||||
|         WHERE confirm_status = '1' AND company_id = #{companyId} | ||||
|         <include refid="dateSel" /> | ||||
|         GROUP BY client_id) t2 ON t0.id = t2.client_id | ||||
|         LEFT JOIN crm_servicer_user_info csui ON t0.service_id = csui.id | ||||
|         LEFT JOIN crm_marketing_area_info cmai ON t0.marketing_area_id = cmai.id | ||||
|         WHERE 1=1 | ||||
|         <if test="clientId !=null and clientId !=''"> | ||||
|             AND t0.id = #{clientId} | ||||
|         </if> | ||||
|         <if test="uecode !=null and uecode !=''"> | ||||
|             AND t0.uecode LIKE '%' || #{uecode} || '%' | ||||
|         </if> | ||||
|         <if test="clientName !=null and clientName !=''"> | ||||
|             AND t0.distributor_name  LIKE '%' || #{clientName} || '%' | ||||
|         </if> | ||||
|         <if test="staffName !=null and staffName !=''"> | ||||
|             AND csui.name LIKE '%' || #{staffName} || '%' | ||||
|         </if> | ||||
|         <if test="areaName !=null and areaName !=''"> | ||||
|             AND cmai.area_name LIKE '%' || #{areaName} || '%' | ||||
|         </if> | ||||
|     <!-- 数据权限查询条件 --> | ||||
|     <sql id="dataScopeSql"> | ||||
|         <if test="flag !=null and flag !=''"> | ||||
|             <!-- 前端传营销区域 --> | ||||
|             <if test="flag == 1"> | ||||
|  | @ -187,6 +113,128 @@ | |||
|             t0.service_id LIKE '%' || #{userId} || '%' | ||||
|             ) | ||||
|         </if> | ||||
|     </sql> | ||||
| 
 | ||||
|     <!-- 客户库存盘点明细 --> | ||||
|     <select id="getClientStockReportSql" resultType="com.yb.lb.webapp.stock.entity.ClientStockReport" parameterType="map"> | ||||
|         SELECT | ||||
|         t0.id "clientId", | ||||
|         t0.uecode "uecode", | ||||
|         t0.distributor_name "clientName", | ||||
|         csui.name "staffName", | ||||
|         cmai.area_name "areaName", | ||||
|         NVL(t1.bill_date, '---') "billDate", | ||||
|         NVL(t1.count_num, 0) "countNum", | ||||
|         NVL(t1.goods_num, 0) "goodsNum", | ||||
|         NVL(t2.bill_num, 0) "billNum" | ||||
|         FROM (        SELECT | ||||
|         cdui.id, | ||||
|         cdui.uecode, | ||||
|         cdui.distributor_name, | ||||
|         cdui.ancestors, | ||||
|         cdui.marketing_area_id, | ||||
|         cdui.region, | ||||
|         cdui.service_id, | ||||
|         cdui.company_id | ||||
|         FROM ( | ||||
|         SELECT client_id | ||||
|         FROM crm_inventory_info | ||||
|         WHERE confirm_status = '1' AND company_id = #{companyId} | ||||
|         <include refid="dateSel" /> | ||||
|         GROUP BY client_id | ||||
|         ) table_client | ||||
|         LEFT JOIN crm_distributor_user_info cdui ON table_client.client_id = cdui.id | ||||
|         WHERE cdui.status = '1' AND cdui.documents_status = '1' | ||||
|         AND cdui.uecode IS NOT NULL AND cdui.company_id = #{companyId} | ||||
|         ) t0 | ||||
|         LEFT JOIN ( | ||||
|         SELECT * | ||||
|         FROM ( | ||||
|         SELECT tt1.*, | ||||
|         ROW_NUMBER() OVER ( PARTITION BY tt1.client_id ORDER BY tt1.bill_date DESC, tt1.create_time DESC ) AS rn | ||||
|         FROM ( | ||||
|         SELECT a.bill_no, | ||||
|         a.bill_date, | ||||
|         a.client_id, | ||||
|         a.create_time, | ||||
|         b.count_num, | ||||
|         b.goods_num | ||||
|         FROM crm_inventory_info a | ||||
|         LEFT JOIN client_pd_num_view b ON a.id = b.bill_id | ||||
|         WHERE a.confirm_status = '1' AND a.company_id = #{companyId} | ||||
|         <include refid="dateSel_a" /> | ||||
|         ) tt1 | ||||
|         ) temp | ||||
|         WHERE rn = 1 | ||||
|         ) t1 ON t0.id = t1.client_id | ||||
|         LEFT JOIN (SELECT client_id, COUNT(1) bill_num | ||||
|         FROM crm_inventory_info | ||||
|         WHERE confirm_status = '1' AND company_id = #{companyId} | ||||
|         <include refid="dateSel" /> | ||||
|         GROUP BY client_id) t2 ON t0.id = t2.client_id | ||||
|         LEFT JOIN crm_servicer_user_info csui ON t0.service_id = csui.id | ||||
|         LEFT JOIN crm_marketing_area_info cmai ON t0.marketing_area_id = cmai.id | ||||
|         WHERE 1=1 | ||||
|         <if test="clientId !=null and clientId !=''"> | ||||
|             AND t0.id = #{clientId} | ||||
|         </if> | ||||
|         <if test="uecode !=null and uecode !=''"> | ||||
|             AND t0.uecode LIKE '%' || #{uecode} || '%' | ||||
|         </if> | ||||
|         <if test="clientName !=null and clientName !=''"> | ||||
|             AND t0.distributor_name  LIKE '%' || #{clientName} || '%' | ||||
|         </if> | ||||
|         <if test="staffName !=null and staffName !=''"> | ||||
|             AND csui.name LIKE '%' || #{staffName} || '%' | ||||
|         </if> | ||||
|         <if test="areaName !=null and areaName !=''"> | ||||
|             AND cmai.area_name LIKE '%' || #{areaName} || '%' | ||||
|         </if> | ||||
|         <include refid="dataScopeSql" /> | ||||
|     </select> | ||||
| 
 | ||||
|     <!-- 根据条件查询没有盘点过的客户 --> | ||||
|     <select id="getNoClientStockSql" resultType="com.yb.lb.webapp.stock.entity.ClientStockReport" parameterType="map"> | ||||
|         SELECT t0.id "clientId", | ||||
|         t0.uecode "uecode", | ||||
|         t0.distributor_name "clientName", | ||||
|         csui.name "staffName", | ||||
|         cmai.area_name "areaName", | ||||
|         '---' "billDate", | ||||
|         0 "countNum", | ||||
|         0 "goodsNum", | ||||
|         0 "billNum" | ||||
|         FROM crm_distributor_user_info t0 | ||||
|         LEFT JOIN crm_servicer_user_info csui ON t0.service_id = csui.id | ||||
|         LEFT JOIN crm_marketing_area_info cmai ON t0.marketing_area_id = cmai.id | ||||
|         WHERE NOT EXISTS( | ||||
|         SELECT cii.client_id | ||||
|         FROM ( | ||||
|         SELECT client_id FROM crm_inventory_info | ||||
|         WHERE confirm_status = '1' AND company_id = #{companyId} | ||||
|         <include refid="dateSel"/> | ||||
|         GROUP BY client_id) cii | ||||
|         WHERE t0.id = cii.client_id | ||||
|         ) | ||||
|         AND t0.status = '1' | ||||
|         AND t0.documents_status = '1' | ||||
|         AND t0.uecode IS NOT NULL AND t0.company_id = #{companyId} | ||||
|         <if test="clientId !=null and clientId !=''"> | ||||
|             AND t0.id = #{clientId} | ||||
|         </if> | ||||
|         <if test="uecode !=null and uecode !=''"> | ||||
|             AND t0.uecode LIKE '%' || #{uecode} || '%' | ||||
|         </if> | ||||
|         <if test="clientName !=null and clientName !=''"> | ||||
|             AND t0.distributor_name  LIKE '%' || #{clientName} || '%' | ||||
|         </if> | ||||
|         <if test="staffName !=null and staffName !=''"> | ||||
|             AND csui.name LIKE '%' || #{staffName} || '%' | ||||
|         </if> | ||||
|         <if test="areaName !=null and areaName !=''"> | ||||
|             AND cmai.area_name LIKE '%' || #{areaName} || '%' | ||||
|         </if> | ||||
|         <include refid="dataScopeSql" /> | ||||
|     </select> | ||||
| 
 | ||||
|     <!-- 根据条件参数查询盘点子表的商品 --> | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue