| | |
| | | * 设备配置表 控制器 |
| | | * |
| | | * @author lw |
| | | * @since 2026-01-07 |
| | | * @since 2026-01-08 |
| | | */ |
| | | @RestController |
| | | @AllArgsConstructor |
| | |
| | | */ |
| | | @GetMapping("/detail") |
| | | @ApiOperationSupport(order = 1) |
| | | @ApiOperation(value = "详情", notes = "传入fwDeviceConfig") |
| | | public R<FwDeviceConfigVO> detail(FwDeviceConfigEntity fwDeviceConfig) { |
| | | FwDeviceConfigEntity detail = fwDeviceConfigService.getOne(Condition.getQueryWrapper(fwDeviceConfig)); |
| | | @ApiOperation(value = "详情", notes = "传入deviceId") |
| | | public R<FwDeviceConfigVO> detail(@ApiParam(value = "设备id", required = true) @RequestParam Long deviceId) { |
| | | if (deviceId == null) { |
| | | return R.fail("设备id不能为空"); |
| | | } |
| | | FwDeviceConfigEntity detail = fwDeviceConfigService.selectLatestByDeviceId(deviceId); |
| | | if (detail == null) { |
| | | detail = fwDeviceConfigService.selectLatestVersionByDeviceId(deviceId); |
| | | } |
| | | if (detail == null) { |
| | | return R.fail("数据不存在"); |
| | | } |
| | | return R.data(FwDeviceConfigWrapper.build().entityVO(detail)); |
| | | } |
| | | /** |
| | |
| | | */ |
| | | @GetMapping("/list") |
| | | @ApiOperationSupport(order = 2) |
| | | @ApiOperation(value = "分页", notes = "传入fwDeviceConfig") |
| | | @ApiOperation(value = "列表", notes = "传入fwDeviceConfig") |
| | | public R<IPage<FwDeviceConfigVO>> list(@ApiIgnore @RequestParam Map<String, Object> fwDeviceConfig, Query query) { |
| | | IPage<FwDeviceConfigEntity> pages = fwDeviceConfigService.page(Condition.getPage(query), Condition.getQueryWrapper(fwDeviceConfig, FwDeviceConfigEntity.class)); |
| | | return R.data(FwDeviceConfigWrapper.build().pageVO(pages)); |
| | |
| | | IPage<FwDeviceConfigVO> pages = fwDeviceConfigService.selectFwDeviceConfigPage(Condition.getPage(query), fwDeviceConfig); |
| | | return R.data(pages); |
| | | } |
| | | |
| | | /** |
| | | * 设备配置表 新增 |
| | | */ |
| | | @PostMapping("/save") |
| | | @ApiOperationSupport(order = 4) |
| | | @ApiOperation(value = "新增", notes = "传入fwDeviceConfig") |
| | | public R save(@Valid @RequestBody FwDeviceConfigEntity fwDeviceConfig) { |
| | | return R.status(fwDeviceConfigService.save(fwDeviceConfig)); |
| | | } |
| | | |
| | | /** |
| | | * 设备配置表 修改 |
| | | */ |
| | | @PostMapping("/update") |
| | | @ApiOperationSupport(order = 5) |
| | | @ApiOperation(value = "修改", notes = "传入fwDeviceConfig") |
| | | public R update(@Valid @RequestBody FwDeviceConfigEntity fwDeviceConfig) { |
| | | return R.status(fwDeviceConfigService.updateById(fwDeviceConfig)); |
| | | } |
| | | // |
| | | // /** |
| | | // * 设备配置表 新增 |
| | | // */ |
| | | // @PostMapping("/save") |
| | | // @ApiOperationSupport(order = 4) |
| | | // @ApiOperation(value = "新增", notes = "传入fwDeviceConfig") |
| | | // public R save(@Valid @RequestBody FwDeviceConfigEntity fwDeviceConfig) { |
| | | // return saveOrUpdateConfig(fwDeviceConfig); |
| | | // } |
| | | // |
| | | // /** |
| | | // * 设备配置表 修改 |
| | | // */ |
| | | // @PostMapping("/update") |
| | | // @ApiOperationSupport(order = 5) |
| | | // @ApiOperation(value = "修改", notes = "传入fwDeviceConfig") |
| | | // public R update(@Valid @RequestBody FwDeviceConfigEntity fwDeviceConfig) { |
| | | // return saveOrUpdateConfig(fwDeviceConfig); |
| | | // } |
| | | |
| | | /** |
| | | * 设备配置表 新增或修改 |
| | |
| | | @ApiOperationSupport(order = 6) |
| | | @ApiOperation(value = "新增或修改", notes = "传入fwDeviceConfig") |
| | | public R submit(@Valid @RequestBody FwDeviceConfigEntity fwDeviceConfig) { |
| | | return R.status(fwDeviceConfigService.saveOrUpdate(fwDeviceConfig)); |
| | | return saveOrUpdateConfig(fwDeviceConfig); |
| | | } |
| | | |
| | | /** |
| | |
| | | ExcelUtil.export(response, "设备配置表数据" + DateUtil.time(), "设备配置表数据表", list, FwDeviceConfigExcel.class); |
| | | } |
| | | |
| | | private R saveOrUpdateConfig(FwDeviceConfigEntity fwDeviceConfig) { |
| | | if (fwDeviceConfig == null || fwDeviceConfig.getDeviceId() == null) { |
| | | return R.fail("设备id不能为空"); |
| | | } |
| | | Long deviceId = fwDeviceConfig.getDeviceId(); |
| | | FwDeviceConfigEntity existing = null; |
| | | if (fwDeviceConfig.getId() != null) { |
| | | existing = fwDeviceConfigService.getById(fwDeviceConfig.getId()); |
| | | if (existing == null) { |
| | | return R.fail("数据不存在"); |
| | | } |
| | | } |
| | | if (existing == null) { |
| | | Integer maxVersion = fwDeviceConfigService.selectMaxConfigVersion(deviceId); |
| | | fwDeviceConfig.setConfigVersion(maxVersion == null ? 1 : maxVersion + 1); |
| | | fwDeviceConfig.setIsLatest((byte) 1); |
| | | fwDeviceConfigService.resetLatestByDeviceId(deviceId, null); |
| | | return R.status(fwDeviceConfigService.save(fwDeviceConfig)); |
| | | } |
| | | |
| | | if (fwDeviceConfig.getConfigVersion() == null) { |
| | | fwDeviceConfig.setConfigVersion(existing.getConfigVersion()); |
| | | } |
| | | if (fwDeviceConfig.getIsLatest() == null) { |
| | | fwDeviceConfig.setIsLatest(existing.getIsLatest()); |
| | | } |
| | | if (fwDeviceConfig.getIsLatest() != null && fwDeviceConfig.getIsLatest() == 1) { |
| | | fwDeviceConfigService.resetLatestByDeviceId(deviceId, fwDeviceConfig.getId()); |
| | | } |
| | | return R.status(fwDeviceConfigService.updateById(fwDeviceConfig)); |
| | | } |
| | | |
| | | } |