mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 15:55:18 +08:00
feat:完善库存查询
This commit is contained in:
@@ -2,6 +2,7 @@ package cn.lihongjie.coal.warehouseGoods.dto;
|
|||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@@ -11,4 +12,8 @@ public class GoodsCountRequest {
|
|||||||
private String shelveId;
|
private String shelveId;
|
||||||
|
|
||||||
private String goodsId;
|
private String goodsId;
|
||||||
|
|
||||||
|
private LocalDateTime startTime;
|
||||||
|
private LocalDateTime endTime;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ public class WarehouseReceiptService
|
|||||||
createType2Receipt(entity);
|
createType2Receipt(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return getById(entity.getId());
|
return getById(entity.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -257,21 +258,23 @@ public class WarehouseReceiptService
|
|||||||
request.setGoodsId(warehouseReceiptDetailEntity.getGoods().getId());
|
request.setGoodsId(warehouseReceiptDetailEntity.getGoods().getId());
|
||||||
request.setWarehouseId(warehouseReceiptDetailEntity.getWarehouse().getId());
|
request.setWarehouseId(warehouseReceiptDetailEntity.getWarehouse().getId());
|
||||||
request.setShelveId(warehouseReceiptDetailEntity.getShelve().getId());
|
request.setShelveId(warehouseReceiptDetailEntity.getShelve().getId());
|
||||||
|
request.setStartTime(null);
|
||||||
|
request.setEndTime(entity.getReceiptDate().minusSeconds(1));
|
||||||
|
|
||||||
Integer goodsCount = getGoodsCount(request);
|
Integer goodsCount = getGoodsCount(request);
|
||||||
|
|
||||||
WarehouseGoodsDto goods =
|
WarehouseGoodsDto goods =
|
||||||
warehouseGoodsService.getById(
|
warehouseGoodsService.getById(
|
||||||
warehouseReceiptDetailEntity.getGoods().getId());
|
warehouseReceiptDetailEntity.getGoods().getId());
|
||||||
if (ObjectUtils.notEqual(
|
// if (ObjectUtils.notEqual(
|
||||||
goodsCount, warehouseReceiptDetailEntity.getStock().intValue())) {
|
// goodsCount, warehouseReceiptDetailEntity.getStock().intValue())) {
|
||||||
|
//
|
||||||
throw new BizException("商品 " + goods.getName() + " 库存数量发生变化, 请重新操作");
|
// throw new BizException("商品 " + goods.getName() + " 库存数量发生变化, 请重新操作");
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (StringUtils.equals(entity.getReceiptType(), "1")) {
|
if (StringUtils.equals(entity.getReceiptType(), "1")) {
|
||||||
if (goodsCount < warehouseReceiptDetailEntity.getNumber()) {
|
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.setShelveSummary(true);
|
||||||
reportRequest.setExcludeEmpty(true);
|
reportRequest.setExcludeEmpty(true);
|
||||||
reportRequest.setIncludeSum(false);
|
reportRequest.setIncludeSum(false);
|
||||||
|
reportRequest.setStartTime(request.getStartTime());
|
||||||
|
reportRequest.setEndTime(request.getEndTime());
|
||||||
Object report = report(reportRequest);
|
Object report = report(reportRequest);
|
||||||
|
|
||||||
List content = ((PageImpl) report).getContent();
|
List content = ((PageImpl) report).getContent();
|
||||||
@@ -312,69 +317,6 @@ public class WarehouseReceiptService
|
|||||||
return NumberUtil.parseInt(map.get("currNumber").toString());
|
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) {
|
public WarehouseReceiptDto update(UpdateWarehouseReceiptDto request) {
|
||||||
|
|
||||||
long count =
|
long count =
|
||||||
@@ -399,47 +341,21 @@ public class WarehouseReceiptService
|
|||||||
throw new BizException("数据由调货单、盘库单生成,无法编辑或删除");
|
throw new BizException("数据由调货单、盘库单生成,无法编辑或删除");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.warehouseReceiptDetailRepository.delete(
|
this.repository.deleteById(request.getId());
|
||||||
new Specification<WarehouseReceiptDetailEntity>() {
|
|
||||||
@Override
|
|
||||||
public Predicate toPredicate(
|
|
||||||
Root<WarehouseReceiptDetailEntity> root,
|
|
||||||
CriteriaQuery<?> query,
|
|
||||||
CriteriaBuilder criteriaBuilder) {
|
|
||||||
|
|
||||||
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) {
|
public void delete(IdRequest dto) {
|
||||||
|
|
||||||
@@ -593,7 +509,12 @@ public class WarehouseReceiptService
|
|||||||
<#if shelveSummary>
|
<#if shelveSummary>
|
||||||
, d.shelve_id
|
, d.shelve_id
|
||||||
</#if>
|
</#if>
|
||||||
) gs.id,
|
) concat( gs.id, w.id
|
||||||
|
|
||||||
|
<#if shelveSummary>
|
||||||
|
, d.shelve_id
|
||||||
|
</#if>
|
||||||
|
) as uid, gs.id,
|
||||||
gs.create_time,
|
gs.create_time,
|
||||||
gs.create_user_id,
|
gs.create_user_id,
|
||||||
gs.file_ids,
|
gs.file_ids,
|
||||||
@@ -642,27 +563,27 @@ public class WarehouseReceiptService
|
|||||||
</#if>
|
</#if>
|
||||||
|
|
||||||
round((sum(d.number)
|
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,
|
2) as type0_number,
|
||||||
round((sum(d.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,
|
2) as type1_number,
|
||||||
round((sum(d.amount)
|
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,
|
2) as type0_amount,
|
||||||
round((sum(d.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,
|
2) as type1_amount,
|
||||||
round((sum(d.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)
|
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,
|
2) as type0_price,
|
||||||
|
|
||||||
round((sum(d.amount)
|
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)
|
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
|
2) as type1_price
|
||||||
from t_warehouse_goods gs
|
from t_warehouse_goods gs
|
||||||
inner join t_warehouse w on 1 = 1
|
inner join t_warehouse w on 1 = 1
|
||||||
@@ -895,7 +816,7 @@ from (
|
|||||||
|
|
||||||
if (o instanceof Map<?, ?> prevMap) {
|
if (o instanceof Map<?, ?> prevMap) {
|
||||||
|
|
||||||
String id = prevMap.get("id").toString();
|
String uid = prevMap.get("uid").toString();
|
||||||
|
|
||||||
Map<String, Object> currMap =
|
Map<String, Object> currMap =
|
||||||
(Map<String, Object>)
|
(Map<String, Object>)
|
||||||
@@ -903,7 +824,7 @@ from (
|
|||||||
.filter(
|
.filter(
|
||||||
x ->
|
x ->
|
||||||
x instanceof Map
|
x instanceof Map
|
||||||
&& ((Map) x).get("id").equals(id))
|
&& ((Map) x).get("uid").equals(uid))
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user