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; 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 { @Autowired private DeviceService deviceService; @Autowired private SysOrgService sysOrgService; /** * 分页查询设备列表 */ @ApiOperation("分页查询设备列表") @GetMapping("/list") public R list(@RequestParam Map params) { PageUtils page = deviceService.queryPage(params, getUserId()); Map 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, "无权限查看该设备"); } Map 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, "无权限操作该门店"); } deviceService.saveDevice(device); Map data = new HashMap<>(); data.put("id", device.getId()); return R.dataSuccess(data); } /** * 修改设备 */ @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, "无权限操作该设备"); } deviceService.updateDevice(device); return R.dataSuccess(new HashMap<>()); } /** * 删除设备(软删除) */ @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, "无权限删除该设备"); } } deviceService.delete(ids); return R.dataSuccess(new HashMap<>()); } /** * 绑定门店 */ @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, "无权限绑定到此门店"); } deviceService.bindStore(deviceId, storeOrgId); return R.dataSuccess(new HashMap<>()); } }