mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
仓库管理调货单处理逻辑
This commit is contained in:
@@ -33,6 +33,10 @@ public class CreateWarehouseReceiptDto extends OrgCommonDto {
|
||||
@ManyToOne
|
||||
private String warehouse;
|
||||
|
||||
|
||||
@ManyToOne
|
||||
private String warehouse2;
|
||||
|
||||
@Comment("单据日期")
|
||||
private LocalDateTime receiptDate;
|
||||
|
||||
|
||||
@@ -33,6 +33,10 @@ public class UpdateWarehouseReceiptDto extends OrgCommonDto {
|
||||
@ManyToOne
|
||||
private String warehouse;
|
||||
|
||||
|
||||
@ManyToOne
|
||||
private String warehouse2;
|
||||
|
||||
@Comment("单据日期")
|
||||
private LocalDateTime receiptDate;
|
||||
|
||||
|
||||
@@ -43,6 +43,10 @@ public class WarehouseReceiptDto extends OrgCommonDto {
|
||||
@ManyToOne
|
||||
private WarehouseDto warehouse;
|
||||
|
||||
|
||||
@ManyToOne
|
||||
private WarehouseDto warehouse2;
|
||||
|
||||
@Comment("单据日期")
|
||||
private LocalDateTime receiptDate;
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import cn.lihongjie.coal.base.entity.OrgCommonEntity;
|
||||
import cn.lihongjie.coal.warehouse.entity.WarehouseEntity;
|
||||
import cn.lihongjie.coal.warehouseReceiptDetail.entity.WarehouseReceiptDetailEntity;
|
||||
|
||||
import jakarta.persistence.CascadeType;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.OneToMany;
|
||||
@@ -43,11 +44,17 @@ public class WarehouseReceiptEntity extends OrgCommonEntity {
|
||||
|
||||
@ManyToOne private WarehouseEntity warehouse;
|
||||
|
||||
|
||||
// 调入仓库
|
||||
@ManyToOne private WarehouseEntity warehouse2;
|
||||
|
||||
|
||||
|
||||
@Comment("单据日期")
|
||||
private LocalDateTime receiptDate;
|
||||
|
||||
|
||||
@OneToMany(mappedBy = "receipt")
|
||||
@OneToMany(mappedBy = "receipt", cascade = CascadeType.REMOVE)
|
||||
private List<WarehouseReceiptDetailEntity> detail;
|
||||
|
||||
|
||||
@@ -60,5 +67,16 @@ public class WarehouseReceiptEntity extends OrgCommonEntity {
|
||||
|
||||
|
||||
|
||||
// 调货单产生的入库单
|
||||
@ManyToOne(cascade = CascadeType.REMOVE)
|
||||
private WarehouseReceiptEntity receipt0;
|
||||
|
||||
|
||||
|
||||
// 调货单产生的出库单
|
||||
@ManyToOne(cascade = CascadeType.REMOVE)
|
||||
private WarehouseReceiptEntity receipt1;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import cn.lihongjie.coal.warehouseReceipt.dto.WarehouseReceiptDto;
|
||||
import cn.lihongjie.coal.warehouseReceipt.entity.WarehouseReceiptEntity;
|
||||
import cn.lihongjie.coal.warehouseReceipt.mapper.WarehouseReceiptMapper;
|
||||
import cn.lihongjie.coal.warehouseReceipt.repository.WarehouseReceiptRepository;
|
||||
import cn.lihongjie.coal.warehouseReceiptDetail.entity.WarehouseReceiptDetailEntity;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@@ -21,6 +22,7 @@ import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@@ -39,15 +41,89 @@ public class WarehouseReceiptService
|
||||
public WarehouseReceiptDto create(CreateWarehouseReceiptDto request) {
|
||||
WarehouseReceiptEntity entity = mapper.toEntity(request);
|
||||
|
||||
this.repository.save(entity);
|
||||
|
||||
handleType3Create(entity);
|
||||
this.repository.save(entity);
|
||||
warehouseGoodsSummaryService.refresh(List.of(entity));
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
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) {
|
||||
WarehouseReceiptEntity entity = this.repository.get(request.getId());
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
handleType3Update(entity);
|
||||
this.repository.save(entity);
|
||||
|
||||
warehouseGoodsSummaryService.refresh(List.of(entity));
|
||||
@@ -55,13 +131,25 @@ public class WarehouseReceiptService
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
private void handleType3Update(WarehouseReceiptEntity entity) {
|
||||
repository.delete(entity.getReceipt0());
|
||||
repository.delete(entity.getReceipt1());
|
||||
handleType3Create(entity);
|
||||
|
||||
}
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
List<WarehouseReceiptEntity> allById = this.repository.findAllById(request.getIds());
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
|
||||
handleType3Delete(allById);
|
||||
warehouseGoodsSummaryService.refresh(allById);
|
||||
}
|
||||
|
||||
private void handleType3Delete(List<WarehouseReceiptEntity> allById) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
public WarehouseReceiptDto getById(String id) {
|
||||
WarehouseReceiptEntity entity = repository.get(id);
|
||||
|
||||
|
||||
@@ -24,6 +24,11 @@ public class WarehouseReceiptDetailEntity extends OrgCommonEntity {
|
||||
@ManyToOne
|
||||
private WarehouseShelveEntity shelve;
|
||||
|
||||
|
||||
// 调入货架
|
||||
@ManyToOne
|
||||
private WarehouseShelveEntity shelve2;
|
||||
|
||||
@ManyToOne
|
||||
private WarehouseReceiptEntity receipt;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user