1
This commit is contained in:
@@ -9,6 +9,9 @@ import java.util.Map;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.ruoyi.jarvis.domain.GroupRebateExcelUpload;
|
||||
import com.ruoyi.jarvis.domain.OrderRows;
|
||||
import com.ruoyi.jarvis.service.IGroupRebateExcelUploadService;
|
||||
@@ -50,17 +53,21 @@ public class JDOrderListController extends BaseController
|
||||
private final GroupRebateExcelImportService groupRebateExcelImportService;
|
||||
private final IGroupRebateExcelUploadService groupRebateExcelUploadService;
|
||||
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
public JDOrderListController(IJDOrderService jdOrderService, IJDOrderProfitService jdOrderProfitService,
|
||||
IOrderRowsService orderRowsService,
|
||||
IInstructionService instructionService,
|
||||
GroupRebateExcelImportService groupRebateExcelImportService,
|
||||
IGroupRebateExcelUploadService groupRebateExcelUploadService) {
|
||||
IGroupRebateExcelUploadService groupRebateExcelUploadService,
|
||||
ObjectMapper objectMapper) {
|
||||
this.jdOrderService = jdOrderService;
|
||||
this.jdOrderProfitService = jdOrderProfitService;
|
||||
this.orderRowsService = orderRowsService;
|
||||
this.instructionService = instructionService;
|
||||
this.groupRebateExcelImportService = groupRebateExcelImportService;
|
||||
this.groupRebateExcelUploadService = groupRebateExcelUploadService;
|
||||
this.objectMapper = objectMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -292,15 +299,53 @@ public class JDOrderListController extends BaseController
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改JD订单
|
||||
* 修改JD订单(PUT body 使用 JsonNode:extraCost / extra_cost 从原始 JSON 显式写入实体,
|
||||
* 避免个别 Jackson + Lombok 场景下 treeToValue 未映射导致重算利润仍按 0 计算)
|
||||
*/
|
||||
@Log(title = "JD订单", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody JDOrder jdOrder)
|
||||
{
|
||||
public AjaxResult edit(@RequestBody JsonNode root) throws JsonProcessingException {
|
||||
JDOrder jdOrder = objectMapper.treeToValue(root, JDOrder.class);
|
||||
applyExtraCostFromPayload(root, jdOrder);
|
||||
jdOrderProfitService.recalculate(jdOrder);
|
||||
jdOrder.getParams().put("applyProfitFields", Boolean.TRUE);
|
||||
return toAjax(jdOrderService.updateJDOrder(jdOrder));
|
||||
int rows = jdOrderService.updateJDOrder(jdOrder);
|
||||
if (rows <= 0) {
|
||||
return AjaxResult.error("更新失败或订单不存在");
|
||||
}
|
||||
return AjaxResult.success(jdOrderService.selectJDOrderById(jdOrder.getId()));
|
||||
}
|
||||
|
||||
private static void applyExtraCostFromPayload(JsonNode root, JDOrder order) {
|
||||
if (root == null || order == null) {
|
||||
return;
|
||||
}
|
||||
JsonNode n = root.get("extraCost");
|
||||
if (readExtraCostNumber(n, order)) {
|
||||
return;
|
||||
}
|
||||
n = root.get("extra_cost");
|
||||
readExtraCostNumber(n, order);
|
||||
}
|
||||
|
||||
/** @return true 已从节点解析并写入 order */
|
||||
private static boolean readExtraCostNumber(JsonNode n, JDOrder order) {
|
||||
if (n == null || n.isNull()) {
|
||||
return false;
|
||||
}
|
||||
if (n.isNumber()) {
|
||||
order.setExtraCost(n.asDouble());
|
||||
return true;
|
||||
}
|
||||
if (n.isTextual()) {
|
||||
try {
|
||||
order.setExtraCost(Double.parseDouble(n.asText().trim()));
|
||||
return true;
|
||||
} catch (NumberFormatException ignored) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user