This commit is contained in:
van
2026-05-17 18:09:35 +08:00
parent 8770ea92ed
commit 77776802f2
2 changed files with 52 additions and 6 deletions

View File

@@ -9,6 +9,9 @@ import java.util.Map;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; 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.GroupRebateExcelUpload;
import com.ruoyi.jarvis.domain.OrderRows; import com.ruoyi.jarvis.domain.OrderRows;
import com.ruoyi.jarvis.service.IGroupRebateExcelUploadService; import com.ruoyi.jarvis.service.IGroupRebateExcelUploadService;
@@ -50,17 +53,21 @@ public class JDOrderListController extends BaseController
private final GroupRebateExcelImportService groupRebateExcelImportService; private final GroupRebateExcelImportService groupRebateExcelImportService;
private final IGroupRebateExcelUploadService groupRebateExcelUploadService; private final IGroupRebateExcelUploadService groupRebateExcelUploadService;
private final ObjectMapper objectMapper;
public JDOrderListController(IJDOrderService jdOrderService, IJDOrderProfitService jdOrderProfitService, public JDOrderListController(IJDOrderService jdOrderService, IJDOrderProfitService jdOrderProfitService,
IOrderRowsService orderRowsService, IOrderRowsService orderRowsService,
IInstructionService instructionService, IInstructionService instructionService,
GroupRebateExcelImportService groupRebateExcelImportService, GroupRebateExcelImportService groupRebateExcelImportService,
IGroupRebateExcelUploadService groupRebateExcelUploadService) { IGroupRebateExcelUploadService groupRebateExcelUploadService,
ObjectMapper objectMapper) {
this.jdOrderService = jdOrderService; this.jdOrderService = jdOrderService;
this.jdOrderProfitService = jdOrderProfitService; this.jdOrderProfitService = jdOrderProfitService;
this.orderRowsService = orderRowsService; this.orderRowsService = orderRowsService;
this.instructionService = instructionService; this.instructionService = instructionService;
this.groupRebateExcelImportService = groupRebateExcelImportService; this.groupRebateExcelImportService = groupRebateExcelImportService;
this.groupRebateExcelUploadService = groupRebateExcelUploadService; this.groupRebateExcelUploadService = groupRebateExcelUploadService;
this.objectMapper = objectMapper;
} }
/** /**
@@ -292,15 +299,53 @@ public class JDOrderListController extends BaseController
} }
/** /**
* 修改JD订单 * 修改JD订单PUT body 使用 JsonNodeextraCost / extra_cost 从原始 JSON 显式写入实体,
* 避免个别 Jackson + Lombok 场景下 treeToValue 未映射导致重算利润仍按 0 计算)
*/ */
@Log(title = "JD订单", businessType = BusinessType.UPDATE) @Log(title = "JD订单", businessType = BusinessType.UPDATE)
@PutMapping @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); jdOrderProfitService.recalculate(jdOrder);
jdOrder.getParams().put("applyProfitFields", Boolean.TRUE); 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;
} }
/** /**

View File

@@ -221,13 +221,14 @@
<if test="reviewPostedDate != null"> review_posted_date = #{reviewPostedDate},</if> <if test="reviewPostedDate != null"> review_posted_date = #{reviewPostedDate},</if>
<if test="rebateRemarkJson != null"> rebate_remark_json = #{rebateRemarkJson},</if> <if test="rebateRemarkJson != null"> rebate_remark_json = #{rebateRemarkJson},</if>
<if test="rebateRemarkHasAbnormal != null"> rebate_remark_has_abnormal = #{rebateRemarkHasAbnormal},</if> <if test="rebateRemarkHasAbnormal != null"> rebate_remark_has_abnormal = #{rebateRemarkHasAbnormal},</if>
<if test="extraCost != null"> extra_cost = #{extraCost},</if> <!-- extra_cost:随列表保存一并写入 applyProfitFields避免仅写了 profit 却未持久化额外成本 -->
<if test="params != null and params.applyProfitFields != null and params.applyProfitFields == true"> <if test="params != null and params.applyProfitFields != null and params.applyProfitFields == true">
selling_price_type = #{sellingPriceType,jdbcType=VARCHAR}, selling_price_type = #{sellingPriceType,jdbcType=VARCHAR},
selling_price = #{sellingPrice,jdbcType=DOUBLE}, selling_price = #{sellingPrice,jdbcType=DOUBLE},
profit = #{profit,jdbcType=DOUBLE}, profit = #{profit,jdbcType=DOUBLE},
selling_price_manual = #{sellingPriceManual,jdbcType=INTEGER}, selling_price_manual = #{sellingPriceManual,jdbcType=INTEGER},
profit_manual = #{profitManual,jdbcType=INTEGER}, profit_manual = #{profitManual,jdbcType=INTEGER},
extra_cost = COALESCE(#{extraCost,jdbcType=DOUBLE}, 0),
</if> </if>
update_time = now() update_time = now()
</set> </set>