| | |
| | | String purpose, |
| | | String status, |
| | | List<String> batteryNos, |
| | | List<FieldValueDto> fields) { |
| | | public record FieldValueDto(Long fieldId, String value) { } |
| | | List<FieldValueDto> fields, |
| | | String remark, |
| | | Long templateId, |
| | | List<FieldValueDto> templateFieldRelations) { |
| | | public BatteryGroupDto(Long groupId, String groupName, String model, String purpose, String status, |
| | | List<String> batteryNos, List<FieldValueDto> fields) { |
| | | this(groupId, groupName, model, purpose, status, batteryNos, fields, null, null, null); |
| | | } |
| | | public List<FieldValueDto> currentFields() { return fields != null ? fields : templateFieldRelations; } |
| | | public record FieldValueDto(Long fieldId, String value, Long batteryGroupFieldId, String fieldValue) { |
| | | public FieldValueDto(Long fieldId, String value) { this(fieldId, value, null, null); } |
| | | public Long resolvedFieldId() { return fieldId != null ? fieldId : batteryGroupFieldId; } |
| | | public String resolvedValue() { return value != null ? value : fieldValue; } |
| | | } |
| | | } |
| | |
| | | /** 单个测试电池及检测柜、采集器通道绑定请求。 */ |
| | | public record TestBatteryBindingDto( |
| | | Long testBatteryId, |
| | | Long relationId, |
| | | Long groupId, |
| | | String batteryNo, |
| | | Long collectorId, |
| | | CabinetChannelDto cabinetChannel, |
| | | CabinetChannelDto binding, |
| | | List<CollectorChannelDto> collectorChannels) { |
| | | public TestBatteryBindingDto(Long testBatteryId, Long groupId, String batteryNo, Long collectorId, |
| | | CabinetChannelDto cabinetChannel, List<CollectorChannelDto> collectorChannels) { |
| | | this(testBatteryId, null, groupId, batteryNo, collectorId, cabinetChannel, null, collectorChannels); |
| | | } |
| | | public Long resolvedTestBatteryId() { return testBatteryId != null ? testBatteryId : relationId; } |
| | | public CabinetChannelDto resolvedCabinetChannel() { return cabinetChannel != null ? cabinetChannel : binding; } |
| | | public record CabinetChannelDto(Long channelId, String expectedBarcode) { } |
| | | public record CollectorChannelDto(String measurementCode, String measurementName, String channelCode) { } |
| | | } |
| | |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.common.enums.BusinessType; |
| | | import com.ruoyi.system.domain.TBatteryGroup; |
| | | import com.battery.business.battery.dto.BatteryGroupDto; |
| | | import com.ruoyi.system.service.ITBatteryGroupService; |
| | | |
| | | /** 电池组管理 Controller。 */ |
| | |
| | | public AjaxResult getInfo(@PathVariable Long groupId) { return success(batteryGroupService.selectBatteryGroupById(groupId)); } |
| | | |
| | | @PreAuthorize("@ss.hasPermi('system:batteryGroup:add')") @Log(title = "电池组管理", businessType = BusinessType.INSERT) @PostMapping |
| | | public AjaxResult add(@Validated @RequestBody TBatteryGroup group) { group.setCreateBy(getUsername()); return toAjax(batteryGroupService.insertBatteryGroup(group)); } |
| | | public AjaxResult add(@Validated @RequestBody BatteryGroupDto request) { TBatteryGroup group = toDomain(request); group.setCreateBy(getUsername()); return toAjax(batteryGroupService.insertBatteryGroup(group)); } |
| | | |
| | | @PreAuthorize("@ss.hasPermi('system:batteryGroup:edit')") @Log(title = "电池组管理", businessType = BusinessType.UPDATE) @PutMapping |
| | | public AjaxResult edit(@Validated @RequestBody TBatteryGroup group) { group.setUpdateBy(getUsername()); return toAjax(batteryGroupService.updateBatteryGroup(group)); } |
| | | public AjaxResult edit(@Validated @RequestBody BatteryGroupDto request) { TBatteryGroup group = toDomain(request); group.setUpdateBy(getUsername()); return toAjax(batteryGroupService.updateBatteryGroup(group)); } |
| | | |
| | | @PreAuthorize("@ss.hasPermi('system:batteryGroup:changeStatus')") @Log(title = "电池组管理", businessType = BusinessType.UPDATE) @PutMapping("/changeStatus") |
| | | public AjaxResult changeStatus(@RequestBody TBatteryGroup group) { group.setUpdateBy(getUsername()); return toAjax(batteryGroupService.updateBatteryGroupStatus(group)); } |
| | | |
| | | @PreAuthorize("@ss.hasPermi('system:batteryGroup:remove')") @Log(title = "电池组管理", businessType = BusinessType.DELETE) @DeleteMapping("/{groupIds}") |
| | | public AjaxResult remove(@PathVariable Long[] groupIds) { return toAjax(batteryGroupService.deleteBatteryGroupByIds(groupIds, getUsername())); } |
| | | |
| | | /** 将公开写入 DTO 转换为现有持久化服务模型,字段值仍写入电池组当前关系。 */ |
| | | private TBatteryGroup toDomain(BatteryGroupDto request) |
| | | { |
| | | if (request == null) return null; |
| | | TBatteryGroup group = new TBatteryGroup(); |
| | | group.setGroupId(request.groupId()); group.setGroupName(request.groupName()); |
| | | group.setModel(request.model()); group.setPurpose(request.purpose()); group.setStatus(request.status()); |
| | | group.setRemark(request.remark()); group.setTemplateId(request.templateId()); group.setBatteryNos(request.batteryNos()); |
| | | java.util.List<BatteryGroupDto.FieldValueDto> values = request.currentFields(); |
| | | if (values != null) |
| | | { |
| | | java.util.List<com.ruoyi.system.domain.TBatteryGroupRelationField> fields = new java.util.ArrayList<>(); |
| | | for (BatteryGroupDto.FieldValueDto value : values) |
| | | { |
| | | if (value == null) continue; |
| | | com.ruoyi.system.domain.TBatteryGroupRelationField field = new com.ruoyi.system.domain.TBatteryGroupRelationField(); |
| | | field.setBatteryGroupFieldId(value.resolvedFieldId()); field.setFieldValue(value.resolvedValue()); fields.add(field); |
| | | } |
| | | group.setFields(fields); |
| | | group.setTemplateFieldRelations(fields); |
| | | } |
| | | return group; |
| | | } |
| | | } |
| | |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.common.enums.BusinessType; |
| | | import com.ruoyi.system.domain.TTest; |
| | | import com.ruoyi.system.domain.TTestBattery; |
| | | import com.ruoyi.system.domain.TTestChannelBinding; |
| | | import com.ruoyi.system.domain.TTestCollectorChannel; |
| | | import com.ruoyi.system.domain.TTestWarningThreshold; |
| | | import com.battery.business.test.dto.TestConfigurationDto; |
| | | import com.battery.business.test.dto.TestBatteryBindingDto; |
| | | import com.battery.business.test.dto.ThresholdDto; |
| | | import com.ruoyi.system.domain.TTestResult; |
| | | import com.ruoyi.system.domain.TTestLogicStepMapping; |
| | | import com.ruoyi.system.domain.TTestConsoleDetail; |
| | |
| | | @PreAuthorize("@ss.hasPermi('system:test:add')") |
| | | @Log(title = "测试管理", businessType = BusinessType.INSERT) |
| | | @PostMapping |
| | | public AjaxResult add(@Validated @RequestBody TTest test) |
| | | public AjaxResult add(@Validated @RequestBody TestConfigurationDto request) |
| | | { |
| | | TTest test = toDomain(request); |
| | | test.setOperatorId(getUserId()); |
| | | test.setCreatorId(getUserId()); |
| | | test.setCreateBy(getUsername()); |
| | |
| | | @PreAuthorize("@ss.hasPermi('system:test:edit')") |
| | | @Log(title = "测试管理", businessType = BusinessType.UPDATE) |
| | | @PutMapping |
| | | public AjaxResult edit(@Validated @RequestBody TTest test) |
| | | public AjaxResult edit(@Validated @RequestBody TestConfigurationDto request) |
| | | { |
| | | TTest test = toDomain(request); |
| | | test.setOperatorId(getUserId()); |
| | | test.setUpdateBy(getUsername()); |
| | | testService.updateTest(test); |
| | |
| | | return getDataTable(testService.selectTestResults(result)); |
| | | } |
| | | |
| | | /** 将测试配置 DTO 转换为现有测试服务模型;计划工步等废止字段不再进入服务。 */ |
| | | private TTest toDomain(TestConfigurationDto request) |
| | | { |
| | | if (request == null) return null; |
| | | TTest test = new TTest(); |
| | | test.setTestId(request.testId()); test.setTestName(request.testName()); test.setPrincipalId(request.principalId()); |
| | | test.setTestTypeId(request.testTypeId()); test.setTestPurpose(request.testPurpose()); |
| | | test.setMonitorTimeoutMinutes(request.monitorTimeoutMinutes()); test.setRemark(request.remark()); |
| | | java.util.List<TTestBattery> batteries = new java.util.ArrayList<>(); |
| | | if (request.batteries() != null) for (TestBatteryBindingDto item : request.batteries()) |
| | | { |
| | | if (item == null) continue; |
| | | TTestBattery battery = new TTestBattery(); battery.setTestBatteryId(item.resolvedTestBatteryId()); |
| | | battery.setGroupId(item.groupId()); battery.setBatteryNo(item.batteryNo()); battery.setCollectorId(item.collectorId()); |
| | | if (item.resolvedCabinetChannel() != null) |
| | | { |
| | | TTestChannelBinding binding = new TTestChannelBinding(); |
| | | binding.setTestBatteryId(item.resolvedTestBatteryId()); binding.setChannelId(item.resolvedCabinetChannel().channelId()); |
| | | binding.setExpectedBarcode(item.resolvedCabinetChannel().expectedBarcode()); battery.setBinding(binding); |
| | | } |
| | | java.util.List<TTestCollectorChannel> channels = new java.util.ArrayList<>(); |
| | | if (item.collectorChannels() != null) for (TestBatteryBindingDto.CollectorChannelDto channel : item.collectorChannels()) |
| | | { |
| | | if (channel == null) continue; |
| | | TTestCollectorChannel mapping = new TTestCollectorChannel(); mapping.setTestBatteryId(item.resolvedTestBatteryId()); |
| | | mapping.setCollectorId(item.collectorId()); mapping.setMeasurementCode(channel.measurementCode()); |
| | | mapping.setMeasurementName(channel.measurementName()); mapping.setChannelCode(channel.channelCode()); channels.add(mapping); |
| | | } |
| | | battery.setCollectorChannels(channels); batteries.add(battery); |
| | | } |
| | | test.setBatteries(batteries); |
| | | java.util.List<TTestWarningThreshold> thresholds = new java.util.ArrayList<>(); |
| | | if (request.thresholds() != null) for (ThresholdDto item : request.thresholds()) |
| | | { |
| | | if (item == null) continue; |
| | | TTestWarningThreshold threshold = new TTestWarningThreshold(); threshold.setMetricCode(item.metricCode()); |
| | | threshold.setMinValue(item.minValue()); threshold.setMaxValue(item.maxValue()); threshold.setUnit(item.unit()); |
| | | threshold.setSeverity(item.severity()); thresholds.add(threshold); |
| | | } |
| | | test.setThresholds(thresholds); |
| | | return test; |
| | | } |
| | | |
| | | } |
| | |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.PutMapping; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import com.battery.business.test.dto.TestConfigurationDto; |
| | | |
| | | class TTestControllerContractTest |
| | | { |
| | |
| | | { |
| | | assertPermission("options", "@ss.hasAnyPermi('system:test:add,system:test:edit')"); |
| | | assertPermission("getInfo", "@ss.hasPermi('system:test:query')", Long.class); |
| | | assertPermission("add", "@ss.hasPermi('system:test:add')", com.ruoyi.system.domain.TTest.class); |
| | | assertPermission("edit", "@ss.hasPermi('system:test:edit')", com.ruoyi.system.domain.TTest.class); |
| | | assertPermission("add", "@ss.hasPermi('system:test:add')", TestConfigurationDto.class); |
| | | assertPermission("edit", "@ss.hasPermi('system:test:edit')", TestConfigurationDto.class); |
| | | assertPermission("startReception", "@ss.hasPermi('system:test:start')", Long.class); |
| | | Method startReception = TTestController.class.getMethod("startReception", Long.class); |
| | | assertEquals("/{testId}/reception/start", startReception.getAnnotation(PostMapping.class).value()[0]); |
| | |
| | | sample.energy_wh energy, channel.adapter_id adapterId, channel.adapter_code adapterCode, |
| | | channel.devtype devtype, channel.devid deviceId, channel.subdevid subdevid, channel.chlid channelId |
| | | from t_test_sample sample |
| | | join t_test_battery battery on battery.test_battery_id = sample.binding_id and battery.del_flag = 0 |
| | | join t_test_channel_binding binding on binding.binding_id = sample.binding_id |
| | | join t_test_battery battery on battery.test_battery_id = binding.test_battery_id and battery.del_flag = 0 |
| | | join t_detection_channel channel on channel.channel_id = sample.channel_id and channel.del_flag = 0 |
| | | where sample.test_id = #{testId} |
| | | order by sample.device_time_utc desc, sample.seq_id desc, sample.sample_id desc |
| | |
| | | channel.adapter_id adapterId, channel.adapter_code adapterCode, channel.devtype devtype, |
| | | channel.devid deviceId, channel.subdevid subdevid, channel.chlid channelId |
| | | from t_test_sample sample |
| | | join t_test_battery battery on battery.test_battery_id = sample.binding_id and battery.del_flag = 0 |
| | | join t_test_channel_binding binding on binding.binding_id = sample.binding_id |
| | | join t_test_battery battery on battery.test_battery_id = binding.test_battery_id and battery.del_flag = 0 |
| | | join t_detection_channel channel on channel.channel_id = sample.channel_id and channel.del_flag = 0 |
| | | where sample.test_id = #{testId} |
| | | group by sample.binding_id, battery.battery_no, channel.adapter_id, channel.adapter_code, channel.devtype, |
| | |
| | | channel.adapter_id adapterId, channel.adapter_code adapterCode, channel.devtype devtype, |
| | | channel.devid deviceId, channel.subdevid subdevid, channel.chlid channelId |
| | | from t_test_sample sample |
| | | join t_test_battery battery on battery.test_battery_id = sample.binding_id and battery.del_flag = 0 |
| | | join t_test_channel_binding binding on binding.binding_id = sample.binding_id |
| | | join t_test_battery battery on battery.test_battery_id = binding.test_battery_id and battery.del_flag = 0 |
| | | join t_detection_channel channel on channel.channel_id = sample.channel_id and channel.del_flag = 0 |
| | | where sample.test_id = #{testId} |
| | | group by sample.binding_id, battery.battery_no, channel.adapter_id, channel.adapter_code, channel.devtype, |