调整修改和新增得参数,为表名称
This commit is contained in:
parent
c5dc5449d0
commit
422f5f4469
|
@ -149,26 +149,37 @@ public class ComparisonServiceImpl extends BaseService<ComparisonEntity, String>
|
||||||
}
|
}
|
||||||
JSONObject jsonObjectMain=new JSONObject();
|
JSONObject jsonObjectMain=new JSONObject();
|
||||||
JSONArray jsonArray=new JSONArray();
|
JSONArray jsonArray=new JSONArray();
|
||||||
|
List<JSONArray> arrayList=new ArrayList<>();
|
||||||
//根据dbtype和dbname分组,拿到表名称和表类型
|
//根据dbtype和dbname分组,拿到表名称和表类型
|
||||||
Map<String, Map<String, List<ComparisonEntity>>> collect = comparisonEntities.stream().collect(Collectors.groupingBy(ComparisonEntity::getDbName, Collectors.groupingBy(ComparisonEntity::getDbType)));
|
Map<String, Map<String, List<ComparisonEntity>>> collect = comparisonEntities.stream().collect(Collectors.groupingBy(ComparisonEntity::getDbName, Collectors.groupingBy(ComparisonEntity::getDbType)));
|
||||||
List<Map.Entry<String, String>> keyPairs = collect.entrySet().stream()
|
List<Map.Entry<String, String>> keyPairs = collect.entrySet().stream()
|
||||||
.flatMap(e1 -> e1.getValue().keySet().stream()
|
.flatMap(e1 -> e1.getValue().keySet().stream()
|
||||||
.map(dbname -> new AbstractMap.SimpleEntry<>(e1.getKey(), dbname)))
|
.map(dbname -> new AbstractMap.SimpleEntry<>(e1.getKey(), dbname)))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
// keyPairs 得值为键值对,键是表名称,值是类型,避免多个子表得键一样,比如:mdm_customer:1,mdm_customer_bank:2,mdm_customer_option_log:2
|
||||||
for (Map.Entry<String, String> keyPair : keyPairs) {
|
for (Map.Entry<String, String> keyPair : keyPairs) {
|
||||||
|
//如果是1,就是主表,根据查询出来得主表是否是传输传递得主表
|
||||||
if(keyPair.getValue().equals("1")){
|
if(keyPair.getValue().equals("1")){
|
||||||
String main = jsonObject.getString(keyPair.getKey());
|
String main = jsonObject.getString(keyPair.getKey());
|
||||||
if(main!=null){
|
if(main!=null){
|
||||||
jsonObjectMain = JSONObject.parseObject(main);
|
jsonObjectMain = JSONObject.parseObject(main);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//如果是2,就是明细表,根据查询出来得子表是否是传输传递得子表
|
||||||
if(keyPair.getValue().equals("2")){
|
if(keyPair.getValue().equals("2")){
|
||||||
jsonArray= jsonObject.getJSONArray(keyPair.getKey());
|
jsonArray= jsonObject.getJSONArray(keyPair.getKey());
|
||||||
|
if(jsonArray!= null) {
|
||||||
|
for (int i = 0; i < jsonArray.size(); i++) {
|
||||||
|
JSONObject jsonObjectDetails = jsonArray.getJSONObject(i);
|
||||||
|
jsonObjectDetails.put("table_name", keyPair.getKey());
|
||||||
|
}
|
||||||
|
arrayList.add(jsonArray);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(jsonObjectMain!=null && jsonObjectMain.size()>0) {
|
if(jsonObjectMain!=null && jsonObjectMain.size()>0) {
|
||||||
Map<String, Object> map = new HashMap<>();//将主表数据存到map中
|
Map<String, Object> map = new HashMap<>();//将主表数据存到map中
|
||||||
List<Map<String, Object>> mapDetails = new ArrayList<>();//将子表数据存到map中
|
List<List<Map<String, Object>>> mapDetails = new ArrayList<>();//将子表数据存到map中
|
||||||
if (comparisonEntities != null && comparisonEntities.size() > 0) {
|
if (comparisonEntities != null && comparisonEntities.size() > 0) {
|
||||||
map = spliceMainMap(comparisonEntities, jsonObjectMain, map, comparisonEntity, comparisonDetailsEntity);
|
map = spliceMainMap(comparisonEntities, jsonObjectMain, map, comparisonEntity, comparisonDetailsEntity);
|
||||||
String uuid = null;
|
String uuid = null;
|
||||||
|
@ -227,28 +238,32 @@ public class ComparisonServiceImpl extends BaseService<ComparisonEntity, String>
|
||||||
List<JSONObject> list = new ArrayList<>();
|
List<JSONObject> list = new ArrayList<>();
|
||||||
JSONObject jsonObjectList = new JSONObject();
|
JSONObject jsonObjectList = new JSONObject();
|
||||||
//保存主表数据
|
//保存主表数据
|
||||||
//ComparisonEntity comparisonEntityOne = comparisonDao.saveComparison(comparisonEntityRule);
|
ComparisonEntity comparisonEntityOne = comparisonDao.saveComparison(comparisonEntityRule);
|
||||||
// jsonObjectList.put(comparisonEntityOne.getDbName(),map);
|
jsonObjectList.put(comparisonEntityOne.getDbName(),map);
|
||||||
//保存子表数据
|
//保存子表数据
|
||||||
if (jsonArray != null && jsonArray.size() > 0) {
|
if (arrayList != null && arrayList.size() > 0) {
|
||||||
mapDetails = spliceDetailMap(comparisonEntities, mapDetails, jsonArray);
|
mapDetails = spliceDetailMap(comparisonEntities, mapDetails, arrayList);
|
||||||
if (mapDetails.size() > 0 && mapDetails != null) {
|
if(mapDetails.size()>0 && mapDetails!=null ){
|
||||||
for (Map<String, Object> mapDetail : mapDetails) {
|
for (List<Map<String, Object>> mapDetail : mapDetails) {
|
||||||
String uuidDetail = UUIDUtils.getUUID();
|
for (Map<String, Object> stringObjectMap : mapDetail) {
|
||||||
mapDetail.put("id", uuidDetail);
|
String uuidDetail = UUIDUtils.getUUID();
|
||||||
mapDetail.put("formmain_id", uuid);
|
stringObjectMap.put("id", uuidDetail);
|
||||||
mapDetail.put("create_user_id", "c796fd9ba4c9f5ff3cc2fa41a040e443");
|
stringObjectMap.put("formmain_id", uuid);
|
||||||
mapDetail.put("modify_user_id", "c796fd9ba4c9f5ff3cc2fa41a040e443");
|
stringObjectMap.put("create_user_id", "c796fd9ba4c9f5ff3cc2fa41a040e443");
|
||||||
mapDetail.put("org_id", "0");
|
stringObjectMap.put("modify_user_id", "c796fd9ba4c9f5ff3cc2fa41a040e443");
|
||||||
mapDetail.put("create_time", new Date());
|
stringObjectMap.put("org_id", "0");
|
||||||
mapDetail.put("modify_time", new Date());
|
stringObjectMap.put("create_time", new Date());
|
||||||
mapDetail.put("sts", "Y");
|
stringObjectMap.put("modify_time", new Date());
|
||||||
mapDetail.put("data_status", "Y");//新增状态
|
stringObjectMap.put("sts", "Y");
|
||||||
comparisonDetailsEntity.setMapDetails(mapDetail);
|
stringObjectMap.put("data_status", "Y");//新增状态
|
||||||
//ComparisonDetailsEntity comparisonDetailsEntityOne = comparisonDetailsDao.saveComparisonDetails(comparisonDetailsEntity);
|
comparisonDetailsEntity.setMapDetails(stringObjectMap);
|
||||||
//comparisonEntityOne.setComparisonDetailsEntity(comparisonDetailsEntityOne);
|
comparisonDetailsEntity.setDbName(String.valueOf(stringObjectMap.get("table_name")));
|
||||||
//保存操作日志
|
stringObjectMap.remove("table_name");
|
||||||
//controlsLogDaoimpl.saveControlsLog(uuidDetail,jsonObject.getString("appName"),jsonObject.getString("appCode"),jsonObject.toJSONString(),"接口新增",jsonObject.getString("optionName"),comparisonDetailsEntity.getDbName()+"_option_log");
|
ComparisonDetailsEntity comparisonDetailsEntityOne = comparisonDetailsDao.saveComparisonDetails(comparisonDetailsEntity);
|
||||||
|
comparisonEntityOne.setComparisonDetailsEntity(comparisonDetailsEntityOne);
|
||||||
|
//保存操作日志
|
||||||
|
//controlsLogDaoimpl.saveControlsLog(uuidDetail,jsonObject.getString("appName"),jsonObject.getString("appCode"),jsonObject.toJSONString(),"接口新增",jsonObject.getString("optionName"),comparisonDetailsEntity.getDbName()+"_option_log");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
jsonObjectList.put(comparisonDetailsEntity.getDbName(), mapDetails);
|
jsonObjectList.put(comparisonDetailsEntity.getDbName(), mapDetails);
|
||||||
}
|
}
|
||||||
|
@ -283,11 +298,6 @@ public class ComparisonServiceImpl extends BaseService<ComparisonEntity, String>
|
||||||
}
|
}
|
||||||
ComparisonEntity comparisonEntity = jsonObject.toJavaObject(ComparisonEntity.class);
|
ComparisonEntity comparisonEntity = jsonObject.toJavaObject(ComparisonEntity.class);
|
||||||
ComparisonDetailsEntity comparisonDetailsEntity=new ComparisonDetailsEntity();
|
ComparisonDetailsEntity comparisonDetailsEntity=new ComparisonDetailsEntity();
|
||||||
JSONObject jsonObjectMain=jsonObject.getJSONObject("main");//获取主表数据
|
|
||||||
JSONArray jsonArray = jsonObject.getJSONArray("details");//获取子表数据
|
|
||||||
if(!checkStr(jsonObjectMain.getString("id"))){
|
|
||||||
return BaseResult.getFailureMessageEntity("更新时候主表id不能为空");
|
|
||||||
}
|
|
||||||
List<ComparisonEntity> comparisonEntities=new ArrayList<>();
|
List<ComparisonEntity> comparisonEntities=new ArrayList<>();
|
||||||
//根据主数据编码查询表名称,字段名称等信息 10001
|
//根据主数据编码查询表名称,字段名称等信息 10001
|
||||||
try {
|
try {
|
||||||
|
@ -299,8 +309,41 @@ public class ComparisonServiceImpl extends BaseService<ComparisonEntity, String>
|
||||||
logger.info("根据主数据编码查询信息错误:{}",e.getMessage());
|
logger.info("根据主数据编码查询信息错误:{}",e.getMessage());
|
||||||
return BaseResult.getFailureMessageEntity("更新失败");
|
return BaseResult.getFailureMessageEntity("更新失败");
|
||||||
}
|
}
|
||||||
|
JSONObject jsonObjectMain=new JSONObject();
|
||||||
|
JSONArray jsonArray=new JSONArray();
|
||||||
|
List<JSONArray> arrayList=new ArrayList<>();
|
||||||
|
//根据dbtype和dbname分组,拿到表名称和表类型
|
||||||
|
Map<String, Map<String, List<ComparisonEntity>>> collect = comparisonEntities.stream().collect(Collectors.groupingBy(ComparisonEntity::getDbName, Collectors.groupingBy(ComparisonEntity::getDbType)));
|
||||||
|
List<Map.Entry<String, String>> keyPairs = collect.entrySet().stream()
|
||||||
|
.flatMap(e1 -> e1.getValue().keySet().stream()
|
||||||
|
.map(dbname -> new AbstractMap.SimpleEntry<>(e1.getKey(), dbname)))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
for (Map.Entry<String, String> keyPair : keyPairs) {
|
||||||
|
if(keyPair.getValue().equals("1")){
|
||||||
|
String main = jsonObject.getString(keyPair.getKey());
|
||||||
|
if(main!=null){
|
||||||
|
jsonObjectMain = JSONObject.parseObject(main);
|
||||||
|
if(!checkStr(jsonObjectMain.getString("id"))){
|
||||||
|
return BaseResult.getFailureMessageEntity("更新时候主表id不能为空");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(keyPair.getValue().equals("2")){
|
||||||
|
jsonArray= jsonObject.getJSONArray(keyPair.getKey());
|
||||||
|
if(jsonArray!= null) {
|
||||||
|
for (int i = 0; i < jsonArray.size(); i++) {
|
||||||
|
JSONObject jsonObjectDetails = jsonArray.getJSONObject(i);
|
||||||
|
if(!checkStr(jsonObjectDetails.getString("id"))){
|
||||||
|
return BaseResult.getFailureMessageEntity("更新明细表时候明细表id不能为空");
|
||||||
|
}
|
||||||
|
jsonObjectDetails.put("table_name", keyPair.getKey());
|
||||||
|
}
|
||||||
|
arrayList.add(jsonArray);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Map<String,Object> map=new HashMap<>();//将主表数据存到map中
|
Map<String,Object> map=new HashMap<>();//将主表数据存到map中
|
||||||
List<Map<String,Object>> mapDetails=new ArrayList<>();//将子表数据存到map中
|
List<List<Map<String,Object>>> mapDetails=new ArrayList<>();//将子表数据存到map中
|
||||||
if(comparisonEntities !=null && comparisonEntities.size()>0) {
|
if(comparisonEntities !=null && comparisonEntities.size()>0) {
|
||||||
map=spliceMainMap(comparisonEntities,jsonObjectMain,map,comparisonEntity,comparisonDetailsEntity);
|
map=spliceMainMap(comparisonEntities,jsonObjectMain,map,comparisonEntity,comparisonDetailsEntity);
|
||||||
map.put("create_user_id", "c796fd9ba4c9f5ff3cc2fa41a040e443");
|
map.put("create_user_id", "c796fd9ba4c9f5ff3cc2fa41a040e443");
|
||||||
|
@ -330,21 +373,24 @@ public class ComparisonServiceImpl extends BaseService<ComparisonEntity, String>
|
||||||
jsonObjectList.put(comparisonEntity.getDbName(),map);
|
jsonObjectList.put(comparisonEntity.getDbName(),map);
|
||||||
if (integer>0) {
|
if (integer>0) {
|
||||||
//保存子表数据
|
//保存子表数据
|
||||||
if (jsonArray != null && jsonArray.size() > 0) {
|
if (arrayList != null && arrayList.size() > 0) {
|
||||||
mapDetails=spliceDetailMap(comparisonEntities,mapDetails,jsonArray);
|
mapDetails=spliceDetailMap(comparisonEntities,mapDetails,arrayList);
|
||||||
for (Map<String, Object> mapDetail : mapDetails) {
|
for (List<Map<String, Object>> mapDetail : mapDetails) {
|
||||||
mapDetail.put("create_user_id", "c796fd9ba4c9f5ff3cc2fa41a040e443");
|
for (Map<String, Object> stringObjectMap : mapDetail) {
|
||||||
mapDetail.put("modify_user_id", "c796fd9ba4c9f5ff3cc2fa41a040e443");
|
stringObjectMap.put("create_user_id", "c796fd9ba4c9f5ff3cc2fa41a040e443");
|
||||||
mapDetail.put("org_id", "0");
|
stringObjectMap.put("modify_user_id", "c796fd9ba4c9f5ff3cc2fa41a040e443");
|
||||||
mapDetail.put("modify_time", new Date());
|
stringObjectMap.put("org_id", "0");
|
||||||
mapDetail.put("sts", "Y");
|
stringObjectMap.put("modify_time", new Date());
|
||||||
mapDetail.put("data_status","F");//数据状态
|
stringObjectMap.put("sts", "Y");
|
||||||
//comparisonDetailsEntity.setFormmainId(jsonObjectMain.getString("id"));
|
stringObjectMap.put("data_status","F");//数据状态
|
||||||
comparisonDetailsEntity.setId(String.valueOf(mapDetail.get("id")));
|
comparisonDetailsEntity.setId(String.valueOf(stringObjectMap.get("id")));
|
||||||
comparisonDetailsEntity.setMapDetails(mapDetail);
|
comparisonDetailsEntity.setMapDetails(stringObjectMap);
|
||||||
comparisonDetailsDao.updateComparisonDetailsByType(comparisonDetailsEntity);
|
comparisonDetailsEntity.setDbName(String.valueOf(stringObjectMap.get("table_name")));
|
||||||
//保存操作日志
|
stringObjectMap.remove("table_name");
|
||||||
// controlsLogDaoimpl.saveControlsLog(comparisonDetailsEntity.getId(),jsonObject.getString("appName"),jsonObject.getString("appCode"),jsonObject.toJSONString(),"接口更新",jsonObject.getString("optionName"),comparisonDetailsEntity.getDbName()+"_option_log");
|
comparisonDetailsDao.updateComparisonDetailsByType(comparisonDetailsEntity);
|
||||||
|
//保存操作日志
|
||||||
|
// controlsLogDaoimpl.saveControlsLog(comparisonDetailsEntity.getId(),jsonObject.getString("appName"),jsonObject.getString("appCode"),jsonObject.toJSONString(),"接口更新",jsonObject.getString("optionName"),comparisonDetailsEntity.getDbName()+"_option_log");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
jsonObjectList.put(comparisonDetailsEntity.getDbName(),mapDetails);
|
jsonObjectList.put(comparisonDetailsEntity.getDbName(),mapDetails);
|
||||||
}else{
|
}else{
|
||||||
|
@ -352,7 +398,7 @@ public class ComparisonServiceImpl extends BaseService<ComparisonEntity, String>
|
||||||
}
|
}
|
||||||
jsonObjects.add(jsonObjectList);
|
jsonObjects.add(jsonObjectList);
|
||||||
//保存操作日志
|
//保存操作日志
|
||||||
controlsLogDaoimpl.saveControlsLog(comparisonEntity.getId(),jsonObject.getString("appName"),jsonObject.getString("appCode"),jsonObject.toJSONString(),"接口更新",jsonObject.getString("optionName"),comparisonEntity.getDbName()+"_option_log");
|
// controlsLogDaoimpl.saveControlsLog(comparisonEntity.getId(),jsonObject.getString("appName"),jsonObject.getString("appCode"),jsonObject.toJSONString(),"接口更新",jsonObject.getString("optionName"),comparisonEntity.getDbName()+"_option_log");
|
||||||
return BaseResult.getSuccessMessageEntity("更新成功", jsonObjects);
|
return BaseResult.getSuccessMessageEntity("更新成功", jsonObjects);
|
||||||
}else{
|
}else{
|
||||||
return BaseResult.getFailureMessageEntity("更新失败");
|
return BaseResult.getFailureMessageEntity("更新失败");
|
||||||
|
@ -487,20 +533,27 @@ public class ComparisonServiceImpl extends BaseService<ComparisonEntity, String>
|
||||||
}
|
}
|
||||||
|
|
||||||
//得到明细表数据
|
//得到明细表数据
|
||||||
private List<Map<String, Object>> spliceDetailMap(List<ComparisonEntity> comparisonEntities,List<Map<String, Object>> mapDetails,JSONArray jsonArray){
|
private List<List<Map<String, Object>>> spliceDetailMap(List<ComparisonEntity> comparisonEntities,List<List<Map<String, Object>>> mapDetails,List<JSONArray> arrayList){
|
||||||
if (jsonArray != null && jsonArray.size() > 0) {
|
if (arrayList != null && arrayList.size() > 0) {
|
||||||
for (Object object : jsonArray) {
|
for (JSONArray jsonArray : arrayList) {
|
||||||
JSONObject jsonObjectDetails = (JSONObject) JSON.toJSON(object);
|
List<Map<String,Object>> list=new ArrayList<>();
|
||||||
JSONObject jsonObject=new JSONObject();
|
for (Object object : jsonArray) {
|
||||||
//遍历主表下面的所有key,字段名
|
JSONObject jsonObject = new JSONObject();
|
||||||
for (String key : jsonObjectDetails.keySet()) {
|
JSONObject jsonObjectDetails = (JSONObject) JSON.toJSON(object);
|
||||||
for (ComparisonEntity entity : comparisonEntities) {
|
//遍历主表下面的所有key,字段名
|
||||||
if (entity.getDbType().equals("2") && entity.getEnName().equals(key)) {
|
for (String key : jsonObjectDetails.keySet()) {
|
||||||
jsonObject.put(key,jsonObjectDetails.getString(key));
|
for (ComparisonEntity entity : comparisonEntities) {
|
||||||
|
if (entity.getDbType().equals("2") && entity.getEnName().equals(key)) {
|
||||||
|
jsonObject.put(key, jsonObjectDetails.getString(key));
|
||||||
|
}
|
||||||
|
if(key.equals("table_name")){
|
||||||
|
jsonObject.put(key,jsonObjectDetails.getString(key));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
list.add(jsonObject);
|
||||||
}
|
}
|
||||||
mapDetails.add(jsonObject);
|
mapDetails.add(list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return mapDetails;
|
return mapDetails;
|
||||||
|
|
Loading…
Reference in New Issue