| File was renamed from ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TBatteryGroupServiceImpl.java |
| | |
| | | package com.ruoyi.system.service.impl; |
| | | package com.battery.business.service.impl; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.math.BigDecimal; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.system.domain.TBatteryGroup; |
| | | import com.ruoyi.system.domain.TBatteryGroupBattery; |
| | | import com.ruoyi.system.domain.TBatteryGroupRelationField; |
| | | import com.ruoyi.system.mapper.TBatteryGroupMapper; |
| | | import com.ruoyi.system.service.ITBatteryGroupService; |
| | | import com.battery.business.domain.TBatteryGroup; |
| | | import com.battery.business.domain.TBatteryGroupBattery; |
| | | import com.battery.business.domain.TBatteryGroupRelationField; |
| | | import com.battery.business.mapper.TBatteryGroupMapper; |
| | | import com.battery.business.service.ITBatteryGroupService; |
| | | |
| | | /** 电池组管理服务实现。 */ |
| | | @Service |
| | |
| | | for (TBatteryGroup item : groups) |
| | | { |
| | | item.setTemplateFields(batteryGroupMapper.selectRelationFields(item.getGroupId())); |
| | | loadSpecFields(item); |
| | | } |
| | | return groups; |
| | | } |
| | |
| | | } |
| | | group.setBatteries(batteryGroupMapper.selectBatteries(groupId)); |
| | | group.setTemplateFields(batteryGroupMapper.selectRelationFields(groupId)); |
| | | loadSpecFields(group); |
| | | return group; |
| | | } |
| | | |
| | |
| | | group.setCreateTime(new Date()); |
| | | int rows = batteryGroupMapper.insertBatteryGroup(group); |
| | | replaceRelations(group); |
| | | batteryGroupMapper.saveSpecFields(group); |
| | | return rows; |
| | | } |
| | | |
| | |
| | | throw new ServiceException("电池组不存在或已删除"); |
| | | } |
| | | replaceRelations(group); |
| | | batteryGroupMapper.saveSpecFields(group); |
| | | return rows; |
| | | } |
| | | |
| | |
| | | } |
| | | if (group.getTemplateId() == null) |
| | | { |
| | | if (group.getTemplateFieldRelations() != null && !group.getTemplateFieldRelations().isEmpty()) |
| | | List<TBatteryGroupRelationField> values = group.getTemplateFieldRelations(); |
| | | if (values != null && !values.isEmpty()) |
| | | { |
| | | throw new ServiceException("未选择模板时不能配置模板字段"); |
| | | List<Long> ids = values.stream().map(TBatteryGroupRelationField::getBatteryGroupFieldId).toList(); |
| | | if (ids.contains(null) || new HashSet<>(ids).size() != ids.size()) throw new ServiceException("字段身份无效或重复"); |
| | | List<TBatteryGroupRelationField> definitions = batteryGroupMapper.selectCurrentFieldDefinitions(ids); |
| | | if (definitions.size() != ids.size()) throw new ServiceException("字段定义不存在"); |
| | | for (TBatteryGroupRelationField value : values) |
| | | { |
| | | if (value.getFieldValue() != null && value.getFieldValue().length() > 500) throw new ServiceException("字段值过长"); |
| | | TBatteryGroupRelationField definition = definitions.stream().filter(item -> item.getBatteryGroupFieldId().equals(value.getBatteryGroupFieldId())).findFirst().orElseThrow(); |
| | | validateFieldValue(definition.getFieldType(), value.getFieldValue()); |
| | | } |
| | | } |
| | | return; |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | private void loadSpecFields(TBatteryGroup group) |
| | | { |
| | | // 现有表单的固定入口投影到当前字段,不恢复主表专用字段或测试快照。 |
| | | if (group.getTemplateFields() == null) return; |
| | | for (TBatteryGroupRelationField field : group.getTemplateFields()) |
| | | { |
| | | if (field.getFieldName() == null) continue; |
| | | switch (field.getFieldName()) |
| | | { |
| | | case "Z" -> group.setZ(field.getFieldValue()); |
| | | case "H" -> group.setH(field.getFieldValue()); |
| | | case "F" -> group.setF(field.getFieldValue()); |
| | | case "A" -> group.setA(field.getFieldValue()); |
| | | case "B" -> group.setB(field.getFieldValue()); |
| | | default -> { } |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void replaceRelations(TBatteryGroup group) |
| | | { |
| | | batteryGroupMapper.deleteBatteries(group.getGroupId()); |
| | |
| | | batteries.add(item); |
| | | } |
| | | batteryGroupMapper.batchInsertBatteries(batteries); |
| | | if (group.getTemplateId() == null) |
| | | if (group.getTemplateId() == null && (group.getTemplateFieldRelations() == null || group.getTemplateFieldRelations().isEmpty())) |
| | | { |
| | | return; |
| | | } |