商品库存流水

This commit is contained in:
Tankaikai
2025-03-13 16:51:30 +08:00
parent 1a25ac2b9a
commit 78b1990b60
6 changed files with 266 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
package com.czg.service.product.mapper;
import com.czg.product.entity.ProductStockFlow;
import com.czg.product.param.ProductInfoParam;
import com.czg.product.vo.ProductStatisticsVo;
import com.mybatisflex.core.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
/**
* 商品库存变动记录
*
* @author Tankaikai tankaikai@aliyun.com
* @since 1.0 2025-02-21
*/
@Mapper
public interface ProductStockFlowMapper extends BaseMapper<ProductStockFlow> {
ProductStatisticsVo getProductStatistics(ProductInfoParam param);
}

View File

@@ -0,0 +1,32 @@
<?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.czg.service.product.mapper.ProductStockFlowMapper">
<select id="getProductStatistics" resultType="com.czg.product.vo.ProductStatisticsVo">
SELECT
sum( CASE WHEN t1.in_out_type = 'in' then t1.in_out_number end) AS inSumTotal,
sum( CASE WHEN t1.in_out_item = 'win-in' THEN t1.in_out_number END ) AS winInNum,
sum( CASE WHEN t1.in_out_item = 'order-in' THEN t1.in_out_number END ) AS refundInNum,
sum( CASE WHEN t1.in_out_type = 'out' then abs(t1.in_out_number) end) AS outSumTotal,
sum( CASE WHEN t1.in_out_item = 'loss-out' THEN abs(t1.in_out_number) END ) AS lossOutNum,
sum( CASE WHEN t1.in_out_item = 'order-out' THEN abs(t1.in_out_number) END ) AS salesNum,
sum( CASE WHEN t1.in_out_item = 'damage-out' THEN abs(t1.in_out_number) END ) AS damageNum
FROM
tb_product_stock_flow t1
LEFT JOIN tb_product t2 on t1.product_id = t2.id
where t1.shop_id = #{shopId}
<if test="id != null">
and t1.product_id = #{id}
</if>
<if test="categoryId != null">
and t2.category_id = #{categoryId}
</if>
<if test="name != null and name != ''">
and t2.name like concat('%', #{name}, '%') or t1.product_name like concat('%', #{name}, '%')
</if>
<if test="type != null and type != ''">
and t2.type = #{type}
</if>
</select>
</mapper>