|
|
@@ -42,8 +42,33 @@ public class AdminPurchaseFieldController {
|
|
|
@PostMapping("/save")
|
|
|
public Result<Void> save(@RequestBody Map<String, Object> params) {
|
|
|
Long productId = Long.parseLong(params.get("productId").toString());
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
- List<ProductPurchaseField> fields = (List<ProductPurchaseField>) params.get("fields");
|
|
|
+ List<ProductPurchaseField> fields = convertFieldList(params.get("fields"));
|
|
|
return purchaseFieldService.save(productId, fields);
|
|
|
}
|
|
|
-}
|
|
|
+
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ private List<ProductPurchaseField> convertFieldList(Object raw) {
|
|
|
+ if (raw == null || !(raw instanceof List)) {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ List<Map<String, Object>> mapList = (List<Map<String, Object>>) raw;
|
|
|
+ List<ProductPurchaseField> list = new ArrayList<>();
|
|
|
+ for (Map<String, Object> m : mapList) {
|
|
|
+ ProductPurchaseField f = new ProductPurchaseField();
|
|
|
+ f.setFieldKey(strVal(m.get("fieldKey")));
|
|
|
+ f.setFieldName(strVal(m.get("fieldName")));
|
|
|
+ f.setIsRequired(intVal(m.get("isRequired")));
|
|
|
+ f.setSortOrder(intVal(m.get("sortOrder")));
|
|
|
+ list.add(f);
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String strVal(Object v) {
|
|
|
+ return v != null ? v.toString() : null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Integer intVal(Object v) {
|
|
|
+ return v != null ? Integer.parseInt(v.toString()) : null;
|
|
|
+ }
|
|
|
+}
|