| | |
| | | import io.swagger.annotations.ApiParam; |
| | | import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; |
| | | import lombok.AllArgsConstructor; |
| | | |
| | | import javax.validation.Valid; |
| | | |
| | | import org.springblade.core.secure.BladeUser; |
| | |
| | | import org.springblade.core.excel.util.ExcelUtil; |
| | | import org.springblade.core.tool.constant.BladeConstant; |
| | | import springfox.documentation.annotations.ApiIgnore; |
| | | |
| | | import java.util.Map; |
| | | import java.util.List; |
| | | import javax.servlet.http.HttpServletResponse; |
| | |
| | | @GetMapping("/detail") |
| | | @ApiOperationSupport(order = 1) |
| | | @ApiOperation(value = "详情", notes = "传入deviceId") |
| | | public R<FwDeviceConfigVO> detail(@ApiParam(value = "设备id", required = true) @RequestParam Long deviceId) { |
| | | public R detail(@ApiParam(value = "设备id", required = true) @RequestParam Long deviceId) { |
| | | if (deviceId == null) { |
| | | return R.fail("设备id不能为空"); |
| | | } |
| | |
| | | detail = fwDeviceConfigService.selectLatestVersionByDeviceId(deviceId); |
| | | } |
| | | if (detail == null) { |
| | | return R.fail("数据不存在"); |
| | | return R.data(""); |
| | | } |
| | | 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)); |
| | |
| | | @ApiOperationSupport(order = 6) |
| | | @ApiOperation(value = "新增或修改", notes = "传入fwDeviceConfig") |
| | | public R submit(@Valid @RequestBody FwDeviceConfigEntity fwDeviceConfig) { |
| | | return saveOrUpdateConfig(fwDeviceConfig); |
| | | return fwDeviceConfigService.saveOrUpdateConfig(fwDeviceConfig); |
| | | } |
| | | |
| | | /** |
| | |
| | | queryWrapper.lambda().eq(FwDeviceConfigEntity::getIsDeleted, BladeConstant.DB_NOT_DELETED); |
| | | List<FwDeviceConfigExcel> list = fwDeviceConfigService.exportFwDeviceConfig(queryWrapper); |
| | | 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)); |
| | | } |
| | | |
| | | } |