|
|
@@ -238,54 +238,57 @@ public class BlindStructuresServiceImpl implements IBlindStructuresService {
|
|
|
Long userId = LoginHelper.getUserId();
|
|
|
update.setUpdateUserId(userId);
|
|
|
|
|
|
-
|
|
|
// 1. 解析 Excel 文件
|
|
|
- List<BlindLevelsImportVo> dataList;
|
|
|
- try (InputStream inputStream = file.getInputStream()) {
|
|
|
- dataList = parseExcel(inputStream);
|
|
|
- } catch (IOException e) {
|
|
|
- log.error("读取文件失败", e);
|
|
|
- return R.fail("读取文件失败");
|
|
|
- }
|
|
|
+ List<BlindLevelsImportVo> dataList = List.of();
|
|
|
+ if (file != null) {
|
|
|
+ try (InputStream inputStream = file.getInputStream()) {
|
|
|
+ dataList = parseExcel(inputStream);
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("读取文件失败", e);
|
|
|
+ return R.fail("读取文件失败");
|
|
|
+ }
|
|
|
|
|
|
- if (CollectionUtils.isEmpty(dataList)) {
|
|
|
- return R.fail("导入数据为空");
|
|
|
+ if (CollectionUtils.isEmpty(dataList)) {
|
|
|
+ return R.fail("导入数据为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 校验数据逻辑(可选)
|
|
|
+ BlindLevelsValidatorUtils.ValidationResult validationResult = BlindLevelsValidatorUtils.validateBlindLevels(dataList);
|
|
|
+ if (validationResult.isValid()) {
|
|
|
+ System.out.println("数据校验通过");
|
|
|
+ } else {
|
|
|
+ return R.fail(validationResult.getErrorMessage());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
- // 校验数据逻辑(可选)
|
|
|
- BlindLevelsValidatorUtils.ValidationResult validationResult = BlindLevelsValidatorUtils.validateBlindLevels(dataList);
|
|
|
- if (validationResult.isValid()) {
|
|
|
- System.out.println("数据校验通过");
|
|
|
- } else {
|
|
|
- return R.fail(validationResult.getErrorMessage());
|
|
|
- }
|
|
|
|
|
|
// 2. 更新主表
|
|
|
int i = baseMapper.updateBlindStructuresById(update);
|
|
|
if (i <= 0) {
|
|
|
return R.fail("更新失败");
|
|
|
}
|
|
|
+ if (file != null) {
|
|
|
+ // 3. 删除原有等级数据
|
|
|
+ Boolean b = blindLevelsService.deleteBlindLevelByBlindStructureId(update.getId());
|
|
|
+ /* if (!b) {
|
|
|
+ return R.fail("删除历史等级失败");
|
|
|
+ }*/
|
|
|
+
|
|
|
+ // 5. 插入新等级数据
|
|
|
+ for (BlindLevelsImportVo vo : dataList) {
|
|
|
+ BlindLevelsBo levelBo = new BlindLevelsBo();
|
|
|
+ levelBo.setBlindStructureId(update.getId());
|
|
|
+ levelBo.setLevelNumber(vo.getLevelNumber());
|
|
|
+ levelBo.setSmallBlind(vo.getSmallBlind());
|
|
|
+ levelBo.setBigBlind(vo.getBigBlind());
|
|
|
+ levelBo.setAnte(vo.getAnte());
|
|
|
+ levelBo.setDurationMinutes(vo.getDurationMinutes());
|
|
|
+ levelBo.setCreateUserId(userId);
|
|
|
+ blindLevelsService.insertByBo(levelBo);
|
|
|
+ }
|
|
|
|
|
|
- // 3. 删除原有等级数据
|
|
|
- Boolean b = blindLevelsService.deleteBlindLevelByBlindStructureId(update.getId());
|
|
|
- /* if (!b) {
|
|
|
- return R.fail("删除历史等级失败");
|
|
|
- }*/
|
|
|
-
|
|
|
- // 5. 插入新等级数据
|
|
|
- for (BlindLevelsImportVo vo : dataList) {
|
|
|
- BlindLevelsBo levelBo = new BlindLevelsBo();
|
|
|
- levelBo.setBlindStructureId(update.getId());
|
|
|
- levelBo.setLevelNumber(vo.getLevelNumber());
|
|
|
- levelBo.setSmallBlind(vo.getSmallBlind());
|
|
|
- levelBo.setBigBlind(vo.getBigBlind());
|
|
|
- levelBo.setAnte(vo.getAnte());
|
|
|
- levelBo.setDurationMinutes(vo.getDurationMinutes());
|
|
|
- levelBo.setCreateUserId(userId);
|
|
|
- blindLevelsService.insertByBo(levelBo);
|
|
|
}
|
|
|
-
|
|
|
return R.ok(true); // 成功返回 true
|
|
|
|
|
|
} catch (Exception e) {
|