新增接口中根据data_id判断数据是否已经保存过

This commit is contained in:
hecan 2024-08-08 10:17:49 +08:00
parent 9d2875e3ba
commit 3b897cf172
1 changed files with 13 additions and 0 deletions

View File

@ -211,6 +211,19 @@ public class ComparisonServiceImpl extends BaseService<ComparisonEntity, String>
if (comparisonEntities != null && comparisonEntities.size() > 0) {
map = spliceMainMap(comparisonEntities, jsonObjectMain, map, comparisonEntity, comparisonDetailsEntity);
//根据data_id判断数据是否已经保存在相关表中,避免重复保存
List<String> fields = getFields(comparisonEntity);
Map<String,Object> mapDataId=new HashMap<>();
mapDataId.put("data_id",jsonObjectMain.getString("data_id"));
ComparisonEntity comparisonDataId=new ComparisonEntity();
comparisonDataId.setMap(mapDataId);
comparisonDataId.setDbName(comparisonEntity.getDbName());
comparisonDataId.setFields(fields);
List<Map<String, Object>> listDataId = comparisonDao.queryComparisonPage(comparisonDataId);
if(CollectionUtils.isNotEmpty(listDataId)){
return BaseResult.getFailureMessageEntity(comparisonEntity.getDbName()+"表中已经存在data_id为:"+jsonObjectMain.getString("data_id")+"的数据");
}
//判断输入的主表字段是否是必填项
for (ComparisonEntity entity : comparisonEntities) {
//如果必填字段不为空