Compare commits
70 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5c2d4a23c2 | |||
| e82a27bf5a | |||
| 38dd783d21 | |||
| 4582c94751 | |||
| 0d98a51b17 | |||
| 0f4d763d05 | |||
| 5b70e70159 | |||
| 908975a7d6 | |||
| daf36e39e1 | |||
| 837633be3c | |||
| 43a8bd61e8 | |||
| ad7cf3c18c | |||
| a0b9b58291 | |||
| 0445c4fa21 | |||
| 4b766184b5 | |||
| 5442967cb6 | |||
| 38d5471a9d | |||
| 0c477a232c | |||
| b13284ebaa | |||
| 69491b07d9 | |||
| b3ef85b0bb | |||
| b4569e5c15 | |||
| a72417b2c1 | |||
| 8df728f2d7 | |||
| ccfb05bf50 | |||
| fb15b12275 | |||
| 99aa751b2a | |||
| ca45e15559 | |||
| 6b2b205083 | |||
| 4f2954ebce | |||
| 8d45439931 | |||
| e2deccc65a | |||
| 2aec7fdd5c | |||
| 5c8e905a37 | |||
| 8fb042f171 | |||
| d8f6ceda59 | |||
| e104c5a3e9 | |||
| fcaf0dc9be | |||
| 9483bb4899 | |||
| 69d9971a79 | |||
| f6012f96e3 | |||
| 111176e767 | |||
| cce123890e | |||
| b76b26b2b1 | |||
| 6e01167f41 | |||
| e0b8eec98d | |||
| 54ac6428e7 | |||
| ee5c79ba29 | |||
| f00f8c619a | |||
| f9038c62ac | |||
| 49f24a6b1b | |||
| 5b8d4de262 | |||
| 215effe036 | |||
| 4503424cf0 | |||
| 3cf7fa30bd | |||
| e34e4f117c | |||
| 03043104bc | |||
| a5cd752005 | |||
| 5d44cc4edf | |||
| 1b43bcca4c | |||
| a38e2c7f57 | |||
| 63ded27fd5 | |||
| 206e4e786b | |||
| 0179a35942 | |||
| 4de755ca60 | |||
| 358e5a46b9 | |||
| ee36c8c902 | |||
| 7e699fb80e | |||
| 80d639d887 | |||
| 87ae3e6674 |
+10
@@ -90,6 +90,16 @@ public class BmsSupplierController extends BaseController
|
||||
return toAjax(bmsSupplierService.updateBmsSupplier(bmsSupplier));
|
||||
}
|
||||
|
||||
/** 只绑定这一家供应商的渠道 */
|
||||
@PreAuthorize("@ss.hasPermi('customersupplier:supplierinfo:bindChannel')")
|
||||
@Log(title = "供应商绑定渠道", businessType = BusinessType.UPDATE)
|
||||
@PutMapping("/{supplierId}/channels")
|
||||
public AjaxResult bindChannels(@PathVariable("supplierId") Long supplierId, @RequestBody BmsSupplier bmsSupplier)
|
||||
{
|
||||
String channelIds = bmsSupplier == null ? "" : bmsSupplier.getChannelIds();
|
||||
return toAjax(bmsSupplierService.bindChannels(supplierId, channelIds));
|
||||
}
|
||||
|
||||
/** 删除供应商 */
|
||||
@PreAuthorize("@ss.hasPermi('customersupplier:supplierinfo:remove')")
|
||||
@Log(title = "供应商信息", businessType = BusinessType.DELETE)
|
||||
|
||||
+5
-6
@@ -33,16 +33,15 @@ public class BillingTaskMonitorController extends BaseController
|
||||
@Autowired
|
||||
private IPrcBillingTaskService billingTaskService;
|
||||
|
||||
/** 默认列表 = FAILED 异常任务。 */
|
||||
/** 列表默认不过滤状态(全部);successStatus=ALL 同样不过滤。 */
|
||||
@PreAuthorize("@ss.hasPermi('monitor:billingTask:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(PrcBillingTask query)
|
||||
{
|
||||
if (query.getSuccessStatus() == null || query.getSuccessStatus().isEmpty())
|
||||
{
|
||||
query.setSuccessStatus(BillTaskSuccessStatus.FAILED.getCode());
|
||||
}
|
||||
else if ("ALL".equalsIgnoreCase(query.getSuccessStatus()))
|
||||
// 空/全部:不过滤状态;仍可按 FAILED/WAITING/SUCCESS 筛选
|
||||
if (query.getSuccessStatus() == null
|
||||
|| query.getSuccessStatus().isEmpty()
|
||||
|| "ALL".equalsIgnoreCase(query.getSuccessStatus()))
|
||||
{
|
||||
query.setSuccessStatus(null);
|
||||
}
|
||||
|
||||
+10
-15
@@ -2,7 +2,6 @@ package com.bms.web.controller.price;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -168,8 +167,9 @@ public class BillingController extends BaseController
|
||||
{
|
||||
query = new PrcOrderBill();
|
||||
}
|
||||
// 计费列表只展示计费成功的订单。
|
||||
query.setBillingFailStatuses(limitBillingListFailStatus());
|
||||
// 计费列表:仅展示 prc_income_bill 存在的订单
|
||||
query.setRequireIncomeBill(Boolean.TRUE);
|
||||
query.setBillingFailStatuses(null);
|
||||
query.setBillingFailStatus(null);
|
||||
startPage();
|
||||
List<PrcOrderBill> list = prcOrderBillService.selectBillList(query);
|
||||
@@ -177,7 +177,7 @@ public class BillingController extends BaseController
|
||||
}
|
||||
|
||||
/**
|
||||
* 按当前筛选条件异步导出计费列表(状态限定为成功 success=0)。
|
||||
* 按当前筛选条件异步导出计费列表(仅 prc_income_bill 存在)。
|
||||
* 需至少一个有效筛选条件。轮询任务完成后再下载。
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('price:billing:export')")
|
||||
@@ -194,7 +194,8 @@ public class BillingController extends BaseController
|
||||
{
|
||||
return error(MessageUtils.message("price.bill.export.filterRequired"));
|
||||
}
|
||||
query.setBillingFailStatuses(limitBillingListFailStatus());
|
||||
query.setRequireIncomeBill(Boolean.TRUE);
|
||||
query.setBillingFailStatuses(null);
|
||||
query.setBillingFailStatus(null);
|
||||
return successTask(prcOrderBillService.submitOrderBillExport(
|
||||
PrcOrderBillExportTask.TYPE_BILLING, query));
|
||||
@@ -220,13 +221,7 @@ public class BillingController extends BaseController
|
||||
prcOrderBillService.downloadOrderBillExport(taskId, response);
|
||||
}
|
||||
|
||||
private static List<Integer> limitBillingListFailStatus()
|
||||
{
|
||||
// 计费列表仅包含成功数据(billing_fail_status = 0)。
|
||||
return new ArrayList<Integer>(Arrays.asList(Integer.valueOf(0)));
|
||||
}
|
||||
|
||||
/** 全部 prc_order_bill 记录。计费列表仍限定为状态 0。 */
|
||||
/** 全部 prc_order_bill 记录。计费列表按 prc_income_bill 存在过滤。 */
|
||||
@PreAuthorize("@ss.hasPermi('price:orderBill:list')")
|
||||
@GetMapping("/orderBill/list")
|
||||
public TableDataInfo orderBillList(PrcOrderBill query)
|
||||
@@ -378,7 +373,7 @@ public class BillingController extends BaseController
|
||||
return query;
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('price:billing:bill') or @ss.hasPermi('price:orderBill:list')")
|
||||
@PreAuthorize("@ss.hasPermi('price:billing:bill') or @ss.hasPermi('price:orderBill:list') or @ss.hasPermi('price:payOrder:query')")
|
||||
@GetMapping("/bill/{billId}")
|
||||
public AjaxResult getBill(@PathVariable Long billId)
|
||||
{
|
||||
@@ -389,7 +384,7 @@ public class BillingController extends BaseController
|
||||
* 该订单的 ES BILL 日志(计费 / 上游同步 / 失败快照)。
|
||||
* bizId 优先取 transferNo,其次取 orderNo(与写入路径一致)。
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('price:billing:bill') or @ss.hasPermi('price:orderBill:list')")
|
||||
@PreAuthorize("@ss.hasPermi('price:billing:bill') or @ss.hasPermi('price:orderBill:list') or @ss.hasPermi('price:payOrder:query')")
|
||||
@GetMapping("/bill/{billId}/history")
|
||||
public TableDataInfo billHistory(@PathVariable("billId") Long billId)
|
||||
{
|
||||
@@ -541,7 +536,7 @@ public class BillingController extends BaseController
|
||||
{
|
||||
msg = e.getClass().getSimpleName();
|
||||
}
|
||||
fails.add((billId == null ? "" : billId) + ": " + msg);
|
||||
fails.add((billId == null ? "" : String.valueOf(billId)) + ": " + msg);
|
||||
}
|
||||
}
|
||||
if (fails.isEmpty())
|
||||
|
||||
+1
-1
@@ -186,7 +186,7 @@ public class LabelPackageController extends BaseController
|
||||
return success(payload);
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('price:label:remove')")
|
||||
@PreAuthorize("@ss.hasPermi('price:label:edit')")
|
||||
@Log(title = "打单套餐删除版本", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{priceSetId}/versions/{versionNo}")
|
||||
public AjaxResult deleteVersion(@PathVariable Long priceSetId, @PathVariable Integer versionNo)
|
||||
|
||||
+169
@@ -0,0 +1,169 @@
|
||||
package com.bms.web.controller.price;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.bms.common.core.controller.BaseController;
|
||||
import com.bms.common.core.domain.AjaxResult;
|
||||
import com.bms.common.core.page.TableDataInfo;
|
||||
import com.bms.price.domain.PayOrderFeeBatch;
|
||||
import com.bms.price.domain.PayOrderFeeLine;
|
||||
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
|
||||
@RequestMapping("/price/payOrder")
|
||||
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)
|
||||
{
|
||||
startPage();
|
||||
return getDataTable(payOrderListService.list(query));
|
||||
}
|
||||
|
||||
/**
|
||||
* 按订单号或提单号批量重算尾程应付。一票失败不影响其他订单。
|
||||
*
|
||||
* @param command sourceType 为 ORDER 或 LADING,text 为单号原文
|
||||
* @return 成功数、失败数和每一票的结果
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('price:payOrder:recalc')")
|
||||
@PostMapping("/recalc")
|
||||
public AjaxResult recalc(@RequestBody PayOrderRecalcCommand command)
|
||||
{
|
||||
Map<String, String> payload = new HashMap<>();
|
||||
payload.put("taskId", payOrderListService.submitRecalc(command));
|
||||
return success(payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询应付费用重算进度。
|
||||
*
|
||||
* @param taskId 任务号
|
||||
* @return Redis 中的进度和每一票结果
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('price:payOrder:recalc')")
|
||||
@GetMapping("/recalc/task/{taskId}")
|
||||
public AjaxResult recalcTask(@PathVariable String taskId)
|
||||
{
|
||||
PayOrderRecalcTask task = payOrderListService.getRecalcTask(taskId);
|
||||
if (task == null)
|
||||
{
|
||||
return error("重算任务不存在或已过期");
|
||||
}
|
||||
return success(task);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消还没开始的应付费用重算。正在计算的这一票会算完。
|
||||
*
|
||||
* @param taskId 任务号
|
||||
* @return 更新后的进度
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('price:payOrder:recalc')")
|
||||
@PostMapping("/recalc/task/{taskId}/cancel")
|
||||
public AjaxResult cancelRecalc(@PathVariable String taskId)
|
||||
{
|
||||
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 四段返回。
|
||||
*
|
||||
* @param billId 计费订单 ID
|
||||
* @return 四段费用
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('price:payOrder:fee')")
|
||||
@GetMapping("/{billId}/fees")
|
||||
public AjaxResult fees(@PathVariable String billId)
|
||||
{
|
||||
return success(payOrderListService.fees(billId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 给勾选订单批量增加手工费用。创建人取当前登录用户,来源为手工,并记新增日志。
|
||||
*
|
||||
* @param batch 订单和费用行
|
||||
* @return 写入的费用条数
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('price:payOrder:feeBatch')")
|
||||
@PostMapping("/fees/batch")
|
||||
public AjaxResult addFees(@RequestBody PayOrderFeeBatch batch)
|
||||
{
|
||||
return success(payOrderListService.addManualFees(batch));
|
||||
}
|
||||
|
||||
/**
|
||||
* 在某一段手工增加一行应付费用。创建人取当前登录用户。
|
||||
*
|
||||
* @param billId 计费订单 ID
|
||||
* @param line 费用项、金额、币种、说明和所属阶段
|
||||
* @return 写入后的费用行
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('price:payOrder:feeAdd')")
|
||||
@PostMapping("/{billId}/fees")
|
||||
public AjaxResult addFee(@PathVariable String billId, @RequestBody PayOrderFeeLine line)
|
||||
{
|
||||
return success(payOrderListService.addManualFee(billId, line));
|
||||
}
|
||||
|
||||
/**
|
||||
* 逻辑删除一条应付费用。
|
||||
*
|
||||
* @param feeId 费用明细 ID
|
||||
* @return 操作结果
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('price:payOrder:feeRemove')")
|
||||
@DeleteMapping("/fees/{feeId}")
|
||||
public AjaxResult removeFee(@PathVariable String feeId)
|
||||
{
|
||||
payOrderListService.removeFee(feeId);
|
||||
return success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查看一票订单的费用操作日志,含变更前和变更后。
|
||||
*
|
||||
* @param billId 计费订单 ID
|
||||
* @return 当前页日志
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('price:payOrder:log')")
|
||||
@GetMapping("/{billId}/feeLogs")
|
||||
public TableDataInfo feeLogs(@PathVariable String billId)
|
||||
{
|
||||
return getDataTable(payOrderListService.feeLogs(billId));
|
||||
}
|
||||
}
|
||||
+45
-22
@@ -29,15 +29,16 @@ import com.bms.price.domain.ChannelProductMap;
|
||||
import com.bms.price.domain.PayProduct;
|
||||
import com.bms.price.domain.PayProductTerm;
|
||||
import com.bms.price.domain.PaySaveCommand;
|
||||
import com.bms.price.domain.PaySurcharge;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 价格基础下的应付配置。导入先预览,确认后才入库。
|
||||
* 应付管理下的应付配置。导入先预览,确认后才入库。
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/price/pay")
|
||||
@@ -49,9 +50,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,28 +105,53 @@ 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(payProductService.saveManual(product));
|
||||
}
|
||||
|
||||
/** 这一版从附加费配置勾选的费用 */
|
||||
@PreAuthorize("@ss.hasPermi('price:pay:surcharge')")
|
||||
@GetMapping("/term/{termId}/config-surcharges")
|
||||
public AjaxResult configSurcharges(@PathVariable Long termId)
|
||||
{
|
||||
return success(payProductService.listConfigSurcharges(termId));
|
||||
}
|
||||
|
||||
/** 保存这一版勾选的附加费和计费参数 */
|
||||
@PreAuthorize("@ss.hasPermi('price:pay:surcharge')")
|
||||
@Log(title = "应付价卡附加费", businessType = BusinessType.UPDATE)
|
||||
@PutMapping("/term/{termId}/config-surcharges")
|
||||
public AjaxResult saveConfigSurcharges(@PathVariable Long termId, @RequestBody List<PaySurcharge> rows)
|
||||
{
|
||||
payProductService.saveConfigSurcharges(termId, rows);
|
||||
return success();
|
||||
}
|
||||
|
||||
@@ -173,7 +196,7 @@ public class PayProductController extends BaseController
|
||||
}
|
||||
|
||||
/** 批量绑定渠道应收/应付产品 */
|
||||
@PreAuthorize("@ss.hasAnyPermi('price:pay:edit,data:serviceChannel:edit')")
|
||||
@PreAuthorize("@ss.hasAnyPermi('price:pay:edit,price:pay:bind,data:serviceChannel:edit')")
|
||||
@Log(title = "渠道批量绑定产品", businessType = BusinessType.UPDATE)
|
||||
@PutMapping("/channel/batchBind")
|
||||
public AjaxResult batchBindChannel(@RequestBody Map<String, Object> body)
|
||||
|
||||
@@ -87,6 +87,7 @@ public class SurchargeController extends BaseController
|
||||
+ " or @ss.hasPermi('price:set:query') or @ss.hasPermi('price:set:add') or @ss.hasPermi('price:set:edit')"
|
||||
+ " or @ss.hasPermi('price:billing:bill')"
|
||||
+ " or @ss.hasPermi('price:pay:query') or @ss.hasPermi('price:pay:edit') or @ss.hasPermi('price:pay:import')"
|
||||
+ " or @ss.hasPermi('price:pay:surcharge')"
|
||||
+ " or @ss.hasPermi('price:airBill:fee')")
|
||||
@GetMapping("/options")
|
||||
public AjaxResult listOptions(PrcSurcharge surcharge)
|
||||
|
||||
@@ -20,11 +20,12 @@ import com.bms.common.core.page.TableDataInfo;
|
||||
import com.bms.common.enums.BusinessType;
|
||||
import com.bms.price.domain.PrcZone;
|
||||
import com.bms.price.domain.PrcZoneDetail;
|
||||
import com.bms.price.domain.PrcZoneLabelProduct;
|
||||
import com.bms.price.domain.PrcZoneRegion;
|
||||
import com.bms.price.service.IPrcZoneService;
|
||||
|
||||
/**
|
||||
* 分区管理:国家(region) -> 分区 -> 邮编明细
|
||||
* 分区管理:常规按国家;打单按产品。
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/price/zone")
|
||||
@@ -59,12 +60,36 @@ public class ZoneController extends BaseController
|
||||
return toAjax(zoneService.deleteZonesByRegionIds(regionIds));
|
||||
}
|
||||
|
||||
|
||||
// ========== label product zones ==========
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('price:zone:list')")
|
||||
@GetMapping("/label/product/list")
|
||||
public TableDataInfo labelProductList(PrcZoneLabelProduct query)
|
||||
{
|
||||
startPage();
|
||||
List<PrcZoneLabelProduct> list = zoneService.selectLabelProductZoneList(query);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('price:zone:remove')")
|
||||
@Log(title = "LabelZoneProduct", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/label/product/{productId}")
|
||||
public AjaxResult removeLabelProductZones(@PathVariable Long productId)
|
||||
{
|
||||
return toAjax(zoneService.deleteZonesByProductId(productId));
|
||||
}
|
||||
|
||||
// ========== zone ==========
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('price:zone:list')")
|
||||
@GetMapping("/item/list")
|
||||
public TableDataInfo zoneList(PrcZone zone)
|
||||
{
|
||||
if (zone.getZoneType() == null || zone.getZoneType().isEmpty())
|
||||
{
|
||||
zone.setZoneType(PrcZone.TYPE_REGULAR);
|
||||
}
|
||||
startPage();
|
||||
List<PrcZone> list = zoneService.selectPrcZoneList(zone);
|
||||
return getDataTable(list);
|
||||
|
||||
+17
-8
@@ -25,15 +25,18 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.bms.receivable.domain.ArBill;
|
||||
import com.bms.receivable.domain.vo.ArBillExportRequest;
|
||||
import com.bms.receivable.domain.ArBankAccount;
|
||||
import com.bms.receivable.domain.ArBillDetailFee;
|
||||
import com.bms.receivable.domain.ArBillGenerateTask;
|
||||
import com.bms.receivable.domain.ArBillLog;
|
||||
import com.bms.receivable.domain.vo.ArBillActionRequest;
|
||||
import com.bms.receivable.domain.vo.ArBillDetailQuery;
|
||||
import com.bms.receivable.domain.vo.ArBillGenerateQuery;
|
||||
import com.bms.receivable.domain.vo.ArBillGenerateRequest;
|
||||
import com.bms.receivable.domain.vo.ArBillListExportRow;
|
||||
import com.bms.receivable.domain.vo.ArBillQuery;
|
||||
import com.bms.receivable.domain.vo.ArBillPreviewOrder;
|
||||
import com.bms.receivable.service.IArBillService;
|
||||
import com.bms.receivable.service.ArBillVoidTaskService;
|
||||
import com.bms.receivable.security.ArBillScopeResolver;
|
||||
@@ -139,9 +142,9 @@ public class ArBillController extends BaseController {
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('ar:bill:query')")
|
||||
@GetMapping("/{arBillId}/details")
|
||||
public TableDataInfo details(@PathVariable Long arBillId) {
|
||||
public TableDataInfo details(@PathVariable Long arBillId, @Valid ArBillDetailQuery query) {
|
||||
startPage();
|
||||
return getDataTable(billService.selectArBillDetails(arBillId));
|
||||
return getDataTable(billService.selectArBillDetails(arBillId, query));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -175,7 +178,7 @@ public class ArBillController extends BaseController {
|
||||
List<PrcOrderBill> list = billService.previewBill(query);
|
||||
TableDataInfo pageData = getDataTable(list);
|
||||
AjaxResult result = success();
|
||||
result.put("rows", pageData.getRows());
|
||||
result.put("rows", list.stream().map(ArBillPreviewOrder::from).toList());
|
||||
result.put("total", pageData.getTotal());
|
||||
return result;
|
||||
}
|
||||
@@ -219,7 +222,7 @@ public class ArBillController extends BaseController {
|
||||
List<PrcOrderBill> list = billService.previewExcludedBill(query);
|
||||
TableDataInfo pageData = getDataTable(list);
|
||||
AjaxResult result = success();
|
||||
result.put("rows", pageData.getRows());
|
||||
result.put("rows", list.stream().map(ArBillPreviewOrder::from).toList());
|
||||
result.put("total", pageData.getTotal());
|
||||
result.put("totalAmount", billService.sumPreviewBill(query));
|
||||
return result;
|
||||
@@ -310,16 +313,22 @@ public class ArBillController extends BaseController {
|
||||
return success(voidTaskService.get(taskId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 仅提交导出任务;前端通过导出任务状态接口轮询并在完成后下载。
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('ar:bill:export')")
|
||||
@GetMapping("/{arBillId}/export-templates")
|
||||
public AjaxResult exportTemplates(@PathVariable Long arBillId) {
|
||||
return success(billService.selectExportTemplates(arBillId));
|
||||
}
|
||||
|
||||
/** 仅提交导出任务;前端轮询任务状态后下载。 */
|
||||
@Log(title = "应收账单导出", businessType = BusinessType.EXPORT)
|
||||
@PreAuthorize("@ss.hasPermi('ar:bill:export')")
|
||||
@PostMapping("/{arBillId}/export")
|
||||
public AjaxResult export(@PathVariable Long arBillId,
|
||||
@RequestBody(required = false) ArBillExportRequest request,
|
||||
@RequestHeader(value = "X-Request-Id", required = false) String headerRequestId) {
|
||||
String requestId = requestId(null, headerRequestId);
|
||||
return success(billService.exportBill(arBillId, getUsername(), requestId)).put("request_id", requestId);
|
||||
return success(billService.exportBill(arBillId, request == null ? null : request.getTemplateId(),
|
||||
getUsername(), requestId)).put("request_id", requestId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+25
-12
@@ -8,6 +8,8 @@ import java.nio.file.Paths;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
@@ -16,6 +18,7 @@ import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.bms.common.annotation.Log;
|
||||
@@ -38,6 +41,7 @@ import com.bms.price.domain.vo.PrcProfitReportProductRow;
|
||||
import com.bms.price.domain.vo.PrcProfitReportQuery;
|
||||
import com.bms.price.domain.vo.PrcProfitReportSummary;
|
||||
import com.bms.price.service.IPrcProfitReportService;
|
||||
import com.bms.price.task.PrcProfitReportExportRunner;
|
||||
|
||||
/** 产品/订单维度毛利报表。 */
|
||||
@RestController
|
||||
@@ -50,6 +54,9 @@ public class PrcProfitReportController extends BaseController
|
||||
@Autowired
|
||||
private OssStorage ossStorage;
|
||||
|
||||
@Autowired
|
||||
private PrcProfitReportExportRunner exportRunner;
|
||||
|
||||
/** 客户筛选选项,沿用毛利报表的访问权限和查询范围。 */
|
||||
@PreAuthorize("@ss.hasPermi('report:profit:list')")
|
||||
@GetMapping("/customer-options")
|
||||
@@ -105,6 +112,8 @@ public class PrcProfitReportController extends BaseController
|
||||
public TableDataInfo orders(PrcProfitReportQuery query)
|
||||
{
|
||||
startPage();
|
||||
// 分页总数由页面复用汇总订单数,订单明细仅执行分页查询。
|
||||
PageHelper.getLocalPage().setCount(false);
|
||||
List<PrcProfitReportOrderRow> rows = profitReportService.selectOrderRows(query);
|
||||
return getDataTable(rows);
|
||||
}
|
||||
@@ -121,19 +130,23 @@ public class PrcProfitReportController extends BaseController
|
||||
@Log(title = "毛利报表-订单维度", businessType = BusinessType.EXPORT)
|
||||
@PreAuthorize("@ss.hasPermi('report:profit:export')")
|
||||
@PostMapping("/orders/export")
|
||||
public AjaxResult exportOrders(PrcProfitReportQuery query)
|
||||
public AjaxResult exportOrders(@RequestBody PrcProfitReportQuery query)
|
||||
{
|
||||
PrcProfitReportExport export = beginExport("ORDER", "订单维度毛利分析");
|
||||
try
|
||||
{
|
||||
List<PrcProfitReportOrderRow> rows = profitReportService.selectOrderRows(query);
|
||||
return finishExport(export, rows, PrcProfitReportOrderRow.class, "订单毛利报表", query.getProfitRule());
|
||||
}
|
||||
catch (RuntimeException e)
|
||||
{
|
||||
failExport(export, e);
|
||||
throw e;
|
||||
}
|
||||
return success(Map.of("taskId", exportRunner.submit(query, getUserId())));
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('report:profit:export')")
|
||||
@GetMapping("/orders/export/task/{taskId}")
|
||||
public AjaxResult orderExportTask(@PathVariable String taskId)
|
||||
{
|
||||
return success(exportRunner.getTask(taskId, getUserId()));
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('report:profit:export')")
|
||||
@GetMapping("/orders/export/download/{taskId}")
|
||||
public void downloadOrderExport(@PathVariable String taskId, HttpServletResponse response) throws Exception
|
||||
{
|
||||
exportRunner.download(taskId, getUserId(), response);
|
||||
}
|
||||
|
||||
@Log(title = "毛利报表-产品维度", businessType = BusinessType.EXPORT)
|
||||
|
||||
@@ -10,6 +10,11 @@ oss:
|
||||
|
||||
# 项目相关配置
|
||||
bms:
|
||||
# 毛利报表区域客户 ID 过滤:默认关闭,完成生产计划和耗时对比后再启用。
|
||||
profit-report:
|
||||
customer-id-filter-enabled: ${BMS_PROFIT_REPORT_CUSTOMER_ID_FILTER_ENABLED:false}
|
||||
# 超过此客户数时自动回退客户表关联;小于等于 0 时停用,上限为 5000。
|
||||
max-customer-ids: ${BMS_PROFIT_REPORT_MAX_CUSTOMER_IDS:1000}
|
||||
# 名称
|
||||
name: BMS
|
||||
# 版本
|
||||
|
||||
@@ -50,11 +50,141 @@ class PayCostCalculatorTest
|
||||
|
||||
PayOrderCostResult over = PayCostCalculator.calculate(product, new BigDecimal("7"),
|
||||
null, null, null, null, "Mainland / Mad High Density", null, 1);
|
||||
assertTrue(hasFee(over, "基础运费", "3.18"));
|
||||
assertTrue(hasFee(over, "每公斤续重", "0.54"));
|
||||
assertTrue(hasFee(over, "基础运费", "3.72"));
|
||||
assertTrue(over.getFees().stream().noneMatch(fee -> "每公斤续重".equals(fee.getFeeName())));
|
||||
assertEquals(new BigDecimal("3.72"), over.getPayTotal());
|
||||
}
|
||||
|
||||
@Test
|
||||
void continuationChargesAFullStepWhenTheExcessIsUnderOneKilogram()
|
||||
{
|
||||
PayProduct product = new PayProduct();
|
||||
product.setProductName("CTT 48H");
|
||||
product.setCurrency("EUR");
|
||||
PayWeightBand first = band("0", "1", "2.40", "Medium");
|
||||
first.setSectionName("派送费");
|
||||
first.setChargeName("派送费");
|
||||
first.setPriceUnit("EUR/ITEM");
|
||||
product.setWeightBands(new ArrayList<>(List.of(first)));
|
||||
PaySurcharge extra = fee(11L, "每公斤续重", "0.34", "EUR", "EXTRA_KG", "1");
|
||||
extra.setSectionName("派送费");
|
||||
extra.setZoneName("Medium");
|
||||
extra.setPriceUnit("EUR/KG");
|
||||
extra.setChargeText("每增加 1Kg 0.34 EUR/KG");
|
||||
product.setSurcharges(List.of(extra));
|
||||
|
||||
PayOrderCostResult partial = PayCostCalculator.calculate(product, new BigDecimal("1.2"),
|
||||
null, null, null, null, "Medium", null, 1);
|
||||
assertTrue(hasFee(partial, "基础运费", "2.74"));
|
||||
assertTrue(partial.getFees().stream().noneMatch(fee -> "每公斤续重".equals(fee.getFeeName())));
|
||||
assertEquals(new BigDecimal("2.74"), partial.getPayTotal());
|
||||
|
||||
PayOrderCostResult twoSteps = PayCostCalculator.calculate(product, new BigDecimal("2.2"),
|
||||
null, null, null, null, "Medium", null, 1);
|
||||
assertTrue(hasFee(twoSteps, "基础运费", "3.08"));
|
||||
assertTrue(twoSteps.getFees().stream().noneMatch(fee -> "每公斤续重".equals(fee.getFeeName())));
|
||||
}
|
||||
|
||||
@Test
|
||||
void boundSurchargesKeepTheCardContinuation()
|
||||
{
|
||||
PayWeightBand first = band("0", "1", "10", "UK Mainland");
|
||||
first.setSectionName("派送费");
|
||||
first.setPriceUnit("CNY/ITEM");
|
||||
first.setChargeName("首重");
|
||||
PaySurcharge extra = fee(1L, "每公斤续重", "2", "CNY", "EXTRA_KG", "1");
|
||||
extra.setSectionName("派送费");
|
||||
extra.setZoneName("UK Mainland");
|
||||
extra.setPriceUnit("CNY/KG");
|
||||
PaySurcharge imported = fee(2L, "偏远地区附加费", "8", "CNY", "POSTCODE", "BT");
|
||||
PaySurcharge bound = fee(3L, "燃油", "1", "CNY", "ALWAYS", null);
|
||||
bound.setSectionName("附加费配置");
|
||||
PaySurcharge configExtra = fee(5L, "超重续收", "9", "CNY", "EXTRA_KG", "1");
|
||||
configExtra.setSectionName("附加费配置");
|
||||
configExtra.setExtraWeightKg(new BigDecimal("1"));
|
||||
configExtra.setZoneName("UK Mainland");
|
||||
PayProduct product = new PayProduct();
|
||||
product.setProductName("续重价");
|
||||
product.setCurrency("CNY");
|
||||
product.setWeightBands(new ArrayList<>(List.of(first)));
|
||||
product.setSurcharges(PaySurchargeRules.surchargesForCalc(List.of(extra, imported), List.of(bound, configExtra)));
|
||||
|
||||
PayOrderCostResult over = PayCostCalculator.calculate(product, new BigDecimal("3"),
|
||||
null, null, null, "KY4 0DN", "UK Mainland", null, 1);
|
||||
assertTrue(hasFee(over, "基础运费", "14"));
|
||||
assertTrue(over.getFees().stream().noneMatch(fee -> "每公斤续重".equals(fee.getFeeName())));
|
||||
assertTrue(hasFee(over, "燃油", "1"));
|
||||
assertFalse(over.getFees().stream().anyMatch(fee -> fee.getFeeName().contains("偏远")));
|
||||
assertFalse(over.getFees().stream().anyMatch(fee -> "超重续收".equals(fee.getFeeName())));
|
||||
assertEquals(new BigDecimal("15.00"), over.getPayTotal());
|
||||
}
|
||||
|
||||
@Test
|
||||
void boundConfigFeesFollowTheirOwnChargeRule()
|
||||
{
|
||||
PayProduct product = new PayProduct();
|
||||
product.setProductName("CTT 48H");
|
||||
product.setCurrency("EUR");
|
||||
product.setWeightBands(new ArrayList<>(List.of(band("0", "5", "2.05", "马德里"))));
|
||||
PaySurcharge fuel = fee(11L, "燃油附加费", "0.50", "EUR", "ALWAYS", null);
|
||||
fuel.setSectionName("附加费配置");
|
||||
fuel.setScId(101L);
|
||||
PaySurcharge heavy = fee(12L, "超重附加费", "3", "EUR", "WEIGHT", null);
|
||||
heavy.setSectionName("附加费配置");
|
||||
heavy.setOverWeightKg(new BigDecimal("2"));
|
||||
PaySurcharge bulky = fee(13L, "超尺寸附加费", "4", "EUR", "SIZE", null);
|
||||
bulky.setSectionName("附加费配置");
|
||||
bulky.setLengthCm(new BigDecimal("60"));
|
||||
bulky.setWidthCm(new BigDecimal("40"));
|
||||
bulky.setHeightCm(new BigDecimal("30"));
|
||||
PaySurcharge remote = fee(14L, "偏远附加费", "7.1", "EUR", "POSTCODE", null);
|
||||
remote.setSectionName("附加费配置");
|
||||
remote.setPostcodeText("07");
|
||||
remote.setCountryCode("ES");
|
||||
PaySurcharge manual = fee(15L, "仓库操作费", "1", "EUR", "MANUAL", null);
|
||||
manual.setSectionName("附加费配置");
|
||||
PaySurcharge returned = fee(16L, "退件费", "2", "EUR", "RETURN", null);
|
||||
returned.setSectionName("附加费配置");
|
||||
product.setSurcharges(List.of(fuel, heavy, bulky, remote, manual, returned));
|
||||
|
||||
PayOrderCostResult light = PayCostCalculator.calculate(product, new BigDecimal("1"),
|
||||
new BigDecimal("10"), new BigDecimal("10"), new BigDecimal("10"), "28001", "马德里", null, 1,
|
||||
List.of(), true, true, "ES", "西班牙");
|
||||
assertTrue(hasFee(light, "燃油附加费", "0.50"));
|
||||
assertEquals(101L, light.getFees().stream().filter(row -> "燃油附加费".equals(row.getFeeName())).findFirst().orElseThrow().getScId());
|
||||
assertTrue(light.getFees().stream().noneMatch(row -> "超重附加费".equals(row.getFeeName()) || "超尺寸附加费".equals(row.getFeeName())
|
||||
|| "偏远附加费".equals(row.getFeeName()) || "仓库操作费".equals(row.getFeeName()) || "退件费".equals(row.getFeeName())));
|
||||
|
||||
PayOrderCostResult hit = PayCostCalculator.calculate(product, new BigDecimal("3"),
|
||||
new BigDecimal("70"), new BigDecimal("50"), new BigDecimal("40"), "07008", "马德里", null, 9,
|
||||
List.of(), true, true, "ES", "西班牙");
|
||||
assertTrue(hasFee(hit, "燃油附加费", "0.50"));
|
||||
assertTrue(hasFee(hit, "超重附加费", "3"));
|
||||
assertTrue(hasFee(hit, "超尺寸附加费", "4"));
|
||||
assertTrue(hasFee(hit, "偏远附加费", "7.1"));
|
||||
assertTrue(hasFee(hit, "退件费", "2"));
|
||||
assertTrue(hit.getFees().stream().noneMatch(row -> "仓库操作费".equals(row.getFeeName())));
|
||||
|
||||
PayOrderCostResult france = PayCostCalculator.calculate(product, new BigDecimal("3"),
|
||||
new BigDecimal("70"), new BigDecimal("50"), new BigDecimal("40"), "07008", "马德里", null, 9,
|
||||
List.of(), true, true, "FR", "法国");
|
||||
assertTrue(france.getFees().stream().noneMatch(row -> "偏远附加费".equals(row.getFeeName())));
|
||||
|
||||
PaySurcharge volume = fee(17L, "体积附加费", "6", "EUR", "SIZE", null);
|
||||
volume.setSectionName("附加费配置");
|
||||
volume.setSizeType("VOLUME");
|
||||
volume.setVolumeM3(new BigDecimal("0.01"));
|
||||
product.setSurcharges(List.of(fuel, volume));
|
||||
PayOrderCostResult underVolume = PayCostCalculator.calculate(product, new BigDecimal("1"),
|
||||
new BigDecimal("20"), new BigDecimal("20"), new BigDecimal("5"), "28001", "马德里", null, 1);
|
||||
assertTrue(underVolume.getFees().stream().noneMatch(row -> "体积附加费".equals(row.getFeeName())));
|
||||
PayOrderCostResult overVolume = PayCostCalculator.calculate(product, new BigDecimal("1"),
|
||||
new BigDecimal("50"), new BigDecimal("40"), new BigDecimal("20"), "28001", "马德里", null, 1);
|
||||
assertTrue(hasFee(overVolume, "体积附加费", "6"));
|
||||
assertTrue(overVolume.getFees().stream().anyMatch(row -> "体积附加费".equals(row.getFeeName())
|
||||
&& row.getRemark() != null && row.getRemark().contains("体积超过")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void extraKgFollowsTheSameServiceSection()
|
||||
{
|
||||
@@ -80,9 +210,8 @@ class PayCostCalculatorTest
|
||||
|
||||
PayOrderCostResult over = PayCostCalculator.calculate(product, new BigDecimal("2"),
|
||||
null, null, null, null, "Canary Islands / Minor Islands", null, 1);
|
||||
assertTrue(hasFee(over, "基础运费", "13.12"));
|
||||
assertTrue(hasFee(over, "每公斤续重", "1.86"));
|
||||
assertEquals(1, over.getFees().stream().filter(fee -> "每公斤续重".equals(fee.getFeeName())).count());
|
||||
assertTrue(hasFee(over, "基础运费", "14.98"));
|
||||
assertTrue(over.getFees().stream().noneMatch(fee -> "每公斤续重".equals(fee.getFeeName())));
|
||||
assertEquals(new BigDecimal("14.98"), over.getPayTotal());
|
||||
}
|
||||
|
||||
@@ -96,13 +225,15 @@ class PayCostCalculatorTest
|
||||
}
|
||||
|
||||
@Test
|
||||
void oversizeUsesTheHigherPercentWhenBothTiersMatch()
|
||||
void oversizeAddsEveryMatchingTierOfTheSameName()
|
||||
{
|
||||
PayOrderCostResult result = PayCostCalculator.calculate(spainOneZone(), new BigDecimal("1"),
|
||||
new BigDecimal("130"), new BigDecimal("50"), new BigDecimal("40"), "28001", null, 1);
|
||||
assertTrue(hasFee(result, "基础运费", "2.27"));
|
||||
assertTrue(hasFee(result, "特大包裹收费", "0.79"));
|
||||
assertTrue(hasFee(result, "特大包裹收费", "1.59"));
|
||||
assertEquals(1, result.getFees().stream().filter(fee -> "特大包裹收费".equals(fee.getFeeName())).count());
|
||||
assertEquals(2, result.getFees().stream().filter(fee -> "特大包裹收费".equals(fee.getFeeName())).count());
|
||||
assertEquals(new BigDecimal("4.65"), result.getPayTotal());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -147,6 +278,43 @@ class PayCostCalculatorTest
|
||||
assertTrue(mainland.getFees().stream().noneMatch(fee -> "偏远附加费".equals(fee.getFeeName())));
|
||||
}
|
||||
|
||||
@Test
|
||||
void evriRemoteWeightBandAddsTheSameWeightRow()
|
||||
{
|
||||
PayProduct product = new PayProduct();
|
||||
product.setProductName("Evri 48H");
|
||||
product.setCurrency("GBP");
|
||||
PayWeightBand mainlandLight = band("0", "1", "1.51", "UK Mainland\n英国大陆");
|
||||
mainlandLight.setChargeName("派送费");
|
||||
mainlandLight.setSectionName("派送费");
|
||||
PayWeightBand mainlandNext = band("1", "2", "1.53", "UK Mainland\n英国大陆");
|
||||
mainlandNext.setChargeName("派送费");
|
||||
mainlandNext.setSectionName("派送费");
|
||||
PayWeightBand highlandsLight = band("0", "1", "5.95", "Highlands& Islands\n高地和岛屿");
|
||||
highlandsLight.setChargeName("偏远附加费");
|
||||
highlandsLight.setSectionName("偏远附加费");
|
||||
PayWeightBand highlandsNext = band("1", "2", "5.95", "Highlands& Islands\n高地和岛屿");
|
||||
highlandsNext.setChargeName("偏远附加费");
|
||||
highlandsNext.setSectionName("偏远附加费");
|
||||
PayWeightBand heavyRemote = band("15", "20", "8.2", "Highlands& Islands\n高地和岛屿");
|
||||
heavyRemote.setChargeName("偏远附加费");
|
||||
heavyRemote.setSectionName("偏远附加费");
|
||||
product.setWeightBands(new ArrayList<>(List.of(mainlandLight, mainlandNext, highlandsLight, highlandsNext, heavyRemote)));
|
||||
|
||||
PayOrderCostResult mainland = PayCostCalculator.calculate(product, new BigDecimal("0.5"),
|
||||
null, null, null, "LL22 8PJ", "UK Mainland\n英国大陆", null, 1);
|
||||
assertTrue(hasFee(mainland, "基础运费", "1.51"));
|
||||
assertTrue(mainland.getFees().stream().noneMatch(fee -> "偏远附加费".equals(fee.getFeeName())));
|
||||
assertEquals(new BigDecimal("1.51"), mainland.getPayTotal());
|
||||
|
||||
PayOrderCostResult remote = PayCostCalculator.calculate(product, new BigDecimal("0.5"),
|
||||
null, null, null, "IV1 1AA", "Highlands& Islands\n高地和岛屿", null, 1);
|
||||
assertTrue(hasFee(remote, "基础运费", "1.51"));
|
||||
assertTrue(hasFee(remote, "偏远附加费", "5.95"));
|
||||
assertEquals(1, remote.getFees().stream().filter(fee -> "偏远附加费".equals(fee.getFeeName())).count());
|
||||
assertEquals(new BigDecimal("7.46"), remote.getPayTotal());
|
||||
}
|
||||
|
||||
@Test
|
||||
void spanishPrefixChargesFirstWeightThenExtraKg()
|
||||
{
|
||||
@@ -184,12 +352,89 @@ class PayCostCalculatorTest
|
||||
assertTrue(PaySurchargeRules.matchesPostcode("07,35,38,51,52,9", "9000"));
|
||||
assertFalse(PaySurchargeRules.matchesPostcode("07,35,38,51,52,9", "28001"));
|
||||
assertTrue(PaySurchargeRules.matchesPostcode("IV,HS,KA27-28", "KA27 8AA"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void zoneFeeBandsKeepDeliveryAndAddRemoteAndLineHaul()
|
||||
{
|
||||
PayProduct product = new PayProduct();
|
||||
product.setProductName("CTT 48H");
|
||||
product.setCurrency("EUR");
|
||||
PayWeightBand delivery = band("0", "1", "2.05", "Mad High Density 马德里高密度地区");
|
||||
delivery.setSectionName("派送费");
|
||||
delivery.setChargeName("派送费");
|
||||
PayWeightBand lineHaul = band("0", "1", "0.09", "Mad High Density 马德里高密度地区");
|
||||
lineHaul.setSectionName("额外线路运输费");
|
||||
lineHaul.setChargeName("额外线路运输费");
|
||||
PayWeightBand remote = band("0", "1", "7.1", "Balearic Islands");
|
||||
remote.setSectionName("偏远附加费");
|
||||
remote.setChargeName("偏远附加费");
|
||||
remote.setCalcRule("POSTCODE");
|
||||
remote.setCalcParam("07");
|
||||
product.setWeightBands(new ArrayList<>(List.of(delivery, lineHaul, remote)));
|
||||
PaySurcharge deliveryExtra = fee(11L, "每公斤续重", "0.29", "EUR", "EXTRA_KG", "1");
|
||||
deliveryExtra.setSectionName("派送费");
|
||||
deliveryExtra.setZoneName("Mad High Density 马德里高密度地区");
|
||||
PaySurcharge lineExtra = fee(12L, "每公斤续重", "0.05", "EUR", "EXTRA_KG", "1");
|
||||
lineExtra.setSectionName("额外线路运输费");
|
||||
lineExtra.setZoneName("Mad High Density 马德里高密度地区");
|
||||
PaySurcharge remoteExtra = fee(13L, "每公斤续重", "4", "EUR", "EXTRA_KG", "1");
|
||||
remoteExtra.setSectionName("偏远附加费");
|
||||
remoteExtra.setZoneName("Balearic Islands");
|
||||
product.setSurcharges(List.of(deliveryExtra, lineExtra, remoteExtra));
|
||||
|
||||
PayOrderCostResult island = PayCostCalculator.calculate(product, new BigDecimal("3"),
|
||||
null, null, null, "07008", "Mad High Density 马德里高密度地区", null, 1, List.of(), true, true, "ES", "西班牙");
|
||||
assertTrue(hasFee(island, "基础运费", "15.1"));
|
||||
assertTrue(island.getFees().stream().noneMatch(fee -> "每公斤续重".equals(fee.getFeeName())
|
||||
|| fee.getAmount().compareTo(new BigDecimal("2.05")) == 0
|
||||
|| fee.getFeeName().contains("额外线路") || "偏远附加费".equals(fee.getFeeName())));
|
||||
|
||||
PayOrderCostResult mainland = PayCostCalculator.calculate(product, new BigDecimal("3"),
|
||||
null, null, null, "28001", "Mad High Density 马德里高密度地区", null, 1);
|
||||
assertTrue(hasFee(mainland, "基础运费", "2.63"));
|
||||
assertTrue(hasFee(mainland, "额外线路运输费", "0.09"));
|
||||
assertTrue(mainland.getFees().stream().noneMatch(fee -> "偏远附加费".equals(fee.getFeeName())));
|
||||
assertEquals("07", PaySurchargeRules.remotePrefixes("Balearic Islands 07邮编开头"));
|
||||
assertEquals("35,38", PaySurchargeRules.remotePrefixes("Canary Islands 35、38邮编开头"));
|
||||
assertEquals("9", PaySurchargeRules.remotePrefixes("Portuguese Island 9邮编开头"));
|
||||
assertEquals("", PaySurchargeRules.remotePrefixes("岛屿邮编地区"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void weightBandConditionSelectsSizeOrWeightTier()
|
||||
{
|
||||
PayProduct product = new PayProduct();
|
||||
product.setProductName("尺寸重量");
|
||||
product.setCurrency("EUR");
|
||||
PayWeightBand normal = band("0", "30", "2.00", "普通");
|
||||
normal.setSectionName("派送费");
|
||||
normal.setChargeName("派送费");
|
||||
PayWeightBand heavy = band("0", "30", "8.00", "超重");
|
||||
heavy.setSectionName("派送费");
|
||||
heavy.setChargeName("派送费");
|
||||
heavy.setCalcRule("WEIGHT");
|
||||
heavy.setCalcParam("5");
|
||||
PayWeightBand bulky = band("0", "30", "12.00", "超尺寸");
|
||||
bulky.setSectionName("派送费");
|
||||
bulky.setChargeName("派送费");
|
||||
bulky.setCalcRule("SIZE");
|
||||
bulky.setCalcParam("side:100");
|
||||
product.setWeightBands(new ArrayList<>(List.of(normal, heavy, bulky)));
|
||||
|
||||
PayOrderCostResult plain = PayCostCalculator.calculate(product, new BigDecimal("2"),
|
||||
new BigDecimal("40"), new BigDecimal("30"), new BigDecimal("20"), "28001", "普通", null, 1);
|
||||
assertTrue(hasFee(plain, "基础运费", "2"));
|
||||
|
||||
PayOrderCostResult overWeight = PayCostCalculator.calculate(product, new BigDecimal("6"),
|
||||
new BigDecimal("40"), new BigDecimal("30"), new BigDecimal("20"), "28001", "普通", null, 1);
|
||||
assertTrue(hasFee(overWeight, "基础运费", "8"));
|
||||
|
||||
PayOrderCostResult overSize = PayCostCalculator.calculate(product, new BigDecimal("6"),
|
||||
new BigDecimal("120"), new BigDecimal("30"), new BigDecimal("20"), "28001", "普通", null, 1);
|
||||
assertTrue(hasFee(overSize, "基础运费", "12"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void productPostcodeBookChoosesTheMatchingRemoteFee()
|
||||
{
|
||||
@@ -281,6 +526,59 @@ class PayCostCalculatorTest
|
||||
assertTrue(PayRemoteBook.hits(List.of(delivery), List.of(line(42L, "28001")), "28001", "ES", "西班牙") == null);
|
||||
}
|
||||
|
||||
@Test
|
||||
void evriFeePostcodeAddsTheMatchingSurcharge()
|
||||
{
|
||||
assertTrue(PaySurchargeRules.matchesFeePostcode("BS1 1BT", "BS1 1BT"));
|
||||
assertTrue(PaySurchargeRules.matchesFeePostcode("BS1 1BT", "bs11bt"));
|
||||
assertTrue(PaySurchargeRules.matchesFeePostcode("BS1", "BS1 1BT"));
|
||||
assertTrue(PaySurchargeRules.matchesFeePostcode("BS1 1BT", "BS1"));
|
||||
assertFalse(PaySurchargeRules.matchesFeePostcode("BS1 1BT", "SW1A 1AA"));
|
||||
assertFalse(PaySurchargeRules.matchesFeePostcode("B", "BS1 1BT"));
|
||||
|
||||
PayProduct product = new PayProduct();
|
||||
product.setProductName("Evri 48H");
|
||||
product.setCurrency("GBP");
|
||||
product.setWeightBands(new ArrayList<>(List.of(band("0", "1", "1.51", "UK Mainland"))));
|
||||
PaySurcharge air = fee(9L, "空气减排附加费", "0.45", "GBP", "FEE_POSTCODE", null);
|
||||
air.setSectionName("附加费配置");
|
||||
air.setScId(9L);
|
||||
product.setSurcharges(List.of(air));
|
||||
List<PayRemoteBook.Hit> hits = List.of(new PayRemoteBook.Hit("空气减排附加费", null, "Bristol", "Bristol"));
|
||||
PayOrderCostResult hit = PayCostCalculator.calculate(product, new BigDecimal("0.5"),
|
||||
null, null, null, "BS1 1BT", "UK Mainland", null, 1, null, true, true, "GB", "英国", hits);
|
||||
assertTrue(hasFee(hit, "基础运费", "1.51"));
|
||||
assertTrue(hasFee(hit, "空气减排附加费", "0.45"));
|
||||
assertEquals(new BigDecimal("1.96"), hit.getPayTotal());
|
||||
|
||||
PayOrderCostResult miss = PayCostCalculator.calculate(product, new BigDecimal("0.5"),
|
||||
null, null, null, "SW1A 1AA", "UK Mainland", null, 1, null, true, true, "GB", "英国", List.of());
|
||||
assertTrue(miss.getFees().stream().noneMatch(row -> "空气减排附加费".equals(row.getFeeName())));
|
||||
|
||||
List<PayRemoteBook.Hit> other = List.of(new PayRemoteBook.Hit("燃油附加费", null, "", ""));
|
||||
PayOrderCostResult named = PayCostCalculator.calculate(product, new BigDecimal("0.5"),
|
||||
null, null, null, "BS1 1BT", "UK Mainland", null, 1, null, true, true, "GB", "英国", other);
|
||||
assertTrue(named.getFees().stream().noneMatch(row -> "空气减排附加费".equals(row.getFeeName())));
|
||||
|
||||
PayPostcodeLine stored = new PayPostcodeLine();
|
||||
stored.setChannelName("Evri 48H");
|
||||
stored.setFeeName("空气减排附加费");
|
||||
stored.setPostcode("BS1 3LT");
|
||||
List<PayRemoteBook.Hit> channelHits = PayRemoteBook.surchargeHits(List.of(stored), "BS1 3LT", "UBI英国EVRi普", "UBI_GBPEVRI", "Evri 48H");
|
||||
assertEquals(1, channelHits.size());
|
||||
assertEquals("空气减排附加费", channelHits.get(0).getFeeName());
|
||||
|
||||
PaySurcharge configured = fee(203L, "空气减排费_Evri_48H", "0.45", "EUR", "POSTCODE", null);
|
||||
configured.setSectionName("附加费配置");
|
||||
configured.setScId(203L);
|
||||
configured.setPostcodeText("BS1");
|
||||
product.setSurcharges(List.of(configured));
|
||||
PayOrderCostResult order = PayCostCalculator.calculate(product, new BigDecimal("0.5"),
|
||||
null, null, null, "BS1 3LT", "UK Mainland", null, 1, null, true, true, "GB", "英国", channelHits);
|
||||
assertTrue(order.getFees().stream().anyMatch(row -> "空气减排费_Evri_48H".equals(row.getFeeName())
|
||||
&& row.getAmount().compareTo(new BigDecimal("0.45")) == 0 && "EUR".equals(row.getCurrency())));
|
||||
}
|
||||
|
||||
@Test
|
||||
void severalZonesCannotBePricedFromTheOrder()
|
||||
{
|
||||
|
||||
@@ -2,11 +2,13 @@ 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.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Stream;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import com.bms.price.domain.PayPostcodeGroup;
|
||||
@@ -32,7 +34,7 @@ class PayPostcodeImporterTest
|
||||
assertEquals("Royal Mail", remote195.getChannelName());
|
||||
assertEquals("Royal Mail", remote115.getChannelName());
|
||||
assertEquals("EVRI", evri.getChannelName());
|
||||
assertEquals("EVRI", air.getChannelName());
|
||||
assertEquals("Evri 48H", air.getChannelName());
|
||||
assertEquals(15, remote195.getLineCount());
|
||||
assertTrue(remote195.getLines().stream().anyMatch(line -> "PA60-78".equals(line.getPostcode())));
|
||||
assertTrue(remote195.getLines().stream().anyMatch(line -> "PA80".equals(line.getPostcode())));
|
||||
@@ -47,7 +49,8 @@ class PayPostcodeImporterTest
|
||||
assertEquals("REMOTE", remote195.getCoverage());
|
||||
assertEquals("REMOTE", remote115.getCoverage());
|
||||
assertEquals("REMOTE", evri.getCoverage());
|
||||
assertEquals("", air.getCoverage());
|
||||
assertEquals("SURCHARGE", air.getCoverage());
|
||||
assertTrue(air.getLines().stream().anyMatch(line -> "BS1 1BT".equals(line.getPostcode()) && "Bristol".equals(line.getZoneName())));
|
||||
assertTrue(groups.stream().noneMatch(item -> "Evri 48H".equals(item.getSheetName())));
|
||||
|
||||
PayPostcodeGroup italy = groups.stream().filter(item -> "iMile邮编分区".equals(item.getSheetName()) && "IT".equals(item.getCountryCode())).findFirst().orElseThrow();
|
||||
@@ -80,7 +83,7 @@ class PayPostcodeImporterTest
|
||||
assertEquals("REACH", PayPostcodeImporter.coverageOf("法国GOFO可达邮编", "", ""));
|
||||
assertEquals("UNREACH", PayPostcodeImporter.coverageOf("德国DPD挂号(DEDPD)不可达邮编", "", ""));
|
||||
assertEquals("REMOTE", PayPostcodeImporter.coverageOf("evri 偏远", "", ""));
|
||||
assertEquals("", PayPostcodeImporter.coverageOf("英国附加费", "EVRI偏远&空气减排地区附加费", "空气减排附加费"));
|
||||
assertEquals("SURCHARGE", PayPostcodeImporter.coverageOf("英国附加费", "EVRI偏远&空气减排地区附加费", "空气减排附加费"));
|
||||
List<PayPostcodeImporter.PostcodeToken> kept = PayPostcodeImporter.expandPostcode("KA27-28");
|
||||
assertEquals("KA27-28", kept.get(0).postcode);
|
||||
assertEquals("", kept.get(0).end);
|
||||
@@ -89,6 +92,75 @@ class PayPostcodeImporterTest
|
||||
assertEquals("57039", range.get(0).end);
|
||||
}
|
||||
|
||||
@Test
|
||||
void evriAirReductionReadsAsSurchargeOnEvri48h() throws Exception
|
||||
{
|
||||
List<PayPostcodeGroup> groups = importer.parse(ukFeeBook(), "英国附加费.xlsx");
|
||||
PayPostcodeGroup royal = one(groups.stream().filter(item -> "FEE".equals(item.getConfigKind())).toList(), "偏远附加费", "1.95GBP/票");
|
||||
assertEquals("Royal Mail", royal.getChannelName());
|
||||
assertEquals("REMOTE", royal.getCoverage());
|
||||
assertTrue(royal.getLines().stream().anyMatch(line -> "IV".equals(line.getPostcode())));
|
||||
assertTrue(royal.getLines().stream().anyMatch(line -> "HS".equals(line.getPostcode())));
|
||||
|
||||
PayPostcodeGroup evri = one(groups.stream().filter(item -> "FEE".equals(item.getConfigKind())).toList(), "偏远附加费", "5.95GBP/票");
|
||||
assertEquals("EVRI", evri.getChannelName());
|
||||
assertEquals("REMOTE", evri.getCoverage());
|
||||
assertTrue(evri.getLines().stream().anyMatch(line -> "GY".equals(line.getPostcode()) && "GY*".equals(line.getPostcodeRaw())));
|
||||
assertTrue(evri.getLines().stream().noneMatch(line -> "BS1 1BT".equals(line.getPostcode())));
|
||||
|
||||
PayPostcodeGroup air = one(groups.stream().filter(item -> "FEE".equals(item.getConfigKind())).toList(), "空气减排附加费", "0.45GBP/票");
|
||||
assertEquals("Evri 48H", air.getChannelName());
|
||||
assertEquals("SURCHARGE", air.getCoverage());
|
||||
assertEquals("英国", air.getCountryName());
|
||||
assertEquals(2, air.getLineCount());
|
||||
assertTrue(air.getLines().stream().anyMatch(line -> "BS1 1BT".equals(line.getPostcode()) && "Bristol".equals(line.getZoneName()) && "Bristol".equals(line.getRegionName())));
|
||||
assertTrue(air.getLines().stream().anyMatch(line -> "BS1 1BU".equals(line.getPostcode()) && "Bristol".equals(line.getZoneName())));
|
||||
}
|
||||
|
||||
private static byte[] ukFeeBook() throws Exception
|
||||
{
|
||||
try (XSSFWorkbook book = new XSSFWorkbook(); ByteArrayOutputStream out = new ByteArrayOutputStream())
|
||||
{
|
||||
var sheet = book.createSheet("英国附加费");
|
||||
var title = sheet.createRow(0);
|
||||
title.createCell(0).setCellValue("Royal Mail偏远地区附加费");
|
||||
title.createCell(4).setCellValue("EVRI偏远&空气减排地区附加费");
|
||||
var head = sheet.createRow(1);
|
||||
String[] headers = {
|
||||
"偏远地区(英文)", "邮编开头", "偏远附加费", "",
|
||||
"偏远地区(英文)", "偏远地区(中文)", "邮编开头", "偏远附加费",
|
||||
"空气减排地区", "空气减排地区邮编", "空气减排附加费"
|
||||
};
|
||||
for (int i = 0; i < headers.length; i++)
|
||||
{
|
||||
if (!headers[i].isEmpty())
|
||||
{
|
||||
head.createCell(i).setCellValue(headers[i]);
|
||||
}
|
||||
}
|
||||
var first = sheet.createRow(2);
|
||||
first.createCell(0).setCellValue("The Highlands");
|
||||
first.createCell(1).setCellValue("IV");
|
||||
first.createCell(2).setCellValue("1.95GBP/票");
|
||||
first.createCell(4).setCellValue("Channel Islands");
|
||||
first.createCell(5).setCellValue("海峡群岛(含锡利岛)");
|
||||
first.createCell(6).setCellValue("GY*");
|
||||
first.createCell(7).setCellValue("5.95GBP/票");
|
||||
first.createCell(8).setCellValue("Bristol");
|
||||
first.createCell(9).setCellValue("BS1 1BT");
|
||||
first.createCell(10).setCellValue("0.45GBP/票");
|
||||
var second = sheet.createRow(3);
|
||||
second.createCell(1).setCellValue("HS");
|
||||
second.createCell(2).setCellValue("1.95GBP/票");
|
||||
second.createCell(6).setCellValue("JE*");
|
||||
second.createCell(7).setCellValue("5.95GBP/票");
|
||||
second.createCell(9).setCellValue("BS1 1BU");
|
||||
second.createCell(10).setCellValue("0.45GBP/票");
|
||||
book.write(out);
|
||||
return out.toByteArray();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled("依赖开发机 D:/应付供应商 下的价卡文件,未随项目提供")
|
||||
void reachableUnreachableAndRemoteKeepTheirOwnCountry() throws Exception
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package com.bms.price.pay;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import java.math.BigDecimal;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
@@ -34,7 +35,26 @@ class PayWorkbookParserTest
|
||||
assertTrue(evri.getSurcharges().stream().anyMatch(fee -> "战争附加费".equals(fee.getFeeName()) && fee.getChargeText().contains("2.5")));
|
||||
PayProduct ctt = product(preview, "CTT 48H");
|
||||
assertTrue(ctt.getWeightBands().stream().anyMatch(band -> band.getWeightLabel() != null && band.getWeightLabel().contains("首重") && decimal(band, "2.05")));
|
||||
assertTrue(ctt.getWeightBands().stream().anyMatch(band -> "每增加 1Kg".equals(band.getWeightLabel()) || (band.getWeightLabel() != null && band.getWeightLabel().contains("每增加"))));
|
||||
assertTrue(ctt.getWeightBands().stream().noneMatch(band -> band.getWeightLabel() != null && band.getWeightLabel().contains("每增加")));
|
||||
assertTrue(ctt.getSurcharges().stream().anyMatch(fee -> "每公斤续重".equals(fee.getFeeName()) && fee.getAmount() != null && fee.getAmount().compareTo(new BigDecimal("0.29")) == 0));
|
||||
assertTrue(ctt.getWeightBands().stream().anyMatch(band -> "西班牙(ES)".equals(band.getCountryName()) && "ES".equals(band.getCountryCode())
|
||||
&& band.getZoneName() != null && band.getZoneName().contains("马德里") && decimal(band, "2.05")));
|
||||
assertTrue(ctt.getWeightBands().stream().anyMatch(band -> "葡萄牙(PT)".equals(band.getCountryName()) && "PT".equals(band.getCountryCode())
|
||||
&& band.getZoneName() != null && band.getZoneName().contains("Mainland") && decimal(band, "2.63")));
|
||||
assertTrue(ctt.getWeightBands().stream().noneMatch(band -> band.getCountryName() != null && band.getCountryName().contains("西班牙") && band.getCountryName().contains("葡萄牙")));
|
||||
assertEquals(1, ctt.getWeightBands().stream().filter(band -> "葡萄牙(PT)".equals(band.getCountryName()) && "派送费".equals(band.getChargeName())).count());
|
||||
assertTrue(ctt.getWeightBands().stream().anyMatch(band -> band.getChargeName() != null && band.getChargeName().contains("偏远")
|
||||
&& "西班牙(ES)".equals(band.getCountryName()) && "Balearic Islands".equals(band.getZoneName())
|
||||
&& "POSTCODE".equals(band.getCalcRule()) && "07".equals(band.getCalcParam()) && decimal(band, "7.1")));
|
||||
assertTrue(ctt.getWeightBands().stream().anyMatch(band -> band.getChargeName() != null && band.getChargeName().contains("偏远")
|
||||
&& "葡萄牙(PT)".equals(band.getCountryName()) && "Portuguese Island".equals(band.getZoneName())
|
||||
&& "POSTCODE".equals(band.getCalcRule()) && "9".equals(band.getCalcParam())));
|
||||
assertTrue(ctt.getWeightBands().stream().noneMatch(band -> band.getZoneName() != null && band.getZoneName().contains("邮编")));
|
||||
assertTrue(ctt.getSurcharges().stream().anyMatch(fee -> "每公斤续重".equals(fee.getFeeName()) && fee.getSectionName() != null && fee.getSectionName().contains("偏远")
|
||||
&& fee.getZoneName() != null && "Balearic Islands".equals(fee.getZoneName())
|
||||
&& fee.getAmount() != null && fee.getAmount().compareTo(new BigDecimal("4")) == 0));
|
||||
assertTrue(ctt.getWeightBands().stream().noneMatch(band -> band.getChargeName() != null && (band.getChargeName().contains("额外") || band.getChargeName().toLowerCase().contains("line-haul"))));
|
||||
assertTrue(ctt.getSurcharges().stream().noneMatch(fee -> fee.getFeeName() != null && (fee.getFeeName().contains("额外线路") || fee.getFeeName().toLowerCase().contains("line-haul") || fee.getSectionName() != null && fee.getSectionName().toLowerCase().contains("line-haul"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -221,14 +241,24 @@ class PayWorkbookParserTest
|
||||
assertEquals("Evri 48H", evri.getDictValue());
|
||||
assertEquals("Evri 48H", evri.getSheetName());
|
||||
assertFalse(evri.getWeightBands().isEmpty());
|
||||
assertTrue(evri.getWeightBands().stream().allMatch(band -> "派送费".equals(band.getChargeName())));
|
||||
assertTrue(evri.getWeightBands().stream().noneMatch(band -> bandText(band).contains("偏远") || bandText(band).contains("Highlands")));
|
||||
assertTrue(evri.getWeightBands().stream().anyMatch(band -> decimal(band, "1.51") && band.getZoneName().contains("Mainland")));
|
||||
PaySurcharge highlands = evri.getSurcharges().stream()
|
||||
.filter(fee -> "偏远附加费".equals(fee.getFeeName()) && fee.getZoneName().contains("Highlands") && decimalFee(fee, "5.95"))
|
||||
assertTrue(evri.getWeightBands().stream().filter(band -> "派送费".equals(band.getChargeName()))
|
||||
.allMatch(band -> band.getZoneName() != null && band.getZoneName().contains("Mainland")));
|
||||
assertTrue(evri.getWeightBands().stream().anyMatch(band -> decimal(band, "1.51") && band.getZoneName().contains("Mainland")
|
||||
&& "派送费".equals(band.getChargeName())));
|
||||
PayWeightBand highlands = evri.getWeightBands().stream()
|
||||
.filter(band -> "偏远附加费".equals(band.getChargeName()) && band.getZoneName().contains("Highlands") && decimal(band, "5.95"))
|
||||
.findFirst().orElseThrow();
|
||||
assertEquals("ZONE", highlands.getCalcRule());
|
||||
assertTrue(highlands.getWeightMax() != null && highlands.getWeightMax().compareTo(java.math.BigDecimal.ONE) == 0);
|
||||
assertTrue(highlands.getWeightMin() != null && highlands.getWeightMin().compareTo(java.math.BigDecimal.ZERO) == 0);
|
||||
assertEquals(5, evri.getWeightBands().stream()
|
||||
.filter(band -> "偏远附加费".equals(band.getChargeName()) && band.getWeightMax() != null
|
||||
&& band.getWeightMax().compareTo(java.math.BigDecimal.ONE) == 0)
|
||||
.count());
|
||||
assertTrue(evri.getWeightBands().stream().anyMatch(band -> "偏远附加费".equals(band.getChargeName())
|
||||
&& band.getZoneName().contains("Isle of Man") && decimal(band, "8.2")
|
||||
&& band.getWeightMin() != null && band.getWeightMin().compareTo(new java.math.BigDecimal("15")) == 0));
|
||||
assertTrue(evri.getSurcharges().stream().noneMatch(fee -> "偏远附加费".equals(fee.getFeeName()) && decimalFee(fee, "5.95")));
|
||||
assertTrue(evri.getSurcharges().stream().anyMatch(fee -> "战争附加费".equals(fee.getFeeName())));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -454,29 +484,18 @@ class PayWorkbookParserTest
|
||||
PayPreview preview = parser.parseMatched(Files.readAllBytes(file), file.getFileName().toString(), "CTT 48H",
|
||||
List.of("CTT 48H"));
|
||||
PayProduct ctt = preview.getProducts().get(0);
|
||||
assertTrue(ctt.getWeightBands().stream().allMatch(band -> "派送费".equals(band.getChargeName())),
|
||||
ctt.getWeightBands().stream().map(band -> band.getChargeName() + "/" + band.getZoneName() + "/" + band.getPrice()).toList().toString());
|
||||
assertTrue(ctt.getWeightBands().stream().anyMatch(band -> decimal(band, "2.05") && band.getZoneName().contains("马德里")));
|
||||
assertTrue(ctt.getWeightBands().stream().noneMatch(band -> bandText(band).contains("偏远") || bandText(band).contains("额外")
|
||||
|| bandText(band).toLowerCase().contains("line-haul")));
|
||||
PaySurcharge balearic = ctt.getSurcharges().stream()
|
||||
.filter(fee -> "偏远附加费".equals(fee.getFeeName()) && fee.getZoneName().contains("Balearic") && decimalFee(fee, "7.1"))
|
||||
.findFirst().orElseThrow();
|
||||
assertTrue(balearic.getFeeDesc().contains("首重"));
|
||||
assertEquals("POSTCODE", balearic.getCalcRule());
|
||||
assertTrue(balearic.getCalcParam() != null && balearic.getCalcParam().contains("07"));
|
||||
assertTrue(balearic.getWeightMax() != null && balearic.getWeightMax().compareTo(new java.math.BigDecimal("1")) == 0);
|
||||
PaySurcharge canary = ctt.getSurcharges().stream()
|
||||
.filter(fee -> "偏远附加费".equals(fee.getFeeName()) && fee.getZoneName().contains("Canary") && decimalFee(fee, "4.5")
|
||||
&& fee.getChargeText().contains("KG"))
|
||||
.findFirst().orElseThrow();
|
||||
assertEquals("EXTRA_KG", canary.getCalcRule());
|
||||
assertEquals("1", canary.getCalcParam());
|
||||
assertTrue(canary.getPostcodeParam() != null && canary.getPostcodeParam().contains("35") && canary.getPostcodeParam().contains("38"));
|
||||
assertTrue(ctt.getSurcharges().stream().anyMatch(fee -> fee.getFeeName().contains("额外线路运输费") && "MANUAL".equals(fee.getCalcRule())));
|
||||
assertTrue(ctt.getSurcharges().stream().anyMatch(fee -> fee.getFeeName().contains("额外线路运输费") && decimalFee(fee, "0.09")));
|
||||
assertTrue(ctt.getSurcharges().stream().anyMatch(fee -> fee.getFeeName().contains("额外线路运输费")
|
||||
&& fee.getFeeDesc().contains("800公里")));
|
||||
assertTrue(ctt.getWeightBands().stream().anyMatch(band -> "派送费".equals(band.getChargeName()) && "西班牙(ES)".equals(band.getCountryName())
|
||||
&& decimal(band, "2.05") && band.getZoneName().contains("马德里")));
|
||||
assertTrue(ctt.getWeightBands().stream().anyMatch(band -> "派送费".equals(band.getChargeName()) && "葡萄牙(PT)".equals(band.getCountryName())
|
||||
&& band.getZoneName() != null && band.getZoneName().contains("Mainland")));
|
||||
assertTrue(ctt.getWeightBands().stream().anyMatch(band -> band.getChargeName() != null && band.getChargeName().contains("偏远")
|
||||
&& "西班牙(ES)".equals(band.getCountryName()) && band.getZoneName() != null && band.getZoneName().contains("Balearic") && decimal(band, "7.1")));
|
||||
assertTrue(ctt.getSurcharges().stream().anyMatch(fee -> "每公斤续重".equals(fee.getFeeName()) && fee.getSectionName() != null
|
||||
&& fee.getSectionName().contains("偏远") && fee.getZoneName() != null && fee.getZoneName().contains("Canary") && decimalFee(fee, "4.5")));
|
||||
assertTrue(ctt.getWeightBands().stream().noneMatch(band -> band.getChargeName() != null
|
||||
&& (band.getChargeName().contains("额外") || band.getChargeName().toLowerCase().contains("line-haul"))));
|
||||
assertTrue(ctt.getSurcharges().stream().noneMatch(fee -> (fee.getFeeName() != null && (fee.getFeeName().contains("额外线路") || fee.getFeeName().toLowerCase().contains("line-haul")))
|
||||
|| (fee.getSectionName() != null && (fee.getSectionName().contains("额外线路") || fee.getSectionName().toLowerCase().contains("line-haul")))));
|
||||
assertTrue(ctt.getSurcharges().stream().anyMatch(fee -> "超重附加费".equals(fee.getFeeName()) && decimalFee(fee, "5.98")));
|
||||
}
|
||||
|
||||
@@ -489,7 +508,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 +553,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());
|
||||
@@ -584,13 +603,13 @@ class PayWorkbookParserTest
|
||||
PayOrderCostResult twoKg = PayCostCalculator.calculate(ctt, new java.math.BigDecimal("2"), null, null, null, null,
|
||||
"Balearic Islands Economy 48H / Majorca", null, 1);
|
||||
assertEquals(new java.math.BigDecimal("4.24"), twoKg.getPayTotal());
|
||||
assertEquals(1, twoKg.getFees().stream().filter(fee -> "每公斤续重".equals(fee.getFeeName())
|
||||
&& fee.getAmount().compareTo(new java.math.BigDecimal("0.85")) == 0).count());
|
||||
assertTrue(twoKg.getFees().stream().anyMatch(fee -> "基础运费".equals(fee.getFeeName())
|
||||
&& fee.getAmount().compareTo(new java.math.BigDecimal("4.24")) == 0));
|
||||
assertTrue(twoKg.getFees().stream().noneMatch(fee -> "每公斤续重".equals(fee.getFeeName())));
|
||||
PayOrderCostResult island = PayCostCalculator.calculate(ctt, new java.math.BigDecimal("2"), null, null, null, null,
|
||||
"Portuguese Island / Island", null, 1);
|
||||
assertEquals(new java.math.BigDecimal("12.41"), island.getPayTotal());
|
||||
assertEquals(1, island.getFees().stream().filter(fee -> "每公斤续重".equals(fee.getFeeName())
|
||||
&& fee.getAmount().compareTo(new java.math.BigDecimal("3.34")) == 0).count());
|
||||
assertTrue(island.getFees().stream().noneMatch(fee -> "每公斤续重".equals(fee.getFeeName())));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -607,7 +626,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())
|
||||
|
||||
@@ -25,6 +25,17 @@ class PayZoneMatcherTest
|
||||
assertEquals("UK Mainland\n英国大陆", decision.getZoneName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void ordinaryUkPostcodeIsMainlandAndNotARemoteZone()
|
||||
{
|
||||
PayZoneMatcher.Decision decision = PayZoneMatcher.resolve(ZONES, evriLines(), "KY4 0DN");
|
||||
assertNull(decision.getMessage());
|
||||
assertEquals("UK Mainland\n英国大陆", decision.getZoneName());
|
||||
PayZoneMatcher.Decision emptyBook = PayZoneMatcher.resolve(ZONES, List.of(), "KY4 0DN");
|
||||
assertNull(emptyBook.getMessage());
|
||||
assertEquals("UK Mainland\n英国大陆", emptyBook.getZoneName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void northernIrelandAndHighlandsComeFromThePostcodeBook()
|
||||
{
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
package com.bms.receivable;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import com.bms.receivable.domain.ArBillDetail;
|
||||
import com.bms.receivable.domain.vo.ArBillDetailQuery;
|
||||
import com.bms.receivable.mapper.ArBillDetailMapper;
|
||||
import com.bms.receivable.security.ArBillRowScope;
|
||||
import com.bms.receivable.security.ArBillScopeResolver;
|
||||
import com.bms.receivable.service.impl.ArBillServiceImpl;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.parser.defaults.DefaultCountSqlParser;
|
||||
import org.apache.ibatis.builder.xml.XMLMapperBuilder;
|
||||
import org.apache.ibatis.mapping.BoundSql;
|
||||
import org.apache.ibatis.session.Configuration;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
class ArBillDetailSearchTest {
|
||||
@Test
|
||||
void numberSearchUsesExactMatchesAndCannotBypassBillOrPermissionScope() throws Exception {
|
||||
ArBillDetailQuery query = new ArBillDetailQuery();
|
||||
query.setOrderKeyword("00123' OR 1=1 --");
|
||||
BoundSql bound = detailSql(query, scope(false, true));
|
||||
String sql = normalized(bound.getSql());
|
||||
assertTrue(sql.contains("where ar_bill_id = ?"));
|
||||
assertTrue(sql.contains("and (order_no = ? or tracking_no = ? or transfer_no = ?)"));
|
||||
assertTrue(sql.contains("b.ar_bill_id = ar_bill_detail.ar_bill_id"));
|
||||
assertTrue(sql.contains("c.customer_id = b.customer_id"));
|
||||
assertTrue(sql.contains("su.user_id = ?"));
|
||||
assertFalse(sql.contains("order_no like"));
|
||||
assertFalse(sql.contains(query.getOrderKeyword()));
|
||||
assertEquals(3, bound.getParameterMappings().stream()
|
||||
.filter(parameter -> parameter.getProperty().equals("query.orderKeyword")).count());
|
||||
}
|
||||
|
||||
@Test
|
||||
void productSearchAndPaginationCountApplyBothFiltersAndTheSameScope() throws Exception {
|
||||
ArBillDetailQuery query = new ArBillDetailQuery();
|
||||
query.setOrderKeyword("ORDER001");
|
||||
query.setProductKeyword("荷兰");
|
||||
String sql = normalized(detailSql(query, scope(false, true)).getSql());
|
||||
assertTrue(sql.contains("and (product_code like concat('%', ?, '%') or product_name like concat('%', ?, '%'))"));
|
||||
String count = normalized(new DefaultCountSqlParser().getSmartCountSql(sql, "0"));
|
||||
assertTrue(count.startsWith("select count(0)"));
|
||||
assertTrue(count.contains("ar_bill_id = ?"));
|
||||
assertTrue(count.contains("order_no = ?"));
|
||||
assertTrue(count.contains("tracking_no = ?"));
|
||||
assertTrue(count.contains("transfer_no = ?"));
|
||||
assertTrue(count.contains("product_code like"));
|
||||
assertTrue(count.contains("product_name like"));
|
||||
assertTrue(count.contains("su.user_id = ?"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void noSearchKeepsExistingQueryAndDeniedScopeRemainsDenied() throws Exception {
|
||||
for (ArBillDetailQuery query : new ArBillDetailQuery[]{null, new ArBillDetailQuery()}) {
|
||||
String sql = normalized(detailSql(query, scope(false, false)).getSql());
|
||||
assertFalse(sql.contains("order_no = ?"));
|
||||
assertFalse(sql.contains("product_code like"));
|
||||
assertTrue(sql.contains("and 1 = 0"));
|
||||
assertTrue(sql.contains("where ar_bill_id = ?"));
|
||||
assertTrue(sql.endsWith("order by detail_no"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void serviceTrimsSearchAndPreservesPaginationForTheScopedDetailQuery() {
|
||||
ArBillServiceImpl service = new ArBillServiceImpl();
|
||||
ArBillDetailMapper details = mock(ArBillDetailMapper.class);
|
||||
ArBillScopeResolver resolver = mock(ArBillScopeResolver.class);
|
||||
ArBillRowScope scope = mock(ArBillRowScope.class);
|
||||
ReflectionTestUtils.setField(service, "detailMapper", details);
|
||||
ReflectionTestUtils.setField(service, "billScope", resolver);
|
||||
when(resolver.resolve()).thenReturn(scope);
|
||||
List<ArBillDetail> result = List.of(new ArBillDetail());
|
||||
when(details.selectByBillIdScoped(eq(7L), any(), same(scope))).thenAnswer(invocation -> {
|
||||
ArBillDetailQuery query = invocation.getArgument(1);
|
||||
assertEquals("000123", query.getOrderKeyword());
|
||||
assertEquals("荷兰", query.getProductKeyword());
|
||||
assertEquals(3, PageHelper.getLocalPage().getPageNum());
|
||||
return result;
|
||||
});
|
||||
ArBillDetailQuery query = new ArBillDetailQuery();
|
||||
query.setOrderKeyword(" 000123 ");
|
||||
query.setProductKeyword(" 荷兰 ");
|
||||
PageHelper.startPage(3, 10);
|
||||
try {
|
||||
assertSame(result, service.selectArBillDetails(7L, query));
|
||||
verify(details).selectByBillIdScoped(eq(7L), any(), same(scope));
|
||||
verifyNoMoreInteractions(details);
|
||||
} finally {
|
||||
PageHelper.clearPage();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void wholeBillExportQueryDoesNotInheritDetailSearchFilters() throws Exception {
|
||||
String sql = normalized(configuration().getMappedStatement("com.bms.receivable.mapper.ArBillDetailMapper.selectExportPage")
|
||||
.getBoundSql(Map.of("arBillId", 7L, "lastDetailNo", 0, "pageSize", 2000)).getSql());
|
||||
assertTrue(sql.contains("where ar_bill_id = ? and detail_no > ?"));
|
||||
assertFalse(sql.contains("order_no = ?"));
|
||||
assertFalse(sql.contains("product_code like"));
|
||||
assertTrue(sql.endsWith("limit ?"));
|
||||
}
|
||||
|
||||
private BoundSql detailSql(ArBillDetailQuery query, Map<String, Object> scope) throws Exception {
|
||||
Map<String, Object> parameters = new HashMap<>();
|
||||
parameters.put("arBillId", 7L);
|
||||
parameters.put("query", query);
|
||||
parameters.put("scope", scope);
|
||||
return configuration().getMappedStatement("com.bms.receivable.mapper.ArBillDetailMapper.selectByBillIdScoped")
|
||||
.getBoundSql(parameters);
|
||||
}
|
||||
|
||||
private Configuration configuration() throws Exception {
|
||||
Configuration configuration = new Configuration();
|
||||
configuration.getTypeAliasRegistry().registerAlias("ArBillDetail", ArBillDetail.class);
|
||||
for (String resource : List.of("mapper/receivable/ArBillScopeMapper.xml", "mapper/receivable/ArBillDetailMapper.xml")) {
|
||||
try (InputStream input = getClass().getClassLoader().getResourceAsStream(resource)) {
|
||||
new XMLMapperBuilder(input, configuration, resource, configuration.getSqlFragments()).parse();
|
||||
}
|
||||
}
|
||||
return configuration;
|
||||
}
|
||||
|
||||
private Map<String, Object> scope(boolean all, boolean self) {
|
||||
return Map.of("all", all, "self", self, "department", false, "userId", 9L, "deptId", 10L);
|
||||
}
|
||||
|
||||
private String normalized(String sql) {
|
||||
return sql.replaceAll("\\s+", " ").trim().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
}
|
||||
+144
@@ -0,0 +1,144 @@
|
||||
package com.bms.receivable.export;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.sql.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.bms.common.core.domain.model.LoginUser;
|
||||
import com.bms.common.exception.ServiceException;
|
||||
import com.bms.receivable.domain.ArBill;
|
||||
import com.bms.receivable.domain.ArBillExport;
|
||||
import com.bms.receivable.domain.ArExportTemplate;
|
||||
import com.bms.receivable.event.ArBillExportTaskEvent;
|
||||
import com.bms.receivable.mapper.ArBillExportMapper;
|
||||
import com.bms.receivable.mapper.ArBillLogMapper;
|
||||
import com.bms.receivable.mapper.ArBillMapper;
|
||||
import com.bms.receivable.mapper.ArExportTemplateMapper;
|
||||
import com.bms.receivable.security.ArBillScopeResolver;
|
||||
import com.bms.receivable.service.ArBillVoidTaskService;
|
||||
import com.bms.receivable.service.IArBillLogService;
|
||||
import com.bms.receivable.service.impl.ArBillServiceImpl;
|
||||
import org.apache.ibatis.builder.xml.XMLMapperBuilder;
|
||||
import org.apache.ibatis.session.Configuration;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
class ArBillTemplateSelectionTest {
|
||||
private final ArBillServiceImpl service = new ArBillServiceImpl();
|
||||
private final ArBillMapper bills = mock(ArBillMapper.class);
|
||||
private final ArExportTemplateMapper templates = mock(ArExportTemplateMapper.class);
|
||||
private final ArBillExportMapper exports = mock(ArBillExportMapper.class);
|
||||
private final ApplicationEventPublisher publisher = mock(ApplicationEventPublisher.class);
|
||||
private final ArBill bill = new ArBill();
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
LoginUser login = new LoginUser();
|
||||
login.setUserId(1L);
|
||||
SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(login, null, List.of()));
|
||||
ReflectionTestUtils.setField(service, "billMapper", bills);
|
||||
ReflectionTestUtils.setField(service, "exportTemplateMapper", templates);
|
||||
ReflectionTestUtils.setField(service, "exportMapper", exports);
|
||||
ReflectionTestUtils.setField(service, "billScope", mock(ArBillScopeResolver.class));
|
||||
ReflectionTestUtils.setField(service, "voidTaskService", mock(ArBillVoidTaskService.class));
|
||||
ReflectionTestUtils.setField(service, "logMapper", mock(ArBillLogMapper.class));
|
||||
ReflectionTestUtils.setField(service, "logService", mock(IArBillLogService.class));
|
||||
ReflectionTestUtils.setField(service, "eventPublisher", publisher);
|
||||
ReflectionTestUtils.setField(service, "workbookWriters", new ArBillWorkbookWriters(
|
||||
new DefaultArBillWorkbookWriter(), new SummaryArBillWorkbookWriter()));
|
||||
bill.setArBillId(7L);
|
||||
bill.setGenerationStatus("READY");
|
||||
bill.setStatus("CONFIRMED");
|
||||
bill.setBillDate(Date.valueOf("2026-10-31"));
|
||||
bill.setBillPeriodEnd(Date.valueOf("2026-10-31"));
|
||||
bill.setCustomerName("测试客户");
|
||||
bill.setCustomerCode("C1");
|
||||
when(bills.selectArBillByIdForUpdate(7L)).thenReturn(bill);
|
||||
when(bills.selectArBillById(7L)).thenReturn(bill);
|
||||
when(exports.insert(any())).thenAnswer(invocation -> {
|
||||
((ArBillExport) invocation.getArgument(0)).setExportId(99L);
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void clearLogin() { SecurityContextHolder.clearContext(); }
|
||||
|
||||
@Test
|
||||
void bindsSelectedTemplateAndOnlyReusesTasksWithTheSameTemplate() {
|
||||
ArExportTemplate selected = template(2L, "AR_BILL_SUMMARY");
|
||||
when(templates.selectEnabledById(2L, "AR_BILL", bill.getBillDate())).thenReturn(selected);
|
||||
ArBillExport task = service.exportBill(7L, 2L, "admin", "request-summary");
|
||||
assertEquals(2L, task.getTemplateId());
|
||||
assertEquals("AR_BILL_SUMMARY", task.getTemplateCode());
|
||||
assertEquals("1.0", task.getTemplateVersion());
|
||||
assertEquals(selected.getStorageKey(), task.getTemplateStorageKey());
|
||||
assertTrue(task.getFileName().endsWith("_汇总.xlsx"));
|
||||
verify(exports).selectProcessingByBillAndTemplate(7L, 2L);
|
||||
verify(publisher).publishEvent(any(ArBillExportTaskEvent.class));
|
||||
|
||||
when(exports.selectProcessingByBillAndTemplate(7L, 2L)).thenReturn(task);
|
||||
assertSame(task, service.exportBill(7L, 2L, "admin", "request-repeat"));
|
||||
verify(exports, times(1)).insert(any());
|
||||
verify(templates, never()).selectDefaultEnabled(anyString(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void omittingTemplateRetainsDefaultBehaviorAndInvalidSelectionCannotQueueAnExport() {
|
||||
when(templates.selectDefaultEnabled("AR_BILL", bill.getBillDate())).thenReturn(template(1L, "AR_CUSTOMER_BILL"));
|
||||
ArBillExport task = service.exportBill(7L, null, "admin", "request-default");
|
||||
assertEquals(1L, task.getTemplateId());
|
||||
assertFalse(task.getFileName().contains("汇总"));
|
||||
assertThrows(ServiceException.class, () -> service.exportBill(7L, 9L, "admin", "request-invalid"));
|
||||
verify(exports, times(1)).insert(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void optionsUseTheBillEffectiveDateAndOnlyExposeChoiceMetadata() {
|
||||
when(templates.selectEnabledList("AR_BILL", bill.getBillDate())).thenReturn(List.of(template(2L, "AR_BILL_SUMMARY")));
|
||||
var options = service.selectExportTemplates(7L);
|
||||
assertEquals(2L, options.get(0).getTemplateId());
|
||||
assertEquals("应收账单汇总模板", options.get(0).getTemplateName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void mapperQueriesEnforceBusinessStatusEffectiveDatesAndTaskTemplate() throws Exception {
|
||||
Configuration configuration = new Configuration();
|
||||
configuration.getTypeAliasRegistry().registerAlias("ArExportTemplate", ArExportTemplate.class);
|
||||
configuration.getTypeAliasRegistry().registerAlias("ArBillExport", ArBillExport.class);
|
||||
for (String resource : List.of("mapper/receivable/ArExportTemplateMapper.xml", "mapper/receivable/ArBillExportMapper.xml")) {
|
||||
try (InputStream input = getClass().getClassLoader().getResourceAsStream(resource)) {
|
||||
new XMLMapperBuilder(input, configuration, resource, configuration.getSqlFragments()).parse();
|
||||
}
|
||||
}
|
||||
String sql = configuration.getMappedStatement("com.bms.receivable.mapper.ArExportTemplateMapper.selectEnabledById")
|
||||
.getBoundSql(Map.of("templateId", 2L, "businessType", "AR_BILL", "effectiveDate", bill.getBillDate())).getSql();
|
||||
for (String condition : List.of("business_type = ?", "status = 'ENABLED'", "effective_start <= ?",
|
||||
"effective_end >= ?", "template_id = ?")) assertTrue(sql.contains(condition), sql);
|
||||
String taskSql = configuration.getMappedStatement("com.bms.receivable.mapper.ArBillExportMapper.selectProcessingByBillAndTemplate")
|
||||
.getBoundSql(Map.of("arBillId", 7L, "templateId", 2L)).getSql();
|
||||
assertTrue(taskSql.contains("template_id = ?"));
|
||||
assertTrue(taskSql.contains("export_status = 'PROCESSING'"));
|
||||
}
|
||||
|
||||
private ArExportTemplate template(Long id, String code) {
|
||||
ArExportTemplate template = new ArExportTemplate();
|
||||
template.setTemplateId(id);
|
||||
template.setTemplateCode(code);
|
||||
template.setTemplateName("应收账单汇总模板");
|
||||
template.setTemplateVersion("1.0");
|
||||
template.setStorageType("CLASSPATH");
|
||||
template.setStorageKey("templates/receivable/ar_bill_template_summary.xlsx");
|
||||
return template;
|
||||
}
|
||||
}
|
||||
+343
@@ -0,0 +1,343 @@
|
||||
package com.bms.receivable.export;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.sql.Date;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
import com.bms.receivable.domain.ArBill;
|
||||
import com.bms.receivable.domain.ArBillDetail;
|
||||
import com.bms.receivable.domain.ArExportTemplate;
|
||||
import com.bms.receivable.mapper.ArBillDetailFeeMapper;
|
||||
import com.bms.receivable.mapper.ArBillDetailMapper;
|
||||
import org.apache.poi.ss.usermodel.CellType;
|
||||
import org.apache.poi.ss.usermodel.FormulaEvaluator;
|
||||
import org.apache.poi.ss.usermodel.IndexedColors;
|
||||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
class ArBillWorkbookWriterTest {
|
||||
@TempDir
|
||||
Path temporary;
|
||||
|
||||
@Test
|
||||
void summaryAndDetailsReconcileSnapshotAmountsAndKeepFreightFormulaAndBlankFields() throws Exception {
|
||||
ArBill bill = bill(3, "13.20", "CNY");
|
||||
List<ArBillDetail> details = List.of(detail(1, "P1", "10.12"), detail(2, "P1", "-2.22"),
|
||||
detail(3, "P2", "5.30"));
|
||||
// 相同名称的不同产品仍需分组;收货日期也不能替代账单所属期。
|
||||
details.forEach(row -> row.setProductName("相同产品名"));
|
||||
Path target = temporary.resolve("summary.xlsx");
|
||||
SummaryArBillWorkbookWriter writer = summaryWriter(details);
|
||||
writer.write(bill, summaryTemplate(), target);
|
||||
try (XSSFWorkbook workbook = new XSSFWorkbook(target.toFile())) {
|
||||
assertEquals(2, workbook.getNumberOfSheets());
|
||||
assertEquals("账单汇总", workbook.getSheetName(0));
|
||||
assertEquals("运费明细", workbook.getSheetName(1));
|
||||
XSSFSheet summary = workbook.getSheetAt(0);
|
||||
XSSFSheet freight = workbook.getSheetAt(1);
|
||||
assertEquals("客户 & <测试>", summary.getRow(3).getCell(1).getStringCellValue());
|
||||
assertEquals("相同产品名", summary.getRow(3).getCell(2).getStringCellValue());
|
||||
assertEquals("相同产品名", summary.getRow(4).getCell(2).getStringCellValue());
|
||||
assertEquals("20261001-20261031", summary.getRow(3).getCell(3).getStringCellValue());
|
||||
assertEquals("国际货物运输代理服务费", summary.getRow(4).getCell(6).getStringCellValue());
|
||||
assertEquals(7.90, summary.getRow(3).getCell(4).getNumericCellValue(), 0.00001);
|
||||
assertEquals(5.30, summary.getRow(4).getCell(4).getNumericCellValue(), 0.00001);
|
||||
assertEquals("SUMIF(F4:F5,F7,E4:E5)", summary.getRow(6).getCell(4).getCellFormula());
|
||||
assertEquals(13.20, summary.getRow(6).getCell(4).getNumericCellValue(), 0.00001);
|
||||
assertEquals("收款账户快照", summary.getRow(11).getCell(1).getStringCellValue());
|
||||
assertEquals("1234 5678 90", summary.getRow(12).getCell(1).getStringCellValue());
|
||||
assertTrue(summary.getMergedRegions().stream().anyMatch(region -> "A11:B11".equals(region.formatAsString())));
|
||||
|
||||
assertEquals("客户 & <测试>", freight.getRow(2).getCell(1).getStringCellValue());
|
||||
assertEquals("20261001-20261031", freight.getRow(2).getCell(18).getStringCellValue());
|
||||
assertEquals("0000123", freight.getRow(4).getCell(0).getStringCellValue());
|
||||
assertEquals("00000001", freight.getRow(4).getCell(2).getStringCellValue());
|
||||
assertEquals("001234567890123456789", freight.getRow(4).getCell(3).getStringCellValue());
|
||||
assertEquals("00123", freight.getRow(4).getCell(6).getStringCellValue());
|
||||
assertEquals(9.5, freight.getRow(4).getCell(8).getNumericCellValue());
|
||||
assertEquals("ROUND(J5*L5,2)", freight.getRow(4).getCell(13).getCellFormula());
|
||||
assertEquals(2.81, freight.getRow(4).getCell(13).getNumericCellValue(), 0.00001);
|
||||
assertEquals(CellType.FORMULA, freight.getRow(4).getCell(16).getCellType());
|
||||
assertEquals("N5+K5+M5+P5+O5", freight.getRow(4).getCell(16).getCellFormula());
|
||||
assertEquals(10.12, freight.getRow(4).getCell(16).getNumericCellValue(), 0.00001);
|
||||
assertEquals(-2.22, freight.getRow(5).getCell(16).getNumericCellValue(), 0.00001);
|
||||
assertEquals(21, freight.getRow(4).getLastCellNum());
|
||||
assertEquals("说明", freight.getRow(3).getCell(20).getStringCellValue());
|
||||
assertEquals("", freight.getRow(4).getCell(19).getStringCellValue());
|
||||
assertEquals("", freight.getRow(4).getCell(20).getStringCellValue());
|
||||
for (int column : new int[]{10, 14, 15}) {
|
||||
assertEquals(0.0, freight.getRow(4).getCell(column).getNumericCellValue());
|
||||
assertEquals("0.00", freight.getRow(4).getCell(column).getCellStyle().getDataFormatString());
|
||||
}
|
||||
for (int column : new int[]{7, 17, 18}) {
|
||||
assertEquals("", freight.getRow(4).getCell(column).getStringCellValue());
|
||||
}
|
||||
assertEquals("SUM(Q5:Q7)", freight.getRow(8).getCell(16).getCellFormula());
|
||||
assertEquals(13.20, freight.getRow(8).getCell(16).getNumericCellValue(), 0.00001);
|
||||
FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
|
||||
assertEquals(13.20, evaluator.evaluate(summary.getRow(6).getCell(4)).getNumberValue(), 0.00001);
|
||||
assertEquals(13.20, evaluator.evaluate(freight.getRow(8).getCell(16)).getNumberValue(), 0.00001);
|
||||
assertEquals(2.81, evaluator.evaluate(freight.getRow(4).getCell(13)).getNumberValue(), 0.00001);
|
||||
assertFalse(workbook.getPrintArea(0).contains("#REF!"));
|
||||
assertTrue(workbook.getPrintArea(1).contains("$U$9"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void readsSeveralCursorBatchesOnceAndExportsAllRowsToTheSameDetailSheet() throws Exception {
|
||||
int count = 4001;
|
||||
SummaryArBillWorkbookWriter writer = new SummaryArBillWorkbookWriter();
|
||||
writer.detailMapper = mock(ArBillDetailMapper.class);
|
||||
writer.detailFeeMapper = mock(ArBillDetailFeeMapper.class);
|
||||
when(writer.detailFeeMapper.selectByDetailIds(anyList())).thenReturn(List.of());
|
||||
List<Integer> cursors = new ArrayList<>();
|
||||
when(writer.detailMapper.selectExportPage(eq(7L), anyInt(), eq(2000))).thenAnswer(invocation -> {
|
||||
int previous = invocation.getArgument(1);
|
||||
cursors.add(previous);
|
||||
return IntStream.rangeClosed(previous + 1, Math.min(previous + 2000, count))
|
||||
.mapToObj(number -> detail(number, "P" + (number % 3), "1.00")).toList();
|
||||
});
|
||||
Path target = temporary.resolve("large.xlsx");
|
||||
writer.write(bill(count, "4001.00", "CNY"), summaryTemplate(), target);
|
||||
assertEquals(List.of(0, 2000, 4000, 4001), cursors);
|
||||
try (XSSFWorkbook workbook = new XSSFWorkbook(target.toFile())) {
|
||||
assertEquals(2, workbook.getNumberOfSheets());
|
||||
XSSFSheet sheet = workbook.getSheetAt(1);
|
||||
assertEquals("ROUND(J4005*L4005,2)", sheet.getRow(4004).getCell(13).getCellFormula());
|
||||
assertEquals("SUM(Q5:Q4005)", sheet.getRow(4006).getCell(16).getCellFormula());
|
||||
assertEquals(4001, sheet.getRow(4006).getCell(16).getNumericCellValue());
|
||||
assertEquals(4001, workbook.getSheetAt(0).getRow(7).getCell(4).getNumericCellValue());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void usesBillCurrencyForHeadersAndKeepsFailedOrderHighlightAndExplanation() throws Exception {
|
||||
ArBillDetail detail = detail(1, "P1", "1.00");
|
||||
detail.setCurrency("USD");
|
||||
detail.setBillingFailStatus(2);
|
||||
ArBillDetail withoutRemark = detail(2, "P1", "1.00");
|
||||
withoutRemark.setCurrency("USD");
|
||||
withoutRemark.setBillingFailStatus(2);
|
||||
withoutRemark.setRemark(null);
|
||||
withoutRemark.setGoodsDescription("仅供内部使用的品名描述");
|
||||
ArBillDetail success = detail(3, "P1", "1.00");
|
||||
success.setCurrency("USD");
|
||||
success.setBillingFailStatus(0);
|
||||
Path target = temporary.resolve("usd.xlsx");
|
||||
summaryWriter(List.of(detail, withoutRemark, success)).write(bill(3, "3.00", "USD"), summaryTemplate(), target);
|
||||
try (XSSFWorkbook workbook = new XSSFWorkbook(target.toFile())) {
|
||||
XSSFSheet freight = workbook.getSheetAt(1);
|
||||
for (int column : new int[]{11, 12, 13, 15, 16}) {
|
||||
String title = freight.getRow(3).getCell(column).getStringCellValue();
|
||||
assertTrue(title.contains("USD"));
|
||||
assertFalse(title.contains("CNY"));
|
||||
}
|
||||
assertEquals("USD", workbook.getSheetAt(0).getRow(5).getCell(5).getStringCellValue());
|
||||
for (int column = 0; column < 21; column++) {
|
||||
assertEquals(IndexedColors.YELLOW.getIndex(), freight.getRow(4).getCell(column).getCellStyle().getFillForegroundColor());
|
||||
}
|
||||
assertEquals("", freight.getRow(4).getCell(19).getStringCellValue());
|
||||
assertEquals("销售价未匹配国家", freight.getRow(4).getCell(20).getStringCellValue());
|
||||
assertEquals("", freight.getRow(5).getCell(19).getStringCellValue());
|
||||
assertEquals("销售价未匹配国家", freight.getRow(5).getCell(20).getStringCellValue());
|
||||
assertEquals("", freight.getRow(6).getCell(19).getStringCellValue());
|
||||
assertEquals("", freight.getRow(6).getCell(20).getStringCellValue());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsAnExportWhoseSnapshotDetailsDoNotReconcileWithTheBill() {
|
||||
IOException error = assertThrows(IOException.class, () -> summaryWriter(List.of(detail(1, "P1", "1.00")))
|
||||
.write(bill(1, "2.00", "CNY"), summaryTemplate(), temporary.resolve("mismatch.xlsx")));
|
||||
assertTrue(error.getMessage().contains("应收金额合计与账单总额不一致"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void defaultTemplateStillPreservesItsImageAndTheBlankRowBeforeBankFooter() throws Exception {
|
||||
DefaultArBillWorkbookWriter writer = new DefaultArBillWorkbookWriter();
|
||||
writer.detailMapper = mapper(List.of(detail(1, "P1", "1.00")));
|
||||
when(writer.detailMapper.selectReceiveTimeRangeByBillId(7L)).thenReturn(Map.of(
|
||||
"minReceiveTime", Date.valueOf("2026-11-05"), "maxReceiveTime", Date.valueOf("2026-11-05")));
|
||||
writer.detailFeeMapper = mock(ArBillDetailFeeMapper.class);
|
||||
when(writer.detailFeeMapper.selectByDetailIds(anyList())).thenReturn(List.of());
|
||||
ArExportTemplate template = new ArExportTemplate();
|
||||
template.setStorageKey("templates/receivable/ar_bill_template.xlsx");
|
||||
Path target = temporary.resolve("default.xlsx");
|
||||
writer.write(bill(1, "1.00", "CNY"), template, target);
|
||||
try (InputStream input = getClass().getResourceAsStream("/" + template.getStorageKey());
|
||||
XSSFWorkbook original = new XSSFWorkbook(input);
|
||||
XSSFWorkbook workbook = new XSSFWorkbook(target.toFile())) {
|
||||
assertEquals(original.getNumberOfSheets(), workbook.getNumberOfSheets());
|
||||
assertEquals(1, workbook.getAllPictures().size());
|
||||
XSSFSheet sheet = workbook.getSheetAt(0);
|
||||
assertEquals(21, sheet.getRow(4).getLastCellNum());
|
||||
assertEquals(original.getSheetAt(0).getRow(5).getCell(18).getCellStyle().getBorderBottom(),
|
||||
sheet.getRow(4).getCell(18).getCellStyle().getBorderBottom());
|
||||
assertEquals(original.getSheetAt(0).getRow(5).getCell(18).getCellStyle().getFont().getFontHeight(),
|
||||
sheet.getRow(4).getCell(18).getCellStyle().getFont().getFontHeight());
|
||||
assertEquals(1, sheet.getRow(4).getCell(18).getNumericCellValue());
|
||||
assertEquals("备注 & <快照>", sheet.getRow(4).getCell(19).getStringCellValue());
|
||||
assertEquals(0, sheet.getRow(5).getPhysicalNumberOfCells());
|
||||
assertEquals("银行信息", sheet.getRow(6).getCell(1).getStringCellValue());
|
||||
assertEquals("收款账户快照", sheet.getRow(7).getCell(2).getStringCellValue());
|
||||
}
|
||||
try (InputStream input = getClass().getResourceAsStream("/" + template.getStorageKey());
|
||||
XSSFWorkbook original = new XSSFWorkbook(input)) {
|
||||
if (original.getNumberOfSheets() > 1) {
|
||||
assertArrayEquals(zipPart(getClass().getResourceAsStream("/" + template.getStorageKey()), "xl/worksheets/sheet2.xml"),
|
||||
zipPart(Files.newInputStream(target), "xl/worksheets/sheet2.xml"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void fixedPayeeTemplatesKeepTheirOwnBankDetailsAndSecondSheetWhileFillingOrders() throws Exception {
|
||||
for (String code : List.of(ArBillWorkbookWriters.GUANGZHOU_TEMPLATE_CODE,
|
||||
ArBillWorkbookWriters.JIYUN_TEMPLATE_CODE)) {
|
||||
String suffix = ArBillWorkbookWriters.JIYUN_TEMPLATE_CODE.equals(code) ? "jy" : "gz";
|
||||
ArExportTemplate template = new ArExportTemplate();
|
||||
template.setTemplateCode(code);
|
||||
template.setStorageKey("templates/receivable/ar_bill_template_" + suffix + ".xlsx");
|
||||
DefaultArBillWorkbookWriter writer = new DefaultArBillWorkbookWriter();
|
||||
ArBillDetail success = detail(1, "P1", "1.00");
|
||||
ArBillDetail failed = detail(2, "P2", "2.25");
|
||||
failed.setBillingFailStatus(2);
|
||||
writer.detailMapper = mapper(List.of(success, failed));
|
||||
when(writer.detailMapper.selectReceiveTimeRangeByBillId(7L)).thenReturn(Map.of(
|
||||
"minReceiveTime", Date.valueOf("2026-11-05"), "maxReceiveTime", Date.valueOf("2026-11-05")));
|
||||
writer.detailFeeMapper = mock(ArBillDetailFeeMapper.class);
|
||||
when(writer.detailFeeMapper.selectByDetailIds(anyList())).thenReturn(List.of());
|
||||
ArBill bill = bill(2, "3.25", "CNY");
|
||||
bill.setWrittenOffAmount(BigDecimal.ONE);
|
||||
bill.setUnwrittenAmount(new BigDecimal("2.25"));
|
||||
Path target = temporary.resolve(suffix + ".xlsx");
|
||||
writer.write(bill, template, target);
|
||||
|
||||
try (InputStream input = getClass().getResourceAsStream("/" + template.getStorageKey());
|
||||
XSSFWorkbook original = new XSSFWorkbook(input);
|
||||
XSSFWorkbook exported = new XSSFWorkbook(target.toFile())) {
|
||||
assertEquals(2, exported.getNumberOfSheets());
|
||||
assertEquals("运费", exported.getSheetName(0));
|
||||
assertEquals("汇总表", exported.getSheetName(1));
|
||||
assertEquals(original.getAllPictures().size(), exported.getAllPictures().size());
|
||||
XSSFSheet source = original.getSheetAt(0);
|
||||
XSSFSheet freight = exported.getSheetAt(0);
|
||||
assertEquals(source.getRow(0).getCell(0).getStringCellValue(), freight.getRow(0).getCell(0).getStringCellValue());
|
||||
for (int row = 6; row <= 8; row++) {
|
||||
assertEquals(source.getRow(row).getCell(2).getStringCellValue(),
|
||||
freight.getRow(row + 2).getCell(2).getStringCellValue());
|
||||
}
|
||||
assertEquals("客户 & <测试>", freight.getRow(2).getCell(2).getStringCellValue());
|
||||
assertEquals("2026-11-05 至 2026-11-05", freight.getRow(2).getCell(14).getStringCellValue());
|
||||
assertEquals("ORDER1", freight.getRow(4).getCell(2).getStringCellValue());
|
||||
assertEquals("001234567890123456789", freight.getRow(4).getCell(3).getStringCellValue());
|
||||
assertEquals(1.00, freight.getRow(4).getCell(18).getNumericCellValue(), 0.00001);
|
||||
assertEquals(2.25, freight.getRow(5).getCell(18).getNumericCellValue(), 0.00001);
|
||||
assertEquals("备注 & <快照>", freight.getRow(4).getCell(19).getStringCellValue());
|
||||
assertEquals("销售价未匹配国家", freight.getRow(5).getCell(20).getStringCellValue());
|
||||
assertEquals(IndexedColors.YELLOW.getIndex(), freight.getRow(5).getCell(18).getCellStyle().getFillForegroundColor());
|
||||
assertEquals(0, freight.getRow(6).getPhysicalNumberOfCells());
|
||||
assertEquals("银行信息", freight.getRow(7).getCell(1).getStringCellValue());
|
||||
assertEquals(3.25, freight.getRow(7).getCell(18).getNumericCellValue(), 0.00001);
|
||||
assertEquals(1.00, freight.getRow(8).getCell(18).getNumericCellValue(), 0.00001);
|
||||
assertEquals("S8-S9", freight.getRow(9).getCell(18).getCellFormula());
|
||||
assertEquals(2.25, freight.getRow(9).getCell(18).getNumericCellValue(), 0.00001);
|
||||
assertTrue(freight.getMergedRegions().stream().anyMatch(region -> "C9:E9".equals(region.formatAsString())));
|
||||
}
|
||||
assertArrayEquals(zipPart(getClass().getResourceAsStream("/" + template.getStorageKey()), "xl/worksheets/sheet2.xml"),
|
||||
zipPart(Files.newInputStream(target), "xl/worksheets/sheet2.xml"));
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] zipPart(InputStream input, String path) throws IOException {
|
||||
try (ZipInputStream zip = new ZipInputStream(input)) {
|
||||
for (ZipEntry entry; (entry = zip.getNextEntry()) != null; ) {
|
||||
if (path.equals(entry.getName())) return zip.readAllBytes();
|
||||
}
|
||||
}
|
||||
throw new IOException("Missing ZIP entry: " + path);
|
||||
}
|
||||
|
||||
private SummaryArBillWorkbookWriter summaryWriter(List<ArBillDetail> details) {
|
||||
SummaryArBillWorkbookWriter writer = new SummaryArBillWorkbookWriter();
|
||||
writer.detailMapper = mapper(details);
|
||||
writer.detailFeeMapper = mock(ArBillDetailFeeMapper.class);
|
||||
when(writer.detailFeeMapper.selectByDetailIds(anyList())).thenReturn(List.of());
|
||||
return writer;
|
||||
}
|
||||
|
||||
private ArBillDetailMapper mapper(List<ArBillDetail> rows) {
|
||||
ArBillDetailMapper mapper = mock(ArBillDetailMapper.class);
|
||||
when(mapper.selectExportPage(eq(7L), anyInt(), eq(2000))).thenAnswer(invocation -> {
|
||||
int previous = invocation.getArgument(1);
|
||||
return rows.stream().filter(row -> row.getDetailNo() > previous).limit(2000).toList();
|
||||
});
|
||||
return mapper;
|
||||
}
|
||||
|
||||
private ArExportTemplate summaryTemplate() {
|
||||
ArExportTemplate template = new ArExportTemplate();
|
||||
template.setTemplateCode("AR_BILL_SUMMARY");
|
||||
template.setStorageKey("templates/receivable/ar_bill_template_summary.xlsx");
|
||||
return template;
|
||||
}
|
||||
|
||||
private ArBill bill(int count, String amount, String currency) {
|
||||
ArBill bill = new ArBill();
|
||||
bill.setArBillId(7L);
|
||||
bill.setCustomerCode("0000123");
|
||||
bill.setCustomerName("客户 & <测试>");
|
||||
bill.setCurrency(currency);
|
||||
bill.setBillPeriodStart(Date.valueOf("2026-10-01"));
|
||||
bill.setBillPeriodEnd(Date.valueOf("2026-10-31"));
|
||||
bill.setOrderCount(count);
|
||||
bill.setTotalAmount(new BigDecimal(amount));
|
||||
bill.setWrittenOffAmount(BigDecimal.ZERO);
|
||||
bill.setUnwrittenAmount(new BigDecimal(amount));
|
||||
bill.setBankAccountName("收款账户快照");
|
||||
bill.setBankAccountNo("1234567890");
|
||||
bill.setBankName("开户行快照");
|
||||
return bill;
|
||||
}
|
||||
|
||||
private ArBillDetail detail(int number, String productCode, String amount) {
|
||||
ArBillDetail detail = new ArBillDetail();
|
||||
detail.setDetailId((long) number);
|
||||
detail.setDetailNo(number);
|
||||
detail.setOrderNo("ORDER" + number);
|
||||
detail.setTransferNo(String.format("%08d", number));
|
||||
detail.setTrackingNo("001234567890123456789");
|
||||
detail.setProductCode(productCode);
|
||||
detail.setProductName(productCode);
|
||||
detail.setReceiveTime(Date.valueOf("2026-11-05"));
|
||||
detail.setCountryName("德国");
|
||||
detail.setDestPostcode("00123");
|
||||
detail.setReceiveWeight(new BigDecimal("9.5"));
|
||||
detail.setActualWeight(new BigDecimal("8.5"));
|
||||
detail.setChargeWeight(new BigDecimal("1.125"));
|
||||
detail.setFreightRate(new BigDecimal("2.5"));
|
||||
// 公式导出要求费用组成与账单快照一致,保留运费样例,其余金额作为操作费。
|
||||
BigDecimal freight = detail.getChargeWeight().multiply(detail.getFreightRate()).setScale(2, RoundingMode.HALF_UP);
|
||||
detail.setRegistrationFee(new BigDecimal(amount).subtract(freight));
|
||||
detail.setTotalAmount(new BigDecimal(amount));
|
||||
detail.setCurrency("CNY");
|
||||
detail.setRemark("备注 & <快照>");
|
||||
return detail;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
package com.bms.report;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import org.apache.ibatis.builder.xml.XMLMapperBuilder;
|
||||
import org.apache.ibatis.session.Configuration;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import com.bms.price.domain.PrcProfitReportExport;
|
||||
import com.bms.price.domain.vo.PrcProfitReportOrderRow;
|
||||
import com.bms.price.domain.vo.PrcProfitReportProductRow;
|
||||
import com.bms.price.domain.vo.PrcProfitReportQuery;
|
||||
import com.bms.price.domain.vo.PrcProfitReportSummary;
|
||||
import com.bms.price.mapper.PrcProfitReportMapper;
|
||||
import com.bms.price.service.impl.PrcProfitReportServiceImpl;
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
|
||||
class ProfitReportAreaFilterTest
|
||||
{
|
||||
@AfterEach
|
||||
void clearPage()
|
||||
{
|
||||
PageHelper.clearPage();
|
||||
}
|
||||
|
||||
@Test
|
||||
void customerLookupPreservesPaginationAndUsesOnlyServerResolvedIds()
|
||||
{
|
||||
AtomicReference<List<Long>> ids = new AtomicReference<>(List.of(2L, 3L));
|
||||
AtomicReference<PrcProfitReportQuery> seen = new AtomicReference<>();
|
||||
Page<?> page = PageHelper.startPage(2, 10);
|
||||
PrcProfitReportMapper mapper = mapper(ids, seen, page);
|
||||
PrcProfitReportServiceImpl service = service(mapper, true, 2);
|
||||
PrcProfitReportQuery query = new PrcProfitReportQuery();
|
||||
query.setCustomerArea(" C ");
|
||||
query.setAreaCustomerIds(List.of(999L));
|
||||
|
||||
service.selectOrderRows(query);
|
||||
assertSame(query, seen.get());
|
||||
assertEquals(List.of(2L, 3L), query.getAreaCustomerIds());
|
||||
assertSame(page, PageHelper.getLocalPage());
|
||||
|
||||
ids.set(List.of());
|
||||
service.selectSummary(query);
|
||||
assertEquals(List.of(), query.getAreaCustomerIds());
|
||||
|
||||
ids.set(List.of(1L, 2L, 3L));
|
||||
service.selectProductRows(query);
|
||||
assertNull(query.getAreaCustomerIds());
|
||||
}
|
||||
|
||||
@Test
|
||||
void customerLookupFailureClearsPageContext()
|
||||
{
|
||||
PrcProfitReportMapper mapper = (PrcProfitReportMapper) Proxy.newProxyInstance(
|
||||
getClass().getClassLoader(), new Class<?>[] { PrcProfitReportMapper.class },
|
||||
(proxy, method, args) -> { throw new IllegalStateException("lookup failed"); });
|
||||
PrcProfitReportServiceImpl service = service(mapper, true, 2);
|
||||
PrcProfitReportQuery query = new PrcProfitReportQuery();
|
||||
query.setCustomerArea("C");
|
||||
PageHelper.startPage(1, 10);
|
||||
assertThrows(IllegalStateException.class, () -> service.selectOrderRows(query));
|
||||
assertNull(PageHelper.getLocalPage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void sqlUsesAreaJoinOrCustomerIdsAndEmptyIdsMatchNothing() throws Exception
|
||||
{
|
||||
Configuration config = new Configuration();
|
||||
for (Class<?> type : new Class<?>[] { PrcProfitReportExport.class, PrcProfitReportOrderRow.class,
|
||||
PrcProfitReportProductRow.class, PrcProfitReportSummary.class })
|
||||
{
|
||||
config.getTypeAliasRegistry().registerAlias(type);
|
||||
}
|
||||
String resource = "mapper/price/PrcProfitReportMapper.xml";
|
||||
try (InputStream input = getClass().getClassLoader().getResourceAsStream(resource))
|
||||
{
|
||||
assertNotNull(input);
|
||||
new XMLMapperBuilder(input, config, resource, config.getSqlFragments()).parse();
|
||||
}
|
||||
PrcProfitReportQuery query = new PrcProfitReportQuery();
|
||||
query.setCustomerArea("C");
|
||||
for (String id : List.of("selectOrderRows", "selectProductRows", "selectSummary"))
|
||||
{
|
||||
var statement = config.getMappedStatement("com.bms.price.mapper.PrcProfitReportMapper." + id);
|
||||
query.setAreaCustomerIds(null);
|
||||
String joinSql = statement.getBoundSql(query).getSql();
|
||||
assertTrue(joinSql.contains("join ctr_customer c"));
|
||||
assertTrue(joinSql.contains("c.customer_area = ?"));
|
||||
assertTrue(joinSql.contains("c.del_flag = '0'"));
|
||||
|
||||
query.setAreaCustomerIds(List.of(2L, 3L));
|
||||
String inSql = statement.getBoundSql(query).getSql();
|
||||
assertFalse(inSql.contains("join ctr_customer c"));
|
||||
assertTrue(inSql.contains("p.customer_id in"));
|
||||
|
||||
query.setAreaCustomerIds(List.of());
|
||||
String emptySql = statement.getBoundSql(query).getSql();
|
||||
assertFalse(emptySql.contains("join ctr_customer c"));
|
||||
assertTrue(emptySql.contains("and 1 = 0"));
|
||||
|
||||
query.setAreaCustomerIds(null);
|
||||
query.setProductKeyword("EXP");
|
||||
String productSql = statement.getBoundSql(query).getSql();
|
||||
assertTrue(productSql.contains("p.product_code like concat('%', ?, '%')"));
|
||||
assertTrue(productSql.contains("p.product_name like concat('%', ?, '%')"));
|
||||
}
|
||||
}
|
||||
|
||||
private PrcProfitReportServiceImpl service(PrcProfitReportMapper mapper, boolean enabled, int max)
|
||||
{
|
||||
PrcProfitReportServiceImpl service = new PrcProfitReportServiceImpl();
|
||||
ReflectionTestUtils.setField(service, "profitReportMapper", mapper);
|
||||
ReflectionTestUtils.setField(service, "customerIdFilterEnabled", enabled);
|
||||
ReflectionTestUtils.setField(service, "maxCustomerIds", max);
|
||||
return service;
|
||||
}
|
||||
|
||||
private PrcProfitReportMapper mapper(AtomicReference<List<Long>> ids,
|
||||
AtomicReference<PrcProfitReportQuery> seen, Page<?> page)
|
||||
{
|
||||
return (PrcProfitReportMapper) Proxy.newProxyInstance(getClass().getClassLoader(),
|
||||
new Class<?>[] { PrcProfitReportMapper.class }, (proxy, method, args) -> {
|
||||
if (method.getName().equals("selectAreaCustomerIds"))
|
||||
{
|
||||
assertNull(PageHelper.getLocalPage());
|
||||
assertEquals("C", args[0]);
|
||||
assertEquals(3, args[1]);
|
||||
return ids.get();
|
||||
}
|
||||
assertSame(page, PageHelper.getLocalPage());
|
||||
seen.set((PrcProfitReportQuery) args[0]);
|
||||
return List.of();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,324 @@
|
||||
package com.bms.report;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.math.BigDecimal;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.attribute.FileTime;
|
||||
import java.time.Instant;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TimeZone;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Function;
|
||||
import java.util.zip.ZipFile;
|
||||
import javax.xml.stream.XMLInputFactory;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.ss.usermodel.WorkbookFactory;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.springframework.core.task.TaskRejectedException;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import com.bms.common.config.BmsConfig;
|
||||
import com.bms.common.core.redis.RedisCache;
|
||||
import com.bms.common.exception.ServiceException;
|
||||
import com.bms.common.utils.poi.ExcelUtil;
|
||||
import com.bms.price.domain.PrcProfitReportExportTask;
|
||||
import com.bms.price.domain.vo.PrcProfitReportOrderRow;
|
||||
import com.bms.price.domain.vo.PrcProfitReportQuery;
|
||||
import com.bms.price.enums.ProfitAreaRule;
|
||||
import com.bms.price.service.IPrcProfitReportService;
|
||||
import com.bms.price.task.PrcProfitReportExportRunner;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
|
||||
class ProfitReportAsyncExportTest
|
||||
{
|
||||
@TempDir
|
||||
Path tempDir;
|
||||
private String previousProfile;
|
||||
|
||||
@BeforeEach
|
||||
void useTempProfile()
|
||||
{
|
||||
previousProfile = BmsConfig.getProfile();
|
||||
new BmsConfig().setProfile(tempDir.toString());
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void restoreProfile()
|
||||
{
|
||||
new BmsConfig().setProfile(previousProfile);
|
||||
PageHelper.clearPage();
|
||||
}
|
||||
|
||||
@Test
|
||||
void submissionQueuesWorkAndExportsAllRowsUsingTheSubmittedFiltersAndRegionColumns() throws Exception
|
||||
{
|
||||
for (String area : List.of("C", "GZ"))
|
||||
{
|
||||
AtomicInteger calls = new AtomicInteger();
|
||||
HoldingExecutor executor = new HoldingExecutor();
|
||||
PrcProfitReportExportRunner runner = new PrcProfitReportExportRunner(service(query -> {
|
||||
calls.incrementAndGet();
|
||||
assertNull(PageHelper.getLocalPage());
|
||||
assertEquals(area, query.getCustomerArea());
|
||||
assertEquals("UNBILLED", query.getArBillStatus());
|
||||
assertEquals("P1", query.getProductCode());
|
||||
query.setProfitRule(ProfitAreaRule.fromCustomerArea(area).name());
|
||||
return List.of(row("ORDER-A"), row("ORDER-B"));
|
||||
}), new MemoryRedis(), executor);
|
||||
PrcProfitReportQuery query = query(area);
|
||||
query.setProductCode("P1");
|
||||
String taskId = runner.submit(query, 1L);
|
||||
|
||||
assertEquals(0, calls.get());
|
||||
assertEquals("PENDING", runner.getTask(taskId, 1L).getStatus());
|
||||
assertThrows(ServiceException.class, () -> runner.download(taskId, 1L, new MockHttpServletResponse()));
|
||||
query.setProductCode("CHANGED-AFTER-SUBMIT");
|
||||
PageHelper.startPage(2, 1);
|
||||
executor.work.run();
|
||||
|
||||
PrcProfitReportExportTask task = runner.getTask(taskId, 1L);
|
||||
assertEquals("SUCCESS", task.getStatus());
|
||||
assertEquals(100, task.getPercent());
|
||||
assertEquals(2, task.getRowCount());
|
||||
assertEquals(1, calls.get());
|
||||
assertNull(PageHelper.getLocalPage());
|
||||
assertThrows(ServiceException.class, () -> runner.getTask(taskId, 2L));
|
||||
assertThrows(ServiceException.class, () -> runner.download(taskId, 2L, new MockHttpServletResponse()));
|
||||
Path file = tempDir.resolve("download").resolve(task.getStorageKey());
|
||||
try (InputStream input = Files.newInputStream(file); Workbook workbook = WorkbookFactory.create(input))
|
||||
{
|
||||
var sheet = workbook.getSheetAt(0);
|
||||
assertEquals(2, sheet.getLastRowNum());
|
||||
Row header = sheet.getRow(0);
|
||||
assertEquals(area.equals("C"), hasColumn(header, "产品价(目录价)"));
|
||||
assertEquals(area.equals("C"), hasColumn(header, "红线毛利"));
|
||||
assertTrue(hasColumn(header, "销售价"));
|
||||
}
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
runner.download(taskId, 1L, response);
|
||||
assertArrayEquals(Files.readAllBytes(file), response.getContentAsByteArray());
|
||||
assertTrue(response.getHeader("Content-Disposition").contains(".xlsx"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectedExecutionAndQueryFailuresBecomeVisibleFailedTasks() throws Exception
|
||||
{
|
||||
ThreadPoolTaskExecutor rejected = new ThreadPoolTaskExecutor() {
|
||||
@Override
|
||||
public void execute(Runnable task) { throw new TaskRejectedException("busy"); }
|
||||
};
|
||||
PrcProfitReportExportRunner runner = new PrcProfitReportExportRunner(service(query -> {
|
||||
fail("Rejected tasks must not query orders");
|
||||
return List.of();
|
||||
}), new MemoryRedis(), rejected);
|
||||
String rejectedId = runner.submit(query("C"), 1L);
|
||||
assertEquals("FAIL", runner.getTask(rejectedId, 1L).getStatus());
|
||||
assertEquals("导出任务较多,请稍后重试", runner.getTask(rejectedId, 1L).getError());
|
||||
|
||||
HoldingExecutor executor = new HoldingExecutor();
|
||||
PrcProfitReportExportRunner failing = new PrcProfitReportExportRunner(service(query -> {
|
||||
throw new ServiceException("该客户区域未配置毛利规则");
|
||||
}), new MemoryRedis(), executor);
|
||||
String failedId = failing.submit(query("INVALID"), 1L);
|
||||
executor.work.run();
|
||||
PrcProfitReportExportTask failed = failing.getTask(failedId, 1L);
|
||||
assertEquals("FAIL", failed.getStatus());
|
||||
assertEquals("该客户区域未配置毛利规则", failed.getError());
|
||||
assertNull(failed.getStorageKey());
|
||||
assertThrows(ServiceException.class, () -> failing.download(failedId, 1L, new MockHttpServletResponse()));
|
||||
assertFalse(Files.exists(tempDir.resolve("download/profitReportExport/" + failedId + ".xlsx")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void exportsMoreThanLegacySheetLimitIntoOneSheet() throws Exception
|
||||
{
|
||||
int rowCount = ExcelUtil.sheetSize + 1;
|
||||
List<PrcProfitReportOrderRow> rows = Collections.nCopies(rowCount, row("ORDER-LARGE"));
|
||||
HoldingExecutor executor = new HoldingExecutor();
|
||||
PrcProfitReportExportRunner runner = new PrcProfitReportExportRunner(service(query -> rows),
|
||||
new MemoryRedis(), executor);
|
||||
String taskId = runner.submit(query("C"), 1L);
|
||||
executor.work.run();
|
||||
|
||||
PrcProfitReportExportTask task = runner.getTask(taskId, 1L);
|
||||
assertEquals("SUCCESS", task.getStatus());
|
||||
assertEquals(rowCount, task.getRowCount());
|
||||
Path file = tempDir.resolve("download").resolve(task.getStorageKey());
|
||||
assertEquals(1, countWorkbookSheets(file));
|
||||
assertEquals(rowCount + 1, lastWorksheetRowNumber(file));
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsRowsBeyondTheSingleSheetLimit()
|
||||
{
|
||||
List<PrcProfitReportOrderRow> rows = Collections.nCopies(ExcelUtil.XLSX_MAX_ROW_COUNT, row("ORDER-LARGE"));
|
||||
HoldingExecutor executor = new HoldingExecutor();
|
||||
PrcProfitReportExportRunner runner = new PrcProfitReportExportRunner(service(query -> rows),
|
||||
new MemoryRedis(), executor);
|
||||
String taskId = runner.submit(query("C"), 1L);
|
||||
executor.work.run();
|
||||
|
||||
PrcProfitReportExportTask task = runner.getTask(taskId, 1L);
|
||||
assertEquals("FAIL", task.getStatus());
|
||||
assertTrue(task.getError().contains("单个工作表最多支持1048575条订单"));
|
||||
assertFalse(Files.exists(tempDir.resolve("download/profitReportExport/" + taskId + ".xlsx")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void cleanupRemovesOnlyExpiredExportFiles() throws Exception
|
||||
{
|
||||
Path dir = Files.createDirectories(tempDir.resolve("download/profitReportExport"));
|
||||
Path old = Files.writeString(dir.resolve("a".repeat(32) + ".xlsx"), "old");
|
||||
Path recent = Files.writeString(dir.resolve("b".repeat(32) + ".xlsx"), "new");
|
||||
Path other = Files.writeString(dir.resolve("unrelated.xlsx"), "other");
|
||||
FileTime expired = FileTime.from(Instant.now().minusSeconds(TimeUnit.HOURS.toSeconds(25)));
|
||||
Files.setLastModifiedTime(old, expired);
|
||||
Files.setLastModifiedTime(other, expired);
|
||||
PrcProfitReportExportRunner runner = new PrcProfitReportExportRunner(service(query -> List.of()),
|
||||
new MemoryRedis(), new HoldingExecutor());
|
||||
runner.cleanupExpiredFiles();
|
||||
assertFalse(Files.exists(old));
|
||||
assertTrue(Files.exists(recent));
|
||||
assertTrue(Files.exists(other));
|
||||
}
|
||||
|
||||
@Test
|
||||
void jsonSubmissionRetainsTheListDateRangeAndFilters() throws Exception
|
||||
{
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.setTimeZone(TimeZone.getTimeZone("GMT+8"));
|
||||
PrcProfitReportQuery query = mapper.readValue("""
|
||||
{"customerArea":"C", "beginBizDate":"2026-10-18 00:00:00",
|
||||
"endBizDate":"2026-11-17 23:59:59", "arBillStatus":"UNBILLED", "orderNo":"A\\nB"}
|
||||
""", PrcProfitReportQuery.class);
|
||||
assertEquals(Instant.parse("2026-10-17T16:00:00Z"), query.getBeginBizDate().toInstant());
|
||||
assertEquals(Instant.parse("2026-11-17T15:59:59Z"), query.getEndBizDate().toInstant());
|
||||
assertEquals("A\nB", query.getOrderNo());
|
||||
assertEquals("UNBILLED", query.getArBillStatus());
|
||||
}
|
||||
|
||||
private static PrcProfitReportQuery query(String area)
|
||||
{
|
||||
PrcProfitReportQuery query = new PrcProfitReportQuery();
|
||||
query.setCustomerArea(area);
|
||||
query.setArBillStatus("UNBILLED");
|
||||
return query;
|
||||
}
|
||||
|
||||
private static PrcProfitReportOrderRow row(String orderNo)
|
||||
{
|
||||
PrcProfitReportOrderRow row = new PrcProfitReportOrderRow();
|
||||
row.setOrderNo(orderNo);
|
||||
row.setSalesAmount(new BigDecimal("26.60"));
|
||||
row.setArBillStatus("UNBILLED");
|
||||
return row;
|
||||
}
|
||||
|
||||
private static boolean hasColumn(Row header, String name)
|
||||
{
|
||||
for (var cell : header) if (name.equals(cell.getStringCellValue())) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private static int countWorkbookSheets(Path file) throws Exception
|
||||
{
|
||||
try (ZipFile workbook = new ZipFile(file.toFile());
|
||||
InputStream input = workbook.getInputStream(workbook.getEntry("xl/workbook.xml")))
|
||||
{
|
||||
XMLStreamReader reader = xmlInputFactory().createXMLStreamReader(input);
|
||||
int count = 0;
|
||||
try
|
||||
{
|
||||
while (reader.hasNext())
|
||||
{
|
||||
if (reader.next() == XMLStreamReader.START_ELEMENT && "sheet".equals(reader.getLocalName()))
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
reader.close();
|
||||
}
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
private static int lastWorksheetRowNumber(Path file) throws Exception
|
||||
{
|
||||
try (ZipFile workbook = new ZipFile(file.toFile());
|
||||
InputStream input = workbook.getInputStream(workbook.getEntry("xl/worksheets/sheet1.xml")))
|
||||
{
|
||||
XMLStreamReader reader = xmlInputFactory().createXMLStreamReader(input);
|
||||
int lastRowNumber = 0;
|
||||
try
|
||||
{
|
||||
while (reader.hasNext())
|
||||
{
|
||||
if (reader.next() == XMLStreamReader.START_ELEMENT && "row".equals(reader.getLocalName()))
|
||||
{
|
||||
lastRowNumber = Integer.parseInt(reader.getAttributeValue(null, "r"));
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
reader.close();
|
||||
}
|
||||
return lastRowNumber;
|
||||
}
|
||||
}
|
||||
|
||||
private static XMLInputFactory xmlInputFactory()
|
||||
{
|
||||
XMLInputFactory factory = XMLInputFactory.newFactory();
|
||||
factory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
|
||||
factory.setProperty("javax.xml.stream.isSupportingExternalEntities", false);
|
||||
return factory;
|
||||
}
|
||||
|
||||
private static IPrcProfitReportService service(Function<PrcProfitReportQuery, List<PrcProfitReportOrderRow>> query)
|
||||
{
|
||||
return (IPrcProfitReportService) Proxy.newProxyInstance(ProfitReportAsyncExportTest.class.getClassLoader(),
|
||||
new Class<?>[] { IPrcProfitReportService.class }, (proxy, method, args) -> {
|
||||
if ("selectOrderRows".equals(method.getName())) return query.apply((PrcProfitReportQuery) args[0]);
|
||||
throw new AssertionError("Unexpected service call: " + method.getName());
|
||||
});
|
||||
}
|
||||
|
||||
private static class HoldingExecutor extends ThreadPoolTaskExecutor
|
||||
{
|
||||
private Runnable work;
|
||||
@Override
|
||||
public void execute(Runnable task) { work = task; }
|
||||
}
|
||||
|
||||
private static class MemoryRedis extends RedisCache
|
||||
{
|
||||
private final Map<String, Object> values = new HashMap<>();
|
||||
@Override
|
||||
public <T> void setCacheObject(String key, T value, Integer timeout, TimeUnit unit)
|
||||
{
|
||||
values.put(key, value);
|
||||
}
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T getCacheObject(String key) { return (T) values.get(key); }
|
||||
}
|
||||
}
|
||||
@@ -151,7 +151,7 @@ public class LoginUser implements UserDetails
|
||||
@Override
|
||||
public String getUsername()
|
||||
{
|
||||
return user.getUserName();
|
||||
return user == null ? null : user.getUserName();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -44,7 +44,7 @@ public enum PaymentMesEnum
|
||||
BMS_PAY_PICK_CH("BMS_PAY_PICK_CH", "渠道绑定产品", "请先勾选渠道"),
|
||||
BMS_PAY_PICK_SIDE("BMS_PAY_PICK_SIDE", "渠道绑定产品", "请至少选择应付或应收产品"),
|
||||
BMS_PAY_BIND_NONE("BMS_PAY_BIND_NONE", "渠道绑定产品", "没有可绑定的渠道"),
|
||||
BMS_PAY_CH_PROD("BMS_PAY_CH_PROD", "渠道应付产品", "渠道还没有选择应付产品"),
|
||||
BMS_PAY_CH_PROD("BMS_PAY_CH_PROD", "渠道应付价卡", "渠道还没有选择应付价卡"),
|
||||
BMS_PAY_OUT_TERM("BMS_PAY_OUT_TERM", "应付价格有效期", "订单时间没有落在价格有效期内"),
|
||||
BMS_PAY_TWO_VER("BMS_PAY_TWO_VER", "应付价格对比", "请选择两个价格版本"),
|
||||
BMS_PAY_AR_AP("BMS_PAY_AR_AP", "收付类型", "收付类型只能是应收AR或应付AP"),
|
||||
|
||||
@@ -170,7 +170,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
|
||||
/**
|
||||
* 规范化目的地邮编,用于分区匹配/持久化。
|
||||
* 移除所有 Unicode 空白字符(包括 NBSP / U+2005)和 ASCII 空格;
|
||||
* 仅去掉两端 Unicode 空白(含 NBSP / U+2005),保留中间空格;
|
||||
* 去除纯数字末尾 Excel 风格的 ".0"。
|
||||
*/
|
||||
public static String normalizePostcode(String postcode)
|
||||
@@ -179,17 +179,27 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
{
|
||||
return postcode;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder(postcode.length());
|
||||
for (int i = 0; i < postcode.length(); )
|
||||
int startIdx = 0;
|
||||
int endIdx = postcode.length();
|
||||
while (startIdx < endIdx)
|
||||
{
|
||||
int cp = postcode.codePointAt(i);
|
||||
int cp = postcode.codePointAt(startIdx);
|
||||
if (!Character.isWhitespace(cp))
|
||||
{
|
||||
sb.appendCodePoint(cp);
|
||||
break;
|
||||
}
|
||||
i += Character.charCount(cp);
|
||||
startIdx += Character.charCount(cp);
|
||||
}
|
||||
String n = sb.toString();
|
||||
while (endIdx > startIdx)
|
||||
{
|
||||
int cp = postcode.codePointBefore(endIdx);
|
||||
if (!Character.isWhitespace(cp))
|
||||
{
|
||||
break;
|
||||
}
|
||||
endIdx -= Character.charCount(cp);
|
||||
}
|
||||
String n = postcode.substring(startIdx, endIdx);
|
||||
if (n.endsWith(".0") && n.matches("\\d+\\.0"))
|
||||
{
|
||||
return n.substring(0, n.length() - 2);
|
||||
|
||||
@@ -111,11 +111,12 @@ public class ExcelUtil<T>
|
||||
*/
|
||||
private Map<String, CellStyle> cellStyleCache = new HashMap<String, CellStyle>();
|
||||
|
||||
/**
|
||||
* Excel sheet最大行数,默认65536
|
||||
*/
|
||||
/** 通用导出的默认每个工作表数据行数;单工作表 XLSX 导出使用 XLSX 实际上限。 */
|
||||
public static final int sheetSize = 65536;
|
||||
|
||||
/** XLSX 工作表的最大行数。 */
|
||||
public static final int XLSX_MAX_ROW_COUNT = 1_048_576;
|
||||
|
||||
/**
|
||||
* 工作表名称
|
||||
*/
|
||||
@@ -796,6 +797,28 @@ public class ExcelUtil<T>
|
||||
}
|
||||
}
|
||||
|
||||
/** 写入单个 XLSX 工作表;超出 Excel 行数上限时返回明确错误。 */
|
||||
public void exportExcelToSingleSheetStream(List<T> list, String sheetName, OutputStream output) throws IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
this.init(list, sheetName, StringUtils.EMPTY, Type.EXPORT);
|
||||
int reservedRows = rownum + 1 + (hasStatisticsColumns() ? 1 : 0);
|
||||
int maxDataRows = XLSX_MAX_ROW_COUNT - reservedRows;
|
||||
if (this.list.size() > maxDataRows)
|
||||
{
|
||||
throw new IOException(StringUtils.format("单个工作表最多支持{}条数据,当前{}条,请缩小查询范围",
|
||||
maxDataRows, this.list.size()));
|
||||
}
|
||||
writeSheet(maxDataRows);
|
||||
wb.write(output);
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtils.closeQuietly(wb);
|
||||
}
|
||||
}
|
||||
|
||||
/** 对 list 数据源生成本地 Excel 文件,返回文件名。 */
|
||||
public AjaxResult exportExcel()
|
||||
{
|
||||
@@ -824,9 +847,14 @@ public class ExcelUtil<T>
|
||||
* 创建写入数据到Sheet
|
||||
*/
|
||||
public void writeSheet()
|
||||
{
|
||||
writeSheet(sheetSize);
|
||||
}
|
||||
|
||||
private void writeSheet(int rowsPerSheet)
|
||||
{
|
||||
// 取出一共有多少个sheet.
|
||||
int sheetNo = Math.max(1, (int) Math.ceil(list.size() * 1.0 / sheetSize));
|
||||
int sheetNo = Math.max(1, (int) Math.ceil(list.size() * 1.0 / rowsPerSheet));
|
||||
for (int index = 0; index < sheetNo; index++)
|
||||
{
|
||||
createSheet(sheetNo, index);
|
||||
@@ -855,7 +883,7 @@ public class ExcelUtil<T>
|
||||
}
|
||||
if (Type.EXPORT.equals(type))
|
||||
{
|
||||
fillExcelData(index);
|
||||
fillExcelData(index, rowsPerSheet);
|
||||
addStatisticsRow();
|
||||
}
|
||||
}
|
||||
@@ -869,8 +897,13 @@ public class ExcelUtil<T>
|
||||
@SuppressWarnings("unchecked")
|
||||
public void fillExcelData(int index)
|
||||
{
|
||||
int startNo = index * sheetSize;
|
||||
int endNo = Math.min(startNo + sheetSize, list.size());
|
||||
fillExcelData(index, sheetSize);
|
||||
}
|
||||
|
||||
private void fillExcelData(int index, int rowsPerSheet)
|
||||
{
|
||||
int startNo = index * rowsPerSheet;
|
||||
int endNo = Math.min(startNo + rowsPerSheet, list.size());
|
||||
int currentRowNum = rownum + 1; // 从标题行后开始
|
||||
|
||||
for (int i = startNo; i < endNo; i++)
|
||||
@@ -931,6 +964,18 @@ public class ExcelUtil<T>
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasStatisticsColumns()
|
||||
{
|
||||
for (Object[] field : fields)
|
||||
{
|
||||
if (((Excel) field[1]).isStatistics())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取子列表最大数
|
||||
*/
|
||||
|
||||
+4
@@ -136,6 +136,10 @@ public class BmsSupplier extends BaseEntity
|
||||
@Excel(name = "合作状态", readConverterExp = "0=正常,1=暂停,2=终止")
|
||||
private String cooperationStatus;
|
||||
|
||||
/** 数据来源,字典 bms_supplier_data_source。空表示未填写 */
|
||||
@Excel(name = "数据来源", dictType = "bms_supplier_data_source")
|
||||
private String dataSource;
|
||||
|
||||
/** 绑定的渠道/服务ID */
|
||||
private String channelIds;
|
||||
|
||||
|
||||
+3
@@ -26,6 +26,9 @@ public interface BmsSupplierMapper
|
||||
/** 修改供应商 */
|
||||
public int updateBmsSupplier(BmsSupplier bmsSupplier);
|
||||
|
||||
/** 只更新供应商绑定的渠道编码。 */
|
||||
public int updateSupplierChannels(BmsSupplier bmsSupplier);
|
||||
|
||||
/** 删除供应商 */
|
||||
public int deleteBmsSupplierBySupplierId(Long supplierId);
|
||||
|
||||
|
||||
+3
@@ -26,6 +26,9 @@ public interface IBmsSupplierService
|
||||
/** 修改供应商 */
|
||||
public int updateBmsSupplier(BmsSupplier bmsSupplier);
|
||||
|
||||
/** 只改这一家供应商绑定的渠道,其它资料不动。 */
|
||||
public int bindChannels(Long supplierId, String channelIds);
|
||||
|
||||
/** 批量删除供应商 */
|
||||
public int deleteBmsSupplierBySupplierIds(Long[] supplierIds);
|
||||
|
||||
|
||||
+56
@@ -1,6 +1,7 @@
|
||||
package com.bms.customer.supplierinfo.service.impl;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
|
||||
import com.bms.common.annotation.DataScope;
|
||||
@@ -302,6 +303,61 @@ public class BmsSupplierServiceImpl implements IBmsSupplierService
|
||||
return bmsSupplierMapper.updateBmsSupplier(bmsSupplier);
|
||||
}
|
||||
|
||||
/**
|
||||
* 只改绑定渠道。不走整单修改,避免把附件、采购员和合同日期清掉。
|
||||
*/
|
||||
@Override
|
||||
public int bindChannels(Long supplierId, String channelIds)
|
||||
{
|
||||
if (supplierId == null)
|
||||
{
|
||||
throw new ServiceException("请选择供应商");
|
||||
}
|
||||
if (bmsSupplierMapper.selectBmsSupplierBySupplierId(supplierId) == null)
|
||||
{
|
||||
throw new ServiceException("供应商不存在");
|
||||
}
|
||||
String value = joinChannels(channelIds);
|
||||
if (value.length() > 1000)
|
||||
{
|
||||
throw new ServiceException("绑定的渠道过多,请减少后再保存");
|
||||
}
|
||||
BmsSupplier row = new BmsSupplier();
|
||||
row.setSupplierId(supplierId);
|
||||
row.setChannelIds(value);
|
||||
row.setUpdateBy(SecurityUtils.getUsername());
|
||||
row.setUpdateTime(DateUtils.getNowDate());
|
||||
int rows = bmsSupplierMapper.updateSupplierChannels(row);
|
||||
if (rows == 0)
|
||||
{
|
||||
throw new ServiceException("供应商不存在");
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
/** 渠道编码去空白、去重,仍按选择顺序用逗号拼起来。 */
|
||||
private static String joinChannels(String channelIds)
|
||||
{
|
||||
if (StringUtils.isEmpty(channelIds))
|
||||
{
|
||||
return "";
|
||||
}
|
||||
LinkedHashSet<String> codes = new LinkedHashSet<>();
|
||||
for (String part : channelIds.split(","))
|
||||
{
|
||||
if (part == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
String code = part.trim();
|
||||
if (!code.isEmpty())
|
||||
{
|
||||
codes.add(code);
|
||||
}
|
||||
}
|
||||
return String.join(",", codes);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public int deleteBmsSupplierBySupplierIds(Long[] supplierIds)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.bms.price.airbill.domain;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import lombok.Data;
|
||||
|
||||
/** 待分摊的一条提单费用,供费用处理弹框展示。 */
|
||||
@@ -20,12 +21,18 @@ public class SrvBillAirAllocFee
|
||||
/** 费用状态,字典 bill_fee_status */
|
||||
private String billFeeStatus;
|
||||
|
||||
/** 费用类型,字典 bms_fee_type 的英文编码 */
|
||||
private String feeType;
|
||||
|
||||
private String feeName;
|
||||
|
||||
private BigDecimal price;
|
||||
|
||||
private String currency;
|
||||
|
||||
/** 费用录入时间,用来取汇率 */
|
||||
private Date createTime;
|
||||
|
||||
/** 分摊维度:1订单 2重量 */
|
||||
private String allocDim;
|
||||
|
||||
|
||||
@@ -15,9 +15,12 @@ public class SrvBillAirFee
|
||||
|
||||
private String billCode;
|
||||
|
||||
/** 附加费编号 prc_surcharge.sc_id */
|
||||
/** 费用类型,字典 bms_fee_type 的英文编码 */
|
||||
private String feeType;
|
||||
|
||||
/** 附加费配置ID,对应 prc_surcharge.sc_id */
|
||||
private Long scId;
|
||||
|
||||
/** 附加费名称,仅展示,不入库 */
|
||||
private String feeName;
|
||||
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.bms.price.config;
|
||||
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
|
||||
/** 毛利分析导出专用线程池,限制全量订单查询与 Excel 生成的并发。 */
|
||||
@Configuration
|
||||
public class ProfitReportExportTaskConfig
|
||||
{
|
||||
@Bean(name = "profitReportExportTaskExecutor")
|
||||
public ThreadPoolTaskExecutor profitReportExportTaskExecutor()
|
||||
{
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
executor.setCorePoolSize(1);
|
||||
executor.setMaxPoolSize(1);
|
||||
executor.setQueueCapacity(2);
|
||||
executor.setThreadNamePrefix("profit-report-export-");
|
||||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());
|
||||
return executor;
|
||||
}
|
||||
}
|
||||
@@ -105,6 +105,9 @@ public class LblProduct extends BaseEntity
|
||||
|
||||
private List<LblExtraLine> extraLines;
|
||||
|
||||
/** 邮编→分区(保存时同步到 prc_zone,不落产品子表) */
|
||||
/** 邮编→分区(保存时按产品同步到 prc_zone LABEL,不落产品子表) */
|
||||
private Map<String, List<String>> zonePostcodes;
|
||||
|
||||
/** 编辑保存删除标记(不落库) */
|
||||
private Boolean deleted;
|
||||
}
|
||||
@@ -59,4 +59,7 @@ public class LblSurcharge
|
||||
private BigDecimal weightMax;
|
||||
|
||||
private Integer sortNo;
|
||||
|
||||
/** 编辑保存删除标记(不落库) */
|
||||
private Boolean deleted;
|
||||
}
|
||||
@@ -57,4 +57,7 @@ public class LblWeightBand
|
||||
private String extraPriceUnit;
|
||||
|
||||
private Integer sortNo;
|
||||
|
||||
/** 编辑保存删除标记(不落库) */
|
||||
private Boolean deleted;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ public class PayBillDiff
|
||||
|
||||
private Long lineId;
|
||||
|
||||
private Long feeId;
|
||||
private String feeId;
|
||||
|
||||
private BigDecimal ourAmount;
|
||||
|
||||
@@ -28,7 +28,7 @@ public class PayBillDiff
|
||||
/** OPEN ACCEPT_OURS ACCEPT_THEIRS */
|
||||
private String handleType;
|
||||
|
||||
private Long adjustFeeId;
|
||||
private String adjustFeeId;
|
||||
|
||||
private String createBy;
|
||||
|
||||
|
||||
@@ -13,8 +13,9 @@ public class PayBillLine
|
||||
|
||||
private Long billId;
|
||||
|
||||
private Long feeId;
|
||||
private String feeId;
|
||||
|
||||
/** 计费订单ID,对应 prc_order_bill.bill_id */
|
||||
private Long orderBillId;
|
||||
|
||||
private String orderNo;
|
||||
|
||||
@@ -19,7 +19,7 @@ public class PayBillLog
|
||||
|
||||
private Long lineId;
|
||||
|
||||
private Long feeId;
|
||||
private String feeId;
|
||||
|
||||
private String operationType;
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import lombok.Data;
|
||||
@Data
|
||||
public class PayBillOrder
|
||||
{
|
||||
/** 计费订单ID,对应 prc_order_bill.bill_id */
|
||||
private Long billId;
|
||||
|
||||
private String orderNo;
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.bms.price.domain;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import lombok.Data;
|
||||
|
||||
/** 按订单生成应付的结果。skipped 是价卡里有、但这票算不了的附加费。 */
|
||||
@@ -29,4 +30,12 @@ public class PayOrderCostResult
|
||||
private List<PayCostLine> fees;
|
||||
|
||||
private List<String> skipped;
|
||||
|
||||
/** 本次落库的应付费用,供提交成功后写日志。不返回给页面。 */
|
||||
@JsonIgnore
|
||||
private transient List<PrcPayBillFee> loggedFees;
|
||||
|
||||
/** 本次费用日志的操作类型,字典 bms_pay_fee_log_type */
|
||||
@JsonIgnore
|
||||
private transient String feeLogType;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.bms.price.domain;
|
||||
|
||||
import java.util.List;
|
||||
import lombok.Data;
|
||||
|
||||
/** 应付列表勾选订单后,批量写入同一组手工费用。 */
|
||||
@Data
|
||||
public class PayOrderFeeBatch
|
||||
{
|
||||
/** 勾选的计费订单 ID */
|
||||
private List<String> billIds;
|
||||
|
||||
/** 要加到每一票订单上的费用 */
|
||||
private List<PayOrderFeeLine> fees;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.bms.price.domain;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import lombok.Data;
|
||||
|
||||
/** 一票订单的应付费用,按 abcd 四段排好。 */
|
||||
@Data
|
||||
public class PayOrderFeeBoard
|
||||
{
|
||||
private String billId;
|
||||
|
||||
private String orderNo;
|
||||
|
||||
private String ladingNo;
|
||||
|
||||
private List<PayOrderFeeSection> sections = new ArrayList<>();
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.bms.price.domain;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
/** 应付列表费用弹框里的一条费用。 */
|
||||
@Data
|
||||
public class PayOrderFeeLine
|
||||
{
|
||||
/** 费用明细 ID。新增时为空 */
|
||||
private String feeId;
|
||||
|
||||
/** 费用类型,字典 bms_fee_type 的英文编码。手输名称放不下时记 MANUAL */
|
||||
private String feeType;
|
||||
|
||||
/** 费用项名称。手工费用按填写的名称保存 */
|
||||
private String feeName;
|
||||
|
||||
/** 1A 2B 3C 4D */
|
||||
private String level;
|
||||
|
||||
private BigDecimal amount;
|
||||
|
||||
private String currency;
|
||||
|
||||
/** CALC 尾程计算,LADING 提单分摊,MANUAL 手工 */
|
||||
private String feeSource;
|
||||
|
||||
private String remark;
|
||||
|
||||
/** 已进入应付账单时不能删除 */
|
||||
private Long statementLineId;
|
||||
|
||||
/** 创建人 */
|
||||
private String createBy;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date createTime;
|
||||
|
||||
/** 更新人 */
|
||||
private String updateBy;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date updateTime;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.bms.price.domain;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import lombok.Data;
|
||||
|
||||
/** 应付费用的一个阶段。1A 头程仓储,2B 提单运输,3C 清关,4D 尾程。 */
|
||||
@Data
|
||||
public class PayOrderFeeSection
|
||||
{
|
||||
private String level;
|
||||
|
||||
private String title;
|
||||
|
||||
private List<PayOrderFeeLine> fees = new ArrayList<>();
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.bms.price.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/** 应付列表查询条件。 */
|
||||
@Data
|
||||
public class PayOrderQuery
|
||||
{
|
||||
private String orderNo;
|
||||
|
||||
/** 多个订单号。由服务按逗号、空格或换行拆开。 */
|
||||
private java.util.List<String> orderNos;
|
||||
|
||||
private String ladingNo;
|
||||
|
||||
private String customerName;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.bms.price.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/** 应付列表上的费用重算条件。一次只按订单号或提单号其中一种。 */
|
||||
@Data
|
||||
public class PayOrderRecalcCommand
|
||||
{
|
||||
/** ORDER 按订单号,LADING 按提单号 */
|
||||
private String sourceType;
|
||||
|
||||
/** 单号原文。可用逗号、空格或换行分隔 */
|
||||
private String text;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.bms.price.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/** 费用重算里的一票结果。 */
|
||||
@Data
|
||||
public class PayOrderRecalcLine
|
||||
{
|
||||
private String billId;
|
||||
|
||||
private String orderNo;
|
||||
|
||||
private String ladingNo;
|
||||
|
||||
/** 这一条是否已经处理完 */
|
||||
private boolean finished;
|
||||
|
||||
/** 这一票是否已经生成应付费用 */
|
||||
private boolean success;
|
||||
|
||||
/** 失败原因。成功时为空 */
|
||||
private String message;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.bms.price.domain;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import lombok.Data;
|
||||
|
||||
/** 一次费用重算的结果。失败行不影响已经成功的订单。 */
|
||||
@Data
|
||||
public class PayOrderRecalcResult
|
||||
{
|
||||
/** 计费成功的订单数 */
|
||||
private int successCount;
|
||||
|
||||
/** 未生成费用的订单数,含找不到的单号 */
|
||||
private int failCount;
|
||||
|
||||
/** 每一票或每一个没对上的单号 */
|
||||
private List<PayOrderRecalcLine> lines = new ArrayList<>();
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.bms.price.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import lombok.Data;
|
||||
|
||||
/** 应付费用重算任务。待处理订单和进度都放在 Redis。 */
|
||||
@Data
|
||||
public class PayOrderRecalcTask implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static final String PENDING = "PENDING";
|
||||
|
||||
public static final String RUNNING = "RUNNING";
|
||||
|
||||
public static final String SUCCESS = "SUCCESS";
|
||||
|
||||
public static final String FAIL = "FAIL";
|
||||
|
||||
public static final String CANCELLED = "CANCELLED";
|
||||
|
||||
private String taskId;
|
||||
|
||||
private String status;
|
||||
|
||||
private int percent;
|
||||
|
||||
private String message;
|
||||
|
||||
private int total;
|
||||
|
||||
private int successCount;
|
||||
|
||||
private int failCount;
|
||||
|
||||
/** 查出来的订单,以及没对上的单号。处理完一条就更新这一条。 */
|
||||
private List<PayOrderRecalcLine> lines = new ArrayList<>();
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.bms.price.domain;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
/** 应付列表里的一票订单。提单号来自订单扩展上的空运单号。 */
|
||||
@Data
|
||||
public class PayOrderRow
|
||||
{
|
||||
private String billId;
|
||||
|
||||
private String orderNo;
|
||||
|
||||
private String ladingNo;
|
||||
|
||||
private String trackingNo;
|
||||
|
||||
/** 客户编码,列表展示用 */
|
||||
private String customerCode;
|
||||
|
||||
private String customerName;
|
||||
|
||||
private String productName;
|
||||
|
||||
private String countryName;
|
||||
|
||||
/** 收件邮编,来自 prc_order_bill.dest_postcode */
|
||||
private String destPostcode;
|
||||
|
||||
private String channelName;
|
||||
|
||||
private BigDecimal chargeWeight;
|
||||
|
||||
private BigDecimal payTotal;
|
||||
|
||||
private String currency;
|
||||
|
||||
/** 应付计费状态,字典 bms_pay_calc_status:1计费成功,2计费失败 */
|
||||
private Integer payCalcStatus;
|
||||
|
||||
/** 计费失败原因 */
|
||||
private String payCalcMsg;
|
||||
|
||||
/** 应付主表更新人 */
|
||||
private String updateBy;
|
||||
|
||||
/** 应付主表更新时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date updateTime;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date bizDate;
|
||||
}
|
||||
@@ -28,12 +28,18 @@ public class PayPostcodeGroup extends BaseEntity
|
||||
/** ZONE 邮编分区,FEE 附加费 */
|
||||
private String configKind;
|
||||
|
||||
/** REACH 可达,UNREACH 不可达,REMOTE 偏远。普通分区为空 */
|
||||
/** REACH 可达,UNREACH 不可达,REMOTE 偏远,SURCHARGE 附加费。普通分区为空 */
|
||||
private String coverage;
|
||||
|
||||
/** 渠道名称,从表头识别,可在页面修改 */
|
||||
private String channelName;
|
||||
|
||||
/** 修改渠道名称前的原名称。分区维护按这个渠道收窄 */
|
||||
private String oldChannelName;
|
||||
|
||||
/** 为 true 时国家下的全部分区都查出来,不按渠道收窄 */
|
||||
private Boolean allChannels;
|
||||
|
||||
/** 目录里的服务类型,和报价产品对应 */
|
||||
private String serviceType;
|
||||
|
||||
|
||||
@@ -19,6 +19,12 @@ public class PayPostcodeLine implements Serializable
|
||||
|
||||
private String countryCode;
|
||||
|
||||
/** 查询条件:只看这个渠道下的邮编 */
|
||||
private String channelName;
|
||||
|
||||
/** 附加费邮编查询时带出这一组的费用名 */
|
||||
private String feeName;
|
||||
|
||||
private String regionName;
|
||||
|
||||
private String regionNameCn;
|
||||
|
||||
@@ -61,7 +61,7 @@ public class PayProduct extends BaseEntity
|
||||
@Excel(name = "国家/口岸", width = 18)
|
||||
private String countryScope;
|
||||
|
||||
/** 字典 order_charge_type:续重计费、单票价、常规计重价 */
|
||||
/** 字典 order_charge_type:PER_KG 常规计费、FLAT 一口价、EXTRA 续重价 */
|
||||
@Excel(name = "费用类型", width = 14)
|
||||
private String chargeType;
|
||||
|
||||
|
||||
@@ -63,9 +63,36 @@ public class PaySurcharge
|
||||
/** 邮编列表、重量阈值或尺寸表达式。续重时这里是公斤阈值 */
|
||||
private String calcParam;
|
||||
|
||||
/** 偏远邮编规则。续重行的阈值在 calcParam,邮编放这里,避免互相覆盖 */
|
||||
/** 偏远邮编规则。导入价卡仍可能把邮编写在这里 */
|
||||
private String postcodeParam;
|
||||
|
||||
/** 来自附加费配置的长,厘米。本表不保存 */
|
||||
private BigDecimal lengthCm;
|
||||
|
||||
/** 来自附加费配置的宽,厘米。本表不保存 */
|
||||
private BigDecimal widthCm;
|
||||
|
||||
/** 来自附加费配置的高,厘米。本表不保存 */
|
||||
private BigDecimal heightCm;
|
||||
|
||||
/** 来自附加费配置的超尺寸类型:SIDE 任一边,VOLUME 体积。本表不保存 */
|
||||
private String sizeType;
|
||||
|
||||
/** 来自附加费配置的体积阈值,立方米。本表不保存 */
|
||||
private BigDecimal volumeM3;
|
||||
|
||||
/** 来自附加费配置的超重阈值,公斤。本表不保存 */
|
||||
private BigDecimal overWeightKg;
|
||||
|
||||
/** 来自附加费配置的续重起始重量,公斤。本表不保存 */
|
||||
private BigDecimal extraWeightKg;
|
||||
|
||||
/** 来自附加费配置的命中邮编。本表不保存 */
|
||||
private String postcodeText;
|
||||
|
||||
/** 来自附加费配置的适用国家。本表不保存 */
|
||||
private String countryCode;
|
||||
|
||||
/** 适用重量下限,空表示不限。首重从 0 开始 */
|
||||
private BigDecimal weightMin;
|
||||
|
||||
|
||||
@@ -1,118 +0,0 @@
|
||||
package com.bms.price.domain;
|
||||
|
||||
import java.util.Date;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
|
||||
/** 应付附加费配置在某一产品版本上的操作记录。 */
|
||||
public class PaySurchargeRuleLog
|
||||
{
|
||||
private Long logId;
|
||||
|
||||
private Long productId;
|
||||
|
||||
private Long termId;
|
||||
|
||||
private Integer versionNo;
|
||||
|
||||
/** 1新增 2修改 3删除 */
|
||||
private String operationType;
|
||||
|
||||
private String ruleKey;
|
||||
|
||||
private String changeContent;
|
||||
|
||||
private String createBy;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date createTime;
|
||||
|
||||
public Long getLogId()
|
||||
{
|
||||
return logId;
|
||||
}
|
||||
|
||||
public void setLogId(Long logId)
|
||||
{
|
||||
this.logId = logId;
|
||||
}
|
||||
|
||||
public Long getProductId()
|
||||
{
|
||||
return productId;
|
||||
}
|
||||
|
||||
public void setProductId(Long productId)
|
||||
{
|
||||
this.productId = productId;
|
||||
}
|
||||
|
||||
public Long getTermId()
|
||||
{
|
||||
return termId;
|
||||
}
|
||||
|
||||
public void setTermId(Long termId)
|
||||
{
|
||||
this.termId = termId;
|
||||
}
|
||||
|
||||
public Integer getVersionNo()
|
||||
{
|
||||
return versionNo;
|
||||
}
|
||||
|
||||
public void setVersionNo(Integer versionNo)
|
||||
{
|
||||
this.versionNo = versionNo;
|
||||
}
|
||||
|
||||
public String getOperationType()
|
||||
{
|
||||
return operationType;
|
||||
}
|
||||
|
||||
public void setOperationType(String operationType)
|
||||
{
|
||||
this.operationType = operationType;
|
||||
}
|
||||
|
||||
public String getRuleKey()
|
||||
{
|
||||
return ruleKey;
|
||||
}
|
||||
|
||||
public void setRuleKey(String ruleKey)
|
||||
{
|
||||
this.ruleKey = ruleKey;
|
||||
}
|
||||
|
||||
public String getChangeContent()
|
||||
{
|
||||
return changeContent;
|
||||
}
|
||||
|
||||
public void setChangeContent(String changeContent)
|
||||
{
|
||||
this.changeContent = changeContent;
|
||||
}
|
||||
|
||||
public String getCreateBy()
|
||||
{
|
||||
return createBy;
|
||||
}
|
||||
|
||||
public void setCreateBy(String createBy)
|
||||
{
|
||||
this.createBy = createBy;
|
||||
}
|
||||
|
||||
public Date getCreateTime()
|
||||
{
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(Date createTime)
|
||||
{
|
||||
this.createTime = createTime;
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package com.bms.price.domain;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 把同一套计费条件写到若干产品的当前版本。每个版本只保留这一份。
|
||||
*/
|
||||
@Data
|
||||
public class PaySurchargeRuleSave
|
||||
{
|
||||
private List<PaySurchargeRuleBind> products = new ArrayList<>();
|
||||
|
||||
private List<PaySurchargeRule> rules = new ArrayList<>();
|
||||
|
||||
@Data
|
||||
public static class PaySurchargeRuleBind
|
||||
{
|
||||
private Long productId;
|
||||
|
||||
private Long termId;
|
||||
|
||||
private Integer versionNo;
|
||||
|
||||
private String productName;
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,12 @@ public class PayWeightBand
|
||||
/** 价格列名称,例如英国大陆、马德里高密度 */
|
||||
private String zoneName;
|
||||
|
||||
/** 计费条件类型。POSTCODE 邮编,SIZE 尺寸,WEIGHT 重量。空表示这一档只按分区 */
|
||||
private String calcRule;
|
||||
|
||||
/** 条件参数。邮编如 07 或 35,38;尺寸如 side:80;sum:180 或 box:60*40*30;重量如 30 表示超过 30kg */
|
||||
private String calcParam;
|
||||
|
||||
/** 重量段原文 */
|
||||
private String weightLabel;
|
||||
|
||||
|
||||
@@ -26,7 +26,8 @@ public class PrcBillingTask extends BaseEntity
|
||||
/** 移动端传入的计费时间(非 Oracle 订单时间;回写时不会被覆盖) */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date billTime;
|
||||
private Long billId;
|
||||
/** 对应 prc_order_bill.bill_id */
|
||||
private Long orderId;
|
||||
/** 用于查询的稳定失败码,例如 NO_CUSTOMER_PACKAGE */
|
||||
private String failCode;
|
||||
private String errorMessage;
|
||||
|
||||
@@ -129,6 +129,8 @@ public class PrcOrderBill extends BaseEntity
|
||||
private String errorMessage;
|
||||
/** 批量查询:多个计费失败状态(仅查询用,非表字段) */
|
||||
private List<Integer> billingFailStatuses;
|
||||
/** 计费列表:仅返回 prc_income_bill 存在的订单(仅查询用,非表字段) */
|
||||
private Boolean requireIncomeBill;
|
||||
private String roundMode;
|
||||
|
||||
private List<PrcIncomeBillFee> incomeFees;
|
||||
|
||||
@@ -13,8 +13,8 @@ public class PrcPayBill implements Serializable
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 应付主表ID */
|
||||
private Long payBillId;
|
||||
/** 计费订单ID */
|
||||
private String payBillId;
|
||||
/** 计费订单ID,对应 prc_order_bill.bill_id */
|
||||
private Long billId;
|
||||
/** 币种 */
|
||||
private String currency;
|
||||
@@ -24,8 +24,27 @@ public class PrcPayBill implements Serializable
|
||||
private BigDecimal redlineAmount;
|
||||
/** 成本价合计(当前计费结果) */
|
||||
private BigDecimal costAmount;
|
||||
/** 应付合计(当前等于成本价) */
|
||||
/** 应付合计(当前等于成本价,落库后按全部未删除明细折人民币重算) */
|
||||
private BigDecimal payTotal;
|
||||
|
||||
/** A段合计,人民币 */
|
||||
private BigDecimal amountA;
|
||||
|
||||
/** B段合计,人民币 */
|
||||
private BigDecimal amountB;
|
||||
|
||||
/** C段合计,人民币 */
|
||||
private BigDecimal amountC;
|
||||
|
||||
/** D段合计,人民币 */
|
||||
private BigDecimal amountD;
|
||||
|
||||
/** 应付计费状态,字典 bms_pay_calc_status:1计费成功,2计费失败 */
|
||||
private Integer payCalcStatus;
|
||||
|
||||
/** 计费失败原因,最长 100 字 */
|
||||
private String payCalcMsg;
|
||||
|
||||
/** 业务员/销售员 */
|
||||
private String belongSaler;
|
||||
/** 销售员编码 */
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import lombok.Data;
|
||||
|
||||
/** 应付费用明细 prc_pay_bill_fee */
|
||||
@@ -12,12 +13,18 @@ public class PrcPayBillFee implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Long feeId;
|
||||
private String feeId;
|
||||
/** 计费订单ID,对应 prc_order_bill.bill_id */
|
||||
private Long billId;
|
||||
/** 应付主表ID */
|
||||
private Long payBillId;
|
||||
private String payBillId;
|
||||
/** 费用类型,字典 bms_fee_type 的英文编码 */
|
||||
private String feeType;
|
||||
|
||||
/** 展示用的费用项名称,不入库。附加费取配置名称,其余取字典标签 */
|
||||
private String feeName;
|
||||
|
||||
/** 尾程计算时是附加费配置ID。提单分摊时是 srv_bill_air_fee.id */
|
||||
private Long scId;
|
||||
|
||||
/** 费用所属阶段:1 a段,2 b段,3 c段,4 d段 */
|
||||
@@ -30,7 +37,7 @@ public class PrcPayBillFee implements Serializable
|
||||
/** CALC 计算,LADING 提单分摊,MANUAL 人工 */
|
||||
private String feeSource;
|
||||
|
||||
/** 来源数据id */
|
||||
/** 来源数据id。提单分摊时为 srv_bill_air_fee.id */
|
||||
private String sourceId;
|
||||
|
||||
/** 是否删除:0未删除 1已删除 */
|
||||
@@ -43,6 +50,36 @@ public class PrcPayBillFee implements Serializable
|
||||
private Long settleSupplierId;
|
||||
|
||||
private String settleSupplierName;
|
||||
|
||||
/** 创建人 */
|
||||
private String createBy;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date createTime;
|
||||
|
||||
/** 更新人 */
|
||||
private String updateBy;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date updateTime;
|
||||
|
||||
/** 订单计费日,只在折算汇率时使用,不入库 */
|
||||
@JsonIgnore
|
||||
private Date bizDate;
|
||||
|
||||
/** 写日志时带上的变更前费用项,不入库 */
|
||||
@JsonIgnore
|
||||
private String logBeforeName;
|
||||
|
||||
/** 写日志时带上的变更前金额,不入库 */
|
||||
@JsonIgnore
|
||||
private BigDecimal logBeforeAmount;
|
||||
|
||||
/** 写日志时带上的变更前币种,不入库 */
|
||||
@JsonIgnore
|
||||
private String logBeforeCurrency;
|
||||
|
||||
/** 为 true 时日志只记变更前。重算后消失的计算费用用,不入库 */
|
||||
@JsonIgnore
|
||||
private Boolean logAfterBlank;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.bms.price.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
/** 应付费用日志 prc_pay_bill_fee_log */
|
||||
@Data
|
||||
public class PrcPayBillFeeLog implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Long logId;
|
||||
|
||||
private String feeId;
|
||||
|
||||
private Long billId;
|
||||
|
||||
/** 费用项 */
|
||||
private String feeName;
|
||||
|
||||
private BigDecimal amount;
|
||||
|
||||
private String currency;
|
||||
|
||||
/** 变更前费用项 */
|
||||
private String beforeFeeName;
|
||||
|
||||
/** 变更前金额 */
|
||||
private BigDecimal beforeAmount;
|
||||
|
||||
/** 变更前币种 */
|
||||
private String beforeCurrency;
|
||||
|
||||
/** 变更后费用项 */
|
||||
private String afterFeeName;
|
||||
|
||||
/** 变更后金额 */
|
||||
private BigDecimal afterAmount;
|
||||
|
||||
/** 变更后币种 */
|
||||
private String afterCurrency;
|
||||
|
||||
/** 操作类型,字典 bms_pay_fee_log_type */
|
||||
private String operationType;
|
||||
|
||||
/** 备注。费用重算失败时写入失败原因 */
|
||||
private String remark;
|
||||
|
||||
/** 操作人 */
|
||||
private String createBy;
|
||||
|
||||
/** 操作时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date createTime;
|
||||
}
|
||||
@@ -39,6 +39,8 @@ public class PrcPriceSet extends BaseEntity
|
||||
private Date expireDate;
|
||||
/** D/A/E/R/S */
|
||||
private String status;
|
||||
/** 仅查询用:状态多选(如 D、E) */
|
||||
private List<String> statuses;
|
||||
private Long tmsId;
|
||||
|
||||
private Integer productCount;
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.bms.price.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
import lombok.Data;
|
||||
|
||||
/** 毛利分析订单异步导出任务的临时状态。 */
|
||||
@Data
|
||||
public class PrcProfitReportExportTask implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String taskId;
|
||||
private Long userId;
|
||||
private String status;
|
||||
private int percent;
|
||||
private String message;
|
||||
private String error;
|
||||
private int rowCount;
|
||||
private String fileName;
|
||||
private String storageKey;
|
||||
}
|
||||
@@ -21,6 +21,22 @@ public class PrcSurcharge extends BaseEntity
|
||||
/** 渠道产品(字典 payment_product_type.dict_value) */
|
||||
private String dictValue;
|
||||
private BigDecimal chargeValue;
|
||||
/** 超尺寸长,厘米 */
|
||||
private BigDecimal lengthCm;
|
||||
/** 超尺寸宽,厘米 */
|
||||
private BigDecimal widthCm;
|
||||
/** 超尺寸高,厘米 */
|
||||
private BigDecimal heightCm;
|
||||
/** 超尺寸类型,字典 bms_size_type:SIDE 任一边,VOLUME 体积 */
|
||||
private String sizeType;
|
||||
/** 超尺寸体积阈值,立方米。类型为体积时,订单体积超过该值才收取 */
|
||||
private BigDecimal volumeM3;
|
||||
/** 超重阈值,公斤 */
|
||||
private BigDecimal overWeightKg;
|
||||
/** 超重续收起始重量,公斤 */
|
||||
private BigDecimal extraWeightKg;
|
||||
/** 命中邮编,多个用逗号分隔 */
|
||||
private String postcodeText;
|
||||
private String currency;
|
||||
/** 字典 bms_round_mode:UP / DOWN / HALF_UP */
|
||||
private String roundMode;
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.bms.price.domain;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 产品与附加费配置的关联。应付、应收以及后续类型都按产品编号和类型查询。
|
||||
*/
|
||||
@Data
|
||||
public class PrcSurchargeBind
|
||||
{
|
||||
public static final String TYPE_AP = "AP";
|
||||
|
||||
public static final String TYPE_AR = "AR";
|
||||
|
||||
private Long bindId;
|
||||
|
||||
private Long productId;
|
||||
|
||||
/** AP 应付,AR 应收,以及后续其它类型 */
|
||||
private String productType;
|
||||
|
||||
private Long scId;
|
||||
|
||||
private Integer sortNo;
|
||||
|
||||
private String createdBy;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date createTime;
|
||||
|
||||
private String updatedBy;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date updateTime;
|
||||
|
||||
/** 关联查询带出的附加费配置 */
|
||||
private String scName;
|
||||
|
||||
private String chargeType;
|
||||
|
||||
private BigDecimal chargeValue;
|
||||
|
||||
private String currency;
|
||||
|
||||
/** on 启用,of 停用,vd 作废 */
|
||||
private String ssCode;
|
||||
|
||||
private String blockTitle;
|
||||
|
||||
private String countryCode;
|
||||
|
||||
private String feeType;
|
||||
|
||||
private String scNote;
|
||||
|
||||
private BigDecimal lengthCm;
|
||||
|
||||
private BigDecimal widthCm;
|
||||
|
||||
private BigDecimal heightCm;
|
||||
|
||||
/** 超尺寸类型:SIDE 任一边,VOLUME 体积 */
|
||||
private String sizeType;
|
||||
|
||||
/** 超尺寸体积阈值,立方米 */
|
||||
private BigDecimal volumeM3;
|
||||
|
||||
private BigDecimal overWeightKg;
|
||||
|
||||
private BigDecimal extraWeightKg;
|
||||
|
||||
private String postcodeText;
|
||||
}
|
||||
@@ -51,6 +51,24 @@ public class PrcSurchargeRel extends BaseEntity
|
||||
private String roundMode;
|
||||
private String ssCode;
|
||||
private String scNote;
|
||||
/** 命中邮编(来自 prc_surcharge.postcode_text) */
|
||||
private String postcodeText;
|
||||
/** 超尺寸类型:SIDE 任一边,VOLUME 体积 */
|
||||
private String sizeType;
|
||||
|
||||
/** 超尺寸体积阈值,立方米 */
|
||||
private BigDecimal volumeM3;
|
||||
|
||||
/** 超尺寸长/宽/高(厘米) */
|
||||
private BigDecimal lengthCm;
|
||||
private BigDecimal widthCm;
|
||||
private BigDecimal heightCm;
|
||||
/** 超重阈值(公斤) */
|
||||
private BigDecimal overWeightKg;
|
||||
/** 续重起始重量(公斤) */
|
||||
private BigDecimal extraWeightKg;
|
||||
/** 命中分区(block_title) */
|
||||
private String blockTitle;
|
||||
|
||||
/** 明细展示字段(PRODUCT/REDLINE LEFT JOIN product_country) */
|
||||
private String countryName;
|
||||
|
||||
@@ -5,14 +5,23 @@ import java.util.Date;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
/** 国家下的分区:prc_zone */
|
||||
/** 国家/打单产品下的分区:prc_zone */
|
||||
@Data
|
||||
public class PrcZone implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 常规计费(按国家) */
|
||||
public static final String TYPE_REGULAR = "REGULAR";
|
||||
/** 打单计费(按产品) */
|
||||
public static final String TYPE_LABEL = "LABEL";
|
||||
|
||||
private Long zoneId;
|
||||
/** REGULAR / LABEL */
|
||||
private String zoneType;
|
||||
private Long regionId;
|
||||
/** 打单分区关联 prc_label_product.product_id;常规为 null */
|
||||
private Long productId;
|
||||
/** 存储在 prc_zone 上的 ISO2 国家代码 */
|
||||
private String countryCode;
|
||||
private String zoneCode;
|
||||
@@ -27,4 +36,6 @@ public class PrcZone implements Serializable
|
||||
private Integer detailCount;
|
||||
/** 列表展示,来源于 region */
|
||||
private String countryNameCn;
|
||||
/** 打单产品名,非表字段 */
|
||||
private String productName;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.bms.price.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
import lombok.Data;
|
||||
|
||||
/** 打单计费分区:产品汇总行 */
|
||||
@Data
|
||||
public class PrcZoneLabelProduct implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Long productId;
|
||||
private String productName;
|
||||
private String dictValue;
|
||||
private Integer zoneCount;
|
||||
private Integer detailCount;
|
||||
}
|
||||
+1
-2
@@ -2,7 +2,6 @@ package com.bms.price.domain.vo;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
@@ -12,7 +11,7 @@ public class AddIncomeBillFeeRequest implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@NotBlank(message = "billId required")
|
||||
@NotNull(message = "billId required")
|
||||
private Long billId;
|
||||
|
||||
/** 附加费配置ID(prc_surcharge.sc_id)。 */
|
||||
|
||||
+2
-2
@@ -33,9 +33,9 @@ public class PrcBillingBillListExportRow implements Serializable
|
||||
private String countryName;
|
||||
@Excel(name = "件数", width = 10)
|
||||
private Integer pieces;
|
||||
@Excel(name = "计费重", scale = 3, width = 12)
|
||||
@Excel(name = "客户确认重", scale = 3, width = 12)
|
||||
private BigDecimal chargeWeight;
|
||||
@Excel(name = "原计费重", scale = 3, width = 12)
|
||||
@Excel(name = "计费重", scale = 3, width = 12)
|
||||
private BigDecimal weight;
|
||||
@Excel(name = "收货重", scale = 3, width = 12)
|
||||
private BigDecimal receiveWeight;
|
||||
|
||||
+2
@@ -35,6 +35,8 @@ public class PrcOrderBillListExportRow implements Serializable
|
||||
private Integer pieces;
|
||||
@Excel(name = "计费重", scale = 3, width = 12)
|
||||
private BigDecimal weight;
|
||||
@Excel(name = "客户确认重", scale = 3, width = 12)
|
||||
private BigDecimal chargeWeight;
|
||||
@Excel(name = "体积重", scale = 3, width = 12)
|
||||
private BigDecimal volumeWeight;
|
||||
@Excel(name = "实重", scale = 3, width = 12)
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.bms.price.domain.vo;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import com.bms.common.core.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
@@ -15,8 +16,10 @@ public class PrcProfitReportQuery extends BaseEntity
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date beginBizDate;
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date endBizDate;
|
||||
private String orderNo;
|
||||
/** 订单号拆分后的多值查询条件。 */
|
||||
@@ -26,14 +29,20 @@ public class PrcProfitReportQuery extends BaseEntity
|
||||
private List<String> customerCodes;
|
||||
/** 按客户当前区域筛选。 */
|
||||
private String customerArea;
|
||||
/** 服务端解析的区域客户 ID;null 表示使用客户表关联,空列表表示无匹配客户。 */
|
||||
private List<Long> areaCustomerIds;
|
||||
/** 服务端根据客户区域确定的计算规则。 */
|
||||
private String profitRule;
|
||||
private String customerName;
|
||||
/** 客户名称拆分后的多值查询条件。 */
|
||||
private List<String> customerNames;
|
||||
private String belongSalerCode;
|
||||
/** 产品代码或产品名称的统一模糊查询关键字。 */
|
||||
private String productKeyword;
|
||||
private String productCode;
|
||||
private String productName;
|
||||
private String countryCode;
|
||||
private String countryName;
|
||||
private String currency;
|
||||
/** 订单维度应收状态筛选:UNBILLED、PARTIAL、BILLED。 */
|
||||
private String arBillStatus;
|
||||
|
||||
@@ -42,6 +42,8 @@ public class TmsPriceBillRequest extends TmsPriceQuoteRequest
|
||||
private BigDecimal actualWeight;
|
||||
/** 上游 TAB_ORDER.WEIGHT(收货重量) */
|
||||
private BigDecimal receiveWeight;
|
||||
/** 计费重覆盖:上游 CONFIRM_WEIGHT(客户确认重)或本地人工修改;无值则为 null */
|
||||
private BigDecimal chargeWeight;
|
||||
private BigDecimal volume;
|
||||
private BigDecimal volumeWeight;
|
||||
private BigDecimal pkgLength;
|
||||
|
||||
@@ -10,7 +10,7 @@ public class TmsPriceQuoteFeeLine implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String feeId;
|
||||
private Long feeId;
|
||||
private String feeType;
|
||||
private String feeName;
|
||||
/** 附加费配置ID,运费/挂号费为 0 */
|
||||
@@ -23,6 +23,8 @@ public class TmsPriceQuoteFeeLine implements Serializable
|
||||
private String currency;
|
||||
private String roundMode;
|
||||
private String remark;
|
||||
/** CALC 计算,LADING 提单分摊,MANUAL 手工 */
|
||||
private String feeSource;
|
||||
/** UNBILLED / BILLED */
|
||||
private String arBillStatus;
|
||||
/** 0=系统 1=人工 */
|
||||
|
||||
@@ -72,6 +72,18 @@ public class TmsPriceQuoteResult implements Serializable
|
||||
private BigDecimal incomeTotal;
|
||||
/** 应付合计(订单账单);也是报价应付 */
|
||||
private BigDecimal payTotal;
|
||||
|
||||
/** 应付 A 段合计,来自 prc_pay_bill.amount_a */
|
||||
private BigDecimal amountA;
|
||||
|
||||
/** 应付 B 段合计,来自 prc_pay_bill.amount_b */
|
||||
private BigDecimal amountB;
|
||||
|
||||
/** 应付 C 段合计,来自 prc_pay_bill.amount_c */
|
||||
private BigDecimal amountC;
|
||||
|
||||
/** 应付 D 段合计,来自 prc_pay_bill.amount_d */
|
||||
private BigDecimal amountD;
|
||||
/** 报价 / 历史字段;账单同步时与 incomeTotal 相同 */
|
||||
private BigDecimal payableTotal;
|
||||
private String currency = "CNY";
|
||||
|
||||
+1
-2
@@ -3,7 +3,6 @@ package com.bms.price.domain.vo;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import jakarta.validation.constraints.DecimalMin;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
@@ -13,7 +12,7 @@ public class UpdateChargeWeightRequest implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@NotBlank(message = "billId is required")
|
||||
@NotNull(message = "billId is required")
|
||||
private Long billId;
|
||||
|
||||
@NotNull(message = "chargeWeight is required")
|
||||
|
||||
+2
-2
@@ -2,7 +2,7 @@ package com.bms.price.domain.vo;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
/** 修改计费明细上的手工应收费用行。 */
|
||||
@@ -11,7 +11,7 @@ public class UpdateIncomeBillFeeRequest implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@NotBlank(message = "feeId required")
|
||||
@NotNull(message = "feeId required")
|
||||
private Long feeId;
|
||||
|
||||
/** 可选:更换附加费配置。 */
|
||||
|
||||
@@ -310,6 +310,8 @@ public final class LblBandNormalizer
|
||||
private static LblWeightBand copyBand(LblWeightBand src)
|
||||
{
|
||||
LblWeightBand b = new LblWeightBand();
|
||||
b.setBandId(src.getBandId());
|
||||
b.setDeleted(src.getDeleted());
|
||||
b.setProductId(src.getProductId());
|
||||
b.setVersionId(src.getVersionId());
|
||||
b.setSectionName(src.getSectionName());
|
||||
|
||||
@@ -78,7 +78,7 @@ public final class LblSurchargeRules
|
||||
}
|
||||
if (name.contains("签名") || name.contains("重复") || name.contains("未预报") || name.contains("重新贴"))
|
||||
{
|
||||
fee.setCalcRule("ITEM");
|
||||
fee.setCalcRule(MANUAL);
|
||||
return;
|
||||
}
|
||||
String postcodes = postcodeParam(desc);
|
||||
@@ -104,10 +104,10 @@ public final class LblSurchargeRules
|
||||
}
|
||||
if (blob.contains("固定收取") || "固定收取".equals(fee.getChargeTiming()))
|
||||
{
|
||||
fee.setCalcRule("ITEM");
|
||||
fee.setCalcRule(ALWAYS);
|
||||
return;
|
||||
}
|
||||
fee.setCalcRule("ITEM");
|
||||
fee.setCalcRule(MANUAL);
|
||||
}
|
||||
|
||||
public static boolean matchesPostcode(String param, String postcode)
|
||||
|
||||
@@ -99,6 +99,7 @@ public class LblWorkbookParser
|
||||
}
|
||||
attachImilePostcodes(workbook, preview.getProducts());
|
||||
attachCatalogRates(workbook, preview.getProducts());
|
||||
clearImportedSurcharges(preview.getProducts());
|
||||
LblZonePostcodeAttach.attach(workbook, preview.getProducts());
|
||||
LblBandNormalizer.normalize(preview);
|
||||
return preview;
|
||||
@@ -202,8 +203,9 @@ public class LblWorkbookParser
|
||||
? "没有工作表能对上产品字典"
|
||||
: "文件里没有「" + selected.trim() + "」这张工作表");
|
||||
}
|
||||
report(listener, 92, "正在整理附加费");
|
||||
attachWorkbookRates(workbook, preview.getProducts());
|
||||
// 打单导入暂不自动识别产品表附加费用表,由操作人手动添加
|
||||
report(listener, 92, "跳过附加费自动识别");
|
||||
clearImportedSurcharges(preview.getProducts());
|
||||
LblZonePostcodeAttach.attach(workbook, preview.getProducts());
|
||||
preview.setSkippedSheets(skipped);
|
||||
report(listener, 96, "工作表解析完成");
|
||||
@@ -795,6 +797,27 @@ public class LblWorkbookParser
|
||||
}
|
||||
}
|
||||
|
||||
/** 清空导入过程中自动识别出的附加费,改由操作人手动添加。 */
|
||||
private static void clearImportedSurcharges(List<LblProduct> products)
|
||||
{
|
||||
if (products == null || products.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
for (LblProduct product : products)
|
||||
{
|
||||
if (product == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (product.getSurcharges() != null)
|
||||
{
|
||||
product.getSurcharges().clear();
|
||||
}
|
||||
product.setSurchargeCount(0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 只导入其中一张产品表时,同一本里的高风险国家表仍挂回提到它的产品。
|
||||
* 整本目录解析走关联字段,不从这里再挂一次。
|
||||
@@ -1208,6 +1231,11 @@ public class LblWorkbookParser
|
||||
row++;
|
||||
}
|
||||
readFuelMark(grid, product);
|
||||
// 打单价卡导入:不落库产品表「附加费用/收费标准」等自动识别结果
|
||||
if (product.getSurcharges() != null)
|
||||
{
|
||||
product.getSurcharges().clear();
|
||||
}
|
||||
if (product.getWeightBands().isEmpty() && product.getSurcharges().isEmpty() && product.getExtraLines().isEmpty()
|
||||
&& postcodeHits(grid) >= 5)
|
||||
{
|
||||
@@ -3474,10 +3502,14 @@ public class LblWorkbookParser
|
||||
return;
|
||||
}
|
||||
String rule = fee.getCalcRule() == null ? "" : fee.getCalcRule().trim();
|
||||
if (rule.isEmpty() || LblSurchargeRules.MANUAL.equalsIgnoreCase(rule)
|
||||
|| LblSurchargeRules.ALWAYS.equalsIgnoreCase(rule))
|
||||
// 计费条件默认每票都收;旧 ITEM/等同义也归为 ALWAYS
|
||||
if (rule.isEmpty())
|
||||
{
|
||||
fee.setCalcRule("ITEM");
|
||||
fee.setCalcRule(LblSurchargeRules.ALWAYS);
|
||||
}
|
||||
else if ("ITEM".equalsIgnoreCase(rule) || "FLAT".equalsIgnoreCase(rule) || "FIXED".equalsIgnoreCase(rule))
|
||||
{
|
||||
fee.setCalcRule(LblSurchargeRules.ALWAYS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,8 @@ public interface LblProductMapper
|
||||
|
||||
int deleteAllVersionsBySetAndNo(@Param("priceSetId") Long priceSetId, @Param("versionNo") Integer versionNo);
|
||||
|
||||
int deleteVersionById(@Param("versionId") Long versionId);
|
||||
|
||||
List<LblProductVersion> selectVersionsBySet(@Param("priceSetId") Long priceSetId);
|
||||
|
||||
List<LblProductVersion> selectVersionsBySetAndNo(@Param("priceSetId") Long priceSetId,
|
||||
@@ -56,6 +58,8 @@ public interface LblProductMapper
|
||||
|
||||
int deleteWeightBandsByVersion(@Param("versionId") Long versionId);
|
||||
|
||||
int deleteWeightBandById(@Param("bandId") Long bandId);
|
||||
|
||||
List<LblWeightBand> selectWeightBandsByVersion(@Param("versionId") Long versionId);
|
||||
|
||||
int insertSurcharge(LblSurcharge surcharge);
|
||||
@@ -66,6 +70,8 @@ public interface LblProductMapper
|
||||
|
||||
int deleteSurchargesByVersion(@Param("versionId") Long versionId);
|
||||
|
||||
int deleteSurchargeById(@Param("surchargeId") Long surchargeId);
|
||||
|
||||
List<LblSurcharge> selectSurchargesByVersion(@Param("versionId") Long versionId);
|
||||
|
||||
List<Long> selectVersionIdsBySetAndProducts(@Param("priceSetId") Long priceSetId, @Param("productIds") Long[] productIds);
|
||||
@@ -82,4 +88,13 @@ public interface LblProductMapper
|
||||
|
||||
int expireOtherActive(@Param("priceSetId") Long priceSetId, @Param("versionNo") Integer versionNo,
|
||||
@Param("endDate") java.util.Date endDate, @Param("operator") String operator);
|
||||
|
||||
/** 恢复指定版本为生效:清空失效时间并将 status 置为 1 */
|
||||
int reopenVersionRows(@Param("priceSetId") Long priceSetId, @Param("versionNo") Integer versionNo,
|
||||
@Param("operator") String operator);
|
||||
|
||||
/** 按生效窗口写回失效时间与状态(整版号) */
|
||||
int updateVersionWindowBySetAndNo(@Param("priceSetId") Long priceSetId, @Param("versionNo") Integer versionNo,
|
||||
@Param("effectiveEnd") java.util.Date effectiveEnd, @Param("status") String status,
|
||||
@Param("operator") String operator);
|
||||
}
|
||||
@@ -122,7 +122,7 @@ public interface PayBillMapper
|
||||
* @param lineId 账单行ID
|
||||
* @return 影响行数
|
||||
*/
|
||||
int bindFeeLine(@Param("feeId") Long feeId, @Param("lineId") Long lineId);
|
||||
int bindFeeLine(@Param("feeId") String feeId, @Param("lineId") Long lineId);
|
||||
|
||||
/**
|
||||
* 释放一张账单占用的费用明细。
|
||||
|
||||
@@ -22,7 +22,7 @@ public interface PayFinanceMapper
|
||||
|
||||
Long selectLadingSupplier(@Param("ladingNo") String ladingNo);
|
||||
|
||||
int stampFee(@Param("feeId") Long feeId, @Param("supplierId") Long supplierId, @Param("supplierName") String supplierName);
|
||||
int stampFee(@Param("feeId") String feeId, @Param("supplierId") Long supplierId, @Param("supplierName") String supplierName);
|
||||
|
||||
int stampCalc(@Param("billId") Long billId, @Param("supplierId") Long supplierId, @Param("supplierName") String supplierName);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.bms.price.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import com.bms.common.core.domain.entity.SysUser;
|
||||
import com.bms.price.domain.PayOrderQuery;
|
||||
import com.bms.price.domain.PayOrderRow;
|
||||
|
||||
/** 应付列表。 */
|
||||
public interface PayOrderListMapper
|
||||
{
|
||||
/** 当前页的计费订单 ID,顺序就是列表顺序。 */
|
||||
List<Long> selectPageIds(PayOrderQuery query);
|
||||
|
||||
/** 按主键取出这一页的列表字段。 */
|
||||
List<PayOrderRow> selectByBillIds(@Param("billIds") List<Long> billIds);
|
||||
|
||||
/** 这一页更新人对应的账号和昵称。 */
|
||||
List<SysUser> selectUsers(@Param("userIds") List<Long> userIds, @Param("userNames") List<String> userNames);
|
||||
|
||||
PayOrderRow selectRow(@Param("billId") String billId);
|
||||
|
||||
/**
|
||||
* 按订单号精确找出要重算的订单。
|
||||
*
|
||||
* @param orderNos 订单号,已去重
|
||||
* @return 订单号和提单号
|
||||
*/
|
||||
List<PayOrderRow> selectByOrderNos(@Param("orderNos") List<String> orderNos);
|
||||
|
||||
/**
|
||||
* 按提单号找出下面的全部订单。提单号对应订单扩展上的空运单号。
|
||||
*
|
||||
* @param ladingNos 提单号,已去重
|
||||
* @return 这些提单下的订单
|
||||
*/
|
||||
List<PayOrderRow> selectByLadingNos(@Param("ladingNos") List<String> ladingNos);
|
||||
}
|
||||
@@ -67,6 +67,10 @@ public interface PayPostcodeMapper
|
||||
List<PayPostcodeGroup> selectRemoteGroupsByCountry(@Param("countryCode") String countryCode,
|
||||
@Param("countryName") String countryName);
|
||||
|
||||
/** 附加费邮编。compact 是去掉空格和符号后的订单邮编,用来按前几位缩小范围。 */
|
||||
List<PayPostcodeLine> selectSurchargeLines(@Param("countryCode") String countryCode,
|
||||
@Param("countryName") String countryName, @Param("compact") String compact);
|
||||
|
||||
List<PayPostcodeLine> selectRegionKeys(@Param("groupIds") List<Long> groupIds);
|
||||
|
||||
List<PayPostcodeLine> selectLinesByGroups(@Param("groupIds") List<Long> groupIds);
|
||||
|
||||
@@ -58,6 +58,10 @@ public interface PayProductMapper
|
||||
|
||||
int deleteSurchargesByTerm(@Param("termIds") List<Long> termIds);
|
||||
|
||||
int deleteSurchargesByTermSection(@Param("termId") Long termId, @Param("sectionName") String sectionName);
|
||||
|
||||
int refreshSurchargeCount(@Param("productId") Long productId);
|
||||
|
||||
int deleteExtraLinesByTerm(@Param("termIds") List<Long> termIds);
|
||||
|
||||
Long selectTemplateIdByType(@Param("dictValue") String dictValue, @Param("productType") String productType);
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
package com.bms.price.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import com.bms.price.domain.PaySurchargeRuleLog;
|
||||
|
||||
public interface PaySurchargeRuleLogMapper
|
||||
{
|
||||
List<PaySurchargeRuleLog> selectByTerm(@Param("productId") Long productId, @Param("termId") Long termId);
|
||||
|
||||
List<PaySurchargeRuleLog> selectByProductIds(@Param("productIds") List<Long> productIds);
|
||||
|
||||
int insertBatch(@Param("list") List<PaySurchargeRuleLog> list);
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package com.bms.price.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import com.bms.price.domain.PaySurchargeRule;
|
||||
|
||||
/** 应付附加费计费条件。一份跟产品走。 */
|
||||
public interface PaySurchargeRuleMapper
|
||||
{
|
||||
List<PaySurchargeRule> selectByProduct(@Param("productId") Long productId, @Param("termId") Long termId);
|
||||
|
||||
List<PaySurchargeRule> selectByProductId(@Param("productId") Long productId);
|
||||
|
||||
int deleteByTerm(@Param("productId") Long productId, @Param("termId") Long termId);
|
||||
|
||||
int deleteByProductIds(@Param("productIds") List<Long> productIds);
|
||||
|
||||
int insertBatch(@Param("list") List<PaySurchargeRule> rules);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.bms.price.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import com.bms.price.domain.PrcPayBillFeeLog;
|
||||
|
||||
/** 应付费用日志 prc_pay_bill_fee_log。 */
|
||||
public interface PrcPayBillFeeLogMapper
|
||||
{
|
||||
/**
|
||||
* 批量写入应付费用日志。
|
||||
*
|
||||
* @param logs 本次操作的费用快照
|
||||
* @return 影响行数
|
||||
*/
|
||||
int insertBatch(@Param("list") List<PrcPayBillFeeLog> logs);
|
||||
|
||||
/**
|
||||
* 按订单读取费用日志,新的在前。
|
||||
*
|
||||
* @param billId 计费订单 ID
|
||||
* @return 日志
|
||||
*/
|
||||
List<PrcPayBillFeeLog> selectByBillId(@Param("billId") Long billId);
|
||||
}
|
||||
@@ -15,6 +15,39 @@ public interface PrcPayBillFeeMapper
|
||||
*/
|
||||
public List<PrcPayBillFee> selectByBillId(Long billId);
|
||||
|
||||
/**
|
||||
* 按费用明细 ID 读取一行。已逻辑删除的也返回,调用方自己判断。
|
||||
*
|
||||
* @param feeId 费用明细 ID
|
||||
* @return 费用行,没有时为 null
|
||||
*/
|
||||
public PrcPayBillFee selectByFeeId(@Param("feeId") String feeId);
|
||||
|
||||
/**
|
||||
* 写入一条手工费用。来源固定为 MANUAL,并记下创建人、更新人。
|
||||
*
|
||||
* @param fee 费用项、金额、币种、说明和所属阶段
|
||||
* @return 影响行数
|
||||
*/
|
||||
public int insertManual(PrcPayBillFee fee);
|
||||
|
||||
/**
|
||||
* 逻辑删除一条费用。已经进入应付账单的行不删。
|
||||
*
|
||||
* @param feeId 费用明细 ID
|
||||
* @param operator 当前登录人
|
||||
* @return 影响行数
|
||||
*/
|
||||
public int markFeeDeleted(@Param("feeId") String feeId, @Param("operator") String operator);
|
||||
|
||||
/**
|
||||
* 这票订单里已经进入应付账单的计算费用条数。有则不能重算覆盖。
|
||||
*
|
||||
* @param billId 计费订单 ID
|
||||
* @return 已出账的计算费用条数
|
||||
*/
|
||||
public int countSettledCalc(@Param("billId") Long billId);
|
||||
|
||||
/**
|
||||
* 插入一条订单应付费用。
|
||||
*
|
||||
@@ -32,15 +65,17 @@ public interface PrcPayBillFeeMapper
|
||||
public int insertBatch(@Param("list") List<PrcPayBillFee> fees);
|
||||
|
||||
/** 把还没标明来源的费用,关联到本行主键 id。 */
|
||||
public int fillSourceIdByFeeIds(@Param("feeIds") List<Long> feeIds);
|
||||
public int fillSourceIdByFeeIds(@Param("feeIds") List<String> feeIds);
|
||||
|
||||
/**
|
||||
* 删除一票订单上来源为计算的费用。提单分摊和人工费用保留。
|
||||
* 逻辑删除一票订单上来源为计算的费用。提单分摊和人工费用保留。
|
||||
* 已进入应付账单的行不删。删除标记写成主键,避免重新生成时撞上唯一键。
|
||||
*
|
||||
* @param billId 计费订单ID
|
||||
* @param operator 操作人
|
||||
* @return 影响行数
|
||||
*/
|
||||
public int deleteByBillId(Long billId);
|
||||
public int markCalcDeleted(@Param("billId") Long billId, @Param("operator") String operator);
|
||||
|
||||
/**
|
||||
* 逻辑删除某一条提单费用分摊到订单上的明细。
|
||||
@@ -53,9 +88,15 @@ public interface PrcPayBillFeeMapper
|
||||
/** 这条提单费用已经分摊到的订单。作废前取出,用来重算应付总额。 */
|
||||
public List<Long> selectBillIdsByLadingFee(@Param("feeId") Long feeId);
|
||||
|
||||
/** 这条提单费用已经分摊、且还没删除的订单费用。作废前取出,用来记日志。 */
|
||||
public List<PrcPayBillFee> selectAliveByLadingFee(@Param("feeId") Long feeId);
|
||||
|
||||
/** 明细还没挂上应付主表时,按订单补上主表 ID。单次不超过 1000 个订单。 */
|
||||
public int bindPayBillId(@Param("billIds") List<Long> billIds);
|
||||
|
||||
/** 这些订单上未删除的应付明细。带上订单计费日,汇总时用来取汇率。 */
|
||||
public List<PrcPayBillFee> selectOpenFees(@Param("billIds") List<Long> billIds);
|
||||
|
||||
/**
|
||||
* 这条提单费用分摊到的订单里,取一个已经生成应付账单的订单号。
|
||||
* 是否出账看 prc_order_bill_ext.is_meet:1 已生成。
|
||||
|
||||
@@ -21,7 +21,7 @@ public interface PrcPayBillMapper
|
||||
* @param payBillId 订单应付ID
|
||||
* @return 订单应付,没有时为 null
|
||||
*/
|
||||
PrcPayBill selectByPayBillId(Long payBillId);
|
||||
PrcPayBill selectByPayBillId(String payBillId);
|
||||
|
||||
/**
|
||||
* 新增一票订单的应付主表。
|
||||
@@ -63,6 +63,21 @@ public interface PrcPayBillMapper
|
||||
*/
|
||||
int refreshPayTotal(@Param("billIds") List<Long> billIds);
|
||||
|
||||
/** 把折成人民币后的应付总额和 ABCD 段合计写到主表,明细金额和币种不动。 */
|
||||
int updateCnyPayTotal(PrcPayBill row);
|
||||
|
||||
/** 订单还没有应付主表时补一行,总额随后按明细重算。单次不超过 1000 个订单。 */
|
||||
int insertMissingPayBills(@Param("billIds") List<Long> billIds, @Param("operator") String operator);
|
||||
|
||||
/**
|
||||
* 写下这票应付的计费状态和失败原因。成功时原因传空。
|
||||
*
|
||||
* @param billId 计费订单 ID,对应 prc_pay_bill.bill_id
|
||||
* @param status 1计费成功,2计费失败
|
||||
* @param message 失败原因,最长 100 字;成功时为 null
|
||||
* @param operator 操作人账号
|
||||
* @return 影响行数
|
||||
*/
|
||||
int markCalcStatus(@Param("billId") Long billId, @Param("status") Integer status,
|
||||
@Param("message") String message, @Param("operator") String operator);
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ import com.bms.price.domain.vo.PrcProfitReportSummary;
|
||||
/** 毛利报表 mapper;金额事实取自 prc_income_bill。 */
|
||||
public interface PrcProfitReportMapper
|
||||
{
|
||||
List<Long> selectAreaCustomerIds(@Param("customerArea") String customerArea, @Param("limit") int limit);
|
||||
|
||||
List<PrcProfitReportOrderRow> selectOrderRows(PrcProfitReportQuery query);
|
||||
|
||||
List<PrcProfitReportProductRow> selectProductRows(PrcProfitReportQuery query);
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.bms.price.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import com.bms.price.domain.PrcSurchargeBind;
|
||||
|
||||
/**
|
||||
* 产品与附加费配置的关联。
|
||||
*/
|
||||
public interface PrcSurchargeBindMapper
|
||||
{
|
||||
List<PrcSurchargeBind> selectByProduct(@Param("productId") Long productId, @Param("productType") String productType);
|
||||
|
||||
List<PrcSurchargeBind> selectByProductIds(@Param("productIds") List<Long> productIds);
|
||||
|
||||
int deleteByProduct(@Param("productId") Long productId, @Param("productType") String productType);
|
||||
|
||||
int deleteByProductIds(@Param("productIds") List<Long> productIds);
|
||||
|
||||
int insertBinds(@Param("list") List<PrcSurchargeBind> list);
|
||||
|
||||
int rebindScId(@Param("oldScId") Long oldScId, @Param("newScId") Long newScId);
|
||||
}
|
||||
@@ -24,4 +24,10 @@ public interface PrcSurchargeMapper
|
||||
|
||||
/** 状态原地更新(不新增数据):停用置 of,版本化作废旧记录置 vd */
|
||||
public int updateSsCodeByIds(@Param("scIds") Long[] scIds, @Param("ssCode") String ssCode, @Param("operator") String operator);
|
||||
|
||||
/** 附加费改版后,应付价卡上的选择改指向新记录,并带上新的金额和说明。 */
|
||||
public int rebindPayConfig(@Param("oldScId") Long oldScId, @Param("newScId") Long newScId,
|
||||
@Param("feeName") String feeName, @Param("zoneName") String zoneName, @Param("amount") java.math.BigDecimal amount,
|
||||
@Param("currency") String currency, @Param("feeDesc") String feeDesc, @Param("calcRule") String calcRule,
|
||||
@Param("chargeText") String chargeText, @Param("priceUnit") String priceUnit);
|
||||
}
|
||||
|
||||
@@ -27,10 +27,16 @@ public interface PrcZoneDetailMapper
|
||||
|
||||
public int deletePrcZoneDetailByRegionId(Long regionId);
|
||||
|
||||
/**
|
||||
* 按国家 ISO2 + 邮编解析分区(先精确匹配,再取最长前缀)。
|
||||
*/
|
||||
public int deletePrcZoneDetailByProductId(Long productId);
|
||||
|
||||
/** 按国家 ISO2 + 邮编解析常规分区(先精确再最长前缀) */
|
||||
public PrcZone selectZoneByCountryPostcode(
|
||||
@Param("countryCode") String countryCode,
|
||||
@Param("postcode") String postcode);
|
||||
|
||||
/** 按打单产品 + 邮编解析 LABEL 分区(先精确再最长前缀) */
|
||||
public PrcZone selectZoneByProductPostcode(
|
||||
@Param("productId") Long productId,
|
||||
@Param("postcode") String postcode);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.bms.price.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.bms.price.domain.PrcZone;
|
||||
import com.bms.price.domain.PrcZoneLabelProduct;
|
||||
import com.bms.price.domain.PrcZoneRegion;
|
||||
|
||||
public interface PrcZoneMapper
|
||||
@@ -12,10 +13,14 @@ public interface PrcZoneMapper
|
||||
|
||||
public List<PrcZone> selectPrcZoneListByRegionId(Long regionId);
|
||||
|
||||
public List<PrcZone> selectPrcZoneListByProductId(Long productId);
|
||||
|
||||
public List<PrcZoneRegion> selectZoneRegionList(PrcZoneRegion query);
|
||||
|
||||
public PrcZoneRegion selectZoneRegionById(Long regionId);
|
||||
|
||||
public List<PrcZoneLabelProduct> selectLabelProductZoneList(PrcZoneLabelProduct query);
|
||||
|
||||
public int countByRegionId(Long regionId);
|
||||
|
||||
public int insertPrcZone(PrcZone zone);
|
||||
@@ -27,4 +32,6 @@ public interface PrcZoneMapper
|
||||
public int deletePrcZoneByRegionId(Long regionId);
|
||||
|
||||
public int deletePrcZoneByRegionIds(Long[] regionIds);
|
||||
|
||||
public int deletePrcZoneByProductId(Long productId);
|
||||
}
|
||||
|
||||
@@ -49,9 +49,11 @@ public class OracleOrderBillMapper
|
||||
String countryName = firstStr(row, "COUNTRY_NAME", "COUNTRY_EINGTH_NAME", "COUNTRY");
|
||||
req.setCountryName(countryName);
|
||||
req.setDestPostcode(StringUtils.normalizePostcode(firstStr(row, "CONSIGNEE_POSTCODE")));
|
||||
// 优先取 CONFIRM_WEIGHT(客户确认重量);回退取 DIMENSIONAL_WEIGHT_FACTOR(计费重量)。
|
||||
BigDecimal weight = firstPositiveDecimal(row, "CONFIRM_WEIGHT", "DIMENSIONAL_WEIGHT_FACTOR");
|
||||
// weight = 上游计费重 DIMENSIONAL_WEIGHT_FACTOR
|
||||
BigDecimal weight = firstPositiveDecimal(row, "DIMENSIONAL_WEIGHT_FACTOR");
|
||||
req.setWeight(weight);
|
||||
// charge_weight 仅在客户确认重 CONFIRM_WEIGHT 有值时落库
|
||||
req.setChargeWeight(firstPositiveDecimal(row, "CONFIRM_WEIGHT"));
|
||||
// TAB_ORDER.WEIGHT = 收货重
|
||||
req.setReceiveWeight(firstDecimal(row, "WEIGHT"));
|
||||
req.setActualWeight(firstPositiveDecimal(row, "ACTUAL_WEIGHT", "PUSH_WEIGHT", "WEIGHT"));
|
||||
|
||||
@@ -338,7 +338,7 @@ public final class LabelArCostCalculator
|
||||
String name = blank(fee.getFeeName());
|
||||
if (PaySurchargeRules.POSTCODE.equals(rule))
|
||||
{
|
||||
String param = blank(fee.getPostcodeParam()).isEmpty() ? fee.getCalcParam() : fee.getPostcodeParam();
|
||||
String param = PaySurchargeRules.feePostcodes(fee);
|
||||
if (postcode == null || postcode.isBlank())
|
||||
{
|
||||
result.getSkipped().add(name + ":订单没有邮编");
|
||||
@@ -358,9 +358,9 @@ public final class LabelArCostCalculator
|
||||
}
|
||||
else if (PaySurchargeRules.WEIGHT.equals(rule))
|
||||
{
|
||||
if (PaySurchargeRules.matchesWeight(fee.getCalcParam(), weight))
|
||||
if (PaySurchargeRules.matchesFeeWeight(fee, weight))
|
||||
{
|
||||
addFlat(result.getFees(), fee, currency, "计费重超过 " + fee.getCalcParam() + "kg");
|
||||
addFlat(result.getFees(), fee, currency, "计费重超过 " + PaySurchargeRules.weightText(fee) + "kg");
|
||||
}
|
||||
}
|
||||
// 超出尺寸费用
|
||||
@@ -370,7 +370,7 @@ public final class LabelArCostCalculator
|
||||
{
|
||||
result.getSkipped().add(name + ":订单没有长宽高");
|
||||
}
|
||||
else if (PaySurchargeRules.matchesSize(fee.getCalcParam(), length, width, height))
|
||||
else if (PaySurchargeRules.matchesFeeSize(fee, length, width, height))
|
||||
{
|
||||
PayCostLine matched = matchedFee(fee, freight, currency, "尺寸命中 " + fee.getCalcParam());
|
||||
if (matched != null)
|
||||
@@ -423,34 +423,7 @@ public final class LabelArCostCalculator
|
||||
result.getSkipped().add(name + ":价卡没有可计算的条件,暂不计费");
|
||||
}
|
||||
}
|
||||
result.getFees().addAll(keepHighestByName(sized));
|
||||
}
|
||||
|
||||
/** 同一费用名的尺寸档同时命中时,只收较高的一档,例如 70% 覆盖 35%。 */
|
||||
private static List<PayCostLine> keepHighestByName(List<PayCostLine> lines)
|
||||
{
|
||||
List<PayCostLine> kept = new ArrayList<>();
|
||||
for (PayCostLine line : lines)
|
||||
{
|
||||
PayCostLine same = null;
|
||||
for (PayCostLine exists : kept)
|
||||
{
|
||||
if (exists.getFeeName().equals(line.getFeeName()))
|
||||
{
|
||||
same = exists;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (same == null)
|
||||
{
|
||||
kept.add(line);
|
||||
}
|
||||
else if (line.getAmount().compareTo(same.getAmount()) > 0)
|
||||
{
|
||||
kept.set(kept.indexOf(same), line);
|
||||
}
|
||||
}
|
||||
return kept;
|
||||
result.getFees().addAll(sized);
|
||||
}
|
||||
|
||||
private static void addExtraKg(List<PayCostLine> fees, PaySurcharge fee, BigDecimal weight, String currency)
|
||||
@@ -459,12 +432,8 @@ public final class LabelArCostCalculator
|
||||
{
|
||||
return;
|
||||
}
|
||||
BigDecimal threshold;
|
||||
try
|
||||
{
|
||||
threshold = new BigDecimal(fee.getCalcParam() == null ? "" : fee.getCalcParam().trim());
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
BigDecimal threshold = PaySurchargeRules.extraStartKg(fee);
|
||||
if (threshold == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -477,13 +446,43 @@ public final class LabelArCostCalculator
|
||||
{
|
||||
return;
|
||||
}
|
||||
BigDecimal steps = PaySurchargeRules.extraSteps(fee, weight);
|
||||
if (steps.compareTo(BigDecimal.ZERO) <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
BigDecimal over = weight.subtract(threshold);
|
||||
BigDecimal amount = fee.getAmount().multiply(over).setScale(2, RoundingMode.HALF_UP);
|
||||
BigDecimal amount = fee.getAmount().multiply(steps).setScale(2, RoundingMode.HALF_UP);
|
||||
String billed = plain(steps.multiply(PaySurchargeRules.extraStepKg(fee)));
|
||||
PayCostLine freightLine = freightLine(fees);
|
||||
if (freightLine != null && "每公斤续重".equals(blank(fee.getFeeName())))
|
||||
{
|
||||
freightLine.setAmount(freightLine.getAmount().add(amount).setScale(2, RoundingMode.HALF_UP));
|
||||
String remark = blank(freightLine.getRemark());
|
||||
freightLine.setRemark((remark.isEmpty() ? "" : remark + ";") + "续重 " + billed + "kg × " + plain(fee.getAmount()));
|
||||
return;
|
||||
}
|
||||
long scId = fee.getSurchargeId() == null ? 0L : fee.getSurchargeId();
|
||||
String remark = "超出 " + plain(over) + "kg × " + plain(fee.getAmount()) + " " + blank(fee.getPriceUnit());
|
||||
String remark = "超出 " + plain(over) + "kg,按 " + billed + "kg × " + plain(fee.getAmount()) + " " + blank(fee.getPriceUnit());
|
||||
fees.add(line("SURCHARGE", blank(fee.getFeeName()), scId, amount, currency, remark));
|
||||
}
|
||||
|
||||
private static PayCostLine freightLine(List<PayCostLine> fees)
|
||||
{
|
||||
if (fees == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
for (PayCostLine row : fees)
|
||||
{
|
||||
if (row != null && "BASIC_FREIGHT".equals(row.getFeeType()))
|
||||
{
|
||||
return row;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** 同一地区有多张服务表时,续重只跟本次首重所在的那一张表。 */
|
||||
private static boolean sameSection(String feeSection, String freightSection)
|
||||
{
|
||||
@@ -517,16 +516,10 @@ public final class LabelArCostCalculator
|
||||
{
|
||||
continue;
|
||||
}
|
||||
try
|
||||
BigDecimal start = PaySurchargeRules.extraStartKg(fee);
|
||||
if (start != null && start.compareTo(threshold) == 0)
|
||||
{
|
||||
if (fee.getCalcParam() != null && new BigDecimal(fee.getCalcParam().trim()).compareTo(threshold) == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
continue;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@@ -593,11 +586,7 @@ public final class LabelArCostCalculator
|
||||
/** 价卡这一档写了邮编时,订单邮编必须落在里面。续重的重量门槛不算邮编。 */
|
||||
private static boolean feePostcodeMatches(PaySurcharge fee, String rule, String postcode)
|
||||
{
|
||||
String param = blank(fee.getPostcodeParam());
|
||||
if (param.isEmpty() && !PaySurchargeRules.EXTRA_KG.equals(rule))
|
||||
{
|
||||
param = blank(fee.getCalcParam());
|
||||
}
|
||||
String param = PaySurchargeRules.EXTRA_KG.equals(rule) ? blank(fee.getPostcodeParam()) : PaySurchargeRules.feePostcodes(fee);
|
||||
if (param.isEmpty())
|
||||
{
|
||||
return false;
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.bms.price.pay;
|
||||
|
||||
/**
|
||||
* 应付价卡的三种计费模式,对应字典 order_charge_type 的键值。
|
||||
*/
|
||||
public final class PayChargeMode
|
||||
{
|
||||
private PayChargeMode()
|
||||
{
|
||||
}
|
||||
|
||||
/** 单价乘以公斤重 */
|
||||
public static final String PER_KG = "PER_KG";
|
||||
|
||||
/** 重量段内按票收取固定金额 */
|
||||
public static final String FLAT = "FLAT";
|
||||
|
||||
/** 首重一口价,超出部分按每公斤续重 */
|
||||
public static final String EXTRA = "EXTRA";
|
||||
|
||||
/**
|
||||
* 把字典键、中文名和历史名称收成这三种键值。认不出时返回空字符串。
|
||||
*
|
||||
* @param raw 页面或库里的计费模式
|
||||
* @return PER_KG、FLAT、EXTRA 之一,空表示不是这三种
|
||||
*/
|
||||
public static String code(String raw)
|
||||
{
|
||||
if (raw == null)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
String text = raw.trim();
|
||||
if (text.isEmpty())
|
||||
{
|
||||
return "";
|
||||
}
|
||||
if (PER_KG.equalsIgnoreCase(text) || "常规计费".equals(text) || "常规计重价".equals(text))
|
||||
{
|
||||
return PER_KG;
|
||||
}
|
||||
if (FLAT.equalsIgnoreCase(text) || "一口价".equals(text) || "单票价".equals(text))
|
||||
{
|
||||
return FLAT;
|
||||
}
|
||||
if (EXTRA.equalsIgnoreCase(text) || "续重价".equals(text) || "续重计费".equals(text))
|
||||
{
|
||||
return EXTRA;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* 字典上的显示名。
|
||||
*
|
||||
* @param raw 计费模式键值或历史名称
|
||||
* @return 常规计费、一口价、续重价;认不出时退回原文
|
||||
*/
|
||||
public static String label(String raw)
|
||||
{
|
||||
String mode = code(raw);
|
||||
if (PER_KG.equals(mode))
|
||||
{
|
||||
return "常规计费";
|
||||
}
|
||||
if (FLAT.equals(mode))
|
||||
{
|
||||
return "一口价";
|
||||
}
|
||||
if (EXTRA.equals(mode))
|
||||
{
|
||||
return "续重价";
|
||||
}
|
||||
return raw == null ? "" : raw.trim();
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user