fix GaoProductStockRecordPageResult

This commit is contained in:
Timi
2026-10-16 01:33:17 +08:00
parent a4abdc0632
commit adaadcbe51
13 changed files with 85 additions and 82 deletions
@@ -12,9 +12,9 @@ import com.imyeyu.api.modules.gao.vo.GaoProductStockChangeRequest;
import com.imyeyu.api.modules.gao.vo.GaoProductStockManualInBatchRequest; import com.imyeyu.api.modules.gao.vo.GaoProductStockManualInBatchRequest;
import com.imyeyu.api.modules.gao.vo.GaoProductStockManualRevokeRequest; import com.imyeyu.api.modules.gao.vo.GaoProductStockManualRevokeRequest;
import com.imyeyu.api.modules.gao.vo.GaoProductStockPage; import com.imyeyu.api.modules.gao.vo.GaoProductStockPage;
import com.imyeyu.api.modules.gao.vo.GaoProductStockPageResult;
import com.imyeyu.api.modules.gao.vo.GaoProductStockProductView; import com.imyeyu.api.modules.gao.vo.GaoProductStockProductView;
import com.imyeyu.api.modules.gao.vo.GaoProductStockRecordPage; import com.imyeyu.api.modules.gao.vo.GaoProductStockRecordPage;
import com.imyeyu.api.modules.gao.vo.GaoProductStockRecordPageResult;
import com.imyeyu.java.bean.timi.TimiException; import com.imyeyu.java.bean.timi.TimiException;
import com.imyeyu.spring.annotation.AOPLog; import com.imyeyu.spring.annotation.AOPLog;
import com.imyeyu.spring.annotation.RequestRateLimit; import com.imyeyu.spring.annotation.RequestRateLimit;
@@ -41,14 +41,11 @@ public class GaoProductStockController {
private final GaoProductStockRecordService recordService; private final GaoProductStockRecordService recordService;
private final GaoStoreScopeService storeScopeService; private final GaoStoreScopeService storeScopeService;
/// 分页查询产品库存;指定 SKU 时附带基础单位库存统计
/// @param page 分页与筛选条件
/// @return 库存分页结果,指定 SKU 时包含基础单位库存统计
@AOPLog @AOPLog
@RequestRateLimit @RequestRateLimit
@RequireGaoPermission(GaoPermissionCode.PRODUCT_STOCK_READ) @RequireGaoPermission(GaoPermissionCode.PRODUCT_STOCK_READ)
@PostMapping("/list") @PostMapping("/list")
public GaoProductStockPageResult list(@RequestBody GaoProductStockPage page) { public PageResult<GaoProductStock> list(@RequestBody GaoProductStockPage page) {
TimiException.required(page, "not found stock page"); TimiException.required(page, "not found stock page");
page.setStoreId(storeScopeService.resolveStoreId(page.getStoreId())); page.setStoreId(storeScopeService.resolveStoreId(page.getStoreId()));
return stockService.pageByQuery(page); return stockService.pageByQuery(page);
@@ -145,11 +142,15 @@ public class GaoProductStockController {
return stockService.stocktakeLoss(normalize(request)); return stockService.stocktakeLoss(normalize(request));
} }
/// 按条件分页查询库存流水并汇总 SKU 基础单位变动
/// @param page 流水分页与筛选条件
/// @return 流水分页及匹配条件下的 SKU 基础单位汇总
/// @throws TimiException 分页请求为空或门店范围校验失败
@AOPLog @AOPLog
@RequestRateLimit @RequestRateLimit
@RequireGaoPermission(GaoPermissionCode.PRODUCT_STOCK_READ) @RequireGaoPermission(GaoPermissionCode.PRODUCT_STOCK_READ)
@PostMapping("/record/list") @PostMapping("/record/list")
public PageResult<GaoProductStockRecord> recordList(@RequestBody GaoProductStockRecordPage page) { public GaoProductStockRecordPageResult recordList(@RequestBody GaoProductStockRecordPage page) {
TimiException.required(page, "not found stock record page"); TimiException.required(page, "not found stock record page");
page.setStoreId(storeScopeService.resolveStoreId(page.getStoreId())); page.setStoreId(storeScopeService.resolveStoreId(page.getStoreId()));
return recordService.pageByQuery(page); return recordService.pageByQuery(page);
@@ -2,7 +2,6 @@ package com.imyeyu.api.modules.gao.mapper;
import com.imyeyu.api.modules.gao.entity.GaoProductStock; import com.imyeyu.api.modules.gao.entity.GaoProductStock;
import com.imyeyu.api.modules.gao.vo.GaoProductStockPage; import com.imyeyu.api.modules.gao.vo.GaoProductStockPage;
import com.imyeyu.api.modules.gao.vo.GaoProductStockPageResult;
import com.imyeyu.api.modules.gao.vo.GaoProductStockProductView; import com.imyeyu.api.modules.gao.vo.GaoProductStockProductView;
import com.imyeyu.spring.mapper.BaseMapper; import com.imyeyu.spring.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
@@ -24,11 +23,6 @@ public interface GaoProductStockMapper extends BaseMapper<GaoProductStock, Strin
/// 按条件查询库存余额 /// 按条件查询库存余额
List<GaoProductStock> selectByQuery(GaoProductStockPage page); List<GaoProductStock> selectByQuery(GaoProductStockPage page);
/// 按条件统计基础单位库存数量
/// @param page 库存分页查询条件
/// @return 匹配 SKU 的库存数量汇总,数量均为基础单位
GaoProductStockPageResult selectQuantitySummaryByQuery(GaoProductStockPage page);
/// 按产品汇总库存数量 /// 按产品汇总库存数量
long countProductByQuery(GaoProductStockPage page); long countProductByQuery(GaoProductStockPage page);
@@ -2,6 +2,7 @@ package com.imyeyu.api.modules.gao.mapper;
import com.imyeyu.api.modules.gao.entity.GaoProductStockRecord; import com.imyeyu.api.modules.gao.entity.GaoProductStockRecord;
import com.imyeyu.api.modules.gao.vo.GaoProductStockRecordPage; import com.imyeyu.api.modules.gao.vo.GaoProductStockRecordPage;
import com.imyeyu.api.modules.gao.vo.GaoProductStockRecordSkuSummaryView;
import com.imyeyu.spring.mapper.BaseMapper; import com.imyeyu.spring.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
@@ -33,4 +34,9 @@ public interface GaoProductStockRecordMapper extends BaseMapper<GaoProductStockR
/// 按条件查询库存流水 /// 按条件查询库存流水
List<GaoProductStockRecord> selectByQuery(GaoProductStockRecordPage page); List<GaoProductStockRecord> selectByQuery(GaoProductStockRecordPage page);
/// 按条件统计指定 SKU 的出入库基础单位数量,不受分页字段限制
/// @param page 包含 SKU 和库存流水筛选条件的请求
/// @return 指定 SKU 的出入库基础单位数量
GaoProductStockRecordSkuSummaryView selectSkuBaseUnitSummaryByQuery(GaoProductStockRecordPage page);
} }
@@ -3,7 +3,7 @@ package com.imyeyu.api.modules.gao.service;
import com.imyeyu.api.modules.common.entity.Attachment; import com.imyeyu.api.modules.common.entity.Attachment;
import com.imyeyu.api.modules.gao.entity.GaoProductStockRecord; import com.imyeyu.api.modules.gao.entity.GaoProductStockRecord;
import com.imyeyu.api.modules.gao.vo.GaoProductStockRecordPage; import com.imyeyu.api.modules.gao.vo.GaoProductStockRecordPage;
import com.imyeyu.spring.bean.PageResult; import com.imyeyu.api.modules.gao.vo.GaoProductStockRecordPageResult;
import com.imyeyu.spring.service.BaseService; import com.imyeyu.spring.service.BaseService;
import java.util.List; import java.util.List;
@@ -14,8 +14,10 @@ import java.util.List;
/// @since 2026-09-02 /// @since 2026-09-02
public interface GaoProductStockRecordService extends BaseService<GaoProductStockRecord, String> { public interface GaoProductStockRecordService extends BaseService<GaoProductStockRecord, String> {
/// 按条件查询库存流水 /// 按条件查询库存流水;指定 SKU 时统计其出入库基础单位数量
PageResult<GaoProductStockRecord> pageByQuery(GaoProductStockRecordPage page); /// @param page 流水分页和统计筛选条件
/// @return 流水分页及匹配条件下的 SKU 基础单位汇总
GaoProductStockRecordPageResult pageByQuery(GaoProductStockRecordPage page);
/// 查询库存流水详情 /// 查询库存流水详情
GaoProductStockRecord detail(String id); GaoProductStockRecord detail(String id);
@@ -7,7 +7,6 @@ import com.imyeyu.api.modules.gao.vo.GaoProductStockChangeRequest;
import com.imyeyu.api.modules.gao.vo.GaoProductStockManualInBatchRequest; import com.imyeyu.api.modules.gao.vo.GaoProductStockManualInBatchRequest;
import com.imyeyu.api.modules.gao.vo.GaoProductStockManualRevokeRequest; import com.imyeyu.api.modules.gao.vo.GaoProductStockManualRevokeRequest;
import com.imyeyu.api.modules.gao.vo.GaoProductStockPage; import com.imyeyu.api.modules.gao.vo.GaoProductStockPage;
import com.imyeyu.api.modules.gao.vo.GaoProductStockPageResult;
import com.imyeyu.api.modules.gao.vo.GaoProductStockProductView; import com.imyeyu.api.modules.gao.vo.GaoProductStockProductView;
import com.imyeyu.api.modules.gao.vo.GaoStockChangeItem; import com.imyeyu.api.modules.gao.vo.GaoStockChangeItem;
import com.imyeyu.java.bean.timi.TimiException; import com.imyeyu.java.bean.timi.TimiException;
@@ -21,10 +20,8 @@ import java.util.List;
/// @since 2026-09-02 /// @since 2026-09-02
public interface GaoProductStockService { public interface GaoProductStockService {
/// 分页查询库存余额;指定 SKU 时附带基础单位库存统计 /// 查询库存余额
/// @param page 分页与筛选条件 PageResult<GaoProductStock> pageByQuery(GaoProductStockPage page);
/// @return 库存分页结果,指定 SKU 时包含基础单位库存统计
GaoProductStockPageResult pageByQuery(GaoProductStockPage page);
/// 按产品汇总查询库存 /// 按产品汇总查询库存
PageResult<GaoProductStockProductView> pageProductByQuery(GaoProductStockPage page); PageResult<GaoProductStockProductView> pageProductByQuery(GaoProductStockPage page);
@@ -10,12 +10,13 @@ import com.imyeyu.api.modules.gao.mapper.GaoProductStockRecordMapper;
import com.imyeyu.api.modules.gao.service.GaoCustomerService; import com.imyeyu.api.modules.gao.service.GaoCustomerService;
import com.imyeyu.api.modules.gao.service.GaoProductStockRecordService; import com.imyeyu.api.modules.gao.service.GaoProductStockRecordService;
import com.imyeyu.api.modules.gao.vo.GaoProductStockRecordPage; import com.imyeyu.api.modules.gao.vo.GaoProductStockRecordPage;
import com.imyeyu.api.modules.gao.vo.GaoProductStockRecordPageResult;
import com.imyeyu.api.modules.gao.vo.GaoProductStockRecordSkuSummaryView;
import com.imyeyu.api.modules.user.entity.User; import com.imyeyu.api.modules.user.entity.User;
import com.imyeyu.api.modules.user.service.UserService; import com.imyeyu.api.modules.user.service.UserService;
import com.imyeyu.java.TimiJava; import com.imyeyu.java.TimiJava;
import com.imyeyu.java.bean.timi.TimiCode; import com.imyeyu.java.bean.timi.TimiCode;
import com.imyeyu.java.bean.timi.TimiException; import com.imyeyu.java.bean.timi.TimiException;
import com.imyeyu.spring.bean.PageResult;
import com.imyeyu.spring.mapper.BaseMapper; import com.imyeyu.spring.mapper.BaseMapper;
import com.imyeyu.spring.service.AbstractEntityService; import com.imyeyu.spring.service.AbstractEntityService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@@ -45,12 +46,17 @@ public class GaoProductStockRecordServiceImplement extends AbstractEntityService
} }
@Override @Override
public PageResult<GaoProductStockRecord> pageByQuery(GaoProductStockRecordPage page) { public GaoProductStockRecordPageResult pageByQuery(GaoProductStockRecordPage page) {
TimiException.required(page, "not found stock record page"); TimiException.required(page, "not found stock record page");
PageResult<GaoProductStockRecord> result = new PageResult<>(); GaoProductStockRecordPageResult result = new GaoProductStockRecordPageResult();
result.setTotal(mapper.countByQuery(page)); result.setTotal(mapper.countByQuery(page));
result.setList(mapper.selectByQuery(page)); result.setList(mapper.selectByQuery(page));
fillTransient(result.getList()); fillTransient(result.getList());
if (page.getSkuId() != null && !page.getSkuId().isBlank()) {
GaoProductStockRecordSkuSummaryView summary = mapper.selectSkuBaseUnitSummaryByQuery(page);
result.setInBaseQuantityTotal(summary.getInBaseQuantityTotal());
result.setOutBaseQuantityTotal(summary.getOutBaseQuantityTotal());
}
return result; return result;
} }
@@ -19,7 +19,6 @@ import com.imyeyu.api.modules.gao.vo.GaoProductStockChangeRequest;
import com.imyeyu.api.modules.gao.vo.GaoProductStockManualInBatchRequest; import com.imyeyu.api.modules.gao.vo.GaoProductStockManualInBatchRequest;
import com.imyeyu.api.modules.gao.vo.GaoProductStockManualRevokeRequest; import com.imyeyu.api.modules.gao.vo.GaoProductStockManualRevokeRequest;
import com.imyeyu.api.modules.gao.vo.GaoProductStockPage; import com.imyeyu.api.modules.gao.vo.GaoProductStockPage;
import com.imyeyu.api.modules.gao.vo.GaoProductStockPageResult;
import com.imyeyu.api.modules.gao.vo.GaoProductStockProductView; import com.imyeyu.api.modules.gao.vo.GaoProductStockProductView;
import com.imyeyu.api.modules.gao.vo.GaoStockChangeItem; import com.imyeyu.api.modules.gao.vo.GaoStockChangeItem;
import com.imyeyu.api.modules.system.audit.AuditOperation; import com.imyeyu.api.modules.system.audit.AuditOperation;
@@ -63,16 +62,10 @@ public class GaoProductStockServiceImplement implements GaoProductStockService {
private final UserLoginService userLoginService; private final UserLoginService userLoginService;
@Override @Override
public GaoProductStockPageResult pageByQuery(GaoProductStockPage page) { public PageResult<GaoProductStock> pageByQuery(GaoProductStockPage page) {
TimiException.required(page, "not found stock page"); TimiException.required(page, "not found stock page");
GaoProductStockPageResult result = new GaoProductStockPageResult(); PageResult<GaoProductStock> result = new PageResult<>();
result.setTotal(stockMapper.countByQuery(page)); result.setTotal(stockMapper.countByQuery(page));
if (page.getSkuId() != null && !page.getSkuId().isBlank()) {
GaoProductStockPageResult summary = stockMapper.selectQuantitySummaryByQuery(page);
result.setOnHandQuantityTotal(summary.getOnHandQuantityTotal());
result.setReservedQuantityTotal(summary.getReservedQuantityTotal());
result.setAvailableQuantityTotal(summary.getAvailableQuantityTotal());
}
List<GaoProductStock> list = stockMapper.selectByQuery(page); List<GaoProductStock> list = stockMapper.selectByQuery(page);
Map<String, Attachment> photoMap = attachmentService.mapFirstImageByIdList( Map<String, Attachment> photoMap = attachmentService.mapFirstImageByIdList(
Attachment.BizType.GAO_PRODUCT_SKU, Attachment.BizType.GAO_PRODUCT_SKU,
@@ -18,9 +18,6 @@ public class GaoProductStockPage extends BasePage {
/// 产品 ID /// 产品 ID
private String productId; private String productId;
/// SKU ID
private String skuId;
/// 产品或 SKU 名称、拼音、编码、规格摘要关键词 /// 产品或 SKU 名称、拼音、编码、规格摘要关键词
private String keyword; private String keyword;
} }
@@ -1,26 +0,0 @@
package com.imyeyu.api.modules.gao.vo;
import com.imyeyu.api.modules.gao.entity.GaoProductStock;
import com.imyeyu.spring.bean.PageResult;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.math.BigDecimal;
/// GAO 产品库存分页查询结果
///
/// @author Codex
/// @since 2026-10-14
@Data
@EqualsAndHashCode(callSuper = true)
public class GaoProductStockPageResult extends PageResult<GaoProductStock> {
/// SKU 筛选条件下的实际库存合计,基础单位
private BigDecimal onHandQuantityTotal;
/// SKU 筛选条件下的已预占库存合计,基础单位
private BigDecimal reservedQuantityTotal;
/// SKU 筛选条件下的可用库存合计,基础单位
private BigDecimal availableQuantityTotal;
}
@@ -0,0 +1,26 @@
package com.imyeyu.api.modules.gao.vo;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.imyeyu.api.modules.gao.entity.GaoProductStockRecord;
import com.imyeyu.spring.bean.PageResult;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.math.BigDecimal;
/// GAO 库存流水分页查询结果
///
/// @author Codex
/// @since 2026-10-16
@Data
@EqualsAndHashCode(callSuper = true)
public class GaoProductStockRecordPageResult extends PageResult<GaoProductStockRecord> {
/// 指定 SKU 在查询条件下的入库基础单位数量合计
@JsonInclude(JsonInclude.Include.NON_NULL)
private BigDecimal inBaseQuantityTotal;
/// 指定 SKU 在查询条件下的出库基础单位数量合计
@JsonInclude(JsonInclude.Include.NON_NULL)
private BigDecimal outBaseQuantityTotal;
}
@@ -0,0 +1,19 @@
package com.imyeyu.api.modules.gao.vo;
import lombok.Data;
import java.math.BigDecimal;
/// 库存流水 SKU 基础单位统计
///
/// @author Codex
/// @since 2026-10-16
@Data
public class GaoProductStockRecordSkuSummaryView {
/// 入库基础单位数量合计
private BigDecimal inBaseQuantityTotal;
/// 出库基础单位数量合计
private BigDecimal outBaseQuantityTotal;
}
@@ -42,7 +42,6 @@
AND k.`stock_enabled` = 1 AND k.`status` = 'ACTIVE' AND k.`stock_enabled` = 1 AND k.`status` = 'ACTIVE'
<if test="storeId != null and storeId != ''">AND p.`store_id` = #{storeId}</if> <if test="storeId != null and storeId != ''">AND p.`store_id` = #{storeId}</if>
<if test="productId != null and productId != ''">AND k.`product_id` = #{productId}</if> <if test="productId != null and productId != ''">AND k.`product_id` = #{productId}</if>
<if test="skuId != null and skuId.trim() != ''">AND k.`id` = #{skuId}</if>
<if test="keyword != null and keyword.trim() != ''">AND (p.`code` LIKE CONCAT('%', #{keyword}, '%') OR p.`name` LIKE CONCAT('%', #{keyword}, '%') OR p.`name_pinyin_full` LIKE CONCAT(#{keyword}, '%') OR p.`name_pinyin_initial` LIKE CONCAT(#{keyword}, '%') OR p.`name_pinyin_mixed` LIKE CONCAT(#{keyword}, '%') OR k.`code` LIKE CONCAT('%', #{keyword}, '%') OR k.`name` LIKE CONCAT('%', #{keyword}, '%') OR k.`spec_summary` LIKE CONCAT('%', #{keyword}, '%') OR k.`barcode` LIKE CONCAT('%', #{keyword}, '%'))</if> <if test="keyword != null and keyword.trim() != ''">AND (p.`code` LIKE CONCAT('%', #{keyword}, '%') OR p.`name` LIKE CONCAT('%', #{keyword}, '%') OR p.`name_pinyin_full` LIKE CONCAT(#{keyword}, '%') OR p.`name_pinyin_initial` LIKE CONCAT(#{keyword}, '%') OR p.`name_pinyin_mixed` LIKE CONCAT(#{keyword}, '%') OR k.`code` LIKE CONCAT('%', #{keyword}, '%') OR k.`name` LIKE CONCAT('%', #{keyword}, '%') OR k.`spec_summary` LIKE CONCAT('%', #{keyword}, '%') OR k.`barcode` LIKE CONCAT('%', #{keyword}, '%'))</if>
</select> </select>
<select id="selectByQuery" resultType="com.imyeyu.api.modules.gao.entity.GaoProductStock"> <select id="selectByQuery" resultType="com.imyeyu.api.modules.gao.entity.GaoProductStock">
@@ -65,29 +64,10 @@
AND k.`stock_enabled` = 1 AND k.`status` = 'ACTIVE' AND k.`stock_enabled` = 1 AND k.`status` = 'ACTIVE'
<if test="storeId != null and storeId != ''">AND p.`store_id` = #{storeId}</if> <if test="storeId != null and storeId != ''">AND p.`store_id` = #{storeId}</if>
<if test="productId != null and productId != ''">AND k.`product_id` = #{productId}</if> <if test="productId != null and productId != ''">AND k.`product_id` = #{productId}</if>
<if test="skuId != null and skuId.trim() != ''">AND k.`id` = #{skuId}</if>
<if test="keyword != null and keyword.trim() != ''">AND (p.`code` LIKE CONCAT('%', #{keyword}, '%') OR p.`name` LIKE CONCAT('%', #{keyword}, '%') OR p.`name_pinyin_full` LIKE CONCAT(#{keyword}, '%') OR p.`name_pinyin_initial` LIKE CONCAT(#{keyword}, '%') OR p.`name_pinyin_mixed` LIKE CONCAT(#{keyword}, '%') OR k.`code` LIKE CONCAT('%', #{keyword}, '%') OR k.`name` LIKE CONCAT('%', #{keyword}, '%') OR k.`spec_summary` LIKE CONCAT('%', #{keyword}, '%') OR k.`barcode` LIKE CONCAT('%', #{keyword}, '%'))</if> <if test="keyword != null and keyword.trim() != ''">AND (p.`code` LIKE CONCAT('%', #{keyword}, '%') OR p.`name` LIKE CONCAT('%', #{keyword}, '%') OR p.`name_pinyin_full` LIKE CONCAT(#{keyword}, '%') OR p.`name_pinyin_initial` LIKE CONCAT(#{keyword}, '%') OR p.`name_pinyin_mixed` LIKE CONCAT(#{keyword}, '%') OR k.`code` LIKE CONCAT('%', #{keyword}, '%') OR k.`name` LIKE CONCAT('%', #{keyword}, '%') OR k.`spec_summary` LIKE CONCAT('%', #{keyword}, '%') OR k.`barcode` LIKE CONCAT('%', #{keyword}, '%'))</if>
ORDER BY p.`sort`, p.`name`, p.`code`, k.`sort`, k.`name`, k.`code` ORDER BY p.`sort`, p.`name`, p.`code`, k.`sort`, k.`name`, k.`code`
LIMIT #{offset}, #{limit} LIMIT #{offset}, #{limit}
</select> </select>
<select id="selectQuantitySummaryByQuery" resultType="com.imyeyu.api.modules.gao.vo.GaoProductStockPageResult">
SELECT COALESCE(SUM(COALESCE(s.`on_hand_quantity`, 0)), 0) AS `on_hand_quantity_total`,
COALESCE(SUM(COALESCE(s.`reserved_quantity`, 0)), 0) AS `reserved_quantity_total`,
COALESCE(SUM(COALESCE(s.`on_hand_quantity`, 0) - COALESCE(s.`reserved_quantity`, 0)), 0) AS `available_quantity_total`
FROM `gao_product_sku` k
JOIN `gao_product` p ON p.`id` = k.`product_id`
LEFT JOIN `gao_product_stock` s ON s.`sku_id` = k.`id`
<choose>
<when test="storeId != null and storeId != ''">AND s.`store_id` = #{storeId}</when>
<otherwise>AND s.`store_id` = k.`store_id`</otherwise>
</choose>
WHERE p.`deleted_at` IS NULL AND k.`deleted_at` IS NULL
AND k.`stock_enabled` = 1 AND k.`status` = 'ACTIVE'
<if test="storeId != null and storeId != ''">AND p.`store_id` = #{storeId}</if>
<if test="productId != null and productId != ''">AND k.`product_id` = #{productId}</if>
<if test="skuId != null and skuId.trim() != ''">AND k.`id` = #{skuId}</if>
<if test="keyword != null and keyword.trim() != ''">AND (p.`code` LIKE CONCAT('%', #{keyword}, '%') OR p.`name` LIKE CONCAT('%', #{keyword}, '%') OR p.`name_pinyin_full` LIKE CONCAT(#{keyword}, '%') OR p.`name_pinyin_initial` LIKE CONCAT(#{keyword}, '%') OR p.`name_pinyin_mixed` LIKE CONCAT(#{keyword}, '%') OR k.`code` LIKE CONCAT('%', #{keyword}, '%') OR k.`name` LIKE CONCAT('%', #{keyword}, '%') OR k.`spec_summary` LIKE CONCAT('%', #{keyword}, '%') OR k.`barcode` LIKE CONCAT('%', #{keyword}, '%'))</if>
</select>
<select id="countProductByQuery" resultType="long"> <select id="countProductByQuery" resultType="long">
SELECT COUNT(DISTINCT p.`id`) SELECT COUNT(DISTINCT p.`id`)
FROM `gao_product_sku` k FROM `gao_product_sku` k
@@ -31,7 +31,7 @@
1 = 1 1 = 1
<if test="storeId != null and storeId != ''">AND r.`store_id` = #{storeId}</if> <if test="storeId != null and storeId != ''">AND r.`store_id` = #{storeId}</if>
<if test="productId != null and productId != ''">AND k.`product_id` = #{productId}</if> <if test="productId != null and productId != ''">AND k.`product_id` = #{productId}</if>
<if test="skuId != null and skuId != ''">AND r.`sku_id` = #{skuId}</if> <if test="skuId != null and skuId.trim() != ''">AND r.`sku_id` = #{skuId}</if>
<if test="keyword != null and keyword.trim() != ''">AND (r.`product_name_snapshot` LIKE CONCAT('%', #{keyword}, '%') OR p.`name` LIKE CONCAT('%', #{keyword}, '%') OR p.`name_pinyin_full` LIKE CONCAT(#{keyword}, '%') OR p.`name_pinyin_initial` LIKE CONCAT(#{keyword}, '%') OR p.`name_pinyin_mixed` LIKE CONCAT(#{keyword}, '%') OR p.`code` LIKE CONCAT('%', #{keyword}, '%'))</if> <if test="keyword != null and keyword.trim() != ''">AND (r.`product_name_snapshot` LIKE CONCAT('%', #{keyword}, '%') OR p.`name` LIKE CONCAT('%', #{keyword}, '%') OR p.`name_pinyin_full` LIKE CONCAT(#{keyword}, '%') OR p.`name_pinyin_initial` LIKE CONCAT(#{keyword}, '%') OR p.`name_pinyin_mixed` LIKE CONCAT(#{keyword}, '%') OR p.`code` LIKE CONCAT('%', #{keyword}, '%'))</if>
<if test="bizType != null">AND r.`biz_type` = #{bizType}</if> <if test="bizType != null">AND r.`biz_type` = #{bizType}</if>
<if test="bizId != null and bizId != ''">AND r.`biz_id` = #{bizId}</if> <if test="bizId != null and bizId != ''">AND r.`biz_id` = #{bizId}</if>
@@ -61,4 +61,12 @@
ORDER BY r.`occurred_at` DESC, r.`id` DESC ORDER BY r.`occurred_at` DESC, r.`id` DESC
LIMIT #{offset}, #{limit} LIMIT #{offset}, #{limit}
</select> </select>
<select id="selectSkuBaseUnitSummaryByQuery" resultType="com.imyeyu.api.modules.gao.vo.GaoProductStockRecordSkuSummaryView">
SELECT COALESCE(SUM(CASE WHEN 0 &lt; r.`on_hand_delta` THEN COALESCE(r.`base_quantity`, 0) ELSE 0 END), 0) AS `in_base_quantity_total`,
COALESCE(SUM(CASE WHEN r.`on_hand_delta` &lt; 0 THEN COALESCE(r.`base_quantity`, 0) ELSE 0 END), 0) AS `out_base_quantity_total`
FROM `gao_product_stock_record` r
LEFT JOIN `gao_product_sku` k ON k.`id` = r.`sku_id` AND k.`store_id` = r.`store_id`
LEFT JOIN `gao_product` p ON p.`id` = k.`product_id`
WHERE <include refid="queryWhere"/>
</select>
</mapper> </mapper>