新增字段data_id为第三方主键id,用第三方主键来操作
This commit is contained in:
parent
0e7b05e788
commit
15b031bd36
|
@ -31,6 +31,16 @@ public class ComparisonDetailsEntity extends BaseEntity {
|
|||
private String filedType;//字段类型 1、BIGINT 2、DECIMAL 3、VARCHAR 4、DATETIME
|
||||
private String formmainId;//上级id
|
||||
|
||||
private String dataId;//第三方主键id
|
||||
|
||||
public String getDataId() {
|
||||
return dataId;
|
||||
}
|
||||
|
||||
public void setDataId(String dataId) {
|
||||
this.dataId = dataId;
|
||||
}
|
||||
|
||||
public String getFormmainId() {
|
||||
return formmainId;
|
||||
}
|
||||
|
|
|
@ -48,14 +48,14 @@
|
|||
${key} =#{value}
|
||||
</foreach>
|
||||
</set>
|
||||
where id=#{id} and sts='Y'
|
||||
where data_id=#{dataId} and sts='Y'
|
||||
</update>
|
||||
|
||||
<!-- 多条件逻辑删除 -->
|
||||
<update id="deleteComparisonDetails" parameterType = "java.util.Map" >
|
||||
update
|
||||
${dbName}
|
||||
set sts= 'N' ,modify_time = now(),modify_user_id = #{modify_user_id}, data_status= 'N',delete_status='0'
|
||||
set modify_time = now(),modify_user_id = #{modify_user_id}, data_status= 'N'
|
||||
<trim prefix="where" prefixOverrides="and">
|
||||
<!--<foreach collection="mapDetails.entrySet()" item="value" index="key">
|
||||
${key} =#{value}
|
||||
|
|
|
@ -44,6 +44,16 @@ public class ComparisonEntity extends BaseEntity {
|
|||
private String listType;//显示类型:列表
|
||||
private String viewType;//显示类型:显示
|
||||
|
||||
private String dataId;//第三方主键id
|
||||
|
||||
public String getDataId() {
|
||||
return dataId;
|
||||
}
|
||||
|
||||
public void setDataId(String dataId) {
|
||||
this.dataId = dataId;
|
||||
}
|
||||
|
||||
public String getAddType() {
|
||||
return addType;
|
||||
}
|
||||
|
|
|
@ -106,7 +106,7 @@
|
|||
${key} =#{value}
|
||||
</foreach>
|
||||
</set>
|
||||
where id=#{id} and sts='Y'
|
||||
where data_id=#{dataId} and sts='Y'
|
||||
</update>
|
||||
|
||||
|
||||
|
@ -119,7 +119,7 @@
|
|||
<foreach collection="map.entrySet()" item="value" index="key">
|
||||
and ${key} =#{value}
|
||||
</foreach>
|
||||
and id=#{id} and sts='Y'
|
||||
and data_id=#{dataId} and sts='Y'
|
||||
</trim>
|
||||
</update>
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ import com.hzya.frame.sysnew.comparison.dao.IComparisonDetailsDao;
|
|||
import com.hzya.frame.sysnew.comparison.entity.ComparisonDetailsEntity;
|
||||
import com.hzya.frame.sysnew.comparison.entity.ComparisonEntity;
|
||||
import com.hzya.frame.sysnew.comparison.service.IComparisonService;
|
||||
import com.hzya.frame.uuid.UUIDLong;
|
||||
import com.hzya.frame.uuid.UUIDUtils;
|
||||
import com.hzya.frame.web.entity.BaseResult;
|
||||
import com.hzya.frame.web.entity.JsonResultEntity;
|
||||
|
@ -101,7 +102,7 @@ public class ComparisonServiceImpl extends BaseService<ComparisonEntity, String>
|
|||
JSONObject jsonObjects=new JSONObject();
|
||||
jsonObjects.put(comparisonEntity.getDbName(),comparisonEntitiePage);
|
||||
if(comparisonDetailsEntity.getDbName()!=null){
|
||||
comparisonDetailsEntity.setFormmainId(String.valueOf(comparisonEntitiePage.get("id")));
|
||||
comparisonDetailsEntity.setFormmainId(String.valueOf(comparisonEntitiePage.get("data_id")));
|
||||
//查询明细表数据
|
||||
List<Map<String, Object>> maps = comparisonDetailsDao.queryComparisonDetailsPage(comparisonDetailsEntity);
|
||||
if(CollectionUtils.isNotEmpty(maps)){
|
||||
|
@ -165,8 +166,8 @@ public class ComparisonServiceImpl extends BaseService<ComparisonEntity, String>
|
|||
String main = jsonObject.getString(keyPair.getKey());
|
||||
if(main!=null){
|
||||
jsonObjectMain = JSONObject.parseObject(main);
|
||||
if(!checkStr(jsonObjectMain.getString("id"))){
|
||||
return BaseResult.getFailureMessageEntity("新增时候主表id不能为空");
|
||||
if(!checkStr(jsonObjectMain.getString("data_id"))){
|
||||
return BaseResult.getFailureMessageEntity("新增时候主表data_id不能为空");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -177,8 +178,8 @@ public class ComparisonServiceImpl extends BaseService<ComparisonEntity, String>
|
|||
for (int i = 0; i < jsonArray.size(); i++) {
|
||||
JSONObject jsonObjectDetails = jsonArray.getJSONObject(i);
|
||||
jsonObjectDetails.put("table_name", keyPair.getKey());
|
||||
if(!checkStr(jsonObjectDetails.getString("id"))){
|
||||
return BaseResult.getFailureMessageEntity("新增时候明细id不能为空");
|
||||
if(!checkStr(jsonObjectDetails.getString("data_id"))){
|
||||
return BaseResult.getFailureMessageEntity("新增时候明细data_id不能为空");
|
||||
}
|
||||
}
|
||||
arrayList.add(jsonArray);
|
||||
|
@ -190,6 +191,7 @@ public class ComparisonServiceImpl extends BaseService<ComparisonEntity, String>
|
|||
List<List<Map<String, Object>>> mapDetails = new ArrayList<>();//将子表数据存到map中
|
||||
if (comparisonEntities != null && comparisonEntities.size() > 0) {
|
||||
map = spliceMainMap(comparisonEntities, jsonObjectMain, map, comparisonEntity, comparisonDetailsEntity);
|
||||
map.put("id", UUIDLong.longUUID());
|
||||
map.put("create_user_id", "c796fd9ba4c9f5ff3cc2fa41a040e443");
|
||||
map.put("modify_user_id", "c796fd9ba4c9f5ff3cc2fa41a040e443");
|
||||
map.put("org_id", "0");
|
||||
|
@ -246,8 +248,8 @@ public class ComparisonServiceImpl extends BaseService<ComparisonEntity, String>
|
|||
if(mapDetails.size()>0 && mapDetails!=null ){
|
||||
for (List<Map<String, Object>> mapDetail : mapDetails) {
|
||||
for (Map<String, Object> stringObjectMap : mapDetail) {
|
||||
stringObjectMap.put("id", stringObjectMap.get("id"));
|
||||
stringObjectMap.put("formmain_id", jsonObjectMain.getString("id"));
|
||||
stringObjectMap.put("id", UUIDLong.longUUID());
|
||||
stringObjectMap.put("formmain_id", jsonObjectMain.getString("data_id"));
|
||||
stringObjectMap.put("create_user_id", "c796fd9ba4c9f5ff3cc2fa41a040e443");
|
||||
stringObjectMap.put("modify_user_id", "c796fd9ba4c9f5ff3cc2fa41a040e443");
|
||||
stringObjectMap.put("org_id", "0");
|
||||
|
@ -271,7 +273,7 @@ public class ComparisonServiceImpl extends BaseService<ComparisonEntity, String>
|
|||
}
|
||||
list.add(jsonObjectList);
|
||||
//保存操作日志
|
||||
controlsLogDaoimpl.saveControlsLog(jsonObjectMain.getString("id"),jsonObject.getString("appName"),jsonObject.getString("appCode"),jsonObject.toJSONString(),"接口新增",jsonObject.getString("optionName"),comparisonEntityRule.getDbName()+"_option_log");
|
||||
controlsLogDaoimpl.saveControlsLog(jsonObjectMain.getString("data_id"),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());
|
||||
|
@ -322,8 +324,8 @@ public class ComparisonServiceImpl extends BaseService<ComparisonEntity, String>
|
|||
String main = jsonObject.getString(keyPair.getKey());
|
||||
if(main!=null){
|
||||
jsonObjectMain = JSONObject.parseObject(main);
|
||||
if(!checkStr(jsonObjectMain.getString("id"))){
|
||||
return BaseResult.getFailureMessageEntity("更新时候主表id不能为空");
|
||||
if(!checkStr(jsonObjectMain.getString("data_id"))){
|
||||
return BaseResult.getFailureMessageEntity("更新时候主表data_id不能为空");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -332,8 +334,8 @@ public class ComparisonServiceImpl extends BaseService<ComparisonEntity, String>
|
|||
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不能为空");
|
||||
if(!checkStr(jsonObjectDetails.getString("data_id"))){
|
||||
return BaseResult.getFailureMessageEntity("更新明细表时候明细表data_id不能为空");
|
||||
}
|
||||
jsonObjectDetails.put("table_name", keyPair.getKey());
|
||||
}
|
||||
|
@ -353,7 +355,7 @@ public class ComparisonServiceImpl extends BaseService<ComparisonEntity, String>
|
|||
map.put("data_status","F");//数据状态
|
||||
map.put("update_status","0");//修改状态
|
||||
comparisonEntity.setMap(map);
|
||||
comparisonEntity.setId(jsonObjectMain.getString("id"));
|
||||
comparisonEntity.setDataId(jsonObjectMain.getString("data_id"));
|
||||
/*//生成单据规则
|
||||
comparisonEntity.setRulePrefix(jsonObject.getString("rulePrefix"));
|
||||
try {
|
||||
|
@ -367,7 +369,7 @@ public class ComparisonServiceImpl extends BaseService<ComparisonEntity, String>
|
|||
try {
|
||||
List<JSONObject> jsonObjects=new ArrayList<>();
|
||||
JSONObject jsonObjectList=new JSONObject();
|
||||
//保存主表数据
|
||||
//更新主表数据
|
||||
Integer integer = comparisonDao.updateComparisonByType(comparisonEntity);
|
||||
jsonObjectList.put(comparisonEntity.getDbName(),map);
|
||||
if (integer>0) {
|
||||
|
@ -382,7 +384,7 @@ public class ComparisonServiceImpl extends BaseService<ComparisonEntity, String>
|
|||
stringObjectMap.put("modify_time", new Date());
|
||||
stringObjectMap.put("sts", "Y");
|
||||
stringObjectMap.put("data_status","F");//数据状态
|
||||
comparisonDetailsEntity.setId(String.valueOf(stringObjectMap.get("id")));
|
||||
comparisonDetailsEntity.setDataId(String.valueOf(stringObjectMap.get("data_id")));
|
||||
comparisonDetailsEntity.setMapDetails(stringObjectMap);
|
||||
comparisonDetailsEntity.setDbName(String.valueOf(stringObjectMap.get("table_name")));
|
||||
stringObjectMap.remove("table_name");
|
||||
|
@ -425,10 +427,6 @@ public class ComparisonServiceImpl extends BaseService<ComparisonEntity, String>
|
|||
}
|
||||
ComparisonEntity comparisonEntity = jsonObject.toJavaObject(ComparisonEntity.class);
|
||||
ComparisonDetailsEntity comparisonDetailsEntity=new ComparisonDetailsEntity();
|
||||
JSONObject jsonObjectMain=jsonObject.getJSONObject("main");//获取主表数据
|
||||
if(!checkStr(jsonObjectMain.getString("id"))){
|
||||
return BaseResult.getFailureMessageEntity("删除时候主表id不能为空");
|
||||
}
|
||||
List<ComparisonEntity> comparisonEntities=new ArrayList<>();
|
||||
//根据主数据编码查询表名称,字段名称等信息 10001
|
||||
try {
|
||||
|
@ -440,6 +438,25 @@ public class ComparisonServiceImpl extends BaseService<ComparisonEntity, String>
|
|||
logger.info("根据主数据编码查询信息错误:{}",e.getMessage());
|
||||
return BaseResult.getFailureMessageEntity("删除失败");
|
||||
}
|
||||
JSONObject jsonObjectMain=new JSONObject();
|
||||
//根据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("data_id"))){
|
||||
return BaseResult.getFailureMessageEntity("更新时候主表data_id不能为空");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Map<String,Object> map=new HashMap<>();
|
||||
if(comparisonEntities !=null && comparisonEntities.size()>0) {
|
||||
for (ComparisonEntity entity : comparisonEntities) {
|
||||
|
@ -456,14 +473,14 @@ public class ComparisonServiceImpl extends BaseService<ComparisonEntity, String>
|
|||
}
|
||||
}
|
||||
}
|
||||
comparisonEntity.setId(jsonObjectMain.getString("id"));
|
||||
comparisonEntity.setDataId(jsonObjectMain.getString("data_id"));
|
||||
comparisonEntity.setModify_user_id("c796fd9ba4c9f5ff3cc2fa41a040e443");
|
||||
comparisonEntity.setMap(map);
|
||||
try {
|
||||
Integer integer = comparisonDao.deleteComparison(comparisonEntity);
|
||||
if(integer>0){
|
||||
if(comparisonDetailsEntity.getDbName()!=null){
|
||||
comparisonDetailsEntity.setFormmainId(jsonObjectMain.getString("id"));
|
||||
comparisonDetailsEntity.setFormmainId(jsonObjectMain.getString("data_id"));
|
||||
comparisonDetailsEntity.setModify_user_id("c796fd9ba4c9f5ff3cc2fa41a040e443");
|
||||
comparisonDetailsDao.deleteComparisonDetails(comparisonDetailsEntity);
|
||||
// controlsLogDaoimpl.saveControlsLog(comparisonDetailsEntity.getId(),jsonObject.getString("appName"),jsonObject.getString("appCode"),jsonObject.toJSONString(),"接口删除",jsonObject.getString("optionName"),comparisonEntity.getDbName()+"_option_log");
|
||||
|
@ -471,7 +488,7 @@ public class ComparisonServiceImpl extends BaseService<ComparisonEntity, String>
|
|||
controlsLogDaoimpl.saveControlsLog(comparisonEntity.getId(),jsonObject.getString("appName"),jsonObject.getString("appCode"),jsonObject.toJSONString(),"接口删除",jsonObject.getString("optionName"),comparisonEntity.getDbName()+"_option_log");
|
||||
return BaseResult.getSuccessMessageEntity("删除成功",integer);
|
||||
}else{
|
||||
return BaseResult.getFailureMessageEntity("删除失败","请查看id是否在表中存在");
|
||||
return BaseResult.getFailureMessageEntity("删除失败","请查看data_id是否在表中存在");
|
||||
}
|
||||
}catch (Exception e){
|
||||
logger.info("删除通用数据数据错误:{}",e.getMessage());
|
||||
|
|
Loading…
Reference in New Issue