调整应付配置和应付列表订单的费用重算
This commit is contained in:
@@ -19,6 +19,7 @@ import com.bms.price.domain.PayOrderQuery;
|
||||
import com.bms.price.domain.PayOrderRecalcCommand;
|
||||
import com.bms.price.domain.PayOrderRecalcTask;
|
||||
import com.bms.price.service.IPayOrderListService;
|
||||
import com.bms.price.service.IPrcOrderBillService;
|
||||
|
||||
/** 提单管理下的应付列表。 */
|
||||
@RestController
|
||||
@@ -28,6 +29,9 @@ public class PayOrderController extends BaseController
|
||||
@Autowired
|
||||
private IPayOrderListService payOrderListService;
|
||||
|
||||
@Autowired
|
||||
private IPrcOrderBillService orderBillService;
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('price:payOrder:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(PayOrderQuery query)
|
||||
@@ -82,6 +86,19 @@ public class PayOrderController extends BaseController
|
||||
return success(payOrderListService.cancelRecalc(taskId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 应付列表里的订单详情。带出应收费用和应付费用,不按计费列表的销售员权限过滤。
|
||||
*
|
||||
* @param billId 计费订单 ID
|
||||
* @return 订单、应收明细和应付明细
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('price:payOrder:query')")
|
||||
@GetMapping("/{billId}")
|
||||
public AjaxResult detail(@PathVariable Long billId)
|
||||
{
|
||||
return success(orderBillService.getPayOrderBill(billId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看一票订单的应付费用,按 A、B、C、D 四段返回。
|
||||
*
|
||||
|
||||
+25
-21
@@ -30,10 +30,10 @@ import com.bms.price.domain.PayProduct;
|
||||
import com.bms.price.domain.PayProductTerm;
|
||||
import com.bms.price.domain.PaySaveCommand;
|
||||
import com.bms.price.pay.PayDetailExporter;
|
||||
import com.bms.price.domain.PaySurchargeRuleSave;
|
||||
import com.bms.price.pay.PayChargeMode;
|
||||
import com.bms.price.pay.PayTemplateWorkbook;
|
||||
import com.bms.price.service.IPayOrderCostService;
|
||||
import com.bms.price.service.IPayProductService;
|
||||
import com.bms.price.service.IPaySurchargeRuleService;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
@@ -49,9 +49,6 @@ public class PayProductController extends BaseController
|
||||
@Autowired
|
||||
private IPayOrderCostService payOrderCostService;
|
||||
|
||||
@Autowired
|
||||
private IPaySurchargeRuleService paySurchargeRuleService;
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('price:pay:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(PayProduct query)
|
||||
@@ -107,29 +104,36 @@ public class PayProductController extends BaseController
|
||||
payProductService.writeSource(productId, response.getOutputStream());
|
||||
}
|
||||
|
||||
/** 产品上的附加费计费条件。不按价格版本拆开。 */
|
||||
@PreAuthorize("@ss.hasAnyPermi('price:pay:query,price:pay:edit')")
|
||||
@GetMapping("/surchargeRule")
|
||||
public AjaxResult surchargeRule(@RequestParam Long productId, @RequestParam(required = false) Long termId)
|
||||
/** 下载所选计费模式的标准模板 */
|
||||
@PreAuthorize("@ss.hasAnyPermi('price:pay:import,price:pay:add')")
|
||||
@PostMapping("/template")
|
||||
public void template(HttpServletResponse response, @RequestParam String chargeType) throws Exception
|
||||
{
|
||||
return success(paySurchargeRuleService.list(productId, termId));
|
||||
String mode = PayChargeMode.code(chargeType);
|
||||
String filename = (mode.isEmpty() ? "价卡" : PayChargeMode.label(mode)) + "模板.xlsx";
|
||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
FileUtils.setAttachmentResponseHeader(response, filename);
|
||||
PayTemplateWorkbook.write(mode, response.getOutputStream());
|
||||
}
|
||||
|
||||
/** 这个产品上的附加费配置操作记录。 */
|
||||
@PreAuthorize("@ss.hasAnyPermi('price:pay:query,price:pay:edit')")
|
||||
@GetMapping("/surchargeRule/log")
|
||||
public AjaxResult surchargeRuleLog(@RequestParam Long productId, @RequestParam(required = false) Long termId)
|
||||
/** 按标准模板预览,不写数据库 */
|
||||
@PreAuthorize("@ss.hasPermi('price:pay:import')")
|
||||
@Log(title = "应付配置", businessType = BusinessType.IMPORT)
|
||||
@PostMapping(value = "/template/preview", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public AjaxResult previewTemplate(MultipartFile file, @RequestParam String chargeType) throws Exception
|
||||
{
|
||||
return success(paySurchargeRuleService.logs(productId, termId));
|
||||
assertWorkbook(file);
|
||||
return success(payProductService.previewTemplate(file.getBytes(), file.getOriginalFilename(), chargeType));
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('price:pay:edit')")
|
||||
@Log(title = "应付附加费计费条件", businessType = BusinessType.UPDATE)
|
||||
@PostMapping("/surchargeRule")
|
||||
public AjaxResult saveSurchargeRule(@RequestBody PaySurchargeRuleSave command)
|
||||
/** 按所选计费模式手工新增一条价卡 */
|
||||
@PreAuthorize("@ss.hasPermi('price:pay:add')")
|
||||
@Log(title = "应付配置", businessType = BusinessType.INSERT)
|
||||
@PostMapping("/manual")
|
||||
public AjaxResult manual(@RequestBody PayProduct product)
|
||||
{
|
||||
paySurchargeRuleService.save(command);
|
||||
return success();
|
||||
return success(payProductService.saveManual(product));
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('price:pay:query')")
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.bms.price.pay;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.bms.price.domain.PayPreview;
|
||||
import com.bms.price.domain.PayProduct;
|
||||
import com.bms.price.pay.PayCostCalculator;
|
||||
import com.bms.price.domain.PayOrderCostResult;
|
||||
|
||||
/** 三种标准模板都能导回,并且按各自公式算出运费。 */
|
||||
class PayTemplateWorkbookTest
|
||||
{
|
||||
@Test
|
||||
void flatTemplateChargesTheBandPrice() throws Exception
|
||||
{
|
||||
byte[] file = workbook(PayChargeMode.FLAT);
|
||||
PayPreview preview = PayTemplateWorkbook.parse(replaceSample(file,
|
||||
"法国Colissimo", "威狮", "EUR", "法国", "FR", "", "0", "1", "3.03"), "一口价.xlsx", PayChargeMode.FLAT);
|
||||
PayProduct product = preview.getProducts().get(0);
|
||||
assertEquals(PayChargeMode.FLAT, product.getChargeType());
|
||||
PayOrderCostResult result = PayCostCalculator.calculate(product, new BigDecimal("0.6"), null, null, null, null, null, null);
|
||||
assertEquals(new BigDecimal("3.03"), result.getPayTotal());
|
||||
}
|
||||
|
||||
@Test
|
||||
void perKgTemplateMultipliesWeight() throws Exception
|
||||
{
|
||||
byte[] file = workbook(PayChargeMode.PER_KG);
|
||||
PayPreview preview = PayTemplateWorkbook.parse(replaceSample(file,
|
||||
"DHL泛欧", "威狮", "EUR", "奥地利", "AT", "", "0", "31.5", "0.29"), "常规计费.xlsx", PayChargeMode.PER_KG);
|
||||
PayProduct product = preview.getProducts().get(0);
|
||||
PayOrderCostResult result = PayCostCalculator.calculate(product, new BigDecimal("2.4"), null, null, null, null, null, null);
|
||||
assertEquals(new BigDecimal("0.70"), result.getPayTotal());
|
||||
}
|
||||
|
||||
@Test
|
||||
void extraTemplateAddsWeightBeyondTheFirstKilo() throws Exception
|
||||
{
|
||||
byte[] file = workbook(PayChargeMode.EXTRA);
|
||||
PayPreview preview = PayTemplateWorkbook.parse(replaceSample(file,
|
||||
"CTT", "威狮", "EUR", "西班牙", "ES", "马德里", "1", "2.05", "0.29"), "续重价.xlsx", PayChargeMode.EXTRA);
|
||||
PayProduct product = preview.getProducts().get(0);
|
||||
assertTrue(product.getSurcharges().stream().anyMatch(fee -> "EXTRA_KG".equals(fee.getCalcRule())));
|
||||
PayOrderCostResult result = PayCostCalculator.calculate(product, new BigDecimal("2.4"), null, null, null, null, null, null);
|
||||
assertEquals(new BigDecimal("2.46"), result.getPayTotal());
|
||||
}
|
||||
|
||||
private static byte[] workbook(String mode) throws Exception
|
||||
{
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
PayTemplateWorkbook.write(mode, out);
|
||||
return out.toByteArray();
|
||||
}
|
||||
|
||||
/** 用真实数据换掉模板里的示例行,避免示例被跳过。 */
|
||||
private static byte[] replaceSample(byte[] source, String... values) throws Exception
|
||||
{
|
||||
try (org.apache.poi.xssf.usermodel.XSSFWorkbook book = new org.apache.poi.xssf.usermodel.XSSFWorkbook(new java.io.ByteArrayInputStream(source)))
|
||||
{
|
||||
org.apache.poi.ss.usermodel.Row row = book.getSheetAt(0).getRow(1);
|
||||
for (int i = 0; i < values.length; i++)
|
||||
{
|
||||
row.getCell(i).setCellValue(values[i]);
|
||||
}
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
book.write(out);
|
||||
return out.toByteArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -489,7 +489,7 @@ class PayWorkbookParserTest
|
||||
"西班牙CTT带电专线(主要地区)", List.of("西班牙CTT带电专线(主要地区)"));
|
||||
PayProduct ctt = preview.getProducts().get(0);
|
||||
assertEquals("OK", ctt.getParseStatus());
|
||||
assertEquals("单票价", ctt.getChargeType());
|
||||
assertEquals("FLAT", ctt.getChargeType());
|
||||
assertTrue(ctt.getExtraPerKg() == null || ctt.getExtraPerKg().isBlank());
|
||||
assertEquals(150, ctt.getWeightBands().size());
|
||||
assertTrue(ctt.getWeightBands().stream().anyMatch(band -> "1".equals(band.getWeightLabel())
|
||||
@@ -534,7 +534,7 @@ class PayWorkbookParserTest
|
||||
PayProduct ctt = preview.getProducts().get(0);
|
||||
assertEquals("OK", ctt.getParseStatus());
|
||||
assertEquals("EUR", ctt.getCurrency());
|
||||
assertEquals("续重计费", ctt.getChargeType());
|
||||
assertEquals("EXTRA", ctt.getChargeType());
|
||||
assertTrue(covers(ctt.getExtraPerKg(), "1.86"));
|
||||
assertTrue(covers(ctt.getExtraPerKg(), "5.79"));
|
||||
assertEquals(24, ctt.getWeightBands().size());
|
||||
@@ -607,7 +607,7 @@ class PayWorkbookParserTest
|
||||
PayProduct ctt = preview.getProducts().get(0);
|
||||
assertEquals("OK", ctt.getParseStatus());
|
||||
assertEquals("西班牙", ctt.getCountryScope());
|
||||
assertEquals("续重计费", ctt.getChargeType());
|
||||
assertEquals("EXTRA", ctt.getChargeType());
|
||||
assertTrue(covers(ctt.getExtraPerKg(), "0.82"));
|
||||
assertEquals(60, ctt.getWeightBands().size());
|
||||
assertTrue(ctt.getWeightBands().stream().anyMatch(band -> "西班牙".equals(band.getCountryName()) && "ES".equals(band.getCountryCode())
|
||||
|
||||
Reference in New Issue
Block a user