|
|
@@ -48,24 +48,70 @@ public class AdminSupplierController {
|
|
|
return Result.success(data);
|
|
|
}
|
|
|
|
|
|
- @Operation(summary = "新增供应商")
|
|
|
+ @Operation(summary = "新增供应商(兼容新旧字段契约)")
|
|
|
@PostMapping("/save")
|
|
|
- public Result<EcomSupplier> save(@RequestBody EcomSupplier supplier) {
|
|
|
+ public Result<EcomSupplier> save(@RequestBody Map<String, Object> body) {
|
|
|
+ EcomSupplier supplier = new EcomSupplier();
|
|
|
+ applyFields(supplier, body);
|
|
|
+ if (supplier.getName() == null || supplier.getName().trim().isEmpty()) {
|
|
|
+ return Result.error("供应商名称不能为空");
|
|
|
+ }
|
|
|
supplier.setCreatedAt(new Date());
|
|
|
supplier.setUpdatedAt(new Date());
|
|
|
ecomSupplierMapper.insert(supplier);
|
|
|
return Result.success(supplier);
|
|
|
}
|
|
|
|
|
|
- @Operation(summary = "更新供应商")
|
|
|
+ @Operation(summary = "更新供应商(兼容新旧字段契约)")
|
|
|
@PostMapping("/update")
|
|
|
- public Result<String> update(@RequestBody EcomSupplier supplier) {
|
|
|
- if (supplier.getId() == null) return Result.error("id不能为空");
|
|
|
+ public Result<String> update(@RequestBody Map<String, Object> body) {
|
|
|
+ Long id = ParamUtils.getLong(body.get("id"));
|
|
|
+ if (id == null) return Result.error("id不能为空");
|
|
|
+ EcomSupplier supplier = ecomSupplierMapper.selectById(id);
|
|
|
+ if (supplier == null) return Result.error("供应商不存在");
|
|
|
+ applyFields(supplier, body);
|
|
|
supplier.setUpdatedAt(new Date());
|
|
|
ecomSupplierMapper.updateById(supplier);
|
|
|
return Result.success("ok");
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 字段契约兼容:前端表单提交 {phone,nickname,realName,vendorType,vendorStatus},
|
|
|
+ * 库表字段为 {name,contactName,contactPhone,status,remark}。新旧字段都接受,新字段优先。
|
|
|
+ */
|
|
|
+ private void applyFields(EcomSupplier supplier, Map<String, Object> body) {
|
|
|
+ String name = str(body, "nickname", body.get("name"));
|
|
|
+ if (name != null) supplier.setName(name);
|
|
|
+ String contactName = str(body, "realName", body.get("contactName"));
|
|
|
+ if (contactName != null) supplier.setContactName(contactName);
|
|
|
+ String contactPhone = str(body, "phone", body.get("contactPhone"));
|
|
|
+ if (contactPhone != null) supplier.setContactPhone(contactPhone);
|
|
|
+ String remark = str(body, "remark", null);
|
|
|
+ if (remark != null) supplier.setRemark(remark);
|
|
|
+ Object vendorStatus = body.get("vendorStatus") != null ? body.get("vendorStatus") : body.get("status");
|
|
|
+ if (vendorStatus != null) {
|
|
|
+ supplier.setStatus(parseStatus(vendorStatus));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String str(Map<String, Object> body, String key, Object fallback) {
|
|
|
+ Object v = body.get(key);
|
|
|
+ if (v == null) v = fallback;
|
|
|
+ return v != null ? v.toString() : null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Integer parseStatus(Object v) {
|
|
|
+ if (v instanceof Number) return ((Number) v).intValue();
|
|
|
+ String s = v.toString().trim();
|
|
|
+ if ("active".equalsIgnoreCase(s) || "enabled".equalsIgnoreCase(s) || "1".equals(s)) return 1;
|
|
|
+ if ("pending".equalsIgnoreCase(s) || "disabled".equalsIgnoreCase(s) || "0".equals(s)) return 0;
|
|
|
+ try {
|
|
|
+ return Integer.valueOf(s);
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Operation(summary = "删除供应商")
|
|
|
@PostMapping("/delete")
|
|
|
public Result<String> delete(@RequestBody Map<String, Object> params) {
|