|
|
@ -3,10 +3,12 @@ package cn.estsh.i3plus.core.apiservice.mq;
|
|
|
|
import cn.estsh.i3plus.core.api.iservice.busi.ISysPojoVersionDetailService;
|
|
|
|
import cn.estsh.i3plus.core.api.iservice.busi.ISysPojoVersionDetailService;
|
|
|
|
import cn.estsh.i3plus.core.api.iservice.busi.ISysPojoVersionService;
|
|
|
|
import cn.estsh.i3plus.core.api.iservice.busi.ISysPojoVersionService;
|
|
|
|
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
|
|
|
|
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.platform.common.tool.ExcelTool;
|
|
|
|
import cn.estsh.i3plus.platform.common.tool.JsonUtilTool;
|
|
|
|
import cn.estsh.i3plus.platform.common.tool.JsonUtilTool;
|
|
|
|
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
|
|
|
|
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
|
|
|
|
import cn.estsh.i3plus.pojo.base.codemaker.SnowflakeIdMaker;
|
|
|
|
import cn.estsh.i3plus.pojo.base.codemaker.SnowflakeIdMaker;
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.pojo.platform.bean.SysConfig;
|
|
|
|
import cn.estsh.i3plus.pojo.platform.bean.SysPojoVersion;
|
|
|
|
import cn.estsh.i3plus.pojo.platform.bean.SysPojoVersion;
|
|
|
|
import cn.estsh.i3plus.pojo.platform.bean.SysPojoVersionDetail;
|
|
|
|
import cn.estsh.i3plus.pojo.platform.bean.SysPojoVersionDetail;
|
|
|
|
import cn.estsh.i3plus.pojo.platform.bean.SysPojoVersionPlan;
|
|
|
|
import cn.estsh.i3plus.pojo.platform.bean.SysPojoVersionPlan;
|
|
|
@ -25,7 +27,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.HashMap;
|
|
|
@ -56,16 +57,17 @@ public class PojoVersionQueueReceiver {
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private SnowflakeIdMaker snowflakeIdMaker;
|
|
|
|
private SnowflakeIdMaker snowflakeIdMaker;
|
|
|
|
|
|
|
|
|
|
|
|
@Resource(name= CommonConstWords.IMPP_REDIS_RES)
|
|
|
|
@Resource(name = CommonConstWords.IMPP_REDIS_RES)
|
|
|
|
private ImppRedis redisRes;
|
|
|
|
private ImppRedis redisRes;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* QUEUE_SWEB_NOTICE 队列
|
|
|
|
* QUEUE_SWEB_NOTICE 队列
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return 队列
|
|
|
|
* @return 队列
|
|
|
|
* @throws Exception
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Bean
|
|
|
|
@Bean
|
|
|
|
public Queue getQueueSwebNoticeQueue(){
|
|
|
|
public Queue getQueueSwebNoticeQueue() {
|
|
|
|
return new Queue(QUEUE_IMPP_POJO_VERSION);
|
|
|
|
return new Queue(QUEUE_IMPP_POJO_VERSION);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -74,39 +76,39 @@ public class PojoVersionQueueReceiver {
|
|
|
|
boolean isNack = false;
|
|
|
|
boolean isNack = false;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
byte[] messageBody = message.getBody();
|
|
|
|
byte[] messageBody = message.getBody();
|
|
|
|
if(messageBody != null && messageBody.length > 0){
|
|
|
|
if (messageBody != null && messageBody.length > 0) {
|
|
|
|
String msg = new String(messageBody);
|
|
|
|
String msg = new String(messageBody);
|
|
|
|
if(StringUtils.isNotBlank(msg)){
|
|
|
|
if (StringUtils.isNotBlank(msg)) {
|
|
|
|
// 当前操作数据
|
|
|
|
// 当前操作数据
|
|
|
|
SysPojoVersion afterVersion = JSON.parseObject(msg, SysPojoVersion.class);
|
|
|
|
SysPojoVersion afterVersion = JSON.parseObject(msg, SysPojoVersion.class);
|
|
|
|
|
|
|
|
|
|
|
|
// 是否进行版本控制
|
|
|
|
// 是否进行版本控制
|
|
|
|
Object redisValue = redisRes.getObject(CommonConstWords.REDIS_PREFIX_POJO_VERSION + ":" + afterVersion.getSoftType() + ":" + afterVersion.getRefClass());
|
|
|
|
Object redisValue = redisRes.getObject(CommonConstWords.REDIS_PREFIX_POJO_VERSION + ":" + afterVersion.getSoftType() + ":" + afterVersion.getRefClass());
|
|
|
|
if(Objects.nonNull(redisValue)){
|
|
|
|
if (Objects.nonNull(redisValue)) {
|
|
|
|
SysPojoVersionPlan versionPlan = JSON.parseObject(redisValue.toString(), SysPojoVersionPlan.class);
|
|
|
|
SysPojoVersionPlan versionPlan = JSON.parseObject(redisValue.toString(), SysPojoVersionPlan.class);
|
|
|
|
Map<String,Object> afterMap = JsonUtilTool.decode(afterVersion.getBean(), Map.class);
|
|
|
|
Map<String, Object> afterMap = JsonUtilTool.decode(afterVersion.getBean(), Map.class);
|
|
|
|
SysPojoVersionDetail afterVersionDetail = null;
|
|
|
|
SysPojoVersionDetail afterVersionDetail = null;
|
|
|
|
|
|
|
|
Map<String, String> mapPropDesc = afterVersion.getPojoPropDesc();
|
|
|
|
|
|
|
|
|
|
|
|
// 已存在数据
|
|
|
|
// 已存在数据
|
|
|
|
SysPojoVersion beforeVersion = null;
|
|
|
|
SysPojoVersion beforeVersion = null;
|
|
|
|
SysPojoVersionDetail beforeVersionDetail = null;
|
|
|
|
SysPojoVersionDetail beforeVersionDetail = null;
|
|
|
|
Map<String,Object> beforeMap = new HashMap<>();
|
|
|
|
Map<String, Object> beforeMap = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
|
|
Integer versionNo; // 对象版本
|
|
|
|
Integer versionNo; // 对象版本
|
|
|
|
CommonEnumUtil.DAO_OPERATE_TYPE operateType = CommonEnumUtil.DAO_OPERATE_TYPE.INSERT; // 操作类型
|
|
|
|
CommonEnumUtil.DAO_OPERATE_TYPE operateType = CommonEnumUtil.DAO_OPERATE_TYPE.INSERT; // 操作类型
|
|
|
|
Map<String, MapDifference.ValueDifference<Object>> differing; // 版本对比
|
|
|
|
Map<String, MapDifference.ValueDifference<Object>> mapDiff; // 版本对比
|
|
|
|
String pojoCompare = null;
|
|
|
|
|
|
|
|
String userName = StringUtils.isNotBlank(afterVersion.getModifyUser()) ? afterVersion.getModifyUser() : afterVersion.getCreateUser();
|
|
|
|
String userName = StringUtils.isNotBlank(afterVersion.getModifyUser()) ? afterVersion.getModifyUser() : afterVersion.getCreateUser();
|
|
|
|
|
|
|
|
|
|
|
|
if(!"insert".equals(afterVersion.getVersionMethodName())){ // 不是新增数据的时候则需要查询历史记录
|
|
|
|
if (!"insert".equals(afterVersion.getVersionMethodName())) { // 不是新增数据的时候则需要查询历史记录
|
|
|
|
// 已存在数据封装
|
|
|
|
// 已存在数据封装
|
|
|
|
if(afterVersion != null){
|
|
|
|
if (afterVersion != null) {
|
|
|
|
afterVersion.setOrderByParam("createDatetime");
|
|
|
|
afterVersion.setOrderByParam("createDatetime");
|
|
|
|
afterVersion.setAscOrDesc(CommonEnumUtil.ASC_OR_DESC.DESC.getValue());
|
|
|
|
afterVersion.setAscOrDesc(CommonEnumUtil.ASC_OR_DESC.DESC.getValue());
|
|
|
|
beforeVersion = pojoVersionService.getPojoVersion(afterVersion);
|
|
|
|
beforeVersion = pojoVersionService.getPojoVersion(afterVersion);
|
|
|
|
if(Objects.nonNull(beforeVersion)){
|
|
|
|
if (Objects.nonNull(beforeVersion)) {
|
|
|
|
beforeVersionDetail = pojoVersionDetailService.get(beforeVersion.getPojoDetailId());
|
|
|
|
beforeVersionDetail = pojoVersionDetailService.get(beforeVersion.getPojoDetailId());
|
|
|
|
if(Objects.nonNull(beforeVersionDetail)){
|
|
|
|
if (Objects.nonNull(beforeVersionDetail)) {
|
|
|
|
beforeMap.putAll(JsonUtilTool.decode(beforeVersionDetail.getPojoAfter(), Map.class));
|
|
|
|
beforeMap.putAll(JsonUtilTool.decode(beforeVersionDetail.getPojoAfter(), Map.class));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -119,8 +121,7 @@ public class PojoVersionQueueReceiver {
|
|
|
|
afterMap.remove(key);
|
|
|
|
afterMap.remove(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mapDiff = Maps.difference(beforeMap, afterMap).entriesDiffering();
|
|
|
|
differing = Maps.difference(beforeMap, afterMap).entriesDiffering();
|
|
|
|
|
|
|
|
// // 忽略版本控制属性
|
|
|
|
// // 忽略版本控制属性
|
|
|
|
// if(differing != null ){
|
|
|
|
// if(differing != null ){
|
|
|
|
// for (String key : CommonConstWords.POJO_VERSION_ATTR_INGNORE) {
|
|
|
|
// for (String key : CommonConstWords.POJO_VERSION_ATTR_INGNORE) {
|
|
|
@ -130,7 +131,7 @@ public class PojoVersionQueueReceiver {
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// pojoCompare = differing.toString();
|
|
|
|
// pojoCompare = differing.toString();
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
pojoCompare = differing != null && differing.size() > 0 ? differing.toString() : null;
|
|
|
|
String pojoCompare = mapDiff == null ? null : mapDiff.toString();
|
|
|
|
|
|
|
|
|
|
|
|
versionNo = Objects.nonNull(beforeVersion) ? beforeVersion.getVersionNo() : 0;
|
|
|
|
versionNo = Objects.nonNull(beforeVersion) ? beforeVersion.getVersionNo() : 0;
|
|
|
|
afterVersion.setVersionNo(++versionNo);
|
|
|
|
afterVersion.setVersionNo(++versionNo);
|
|
|
@ -141,34 +142,121 @@ public class PojoVersionQueueReceiver {
|
|
|
|
afterVersionDetail = new SysPojoVersionDetail();
|
|
|
|
afterVersionDetail = new SysPojoVersionDetail();
|
|
|
|
afterVersionDetail.setId(snowflakeIdMaker.nextId());
|
|
|
|
afterVersionDetail.setId(snowflakeIdMaker.nextId());
|
|
|
|
afterVersionDetail.setPojoVersionId(afterVersion.getId());
|
|
|
|
afterVersionDetail.setPojoVersionId(afterVersion.getId());
|
|
|
|
|
|
|
|
|
|
|
|
afterVersionDetail.setPojoBefore(JSON.toJSONString(beforeMap));
|
|
|
|
afterVersionDetail.setPojoBefore(JSON.toJSONString(beforeMap));
|
|
|
|
afterVersionDetail.setPojoAfter(JSON.toJSONString(afterMap));
|
|
|
|
afterVersionDetail.setPojoAfter(JSON.toJSONString(afterMap));
|
|
|
|
afterVersionDetail.setPojoCompare(pojoCompare);
|
|
|
|
afterVersionDetail.setPojoCompare(pojoCompare);
|
|
|
|
ConvertBean.serviceModelInitialize(afterVersionDetail,userName);
|
|
|
|
|
|
|
|
|
|
|
|
afterVersionDetail.setPojoBeforeTxt(getMapToStr(beforeMap, mapPropDesc));
|
|
|
|
|
|
|
|
afterVersionDetail.setPojoAfterTxt(getMapToStr(afterMap, mapPropDesc));
|
|
|
|
|
|
|
|
afterVersionDetail.setPojoCompareTxt(getMapDiffToStr(mapDiff, mapPropDesc));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ConvertBean.serviceModelInitialize(afterVersionDetail, userName);
|
|
|
|
pojoVersionDetailService.insert(afterVersionDetail);
|
|
|
|
pojoVersionDetailService.insert(afterVersionDetail);
|
|
|
|
|
|
|
|
|
|
|
|
afterVersion.setOperateType(operateType.getValue());
|
|
|
|
afterVersion.setOperateType(operateType.getValue());
|
|
|
|
afterVersion.setVersionNo(versionNo);
|
|
|
|
afterVersion.setVersionNo(versionNo);
|
|
|
|
afterVersion.setPojoCompare(pojoCompare);
|
|
|
|
afterVersion.setPojoCompare(pojoCompare);
|
|
|
|
|
|
|
|
afterVersion.setPojoCompareTxt(getMapDiffToStr(mapDiff, mapPropDesc));
|
|
|
|
afterVersion.setPojoDetailId(afterVersionDetail.getId());
|
|
|
|
afterVersion.setPojoDetailId(afterVersionDetail.getId());
|
|
|
|
ConvertBean.serviceModelInitialize(afterVersion,userName);
|
|
|
|
ConvertBean.serviceModelInitialize(afterVersion, userName);
|
|
|
|
pojoVersionService.insert(afterVersion);
|
|
|
|
pojoVersionService.insert(afterVersion);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
}finally {
|
|
|
|
} finally {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if(isNack){
|
|
|
|
if (isNack) {
|
|
|
|
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
|
|
|
|
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
|
|
|
|
}else{
|
|
|
|
} else {
|
|
|
|
channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, false);
|
|
|
|
channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}catch (Exception e){
|
|
|
|
} catch (Exception e) {
|
|
|
|
LOGGER.error("Pojo Version MQ ACK Error Message :{}",e.getMessage());
|
|
|
|
LOGGER.error("Pojo Version MQ ACK Error Message :{}", e.getMessage());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Map数据转文本
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param mapData
|
|
|
|
|
|
|
|
* @param mapPropDesc
|
|
|
|
|
|
|
|
* @return
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private String getMapToStr(Map<String, Object> mapData, Map<String, String> mapPropDesc) {
|
|
|
|
|
|
|
|
if (mapData == null) {
|
|
|
|
|
|
|
|
mapData = new HashMap<>();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mapPropDesc == null) {
|
|
|
|
|
|
|
|
mapData = new HashMap<>();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
StringBuilder stringBuffer = new StringBuilder();
|
|
|
|
|
|
|
|
String key;
|
|
|
|
|
|
|
|
for (Map.Entry<String, Object> entry : mapData.entrySet()) {
|
|
|
|
|
|
|
|
key = mapPropDesc.get(entry.getKey());
|
|
|
|
|
|
|
|
if (key == null) {
|
|
|
|
|
|
|
|
key = entry.getKey();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stringBuffer.append(key).append(":").append(entry.getValue()).append(",");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return stringBuffer.toString();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* MapDifference数据转文本
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param mapData
|
|
|
|
|
|
|
|
* @param mapPropDesc
|
|
|
|
|
|
|
|
* @return
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private String getMapDiffToStr(Map<String, MapDifference.ValueDifference<Object>> mapData, Map<String, String> mapPropDesc) {
|
|
|
|
|
|
|
|
if (mapData == null) {
|
|
|
|
|
|
|
|
mapData = new HashMap<>();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mapPropDesc == null) {
|
|
|
|
|
|
|
|
mapData = new HashMap<>();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
StringBuilder stringBuffer = new StringBuilder();
|
|
|
|
|
|
|
|
String key;
|
|
|
|
|
|
|
|
MapDifference.ValueDifference<Object> valDiff;
|
|
|
|
|
|
|
|
for (Map.Entry<String, MapDifference.ValueDifference<Object>> entry : mapData.entrySet()) {
|
|
|
|
|
|
|
|
valDiff = entry.getValue();
|
|
|
|
|
|
|
|
if (valDiff == null) {
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
key = mapPropDesc.get(entry.getKey());
|
|
|
|
|
|
|
|
if (key == null) {
|
|
|
|
|
|
|
|
key = entry.getKey();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
stringBuffer.append("修改值 ").append(key)
|
|
|
|
|
|
|
|
.append(",旧值为 ").append(valDiff.leftValue())
|
|
|
|
|
|
|
|
.append(",新值为 ").append(valDiff.rightValue())
|
|
|
|
|
|
|
|
.append("。");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return stringBuffer.toString();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
|
|
|
Map<String, String> orginMap = new HashMap<>();
|
|
|
|
|
|
|
|
orginMap.put("name", "wyh");
|
|
|
|
|
|
|
|
orginMap.put("age", "18");
|
|
|
|
|
|
|
|
orginMap.put("sex", "male");
|
|
|
|
|
|
|
|
Map<String, String> newMap = new HashMap<>();
|
|
|
|
|
|
|
|
newMap.put("name", "hyw");
|
|
|
|
|
|
|
|
newMap.put("age", "81");
|
|
|
|
|
|
|
|
MapDifference mapDiff = Maps.difference(orginMap, newMap);
|
|
|
|
|
|
|
|
System.out.println(mapDiff.entriesDiffering());
|
|
|
|
|
|
|
|
System.out.println(mapDiff.entriesInCommon());
|
|
|
|
|
|
|
|
System.out.println(mapDiff.entriesOnlyOnLeft());
|
|
|
|
|
|
|
|
System.out.println(mapDiff.entriesOnlyOnRight());
|
|
|
|
|
|
|
|
System.out.println(mapDiff.areEqual());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
System.out.println(ExcelTool.getColName(SysConfig.class));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|