Files
as-daycard-openapi/src/main/java/io/as/modules/device/controller/DeviceController.java
T

121 lines
3.6 KiB
Java
Raw Normal View History

2026-07-26 12:34:13 +08:00
package io.as.modules.device.controller;
import io.as.common.annotation.AuditAction;
import io.as.common.utils.PageUtils;
import io.as.common.utils.R;
import io.as.modules.device.entity.DeviceEntity;
import io.as.modules.device.service.DeviceService;
import io.as.modules.sys.controller.AbstractController;
import io.as.modules.sys.service.SysOrgService;
2026-07-26 12:34:13 +08:00
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.Map;
/**
* 终端管理
*/
@Api(tags = "终端管理")
@RestController
@RequestMapping("/manage/device")
public class DeviceController extends AbstractController {
2026-07-26 12:34:13 +08:00
@Autowired
private DeviceService deviceService;
@Autowired
private SysOrgService sysOrgService;
2026-07-26 12:34:13 +08:00
/**
* 分页查询设备列表
*/
@ApiOperation("分页查询设备列表")
@GetMapping("/list")
public R list(@RequestParam Map<String, Object> params) {
PageUtils page = deviceService.queryPage(params, getUserId());
2026-07-26 12:34:13 +08:00
Map<String, Object> data = new HashMap<>();
data.put("page", page);
return R.dataSuccess(data);
}
/**
* 设备详情
*/
@ApiOperation("设备详情")
@GetMapping("/info/{id}")
public R info(@PathVariable("id") Long id) {
DeviceEntity device = deviceService.getById(id);
if (device != null && !sysOrgService.isOrgInScope(device.getStoreOrgId(), getUserId())) {
return R.error(403, "无权限查看该设备");
}
2026-07-26 12:34:13 +08:00
Map<String, Object> data = new HashMap<>();
data.put("device", device);
return R.dataSuccess(data);
}
/**
* 新增设备
*/
@ApiOperation("新增设备")
@AuditAction(value = "DEVICE_SAVE", description = "新增设备")
@PostMapping("/save")
public R save(@RequestBody DeviceEntity device) {
if (device.getStoreOrgId() != null && !sysOrgService.isOrgInScope(device.getStoreOrgId(), getUserId())) {
return R.error(403, "无权限操作该门店");
}
2026-07-26 12:34:13 +08:00
deviceService.saveDevice(device);
Map<String, Object> data = new HashMap<>();
data.put("id", device.getId());
return R.dataSuccess(data);
2026-07-26 12:34:13 +08:00
}
/**
* 修改设备
*/
@ApiOperation("修改设备")
@AuditAction(value = "DEVICE_UPDATE", description = "修改设备")
@PostMapping("/update")
public R update(@RequestBody DeviceEntity device) {
DeviceEntity existing = deviceService.getById(device.getId());
if (existing != null && !sysOrgService.isOrgInScope(existing.getStoreOrgId(), getUserId())) {
return R.error(403, "无权限操作该设备");
}
2026-07-26 12:34:13 +08:00
deviceService.updateDevice(device);
return R.dataSuccess(new HashMap<>());
2026-07-26 12:34:13 +08:00
}
/**
* 删除设备(软删除)
*/
@ApiOperation("删除设备")
@AuditAction(value = "DEVICE_DELETE", description = "删除设备")
@PostMapping("/delete")
public R delete(@RequestBody Long[] ids) {
for (Long id : ids) {
DeviceEntity device = deviceService.getById(id);
if (device != null && !sysOrgService.isOrgInScope(device.getStoreOrgId(), getUserId())) {
return R.error(403, "无权限删除该设备");
}
}
2026-07-26 12:34:13 +08:00
deviceService.delete(ids);
return R.dataSuccess(new HashMap<>());
2026-07-26 12:34:13 +08:00
}
/**
* 绑定门店
*/
@ApiOperation("绑定门店")
@AuditAction(value = "DEVICE_BIND_STORE", description = "设备绑定门店")
@PostMapping("/bindStore")
public R bindStore(@RequestParam("deviceId") Long deviceId, @RequestParam("storeOrgId") Long storeOrgId) {
if (!sysOrgService.isOrgInScope(storeOrgId, getUserId())) {
return R.error(403, "无权限绑定到此门店");
}
2026-07-26 12:34:13 +08:00
deviceService.bindStore(deviceId, storeOrgId);
return R.dataSuccess(new HashMap<>());
2026-07-26 12:34:13 +08:00
}
}