yeg
2026-08-27 ebd47e950c8d45f5cc21336f4996857de58e0ea6
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TBatteryGroupServiceImpl.java
@@ -22,7 +22,6 @@
public class TBatteryGroupServiceImpl implements ITBatteryGroupService
{
    private static final String ENABLED = "0";
    private static final String TESTING = "1";
    @Autowired
    private TBatteryGroupMapper batteryGroupMapper;
@@ -56,13 +55,13 @@
    @Transactional(rollbackFor = Exception.class)
    public int insertBatteryGroup(TBatteryGroup group)
    {
        validate(group, false);
        group.setGroupName(StringUtils.trim(group.getGroupName()));
        group.setCreateTime(new Date());
        if (StringUtils.isEmpty(group.getStatus()))
        {
            group.setStatus(ENABLED);
        }
        validate(group, false);
        group.setGroupName(StringUtils.trim(group.getGroupName()));
        group.setCreateTime(new Date());
        int rows = batteryGroupMapper.insertBatteryGroup(group);
        replaceRelations(group);
        return rows;
@@ -76,10 +75,16 @@
        {
            throw new ServiceException("电池组ID不能为空");
        }
        if (batteryGroupMapper.selectBatteryGroupById(group.getGroupId()) == null)
        TBatteryGroup current = batteryGroupMapper.selectBatteryGroupById(group.getGroupId());
        if (current == null)
        {
            throw new ServiceException("电池组不存在");
        }
        if (StringUtils.isEmpty(group.getStatus()))
        {
            group.setStatus(current.getStatus());
        }
        validateStatusChange(group, current.getStatus());
        validate(group, true);
        group.setGroupName(StringUtils.trim(group.getGroupName()));
        group.setUpdateTime(new Date());
@@ -100,7 +105,7 @@
        {
            throw new ServiceException("电池组ID和目标状态不能为空");
        }
        if (TESTING.equals(group.getStatus()) || !ENABLED.equals(group.getStatus()) && !"1".equals(group.getStatus()))
        if (!ENABLED.equals(group.getStatus()) && !"1".equals(group.getStatus()))
        {
            throw new ServiceException("电池组状态不正确");
        }
@@ -155,6 +160,10 @@
        {
            throw new ServiceException("电池组型号不能为空");
        }
        if (!ENABLED.equals(group.getStatus()) && !"1".equals(group.getStatus()))
        {
            throw new ServiceException("电池组状态不正确");
        }
        TBatteryGroup existing = batteryGroupMapper.selectBatteryGroupByName(StringUtils.trim(group.getGroupName()));
        if (existing != null && (group.getGroupId() == null || !group.getGroupId().equals(existing.getGroupId())))
        {
@@ -198,6 +207,10 @@
                if (relation == null || relation.getBatteryGroupFieldId() == null || !fieldIds.add(relation.getBatteryGroupFieldId()))
                {
                    throw new ServiceException("模板字段关系不正确");
                }
                if (relation.getFieldValue() != null && relation.getFieldValue().length() > 500)
                {
                    throw new ServiceException("模板字段值长度不能超过500个字符");
                }
            }
        }
@@ -258,4 +271,13 @@
        }
        batteryGroupMapper.batchInsertRelationFields(relations);
    }
    private void validateStatusChange(TBatteryGroup group, String currentStatus)
    {
        if ("1".equals(group.getStatus()) && !"1".equals(currentStatus)
                && batteryGroupMapper.countTestingByGroupId(group.getGroupId()) > 0)
        {
            throw new ServiceException("测试中的电池组不能禁用");
        }
    }
}