|
|
@@ -1,9 +1,10 @@
|
|
|
package com.haha.admin.controller;
|
|
|
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.haha.admin.dto.ShopQueryDTO;
|
|
|
import com.haha.common.annotation.Log;
|
|
|
import com.haha.common.enums.OperationType;
|
|
|
+import com.haha.common.vo.PageResult;
|
|
|
import com.haha.common.vo.Result;
|
|
|
import com.haha.entity.Shop;
|
|
|
import com.haha.entity.Device;
|
|
|
@@ -13,8 +14,8 @@ import com.haha.service.ShopService;
|
|
|
import com.haha.service.DeviceService;
|
|
|
import com.haha.service.ShopReplenisherService;
|
|
|
import com.haha.service.AdminService;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
@@ -27,55 +28,31 @@ import java.util.Map;
|
|
|
@Slf4j
|
|
|
@RestController
|
|
|
@RequestMapping("/shops")
|
|
|
+@RequiredArgsConstructor
|
|
|
public class ShopController {
|
|
|
|
|
|
- @Autowired
|
|
|
- private ShopService shopService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private DeviceService deviceService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private ShopReplenisherService shopReplenisherService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private AdminService adminService;
|
|
|
+ private final ShopService shopService;
|
|
|
+ private final DeviceService deviceService;
|
|
|
+ private final ShopReplenisherService shopReplenisherService;
|
|
|
+ private final AdminService adminService;
|
|
|
|
|
|
/**
|
|
|
* 分页查询门店列表
|
|
|
- * @param params 查询参数
|
|
|
+ * @param queryDTO 查询参数
|
|
|
* @return 门店列表
|
|
|
*/
|
|
|
@GetMapping("/list")
|
|
|
- public Result<Map<String, Object>> list(@RequestParam Map<String, Object> params) {
|
|
|
- try {
|
|
|
- int page = 1;
|
|
|
- int pageSize = 10;
|
|
|
-
|
|
|
- Object pageObj = params.get("page");
|
|
|
- if (pageObj != null && !pageObj.toString().isEmpty()) {
|
|
|
- page = Integer.parseInt(pageObj.toString());
|
|
|
- }
|
|
|
-
|
|
|
- Object pageSizeObj = params.get("pageSize");
|
|
|
- if (pageSizeObj != null && !pageSizeObj.toString().isEmpty()) {
|
|
|
- pageSize = Integer.parseInt(pageSizeObj.toString());
|
|
|
- }
|
|
|
-
|
|
|
- IPage<Shop> shopPage = shopService.getPage(page, pageSize, params);
|
|
|
-
|
|
|
- Map<String, Object> data = new HashMap<>();
|
|
|
- data.put("list", shopPage.getRecords());
|
|
|
- data.put("total", shopPage.getTotal());
|
|
|
- data.put("pageSize", shopPage.getSize());
|
|
|
- data.put("currentPage", shopPage.getCurrent());
|
|
|
-
|
|
|
- return Result.success("查询成功", data);
|
|
|
-
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("查询门店列表失败: {}", e.getMessage(), e);
|
|
|
- return Result.error(500, "查询门店列表失败: " + e.getMessage());
|
|
|
- }
|
|
|
+ public Result<PageResult<Shop>> list(ShopQueryDTO queryDTO) {
|
|
|
+ queryDTO.validate();
|
|
|
+
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
+ params.put("name", queryDTO.getName());
|
|
|
+ params.put("city", queryDTO.getCity());
|
|
|
+ params.put("status", queryDTO.getStatus());
|
|
|
+
|
|
|
+ IPage<Shop> shopPage = shopService.getPage(queryDTO.getPage(), queryDTO.getPageSize(), params);
|
|
|
+
|
|
|
+ return Result.success("查询成功", PageResult.of(shopPage));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -85,16 +62,11 @@ public class ShopController {
|
|
|
*/
|
|
|
@GetMapping("/{id}")
|
|
|
public Result<Shop> getById(@PathVariable Long id) {
|
|
|
- try {
|
|
|
- Shop shop = shopService.getShopWithStats(id);
|
|
|
- if (shop == null) {
|
|
|
- return Result.error(404, "门店不存在");
|
|
|
- }
|
|
|
- return Result.success("查询成功", shop);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("查询门店详情失败: id={}, error={}", id, e.getMessage(), e);
|
|
|
- return Result.error(500, "查询门店详情失败: " + e.getMessage());
|
|
|
+ Shop shop = shopService.getShopWithStats(id);
|
|
|
+ if (shop == null) {
|
|
|
+ return Result.error(404, "门店不存在");
|
|
|
}
|
|
|
+ return Result.success("查询成功", shop);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -103,13 +75,8 @@ public class ShopController {
|
|
|
*/
|
|
|
@GetMapping("/statistics")
|
|
|
public Result<Map<String, Object>> getStatistics() {
|
|
|
- try {
|
|
|
- Map<String, Object> statistics = shopService.getStatistics();
|
|
|
- return Result.success("查询成功", statistics);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("查询门店统计失败: {}", e.getMessage(), e);
|
|
|
- return Result.error(500, "查询门店统计失败: " + e.getMessage());
|
|
|
- }
|
|
|
+ Map<String, Object> statistics = shopService.getStatistics();
|
|
|
+ return Result.success("查询成功", statistics);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -118,13 +85,8 @@ public class ShopController {
|
|
|
*/
|
|
|
@GetMapping("/enabled")
|
|
|
public Result<List<Map<String, Object>>> getEnabledShops() {
|
|
|
- try {
|
|
|
- List<Map<String, Object>> shops = shopService.getAllEnabledShops();
|
|
|
- return Result.success("查询成功", shops);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("查询启用门店失败: {}", e.getMessage(), e);
|
|
|
- return Result.error(500, "查询启用门店失败: " + e.getMessage());
|
|
|
- }
|
|
|
+ List<Map<String, Object>> shops = shopService.getAllEnabledShops();
|
|
|
+ return Result.success("查询成功", shops);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -135,13 +97,8 @@ public class ShopController {
|
|
|
@Log(module = "门店管理", operation = OperationType.INSERT, summary = "新增门店")
|
|
|
@PostMapping
|
|
|
public Result<Shop> create(@RequestBody Shop shop) {
|
|
|
- try {
|
|
|
- Shop created = shopService.createShop(shop);
|
|
|
- return Result.success("创建成功", created);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("创建门店失败: {}", e.getMessage(), e);
|
|
|
- return Result.error(500, "创建门店失败: " + e.getMessage());
|
|
|
- }
|
|
|
+ Shop created = shopService.createShop(shop);
|
|
|
+ return Result.success("创建成功", created);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -153,14 +110,9 @@ public class ShopController {
|
|
|
@Log(module = "门店管理", operation = OperationType.UPDATE, summary = "编辑门店")
|
|
|
@PutMapping("/{id}")
|
|
|
public Result<Shop> update(@PathVariable Long id, @RequestBody Shop shop) {
|
|
|
- try {
|
|
|
- shop.setId(id);
|
|
|
- Shop updated = shopService.updateShop(shop);
|
|
|
- return Result.success("更新成功", updated);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("更新门店失败: id={}, error={}", id, e.getMessage(), e);
|
|
|
- return Result.error(500, "更新门店失败: " + e.getMessage());
|
|
|
- }
|
|
|
+ shop.setId(id);
|
|
|
+ Shop updated = shopService.updateShop(shop);
|
|
|
+ return Result.success("更新成功", updated);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -171,23 +123,18 @@ public class ShopController {
|
|
|
@Log(module = "门店管理", operation = OperationType.DELETE, summary = "删除门店")
|
|
|
@DeleteMapping("/{id}")
|
|
|
public Result<String> delete(@PathVariable Long id) {
|
|
|
- try {
|
|
|
- // 检查门店是否有设备
|
|
|
- Shop shop = shopService.getShopWithStats(id);
|
|
|
- if (shop == null) {
|
|
|
- return Result.error(404, "门店不存在");
|
|
|
- }
|
|
|
-
|
|
|
- if (shop.getDeviceCount() != null && shop.getDeviceCount() > 0) {
|
|
|
- return Result.error(400, "该门店下存在设备,无法删除");
|
|
|
- }
|
|
|
-
|
|
|
- shopService.removeById(id);
|
|
|
- return Result.success("删除成功");
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("删除门店失败: id={}, error={}", id, e.getMessage(), e);
|
|
|
- return Result.error(500, "删除门店失败: " + e.getMessage());
|
|
|
+ // 检查门店是否有设备
|
|
|
+ Shop shop = shopService.getShopWithStats(id);
|
|
|
+ if (shop == null) {
|
|
|
+ return Result.error(404, "门店不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (shop.getDeviceCount() != null && shop.getDeviceCount() > 0) {
|
|
|
+ return Result.error(400, "该门店下存在设备,无法删除");
|
|
|
}
|
|
|
+
|
|
|
+ shopService.removeById(id);
|
|
|
+ return Result.success("删除成功");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -199,18 +146,13 @@ public class ShopController {
|
|
|
@Log(module = "门店管理", operation = OperationType.UPDATE, summary = "切换门店状态")
|
|
|
@PutMapping("/{id}/status")
|
|
|
public Result<String> toggleStatus(@PathVariable Long id, @RequestBody Map<String, Object> params) {
|
|
|
- try {
|
|
|
- Integer status = Integer.valueOf(params.get("status").toString());
|
|
|
- boolean result = shopService.toggleStatus(id, status);
|
|
|
-
|
|
|
- if (result) {
|
|
|
- return Result.success("状态更新成功");
|
|
|
- } else {
|
|
|
- return Result.error(500, "状态更新失败");
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("切换门店状态失败: id={}, error={}", id, e.getMessage(), e);
|
|
|
- return Result.error(500, "切换门店状态失败: " + e.getMessage());
|
|
|
+ Integer status = Integer.valueOf(params.get("status").toString());
|
|
|
+ boolean result = shopService.toggleStatus(id, status);
|
|
|
+
|
|
|
+ if (result) {
|
|
|
+ return Result.success("状态更新成功");
|
|
|
+ } else {
|
|
|
+ return Result.error(500, "状态更新失败");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -221,13 +163,8 @@ public class ShopController {
|
|
|
*/
|
|
|
@GetMapping("/{id}/devices")
|
|
|
public Result<List<Map<String, Object>>> getDevices(@PathVariable Long id) {
|
|
|
- try {
|
|
|
- List<Map<String, Object>> devices = shopService.getDevicesByShopId(id);
|
|
|
- return Result.success("查询成功", devices);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("查询门店设备失败: id={}, error={}", id, e.getMessage(), e);
|
|
|
- return Result.error(500, "查询门店设备失败: " + e.getMessage());
|
|
|
- }
|
|
|
+ List<Map<String, Object>> devices = shopService.getDevicesByShopId(id);
|
|
|
+ return Result.success("查询成功", devices);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -239,17 +176,12 @@ public class ShopController {
|
|
|
@Log(module = "门店管理", operation = OperationType.UPDATE, summary = "关联设备到门店")
|
|
|
@PostMapping("/{id}/devices")
|
|
|
public Result<String> linkDevice(@PathVariable Long id, @RequestBody Map<String, Object> params) {
|
|
|
- try {
|
|
|
- Long deviceId = Long.valueOf(params.get("deviceId").toString());
|
|
|
- boolean result = shopService.linkDevice(id, deviceId);
|
|
|
- if (result) {
|
|
|
- return Result.success("关联成功");
|
|
|
- } else {
|
|
|
- return Result.error(500, "关联失败");
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("关联设备失败: shopId={}, error={}", id, e.getMessage(), e);
|
|
|
- return Result.error(500, "关联失败: " + e.getMessage());
|
|
|
+ Long deviceId = Long.valueOf(params.get("deviceId").toString());
|
|
|
+ boolean result = shopService.linkDevice(id, deviceId);
|
|
|
+ if (result) {
|
|
|
+ return Result.success("关联成功");
|
|
|
+ } else {
|
|
|
+ return Result.error(500, "关联失败");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -262,24 +194,19 @@ public class ShopController {
|
|
|
@Log(module = "门店管理", operation = OperationType.UPDATE, summary = "批量关联设备到门店")
|
|
|
@PostMapping("/{id}/devices/batch")
|
|
|
public Result<Map<String, Object>> batchLinkDevices(@PathVariable Long id, @RequestBody Map<String, Object> params) {
|
|
|
- try {
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
- List<Integer> deviceIdInts = (List<Integer>) params.get("deviceIds");
|
|
|
- List<Long> deviceIds = deviceIdInts.stream()
|
|
|
- .map(Integer::longValue)
|
|
|
- .toList();
|
|
|
-
|
|
|
- int count = shopService.batchLinkDevices(id, deviceIds);
|
|
|
-
|
|
|
- Map<String, Object> result = new HashMap<>();
|
|
|
- result.put("success", count);
|
|
|
- result.put("total", deviceIds.size());
|
|
|
-
|
|
|
- return Result.success("批量关联完成", result);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("批量关联设备失败: shopId={}, error={}", id, e.getMessage(), e);
|
|
|
- return Result.error(500, "批量关联失败: " + e.getMessage());
|
|
|
- }
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ List<Integer> deviceIdInts = (List<Integer>) params.get("deviceIds");
|
|
|
+ List<Long> deviceIds = deviceIdInts.stream()
|
|
|
+ .map(Integer::longValue)
|
|
|
+ .toList();
|
|
|
+
|
|
|
+ int count = shopService.batchLinkDevices(id, deviceIds);
|
|
|
+
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ result.put("success", count);
|
|
|
+ result.put("total", deviceIds.size());
|
|
|
+
|
|
|
+ return Result.success("批量关联完成", result);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -291,16 +218,11 @@ public class ShopController {
|
|
|
@Log(module = "门店管理", operation = OperationType.UPDATE, summary = "移除门店设备关联")
|
|
|
@DeleteMapping("/{id}/devices/{deviceId}")
|
|
|
public Result<String> unlinkDevice(@PathVariable Long id, @PathVariable Long deviceId) {
|
|
|
- try {
|
|
|
- boolean result = shopService.unlinkDevice(id, deviceId);
|
|
|
- if (result) {
|
|
|
- return Result.success("移除成功");
|
|
|
- } else {
|
|
|
- return Result.error(500, "移除失败");
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("移除设备失败: shopId={}, deviceId={}, error={}", id, deviceId, e.getMessage(), e);
|
|
|
- return Result.error(500, "移除失败: " + e.getMessage());
|
|
|
+ boolean result = shopService.unlinkDevice(id, deviceId);
|
|
|
+ if (result) {
|
|
|
+ return Result.success("移除成功");
|
|
|
+ } else {
|
|
|
+ return Result.error(500, "移除失败");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -313,24 +235,19 @@ public class ShopController {
|
|
|
@Log(module = "门店管理", operation = OperationType.UPDATE, summary = "批量移除设备关联")
|
|
|
@DeleteMapping("/{id}/devices/batch")
|
|
|
public Result<Map<String, Object>> batchUnlinkDevices(@PathVariable Long id, @RequestBody Map<String, Object> params) {
|
|
|
- try {
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
- List<Integer> deviceIdInts = (List<Integer>) params.get("deviceIds");
|
|
|
- List<Long> deviceIds = deviceIdInts.stream()
|
|
|
- .map(Integer::longValue)
|
|
|
- .toList();
|
|
|
-
|
|
|
- int count = shopService.batchUnlinkDevices(id, deviceIds);
|
|
|
-
|
|
|
- Map<String, Object> result = new HashMap<>();
|
|
|
- result.put("success", count);
|
|
|
- result.put("total", deviceIds.size());
|
|
|
-
|
|
|
- return Result.success("批量移除完成", result);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("批量移除设备失败: shopId={}, error={}", id, e.getMessage(), e);
|
|
|
- return Result.error(500, "批量移除失败: " + e.getMessage());
|
|
|
- }
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ List<Integer> deviceIdInts = (List<Integer>) params.get("deviceIds");
|
|
|
+ List<Long> deviceIds = deviceIdInts.stream()
|
|
|
+ .map(Integer::longValue)
|
|
|
+ .toList();
|
|
|
+
|
|
|
+ int count = shopService.batchUnlinkDevices(id, deviceIds);
|
|
|
+
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ result.put("success", count);
|
|
|
+ result.put("total", deviceIds.size());
|
|
|
+
|
|
|
+ return Result.success("批量移除完成", result);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -339,13 +256,8 @@ public class ShopController {
|
|
|
*/
|
|
|
@GetMapping("/unlinked-devices")
|
|
|
public Result<List<Device>> getUnlinkedDevices() {
|
|
|
- try {
|
|
|
- List<Device> devices = deviceService.getUnlinkedDevices();
|
|
|
- return Result.success("查询成功", devices);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("查询未关联设备失败: error={}", e.getMessage(), e);
|
|
|
- return Result.error(500, "查询失败: " + e.getMessage());
|
|
|
- }
|
|
|
+ List<Device> devices = deviceService.getUnlinkedDevices();
|
|
|
+ return Result.success("查询成功", devices);
|
|
|
}
|
|
|
|
|
|
// ==================== 补货员管理 ====================
|
|
|
@@ -357,13 +269,8 @@ public class ShopController {
|
|
|
*/
|
|
|
@GetMapping("/{id}/replenishers")
|
|
|
public Result<List<ShopReplenisher>> getReplenishers(@PathVariable Long id) {
|
|
|
- try {
|
|
|
- List<ShopReplenisher> replenishers = shopReplenisherService.getReplenishersByShopId(id);
|
|
|
- return Result.success("查询成功", replenishers);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("查询补货员失败: shopId={}, error={}", id, e.getMessage(), e);
|
|
|
- return Result.error(500, "查询失败: " + e.getMessage());
|
|
|
- }
|
|
|
+ List<ShopReplenisher> replenishers = shopReplenisherService.getReplenishersByShopId(id);
|
|
|
+ return Result.success("查询成功", replenishers);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -375,13 +282,8 @@ public class ShopController {
|
|
|
@Log(module = "门店管理", operation = OperationType.INSERT, summary = "添加门店补货员")
|
|
|
@PostMapping("/{id}/replenishers")
|
|
|
public Result<String> addReplenisher(@PathVariable Long id, @RequestBody Map<String, Object> params) {
|
|
|
- try {
|
|
|
- Long adminId = Long.valueOf(params.get("adminId").toString());
|
|
|
- return shopReplenisherService.addReplenisher(id, adminId);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("添加补货员失败: shopId={}, error={}", id, e.getMessage(), e);
|
|
|
- return Result.error(500, "添加失败: " + e.getMessage());
|
|
|
- }
|
|
|
+ Long adminId = Long.valueOf(params.get("adminId").toString());
|
|
|
+ return shopReplenisherService.addReplenisher(id, adminId);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -393,24 +295,19 @@ public class ShopController {
|
|
|
@Log(module = "门店管理", operation = OperationType.INSERT, summary = "批量添加门店补货员")
|
|
|
@PostMapping("/{id}/replenishers/batch")
|
|
|
public Result<Map<String, Object>> batchAddReplenishers(@PathVariable Long id, @RequestBody Map<String, Object> params) {
|
|
|
- try {
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
- List<Integer> adminIdInts = (List<Integer>) params.get("adminIds");
|
|
|
- List<Long> adminIds = adminIdInts.stream()
|
|
|
- .map(Integer::longValue)
|
|
|
- .toList();
|
|
|
-
|
|
|
- int count = shopReplenisherService.batchAddReplenishers(id, adminIds);
|
|
|
-
|
|
|
- Map<String, Object> result = new HashMap<>();
|
|
|
- result.put("success", count);
|
|
|
- result.put("total", adminIds.size());
|
|
|
-
|
|
|
- return Result.success("批量添加完成", result);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("批量添加补货员失败: shopId={}, error={}", id, e.getMessage(), e);
|
|
|
- return Result.error(500, "批量添加失败: " + e.getMessage());
|
|
|
- }
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ List<Integer> adminIdInts = (List<Integer>) params.get("adminIds");
|
|
|
+ List<Long> adminIds = adminIdInts.stream()
|
|
|
+ .map(Integer::longValue)
|
|
|
+ .toList();
|
|
|
+
|
|
|
+ int count = shopReplenisherService.batchAddReplenishers(id, adminIds);
|
|
|
+
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ result.put("success", count);
|
|
|
+ result.put("total", adminIds.size());
|
|
|
+
|
|
|
+ return Result.success("批量添加完成", result);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -422,12 +319,7 @@ public class ShopController {
|
|
|
@Log(module = "门店管理", operation = OperationType.DELETE, summary = "移除门店补货员")
|
|
|
@DeleteMapping("/{id}/replenishers/{adminId}")
|
|
|
public Result<String> removeReplenisher(@PathVariable Long id, @PathVariable Long adminId) {
|
|
|
- try {
|
|
|
- return shopReplenisherService.removeReplenisher(id, adminId);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("移除补货员失败: shopId={}, adminId={}, error={}", id, adminId, e.getMessage(), e);
|
|
|
- return Result.error(500, "移除失败: " + e.getMessage());
|
|
|
- }
|
|
|
+ return shopReplenisherService.removeReplenisher(id, adminId);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -439,29 +331,19 @@ public class ShopController {
|
|
|
@Log(module = "门店管理", operation = OperationType.DELETE, summary = "批量移除门店补货员")
|
|
|
@DeleteMapping("/{id}/replenishers/batch")
|
|
|
public Result<Map<String, Object>> batchRemoveReplenishers(@PathVariable Long id, @RequestBody Map<String, Object> params) {
|
|
|
- try {
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
- List<Integer> adminIdInts = (List<Integer>) params.get("adminIds");
|
|
|
- List<Long> adminIds = adminIdInts.stream()
|
|
|
- .map(Integer::longValue)
|
|
|
- .toList();
|
|
|
-
|
|
|
- // 执行批量删除
|
|
|
- LambdaQueryWrapper<ShopReplenisher> wrapper = new LambdaQueryWrapper<>();
|
|
|
- wrapper.eq(ShopReplenisher::getShopId, id)
|
|
|
- .in(ShopReplenisher::getAdminId, adminIds);
|
|
|
- int count = (int) shopReplenisherService.count(wrapper);
|
|
|
- shopReplenisherService.remove(wrapper);
|
|
|
-
|
|
|
- Map<String, Object> result = new HashMap<>();
|
|
|
- result.put("success", count);
|
|
|
- result.put("total", adminIds.size());
|
|
|
-
|
|
|
- return Result.success("批量移除完成", result);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("批量移除补货员失败: shopId={}, error={}", id, e.getMessage(), e);
|
|
|
- return Result.error(500, "批量移除失败: " + e.getMessage());
|
|
|
- }
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ List<Integer> adminIdInts = (List<Integer>) params.get("adminIds");
|
|
|
+ List<Long> adminIds = adminIdInts.stream()
|
|
|
+ .map(Integer::longValue)
|
|
|
+ .toList();
|
|
|
+
|
|
|
+ int count = shopReplenisherService.batchRemoveReplenishers(id, adminIds);
|
|
|
+
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ result.put("success", count);
|
|
|
+ result.put("total", adminIds.size());
|
|
|
+
|
|
|
+ return Result.success("批量移除完成", result);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -473,13 +355,8 @@ public class ShopController {
|
|
|
@Log(module = "门店管理", operation = OperationType.UPDATE, summary = "更新补货员状态")
|
|
|
@PutMapping("/replenishers/{id}/status")
|
|
|
public Result<String> updateReplenisherStatus(@PathVariable Long id, @RequestBody Map<String, Object> params) {
|
|
|
- try {
|
|
|
- Integer status = Integer.valueOf(params.get("status").toString());
|
|
|
- return shopReplenisherService.updateStatus(id, status);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("更新补货员状态失败: id={}, error={}", id, e.getMessage(), e);
|
|
|
- return Result.error(500, "更新失败: " + e.getMessage());
|
|
|
- }
|
|
|
+ Integer status = Integer.valueOf(params.get("status").toString());
|
|
|
+ return shopReplenisherService.updateStatus(id, status);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -488,20 +365,7 @@ public class ShopController {
|
|
|
*/
|
|
|
@GetMapping("/available-users")
|
|
|
public Result<List<Admin>> getAvailableUsers(@RequestParam(required = false) String keyword) {
|
|
|
- try {
|
|
|
- LambdaQueryWrapper<Admin> wrapper = new LambdaQueryWrapper<>();
|
|
|
- wrapper.eq(Admin::getStatus, 1); // 只查询正常状态的管理员
|
|
|
- if (keyword != null && !keyword.isEmpty()) {
|
|
|
- wrapper.and(w -> w.like(Admin::getRealName, keyword)
|
|
|
- .or().like(Admin::getPhone, keyword)
|
|
|
- .or().like(Admin::getUsername, keyword));
|
|
|
- }
|
|
|
- wrapper.orderByDesc(Admin::getCreateTime);
|
|
|
- List<Admin> admins = adminService.list(wrapper);
|
|
|
- return Result.success("查询成功", admins);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("查询可选管理员失败: error={}", e.getMessage(), e);
|
|
|
- return Result.error(500, "查询失败: " + e.getMessage());
|
|
|
- }
|
|
|
+ List<Admin> admins = adminService.getAvailableAdmins(keyword);
|
|
|
+ return Result.success("查询成功", admins);
|
|
|
}
|
|
|
}
|