package com.ruoyi.other.service.impl; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.common.core.exception.ServiceException; import com.ruoyi.other.domain.TPlatformConfig; import com.ruoyi.other.mapper.TPlatformConfigMapper; import com.ruoyi.other.service.TPlatformConfigService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.HashSet; import java.util.List; import java.util.Set; /** 光伏储能配置服务实现。 */ @Service public class TPlatformConfigServiceImpl extends ServiceImpl implements TPlatformConfigService { @Override public List listAll() { return list(Wrappers.lambdaQuery(TPlatformConfig.class).orderByAsc(TPlatformConfig::getId)); } @Override @Transactional(rollbackFor = Exception.class) public void saveBatchConfigs(List configs) { if (configs == null || configs.isEmpty()) { throw new ServiceException("保存的配置列表不能为空"); } Set ids = new HashSet<>(); for (TPlatformConfig config : configs) { if (config == null) { throw new ServiceException("配置列表不能包含空数据"); } if (config.getType() != null && config.getType() != 1 && config.getType() != 2) { throw new ServiceException("配置类型只能为1(光伏)或2(储能)"); } if (config.getId() != null && (config.getId() <= 0 || !ids.add(config.getId()))) { throw new ServiceException("配置ID必须为正数且不能重复"); } } // 传入 ID 必须对应有效配置,避免误将已删除或不存在的记录作为新增保存。 if (!ids.isEmpty() && listByIds(ids).size() != ids.size()) { throw new ServiceException("待修改的配置不存在或已删除"); } for (TPlatformConfig config : configs) { config.setDelFlag("0"); config.setCreateTime(null); config.setUpdateTime(null); } if (!saveOrUpdateBatch(configs)) { throw new ServiceException("批量保存平台配置失败"); } } }