Commit e89eca99 by wutong

所有项目BigDecimal四舍五入修改; 自动周转加了异常记录.

parent f6af813a
...@@ -119,7 +119,7 @@ public class SyncCostFirstJob extends PointJob { ...@@ -119,7 +119,7 @@ public class SyncCostFirstJob extends PointJob {
if (totalWeight.compareTo(BigDecimal.ZERO) == 1) { if (totalWeight.compareTo(BigDecimal.ZERO) == 1) {
BigDecimal weightRatio = weight.divide(totalWeight, 4, RoundingMode.HALF_EVEN); BigDecimal weightRatio = weight.divide(totalWeight, 4, RoundingMode.HALF_EVEN);
dcBaseCostFirst.setRatioWeight(weightRatio); dcBaseCostFirst.setRatioWeight(weightRatio);
BigDecimal skuCostFirst = costFirstData.getCostFirst().multiply(weightRatio).setScale(3, BigDecimal.ROUND_HALF_EVEN); BigDecimal skuCostFirst = costFirstData.getCostFirst().multiply(weightRatio).setScale(3, RoundingMode.HALF_EVEN);
dcBaseCostFirst.setCostFirst(skuCostFirst); dcBaseCostFirst.setCostFirst(skuCostFirst);
if (i == costFirstData.getSkus().size() - 1) { if (i == costFirstData.getSkus().size() - 1) {
dcBaseCostFirst.setCostFirst(costFirstData.getCostFirst().subtract(totalRatioCostFrist)); dcBaseCostFirst.setCostFirst(costFirstData.getCostFirst().subtract(totalRatioCostFrist));
......
...@@ -75,7 +75,7 @@ public class RefundLinkOrderJob extends PointJob { ...@@ -75,7 +75,7 @@ public class RefundLinkOrderJob extends PointJob {
//利润率要重算 //利润率要重算
BigDecimal quantityOrderedDecimal = BigDecimal.valueOf(dcBaseOmsSku.getBailunSkuQuantityOrdered()); BigDecimal quantityOrderedDecimal = BigDecimal.valueOf(dcBaseOmsSku.getBailunSkuQuantityOrdered());
//退款摊到单个SKU //退款摊到单个SKU
dcBaseOmsSku.setAmountRefund(dcBaseCrmRefund.getAmountRefund().divide(quantityOrderedDecimal.compareTo(BigDecimal.ZERO) == 1? quantityOrderedDecimal : BigDecimal.ONE, 3, BigDecimal.ROUND_HALF_EVEN)); dcBaseOmsSku.setAmountRefund(dcBaseCrmRefund.getAmountRefund().divide(quantityOrderedDecimal.compareTo(BigDecimal.ZERO) == 1? quantityOrderedDecimal : BigDecimal.ONE, 3, RoundingMode.HALF_EVEN));
dcBaseOmsSku.setRefundTime(dcBaseCrmRefund.getRefundTime()); dcBaseOmsSku.setRefundTime(dcBaseCrmRefund.getRefundTime());
BigDecimal profitSku = dcBaseOmsSku.getProfitTotal().subtract(dcBaseOmsSku.getAmountRefund().multiply(dcBaseOmsSku.getSellerOrderExchangeRate())).setScale(3, RoundingMode.HALF_EVEN); BigDecimal profitSku = dcBaseOmsSku.getProfitTotal().subtract(dcBaseOmsSku.getAmountRefund().multiply(dcBaseOmsSku.getSellerOrderExchangeRate())).setScale(3, RoundingMode.HALF_EVEN);
dcBaseOmsSku.setProfitTotal(profitSku); dcBaseOmsSku.setProfitTotal(profitSku);
......
...@@ -405,8 +405,8 @@ public class OrderSyncJob extends PointJob { ...@@ -405,8 +405,8 @@ public class OrderSyncJob extends PointJob {
public void skuOrderFeeHandle(DcBaseOmsOrder dcBaseOmsOrder, BigDecimal totalWeight, Map<String, BailunSkuStructure> skuStructureMap, DcBaseOmsSku dcBaseOmsSku, OmsResult omsResult) { public void skuOrderFeeHandle(DcBaseOmsOrder dcBaseOmsOrder, BigDecimal totalWeight, Map<String, BailunSkuStructure> skuStructureMap, DcBaseOmsSku dcBaseOmsSku, OmsResult omsResult) {
OrderCharge orderCharge = omsResult.getOrderCharge(); OrderCharge orderCharge = omsResult.getOrderCharge();
//--begin 将采购单价 * 数量 / 总采购价 & SKU单个重量 * 数量 / 总重量 计算出来, 传递进费用计算 //--begin 将采购单价 * 数量 / 总采购价 & SKU单个重量 * 数量 / 总重量 计算出来, 传递进费用计算
BigDecimal costRatio = (orderCharge.getCostProduct() != null && orderCharge.getCostProduct().getAmount() != null && orderCharge.getCostProduct().getAmount().compareTo(BigDecimal.ZERO) != 0) ? dcBaseOmsSku.getBailunSkuUnitPrice().multiply(BigDecimal.valueOf(dcBaseOmsSku.getBailunSkuQuantityOrdered())).divide(orderCharge.getCostProduct().getAmount(), 4, BigDecimal.ROUND_HALF_EVEN) : BigDecimal.ONE; BigDecimal costRatio = (orderCharge.getCostProduct() != null && orderCharge.getCostProduct().getAmount() != null && orderCharge.getCostProduct().getAmount().compareTo(BigDecimal.ZERO) != 0) ? dcBaseOmsSku.getBailunSkuUnitPrice().multiply(BigDecimal.valueOf(dcBaseOmsSku.getBailunSkuQuantityOrdered())).divide(orderCharge.getCostProduct().getAmount(), 4, RoundingMode.HALF_EVEN) : BigDecimal.ONE;
BigDecimal weightRatio = (dcBaseOmsSku.getBailunSkuWeight() != null && totalWeight.compareTo(BigDecimal.ZERO) != 0) ? dcBaseOmsSku.getBailunSkuWeight().multiply(BigDecimal.valueOf(dcBaseOmsSku.getBailunSkuQuantityOrdered())).divide(totalWeight, 4, BigDecimal.ROUND_HALF_EVEN) : BigDecimal.ONE; BigDecimal weightRatio = (dcBaseOmsSku.getBailunSkuWeight() != null && totalWeight.compareTo(BigDecimal.ZERO) != 0) ? dcBaseOmsSku.getBailunSkuWeight().multiply(BigDecimal.valueOf(dcBaseOmsSku.getBailunSkuQuantityOrdered())).divide(totalWeight, 4, RoundingMode.HALF_EVEN) : BigDecimal.ONE;
dcBaseOmsSku.setRatioPrice(costRatio); dcBaseOmsSku.setRatioPrice(costRatio);
dcBaseOmsSku.setRatioWeight(weightRatio); dcBaseOmsSku.setRatioWeight(weightRatio);
skuStructureMap.put(dcBaseOmsSku.getBailunSku(), new BailunSkuStructure(dcBaseOmsSku.getBailunSku(), dcBaseOmsSku.getBailunSkuWeight(), dcBaseOmsSku.getBailunSkuUnitPrice() != null ? dcBaseOmsSku.getBailunSkuUnitPrice() : BigDecimal.ZERO, costRatio, weightRatio)); skuStructureMap.put(dcBaseOmsSku.getBailunSku(), new BailunSkuStructure(dcBaseOmsSku.getBailunSku(), dcBaseOmsSku.getBailunSkuWeight(), dcBaseOmsSku.getBailunSkuUnitPrice() != null ? dcBaseOmsSku.getBailunSkuUnitPrice() : BigDecimal.ZERO, costRatio, weightRatio));
......
...@@ -160,8 +160,8 @@ public class OrderSyncJob extends PointJob { ...@@ -160,8 +160,8 @@ public class OrderSyncJob extends PointJob {
bailunSkuStructure.setBailunSku(bailunSku.getBailunSku()); bailunSkuStructure.setBailunSku(bailunSku.getBailunSku());
bailunSkuStructure.setBailunSkuUnitPrice((bailunSku.getBailunSkuUnitPrice() != null&&bailunSku.getBailunSkuUnitPrice().getAmount() != null)?bailunSku.getBailunSkuUnitPrice().getAmount() : BigDecimal.ZERO); bailunSkuStructure.setBailunSkuUnitPrice((bailunSku.getBailunSkuUnitPrice() != null&&bailunSku.getBailunSkuUnitPrice().getAmount() != null)?bailunSku.getBailunSkuUnitPrice().getAmount() : BigDecimal.ZERO);
bailunSkuStructure.setBailunSkuWeight(bailunSku.getBailunSkuWeight() != null?bailunSku.getBailunSkuWeight() : BigDecimal.ZERO); bailunSkuStructure.setBailunSkuWeight(bailunSku.getBailunSkuWeight() != null?bailunSku.getBailunSkuWeight() : BigDecimal.ZERO);
bailunSkuStructure.setSkuCostRatio(dcBaseOmsOrder.getCostProduct().compareTo(BigDecimal.ZERO) ==1 ?bailunSkuStructure.getBailunSkuUnitPrice().multiply(BigDecimal.valueOf(bailunSku.getBailunSkuQuantityOrdered())).divide(dcBaseOmsOrder.getCostProduct(), 3 ,BigDecimal.ROUND_HALF_EVEN) : BigDecimal.ONE); bailunSkuStructure.setSkuCostRatio(dcBaseOmsOrder.getCostProduct().compareTo(BigDecimal.ZERO) ==1 ?bailunSkuStructure.getBailunSkuUnitPrice().multiply(BigDecimal.valueOf(bailunSku.getBailunSkuQuantityOrdered())).divide(dcBaseOmsOrder.getCostProduct(), 3 ,RoundingMode.HALF_EVEN) : BigDecimal.ONE);
bailunSkuStructure.setSkuWeightRatio(bailunSkuCumulative.getTotalWeight().compareTo(BigDecimal.ZERO) ==1 ? bailunSkuStructure.getBailunSkuWeight().multiply(BigDecimal.valueOf(bailunSku.getBailunSkuQuantityOrdered())).divide(bailunSkuCumulative.getTotalWeight(), 3 ,BigDecimal.ROUND_HALF_EVEN) : BigDecimal.ONE); bailunSkuStructure.setSkuWeightRatio(bailunSkuCumulative.getTotalWeight().compareTo(BigDecimal.ZERO) ==1 ? bailunSkuStructure.getBailunSkuWeight().multiply(BigDecimal.valueOf(bailunSku.getBailunSkuQuantityOrdered())).divide(bailunSkuCumulative.getTotalWeight(), 3 ,RoundingMode.HALF_EVEN) : BigDecimal.ONE);
bailunSkuStructure.setSkuQuantityOrderd(bailunSku.getBailunSkuQuantityOrdered() != null? bailunSku.getBailunSkuQuantityOrdered(): 0); bailunSkuStructure.setSkuQuantityOrderd(bailunSku.getBailunSkuQuantityOrdered() != null? bailunSku.getBailunSkuQuantityOrdered(): 0);
DcBaseOmsSku dcBaseOmsSku = new DcBaseOmsSku(); DcBaseOmsSku dcBaseOmsSku = new DcBaseOmsSku();
/* /*
...@@ -314,7 +314,7 @@ public class OrderSyncJob extends PointJob { ...@@ -314,7 +314,7 @@ public class OrderSyncJob extends PointJob {
.add(dcBaseOmsSku.getCostTail())//尾程费 .add(dcBaseOmsSku.getCostTail())//尾程费
.add(dcBaseOmsSku.getCostProduct())//采购成本 .add(dcBaseOmsSku.getCostProduct())//采购成本
.add(skuPaypalFeeRmb.divide(quantityOrderdDecimal, 3, RoundingMode.HALF_EVEN))//Paypal费 .add(skuPaypalFeeRmb.divide(quantityOrderdDecimal, 3, RoundingMode.HALF_EVEN))//Paypal费
.setScale(3, BigDecimal.ROUND_HALF_EVEN); .setScale(3, RoundingMode.HALF_EVEN);
} else { } else {
dcBaseOmsSku.setAmountAdjustment(BigDecimal.ZERO); dcBaseOmsSku.setAmountAdjustment(BigDecimal.ZERO);
dcBaseOmsSku.setAmountTax(BigDecimal.ZERO); dcBaseOmsSku.setAmountTax(BigDecimal.ZERO);
...@@ -368,7 +368,7 @@ public class OrderSyncJob extends PointJob { ...@@ -368,7 +368,7 @@ public class OrderSyncJob extends PointJob {
.add(dcBaseOmsOrder.getCostTail()) //尾程费 .add(dcBaseOmsOrder.getCostTail()) //尾程费
.add(dcBaseOmsOrder.getCostProduct())//采购成本 .add(dcBaseOmsOrder.getCostProduct())//采购成本
.add(totalCostPaypalFeeRMB)//Paypal费 .add(totalCostPaypalFeeRMB)//Paypal费
.setScale(3, BigDecimal.ROUND_HALF_EVEN); .setScale(3, RoundingMode.HALF_EVEN);
dcBaseOmsOrder.setCostTotal(costTotal); dcBaseOmsOrder.setCostTotal(costTotal);
//非OMS部分的利润直接减法运算 //非OMS部分的利润直接减法运算
dcBaseOmsOrder.setProfitTotal(totalProfit); dcBaseOmsOrder.setProfitTotal(totalProfit);
...@@ -683,8 +683,8 @@ public class OrderSyncJob extends PointJob { ...@@ -683,8 +683,8 @@ public class OrderSyncJob extends PointJob {
public void skuOrderFeeHandle(DcBaseOmsOrder dcBaseOmsOrder, BigDecimal totalWeight, Map<String, BailunSkuStructure> skuStructureMap, DcBaseOmsSku dcBaseOmsSku, OmsResult omsResult) { public void skuOrderFeeHandle(DcBaseOmsOrder dcBaseOmsOrder, BigDecimal totalWeight, Map<String, BailunSkuStructure> skuStructureMap, DcBaseOmsSku dcBaseOmsSku, OmsResult omsResult) {
OrderCharge orderCharge = omsResult.getOrderCharge(); OrderCharge orderCharge = omsResult.getOrderCharge();
//--begin 将采购单价 * 数量 / 总采购价 & SKU单个重量 * 数量 / 总重量 计算出来, 传递进费用计算 //--begin 将采购单价 * 数量 / 总采购价 & SKU单个重量 * 数量 / 总重量 计算出来, 传递进费用计算
BigDecimal costRatio = (orderCharge.getCostProduct() != null && orderCharge.getCostProduct().getAmount() != null && orderCharge.getCostProduct().getAmount().compareTo(BigDecimal.ZERO) != 0) ? dcBaseOmsSku.getBailunSkuUnitPrice().multiply(BigDecimal.valueOf(dcBaseOmsSku.getBailunSkuQuantityOrdered())).divide(orderCharge.getCostProduct().getAmount(), 4, BigDecimal.ROUND_HALF_EVEN) : BigDecimal.ONE; BigDecimal costRatio = (orderCharge.getCostProduct() != null && orderCharge.getCostProduct().getAmount() != null && orderCharge.getCostProduct().getAmount().compareTo(BigDecimal.ZERO) != 0) ? dcBaseOmsSku.getBailunSkuUnitPrice().multiply(BigDecimal.valueOf(dcBaseOmsSku.getBailunSkuQuantityOrdered())).divide(orderCharge.getCostProduct().getAmount(), 4, RoundingMode.HALF_EVEN) : BigDecimal.ONE;
BigDecimal weightRatio = (dcBaseOmsSku.getBailunSkuWeight() != null && totalWeight.compareTo(BigDecimal.ZERO) != 0) ? dcBaseOmsSku.getBailunSkuWeight().multiply(BigDecimal.valueOf(dcBaseOmsSku.getBailunSkuQuantityOrdered())).divide(totalWeight, 4, BigDecimal.ROUND_HALF_EVEN) : BigDecimal.ONE; BigDecimal weightRatio = (dcBaseOmsSku.getBailunSkuWeight() != null && totalWeight.compareTo(BigDecimal.ZERO) != 0) ? dcBaseOmsSku.getBailunSkuWeight().multiply(BigDecimal.valueOf(dcBaseOmsSku.getBailunSkuQuantityOrdered())).divide(totalWeight, 4, RoundingMode.HALF_EVEN) : BigDecimal.ONE;
dcBaseOmsSku.setRatioPrice(costRatio); dcBaseOmsSku.setRatioPrice(costRatio);
dcBaseOmsSku.setRatioWeight(weightRatio); dcBaseOmsSku.setRatioWeight(weightRatio);
skuStructureMap.put(dcBaseOmsSku.getBailunSku(), new BailunSkuStructure(dcBaseOmsSku.getBailunSku(), dcBaseOmsSku.getBailunSkuWeight(), dcBaseOmsSku.getBailunSkuUnitPrice() != null ? dcBaseOmsSku.getBailunSkuUnitPrice() : BigDecimal.ZERO, costRatio, weightRatio)); skuStructureMap.put(dcBaseOmsSku.getBailunSku(), new BailunSkuStructure(dcBaseOmsSku.getBailunSku(), dcBaseOmsSku.getBailunSkuWeight(), dcBaseOmsSku.getBailunSkuUnitPrice() != null ? dcBaseOmsSku.getBailunSkuUnitPrice() : BigDecimal.ZERO, costRatio, weightRatio));
...@@ -720,7 +720,7 @@ public class OrderSyncJob extends PointJob { ...@@ -720,7 +720,7 @@ public class OrderSyncJob extends PointJob {
DcMidFbaFeeAvgMapper dcMidFbaFeeAvgMapper = SessionUtil.getSession().getMapper(DcMidFbaFeeAvgMapper.class); DcMidFbaFeeAvgMapper dcMidFbaFeeAvgMapper = SessionUtil.getSession().getMapper(DcMidFbaFeeAvgMapper.class);
DcMidFbaFeeAvg dcMidFbaFeeAvg = dcMidFbaFeeAvgMapper.selectOneByExample(DcMidFbaFeeAvgExample.newAndCreateCriteria().andWebsiteEqualTo(dcBaseOmsSku.getWebsite()).andBailunSkuEqualTo(dcBaseOmsSku.getBailunSku()).example()); DcMidFbaFeeAvg dcMidFbaFeeAvg = dcMidFbaFeeAvgMapper.selectOneByExample(DcMidFbaFeeAvgExample.newAndCreateCriteria().andWebsiteEqualTo(dcBaseOmsSku.getWebsite()).andBailunSkuEqualTo(dcBaseOmsSku.getBailunSku()).example());
if (dcMidFbaFeeAvg != null && dcBaseOmsSku.getBailunSkuQuantityOrdered() != 0) { if (dcMidFbaFeeAvg != null && dcBaseOmsSku.getBailunSkuQuantityOrdered() != 0) {
BigDecimal fbaFeeRmb = dcBaseOmsSku.getCostFbaFee().multiply(dcBaseOmsSku.getFinanceOrderExchangeRate()).divide(BigDecimal.valueOf(dcBaseOmsSku.getBailunSkuQuantityOrdered()), 3, BigDecimal.ROUND_HALF_EVEN); BigDecimal fbaFeeRmb = dcBaseOmsSku.getCostFbaFee().multiply(dcBaseOmsSku.getFinanceOrderExchangeRate()).divide(BigDecimal.valueOf(dcBaseOmsSku.getBailunSkuQuantityOrdered()), 3, RoundingMode.HALF_EVEN);
if (fbaFeeRmb.compareTo(dcMidFbaFeeAvg.getMaxFbaFee()) == 1) { if (fbaFeeRmb.compareTo(dcMidFbaFeeAvg.getMaxFbaFee()) == 1) {
dcBaseOmsSku.setHasFbaException(true); dcBaseOmsSku.setHasFbaException(true);
isFbaFeeException = true; isFbaFeeException = true;
......
package com.bailuntec.domain.entity;
import lombok.Data;
@Data
public class DcAutoException {
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column dc_auto_exception.id
*
* @mbg.generated
*/
private Integer id;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column dc_auto_exception.bailun_sku
*
* @mbg.generated
*/
private String bailunSku;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column dc_auto_exception.warehouse_code
*
* @mbg.generated
*/
private String warehouseCode;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column dc_auto_exception.message
*
* @mbg.generated
*/
private String message;
public DcAutoException() {
}
public DcAutoException(String bailunSku, String warehouseCode, String message) {
this.bailunSku = bailunSku;
this.warehouseCode = warehouseCode;
this.message = message;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_auto_exception
*
* @mbg.generated
*/
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", id=").append(id);
sb.append(", bailunSku=").append(bailunSku);
sb.append(", warehouseCode=").append(warehouseCode);
sb.append(", message=").append(message);
sb.append("]");
return sb.toString();
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_auto_exception
*
* @mbg.generated
*/
@Override
public boolean equals(Object that) {
if (this == that) {
return true;
}
if (that == null) {
return false;
}
if (getClass() != that.getClass()) {
return false;
}
DcAutoException other = (DcAutoException) that;
return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
&& (this.getBailunSku() == null ? other.getBailunSku() == null : this.getBailunSku().equals(other.getBailunSku()))
&& (this.getWarehouseCode() == null ? other.getWarehouseCode() == null : this.getWarehouseCode().equals(other.getWarehouseCode()))
&& (this.getMessage() == null ? other.getMessage() == null : this.getMessage().equals(other.getMessage()));
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_auto_exception
*
* @mbg.generated
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
result = prime * result + ((getBailunSku() == null) ? 0 : getBailunSku().hashCode());
result = prime * result + ((getWarehouseCode() == null) ? 0 : getWarehouseCode().hashCode());
result = prime * result + ((getMessage() == null) ? 0 : getMessage().hashCode());
return result;
}
}
\ No newline at end of file
...@@ -13,6 +13,7 @@ import com.bailuntec.utils.SessionUtil; ...@@ -13,6 +13,7 @@ import com.bailuntec.utils.SessionUtil;
import com.dangdang.ddframe.job.api.ShardingContext; import com.dangdang.ddframe.job.api.ShardingContext;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List; import java.util.List;
public class CalculateCostFirstJob extends PointJob { public class CalculateCostFirstJob extends PointJob {
...@@ -27,7 +28,7 @@ public class CalculateCostFirstJob extends PointJob { ...@@ -27,7 +28,7 @@ public class CalculateCostFirstJob extends PointJob {
List<DcBaseCostFirst> dcBaseCostFirsts = dcBaseCostFirstMapper.listSkuWarehouseCostFirst((jobPointLog.getPageIndex() - 1) * jobPointLog.getPageSize(), jobPointLog.getPageSize()); List<DcBaseCostFirst> dcBaseCostFirsts = dcBaseCostFirstMapper.listSkuWarehouseCostFirst((jobPointLog.getPageIndex() - 1) * jobPointLog.getPageSize(), jobPointLog.getPageSize());
if (dcBaseCostFirsts != null && dcBaseCostFirsts.size() > 0) { if (dcBaseCostFirsts != null && dcBaseCostFirsts.size() > 0) {
for (DcBaseCostFirst dcBaseCostFirst : dcBaseCostFirsts) { for (DcBaseCostFirst dcBaseCostFirst : dcBaseCostFirsts) {
BigDecimal unitSkuCostFirst = dcBaseCostFirst.getCostFirst().divide(BigDecimal.valueOf(dcBaseCostFirst.getQuantity()), 3, BigDecimal.ROUND_HALF_EVEN); BigDecimal unitSkuCostFirst = dcBaseCostFirst.getCostFirst().divide(BigDecimal.valueOf(dcBaseCostFirst.getQuantity()), 3, RoundingMode.HALF_EVEN);
DcMidCostFirst dcMidCostFirst = new DcMidCostFirst(); DcMidCostFirst dcMidCostFirst = new DcMidCostFirst();
dcMidCostFirst.setBailunSku(dcBaseCostFirst.getBailunSku()); dcMidCostFirst.setBailunSku(dcBaseCostFirst.getBailunSku());
dcMidCostFirst.setWarehouseCode(dcBaseCostFirst.getWarehouseCode()); dcMidCostFirst.setWarehouseCode(dcBaseCostFirst.getWarehouseCode());
......
...@@ -106,7 +106,16 @@ public class AutoTurnoverJob extends PointJob { ...@@ -106,7 +106,16 @@ public class AutoTurnoverJob extends PointJob {
try { try {
autoTurnoverFromStock(queryTime, dcBaseStock); autoTurnoverFromStock(queryTime, dcBaseStock);
} catch (Exception e) { } catch (Exception e) {
log.warn(dcBaseStock.getBailunSku() + "<--SKU_仓库-->" + dcBaseStock.getWarehouseCode() + "出现异常", e); //错误记录到日志表, 任务跑完了再跑一次错误SKU
try {
DcAutoExceptionMapper dcAutoExceptionMapper = SessionUtil.getSession().getMapper(DcAutoExceptionMapper.class);
DcAutoException dcAutoException = new DcAutoException(dcBaseStock.getBailunSku(),dcBaseStock.getWarehouseCode(),e.toString());
dcAutoExceptionMapper.insertSelective(dcAutoException);
} catch (Exception ex) {
log.error("保存错误SKU失败,sku="+ dcBaseStock.getBailunSku() + ",仓库=" + dcBaseStock.getWarehouseCode()); ;
} finally {
SessionUtil.closeSession();
}
} }
} }
} }
...@@ -182,7 +191,7 @@ public class AutoTurnoverJob extends PointJob { ...@@ -182,7 +191,7 @@ public class AutoTurnoverJob extends PointJob {
dcAveragePurchase = dcAveragePurchaseMapper.selectOneByExample(DcAveragePurchaseExample.newAndCreateCriteria().andBailunSkuEqualTo(bailunSku).andWarehouseCodeEqualTo(warehouseCode).andSupplierIdEqualTo(turnoverSku.getSuppliersId()).example()); dcAveragePurchase = dcAveragePurchaseMapper.selectOneByExample(DcAveragePurchaseExample.newAndCreateCriteria().andBailunSkuEqualTo(bailunSku).andWarehouseCodeEqualTo(warehouseCode).andSupplierIdEqualTo(turnoverSku.getSuppliersId()).example());
DcAverageWarehouseMapper dcAverageWarehouseMapper = SessionUtil.getSession().getMapper(DcAverageWarehouseMapper.class); DcAverageWarehouseMapper dcAverageWarehouseMapper = SessionUtil.getSession().getMapper(DcAverageWarehouseMapper.class);
dcAverageWarehouse = dcAverageWarehouseMapper.selectOneByExample(DcAverageWarehouseExample.newAndCreateCriteria().andBailunSkuEqualTo(bailunSku).andWarehouseCodeEqualTo(warehouseCode).example()); dcAverageWarehouse = dcAverageWarehouseMapper.selectOneByExample(DcAverageWarehouseExample.newAndCreateCriteria().andBailunSkuEqualTo(bailunSku).andWarehouseCodeEqualTo(warehouseCode).example());
if (dcAveragePurchase != null && dcAveragePurchase.getPaymentType().equals(1)) { if (dcAveragePurchase != null && dcAveragePurchase.getPaymentType() != null && dcAveragePurchase.getPaymentType().equals(1)) {
paymentBeforeDelivery = 1; paymentBeforeDelivery = 1;
} }
} catch (Exception e) { } catch (Exception e) {
...@@ -868,7 +877,7 @@ public class AutoTurnoverJob extends PointJob { ...@@ -868,7 +877,7 @@ public class AutoTurnoverJob extends PointJob {
} else { } else {
v = dcAutoSales.getFitAVariable().doubleValue() * Math.exp(dcAutoSales.getFitBVariable().doubleValue() * (j + 31)); v = dcAutoSales.getFitAVariable().doubleValue() * Math.exp(dcAutoSales.getFitBVariable().doubleValue() * (j + 31));
} }
BigDecimal forecastSales = BigDecimal.valueOf(v < 0 ? 0 : v).setScale(0, RoundingMode.HALF_DOWN); BigDecimal forecastSales = BigDecimal.valueOf(v < 0 ? 0 : v).setScale(0, RoundingMode.HALF_EVEN);
forecastSalesList.set(j, forecastSales.compareTo(salesUpperLimit) == 1 ? salesUpperLimit : forecastSales); forecastSalesList.set(j, forecastSales.compareTo(salesUpperLimit) == 1 ? salesUpperLimit : forecastSales);
} }
} }
...@@ -899,13 +908,13 @@ public class AutoTurnoverJob extends PointJob { ...@@ -899,13 +908,13 @@ public class AutoTurnoverJob extends PointJob {
if (dcAutoConfigCorrection.getStartTime() != null && dcAutoConfigCorrection.getEndTime() == null) { if (dcAutoConfigCorrection.getStartTime() != null && dcAutoConfigCorrection.getEndTime() == null) {
int interval = Period.between(recordTime, dcAutoConfigCorrection.getStartTime()).getDays(); int interval = Period.between(recordTime, dcAutoConfigCorrection.getStartTime()).getDays();
BigDecimal param = dcAutoConfigCorrection.getParam(); BigDecimal param = dcAutoConfigCorrection.getParam();
forecastSalesList.set(interval, param.multiply(forecastSalesList.get(interval)).setScale(3, BigDecimal.ROUND_HALF_EVEN)); forecastSalesList.set(interval, param.multiply(forecastSalesList.get(interval)).setScale(3, RoundingMode.HALF_EVEN));
} else if (dcAutoConfigCorrection.getStartTime() != null && dcAutoConfigCorrection.getEndTime() != null) { } else if (dcAutoConfigCorrection.getStartTime() != null && dcAutoConfigCorrection.getEndTime() != null) {
int begin = Period.between(recordTime, dcAutoConfigCorrection.getStartTime()).getDays(); int begin = Period.between(recordTime, dcAutoConfigCorrection.getStartTime()).getDays();
int end = Period.between(recordTime, dcAutoConfigCorrection.getEndTime()).getDays(); int end = Period.between(recordTime, dcAutoConfigCorrection.getEndTime()).getDays();
end = (end > autoForecastDay.intValue()) ? autoForecastDay.intValue() : end; end = (end > autoForecastDay.intValue()) ? autoForecastDay.intValue() : end;
for (int i = begin; i <= end; i++) { for (int i = begin; i <= end; i++) {
forecastSalesList.set(i, dcAutoConfigCorrection.getParam().multiply(forecastSalesList.get(i)).setScale(3, BigDecimal.ROUND_HALF_EVEN)); forecastSalesList.set(i, dcAutoConfigCorrection.getParam().multiply(forecastSalesList.get(i)).setScale(3, RoundingMode.HALF_EVEN));
} }
} }
} }
...@@ -1225,7 +1234,7 @@ public class AutoTurnoverJob extends PointJob { ...@@ -1225,7 +1234,7 @@ public class AutoTurnoverJob extends PointJob {
.add(totalSales)//累计销量 .add(totalSales)//累计销量
.subtract(BigDecimal.valueOf(totalInbound.doubleValue()))//累计到货 .subtract(BigDecimal.valueOf(totalInbound.doubleValue()))//累计到货
.subtract(outStock > 0 ? BigDecimal.ZERO : BigDecimal.valueOf(realInventory.longValue())) //真实库存, 如果缺货就不减,不缺就减去 .subtract(outStock > 0 ? BigDecimal.ZERO : BigDecimal.valueOf(realInventory.longValue())) //真实库存, 如果缺货就不减,不缺就减去
.add(forecastSalesList.get(j)).setScale(0, BigDecimal.ROUND_DOWN);//预计销量 .add(forecastSalesList.get(j)).setScale(0, RoundingMode.HALF_EVEN);//预计销量
forecastPurchaseAdvisedList.add(totalAdvised); forecastPurchaseAdvisedList.add(totalAdvised);
if (totalAdvised.compareTo(moqDecimal) == 1) { if (totalAdvised.compareTo(moqDecimal) == 1) {
moqPurchaseAdvisedList.add(totalAdvised); moqPurchaseAdvisedList.add(totalAdvised);
...@@ -1355,7 +1364,7 @@ public class AutoTurnoverJob extends PointJob { ...@@ -1355,7 +1364,7 @@ public class AutoTurnoverJob extends PointJob {
.add(totalSales)//累计销量 .add(totalSales)//累计销量
.subtract(BigDecimal.valueOf(totalInbound.doubleValue()))//累计到货 .subtract(BigDecimal.valueOf(totalInbound.doubleValue()))//累计到货
.subtract(outStock > 0 ? BigDecimal.ZERO : BigDecimal.valueOf(realInventory.longValue())) //真实库存,如果缺货就不减 .subtract(outStock > 0 ? BigDecimal.ZERO : BigDecimal.valueOf(realInventory.longValue())) //真实库存,如果缺货就不减
.add(forecastSalesList.get(j)).setScale(0, BigDecimal.ROUND_DOWN);//预计销量 .add(forecastSalesList.get(j)).setScale(0, RoundingMode.HALF_EVEN);//预计销量
forecastPurchaseAdvisedList.add(totalAdvised); forecastPurchaseAdvisedList.add(totalAdvised);
if (totalAdvised.compareTo(moqDecimal) == 1) { if (totalAdvised.compareTo(moqDecimal) == 1) {
moqPurchaseAdvisedList.add(totalAdvised); moqPurchaseAdvisedList.add(totalAdvised);
......
package com.bailuntec.listener; package com.bailuntec.listener;
import com.bailuntec.domain.constant.CommonConstant;
import com.bailuntec.domain.entity.DcAutoException;
import com.bailuntec.domain.entity.DcBaseStock;
import com.bailuntec.domain.example.DcAutoExceptionExample;
import com.bailuntec.domain.example.DcBaseStockExample;
import com.bailuntec.job.AutoTurnoverJob;
import com.bailuntec.mapper.DcAutoExceptionMapper;
import com.bailuntec.mapper.DcAutoTurnoverMapper; import com.bailuntec.mapper.DcAutoTurnoverMapper;
import com.bailuntec.mapper.DcBaseStockMapper;
import com.bailuntec.utils.SessionUtil; import com.bailuntec.utils.SessionUtil;
import com.dangdang.ddframe.job.executor.ShardingContexts; import com.dangdang.ddframe.job.executor.ShardingContexts;
import com.dangdang.ddframe.job.lite.api.listener.ElasticJobListener; import com.dangdang.ddframe.job.lite.api.listener.ElasticJobListener;
import org.apache.ibatis.session.SqlSession;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
public class AutoTurnoverJobListener implements ElasticJobListener { public class AutoTurnoverJobListener implements ElasticJobListener {
@Override @Override
...@@ -15,7 +28,7 @@ public class AutoTurnoverJobListener implements ElasticJobListener { ...@@ -15,7 +28,7 @@ public class AutoTurnoverJobListener implements ElasticJobListener {
autoTurnoverMapper.truncateAutoShortSupplyTable(); autoTurnoverMapper.truncateAutoShortSupplyTable();
autoTurnoverMapper.truncateAutoTurnoverTable(); autoTurnoverMapper.truncateAutoTurnoverTable();
autoTurnoverMapper.truncateAutoSalesTable(); autoTurnoverMapper.truncateAutoSalesTable();
SessionUtil.getSession().commit(); autoTurnoverMapper.truncateAutoExceptionTable();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
throw new RuntimeException("Mybatis操作DB失败", e); throw new RuntimeException("Mybatis操作DB失败", e);
...@@ -26,6 +39,37 @@ public class AutoTurnoverJobListener implements ElasticJobListener { ...@@ -26,6 +39,37 @@ public class AutoTurnoverJobListener implements ElasticJobListener {
@Override @Override
public void afterJobExecuted(ShardingContexts shardingContexts) { public void afterJobExecuted(ShardingContexts shardingContexts) {
String queryTime = DateTimeFormatter.ofPattern(CommonConstant.DATE_FORMAT).format(LocalDate.now());
int pageIndex = 0;
int pageSize = 1000;
AutoTurnoverJob autoTurnoverJob = new AutoTurnoverJob();
List<DcAutoException> dcAutoExceptions = null;
SqlSession sqlSession = SessionUtil.getFactory().openSession(true);
try {
DcAutoExceptionMapper mapper = sqlSession.getMapper(DcAutoExceptionMapper.class);
DcBaseStockMapper dcBaseStockMapper = sqlSession.getMapper(DcBaseStockMapper.class);
do {
dcAutoExceptions = mapper.selectByExample(DcAutoExceptionExample.newAndCreateCriteria().example().limit(pageIndex * pageSize, pageSize));
if (dcAutoExceptions != null && dcAutoExceptions.size() >0) {
for (DcAutoException dcAutoException : dcAutoExceptions) {
DcBaseStock dcBaseStock = dcBaseStockMapper.selectOneByExample(DcBaseStockExample.newAndCreateCriteria().andBailunSkuEqualTo(dcAutoException.getBailunSku()).andWarehouseCodeEqualTo(dcAutoException.getWarehouseCode()).example());
try {
autoTurnoverJob.autoTurnoverFromStock(queryTime, dcBaseStock);
} catch (Exception e) {
throw new RuntimeException("Mybatis操作自动周转异常数据再次计算失败SKU=" + dcAutoException.getBailunSku() + ",仓库编码=" + dcAutoException.getWarehouseCode(), e);
}
mapper.deleteByPrimaryKey(dcAutoException.getId());
}
}
pageIndex++;
} while (dcAutoExceptions != null && dcAutoExceptions.size() == pageSize);
} catch (RuntimeException e) {
throw new RuntimeException("Mybatis操作自动周转异常数据再次计算失败", e);
} finally {
if (sqlSession != null) {
sqlSession.close();
}
}
} }
} }
package com.bailuntec.mapper;
import com.bailuntec.domain.entity.DcAutoException;
import com.bailuntec.domain.example.DcAutoExceptionExample;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface DcAutoExceptionMapper {
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_auto_exception
*
* @mbg.generated
*/
long countByExample(DcAutoExceptionExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_auto_exception
*
* @mbg.generated
*/
int deleteByExample(DcAutoExceptionExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_auto_exception
*
* @mbg.generated
*/
int deleteByPrimaryKey(Integer id);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_auto_exception
*
* @mbg.generated
*/
int insert(DcAutoException record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_auto_exception
*
* @mbg.generated
*/
int insertSelective(DcAutoException record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_auto_exception
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
DcAutoException selectOneByExample(DcAutoExceptionExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_auto_exception
*
* @mbg.generated
*/
List<DcAutoException> selectByExample(DcAutoExceptionExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_auto_exception
*
* @mbg.generated
*/
DcAutoException selectByPrimaryKey(Integer id);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_auto_exception
*
* @mbg.generated
*/
int updateByExampleSelective(@Param("record") DcAutoException record, @Param("example") DcAutoExceptionExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_auto_exception
*
* @mbg.generated
*/
int updateByExample(@Param("record") DcAutoException record, @Param("example") DcAutoExceptionExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_auto_exception
*
* @mbg.generated
*/
int updateByPrimaryKeySelective(DcAutoException record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_auto_exception
*
* @mbg.generated
*/
int updateByPrimaryKey(DcAutoException record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_auto_exception
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
int upsert(DcAutoException record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_auto_exception
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
int upsertSelective(DcAutoException record);
}
\ No newline at end of file
...@@ -132,4 +132,6 @@ public interface DcAutoTurnoverMapper { ...@@ -132,4 +132,6 @@ public interface DcAutoTurnoverMapper {
void truncateAutoTurnoverTable(); void truncateAutoTurnoverTable();
void truncateAutoSalesTable(); void truncateAutoSalesTable();
void truncateAutoExceptionTable();
} }
\ No newline at end of file
...@@ -1667,5 +1667,8 @@ ...@@ -1667,5 +1667,8 @@
<delete id="truncateAutoSalesTable"> <delete id="truncateAutoSalesTable">
TRUNCATE dc_auto_sales TRUNCATE dc_auto_sales
</delete> </delete>
<delete id="truncateAutoExceptionTable">
TRUNCATE dc_auto_exception
</delete>
</mapper> </mapper>
\ No newline at end of file
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
<result column="delivery_days" jdbcType="INTEGER" property="deliveryDays" /> <result column="delivery_days" jdbcType="INTEGER" property="deliveryDays" />
<result column="inbound_days" jdbcType="INTEGER" property="inboundDays" /> <result column="inbound_days" jdbcType="INTEGER" property="inboundDays" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" /> <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
<result column="payment_type" jdbcType="TINYINT" property="paymentType" />
</resultMap> </resultMap>
<sql id="Example_Where_Clause"> <sql id="Example_Where_Clause">
<!-- <!--
...@@ -88,7 +89,7 @@ ...@@ -88,7 +89,7 @@
This element is automatically generated by MyBatis Generator, do not modify. This element is automatically generated by MyBatis Generator, do not modify.
--> -->
ID, bailun_sku, warehouse_code, supplier_id, supplier_name, price, delivery_days, ID, bailun_sku, warehouse_code, supplier_id, supplier_name, price, delivery_days,
inbound_days, update_time inbound_days, update_time, payment_type
</sql> </sql>
<select id="selectByExample" parameterType="com.bailuntec.domain.example.DcAveragePurchaseExample" resultMap="BaseResultMap"> <select id="selectByExample" parameterType="com.bailuntec.domain.example.DcAveragePurchaseExample" resultMap="BaseResultMap">
<!-- <!--
...@@ -151,12 +152,12 @@ ...@@ -151,12 +152,12 @@
--> -->
insert into dc_average_purchase (ID, bailun_sku, warehouse_code, insert into dc_average_purchase (ID, bailun_sku, warehouse_code,
supplier_id, supplier_name, price, supplier_id, supplier_name, price,
delivery_days, inbound_days, update_time delivery_days, inbound_days, update_time,
) payment_type)
values (#{id,jdbcType=INTEGER}, #{bailunSku,jdbcType=VARCHAR}, #{warehouseCode,jdbcType=VARCHAR}, values (#{id,jdbcType=INTEGER}, #{bailunSku,jdbcType=VARCHAR}, #{warehouseCode,jdbcType=VARCHAR},
#{supplierId,jdbcType=INTEGER}, #{supplierName,jdbcType=VARCHAR}, #{price,jdbcType=DECIMAL}, #{supplierId,jdbcType=INTEGER}, #{supplierName,jdbcType=VARCHAR}, #{price,jdbcType=DECIMAL},
#{deliveryDays,jdbcType=INTEGER}, #{inboundDays,jdbcType=INTEGER}, #{updateTime,jdbcType=TIMESTAMP} #{deliveryDays,jdbcType=INTEGER}, #{inboundDays,jdbcType=INTEGER}, #{updateTime,jdbcType=TIMESTAMP},
) #{paymentType,jdbcType=TINYINT})
</insert> </insert>
<insert id="insertSelective" parameterType="com.bailuntec.domain.entity.DcAveragePurchase"> <insert id="insertSelective" parameterType="com.bailuntec.domain.entity.DcAveragePurchase">
<!-- <!--
...@@ -192,6 +193,9 @@ ...@@ -192,6 +193,9 @@
<if test="updateTime != null"> <if test="updateTime != null">
update_time, update_time,
</if> </if>
<if test="paymentType != null">
payment_type,
</if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null"> <if test="id != null">
...@@ -221,6 +225,9 @@ ...@@ -221,6 +225,9 @@
<if test="updateTime != null"> <if test="updateTime != null">
#{updateTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP},
</if> </if>
<if test="paymentType != null">
#{paymentType,jdbcType=TINYINT},
</if>
</trim> </trim>
</insert> </insert>
<select id="countByExample" parameterType="com.bailuntec.domain.example.DcAveragePurchaseExample" resultType="java.lang.Long"> <select id="countByExample" parameterType="com.bailuntec.domain.example.DcAveragePurchaseExample" resultType="java.lang.Long">
...@@ -267,6 +274,9 @@ ...@@ -267,6 +274,9 @@
<if test="record.updateTime != null"> <if test="record.updateTime != null">
update_time = #{record.updateTime,jdbcType=TIMESTAMP}, update_time = #{record.updateTime,jdbcType=TIMESTAMP},
</if> </if>
<if test="record.paymentType != null">
payment_type = #{record.paymentType,jdbcType=TINYINT},
</if>
</set> </set>
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" /> <include refid="Update_By_Example_Where_Clause" />
...@@ -286,7 +296,8 @@ ...@@ -286,7 +296,8 @@
price = #{record.price,jdbcType=DECIMAL}, price = #{record.price,jdbcType=DECIMAL},
delivery_days = #{record.deliveryDays,jdbcType=INTEGER}, delivery_days = #{record.deliveryDays,jdbcType=INTEGER},
inbound_days = #{record.inboundDays,jdbcType=INTEGER}, inbound_days = #{record.inboundDays,jdbcType=INTEGER},
update_time = #{record.updateTime,jdbcType=TIMESTAMP} update_time = #{record.updateTime,jdbcType=TIMESTAMP},
payment_type = #{record.paymentType,jdbcType=TINYINT}
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" /> <include refid="Update_By_Example_Where_Clause" />
</if> </if>
...@@ -322,6 +333,9 @@ ...@@ -322,6 +333,9 @@
<if test="updateTime != null"> <if test="updateTime != null">
update_time = #{updateTime,jdbcType=TIMESTAMP}, update_time = #{updateTime,jdbcType=TIMESTAMP},
</if> </if>
<if test="paymentType != null">
payment_type = #{paymentType,jdbcType=TINYINT},
</if>
</set> </set>
where ID = #{id,jdbcType=INTEGER} where ID = #{id,jdbcType=INTEGER}
</update> </update>
...@@ -338,7 +352,8 @@ ...@@ -338,7 +352,8 @@
price = #{price,jdbcType=DECIMAL}, price = #{price,jdbcType=DECIMAL},
delivery_days = #{deliveryDays,jdbcType=INTEGER}, delivery_days = #{deliveryDays,jdbcType=INTEGER},
inbound_days = #{inboundDays,jdbcType=INTEGER}, inbound_days = #{inboundDays,jdbcType=INTEGER},
update_time = #{updateTime,jdbcType=TIMESTAMP} update_time = #{updateTime,jdbcType=TIMESTAMP},
payment_type = #{paymentType,jdbcType=TINYINT}
where ID = #{id,jdbcType=INTEGER} where ID = #{id,jdbcType=INTEGER}
</update> </update>
<insert id="upsertSelective" parameterType="com.bailuntec.domain.entity.DcAveragePurchase"> <insert id="upsertSelective" parameterType="com.bailuntec.domain.entity.DcAveragePurchase">
...@@ -376,6 +391,9 @@ ...@@ -376,6 +391,9 @@
<if test="updateTime != null"> <if test="updateTime != null">
update_time, update_time,
</if> </if>
<if test="paymentType != null">
payment_type,
</if>
</trim> </trim>
values values
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
...@@ -406,6 +424,9 @@ ...@@ -406,6 +424,9 @@
<if test="updateTime != null"> <if test="updateTime != null">
#{updateTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP},
</if> </if>
<if test="paymentType != null">
#{paymentType,jdbcType=TINYINT},
</if>
</trim> </trim>
on duplicate key update on duplicate key update
<trim suffixOverrides=","> <trim suffixOverrides=",">
...@@ -436,6 +457,9 @@ ...@@ -436,6 +457,9 @@
<if test="updateTime != null"> <if test="updateTime != null">
update_time = #{updateTime,jdbcType=TIMESTAMP}, update_time = #{updateTime,jdbcType=TIMESTAMP},
</if> </if>
<if test="paymentType != null">
payment_type = #{paymentType,jdbcType=TINYINT},
</if>
</trim> </trim>
</insert> </insert>
<insert id="upsert" parameterType="com.bailuntec.domain.entity.DcAveragePurchase"> <insert id="upsert" parameterType="com.bailuntec.domain.entity.DcAveragePurchase">
...@@ -446,12 +470,12 @@ ...@@ -446,12 +470,12 @@
--> -->
insert into dc_average_purchase insert into dc_average_purchase
(ID, bailun_sku, warehouse_code, supplier_id, supplier_name, price, delivery_days, (ID, bailun_sku, warehouse_code, supplier_id, supplier_name, price, delivery_days,
inbound_days, update_time) inbound_days, update_time, payment_type)
values values
(#{id,jdbcType=INTEGER}, #{bailunSku,jdbcType=VARCHAR}, #{warehouseCode,jdbcType=VARCHAR}, (#{id,jdbcType=INTEGER}, #{bailunSku,jdbcType=VARCHAR}, #{warehouseCode,jdbcType=VARCHAR},
#{supplierId,jdbcType=INTEGER}, #{supplierName,jdbcType=VARCHAR}, #{price,jdbcType=DECIMAL}, #{supplierId,jdbcType=INTEGER}, #{supplierName,jdbcType=VARCHAR}, #{price,jdbcType=DECIMAL},
#{deliveryDays,jdbcType=INTEGER}, #{inboundDays,jdbcType=INTEGER}, #{updateTime,jdbcType=TIMESTAMP} #{deliveryDays,jdbcType=INTEGER}, #{inboundDays,jdbcType=INTEGER}, #{updateTime,jdbcType=TIMESTAMP},
) #{paymentType,jdbcType=TINYINT})
on duplicate key update on duplicate key update
ID = #{id,jdbcType=INTEGER}, ID = #{id,jdbcType=INTEGER},
bailun_sku = #{bailunSku,jdbcType=VARCHAR}, bailun_sku = #{bailunSku,jdbcType=VARCHAR},
...@@ -461,7 +485,8 @@ ...@@ -461,7 +485,8 @@
price = #{price,jdbcType=DECIMAL}, price = #{price,jdbcType=DECIMAL},
delivery_days = #{deliveryDays,jdbcType=INTEGER}, delivery_days = #{deliveryDays,jdbcType=INTEGER},
inbound_days = #{inboundDays,jdbcType=INTEGER}, inbound_days = #{inboundDays,jdbcType=INTEGER},
update_time = #{updateTime,jdbcType=TIMESTAMP} update_time = #{updateTime,jdbcType=TIMESTAMP},
payment_type = #{paymentType,jdbcType=TINYINT}
</insert> </insert>
<select id="selectOneByExample" parameterType="com.bailuntec.domain.example.DcAveragePurchaseExample" resultMap="BaseResultMap"> <select id="selectOneByExample" parameterType="com.bailuntec.domain.example.DcAveragePurchaseExample" resultMap="BaseResultMap">
<!-- <!--
......
import com.bailuntec.domain.constant.CommonConstant; import com.bailuntec.domain.constant.CommonConstant;
import com.bailuntec.domain.entity.DcBaseStock; import com.bailuntec.domain.entity.DcBaseStock;
import com.bailuntec.domain.entity.JobPointLog;
import com.bailuntec.domain.example.DcBaseStockExample; import com.bailuntec.domain.example.DcBaseStockExample;
import com.bailuntec.job.AutoTurnoverJob; import com.bailuntec.job.AutoTurnoverJob;
import com.bailuntec.listener.AutoTurnoverJobListener;
import com.bailuntec.mapper.DcBaseStockMapper; import com.bailuntec.mapper.DcBaseStockMapper;
import com.bailuntec.utils.SessionUtil; import com.bailuntec.utils.SessionUtil;
import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.executor.ShardingContexts;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.Period; import java.time.Period;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.List; import java.util.List;
public class AutoTurnoverTest { public class AutoTurnoverTest {
...@@ -45,7 +50,7 @@ public class AutoTurnoverTest { ...@@ -45,7 +50,7 @@ public class AutoTurnoverTest {
try { try {
DcBaseStockMapper mapper = SessionUtil.getSession().getMapper(DcBaseStockMapper.class); DcBaseStockMapper mapper = SessionUtil.getSession().getMapper(DcBaseStockMapper.class);
// dcBaseStock = mapper.selectOneByExample(DcBaseStockExample.newAndCreateCriteria().andBailunSkuEqualTo("322572421").andWarehouseCodeEqualTo("QYBLZZ").example()); // dcBaseStock = mapper.selectOneByExample(DcBaseStockExample.newAndCreateCriteria().andBailunSkuEqualTo("322572421").andWarehouseCodeEqualTo("QYBLZZ").example());
dcBaseStock = mapper.selectOneByExample(DcBaseStockExample.newAndCreateCriteria().andBailunSkuEqualTo("377891505").andWarehouseCodeEqualTo("QYBLZZ").example()); dcBaseStock = mapper.selectOneByExample(DcBaseStockExample.newAndCreateCriteria().andBailunSkuEqualTo("273129601").andWarehouseCodeEqualTo("GZBLWH").example());
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
...@@ -73,38 +78,17 @@ public class AutoTurnoverTest { ...@@ -73,38 +78,17 @@ public class AutoTurnoverTest {
@Test @Test
public void test4() { public void test4() {
AutoTurnoverJob autoTurnoverJob = new AutoTurnoverJob(); AutoTurnoverJob autoTurnoverJob = new AutoTurnoverJob();
int totalPage = 20; HashMap<Integer, String> map = new HashMap<>();
if (totalPage > 0) { map.put(1,"");
int page = 0; ShardingContext shardingContext = new ShardingContext(new ShardingContexts("","",1,"", map), 0);
List<DcBaseStock> dcBaseStockList = null;//分页查SKU_仓库 JobPointLog jobPointLog = new JobPointLog("", 1, 1, 1, 1, LocalDateTime.now().minusSeconds(1), LocalDateTime.now());
String queryTime = DateTimeFormatter.ofPattern(CommonConstant.DATE_FORMAT).format(LocalDate.now()); autoTurnoverJob.executeJob(shardingContext, jobPointLog);
do { }
try {
DcBaseStockMapper baseStockMapperFor = SessionUtil.getSession().getMapper(DcBaseStockMapper.class); @Test
dcBaseStockList = baseStockMapperFor.listNoChinaWarehouse(page * 1000, 1000); public void test5() {
} catch (Exception e) { AutoTurnoverJobListener autoTurnoverJobListener = new AutoTurnoverJobListener();
e.printStackTrace(); autoTurnoverJobListener.afterJobExecuted(null);
throw new RuntimeException("Mybatis操作DB失败", e);
} finally {
SessionUtil.closeSession();
}
if (dcBaseStockList != null && dcBaseStockList.size() > 0) {
/*
* 根据SKU_仓库信息,
* 初始化自动周转对象
* 去取其他数据
*/
for (DcBaseStock dcBaseStock : dcBaseStockList) {
try {
autoTurnoverJob.autoTurnoverFromStock(queryTime, dcBaseStock);
} catch (Exception e) {
continue;
}
}
}
page++;
} while (page < totalPage);
}
} }
} }
table-name=dc_auto_turnover table-name=dc_average_purchase
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment