商品库存流水
This commit is contained in:
parent
1a25ac2b9a
commit
78b1990b60
|
|
@ -0,0 +1,98 @@
|
|||
package com.czg.product.entity;
|
||||
|
||||
import com.mybatisflex.annotation.Column;
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.KeyType;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 商品库存变动记录
|
||||
*
|
||||
* @author Tankaikai tankaikai@aliyun.com
|
||||
* @since 1.0 2025-02-21
|
||||
*/
|
||||
@Data
|
||||
@Table("tb_product_stock_flow")
|
||||
public class ProductStockFlow implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@Id(keyType = KeyType.Auto)
|
||||
private Long id;
|
||||
/**
|
||||
* 店铺id
|
||||
*/
|
||||
private Long shopId;
|
||||
/**
|
||||
* 出入库类型 in-入库 out-出库
|
||||
*/
|
||||
private String inOutType;
|
||||
/**
|
||||
* 出入库名目 manual-in:手动入库 manual-out:手动出库 win-in:盘盈入库 loss-out:盘亏出库 order-in:订单退款入库 order-out:订单消费出库 damage-out:损耗出库
|
||||
*/
|
||||
private String inOutItem;
|
||||
/**
|
||||
* 出入库日期
|
||||
*/
|
||||
private LocalDate inOutDate;
|
||||
/**
|
||||
* 商品id
|
||||
*/
|
||||
private Long productId;
|
||||
/**
|
||||
* 商品名称
|
||||
*/
|
||||
private String productName;
|
||||
/**
|
||||
* 单位
|
||||
*/
|
||||
private String unitName;
|
||||
/**
|
||||
* 变动前的库存
|
||||
*/
|
||||
private BigDecimal beforeNumber;
|
||||
/**
|
||||
* 出入库数量
|
||||
*/
|
||||
private BigDecimal inOutNumber;
|
||||
/**
|
||||
* 变动后的库存
|
||||
*/
|
||||
private BigDecimal afterNumber;
|
||||
/**
|
||||
* 商品订单id
|
||||
*/
|
||||
private Long orderId;
|
||||
/**
|
||||
* 相关图片urls,json数组
|
||||
*/
|
||||
private String imgUrls;
|
||||
/**
|
||||
* 创建人id
|
||||
*/
|
||||
private Long createUserId;
|
||||
/**
|
||||
* 创建人name
|
||||
*/
|
||||
private String createUserName;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@Column(onInsertValue = "now()")
|
||||
private LocalDateTime createTime;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
package com.czg.product.param;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 商品出入库数据统计入参
|
||||
* @author tankaikai
|
||||
* @since 2025-03-12 17:30
|
||||
*/
|
||||
@Data
|
||||
public class ProductInfoParam implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
/**
|
||||
* 商品id
|
||||
*/
|
||||
private Long id;
|
||||
/**
|
||||
* 商品分类id
|
||||
*/
|
||||
private Long categoryId;
|
||||
/**
|
||||
* 商品类型 single-单规格商品 sku-多规格商品 package-套餐商品 weight-称重商品 coupon-团购券
|
||||
*/
|
||||
private String type;
|
||||
/**
|
||||
* 商品名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 店铺id
|
||||
*/
|
||||
@JSONField(serialize = false)
|
||||
private Long shopId;
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package com.czg.product.param;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 商品出入库流水查询
|
||||
* @author tankaikai
|
||||
* @since 2025-03-13 15:59
|
||||
*/
|
||||
@Data
|
||||
public class ProductStockFlowParam implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
/**
|
||||
* 商品id
|
||||
*/
|
||||
private Long productId;
|
||||
/**
|
||||
* 出入库类型 in-增加 out-减少
|
||||
*/
|
||||
private String inOutType;
|
||||
/**
|
||||
* 出入库名目 win-in:手动增加 order-in:退货 loss-out:手动减少 order-out:销售量 damage-out:报损
|
||||
*/
|
||||
private String inOutItem;
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
package com.czg.product.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 商品统计
|
||||
* @author tankaikai
|
||||
* @since 2025-03-12 17:34
|
||||
*/
|
||||
@Data
|
||||
public class ProductStatisticsVo implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 增加数量
|
||||
*/
|
||||
private BigDecimal inSumTotal = BigDecimal.ZERO;
|
||||
/**
|
||||
* 盘盈增加数量(手动增加)
|
||||
*/
|
||||
private BigDecimal winInNum = BigDecimal.ZERO;
|
||||
/**
|
||||
* 退货数量
|
||||
*/
|
||||
private BigDecimal refundInNum = BigDecimal.ZERO;
|
||||
/**
|
||||
* 减少数量
|
||||
*/
|
||||
private BigDecimal outSumTotal = BigDecimal.ZERO;
|
||||
/**
|
||||
* 盘亏减少数量(手动减少)
|
||||
*/
|
||||
private BigDecimal lossOutNum = BigDecimal.ZERO;
|
||||
/**
|
||||
* 销售数量
|
||||
*/
|
||||
private BigDecimal salesNum = BigDecimal.ZERO;
|
||||
/**
|
||||
* 报损数量
|
||||
*/
|
||||
private BigDecimal damageNum = BigDecimal.ZERO;
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
|
@ -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>
|
||||
Loading…
Reference in New Issue