fix(自定义对比): 模块功能完善

This commit is contained in:
yjz
2023-10-31 10:31:32 +08:00
parent bc6be7d658
commit 8f0db41939
@@ -183,43 +183,66 @@ public class LawsCustomCompareInfoServiceImpl extends ServiceImpl<LawsCustomComp
}
saveOrUpdate(lawsCustomCompareInfo);
// 处理自定义对比_标准 关联表
// 删除数据
lawsCustomCompareInfoStandardService.remove(
// 自定义对比_标准 旧数据
List<LawsCustomCompareInfoStandard> oldData = lawsCustomCompareInfoStandardService.list(
new LambdaQueryWrapper<LawsCustomCompareInfoStandard>()
.eq(LawsCustomCompareInfoStandard::getInfoId, lawsCustomCompareInfo.getId()));
// 更新数据
// 自定义对比_标准 处理数据
StandardVO standardVO = new StandardVO();
standardVO.setStandardNumbers(standardSaveVO.getStandardNumber());
// 查询勾选标准
List<StandardVO> standardVOS = queryStandardList(standardVO);
// 数据拷贝
List<LawsCustomCompareInfoStandard> lawsCustomCompareInfoStandards = BeanCopyUtils.copyBeanList(standardVOS, LawsCustomCompareInfoStandard.class);
// 收集数据id集合
List<String> infoStandardIdList = new ArrayList<>();
// 收集标准id集合
List<String> standardIdList = new ArrayList<>();
for (LawsCustomCompareInfoStandard lawsCustomCompareInfoStandard : lawsCustomCompareInfoStandards) {
String standardId = lawsCustomCompareInfoStandard.getId();
String snowflakeId = String.valueOf(SnowflakeUtils.snowflake());
// 自定义对比单元格数据更新
lawsCustomCompareCellService.update(
new LambdaUpdateWrapper<LawsCustomCompareCell>()
.eq(LawsCustomCompareCell::getInfoId, lawsCustomCompareInfo.getId())
.eq(LawsCustomCompareCell::getStandardId, lawsCustomCompareInfoStandard.getId())
.set(LawsCustomCompareCell::getStandardId, snowflakeId));
lawsCustomCompareInfoStandard.setId(snowflakeId);
// 是否已存在此标准 存在更新,不存在新增
Optional<LawsCustomCompareInfoStandard> optional = oldData.stream().filter(v -> v.getStandardId().equals(lawsCustomCompareInfoStandard.getId())).findFirst();
if (optional.isPresent()){
lawsCustomCompareInfoStandard.setId(optional.get().getId());
}else {
lawsCustomCompareInfoStandard.setId(snowflakeId);
}
infoStandardIdList.add(lawsCustomCompareInfoStandard.getId());
lawsCustomCompareInfoStandard.setInfoId(lawsCustomCompareInfo.getId());
lawsCustomCompareInfoStandard.setStandardId(standardId);
standardIdList.add(standardId);
lawsCustomCompareInfoStandard.setCreateBy("");
lawsCustomCompareInfoStandard.setCreateTime(null);
lawsCustomCompareInfoStandard.setUpdateBy("");
lawsCustomCompareInfoStandard.setUpdateTime(null);
lawsCustomCompareInfoStandardService.save(lawsCustomCompareInfoStandard);
lawsCustomCompareInfoStandardService.saveOrUpdate(lawsCustomCompareInfoStandard);
}
// 自定义对比单元格 删除
String ids = standardVOS.stream().map(StandardVO::getId).collect(Collectors.joining(","));
lawsCustomCompareCellService.remove(
new LambdaUpdateWrapper<LawsCustomCompareCell>()
.eq(LawsCustomCompareCell::getInfoId, lawsCustomCompareInfo.getId())
.notIn(LawsCustomCompareCell::getStandardId, ids));
// 删除旧数据
if (standardVOS.isEmpty()){
// 自定义对比_标准 删除
lawsCustomCompareInfoStandardService.remove(
new LambdaQueryWrapper<LawsCustomCompareInfoStandard>()
.eq(LawsCustomCompareInfoStandard::getInfoId, lawsCustomCompareInfo.getId()));
// 自定义对比单元格 删除
lawsCustomCompareCellService.remove(
new LambdaUpdateWrapper<LawsCustomCompareCell>()
.eq(LawsCustomCompareCell::getInfoId, lawsCustomCompareInfo.getId()));
}else {
// 自定义对比_标准 删除
lawsCustomCompareInfoStandardService.remove(
new LambdaQueryWrapper<LawsCustomCompareInfoStandard>()
.eq(LawsCustomCompareInfoStandard::getInfoId, lawsCustomCompareInfo.getId())
.notIn(LawsCustomCompareInfoStandard::getId, infoStandardIdList));
// 自定义对比单元格 删除
lawsCustomCompareCellService.remove(
new LambdaUpdateWrapper<LawsCustomCompareCell>()
.eq(LawsCustomCompareCell::getInfoId, lawsCustomCompareInfo.getId())
.notIn(LawsCustomCompareCell::getStandardId, standardIdList));
}
return lawsCustomCompareInfo.getId();
}
@@ -537,10 +560,13 @@ public class LawsCustomCompareInfoServiceImpl extends ServiceImpl<LawsCustomComp
indexCell.setCellStyle(cellStyle);
// 特点数量
int featureSize = featureList.size();
// 合并单元格(参数说明:起始行,结束行,起始列,结束列)
CellRangeAddress region = new CellRangeAddress(1, 1, index.get() + nextMergeFirst.get(), index.get() + featureSize - 1 + nextMergeFirst.get());
nextMergeFirst.set(featureSize - 1);
sheet.addMergedRegionUnsafe(region);
// 只有一个单元格则不合并
if ((index.get() + nextMergeFirst.get()) != (index.get() + featureSize - 1 + nextMergeFirst.get())){
// 合并单元格(参数说明:起始行,结束行,起始列,结束列)
CellRangeAddress region = new CellRangeAddress(1, 1, index.get() + nextMergeFirst.get(), index.get() + featureSize - 1 + nextMergeFirst.get());
sheet.addMergedRegionUnsafe(region);
nextMergeFirst.set(featureSize - 1);
}
}
}
@@ -569,10 +595,13 @@ public class LawsCustomCompareInfoServiceImpl extends ServiceImpl<LawsCustomComp
Cell indexCell = headerRow.createCell(index.get() + nextMergeFirst.get());
indexCell.setCellValue(k);
indexCell.setCellStyle(cellStyle);
// 合并单元格(参数说明:起始行,结束行,起始列,结束列)
CellRangeAddress region = new CellRangeAddress(0, 0, index.get() + nextMergeFirst.get(), index.get() + nextMergeFirst.get() + merge - 1);
nextMergeFirst.set(merge - 1);
sheet.addMergedRegion(region);
// 只有一个单元格则不合并
if ((index.get() + nextMergeFirst.get()) != (index.get() + nextMergeFirst.get() + merge - 1)){
// 合并单元格(参数说明:起始行,结束行,起始列,结束列)
CellRangeAddress region = new CellRangeAddress(0, 0, index.get() + nextMergeFirst.get(), index.get() + nextMergeFirst.get() + merge - 1);
sheet.addMergedRegion(region);
nextMergeFirst.set(merge - 1);
}
});
}
}