|
@@ -0,0 +1,74 @@
|
|
|
|
|
+package com.etotem.cfc.controller.admin;
|
|
|
|
|
+
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
+import com.etotem.cfc.common.Result;
|
|
|
|
|
+import com.etotem.cfc.entity.EcomSupplier;
|
|
|
|
|
+import com.etotem.cfc.mapper.EcomSupplierMapper;
|
|
|
|
|
+import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
|
+import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
+
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
|
+import java.util.Date;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+
|
|
|
|
|
+@Tag(name = "管理端-电商供应商管理")
|
|
|
|
|
+@RestController
|
|
|
|
|
+@RequestMapping("/api/admin/supplier")
|
|
|
|
|
+public class AdminSupplierController {
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private EcomSupplierMapper ecomSupplierMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "供应商列表")
|
|
|
|
|
+ @PostMapping("/list")
|
|
|
|
|
+ public Result<Map<String, Object>> list(@RequestBody Map<String, Object> params) {
|
|
|
|
|
+ int page = params.get("page") != null ? ((Number) params.get("page")).intValue() : 1;
|
|
|
|
|
+ int size = params.get("size") != null ? ((Number) params.get("size")).intValue() : 20;
|
|
|
|
|
+ String keyword = (String) params.get("keyword");
|
|
|
|
|
+
|
|
|
|
|
+ Page<EcomSupplier> pageParam = new Page<>(page, size);
|
|
|
|
|
+ LambdaQueryWrapper<EcomSupplier> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ if (keyword != null && !keyword.isEmpty()) {
|
|
|
|
|
+ wrapper.like(EcomSupplier::getName, keyword);
|
|
|
|
|
+ }
|
|
|
|
|
+ wrapper.orderByDesc(EcomSupplier::getCreatedAt);
|
|
|
|
|
+ Page<EcomSupplier> result = ecomSupplierMapper.selectPage(pageParam, wrapper);
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, Object> data = new HashMap<>();
|
|
|
|
|
+ data.put("records", result.getRecords());
|
|
|
|
|
+ data.put("total", result.getTotal());
|
|
|
|
|
+ data.put("page", page);
|
|
|
|
|
+ data.put("size", size);
|
|
|
|
|
+ return Result.success(data);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "新增供应商")
|
|
|
|
|
+ @PostMapping("/save")
|
|
|
|
|
+ public Result<EcomSupplier> save(@RequestBody EcomSupplier supplier) {
|
|
|
|
|
+ supplier.setCreatedAt(new Date());
|
|
|
|
|
+ supplier.setUpdatedAt(new Date());
|
|
|
|
|
+ ecomSupplierMapper.insert(supplier);
|
|
|
|
|
+ return Result.success(supplier);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "更新供应商")
|
|
|
|
|
+ @PostMapping("/update")
|
|
|
|
|
+ public Result<String> update(@RequestBody EcomSupplier supplier) {
|
|
|
|
|
+ if (supplier.getId() == null) return Result.error("id不能为空");
|
|
|
|
|
+ supplier.setUpdatedAt(new Date());
|
|
|
|
|
+ ecomSupplierMapper.updateById(supplier);
|
|
|
|
|
+ return Result.success("ok");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "删除供应商")
|
|
|
|
|
+ @PostMapping("/delete")
|
|
|
|
|
+ public Result<String> delete(@RequestBody Map<String, Object> params) {
|
|
|
|
|
+ Long id = params.get("id") != null ? Long.valueOf(params.get("id").toString()) : null;
|
|
|
|
|
+ if (id == null) return Result.error("id不能为空");
|
|
|
|
|
+ ecomSupplierMapper.deleteById(id);
|
|
|
|
|
+ return Result.success("ok");
|
|
|
|
|
+ }
|
|
|
|
|
+}
|