feat:完善库存查询

This commit is contained in:
2024-12-02 20:47:53 +08:00
parent b3e5400b97
commit 6bc074136d
2 changed files with 38 additions and 112 deletions

View File

@@ -2,6 +2,7 @@ package cn.lihongjie.coal.warehouseGoods.dto;
import lombok.Data;
import java.time.LocalDateTime;
import java.util.*;
@Data
@@ -11,4 +12,8 @@ public class GoodsCountRequest {
private String shelveId;
private String goodsId;
private LocalDateTime startTime;
private LocalDateTime endTime;
}

View File

@@ -82,6 +82,7 @@ public class WarehouseReceiptService
createType2Receipt(entity);
}
return getById(entity.getId());
}
@@ -257,21 +258,23 @@ public class WarehouseReceiptService
request.setGoodsId(warehouseReceiptDetailEntity.getGoods().getId());
request.setWarehouseId(warehouseReceiptDetailEntity.getWarehouse().getId());
request.setShelveId(warehouseReceiptDetailEntity.getShelve().getId());
request.setStartTime(null);
request.setEndTime(entity.getReceiptDate().minusSeconds(1));
Integer goodsCount = getGoodsCount(request);
WarehouseGoodsDto goods =
warehouseGoodsService.getById(
warehouseReceiptDetailEntity.getGoods().getId());
if (ObjectUtils.notEqual(
goodsCount, warehouseReceiptDetailEntity.getStock().intValue())) {
throw new BizException("商品 " + goods.getName() + " 库存数量发生变化, 请重新操作");
}
// if (ObjectUtils.notEqual(
// goodsCount, warehouseReceiptDetailEntity.getStock().intValue())) {
//
// throw new BizException("商品 " + goods.getName() + " 库存数量发生变化, 请重新操作");
// }
if (StringUtils.equals(entity.getReceiptType(), "1")) {
if (goodsCount < warehouseReceiptDetailEntity.getNumber()) {
throw new BizException("商品 " + goods.getName() + " 库存数量不足");
throw new BizException("商品 " + goods.getName() + " 库存数量不足: 当前库存数量为 " + goodsCount);
}
}
}
@@ -299,6 +302,8 @@ public class WarehouseReceiptService
reportRequest.setShelveSummary(true);
reportRequest.setExcludeEmpty(true);
reportRequest.setIncludeSum(false);
reportRequest.setStartTime(request.getStartTime());
reportRequest.setEndTime(request.getEndTime());
Object report = report(reportRequest);
List content = ((PageImpl) report).getContent();
@@ -312,69 +317,6 @@ public class WarehouseReceiptService
return NumberUtil.parseInt(map.get("currNumber").toString());
}
private void handleType3Create(WarehouseReceiptEntity entity) {
// 生成入库单
WarehouseReceiptEntity type0 = new WarehouseReceiptEntity();
type0.setReceiptType("0");
type0.setReceiptNo(entity.getReceiptNo() + "-0");
type0.setReason("调货");
type0.setReasonDesc("调货产生的入库单");
// type0.setWarehouse(entity.getWarehouse2());
type0.setReceiptDate(entity.getReceiptDate());
var details = new ArrayList<WarehouseReceiptDetailEntity>();
for (WarehouseReceiptDetailEntity warehouseReceiptDetailEntity : entity.getDetail()) {
WarehouseReceiptDetailEntity detail = new WarehouseReceiptDetailEntity();
detail.setGoods(warehouseReceiptDetailEntity.getGoods());
detail.setNumber(warehouseReceiptDetailEntity.getNumber());
detail.setPrice(warehouseReceiptDetailEntity.getPrice());
detail.setShelve(warehouseReceiptDetailEntity.getShelve2());
details.add(detail);
}
type0.setDetail(details);
this.repository.save(type0);
// 生成出库单
WarehouseReceiptEntity type1 = new WarehouseReceiptEntity();
type1.setReceiptType("1");
type1.setReceiptNo(entity.getReceiptNo() + "-1");
type1.setReason("调货");
type1.setReasonDesc("调货产生的出库单");
// type1.setWarehouse(entity.getWarehouse());
type1.setReceiptDate(entity.getReceiptDate());
details = new ArrayList<WarehouseReceiptDetailEntity>();
for (WarehouseReceiptDetailEntity warehouseReceiptDetailEntity : entity.getDetail()) {
WarehouseReceiptDetailEntity detail = new WarehouseReceiptDetailEntity();
detail.setGoods(warehouseReceiptDetailEntity.getGoods());
detail.setNumber(warehouseReceiptDetailEntity.getNumber());
detail.setPrice(warehouseReceiptDetailEntity.getPrice());
detail.setShelve(warehouseReceiptDetailEntity.getShelve());
details.add(detail);
}
type1.setDetail(details);
this.repository.save(type1);
entity.setReceipt0(type0);
entity.setReceipt1(type1);
}
public WarehouseReceiptDto update(UpdateWarehouseReceiptDto request) {
long count =
@@ -399,47 +341,21 @@ public class WarehouseReceiptService
throw new BizException("数据由调货单、盘库单生成,无法编辑或删除");
}
this.warehouseReceiptDetailRepository.delete(
new Specification<WarehouseReceiptDetailEntity>() {
@Override
public Predicate toPredicate(
Root<WarehouseReceiptDetailEntity> root,
CriteriaQuery<?> query,
CriteriaBuilder criteriaBuilder) {
this.repository.deleteById(request.getId());
return criteriaBuilder.equal(
root.get("receipt").get("id"), request.getId());
}
});
if (CollectionUtils.isNotEmpty(request.getDetail())) {
request.getDetail().forEach(x -> x.setId(null));
}
WarehouseReceiptEntity entity = this.repository.get(request.getId());
processDetail(entity);
this.mapper.updateEntity(entity, request);
CreateWarehouseReceiptDto dto = new CreateWarehouseReceiptDto();
BeanUtil.copyProperties(request, dto);
dto.setId(null);
dto.getDetail().forEach(x -> x.setId(null));
return this.create(dto);
this.repository.save(entity);
if (request.getReceiptType().equals("2")) {
updateType2Receipt(entity);
}
return getById(entity.getId());
}
private void updateType2Receipt(WarehouseReceiptEntity entity) {}
// private void handleType3Update(WarehouseReceiptEntity entity) {
// repository.delete(entity.getReceipt0());
// repository.delete(entity.getReceipt1());
// handleType3Create(entity);
//
// }
public void delete(IdRequest dto) {
@@ -593,7 +509,12 @@ public class WarehouseReceiptService
<#if shelveSummary>
, d.shelve_id
</#if>
) gs.id,
) concat( gs.id, w.id
<#if shelveSummary>
, d.shelve_id
</#if>
) as uid, gs.id,
gs.create_time,
gs.create_user_id,
gs.file_ids,
@@ -642,27 +563,27 @@ public class WarehouseReceiptService
</#if>
round((sum(d.number)
filter (where d.receipt_type = '0') over (partition by w.id, gs.id))::::numeric,
filter (where d.receipt_type = '0') over (partition by w.id, gs.id <#if shelveSummary>,ws.id</#if> ))::::numeric,
2) as type0_number,
round((sum(d.number)
filter (where d.receipt_type = '1') over (partition by w.id, gs.id))::::numeric,
filter (where d.receipt_type = '1') over (partition by w.id, gs.id <#if shelveSummary>,ws.id</#if>))::::numeric,
2) as type1_number,
round((sum(d.amount)
filter (where d.receipt_type = '0') over (partition by w.id, gs.id))::::numeric,
filter (where d.receipt_type = '0') over (partition by w.id, gs.id <#if shelveSummary>,ws.id</#if>))::::numeric,
2) as type0_amount,
round((sum(d.amount)
filter (where d.receipt_type = '1') over (partition by w.id, gs.id))::::numeric,
filter (where d.receipt_type = '1') over (partition by w.id, gs.id<#if shelveSummary>,ws.id</#if>))::::numeric,
2) as type1_amount,
round((sum(d.amount)
filter (where d.receipt_type = '0') over (partition by w.id, gs.id) /
filter (where d.receipt_type = '0') over (partition by w.id, gs.id <#if shelveSummary>,ws.id</#if>) /
sum(d.number)
filter (where d.receipt_type = '0') over (partition by w.id, gs.id))::::numeric,
filter (where d.receipt_type = '0') over (partition by w.id, gs.id <#if shelveSummary>,ws.id</#if>))::::numeric,
2) as type0_price,
round((sum(d.amount)
filter (where d.receipt_type = '1') over (partition by w.id, gs.id) /
filter (where d.receipt_type = '1') over (partition by w.id, gs.id <#if shelveSummary>,ws.id</#if>) /
sum(d.number)
filter (where d.receipt_type = '1') over (partition by w.id, gs.id))::::numeric,
filter (where d.receipt_type = '1') over (partition by w.id, gs.id <#if shelveSummary>,ws.id</#if>))::::numeric,
2) as type1_price
from t_warehouse_goods gs
inner join t_warehouse w on 1 = 1
@@ -895,7 +816,7 @@ from (
if (o instanceof Map<?, ?> prevMap) {
String id = prevMap.get("id").toString();
String uid = prevMap.get("uid").toString();
Map<String, Object> currMap =
(Map<String, Object>)
@@ -903,7 +824,7 @@ from (
.filter(
x ->
x instanceof Map
&& ((Map) x).get("id").equals(id))
&& ((Map) x).get("uid").equals(uid))
.findFirst()
.get();