根据表名称和表类型进行分组
This commit is contained in:
parent
c2e6863913
commit
c5dc5449d0
|
@ -28,6 +28,7 @@ import org.springframework.stereotype.Service;
|
||||||
import sun.java2d.pipe.AAShapePipe;
|
import sun.java2d.pipe.AAShapePipe;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Service(value = "comparisonServiceImpl")
|
@Service(value = "comparisonServiceImpl")
|
||||||
public class ComparisonServiceImpl extends BaseService<ComparisonEntity, String> implements IComparisonService {
|
public class ComparisonServiceImpl extends BaseService<ComparisonEntity, String> implements IComparisonService {
|
||||||
|
@ -50,7 +51,6 @@ public class ComparisonServiceImpl extends BaseService<ComparisonEntity, String>
|
||||||
}
|
}
|
||||||
|
|
||||||
//分页查询通用数据数据
|
//分页查询通用数据数据
|
||||||
@DS("master")
|
|
||||||
@Override
|
@Override
|
||||||
public JsonResultEntity queryEntityPage(JSONObject json) {
|
public JsonResultEntity queryEntityPage(JSONObject json) {
|
||||||
JSONObject jsonObject = json.getJSONObject("jsonStr");
|
JSONObject jsonObject = json.getJSONObject("jsonStr");
|
||||||
|
@ -122,7 +122,6 @@ public class ComparisonServiceImpl extends BaseService<ComparisonEntity, String>
|
||||||
}
|
}
|
||||||
|
|
||||||
//新增通用数据数据
|
//新增通用数据数据
|
||||||
@DS("master")
|
|
||||||
@Override
|
@Override
|
||||||
public JsonResultEntity saveEntity(JSONObject json) {
|
public JsonResultEntity saveEntity(JSONObject json) {
|
||||||
JSONObject jsonObject = json.getJSONObject("jsonStr");
|
JSONObject jsonObject = json.getJSONObject("jsonStr");
|
||||||
|
@ -148,108 +147,124 @@ public class ComparisonServiceImpl extends BaseService<ComparisonEntity, String>
|
||||||
logger.info("根据主数据编码查询信息错误:{}",e.getMessage());
|
logger.info("根据主数据编码查询信息错误:{}",e.getMessage());
|
||||||
return BaseResult.getFailureMessageEntity("保存失败");
|
return BaseResult.getFailureMessageEntity("保存失败");
|
||||||
}
|
}
|
||||||
String main = jsonObject.getString("main");//获取主表数据
|
JSONObject jsonObjectMain=new JSONObject();
|
||||||
JSONArray jsonArray = jsonObject.getJSONArray("details");//获取子表数据
|
JSONArray jsonArray=new JSONArray();
|
||||||
JSONObject jsonObjectMain = JSONObject.parseObject(main);
|
//根据dbtype和dbname分组,拿到表名称和表类型
|
||||||
if(jsonObjectMain != null ) {
|
Map<String, Map<String, List<ComparisonEntity>>> collect = comparisonEntities.stream().collect(Collectors.groupingBy(ComparisonEntity::getDbName, Collectors.groupingBy(ComparisonEntity::getDbType)));
|
||||||
Map<String, Object> map = new HashMap<>();//将主表数据存到map中
|
List<Map.Entry<String, String>> keyPairs = collect.entrySet().stream()
|
||||||
List<Map<String, Object>> mapDetails = new ArrayList<>();//将子表数据存到map中
|
.flatMap(e1 -> e1.getValue().keySet().stream()
|
||||||
if (comparisonEntities != null && comparisonEntities.size() > 0) {
|
.map(dbname -> new AbstractMap.SimpleEntry<>(e1.getKey(), dbname)))
|
||||||
map = spliceMainMap(comparisonEntities, jsonObjectMain, map, comparisonEntity,comparisonDetailsEntity);
|
.collect(Collectors.toList());
|
||||||
String uuid = null;
|
for (Map.Entry<String, String> keyPair : keyPairs) {
|
||||||
if (jsonObjectMain.getString("id") == null) {
|
if(keyPair.getValue().equals("1")){
|
||||||
uuid = UUIDUtils.getUUID();
|
String main = jsonObject.getString(keyPair.getKey());
|
||||||
map.put("id", uuid);
|
if(main!=null){
|
||||||
} else {
|
jsonObjectMain = JSONObject.parseObject(main);
|
||||||
uuid = jsonObjectMain.getString("id");
|
}
|
||||||
map.put("id", jsonObjectMain.getString("id"));
|
}
|
||||||
}
|
if(keyPair.getValue().equals("2")){
|
||||||
map.put("create_user_id", "c796fd9ba4c9f5ff3cc2fa41a040e443");
|
jsonArray= jsonObject.getJSONArray(keyPair.getKey());
|
||||||
map.put("modify_user_id", "c796fd9ba4c9f5ff3cc2fa41a040e443");
|
}
|
||||||
map.put("org_id", "0");
|
}
|
||||||
map.put("create_time", new Date());
|
if(jsonObjectMain!=null && jsonObjectMain.size()>0) {
|
||||||
map.put("modify_time", new Date());
|
Map<String, Object> map = new HashMap<>();//将主表数据存到map中
|
||||||
map.put("sts", "Y");
|
List<Map<String, Object>> mapDetails = new ArrayList<>();//将子表数据存到map中
|
||||||
map.put("data_status", "Y");//新增状态
|
if (comparisonEntities != null && comparisonEntities.size() > 0) {
|
||||||
map.put("add_status", "0");//新增状态
|
map = spliceMainMap(comparisonEntities, jsonObjectMain, map, comparisonEntity, comparisonDetailsEntity);
|
||||||
map.put("update_status", "1");//修改状态
|
String uuid = null;
|
||||||
map.put("delete_status", "1");//删除状态
|
if (jsonObjectMain.getString("id") == null) {
|
||||||
ComparisonEntity comparisonEntityRule = comparisonEntities.get(0);
|
uuid = UUIDUtils.getUUID();
|
||||||
//查询单据规则 只查询主表得,明细表不用
|
map.put("id", uuid);
|
||||||
try {
|
} else {
|
||||||
ComparisonEntity comparisonEntityRules = comparisonDao.queryComparisonById(comparisonEntityRule);
|
uuid = jsonObjectMain.getString("id");
|
||||||
String documentRule = comparisonEntityRules.getDocumentRule();//"KH-2024-05-30-1";
|
map.put("id", jsonObjectMain.getString("id"));
|
||||||
logger.info("通用数据保存接口中根据mId查询出来的单据规则为:{}", documentRule);
|
}
|
||||||
if (documentRule != null) {
|
map.put("create_user_id", "c796fd9ba4c9f5ff3cc2fa41a040e443");
|
||||||
//获取规则前缀 CK
|
map.put("modify_user_id", "c796fd9ba4c9f5ff3cc2fa41a040e443");
|
||||||
String rulePrefix = documentRule.substring(0, documentRule.indexOf("-"));
|
map.put("org_id", "0");
|
||||||
//获取规则中间日期 yyyy-MM-dd
|
map.put("create_time", new Date());
|
||||||
String ruleDate = documentRule.substring(documentRule.indexOf("-") + 1, documentRule.lastIndexOf("-"));
|
map.put("modify_time", new Date());
|
||||||
String ruleMiddle = getRuleDate(ruleDate);
|
map.put("sts", "Y");
|
||||||
//获取规则后缀
|
map.put("data_status", "Y");//新增状态
|
||||||
String ruleSuffixLength = documentRule.substring(documentRule.lastIndexOf("-") + 1);
|
map.put("add_status", "0");//新增状态
|
||||||
int ruleSuffix = ruleSuffixLength.length();
|
map.put("update_status", "1");//修改状态
|
||||||
//生成单据规则
|
map.put("delete_status", "1");//删除状态
|
||||||
comparisonEntityRule.setRulePrefix(rulePrefix);
|
ComparisonEntity comparisonEntityRule = comparisonEntities.get(0);
|
||||||
comparisonEntityRule.setRuleMiddle(ruleMiddle);
|
//查询单据规则 只查询主表得,明细表不用
|
||||||
comparisonEntityRule.setRuleSuffix(ruleSuffix);
|
try {
|
||||||
try {
|
ComparisonEntity comparisonEntityRules = comparisonDao.queryComparisonById(comparisonEntityRule);
|
||||||
//新生成单据规则保存到数据库
|
String documentRule = comparisonEntityRules.getDocumentRule();//"KH-2024-05-30-1";
|
||||||
ComparisonEntity comparisonEntityRuleGz = comparisonDao.queryComparisonRule(comparisonEntityRule);
|
logger.info("通用数据保存接口中根据mId查询出来的单据规则为:{}", documentRule);
|
||||||
map.put("document_rule", comparisonEntityRuleGz.getDocumentRule());//单据规则
|
if (documentRule != null) {
|
||||||
map.put("document_rule_num", comparisonEntityRuleGz.getDocumentRuleNum());//单据规则流水号
|
//获取规则前缀 CK
|
||||||
comparisonEntityRule.setMap(map);
|
String rulePrefix = documentRule.substring(0, documentRule.indexOf("-"));
|
||||||
} catch (Exception e) {
|
//获取规则中间日期 yyyy-MM-dd
|
||||||
logger.info("保存通用数据时候生成单据规则错误:{}", e.getMessage());
|
String ruleDate = documentRule.substring(documentRule.indexOf("-") + 1, documentRule.lastIndexOf("-"));
|
||||||
return BaseResult.getFailureMessageEntity("保存失败");
|
String ruleMiddle = getRuleDate(ruleDate);
|
||||||
}
|
//获取规则后缀
|
||||||
}
|
String ruleSuffixLength = documentRule.substring(documentRule.lastIndexOf("-") + 1);
|
||||||
} catch (Exception e) {
|
int ruleSuffix = ruleSuffixLength.length();
|
||||||
logger.info("通用数据保存接口中查询单据规则错误:{}", e.getMessage());
|
//生成单据规则
|
||||||
return BaseResult.getFailureMessageEntity("保存失败");
|
comparisonEntityRule.setRulePrefix(rulePrefix);
|
||||||
}
|
comparisonEntityRule.setRuleMiddle(ruleMiddle);
|
||||||
try {
|
comparisonEntityRule.setRuleSuffix(ruleSuffix);
|
||||||
List<JSONObject> list=new ArrayList<>();
|
try {
|
||||||
JSONObject jsonObjectList=new JSONObject();
|
//新生成单据规则保存到数据库
|
||||||
//保存主表数据
|
ComparisonEntity comparisonEntityRuleGz = comparisonDao.queryComparisonRule(comparisonEntityRule);
|
||||||
ComparisonEntity comparisonEntityOne = comparisonDao.saveComparison(comparisonEntityRule);
|
map.put("document_rule", comparisonEntityRuleGz.getDocumentRule());//单据规则
|
||||||
jsonObjectList.put(comparisonEntityOne.getDbName(),map);
|
map.put("document_rule_num", comparisonEntityRuleGz.getDocumentRuleNum());//单据规则流水号
|
||||||
//保存子表数据
|
comparisonEntityRule.setMap(map);
|
||||||
if (jsonArray != null && jsonArray.size() > 0) {
|
} catch (Exception e) {
|
||||||
mapDetails = spliceDetailMap(comparisonEntities, mapDetails, jsonArray);
|
logger.info("保存通用数据时候生成单据规则错误:{}", e.getMessage());
|
||||||
if(mapDetails.size()>0 && mapDetails!=null){
|
return BaseResult.getFailureMessageEntity("保存失败");
|
||||||
for (Map<String, Object> mapDetail : mapDetails) {
|
}
|
||||||
String uuidDetail = UUIDUtils.getUUID();
|
}
|
||||||
mapDetail.put("id", uuidDetail);
|
} catch (Exception e) {
|
||||||
mapDetail.put("formmain_id", uuid);
|
logger.info("通用数据保存接口中查询单据规则错误:{}", e.getMessage());
|
||||||
mapDetail.put("create_user_id", "c796fd9ba4c9f5ff3cc2fa41a040e443");
|
return BaseResult.getFailureMessageEntity("保存失败");
|
||||||
mapDetail.put("modify_user_id", "c796fd9ba4c9f5ff3cc2fa41a040e443");
|
}
|
||||||
mapDetail.put("org_id", "0");
|
try {
|
||||||
mapDetail.put("create_time", new Date());
|
List<JSONObject> list = new ArrayList<>();
|
||||||
mapDetail.put("modify_time", new Date());
|
JSONObject jsonObjectList = new JSONObject();
|
||||||
mapDetail.put("sts", "Y");
|
//保存主表数据
|
||||||
mapDetail.put("data_status","Y");//新增状态
|
//ComparisonEntity comparisonEntityOne = comparisonDao.saveComparison(comparisonEntityRule);
|
||||||
comparisonDetailsEntity.setMapDetails(mapDetail);
|
// jsonObjectList.put(comparisonEntityOne.getDbName(),map);
|
||||||
ComparisonDetailsEntity comparisonDetailsEntityOne = comparisonDetailsDao.saveComparisonDetails(comparisonDetailsEntity);
|
//保存子表数据
|
||||||
//comparisonEntityOne.setComparisonDetailsEntity(comparisonDetailsEntityOne);
|
if (jsonArray != null && jsonArray.size() > 0) {
|
||||||
//保存操作日志
|
mapDetails = spliceDetailMap(comparisonEntities, mapDetails, jsonArray);
|
||||||
//controlsLogDaoimpl.saveControlsLog(uuidDetail,jsonObject.getString("appName"),jsonObject.getString("appCode"),jsonObject.toJSONString(),"接口新增",jsonObject.getString("optionName"),comparisonDetailsEntity.getDbName()+"_option_log");
|
if (mapDetails.size() > 0 && mapDetails != null) {
|
||||||
}
|
for (Map<String, Object> mapDetail : mapDetails) {
|
||||||
jsonObjectList.put(comparisonDetailsEntity.getDbName(),mapDetails);
|
String uuidDetail = UUIDUtils.getUUID();
|
||||||
}
|
mapDetail.put("id", uuidDetail);
|
||||||
}else{
|
mapDetail.put("formmain_id", uuid);
|
||||||
jsonObjectList.put(comparisonDetailsEntity.getDbName(),new ArrayList<>());
|
mapDetail.put("create_user_id", "c796fd9ba4c9f5ff3cc2fa41a040e443");
|
||||||
}
|
mapDetail.put("modify_user_id", "c796fd9ba4c9f5ff3cc2fa41a040e443");
|
||||||
list.add(jsonObjectList);
|
mapDetail.put("org_id", "0");
|
||||||
//保存操作日志
|
mapDetail.put("create_time", new Date());
|
||||||
controlsLogDaoimpl.saveControlsLog(uuid,jsonObject.getString("appName"),jsonObject.getString("appCode"),jsonObject.toJSONString(),"接口新增",jsonObject.getString("optionName"),comparisonEntityRule.getDbName()+"_option_log");
|
mapDetail.put("modify_time", new Date());
|
||||||
return BaseResult.getSuccessMessageEntity("保存成功", list);
|
mapDetail.put("sts", "Y");
|
||||||
} catch (Exception e) {
|
mapDetail.put("data_status", "Y");//新增状态
|
||||||
logger.info("保存通用数据时候错误:{}", e.getMessage());
|
comparisonDetailsEntity.setMapDetails(mapDetail);
|
||||||
return BaseResult.getFailureMessageEntity("保存失败");
|
//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);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
jsonObjectList.put(comparisonDetailsEntity.getDbName(), new ArrayList<>());
|
||||||
|
}
|
||||||
|
list.add(jsonObjectList);
|
||||||
|
//保存操作日志
|
||||||
|
// controlsLogDaoimpl.saveControlsLog(uuid,jsonObject.getString("appName"),jsonObject.getString("appCode"),jsonObject.toJSONString(),"接口新增",jsonObject.getString("optionName"),comparisonEntityRule.getDbName()+"_option_log");
|
||||||
|
return BaseResult.getSuccessMessageEntity("保存成功", list);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.info("保存通用数据时候错误:{}", e.getMessage());
|
||||||
|
return BaseResult.getFailureMessageEntity("保存失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return BaseResult.getFailureMessageEntity("查询失败","请检查传递参数");
|
return BaseResult.getFailureMessageEntity("查询失败","请检查传递参数");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue