|
@@ -0,0 +1,132 @@
|
|
|
+import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
+import com.ruoyi.common.core.domain.BaseIdPo;
|
|
|
+import com.sd.SdApplication;
|
|
|
+import com.sd.business.entity.bom.bo.BomSpecBo;
|
|
|
+import com.sd.business.entity.order.po.OrderInfo;
|
|
|
+import com.sd.business.entity.order.po.OrderSku;
|
|
|
+import com.sd.business.entity.sku.po.SkuSpec;
|
|
|
+import com.sd.business.service.order.OrderService;
|
|
|
+import com.sd.business.service.order.OrderSkuService;
|
|
|
+import com.sd.business.service.sku.SkuSpecService;
|
|
|
+import lombok.SneakyThrows;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.junit.Test;
|
|
|
+import org.junit.runner.RunWith;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.boot.test.context.SpringBootTest;
|
|
|
+import org.springframework.test.context.junit4.SpringRunner;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@RunWith(SpringRunner.class)
|
|
|
+@SpringBootTest(classes = SdApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
|
|
|
+public class G1_bzEvaSync {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OrderService orderService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OrderSkuService orderSkuService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SkuSpecService skuSpecService;
|
|
|
+
|
|
|
+ @SneakyThrows
|
|
|
+ @DSTransactional
|
|
|
+ @Test
|
|
|
+ public void test() {
|
|
|
+
|
|
|
+ // 查询白卓订单
|
|
|
+ List<OrderInfo> list = orderService.list(q -> q.eq(OrderInfo::getDepartmentId, 1689164627162529793L));
|
|
|
+
|
|
|
+ List<Long> orderIdList = list.stream().map(BaseIdPo::getId).collect(Collectors.toList());
|
|
|
+ List<OrderSku> orderSkuList = orderSkuService.list(q -> q.in(OrderSku::getOrderId, orderIdList));
|
|
|
+
|
|
|
+ List<Long> bomSpecIdList = orderSkuList.stream().map(OrderSku::getBomSpecId).collect(Collectors.toList());
|
|
|
+ Map<Long, BomSpecBo> bomSpecBoMap = skuSpecService.getBomSpecBoByIdList(bomSpecIdList);
|
|
|
+
|
|
|
+ Map<Long, List<OrderSku>> orderSkuMap = orderSkuList.stream().collect(Collectors.groupingBy(OrderSku::getOrderId));
|
|
|
+
|
|
|
+
|
|
|
+ Map<Long, SkuSpec> skuSpecMap = skuSpecService.mapKEntity(BaseIdPo::getId, null);
|
|
|
+
|
|
|
+
|
|
|
+ for (OrderInfo orderInfo : list) {
|
|
|
+
|
|
|
+ boolean flag = false;
|
|
|
+
|
|
|
+ List<OrderSku> tempOrderSkuList = orderSkuMap.get(orderInfo.getId());
|
|
|
+
|
|
|
+ for (OrderSku orderSku : tempOrderSkuList) {
|
|
|
+
|
|
|
+ BomSpecBo bomSpecBo = bomSpecBoMap.get(orderSku.getBomSpecId());
|
|
|
+ if (bomSpecBo == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ SkuSpec skuSpec = skuSpecMap.get(orderSku.getSkuSpecId());
|
|
|
+ if (skuSpec == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ String bomSpecies = bomSpecBo.getBomSpecies();
|
|
|
+
|
|
|
+ // 如果不是eva材质
|
|
|
+ if (!Objects.equals(bomSpecies, "EVA")) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 加工计费标准
|
|
|
+ BigDecimal customProcessingFee = orderSku.getCustomProcessingFee();
|
|
|
+ // 保证人工费
|
|
|
+ BigDecimal packingLabor = orderSku.getPackingLabor();
|
|
|
+ // 代发费
|
|
|
+ BigDecimal lssueFee = orderSku.getLssueFee();
|
|
|
+ // 快递包材费
|
|
|
+ BigDecimal deliveryMaterialsFee = orderSku.getDeliveryMaterialsFee();
|
|
|
+ // 管理费
|
|
|
+ BigDecimal managementFee = orderSku.getManagementFee();
|
|
|
+
|
|
|
+ BigDecimal fee = Objects.equals(skuSpec.getMachinedPanel(), "20") ? new BigDecimal("0.5") : BigDecimal.ZERO;
|
|
|
+
|
|
|
+ orderSku.setCustomProcessingFee(fee);
|
|
|
+ orderSku.setPackingLabor(new BigDecimal("0.17"));
|
|
|
+ orderSku.setLssueFee(new BigDecimal("0.50"));
|
|
|
+ orderSku.setDeliveryMaterialsFee(new BigDecimal("0.28"));
|
|
|
+ orderSku.setManagementFee(new BigDecimal("0"));
|
|
|
+
|
|
|
+ // 计算出改变值
|
|
|
+ customProcessingFee = fee.subtract(customProcessingFee).multiply(orderSku.getQuantity());
|
|
|
+ packingLabor = new BigDecimal("0.17").subtract(packingLabor).multiply(orderSku.getQuantity());
|
|
|
+ lssueFee = new BigDecimal("0.50").subtract(lssueFee).multiply(orderSku.getQuantity());
|
|
|
+ deliveryMaterialsFee = new BigDecimal("0.28").subtract(deliveryMaterialsFee).multiply(orderSku.getQuantity());
|
|
|
+ managementFee = new BigDecimal("0").subtract(managementFee).multiply(orderSku.getQuantity());
|
|
|
+
|
|
|
+ BigDecimal totalAmount = customProcessingFee.add(lssueFee).add(deliveryMaterialsFee).add(packingLabor).add(managementFee);
|
|
|
+
|
|
|
+ orderInfo.setCustomProcessingFee(orderInfo.getCustomProcessingFee().add(customProcessingFee));
|
|
|
+ orderInfo.setLssueFee(orderInfo.getLssueFee().add(lssueFee));
|
|
|
+ orderInfo.setDeliveryMaterialsFee(orderInfo.getDeliveryMaterialsFee().add(deliveryMaterialsFee));
|
|
|
+ orderInfo.setPackingLabor(orderInfo.getPackingLabor().add(packingLabor));
|
|
|
+ orderInfo.setManagementFee(orderInfo.getManagementFee().add(managementFee));
|
|
|
+ orderInfo.setTotalAmount(orderInfo.getTotalAmount().add(totalAmount));
|
|
|
+
|
|
|
+ flag = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (flag) {
|
|
|
+ orderService.updateById(orderInfo);
|
|
|
+ orderSkuService.updateBatchById(tempOrderSkuList);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|