客户库存盘点明细

This commit is contained in:
mzr 2024-11-05 18:14:41 +08:00
parent 5f171c3112
commit fc7e6b2b5e
3 changed files with 136 additions and 78 deletions

View File

@ -90,6 +90,7 @@ public class StockExcel {
@ApiOperation(value = "导出客户库存盘点明细") @ApiOperation(value = "导出客户库存盘点明细")
@GetMapping(value = "/exportClientStockReport") @GetMapping(value = "/exportClientStockReport")
public void 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 startDate,
@ApiParam(required = true, value = "结束日期") @RequestParam(required = true) String endDate, @ApiParam(required = true, value = "结束日期") @RequestParam(required = true) String endDate,
@ApiParam(required = false, value = "客户id") @RequestParam(required = false) String clientId, @ApiParam(required = false, value = "客户id") @RequestParam(required = false) String clientId,
@ -113,7 +114,11 @@ public class StockExcel {
params.put("uecode", uecode); params.put("uecode", uecode);
params.put("clientName", clientName); params.put("clientName", clientName);
params.put("staffName", staffName); 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); EasyPoiUtils.exportExcel(list, ClientStockReport.class, "客户库存盘点明细导出", response);
} }

View File

@ -132,6 +132,7 @@ public class StockReportController extends BaseController {
@ApiOperation("客户库存盘点明细") @ApiOperation("客户库存盘点明细")
@PostMapping(value = "/getClientStockReport") @PostMapping(value = "/getClientStockReport")
public Map<String, Object> 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 startDate,
@ApiParam(required = true, value = "结束日期") @RequestParam(required = true) String endDate, @ApiParam(required = true, value = "结束日期") @RequestParam(required = true) String endDate,
@ApiParam(required = false, value = "客户id") @RequestParam(required = false) String clientId, @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("staffName", staffName);
params.put("page", pageNum); params.put("page", pageNum);
params.put("pageSize", pageSize); 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));
} }
/** /**

View File

@ -26,82 +26,8 @@
TO_CHAR(TO_DATE(SUBSTR(#{endDate},1,10),'yyyy-MM-dd'),'yyyy-MM-dd') TO_CHAR(TO_DATE(SUBSTR(#{endDate},1,10),'yyyy-MM-dd'),'yyyy-MM-dd')
</if> </if>
</sql> </sql>
<!-- 数据权限查询条件 -->
<!-- 客户库存盘点明细 --> <sql id="dataScopeSql">
<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>
<if test="flag !=null and flag !=''"> <if test="flag !=null and flag !=''">
<!-- 前端传营销区域 --> <!-- 前端传营销区域 -->
<if test="flag == 1"> <if test="flag == 1">
@ -187,6 +113,128 @@
t0.service_id LIKE '%' || #{userId} || '%' t0.service_id LIKE '%' || #{userId} || '%'
) )
</if> </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> </select>
<!-- 根据条件参数查询盘点子表的商品 --> <!-- 根据条件参数查询盘点子表的商品 -->