|
@@ -490,6 +490,10 @@ public class BrandRecommendService {
|
|
|
* Newlines inside "..." quoted fields do NOT split rows. */
|
|
* Newlines inside "..." quoted fields do NOT split rows. */
|
|
|
private static List<String[]> parseCsv(String csv) {
|
|
private static List<String[]> parseCsv(String csv) {
|
|
|
List<String[]> rows = new ArrayList<>();
|
|
List<String[]> rows = new ArrayList<>();
|
|
|
|
|
+ // Strip UTF-8 BOM if present (Excel adds it when saving UTF-8 CSV)
|
|
|
|
|
+ if (csv.startsWith("")) {
|
|
|
|
|
+ csv = csv.substring(1);
|
|
|
|
|
+ }
|
|
|
csv = csv.replace("\r\n", "\n").replace("\r", "\n");
|
|
csv = csv.replace("\r\n", "\n").replace("\r", "\n");
|
|
|
|
|
|
|
|
// Split into logical lines: \n inside a quoted field stays part of the cell value
|
|
// Split into logical lines: \n inside a quoted field stays part of the cell value
|
|
@@ -611,22 +615,20 @@ public class BrandRecommendService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private static String str(Map<String, Object> body, String key) {
|
|
private static String str(Map<String, Object> body, String key) {
|
|
|
- return Optional.ofNullable(body.get(key))
|
|
|
|
|
- .map(Object::toString).map(String::trim)
|
|
|
|
|
- .filter(s -> !s.isEmpty())
|
|
|
|
|
- .orElse(null);
|
|
|
|
|
|
|
+ Object value = body.get(key);
|
|
|
|
|
+ if (value == null) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ String s = value.toString().trim();
|
|
|
|
|
+ return s.isEmpty() ? "" : s;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private static String nullToEmpty(String s) { return s != null ? s : ""; }
|
|
private static String nullToEmpty(String s) { return s != null ? s : ""; }
|
|
|
|
|
|
|
|
private static void applyStr(Map<String, Object> body, String key, Consumer<String> setter) {
|
|
private static void applyStr(Map<String, Object> body, String key, Consumer<String> setter) {
|
|
|
- Optional.ofNullable(body.get(key))
|
|
|
|
|
- .ifPresent(v -> {
|
|
|
|
|
- String s = v.toString().trim();
|
|
|
|
|
- if (!s.isEmpty()) {
|
|
|
|
|
- setter.accept(s);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ if (body.containsKey(key)) {
|
|
|
|
|
+ setter.accept(str(body, key));
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private static String cell(String[] cols, Map<String, Integer> colIdx, String header) {
|
|
private static String cell(String[] cols, Map<String, Integer> colIdx, String header) {
|