refactor(wms): 优化库存台账查询功能

- 移除了 WmsInventoryController 中冗余的权限注解
- 修改了 WmsInventoryMapper.xml 中的 SQL 查询,移除了无效的条件判断
- 重构了 WmsInventoryServiceImpl 中的库存台账查询逻辑:
 - 根据 changeType 参数决定查询哪些类型的记录
  -优化了查询性能,避免了不必要的数据检索
  - 保留了原有的数据处理和计算逻辑
master
zangch@mesnac.com 3 months ago
parent 743e72a533
commit 1d0fe2f860

@ -45,7 +45,7 @@ public class WmsInventoryController extends BaseController {
/** /**
* *
*/ */
@SaCheckPermission("system:inventory:list") @SaCheckPermission("wms:inventory:list")
@GetMapping("/list") @GetMapping("/list")
public TableDataInfo<WmsInventoryVo> list(WmsInventoryBo bo, PageQuery pageQuery) { public TableDataInfo<WmsInventoryVo> list(WmsInventoryBo bo, PageQuery pageQuery) {
return wmsInventoryService.queryPageList(bo, pageQuery); return wmsInventoryService.queryPageList(bo, pageQuery);
@ -65,7 +65,7 @@ public class WmsInventoryController extends BaseController {
/** /**
* *
*/ */
@SaCheckPermission("system:inventory:export") @SaCheckPermission("wms:inventory:export")
@Log(title = "物料库存", businessType = BusinessType.EXPORT) @Log(title = "物料库存", businessType = BusinessType.EXPORT)
@PostMapping("/export") @PostMapping("/export")
public void export(WmsInventoryBo bo, HttpServletResponse response) { public void export(WmsInventoryBo bo, HttpServletResponse response) {
@ -78,7 +78,7 @@ public class WmsInventoryController extends BaseController {
* *
* @param inventoryId * @param inventoryId
*/ */
@SaCheckPermission("system:inventory:query") @SaCheckPermission("wms:inventory:query")
@GetMapping("/{inventoryId}") @GetMapping("/{inventoryId}")
public R<WmsInventoryVo> getInfo(@NotNull(message = "主键不能为空") public R<WmsInventoryVo> getInfo(@NotNull(message = "主键不能为空")
@PathVariable Long inventoryId) { @PathVariable Long inventoryId) {
@ -88,7 +88,7 @@ public class WmsInventoryController extends BaseController {
/** /**
* *
*/ */
@SaCheckPermission("system:inventory:add") @SaCheckPermission("wms:inventory:add")
@Log(title = "物料库存", businessType = BusinessType.INSERT) @Log(title = "物料库存", businessType = BusinessType.INSERT)
@RepeatSubmit() @RepeatSubmit()
@PostMapping() @PostMapping()
@ -99,7 +99,7 @@ public class WmsInventoryController extends BaseController {
/** /**
* *
*/ */
@SaCheckPermission("system:inventory:edit") @SaCheckPermission("wms:inventory:edit")
@Log(title = "物料库存", businessType = BusinessType.UPDATE) @Log(title = "物料库存", businessType = BusinessType.UPDATE)
@RepeatSubmit() @RepeatSubmit()
@PutMapping() @PutMapping()
@ -112,7 +112,7 @@ public class WmsInventoryController extends BaseController {
* *
* @param inventoryIds * @param inventoryIds
*/ */
@SaCheckPermission("system:inventory:remove") @SaCheckPermission("wms:inventory:remove")
@Log(title = "物料库存", businessType = BusinessType.DELETE) @Log(title = "物料库存", businessType = BusinessType.DELETE)
@DeleteMapping("/{inventoryIds}") @DeleteMapping("/{inventoryIds}")
public R<Void> remove(@NotEmpty(message = "主键不能为空") public R<Void> remove(@NotEmpty(message = "主键不能为空")
@ -142,7 +142,7 @@ public class WmsInventoryController extends BaseController {
/** /**
* *
*/ */
@SaCheckPermission("system:inventory:list") // @SaCheckPermission("wms:inventory:list")
@GetMapping("/ledger/list") @GetMapping("/ledger/list")
public TableDataInfo<WmsInventoryLedgerVo> ledgerList(WmsInventoryLedgerBo bo, PageQuery pageQuery) { public TableDataInfo<WmsInventoryLedgerVo> ledgerList(WmsInventoryLedgerBo bo, PageQuery pageQuery) {
return wmsInventoryService.queryInventoryLedgerPageList(bo, pageQuery); return wmsInventoryService.queryInventoryLedgerPageList(bo, pageQuery);
@ -151,7 +151,7 @@ public class WmsInventoryController extends BaseController {
/** /**
* *
*/ */
@SaCheckPermission("system:inventory:export") @SaCheckPermission("wms:inventory:export")
@Log(title = "库存台账", businessType = BusinessType.EXPORT) @Log(title = "库存台账", businessType = BusinessType.EXPORT)
@PostMapping("/ledger/export") @PostMapping("/ledger/export")
public void exportLedger(WmsInventoryLedgerBo bo, HttpServletResponse response) { public void exportLedger(WmsInventoryLedgerBo bo, HttpServletResponse response) {

@ -292,16 +292,16 @@ public class WmsInventoryServiceImpl implements IWmsInventoryService {
@Override @Override
public TableDataInfo<WmsInventoryLedgerVo> queryInventoryLedgerPageList(WmsInventoryLedgerBo bo, PageQuery pageQuery) { public TableDataInfo<WmsInventoryLedgerVo> queryInventoryLedgerPageList(WmsInventoryLedgerBo bo, PageQuery pageQuery) {
List<WmsInventoryLedgerVo> ledgerList = queryInventoryLedgerList(bo); List<WmsInventoryLedgerVo> ledgerList = queryInventoryLedgerList(bo);
// 手动分页处理 // 手动分页处理
int total = ledgerList.size(); int total = ledgerList.size();
int pageNum = pageQuery.getPageNum(); int pageNum = pageQuery.getPageNum();
int pageSize = pageQuery.getPageSize(); int pageSize = pageQuery.getPageSize();
int fromIndex = (pageNum - 1) * pageSize; int fromIndex = (pageNum - 1) * pageSize;
int toIndex = Math.min(fromIndex + pageSize, total); int toIndex = Math.min(fromIndex + pageSize, total);
List<WmsInventoryLedgerVo> pageList = fromIndex < total ? ledgerList.subList(fromIndex, toIndex) : new ArrayList<>(); List<WmsInventoryLedgerVo> pageList = fromIndex < total ? ledgerList.subList(fromIndex, toIndex) : new ArrayList<>();
TableDataInfo<WmsInventoryLedgerVo> dataInfo = TableDataInfo.build(pageList); TableDataInfo<WmsInventoryLedgerVo> dataInfo = TableDataInfo.build(pageList);
dataInfo.setTotal(total); dataInfo.setTotal(total);
return dataInfo; return dataInfo;
@ -316,28 +316,52 @@ public class WmsInventoryServiceImpl implements IWmsInventoryService {
@Override @Override
public List<WmsInventoryLedgerVo> queryInventoryLedgerList(WmsInventoryLedgerBo bo) { public List<WmsInventoryLedgerVo> queryInventoryLedgerList(WmsInventoryLedgerBo bo) {
List<WmsInventoryLedgerVo> ledgerList = new ArrayList<>(); List<WmsInventoryLedgerVo> ledgerList = new ArrayList<>();
// 1. 查询入库记录 // 根据变动类型筛选查询哪些记录
ledgerList.addAll(getInstockRecords(bo)); String changeType = bo.getChangeType();
// 2. 查询出库记录 if (changeType == null || changeType.isEmpty()) {
ledgerList.addAll(getOutstockRecords(bo)); // 查询所有类型
ledgerList.addAll(getInstockRecords(bo));
// 3. 查询盘点调账记录 ledgerList.addAll(getOutstockRecords(bo));
ledgerList.addAll(getInventoryCheckRecords(bo)); ledgerList.addAll(getInventoryCheckRecords(bo));
ledgerList.addAll(getReturnOrderRecords(bo));
// 4. 查询退库记录 // ledgerList.addAll(getTransferRecords(bo));
ledgerList.addAll(getReturnOrderRecords(bo)); } else {
// 根据指定类型查询
// 5. 查询调拨记录 switch (changeType) {
ledgerList.addAll(getTransferRecords(bo)); case "INBOUND":
ledgerList.addAll(getInstockRecords(bo));
break;
case "OUTBOUND":
ledgerList.addAll(getOutstockRecords(bo));
break;
case "RETURN":
ledgerList.addAll(getReturnOrderRecords(bo));
break;
// case "TRANSFER":
// ledgerList.addAll(getTransferRecords(bo));
// break;
case "ADJUST":
ledgerList.addAll(getInventoryCheckRecords(bo));
break;
default:
// 未知类型,查询所有
ledgerList.addAll(getInstockRecords(bo));
ledgerList.addAll(getOutstockRecords(bo));
ledgerList.addAll(getInventoryCheckRecords(bo));
ledgerList.addAll(getReturnOrderRecords(bo));
// ledgerList.addAll(getTransferRecords(bo));
break;
}
}
// 按时间排序 // 按时间排序
ledgerList.sort(Comparator.comparing(WmsInventoryLedgerVo::getChangeDate)); ledgerList.sort(Comparator.comparing(WmsInventoryLedgerVo::getChangeDate));
// 计算结存数量 // 计算结存数量
calculateBalanceQty(ledgerList); calculateBalanceQty(ledgerList);
return ledgerList; return ledgerList;
} }
@ -381,7 +405,7 @@ public class WmsInventoryServiceImpl implements IWmsInventoryService {
*/ */
private void calculateBalanceQty(List<WmsInventoryLedgerVo> ledgerList) { private void calculateBalanceQty(List<WmsInventoryLedgerVo> ledgerList) {
Map<String, BigDecimal> balanceMap = new HashMap<>(); Map<String, BigDecimal> balanceMap = new HashMap<>();
for (WmsInventoryLedgerVo record : ledgerList) { for (WmsInventoryLedgerVo record : ledgerList) {
String key = record.getMaterialId() + "_" + record.getBatchCode() + "_" + record.getLocationCode(); String key = record.getMaterialId() + "_" + record.getBatchCode() + "_" + record.getLocationCode();
BigDecimal currentBalance = balanceMap.getOrDefault(key, BigDecimal.ZERO); BigDecimal currentBalance = balanceMap.getOrDefault(key, BigDecimal.ZERO);

@ -154,9 +154,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="bo.endDate != null"> <if test="bo.endDate != null">
AND ir.create_time &lt;= #{bo.endDate} AND ir.create_time &lt;= #{bo.endDate}
</if> </if>
<if test="bo.changeType != null and bo.changeType != ''">
AND '1' = #{bo.changeType}
</if>
</where> </where>
ORDER BY ir.create_time ASC ORDER BY ir.create_time ASC
</select> </select>
@ -212,9 +209,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="bo.endDate != null"> <if test="bo.endDate != null">
AND ors.create_time &lt;= #{bo.endDate} AND ors.create_time &lt;= #{bo.endDate}
</if> </if>
<if test="bo.changeType != null and bo.changeType != ''"> <!-- <if test="bo.changeType != null and bo.changeType != ''">
AND '2' = #{bo.changeType} AND '2' = #{bo.changeType}
</if> </if> -->
</where> </where>
ORDER BY ors.create_time ASC ORDER BY ors.create_time ASC
</select> </select>
@ -263,9 +260,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="bo.endDate != null"> <if test="bo.endDate != null">
AND icr.create_time &lt;= #{bo.endDate} AND icr.create_time &lt;= #{bo.endDate}
</if> </if>
<if test="bo.changeType != null and bo.changeType != ''"> <!-- <if test="bo.changeType != null and bo.changeType != ''">
AND '5' = #{bo.changeType} AND '5' = #{bo.changeType}
</if> </if> -->
</where> </where>
ORDER BY icr.create_time ASC ORDER BY icr.create_time ASC
</select> </select>
@ -318,9 +315,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="bo.endDate != null"> <if test="bo.endDate != null">
AND ro.create_time &lt;= #{bo.endDate} AND ro.create_time &lt;= #{bo.endDate}
</if> </if>
<if test="bo.changeType != null and bo.changeType != ''"> <!-- <if test="bo.changeType != null and bo.changeType != ''">
AND '4' = #{bo.changeType} AND '4' = #{bo.changeType}
</if> </if> -->
</where> </where>
ORDER BY ro.create_time ASC ORDER BY ro.create_time ASC
</select> </select>
@ -368,9 +365,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="bo.endDate != null"> <if test="bo.endDate != null">
AND ht.create_time &lt;= #{bo.endDate} AND ht.create_time &lt;= #{bo.endDate}
</if> </if>
<if test="bo.changeType != null and bo.changeType != ''"> <!-- <if test="bo.changeType != null and bo.changeType != ''">
AND '3' = #{bo.changeType} AND '3' = #{bo.changeType}
</if> </if> -->
</where> </where>
ORDER BY ht.create_time ASC ORDER BY ht.create_time ASC
</select> </select>

Loading…
Cancel
Save