This commit is contained in:
2024-01-06 16:17:06 +08:00
parent d33dfb5118
commit 7b24b4fe58
5 changed files with 115 additions and 1 deletions

View File

@@ -24,5 +24,6 @@ public class UpdateDeliveryInformationDto extends OrgCommonDto {
private String purchaseOrder;
}

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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<cn.lihongjie.coal.deliveryInformation.entity.DeliveryInformationEntity> deliveryInformationList) {
if (deliveryInformationList == null) {