新增供应链模块服务
This commit is contained in:
parent
103c998ad3
commit
6a2d5ddbb3
|
|
@ -87,12 +87,12 @@ public class DrpInventoryIntoDetailServiceImpl implements IDrpInventoryIntoDetai
|
|||
public Map<String, Object> pageInventoryOutDetail(DrpInventoryIntoDetailQueryDTO queryDTO) {
|
||||
SysUser currentUser = SecurityUtils.getLoginUser().getSysUser();
|
||||
List<Long> warehouseAuthority = drpInventoryIntoDetailMapper.getTenantWarehouseIds(currentUser.getUserId());
|
||||
List<Long> areaAuth = drpInventoryIntoDetailMapper.getTenantAreaIds(currentUser.getUserId());
|
||||
// List<Long> areaAuth = drpInventoryIntoDetailMapper.getTenantAreaIds(currentUser.getUserId());
|
||||
PageHelper.startPage(queryDTO);
|
||||
DrpInventoryIntoDetailWrapper wrapper = new DrpInventoryIntoDetailWrapper();
|
||||
wrapper.setParam(queryDTO);
|
||||
wrapper.setWarehouseAuthority(warehouseAuthority);
|
||||
wrapper.setAreaAuth(areaAuth);
|
||||
wrapper.setAreaAuth(null);
|
||||
List<DrpInventoryoutDetailVO> drpInventoryoutDetailVOS = drpInventoryIntoDetailMapper.queryInventoryOutDetail(wrapper);
|
||||
/* for ( DrpInventoryoutDetailVO c : drpInventoryoutDetailVOS) {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -219,214 +219,143 @@
|
|||
<select id="queryInventoryOutDetail"
|
||||
resultType="com.bonus.canteen.core.reportforms.beans.DrpInventoryoutDetailVO"
|
||||
parameterType="com.bonus.canteen.core.reportforms.beans.DrpInventoryIntoDetailWrapper">
|
||||
|
||||
SELECT
|
||||
de.material_id,
|
||||
mm.material_name as goods_name,
|
||||
mm.material_code as goods_code,
|
||||
mm.material_name AS goods_name,
|
||||
mm.material_code AS goods_code,
|
||||
mmc.category_id,
|
||||
mmc.category_name as goods_category_name,
|
||||
mmc.category_name AS goods_category_name,
|
||||
de.unit_id,
|
||||
du.unit_name,
|
||||
de.unit_price as price,
|
||||
de.unit_price AS price,
|
||||
aa.area_name,
|
||||
dw.warehouse_id,
|
||||
dw.warehouse_name,
|
||||
de.out_into_type intoType,
|
||||
de.fetch_user_id as supplier_id,
|
||||
null as supplier_name,
|
||||
de.record_time intoDate,
|
||||
de.out_into_num intoNum,
|
||||
de.inventory_num balance_num,
|
||||
de.out_into_amount intoAmount,
|
||||
de.total_amount balance_amount,
|
||||
de.fetch_user_id as operator_id,
|
||||
IF(mu.real_name IS NULL OR mu.real_name = '', mu.username, mu.real_name) operatorName,
|
||||
de.product_date as production_date,
|
||||
de.expire_time as expiry_date,
|
||||
de.out_into_type AS intoType,
|
||||
de.fetch_user_id AS supplier_id,
|
||||
NULL AS supplier_name,
|
||||
de.record_time AS intoDate,
|
||||
|
||||
-- 数量:退单为负
|
||||
CASE
|
||||
WHEN de.record_type = 1 AND de.out_into_type = 6
|
||||
THEN -de.out_into_num
|
||||
ELSE de.out_into_num
|
||||
END AS intoNum,
|
||||
|
||||
de.inventory_num AS balance_num,
|
||||
|
||||
-- 金额:退单为负
|
||||
CASE
|
||||
WHEN de.record_type = 1 AND de.out_into_type = 6
|
||||
THEN -de.out_into_amount
|
||||
ELSE de.out_into_amount
|
||||
END AS intoAmount,
|
||||
|
||||
de.total_amount AS balance_amount,
|
||||
de.fetch_user_id AS operator_id,
|
||||
IF(mu.real_name IS NULL OR mu.real_name = '',
|
||||
mu.username,
|
||||
mu.real_name) AS operatorName,
|
||||
de.product_date AS production_date,
|
||||
de.expire_time AS expiry_date,
|
||||
de.record_id,
|
||||
mm.size as specification,
|
||||
0 as record_type_flag -- 0表示正常入库记录
|
||||
from report_drp_inventory_base de
|
||||
mm.size AS specification,
|
||||
|
||||
-- 标识:1=退单,0=正常
|
||||
CASE
|
||||
WHEN de.record_type = 1 AND de.out_into_type = 6
|
||||
THEN 1
|
||||
ELSE 0
|
||||
END AS record_type_flag
|
||||
|
||||
FROM report_drp_inventory_base de
|
||||
LEFT JOIN menu_material mm ON de.material_id = mm.material_id
|
||||
LEFT JOIN drp_unit du ON de.unit_id = du.unit_id
|
||||
LEFT JOIN menu_material_category mmc ON mmc.category_id = mm.category_id
|
||||
left join drp_warehouse dw on dw.warehouse_id = de.warehouse_id
|
||||
left join alloc_area aa on aa.area_id = dw.area_id
|
||||
LEFT JOIN drp_warehouse dw ON dw.warehouse_id = de.warehouse_id
|
||||
LEFT JOIN alloc_area aa ON aa.area_id = dw.area_id
|
||||
LEFT JOIN mgr_user mu ON de.fetch_user_id = mu.user_id
|
||||
where de.record_type = 2 and de.out_into_type in (1,3,5,6)
|
||||
|
||||
WHERE
|
||||
(
|
||||
-- 正常入库
|
||||
(de.record_type = 2 AND de.out_into_type IN (1,3,5,6))
|
||||
|
||||
OR
|
||||
|
||||
-- 超市退单(直接负数,不依赖 order_info/order_refund)
|
||||
(de.record_type = 1 AND de.out_into_type = 6)
|
||||
)
|
||||
|
||||
<if test="param.startDate != null">
|
||||
and de.record_date >= #{param.startDate}
|
||||
AND de.record_date >= #{param.startDate}
|
||||
</if>
|
||||
<if test="param.endDate != null">
|
||||
and de.record_date <= #{param.endDate}
|
||||
AND de.record_date <= #{param.endDate}
|
||||
</if>
|
||||
|
||||
<if test="param.supplierIdList != null and param.supplierIdList.size() > 0">
|
||||
and de.fetch_user_id in
|
||||
AND de.fetch_user_id IN
|
||||
<foreach collection="param.supplierIdList" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
<if test="param.materialName != null and param.materialName != ''">
|
||||
and (mm.material_name like concat('%', #{param.materialName}, '%')
|
||||
or mm.material_code like concat('%', #{param.materialName}, '%'))
|
||||
AND (mm.material_name LIKE CONCAT('%', #{param.materialName}, '%')
|
||||
OR mm.material_code LIKE CONCAT('%', #{param.materialName}, '%'))
|
||||
</if>
|
||||
|
||||
<if test="param.categoryIdList != null and param.categoryIdList.size() > 0">
|
||||
and mmc.category_id in
|
||||
AND mmc.category_id IN
|
||||
<foreach collection="param.categoryIdList" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
<if test="param.intoTypeList != null and param.intoTypeList.size() > 0">
|
||||
and de.out_into_type in
|
||||
AND de.out_into_type IN
|
||||
<foreach collection="param.intoTypeList" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
<if test="param.recordId != null and param.recordId != ''">
|
||||
and de.record_id like concat('%', #{param.recordId}, '%')
|
||||
AND de.record_id LIKE CONCAT('%', #{param.recordId}, '%')
|
||||
</if>
|
||||
|
||||
<if test="param.areaIdList != null and param.areaIdList.size() > 0">
|
||||
and dw.area_id in
|
||||
AND dw.area_id IN
|
||||
<foreach collection="param.areaIdList" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
<if test="param.warehouseIdList != null and param.warehouseIdList.size() > 0">
|
||||
and dw.warehouse_id in
|
||||
AND dw.warehouse_id IN
|
||||
<foreach collection="param.warehouseIdList" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
<if test="warehouseAuthority != null and warehouseAuthority.size() > 0">
|
||||
and dw.warehouse_id in
|
||||
AND dw.warehouse_id IN
|
||||
<foreach collection="warehouseAuthority" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
<if test="areaAuth != null and areaAuth.size() > 0">
|
||||
and dw.area_id in
|
||||
AND dw.area_id IN
|
||||
<foreach collection="areaAuth" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
UNION ALL
|
||||
ORDER BY record_type_flag DESC, intoDate DESC
|
||||
|
||||
-- 退款记录(负数)
|
||||
SELECT
|
||||
de.material_id,
|
||||
mm.material_name as goods_name,
|
||||
mm.material_code as goods_code,
|
||||
mmc.category_id,
|
||||
mmc.category_name as goods_category_name,
|
||||
de.unit_id,
|
||||
du.unit_name,
|
||||
de.unit_price as price,
|
||||
aa.area_name,
|
||||
dw.warehouse_id,
|
||||
dw.warehouse_name,
|
||||
de.out_into_type intoType,
|
||||
de.fetch_user_id as supplier_id,
|
||||
null as supplier_name,
|
||||
de.record_time intoDate,
|
||||
de.out_into_num intoNum, -- 负值表示退款
|
||||
de.inventory_num balance_num,
|
||||
-de.out_into_amount intoAmount, -- 负值表示退款
|
||||
de.total_amount balance_amount,
|
||||
de.fetch_user_id as operator_id,
|
||||
IF(mu.real_name IS NULL OR mu.real_name = '', mu.username, mu.real_name) operatorName,
|
||||
de.product_date as production_date,
|
||||
de.expire_time as expiry_date,
|
||||
de.record_id,
|
||||
mm.size as specification,
|
||||
1 as record_type_flag -- 1表示退款记录
|
||||
from report_drp_inventory_base de
|
||||
LEFT JOIN menu_material mm ON de.material_id = mm.material_id
|
||||
LEFT JOIN drp_unit du ON de.unit_id = du.unit_id
|
||||
LEFT JOIN menu_material_category mmc ON mmc.category_id = mm.category_id
|
||||
left join drp_warehouse dw on dw.warehouse_id = de.warehouse_id
|
||||
left join alloc_area aa on aa.area_id = dw.area_id
|
||||
LEFT JOIN mgr_user mu ON de.fetch_user_id = mu.user_id
|
||||
INNER JOIN order_info oi ON oi.inventory_out_id = de.record_id -- 关联order_info
|
||||
INNER JOIN order_refund rr ON rr.order_id = oi.order_id AND rr.check_state = 2 -- 关联order_refund,只查询已审核的退款
|
||||
where de.record_type = 2 and de.out_into_type in (1,3,5,6)
|
||||
|
||||
<if test="param.startDate != null">
|
||||
and rr.apply_time >= #{param.startDate} -- 退款申请时间条件
|
||||
</if>
|
||||
<if test="param.endDate != null">
|
||||
and rr.apply_time <= #{param.endDate} -- 退款申请时间条件
|
||||
</if>
|
||||
|
||||
<if test="param.supplierIdList != null and param.supplierIdList.size() > 0">
|
||||
and de.fetch_user_id in
|
||||
<foreach collection="param.supplierIdList" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
<if test="param.materialName != null and param.materialName != ''">
|
||||
and (mm.material_name like concat('%', #{param.materialName}, '%')
|
||||
or mm.material_code like concat('%', #{param.materialName}, '%'))
|
||||
</if>
|
||||
|
||||
<if test="param.categoryIdList != null and param.categoryIdList.size() > 0">
|
||||
and mmc.category_id in
|
||||
<foreach collection="param.categoryIdList" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
<if test="param.intoTypeList != null and param.intoTypeList.size() > 0">
|
||||
and de.out_into_type in
|
||||
<foreach collection="param.intoTypeList" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
<if test="param.recordId != null and param.recordId != ''">
|
||||
and de.record_id like concat('%', #{param.recordId}, '%')
|
||||
</if>
|
||||
|
||||
<if test="param.areaIdList != null and param.areaIdList.size() > 0">
|
||||
and dw.area_id in
|
||||
<foreach collection="param.areaIdList" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
<if test="param.warehouseIdList != null and param.warehouseIdList.size() > 0">
|
||||
and dw.warehouse_id in
|
||||
<foreach collection="param.warehouseIdList" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
<if test="warehouseAuthority != null and warehouseAuthority.size() > 0">
|
||||
and dw.warehouse_id in
|
||||
<foreach collection="warehouseAuthority" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
<if test="areaAuth != null and areaAuth.size() > 0">
|
||||
and dw.area_id in
|
||||
<foreach collection="areaAuth" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
</select>
|
||||
</select>
|
||||
|
||||
<!-- 获取租户仓库列表(带权限控制) -->
|
||||
<select id="getTenantWarehouse" resultMap="DrpWarehouseAllVOResult">
|
||||
|
|
@ -527,107 +456,45 @@
|
|||
<select id="queryInventoryIntoDocDetailoutSum"
|
||||
resultType="com.bonus.canteen.core.reportforms.beans.InventoryIntoSummaryVO">
|
||||
SELECT
|
||||
SUM(intoNum) as totalInQty,
|
||||
SUM(intoAmount) as totalInAmount,
|
||||
-- 库存总计(直接从主表查询,不包含退款记录)
|
||||
(SELECT SUM(de2.inventory_num)
|
||||
FROM report_drp_inventory_base de2
|
||||
LEFT JOIN menu_material mm2 ON de2.material_id = mm2.material_id
|
||||
LEFT JOIN drp_warehouse dw2 ON de2.warehouse_id = dw2.warehouse_id
|
||||
LEFT JOIN alloc_area aa2 ON aa2.area_id = dw2.area_id
|
||||
WHERE de2.record_type = 2
|
||||
AND de2.out_into_type IN (1,3,5,6)
|
||||
<if test="param.startDate != null">
|
||||
AND de2.record_date >= #{param.startDate}
|
||||
</if>
|
||||
<if test="param.endDate != null">
|
||||
AND de2.record_date <= #{param.endDate}
|
||||
</if>
|
||||
<if test="param.materialName != null and param.materialName != ''">
|
||||
AND (mm2.material_name like concat('%', #{param.materialName}, '%')
|
||||
OR mm2.material_code like concat('%', #{param.materialName}, '%'))
|
||||
</if>
|
||||
<if test="param.areaIdList != null and param.areaIdList.size() > 0">
|
||||
AND dw2.area_id in
|
||||
<foreach collection="param.areaIdList" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="param.warehouseIdList != null and param.warehouseIdList.size() > 0">
|
||||
AND dw2.warehouse_id in
|
||||
<foreach collection="param.warehouseIdList" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="warehouseAuthority != null and warehouseAuthority.size() > 0">
|
||||
AND dw2.warehouse_id in
|
||||
<foreach collection="warehouseAuthority" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="areaAuth != null and areaAuth.size() > 0">
|
||||
AND dw2.area_id in
|
||||
<foreach collection="areaAuth" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
) as totalStockQty,
|
||||
(SELECT SUM(de2.total_amount)
|
||||
FROM report_drp_inventory_base de2
|
||||
LEFT JOIN menu_material mm2 ON de2.material_id = mm2.material_id
|
||||
LEFT JOIN drp_warehouse dw2 ON de2.warehouse_id = dw2.warehouse_id
|
||||
LEFT JOIN alloc_area aa2 ON aa2.area_id = dw2.area_id
|
||||
WHERE de2.record_type = 2
|
||||
AND de2.out_into_type IN (1,3,5,6)
|
||||
<if test="param.startDate != null">
|
||||
AND de2.record_date >= #{param.startDate}
|
||||
</if>
|
||||
<if test="param.endDate != null">
|
||||
AND de2.record_date <= #{param.endDate}
|
||||
</if>
|
||||
<if test="param.materialName != null and param.materialName != ''">
|
||||
AND (mm2.material_name like concat('%', #{param.materialName}, '%')
|
||||
OR mm2.material_code like concat('%', #{param.materialName}, '%'))
|
||||
</if>
|
||||
<if test="param.areaIdList != null and param.areaIdList.size() > 0">
|
||||
AND dw2.area_id in
|
||||
<foreach collection="param.areaIdList" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="param.warehouseIdList != null and param.warehouseIdList.size() > 0">
|
||||
AND dw2.warehouse_id in
|
||||
<foreach collection="param.warehouseIdList" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="warehouseAuthority != null and warehouseAuthority.size() > 0">
|
||||
AND dw2.warehouse_id in
|
||||
<foreach collection="warehouseAuthority" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="areaAuth != null and areaAuth.size() > 0">
|
||||
AND dw2.area_id in
|
||||
<foreach collection="areaAuth" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
) as totalStockAmount
|
||||
SUM(combined.intoNum) AS totalInQty,
|
||||
SUM(combined.intoAmount) AS totalInAmount,
|
||||
SUM(combined.balance_num) AS totalStockQty,
|
||||
SUM(combined.balance_amount) AS totalStockAmount
|
||||
FROM (
|
||||
-- 正常入库记录
|
||||
-- 正常入库 + 退单负数
|
||||
SELECT
|
||||
de.out_into_num as intoNum,
|
||||
de.out_into_amount as intoAmount
|
||||
-- 数量:退单为负
|
||||
CASE
|
||||
WHEN de.record_type = 1 AND de.out_into_type = 6
|
||||
THEN -de.out_into_num
|
||||
ELSE de.out_into_num
|
||||
END AS intoNum,
|
||||
|
||||
-- 金额:退单为负
|
||||
CASE
|
||||
WHEN de.record_type = 1 AND de.out_into_type = 6
|
||||
THEN -de.out_into_amount
|
||||
ELSE de.out_into_amount
|
||||
END AS intoAmount,
|
||||
|
||||
de.inventory_num AS balance_num,
|
||||
de.total_amount AS balance_amount
|
||||
|
||||
FROM report_drp_inventory_base de
|
||||
LEFT JOIN menu_material mm ON de.material_id = mm.material_id
|
||||
LEFT JOIN drp_unit du ON de.unit_id = du.unit_id
|
||||
LEFT JOIN menu_material_category mmc ON mmc.category_id = mm.category_id
|
||||
LEFT JOIN drp_warehouse dw ON dw.warehouse_id = de.warehouse_id
|
||||
LEFT JOIN alloc_area aa ON aa.area_id = dw.area_id
|
||||
LEFT JOIN mgr_user mu ON de.fetch_user_id = mu.user_id
|
||||
WHERE de.record_type = 2
|
||||
AND de.out_into_type IN (1,3,5,6)
|
||||
|
||||
WHERE
|
||||
(
|
||||
-- 正常入库
|
||||
(de.record_type = 2 AND de.out_into_type IN (1,3,5,6))
|
||||
OR
|
||||
-- 退单
|
||||
(de.record_type = 1 AND de.out_into_type = 6)
|
||||
)
|
||||
|
||||
<if test="param.startDate != null">
|
||||
AND de.record_date >= #{param.startDate}
|
||||
|
|
@ -636,148 +503,42 @@
|
|||
AND de.record_date <= #{param.endDate}
|
||||
</if>
|
||||
|
||||
<if test="param.supplierIdList != null and param.supplierIdList.size() > 0">
|
||||
AND de.fetch_user_id in
|
||||
<foreach collection="param.supplierIdList" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
<if test="param.materialName != null and param.materialName != ''">
|
||||
AND (mm.material_name like concat('%', #{param.materialName}, '%')
|
||||
OR mm.material_code like concat('%', #{param.materialName}, '%'))
|
||||
</if>
|
||||
|
||||
<if test="param.categoryIdList != null and param.categoryIdList.size() > 0">
|
||||
AND mmc.category_id in
|
||||
<foreach collection="param.categoryIdList" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
<if test="param.intoTypeList != null and param.intoTypeList.size() > 0">
|
||||
AND de.out_into_type in
|
||||
<foreach collection="param.intoTypeList" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
<if test="param.recordId != null and param.recordId != ''">
|
||||
AND de.record_id like concat('%', #{param.recordId}, '%')
|
||||
AND (mm.material_name LIKE CONCAT('%', #{param.materialName}, '%')
|
||||
OR mm.material_code LIKE CONCAT('%', #{param.materialName}, '%'))
|
||||
</if>
|
||||
|
||||
<if test="param.areaIdList != null and param.areaIdList.size() > 0">
|
||||
AND dw.area_id in
|
||||
AND dw.area_id IN
|
||||
<foreach collection="param.areaIdList" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
<if test="param.warehouseIdList != null and param.warehouseIdList.size() > 0">
|
||||
AND dw.warehouse_id in
|
||||
AND dw.warehouse_id IN
|
||||
<foreach collection="param.warehouseIdList" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
<if test="warehouseAuthority != null and warehouseAuthority.size() > 0">
|
||||
AND dw.warehouse_id in
|
||||
AND dw.warehouse_id IN
|
||||
<foreach collection="warehouseAuthority" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
<if test="areaAuth != null and areaAuth.size() > 0">
|
||||
AND dw.area_id in
|
||||
AND dw.area_id IN
|
||||
<foreach collection="areaAuth" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
UNION ALL
|
||||
) AS combined
|
||||
|
||||
-- 退款记录(负数)
|
||||
SELECT
|
||||
de.out_into_num as intoNum, -- 注意:这里需要改成负数,或者保持正数在外部处理
|
||||
-de.out_into_amount as intoAmount -- 金额为负数
|
||||
FROM report_drp_inventory_base de
|
||||
LEFT JOIN menu_material mm ON de.material_id = mm.material_id
|
||||
LEFT JOIN drp_unit du ON de.unit_id = du.unit_id
|
||||
LEFT JOIN menu_material_category mmc ON mmc.category_id = mm.category_id
|
||||
LEFT JOIN drp_warehouse dw ON dw.warehouse_id = de.warehouse_id
|
||||
LEFT JOIN alloc_area aa ON aa.area_id = dw.area_id
|
||||
LEFT JOIN mgr_user mu ON de.fetch_user_id = mu.user_id
|
||||
INNER JOIN order_info oi ON oi.inventory_out_id = de.record_id
|
||||
INNER JOIN order_refund rr ON rr.order_id = oi.order_id AND rr.check_state = 2
|
||||
WHERE de.record_type = 2
|
||||
AND de.out_into_type IN (1,3,5,6)
|
||||
|
||||
<if test="param.startDate != null">
|
||||
AND rr.apply_time >= #{param.startDate}
|
||||
</if>
|
||||
<if test="param.endDate != null">
|
||||
AND rr.apply_time <= #{param.endDate}
|
||||
</if>
|
||||
|
||||
<if test="param.supplierIdList != null and param.supplierIdList.size() > 0">
|
||||
AND de.fetch_user_id in
|
||||
<foreach collection="param.supplierIdList" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
<if test="param.materialName != null and param.materialName != ''">
|
||||
AND (mm.material_name like concat('%', #{param.materialName}, '%')
|
||||
OR mm.material_code like concat('%', #{param.materialName}, '%'))
|
||||
</if>
|
||||
|
||||
<if test="param.categoryIdList != null and param.categoryIdList.size() > 0">
|
||||
AND mmc.category_id in
|
||||
<foreach collection="param.categoryIdList" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
<if test="param.intoTypeList != null and param.intoTypeList.size() > 0">
|
||||
AND de.out_into_type in
|
||||
<foreach collection="param.intoTypeList" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
<if test="param.recordId != null and param.recordId != ''">
|
||||
AND de.record_id like concat('%', #{param.recordId}, '%')
|
||||
</if>
|
||||
|
||||
<if test="param.areaIdList != null and param.areaIdList.size() > 0">
|
||||
AND dw.area_id in
|
||||
<foreach collection="param.areaIdList" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
<if test="param.warehouseIdList != null and param.warehouseIdList.size() > 0">
|
||||
AND dw.warehouse_id in
|
||||
<foreach collection="param.warehouseIdList" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
<if test="warehouseAuthority != null and warehouseAuthority.size() > 0">
|
||||
AND dw.warehouse_id in
|
||||
<foreach collection="warehouseAuthority" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
<if test="areaAuth != null and areaAuth.size() > 0">
|
||||
AND dw.area_id in
|
||||
<foreach collection="areaAuth" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
) AS combined_data
|
||||
</select>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,424 @@
|
|||
<?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.bonus.canteen.core.reportforms.mapper.DrpInventoryhzMapper">
|
||||
<!-- 结果映射:库存入库明细VO -->
|
||||
<resultMap type="com.bonus.canteen.core.reportforms.beans.DrpInventoryIntoDetailVO" id="DrpInventoryIntoDetailVOResult">
|
||||
<result property="recordId" column="record_id" />
|
||||
<result property="areaName" column="area_name" />
|
||||
<result property="warehouseId" column="warehouse_id" />
|
||||
<result property="warehouseName" column="warehouse_name" />
|
||||
<result property="intoType" column="intoType" />
|
||||
<result property="intoDate" column="intoDate" />
|
||||
<result property="intoNum" column="intoNum" />
|
||||
<result property="intoAmount" column="intoAmount" />
|
||||
<result property="operatorId" column="operator_id" />
|
||||
<result property="operatorName" column="operatorName" />
|
||||
<result property="goodsCode" column="goods_code" />
|
||||
<result property="goodsCategory" column="goods_category" />
|
||||
<result property="goodsCategoryName" column="goods_category_name" />
|
||||
<result property="goodsName" column="goods_name" />
|
||||
<result property="unitName" column="unit_name" />
|
||||
<result property="specification" column="specification" />
|
||||
<result property="price" column="price" />
|
||||
<result property="supplierId" column="supplier_id" />
|
||||
<result property="supplierName" column="supplier_name" />
|
||||
<result property="balanceNum" column="balance_num" />
|
||||
<result property="balanceAmount" column="balance_amount" />
|
||||
<result property="productionDate" column="production_date" />
|
||||
<result property="expiryDate" column="expiry_date" />
|
||||
</resultMap>
|
||||
<select id="pageInventoryIntoDetail"
|
||||
resultType="com.bonus.canteen.core.reportforms.beans.InventoryGoodsSummaryVO">
|
||||
SELECT
|
||||
t.warehouse_name,
|
||||
t.area_name,
|
||||
t.material_id,
|
||||
t.material_name,
|
||||
t.material_code,
|
||||
t.category_id,
|
||||
t.category_name,
|
||||
t.unit_id,
|
||||
t.unit_name,
|
||||
t.size,
|
||||
SUM(t.into_num) intoTotalNum,
|
||||
SUM(t.into_amount) intoTotalAmount,
|
||||
SUM(t.out_num) outTotalNum,
|
||||
SUM(t.out_amount) outTotalAmount
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
aa.area_name,
|
||||
dw.warehouse_name,
|
||||
ds.material_id,
|
||||
mm.material_name,
|
||||
mm.material_code,
|
||||
mmc.category_id,
|
||||
mmc.category_name,
|
||||
ds.unit_id,
|
||||
du.unit_name,
|
||||
mm.size,
|
||||
dw.warehouse_id,
|
||||
SUM(ds.into_num) into_num,
|
||||
SUM(ds.into_amount) into_amount,
|
||||
SUM(ds.out_num) out_num,
|
||||
SUM(ds.out_amount) out_amount
|
||||
FROM
|
||||
report_drp_inventory_summary ds
|
||||
LEFT JOIN menu_material mm ON ds.material_id = mm.material_id
|
||||
LEFT JOIN drp_unit du ON ds.unit_id = du.unit_id
|
||||
LEFT JOIN menu_material_category mmc ON mmc.category_id = mm.category_id
|
||||
LEFT JOIN drp_warehouse dw ON dw.warehouse_id = ds.warehouse_id
|
||||
left join alloc_area aa on aa.area_id = dw.area_id
|
||||
<where>
|
||||
<if test="param.startDate != null">
|
||||
and ds.statistic_date <![CDATA[ >= ]]> #{param.startDate}
|
||||
</if>
|
||||
<if test="param.endDate != null">
|
||||
and ds.statistic_date <![CDATA[ <= ]]> #{param.endDate}
|
||||
</if>
|
||||
<if test="param.materialName != null and param.materialName != ''">
|
||||
and (mm.material_name like concat('%', #{param.materialName}, '%')
|
||||
or mm.material_code like concat('%', #{param.materialName}, '%')
|
||||
)
|
||||
</if>
|
||||
<if test="param.categoryIdList != null and param.categoryIdList.size() > 0">
|
||||
AND mmc.category_id in
|
||||
<foreach collection="param.categoryIdList" item="categoryId" separator="," open="("
|
||||
close=")">
|
||||
#{categoryId}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="param.areaIdList != null and param.areaIdList.size() > 0">
|
||||
AND dw.area_id in
|
||||
<foreach collection="param.areaIdList" item="item" open="(" close=")" separator=",">
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="param.warehouseIdList != null and param.warehouseIdList.size() > 0">
|
||||
AND dw.warehouse_id in
|
||||
<foreach collection="param.warehouseIdList" item="warehouseId" separator="," open="("
|
||||
close=")">
|
||||
#{warehouseId}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="warehouseAuthority != null and warehouseAuthority.size() > 0">
|
||||
and dw.warehouse_id in
|
||||
<foreach collection="warehouseAuthority" item="warehouseId" separator="," open="(" close=")">
|
||||
#{warehouseId}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="areaAuth != null and areaAuth.size() > 0">
|
||||
and dw.area_id in
|
||||
<foreach collection="areaAuth" item="areaId" separator="," open="(" close=")">
|
||||
#{areaId}
|
||||
</foreach>
|
||||
</if>
|
||||
</where>
|
||||
group by ds.material_id,
|
||||
mm.material_name,
|
||||
mm.material_code,
|
||||
mmc.category_id,
|
||||
mmc.category_name,
|
||||
ds.unit_id,
|
||||
du.unit_name,
|
||||
mm.size,
|
||||
dw.warehouse_id,
|
||||
dw.warehouse_name
|
||||
) t
|
||||
group by t.material_id,
|
||||
t.material_name,
|
||||
t.material_code,
|
||||
t.category_id,
|
||||
t.category_name,
|
||||
t.unit_id,
|
||||
t.unit_name,
|
||||
t.size
|
||||
|
||||
|
||||
</select>
|
||||
<select id="queryInventoryIntoDocDetailSum"
|
||||
resultType="com.bonus.canteen.core.reportforms.beans.InventoryIntoSummaryVO">
|
||||
SELECT
|
||||
SUM(ds.into_num) as intoTotalNum,
|
||||
SUM(ds.into_amount) as intoTotalAmount,
|
||||
SUM(ds.out_num) as outTotalNum,
|
||||
SUM(ds.out_amount) as outTotalAmount
|
||||
FROM
|
||||
report_drp_inventory_summary ds
|
||||
LEFT JOIN menu_material mm ON ds.material_id = mm.material_id
|
||||
LEFT JOIN drp_unit du ON ds.unit_id = du.unit_id
|
||||
LEFT JOIN menu_material_category mmc ON mmc.category_id = mm.category_id
|
||||
LEFT JOIN drp_warehouse dw ON dw.warehouse_id = ds.warehouse_id
|
||||
LEFT JOIN alloc_area aa ON aa.area_id = dw.area_id
|
||||
<where>
|
||||
<if test="param.startDate != null">
|
||||
and ds.statistic_date <![CDATA[ >= ]]> #{param.startDate}
|
||||
</if>
|
||||
<if test="param.endDate != null">
|
||||
and ds.statistic_date <![CDATA[ <= ]]> #{param.endDate}
|
||||
</if>
|
||||
<if test="param.materialName != null and param.materialName != ''">
|
||||
and (mm.material_name like concat('%', #{param.materialName}, '%')
|
||||
or mm.material_code like concat('%', #{param.materialName}, '%')
|
||||
)
|
||||
</if>
|
||||
<if test="param.categoryIdList != null and param.categoryIdList.size() > 0">
|
||||
AND mmc.category_id in
|
||||
<foreach collection="param.categoryIdList" item="categoryId" separator="," open="("
|
||||
close=")">
|
||||
#{categoryId}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="param.areaIdList != null and param.areaIdList.size() > 0">
|
||||
AND dw.area_id in
|
||||
<foreach collection="param.areaIdList" item="item" open="(" close=")" separator=",">
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="param.warehouseIdList != null and param.warehouseIdList.size() > 0">
|
||||
AND dw.warehouse_id in
|
||||
<foreach collection="param.warehouseIdList" item="warehouseId" separator="," open="("
|
||||
close=")">
|
||||
#{warehouseId}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="warehouseAuthority != null and warehouseAuthority.size() > 0">
|
||||
and dw.warehouse_id in
|
||||
<foreach collection="warehouseAuthority" item="warehouseId" separator="," open="(" close=")">
|
||||
#{warehouseId}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="areaAuth != null and areaAuth.size() > 0">
|
||||
and dw.area_id in
|
||||
<foreach collection="areaAuth" item="areaId" separator="," open="(" close=")">
|
||||
#{areaId}
|
||||
</foreach>
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
<select id="queryInventoryWarehouseSummaryList"
|
||||
resultType="com.bonus.canteen.core.reportforms.beans.ReportDrpInventoryWarehouseSummaryVO">
|
||||
select
|
||||
aa.area_name,
|
||||
dw.warehouse_id,
|
||||
dw.warehouse_name,
|
||||
sum(ds.into_num) intoTotalNum,
|
||||
sum(ds.into_amount) intoTotalAmount,
|
||||
sum(ds.out_num) outTotalNum,
|
||||
sum(ds.out_amount) outTotalAmount
|
||||
from report_drp_inventory_summary ds
|
||||
left join drp_warehouse dw on dw.warehouse_id = ds.warehouse_id
|
||||
left join alloc_area aa on aa.area_id = dw.area_id
|
||||
<where>
|
||||
<if test="param.startDate != null">
|
||||
and ds.statistic_date <![CDATA[ >= ]]> #{param.startDate}
|
||||
</if>
|
||||
<if test="param.endDate != null">
|
||||
and ds.statistic_date <![CDATA[ <= ]]> #{param.endDate}
|
||||
</if>
|
||||
<if test="param.areaIdList != null and param.areaIdList.size() > 0">
|
||||
AND dw.area_id in
|
||||
<foreach collection="param.areaIdList" item="item" open="(" close=")" separator=",">
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="param.warehouseIdList != null and param.warehouseIdList.size() > 0">
|
||||
AND dw.warehouse_id in
|
||||
<foreach collection="param.warehouseIdList" item="warehouseId" separator="," open="("
|
||||
close=")">
|
||||
#{warehouseId}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="warehouseAuthority != null and warehouseAuthority.size() > 0">
|
||||
and dw.warehouse_id in
|
||||
<foreach collection="warehouseAuthority" item="warehouseId" separator="," open="(" close=")">
|
||||
#{warehouseId}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="areaAuth != null and areaAuth.size() > 0">
|
||||
and dw.area_id in
|
||||
<foreach collection="areaAuth" item="areaId" separator="," open="(" close=")">
|
||||
#{areaId}
|
||||
</foreach>
|
||||
</if>
|
||||
</where>
|
||||
group by aa.area_name, dw.warehouse_id,
|
||||
dw.warehouse_name
|
||||
</select>
|
||||
<select id="queryInventoryWarehouseSummarySum"
|
||||
resultType="com.bonus.canteen.core.reportforms.beans.InventoryIntoSummaryVO">
|
||||
SELECT
|
||||
SUM(ds.into_num) AS intoTotalNum,
|
||||
SUM(ds.into_amount) AS intoTotalAmount,
|
||||
SUM(ds.out_num) AS outTotalNum,
|
||||
SUM(ds.out_amount) AS outTotalAmount
|
||||
FROM report_drp_inventory_summary ds
|
||||
LEFT JOIN drp_warehouse dw ON dw.warehouse_id = ds.warehouse_id
|
||||
LEFT JOIN alloc_area aa ON aa.area_id = dw.area_id
|
||||
<where>
|
||||
<if test="param.startDate != null">
|
||||
AND ds.statistic_date <![CDATA[ >= ]]> #{param.startDate}
|
||||
</if>
|
||||
<if test="param.endDate != null">
|
||||
AND ds.statistic_date <![CDATA[ <= ]]> #{param.endDate}
|
||||
</if>
|
||||
<if test="param.areaIdList != null and param.areaIdList.size() > 0">
|
||||
AND dw.area_id IN
|
||||
<foreach collection="param.areaIdList" item="item" open="(" close=")" separator=",">
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="param.warehouseIdList != null and param.warehouseIdList.size() > 0">
|
||||
AND dw.warehouse_id IN
|
||||
<foreach collection="param.warehouseIdList" item="warehouseId" separator="," open="(" close=")">
|
||||
#{warehouseId}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="warehouseAuthority != null and warehouseAuthority.size() > 0">
|
||||
AND dw.warehouse_id IN
|
||||
<foreach collection="warehouseAuthority" item="warehouseId" separator="," open="(" close=")">
|
||||
#{warehouseId}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="areaAuth != null and areaAuth.size() > 0">
|
||||
AND dw.area_id IN
|
||||
<foreach collection="areaAuth" item="areaId" separator="," open="(" close=")">
|
||||
#{areaId}
|
||||
</foreach>
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
<select id="queryInventorySupplierSummaryList"
|
||||
resultType="com.bonus.canteen.core.reportforms.beans.InventoryGoodsSummaryVO">
|
||||
|
||||
select t.supplier_id,
|
||||
t.supplier_name as supplierName,
|
||||
sum(t.into_num) as intoNum,
|
||||
sum(t.into_amount) as intoAmount,
|
||||
sum(t.out_num) as outNum,
|
||||
sum(t.out_amount) as outAmount
|
||||
from (select ifnull(dsl.supplier_id, ds.supplier_id) supplier_id,
|
||||
ifnull(dsl.supplier_name, '透支出库') supplier_name,
|
||||
dw.warehouse_id,
|
||||
dw.warehouse_name as warehouseName,
|
||||
sum(ds.into_num) into_num,
|
||||
sum(ds.into_amount) into_amount,
|
||||
sum(ds.out_num) out_num,
|
||||
sum(ds.out_amount) out_amount
|
||||
from report_drp_inventory_summary ds
|
||||
LEFT JOIN drp_supplier dsl ON ds.supplier_id = dsl.supplier_id
|
||||
LEFT JOIN drp_warehouse dw ON dw.warehouse_id = ds.warehouse_id
|
||||
<where>
|
||||
<if test="param.startDate != null">
|
||||
and ds.statistic_date <![CDATA[ >= ]]> #{param.startDate}
|
||||
</if>
|
||||
<if test="param.endDate != null">
|
||||
and ds.statistic_date <![CDATA[ <= ]]> #{param.endDate}
|
||||
</if>
|
||||
<if test="param.supplierIdList != null and param.supplierIdList.size() > 0">
|
||||
AND dsl.supplier_id in
|
||||
<foreach collection="param.supplierIdList" item="supplierId" separator="," open="("
|
||||
close=")">
|
||||
#{supplierId}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="param.areaIdList != null and param.areaIdList.size() > 0">
|
||||
AND dw.area_id in
|
||||
<foreach collection="param.areaIdList" item="item" open="(" close=")" separator=",">
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="param.warehouseIdList != null and param.warehouseIdList.size() > 0">
|
||||
AND dw.warehouse_id in
|
||||
<foreach collection="param.warehouseIdList" item="warehouseId" separator="," open="("
|
||||
close=")">
|
||||
#{warehouseId}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="warehouseAuthority != null and warehouseAuthority.size() > 0">
|
||||
and dw.warehouse_id in
|
||||
<foreach collection="warehouseAuthority" item="warehouseId" separator="," open="(" close=")">
|
||||
#{warehouseId}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="areaAuth != null and areaAuth.size() > 0">
|
||||
and dw.area_id in
|
||||
<foreach collection="areaAuth" item="areaId" separator="," open="(" close=")">
|
||||
#{areaId}
|
||||
</foreach>
|
||||
</if>
|
||||
</where>
|
||||
GROUP BY supplier_id, supplier_name, dw.warehouse_id,
|
||||
dw.warehouse_name) t
|
||||
GROUP BY t.supplier_id, t.supplier_name
|
||||
|
||||
|
||||
</select>
|
||||
<select id="queryWarehouseInventorySupplierSummaryList"
|
||||
resultType="com.bonus.canteen.core.reportforms.beans.InventoryGoodsSummaryVO">
|
||||
select
|
||||
ds.supplier_id,
|
||||
dsl.supplier_name as supplierName,
|
||||
aa.area_name,
|
||||
dw.warehouse_id,
|
||||
dw.warehouse_name,
|
||||
sum(ds.into_num) as intoNum,
|
||||
sum(ds.into_amount) as intoAmount,
|
||||
sum(ds.out_num) as outNum,
|
||||
sum(ds.out_amount) as outAmount
|
||||
from report_drp_inventory_summary ds
|
||||
LEFT JOIN drp_supplier dsl ON ds.supplier_id = dsl.supplier_id
|
||||
LEFT JOIN drp_warehouse dw ON dw.warehouse_id = ds.warehouse_id
|
||||
LEFT JOIN alloc_area aa ON aa.area_id = dw.area_id
|
||||
<where>
|
||||
<if test="wrapper.param.startDate != null">
|
||||
and ds.statistic_date <![CDATA[ >= ]]> #{wrapper.param.startDate}
|
||||
</if>
|
||||
|
||||
<if test="wrapper.param.endDate != null">
|
||||
and ds.statistic_date <![CDATA[ <= ]]> #{wrapper.param.endDate}
|
||||
</if>
|
||||
|
||||
<if test="idList != null and idList.size() > 0">
|
||||
and ds.supplier_id in
|
||||
<foreach collection="idList" item="supplierId" open="(" close=")" separator=",">
|
||||
#{supplierId}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
<if test="wrapper.param.areaIdList != null and wrapper.param.areaIdList.size() > 0">
|
||||
and dw.area_id in
|
||||
<foreach collection="wrapper.param.areaIdList" item="item" open="(" close=")" separator=",">
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
<if test="wrapper.param.warehouseIdList != null and wrapper.param.warehouseIdList.size() > 0">
|
||||
and dw.warehouse_id in
|
||||
<foreach collection="wrapper.param.warehouseIdList" item="warehouseId" open="(" close=")" separator=",">
|
||||
#{warehouseId}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
<if test="wrapper.warehouseAuthority != null and wrapper.warehouseAuthority.size() > 0">
|
||||
and dw.warehouse_id in
|
||||
<foreach collection="wrapper.warehouseAuthority" item="warehouseId" open="(" close=")" separator=",">
|
||||
#{warehouseId}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
<if test="wrapper.areaAuth != null and wrapper.areaAuth.size() > 0">
|
||||
and dw.area_id in
|
||||
<foreach collection="wrapper.areaAuth" item="areaId" open="(" close=")" separator=",">
|
||||
#{areaId}
|
||||
</foreach>
|
||||
</if>
|
||||
</where>
|
||||
|
||||
GROUP BY ds.supplier_id, aa.area_name, dw.warehouse_id,
|
||||
dw.warehouse_name
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
|
||||
|
|
@ -0,0 +1,544 @@
|
|||
<?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.bonus.canteen.core.reportforms.mapper.DrpInventoryIntoDetailMapper">
|
||||
<!-- 结果映射:库存入库明细VO -->
|
||||
<resultMap type="com.bonus.canteen.core.reportforms.beans.DrpInventoryIntoDetailVO" id="DrpInventoryIntoDetailVOResult">
|
||||
<result property="recordId" column="record_id" />
|
||||
<result property="areaName" column="area_name" />
|
||||
<result property="warehouseId" column="warehouse_id" />
|
||||
<result property="warehouseName" column="warehouse_name" />
|
||||
<result property="intoType" column="intoType" />
|
||||
<result property="intoDate" column="intoDate" />
|
||||
<result property="intoNum" column="intoNum" />
|
||||
<result property="intoAmount" column="intoAmount" />
|
||||
<result property="operatorId" column="operator_id" />
|
||||
<result property="operatorName" column="operatorName" />
|
||||
<result property="goodsCode" column="goods_code" />
|
||||
<result property="goodsCategory" column="goods_category" />
|
||||
<result property="goodsCategoryName" column="goods_category_name" />
|
||||
<result property="goodsName" column="goods_name" />
|
||||
<result property="unitName" column="unit_name" />
|
||||
<result property="specification" column="specification" />
|
||||
<result property="price" column="price" />
|
||||
<result property="supplierId" column="supplier_id" />
|
||||
<result property="supplierName" column="supplier_name" />
|
||||
<result property="balanceNum" column="balance_num" />
|
||||
<result property="balanceAmount" column="balance_amount" />
|
||||
<result property="productionDate" column="production_date" />
|
||||
<result property="expiryDate" column="expiry_date" />
|
||||
</resultMap>
|
||||
|
||||
<!-- 结果映射:仓库VO -->
|
||||
<resultMap type="com.bonus.canteen.core.reportforms.beans.DrpWarehouseAllVO" id="DrpWarehouseAllVOResult">
|
||||
<result property="warehouseId" column="warehouse_id" />
|
||||
<result property="areaId" column="area_id" />
|
||||
<result property="warehouseName" column="warehouse_name" />
|
||||
</resultMap>
|
||||
|
||||
<!-- 查询库存入库明细列表 -->
|
||||
<select id="queryInventoryIntoDocDetail" resultMap="DrpInventoryIntoDetailVOResult"
|
||||
parameterType="com.bonus.canteen.core.reportforms.beans.DrpInventoryIntoDetailWrapper" >
|
||||
select de.material_id,
|
||||
mm.material_name as goods_name,
|
||||
mm.material_code as goods_code,
|
||||
mmc.category_id,
|
||||
mmc.category_name as goods_category_name,
|
||||
de.unit_id,
|
||||
du.unit_name,
|
||||
de.unit_price as price,
|
||||
aa.area_name,
|
||||
dw.warehouse_id,
|
||||
dw.warehouse_name,
|
||||
de.out_into_type intoType,
|
||||
de.supplier_id,
|
||||
ds.supplier_name,
|
||||
de.record_time intoDate,
|
||||
de.out_into_num intoNum,
|
||||
de.inventory_num balance_num,
|
||||
de.out_into_amount intoAmount,
|
||||
de.total_amount balance_amount,
|
||||
de.operator_id,
|
||||
IF
|
||||
(mu.real_name IS NULL OR mu.real_name = '', mu.username, mu.real_name) operatorName,
|
||||
de.product_date as production_date,
|
||||
de.expire_time as expiry_date,
|
||||
de.record_id,
|
||||
mm.size as specification
|
||||
from report_drp_inventory_base de
|
||||
LEFT JOIN menu_material mm ON de.material_id = mm.material_id
|
||||
LEFT JOIN drp_unit du ON de.unit_id = du.unit_id
|
||||
LEFT JOIN menu_material_category mmc ON mmc.category_id = mm.category_id
|
||||
left join drp_warehouse dw on dw.warehouse_id = de.warehouse_id
|
||||
left join alloc_area aa on aa.area_id = dw.area_id
|
||||
LEFT JOIN drp_supplier ds ON de.supplier_id = ds.supplier_id
|
||||
LEFT JOIN mgr_user mu ON de.operator_id = mu.username
|
||||
where de.record_type=1 and de.out_into_type in (1, 5)
|
||||
<if test="param.startDate != null">
|
||||
and de.record_date >= #{param.startDate}
|
||||
</if>
|
||||
|
||||
<if test="param.endDate != null">
|
||||
and de.record_date <= #{param.endDate}
|
||||
</if>
|
||||
|
||||
<if test="param.supplierIdList != null and param.supplierIdList.size() > 0">
|
||||
and de.supplier_id in
|
||||
<foreach collection="param.supplierIdList" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
<if test="param.materialName != null and param.materialName != ''">
|
||||
and (mm.material_name like concat('%', #{param.materialName}, '%')
|
||||
or mm.material_code like concat('%', #{param.materialName}, '%'))
|
||||
</if>
|
||||
|
||||
<if test="param.categoryIdList != null and param.categoryIdList.size() > 0">
|
||||
and mmc.category_id in
|
||||
<foreach collection="param.categoryIdList" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
<if test="param.intoTypeList != null and param.intoTypeList.size() > 0">
|
||||
and de.out_into_type in
|
||||
<foreach collection="param.intoTypeList" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
<if test="param.recordId != null and param.recordId != ''">
|
||||
and de.record_id like concat('%', #{param.recordId}, '%')
|
||||
</if>
|
||||
|
||||
<if test="param.areaIdList != null and param.areaIdList.size() > 0">
|
||||
and dw.area_id in
|
||||
<foreach collection="param.areaIdList" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
<if test="param.warehouseIdList != null and param.warehouseIdList.size() > 0">
|
||||
and dw.warehouse_id in
|
||||
<foreach collection="param.warehouseIdList" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
<if test="warehouseAuthority != null and warehouseAuthority.size() > 0">
|
||||
and dw.warehouse_id in
|
||||
<foreach collection="warehouseAuthority" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
<if test="areaAuth != null and areaAuth.size() > 0">
|
||||
and dw.area_id in
|
||||
<foreach collection="areaAuth" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
</select>
|
||||
<!-- 查询库存入库明细合计 -->
|
||||
<select id="queryInventoryIntoDocDetailSum" resultType="com.bonus.canteen.core.reportforms.beans.InventoryIntoSummaryVO"
|
||||
parameterType="com.bonus.canteen.core.reportforms.beans.DrpInventoryIntoDetailWrapper">
|
||||
|
||||
SELECT
|
||||
SUM(de.out_into_num) as totalInQty,
|
||||
SUM(de.out_into_amount) as totalInAmount,
|
||||
SUM(de.inventory_num) as totalStockQty,
|
||||
SUM(de.total_amount) as totalStockAmount
|
||||
FROM report_drp_inventory_base de
|
||||
LEFT JOIN menu_material mm ON de.material_id = mm.material_id
|
||||
LEFT JOIN drp_unit du ON de.unit_id = du.unit_id
|
||||
LEFT JOIN menu_material_category mmc ON mmc.category_id = mm.category_id
|
||||
LEFT JOIN drp_warehouse dw ON dw.warehouse_id = de.warehouse_id
|
||||
LEFT JOIN alloc_area aa ON aa.area_id = dw.area_id
|
||||
LEFT JOIN drp_supplier ds ON de.supplier_id = ds.supplier_id
|
||||
LEFT JOIN mgr_user mu ON de.operator_id = mu.username
|
||||
WHERE de.record_type=1 AND de.out_into_type IN (1,5)
|
||||
|
||||
<!-- 以下条件和明细保持一模一样 -->
|
||||
<if test="param.startDate != null">
|
||||
AND de.record_date >= #{param.startDate}
|
||||
</if>
|
||||
<if test="param.endDate != null">
|
||||
AND de.record_date <= #{param.endDate}
|
||||
</if>
|
||||
<if test="param.supplierIdList != null and param.supplierIdList.size() > 0">
|
||||
AND de.supplier_id IN
|
||||
<foreach collection="param.supplierIdList" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="param.materialName != null and param.materialName != ''">
|
||||
AND (mm.material_name LIKE concat('%',#{param.materialName},'%')
|
||||
OR mm.material_code LIKE concat('%',#{param.materialName},'%'))
|
||||
</if>
|
||||
<if test="param.categoryIdList != null and param.categoryIdList.size() > 0">
|
||||
AND mmc.category_id IN
|
||||
<foreach collection="param.categoryIdList" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="param.intoTypeList != null and param.intoTypeList.size() > 0">
|
||||
AND de.out_into_type IN
|
||||
<foreach collection="param.intoTypeList" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="param.recordId != null and param.recordId != ''">
|
||||
AND de.record_id LIKE concat('%',#{param.recordId},'%')
|
||||
</if>
|
||||
<if test="param.areaIdList != null and param.areaIdList.size() > 0">
|
||||
AND dw.area_id IN
|
||||
<foreach collection="param.areaIdList" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="param.warehouseIdList != null and param.warehouseIdList.size() > 0">
|
||||
AND dw.warehouse_id IN
|
||||
<foreach collection="param.warehouseIdList" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="warehouseAuthority != null and warehouseAuthority.size() > 0">
|
||||
AND dw.warehouse_id IN
|
||||
<foreach collection="warehouseAuthority" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="areaAuth != null and areaAuth.size() > 0">
|
||||
AND dw.area_id IN
|
||||
<foreach collection="areaAuth" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="queryInventoryOutDetail"
|
||||
resultType="com.bonus.canteen.core.reportforms.beans.DrpInventoryoutDetailVO"
|
||||
parameterType="com.bonus.canteen.core.reportforms.beans.DrpInventoryIntoDetailWrapper">
|
||||
SELECT
|
||||
de.material_id,
|
||||
mm.material_name AS goods_name,
|
||||
mm.material_code AS goods_code,
|
||||
mmc.category_id,
|
||||
mmc.category_name AS goods_category_name,
|
||||
de.unit_id,
|
||||
du.unit_name,
|
||||
de.unit_price AS price,
|
||||
aa.area_name,
|
||||
dw.warehouse_id,
|
||||
dw.warehouse_name,
|
||||
de.out_into_type AS intoType,
|
||||
de.fetch_user_id AS supplier_id,
|
||||
NULL AS supplier_name,
|
||||
de.record_time AS intoDate,
|
||||
|
||||
-- 数量:退单为负
|
||||
CASE
|
||||
WHEN de.record_type = 1 AND de.out_into_type = 6
|
||||
THEN -de.out_into_num
|
||||
ELSE de.out_into_num
|
||||
END AS intoNum,
|
||||
|
||||
de.inventory_num AS balance_num,
|
||||
|
||||
-- 金额:退单为负
|
||||
CASE
|
||||
WHEN de.record_type = 1 AND de.out_into_type = 6
|
||||
THEN -de.out_into_amount
|
||||
ELSE de.out_into_amount
|
||||
END AS intoAmount,
|
||||
|
||||
de.total_amount AS balance_amount,
|
||||
de.fetch_user_id AS operator_id,
|
||||
IF(mu.real_name IS NULL OR mu.real_name = '',
|
||||
mu.username,
|
||||
mu.real_name) AS operatorName,
|
||||
de.product_date AS production_date,
|
||||
de.expire_time AS expiry_date,
|
||||
de.record_id,
|
||||
mm.size AS specification,
|
||||
|
||||
-- 标识:1=退单,0=正常
|
||||
CASE
|
||||
WHEN de.record_type = 1 AND de.out_into_type = 6
|
||||
THEN 1
|
||||
ELSE 0
|
||||
END AS record_type_flag
|
||||
|
||||
FROM report_drp_inventory_base de
|
||||
LEFT JOIN menu_material mm ON de.material_id = mm.material_id
|
||||
LEFT JOIN drp_unit du ON de.unit_id = du.unit_id
|
||||
LEFT JOIN menu_material_category mmc ON mmc.category_id = mm.category_id
|
||||
LEFT JOIN drp_warehouse dw ON dw.warehouse_id = de.warehouse_id
|
||||
LEFT JOIN alloc_area aa ON aa.area_id = dw.area_id
|
||||
LEFT JOIN mgr_user mu ON de.fetch_user_id = mu.user_id
|
||||
|
||||
WHERE
|
||||
(
|
||||
-- 正常入库
|
||||
(de.record_type = 2 AND de.out_into_type IN (1,3,5,6))
|
||||
|
||||
OR
|
||||
|
||||
-- 超市退单(直接负数,不依赖 order_info/order_refund)
|
||||
(de.record_type = 1 AND de.out_into_type = 6)
|
||||
)
|
||||
|
||||
<if test="param.startDate != null">
|
||||
AND de.record_date >= #{param.startDate}
|
||||
</if>
|
||||
<if test="param.endDate != null">
|
||||
AND de.record_date <= #{param.endDate}
|
||||
</if>
|
||||
|
||||
<if test="param.supplierIdList != null and param.supplierIdList.size() > 0">
|
||||
AND de.fetch_user_id IN
|
||||
<foreach collection="param.supplierIdList" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
<if test="param.materialName != null and param.materialName != ''">
|
||||
AND (mm.material_name LIKE CONCAT('%', #{param.materialName}, '%')
|
||||
OR mm.material_code LIKE CONCAT('%', #{param.materialName}, '%'))
|
||||
</if>
|
||||
|
||||
<if test="param.categoryIdList != null and param.categoryIdList.size() > 0">
|
||||
AND mmc.category_id IN
|
||||
<foreach collection="param.categoryIdList" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
<if test="param.intoTypeList != null and param.intoTypeList.size() > 0">
|
||||
AND de.out_into_type IN
|
||||
<foreach collection="param.intoTypeList" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
<if test="param.recordId != null and param.recordId != ''">
|
||||
AND de.record_id LIKE CONCAT('%', #{param.recordId}, '%')
|
||||
</if>
|
||||
|
||||
<if test="param.areaIdList != null and param.areaIdList.size() > 0">
|
||||
AND dw.area_id IN
|
||||
<foreach collection="param.areaIdList" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
<if test="param.warehouseIdList != null and param.warehouseIdList.size() > 0">
|
||||
AND dw.warehouse_id IN
|
||||
<foreach collection="param.warehouseIdList" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
<if test="warehouseAuthority != null and warehouseAuthority.size() > 0">
|
||||
AND dw.warehouse_id IN
|
||||
<foreach collection="warehouseAuthority" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
<if test="areaAuth != null and areaAuth.size() > 0">
|
||||
AND dw.area_id IN
|
||||
<foreach collection="areaAuth" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
ORDER BY record_type_flag DESC, intoDate DESC
|
||||
|
||||
</select>
|
||||
|
||||
<!-- 获取租户仓库列表(带权限控制) -->
|
||||
<select id="getTenantWarehouse" resultMap="DrpWarehouseAllVOResult">
|
||||
SELECT
|
||||
a.warehouse_id,
|
||||
a.warehouse_name,
|
||||
a.warehouse_num,
|
||||
a.address,
|
||||
a.fetch_user_id,
|
||||
IF(mu.real_name IS NULL OR mu.real_name = '', mu.username, mu.real_name) AS fetchUserName
|
||||
FROM drp_warehouse a
|
||||
LEFT JOIN alloc_area aa ON aa.area_id = a.area_id
|
||||
LEFT JOIN mgr_user mu ON a.fetch_user_id = mu.user_id
|
||||
WHERE a.del_flag = 2
|
||||
AND a.status = 2
|
||||
|
||||
<if test="areaAuth != null and areaAuth.length > 0">
|
||||
AND (
|
||||
a.area_id IN
|
||||
<foreach collection="areaAuth" item="item" open="(" close=")" separator=",">
|
||||
#{item}
|
||||
</foreach>
|
||||
OR a.area_id IS NULL
|
||||
)
|
||||
</if>
|
||||
|
||||
</select>
|
||||
|
||||
<!-- 获取用户有权限的仓库ID列表 -->
|
||||
<select id="getTenantWarehouseIds" resultType="java.lang.Long">
|
||||
SELECT DISTINCT rw.warehouse_id
|
||||
FROM mgr_role_warehouse rw
|
||||
JOIN mgr_role r ON rw.role_id = r.role_id
|
||||
WHERE r.role_code = '-1'
|
||||
AND r.del_flag = 2;
|
||||
|
||||
</select>
|
||||
|
||||
<!-- 获取用户有权限的区域ID列表 -->
|
||||
<select id="getTenantAreaIds" resultType="java.lang.Long">
|
||||
SELECT DISTINCT d.area_id
|
||||
FROM drp_warehouse d
|
||||
WHERE d.area_id IS NOT NULL
|
||||
</select>
|
||||
|
||||
<!-- 获取供应商列表 -->
|
||||
<select id="getSupplierList" resultType="com.bonus.canteen.core.reportforms.beans.DrpSupplierVO">
|
||||
SELECT
|
||||
ds.supplier_id,
|
||||
ds.supplier_name,
|
||||
ds.supplier_score,
|
||||
ds.area_id,
|
||||
aa.area_name
|
||||
FROM
|
||||
drp_supplier ds
|
||||
LEFT JOIN alloc_area aa ON aa.area_id = ds.area_id
|
||||
where ds.status = 2
|
||||
and ds.del_flag = 2
|
||||
<if test="content != null and content.size() > 0">
|
||||
and (
|
||||
ds.area_id in
|
||||
<foreach collection="content" item="item" separator="," open="(" close=")">
|
||||
#{item}
|
||||
</foreach>
|
||||
or ds.area_id is null
|
||||
)
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<!-- 获取货品类别字典(树形结构) -->
|
||||
<select id="getGoodsCategoryDict" resultType="com.bonus.canteen.core.reportforms.beans.DrpDictVO">
|
||||
SELECT
|
||||
mmc.category_id AS id,
|
||||
CASE
|
||||
WHEN mmc.area_id IS NOT NULL AND aa.area_name IS NOT NULL
|
||||
THEN CONCAT(mmc.category_name, '(', aa.area_name, ')')
|
||||
ELSE mmc.category_name
|
||||
END AS dictLabel,
|
||||
mmc.parent_id,
|
||||
mmc.area_id,
|
||||
mmc.category_type,
|
||||
mmc.level
|
||||
FROM menu_material_category mmc
|
||||
LEFT JOIN alloc_area aa ON aa.area_id = mmc.area_id
|
||||
WHERE mmc.del_flag = 2
|
||||
|
||||
<if test="areaAuth != null and areaAuth.size() > 0">
|
||||
AND (
|
||||
mmc.area_id IN
|
||||
<foreach collection="areaAuth" item="item" open="(" close=")" separator=",">
|
||||
#{item}
|
||||
</foreach>
|
||||
OR mmc.area_id IS NULL
|
||||
)
|
||||
</if>
|
||||
ORDER BY parent_id, category_type, category_id
|
||||
</select>
|
||||
<select id="queryInventoryIntoDocDetailoutSum"
|
||||
resultType="com.bonus.canteen.core.reportforms.beans.InventoryIntoSummaryVO">
|
||||
SELECT
|
||||
SUM(combined.intoNum) AS totalInQty,
|
||||
SUM(combined.intoAmount) AS totalInAmount,
|
||||
SUM(combined.balance_num) AS totalStockQty,
|
||||
SUM(combined.balance_amount) AS totalStockAmount
|
||||
FROM (
|
||||
-- 正常入库 + 退单负数
|
||||
SELECT
|
||||
-- 数量:退单为负
|
||||
CASE
|
||||
WHEN de.record_type = 1 AND de.out_into_type = 6
|
||||
THEN -de.out_into_num
|
||||
ELSE de.out_into_num
|
||||
END AS intoNum,
|
||||
|
||||
-- 金额:退单为负
|
||||
CASE
|
||||
WHEN de.record_type = 1 AND de.out_into_type = 6
|
||||
THEN -de.out_into_amount
|
||||
ELSE de.out_into_amount
|
||||
END AS intoAmount,
|
||||
|
||||
de.inventory_num AS balance_num,
|
||||
de.total_amount AS balance_amount
|
||||
|
||||
FROM report_drp_inventory_base de
|
||||
LEFT JOIN menu_material mm ON de.material_id = mm.material_id
|
||||
LEFT JOIN drp_unit du ON de.unit_id = du.unit_id
|
||||
LEFT JOIN menu_material_category mmc ON mmc.category_id = mm.category_id
|
||||
LEFT JOIN drp_warehouse dw ON dw.warehouse_id = de.warehouse_id
|
||||
LEFT JOIN alloc_area aa ON aa.area_id = dw.area_id
|
||||
|
||||
WHERE
|
||||
(
|
||||
-- 正常入库
|
||||
(de.record_type = 2 AND de.out_into_type IN (1,3,5,6))
|
||||
OR
|
||||
-- 退单
|
||||
(de.record_type = 1 AND de.out_into_type = 6)
|
||||
)
|
||||
|
||||
<if test="param.startDate != null">
|
||||
AND de.record_date >= #{param.startDate}
|
||||
</if>
|
||||
<if test="param.endDate != null">
|
||||
AND de.record_date <= #{param.endDate}
|
||||
</if>
|
||||
|
||||
<if test="param.materialName != null and param.materialName != ''">
|
||||
AND (mm.material_name LIKE CONCAT('%', #{param.materialName}, '%')
|
||||
OR mm.material_code LIKE CONCAT('%', #{param.materialName}, '%'))
|
||||
</if>
|
||||
|
||||
<if test="param.areaIdList != null and param.areaIdList.size() > 0">
|
||||
AND dw.area_id IN
|
||||
<foreach collection="param.areaIdList" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
<if test="param.warehouseIdList != null and param.warehouseIdList.size() > 0">
|
||||
AND dw.warehouse_id IN
|
||||
<foreach collection="param.warehouseIdList" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
<if test="warehouseAuthority != null and warehouseAuthority.size() > 0">
|
||||
AND dw.warehouse_id IN
|
||||
<foreach collection="warehouseAuthority" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
<if test="areaAuth != null and areaAuth.size() > 0">
|
||||
AND dw.area_id IN
|
||||
<foreach collection="areaAuth" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
) AS combined
|
||||
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,136 @@
|
|||
<?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.bonus.canteen.core.reportforms.mapper.PlaceMapper">
|
||||
|
||||
<select id="placeexportExcel" resultType="com.bonus.canteen.core.reportforms.beans.ReportOrderInfoVo">
|
||||
SELECT
|
||||
a.order_id,
|
||||
a.cust_id,
|
||||
ci.cust_num,
|
||||
ci.cust_name,
|
||||
ci.mobile,
|
||||
CASE WHEN ac.canteen_type = '1' THEN '食堂' ELSE '超市' END AS order_type,
|
||||
co.org_name,
|
||||
co.org_full_name,
|
||||
a.payable_amount,
|
||||
a.real_amount,
|
||||
a.pay_time,
|
||||
ac.area_id,
|
||||
ar.area_name,
|
||||
p.dining_place_id,
|
||||
ap.area_name AS work_area_name,
|
||||
a.mch_sn
|
||||
FROM (
|
||||
SELECT
|
||||
a.flow_id AS order_id,
|
||||
a.cust_id,
|
||||
a.flow_amount AS payable_amount,
|
||||
a.flow_real_amount AS real_amount,
|
||||
a.pay_time,
|
||||
CASE
|
||||
WHEN bd.area_id IS NOT NULL THEN bd.area_id
|
||||
WHEN ac.area_id IS NOT NULL THEN ac.area_id
|
||||
WHEN cdp.dining_place_id IS NOT NULL THEN cdp.dining_place_id
|
||||
ELSE a.canteen_id
|
||||
END AS area_id,
|
||||
CONCAT(a.cust_id, a.ord_time) AS id,
|
||||
CASE
|
||||
WHEN bd.canteen_id IS NOT NULL THEN bd.canteen_id
|
||||
WHEN roi.canteen_id IS NOT NULL THEN roi.canteen_id
|
||||
ELSE a.canteen_id
|
||||
END AS canteen_id,
|
||||
a.mch_sn AS mch_sn
|
||||
FROM (
|
||||
SELECT *
|
||||
FROM report_account_flow a
|
||||
WHERE a.pay_time >= #{startTime}
|
||||
AND a.flow_type IN (110, 120)
|
||||
AND a.pay_time <= #{endTime}
|
||||
) a
|
||||
LEFT JOIN device_info di ON a.mch_sn = di.device_sn
|
||||
LEFT JOIN device_bind bd ON di.device_id = bd.device_id
|
||||
LEFT JOIN (
|
||||
SELECT *
|
||||
FROM report_order_info a
|
||||
WHERE a.pay_time >= #{startTime}
|
||||
AND a.pay_time <= #{endTime}
|
||||
) roi ON CONCAT(a.cust_id, a.ord_time) = CONCAT(roi.cust_id, roi.order_time)
|
||||
LEFT JOIN alloc_canteen ac ON ac.canteen_id = roi.canteen_id
|
||||
LEFT JOIN cust_dining_place cdp ON a.cust_id = cdp.cust_id AND cdp.type = 'area'
|
||||
|
||||
UNION
|
||||
|
||||
SELECT
|
||||
rf.flow_id AS order_id,
|
||||
rf.cust_id,
|
||||
rf.flow_amount AS payable_amount,
|
||||
rf.flow_real_amount AS real_amount,
|
||||
rf.pay_time,
|
||||
CASE
|
||||
WHEN bd.area_id IS NOT NULL THEN bd.area_id
|
||||
WHEN ac.area_id IS NOT NULL THEN ac.area_id
|
||||
WHEN cdp.dining_place_id IS NOT NULL THEN cdp.dining_place_id
|
||||
ELSE COALESCE(ori.canteen_id, rf.canteen_id)
|
||||
END AS area_id,
|
||||
CONCAT(rf.cust_id, rf.ord_time) AS id,
|
||||
CASE
|
||||
WHEN bd.canteen_id IS NOT NULL THEN bd.canteen_id
|
||||
WHEN roi.canteen_id IS NOT NULL THEN roi.canteen_id
|
||||
ELSE COALESCE(ori.canteen_id, rf.canteen_id)
|
||||
END AS canteen_id,
|
||||
COALESCE(ori.mch_sn, rf.mch_sn) AS mch_sn
|
||||
FROM (
|
||||
SELECT *
|
||||
FROM report_account_flow a
|
||||
WHERE a.flow_type = 130
|
||||
AND a.pay_time >= #{startTime}
|
||||
AND a.pay_time <= #{endTime}
|
||||
) rf
|
||||
LEFT JOIN acc_trade atr ON rf.flow_id = atr.id
|
||||
LEFT JOIN report_account_flow ori ON atr.origin_trade_id = ori.flow_id
|
||||
LEFT JOIN device_info di ON COALESCE(ori.mch_sn, rf.mch_sn) = di.device_sn
|
||||
LEFT JOIN device_bind bd ON di.device_id = bd.device_id
|
||||
LEFT JOIN (
|
||||
SELECT *
|
||||
FROM report_order_info a
|
||||
WHERE a.pay_time >= #{startTime}
|
||||
AND a.pay_time <= #{endTime}
|
||||
) roi ON (
|
||||
(ori.cust_id IS NOT NULL AND CONCAT(ori.cust_id, ori.ord_time) = CONCAT(roi.cust_id, roi.order_time))
|
||||
OR (ori.cust_id IS NULL AND CONCAT(rf.cust_id, rf.ord_time) = CONCAT(roi.cust_id, roi.order_time))
|
||||
)
|
||||
LEFT JOIN alloc_canteen ac ON ac.canteen_id = roi.canteen_id
|
||||
LEFT JOIN cust_dining_place cdp ON rf.cust_id = cdp.cust_id AND cdp.type = 'area'
|
||||
WHERE rf.flow_id IS NOT NULL
|
||||
) a
|
||||
LEFT JOIN alloc_canteen ac ON ac.canteen_id = a.canteen_id
|
||||
LEFT JOIN cust_info ci ON ci.cust_id = a.cust_id
|
||||
LEFT JOIN cust_org co ON co.org_id = ci.org_id
|
||||
JOIN cust_dining_place p ON p.cust_id = ci.cust_id AND p.type = 'area'
|
||||
LEFT JOIN alloc_area ar ON ar.area_id = a.area_id
|
||||
LEFT JOIN alloc_area ap ON ap.area_id = p.dining_place_id
|
||||
WHERE 1=1
|
||||
<if test="commonOrg != 1">
|
||||
AND ar.area_id != p.dining_place_id
|
||||
</if>
|
||||
<!-- 判断消费地 -->
|
||||
<if test="selectedOrg != null and selectedOrg.length > 0">
|
||||
AND ar.area_id IN
|
||||
<foreach collection="selectedOrg" item="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
<!-- 判断工作地 -->
|
||||
<if test="gzselectedOrg != null and gzselectedOrg.length > 0">
|
||||
AND p.dining_place_id IN
|
||||
<foreach collection="gzselectedOrg" item="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
ORDER BY a.pay_time DESC
|
||||
<if test="pageNum != null and pageSize != null">
|
||||
LIMIT #{offset}, #{pageSize}
|
||||
</if>
|
||||
|
||||
</select>
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue