1
This commit is contained in:
@@ -5,6 +5,7 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@@ -16,6 +17,7 @@ import com.ruoyi.jarvis.domain.GroupRebateExcelUpload;
|
||||
import com.ruoyi.jarvis.domain.OrderRows;
|
||||
import com.ruoyi.jarvis.service.IGroupRebateExcelUploadService;
|
||||
import com.ruoyi.jarvis.service.impl.GroupRebateExcelImportService;
|
||||
import com.ruoyi.jarvis.service.impl.RebateSheetConvertService;
|
||||
import com.ruoyi.jarvis.service.IOrderRowsService;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
@@ -67,6 +69,7 @@ public class JDOrderListController extends BaseController
|
||||
private final IOrderRowsService orderRowsService;
|
||||
private final IInstructionService instructionService;
|
||||
private final GroupRebateExcelImportService groupRebateExcelImportService;
|
||||
private final RebateSheetConvertService rebateSheetConvertService;
|
||||
private final IGroupRebateExcelUploadService groupRebateExcelUploadService;
|
||||
|
||||
private final ObjectMapper objectMapper;
|
||||
@@ -77,6 +80,7 @@ public class JDOrderListController extends BaseController
|
||||
IOrderRowsService orderRowsService,
|
||||
IInstructionService instructionService,
|
||||
GroupRebateExcelImportService groupRebateExcelImportService,
|
||||
RebateSheetConvertService rebateSheetConvertService,
|
||||
IGroupRebateExcelUploadService groupRebateExcelUploadService,
|
||||
ObjectMapper objectMapper,
|
||||
ISysConfigService sysConfigService,
|
||||
@@ -86,6 +90,7 @@ public class JDOrderListController extends BaseController
|
||||
this.orderRowsService = orderRowsService;
|
||||
this.instructionService = instructionService;
|
||||
this.groupRebateExcelImportService = groupRebateExcelImportService;
|
||||
this.rebateSheetConvertService = rebateSheetConvertService;
|
||||
this.groupRebateExcelUploadService = groupRebateExcelUploadService;
|
||||
this.objectMapper = objectMapper;
|
||||
this.sysConfigService = sysConfigService;
|
||||
@@ -261,6 +266,49 @@ public class JDOrderListController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传旧返现表,按订单号匹配系统订单,下载新表头 Excel。
|
||||
* 旧表头:日期、单号、型号、总共返现。
|
||||
* 新表头:日期、订单编号、型号、数量、成本价、实付价、后返金额。
|
||||
*/
|
||||
@Log(title = "返现表转换新表头", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/convertRebateExcel")
|
||||
public void convertRebateExcel(@RequestParam("file") MultipartFile file, HttpServletResponse response) throws IOException {
|
||||
if (file == null || file.isEmpty()) {
|
||||
writeJson(response, AjaxResult.error("请选择文件"));
|
||||
return;
|
||||
}
|
||||
String name = file.getOriginalFilename();
|
||||
if (name != null) {
|
||||
String lower = name.toLowerCase(Locale.ROOT);
|
||||
if (!lower.endsWith(".xls") && !lower.endsWith(".xlsx")) {
|
||||
writeJson(response, AjaxResult.error("请上传 xls 或 xlsx 文件"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
try {
|
||||
RebateSheetConvertService.Result result = rebateSheetConvertService.convert(file.getInputStream());
|
||||
if (result.getErrorMessage() != null) {
|
||||
writeJson(response, AjaxResult.error(result.getErrorMessage()));
|
||||
return;
|
||||
}
|
||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
FileUtils.setAttachmentResponseHeader(response, result.getFilename());
|
||||
String summary = String.format(Locale.ROOT, "共%d行,已匹配%d,未找到订单%d,单号为空%d",
|
||||
result.getTotalRows(), result.getMatched(), result.getUnmatched(), result.getBlankOrder());
|
||||
response.setHeader("x-convert-summary", FileUtils.percentEncode(summary));
|
||||
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition,download-filename,x-convert-summary");
|
||||
response.getOutputStream().write(result.getContent());
|
||||
} catch (Exception e) {
|
||||
writeJson(response, AjaxResult.error("转换失败: " + e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
private void writeJson(HttpServletResponse response, AjaxResult body) throws IOException {
|
||||
response.setContentType(MediaType.APPLICATION_JSON_VALUE + ";charset=UTF-8");
|
||||
response.getWriter().write(JSON.toJSONString(body));
|
||||
}
|
||||
|
||||
/**
|
||||
* 后返表上传记录(分页)
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user