| | |
| | | import com.ruoyi.system.vo.asset.AssetTypeTreeVO; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | |
| | | childQueryWrapper.eq(AssetType::getParentId, id); |
| | | long childCount = this.count(childQueryWrapper); |
| | | if (childCount > 0) { |
| | | throw new ServiceException("该资产类型存在子类型,不能删除"); |
| | | throw new ServiceException(String.format("【%s】存在子类型,不能删除", existingAssetType.getTypeName())); |
| | | } |
| | | |
| | | // 校验是否有关联的资产记录 |
| | |
| | | assetMainQueryWrapper.eq(AssetMain::getAssetTypeId, id); |
| | | long assetMainCount = assetMainService.count(assetMainQueryWrapper); |
| | | if (assetMainCount > 0) { |
| | | throw new ServiceException("该资产类型已关联资产记录,不能删除"); |
| | | throw new ServiceException(String.format("【%s】已关联资产记录,不能删除", existingAssetType.getTypeName())); |
| | | } |
| | | |
| | | // 删除资产类型 |
| | | this.removeById(id); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void batchDeleteAssetType(List<Integer> ids) { |
| | | // 校验ID列表是否为空 |
| | | if (CollUtil.isEmpty(ids)) { |
| | | throw new ServiceException("删除的资产类型ID列表不能为空"); |
| | | } |
| | | |
| | | // 收集删除失败的信息 |
| | | List<String> failedMessages = new ArrayList<>(); |
| | | |
| | | // 逐个删除资产类型 |
| | | for (Integer id : ids) { |
| | | try { |
| | | this.deleteAssetType(id); |
| | | } catch (ServiceException e) { |
| | | failedMessages.add(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | // 如果有删除失败的情况,抛出异常 |
| | | if (CollUtil.isNotEmpty(failedMessages)) { |
| | | throw new ServiceException("批量删除失败:" + String.join(";", failedMessages)); |
| | | } |
| | | } |
| | | |
| | | } |