diff --git a/src/main/java/cn/lihongjie/coal/deliveryInformation/dto/UpdateDeliveryInformationDto.java b/src/main/java/cn/lihongjie/coal/deliveryInformation/dto/UpdateDeliveryInformationDto.java index a54fedb8..97c9b05e 100644 --- a/src/main/java/cn/lihongjie/coal/deliveryInformation/dto/UpdateDeliveryInformationDto.java +++ b/src/main/java/cn/lihongjie/coal/deliveryInformation/dto/UpdateDeliveryInformationDto.java @@ -24,5 +24,6 @@ public class UpdateDeliveryInformationDto extends OrgCommonDto { + private String purchaseOrder; } diff --git a/src/main/java/cn/lihongjie/coal/purchaseOrder/dto/CreatePurchaseOrderDto.java b/src/main/java/cn/lihongjie/coal/purchaseOrder/dto/CreatePurchaseOrderDto.java index a9815760..36add207 100644 --- a/src/main/java/cn/lihongjie/coal/purchaseOrder/dto/CreatePurchaseOrderDto.java +++ b/src/main/java/cn/lihongjie/coal/purchaseOrder/dto/CreatePurchaseOrderDto.java @@ -7,6 +7,9 @@ import jakarta.persistence.ManyToOne; import lombok.Data; import org.hibernate.annotations.Comment; +import org.hibernate.annotations.Formula; + +import java.time.LocalDate; @Data public class CreatePurchaseOrderDto extends OrgCommonDto { @@ -25,6 +28,20 @@ public class CreatePurchaseOrderDto extends OrgCommonDto { private Double price; + @Comment("采购日期") + private LocalDate purchaseDate; + + @Comment("预计到货日期") + private LocalDate estimateDeliveryDate; + + + @Formula("(select min(d.delivery_date) from t_delivery_information d where d.purchase_order_id = id)") + private LocalDate firstDeliveryDate; + + @Formula("(select max(d.delivery_date) from t_delivery_information d where d.purchase_order_id = id)") + private LocalDate lastDeliveryDate; + + } diff --git a/src/main/java/cn/lihongjie/coal/purchaseOrder/dto/PurchaseOrderDto.java b/src/main/java/cn/lihongjie/coal/purchaseOrder/dto/PurchaseOrderDto.java index c49b12a1..53689c3e 100644 --- a/src/main/java/cn/lihongjie/coal/purchaseOrder/dto/PurchaseOrderDto.java +++ b/src/main/java/cn/lihongjie/coal/purchaseOrder/dto/PurchaseOrderDto.java @@ -12,12 +12,40 @@ import lombok.Data; import org.hibernate.annotations.Comment; import org.hibernate.annotations.Formula; +import java.time.LocalDate; import java.util.List; @Data public class PurchaseOrderDto extends OrgCommonDto { + @Comment("采购日期") + private LocalDate purchaseDate; + + @Comment("预计到货日期") + private LocalDate estimateDeliveryDate; + + + @Formula("(select min(d.delivery_date) from t_delivery_information d where d.purchase_order_id = id)") + private LocalDate firstDeliveryDate; + + @Formula("(select max(d.delivery_date) from t_delivery_information d where d.purchase_order_id = id)") + private LocalDate lastDeliveryDate; + + + private Integer dayLeft; + + + private Integer dayAmount; + + + + + + + + + @ManyToOne @Comment("煤炭信息") private CoalInfoDto coalInfo; @@ -34,6 +62,10 @@ public class PurchaseOrderDto extends OrgCommonDto { private Double receivedAmount; + @Formula("(select sum(d.car_count) from t_delivery_information d where d.purchase_order_id = id)") + private Double totalCarCount; + + @Formula("(amount - (select sum(d.amount) from t_delivery_information d where d.purchase_order_id = id))") private Double leftAmount; diff --git a/src/main/java/cn/lihongjie/coal/purchaseOrder/dto/UpdatePurchaseOrderDto.java b/src/main/java/cn/lihongjie/coal/purchaseOrder/dto/UpdatePurchaseOrderDto.java index 9284bbcf..ea8d0aa0 100644 --- a/src/main/java/cn/lihongjie/coal/purchaseOrder/dto/UpdatePurchaseOrderDto.java +++ b/src/main/java/cn/lihongjie/coal/purchaseOrder/dto/UpdatePurchaseOrderDto.java @@ -8,6 +8,8 @@ import lombok.Data; import org.hibernate.annotations.Comment; +import java.time.LocalDate; + @Data public class UpdatePurchaseOrderDto extends OrgCommonDto { @@ -25,4 +27,12 @@ public class UpdatePurchaseOrderDto extends OrgCommonDto { @Comment("采购单价") private Double price; + + + @Comment("采购日期") + private LocalDate purchaseDate; + + @Comment("预计到货日期") + private LocalDate estimateDeliveryDate; + } diff --git a/src/main/java/cn/lihongjie/coal/purchaseOrder/entity/PurchaseOrderEntity.java b/src/main/java/cn/lihongjie/coal/purchaseOrder/entity/PurchaseOrderEntity.java index dc7de1fe..0692a823 100644 --- a/src/main/java/cn/lihongjie/coal/purchaseOrder/entity/PurchaseOrderEntity.java +++ b/src/main/java/cn/lihongjie/coal/purchaseOrder/entity/PurchaseOrderEntity.java @@ -13,12 +13,39 @@ import lombok.Data; import org.hibernate.annotations.Comment; import org.hibernate.annotations.Formula; +import java.time.LocalDate; import java.util.List; @Data @Entity public class PurchaseOrderEntity extends OrgCommonEntity { - + + + + @Comment("采购日期") + private LocalDate purchaseDate; + + @Comment("预计到货日期") + private LocalDate estimateDeliveryDate; + + + @Formula("(select min(d.delivery_date) from t_delivery_information d where d.purchase_order_id = id)") + private LocalDate firstDeliveryDate; + + @Formula("(select max(d.delivery_date) from t_delivery_information d where d.purchase_order_id = id)") + private LocalDate lastDeliveryDate; + + + + @Formula("(estimate_delivery_date - now()::date)") + private Integer dayLeft; + + + @Formula("(estimate_delivery_date - purchase_date)") + private Integer dayAmount; + + + @ManyToOne @Comment("煤炭信息") private CoalInfoEntity coalInfo; @@ -57,6 +84,33 @@ public class PurchaseOrderEntity extends OrgCommonEntity { + " and i.code = order_status)") private String orderStatusName; + @Override + public void prePersist() { + super.prePersist(); + this.updateStatus(); + } + + private void updateStatus() { + if (this.purchaseDate.isBefore(LocalDate.now())){ + this.orderStatus = "0"; + }else { + + double total = this.deliveryInformationList == null ? 0: this.deliveryInformationList.stream().mapToDouble(DeliveryInformationEntity::getAmount).sum(); + + if (total >= this.amount){ + this.orderStatus = "2"; + }else { + this.orderStatus = "1"; + } + + } + } + + @Override + public void preUpdate() { + super.preUpdate(); + this.updateStatus(); + } public void setDeliveryInformationList(List deliveryInformationList) { if (deliveryInformationList == null) {