吉安感知网项目-后端
linwei
2026-01-14 bc1a6bb5bb2803ed6a5669a976bf2b47f3dacfca
drone-service/drone-fw/src/main/java/org/sxkj/fw/detection/controller/FwDeviceConfigController.java
@@ -49,7 +49,7 @@
 * 设备配置表 控制器
 *
 * @author lw
 * @since 2026-01-07
 * @since 2026-01-08
 */
@RestController
@AllArgsConstructor
@@ -64,9 +64,18 @@
    */
   @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));
   }
   /**
@@ -74,7 +83,7 @@
    */
   @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));
@@ -90,26 +99,26 @@
      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);
//   }
   /**
    * 设备配置表 新增或修改
@@ -118,7 +127,7 @@
   @ApiOperationSupport(order = 6)
   @ApiOperation(value = "新增或修改", notes = "传入fwDeviceConfig")
   public R submit(@Valid @RequestBody FwDeviceConfigEntity fwDeviceConfig) {
      return R.status(fwDeviceConfigService.saveOrUpdate(fwDeviceConfig));
      return saveOrUpdateConfig(fwDeviceConfig);
   }
   /**
@@ -148,4 +157,36 @@
      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));
   }
}