|
@@ -65,19 +65,19 @@ public class QueueMessageParser {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 解析哪个表有更改
|
|
// 解析哪个表有更改
|
|
|
- Object object = null;
|
|
|
|
|
|
|
+ Object[] objects = null;
|
|
|
String table = jsonObject.getString("table");
|
|
String table = jsonObject.getString("table");
|
|
|
if (table.equals(SearchConstants.KIND_TABLE_NAME)) {
|
|
if (table.equals(SearchConstants.KIND_TABLE_NAME)) {
|
|
|
- object = parseKind(jsonObject);
|
|
|
|
|
|
|
+ objects = parseKind(jsonObject);
|
|
|
} else if (table.equals(SearchConstants.BRAND_TABLE_NAME)) {
|
|
} else if (table.equals(SearchConstants.BRAND_TABLE_NAME)) {
|
|
|
- object = parseBrand(jsonObject);
|
|
|
|
|
|
|
+ objects = parseBrand(jsonObject);
|
|
|
} else if (table.equals(SearchConstants.COMPONENT_TABLE_NAME)) {
|
|
} else if (table.equals(SearchConstants.COMPONENT_TABLE_NAME)) {
|
|
|
- object = parseComponent(jsonObject);
|
|
|
|
|
|
|
+ objects = parseComponent(jsonObject);
|
|
|
} else {
|
|
} else {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- parsedQueueMessage.setObject(object);
|
|
|
|
|
|
|
+ parsedQueueMessage.setObjects(objects);
|
|
|
return parsedQueueMessage;
|
|
return parsedQueueMessage;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -85,70 +85,86 @@ public class QueueMessageParser {
|
|
|
* 对kind类目进行解析
|
|
* 对kind类目进行解析
|
|
|
*
|
|
*
|
|
|
* @param jsonObject
|
|
* @param jsonObject
|
|
|
- * @return kind类目对象
|
|
|
|
|
|
|
+ * @return kind类目对象数组
|
|
|
* @throws JSONException
|
|
* @throws JSONException
|
|
|
*/
|
|
*/
|
|
|
- // {"method":"value1","table":"product$kind","ki_id":5}
|
|
|
|
|
- private KindSimpleInfo parseKind(JSONObject jsonObject) throws JSONException {
|
|
|
|
|
- Long kindid = jsonObject.getLong("ki_id");
|
|
|
|
|
- KindSimpleInfo kind = kindDao.findById(kindid);
|
|
|
|
|
- // 对删除操作的事务回退进行处理
|
|
|
|
|
- // (新增操作回退的话,返回的是null,并不影响索引;
|
|
|
|
|
- // 更新回退的话,数据与先前一样,这时更新索引,索引数据并不变)
|
|
|
|
|
- if (jsonObject.getString("method").equals("delete")) {
|
|
|
|
|
- // 数据库中该类目仍存在,认为事务回退,不删除索引
|
|
|
|
|
- if (kind != null) {
|
|
|
|
|
- return null;
|
|
|
|
|
- } else {
|
|
|
|
|
- kind = new KindSimpleInfo();
|
|
|
|
|
- kind.setId(kindid);
|
|
|
|
|
|
|
+ // {"method":"insert","table":"product$kind","ids":[2400,1299]}
|
|
|
|
|
+ private KindSimpleInfo[] parseKind(JSONObject jsonObject) throws JSONException {
|
|
|
|
|
+ // 获取本次更改的所有类目id
|
|
|
|
|
+ Object[] ids = jsonObject.getJSONArray("ids").toArray();
|
|
|
|
|
+ KindSimpleInfo[] kinds = new KindSimpleInfo[ids.length];
|
|
|
|
|
+ for (int i = 0; i < ids.length; i++) {
|
|
|
|
|
+ Long kindid = Long.parseLong(ids[i].toString());
|
|
|
|
|
+ KindSimpleInfo kind = kindDao.findById(kindid);
|
|
|
|
|
+ // 对删除操作的事务回退进行处理
|
|
|
|
|
+ // (新增操作回退的话,返回的是null,并不影响索引;
|
|
|
|
|
+ // 更新回退的话,数据与先前一样,这时更新索引,索引数据并不变)
|
|
|
|
|
+ if (jsonObject.getString("method").equals("delete")) {
|
|
|
|
|
+ // 数据库中该类目仍存在,认为事务回退,不删除索引
|
|
|
|
|
+ if (kind != null) {
|
|
|
|
|
+ kind = null;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ kind = new KindSimpleInfo();
|
|
|
|
|
+ kind.setId(kindid);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+ kinds[i] = kind;
|
|
|
}
|
|
}
|
|
|
- return kind;
|
|
|
|
|
|
|
+ return kinds;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 对brand品牌进行解析
|
|
* 对brand品牌进行解析
|
|
|
*
|
|
*
|
|
|
* @param jsonObject
|
|
* @param jsonObject
|
|
|
- * @return brand品牌对象
|
|
|
|
|
|
|
+ * @return brand品牌对象数组
|
|
|
* @throws JSONException
|
|
* @throws JSONException
|
|
|
*/
|
|
*/
|
|
|
- // {"method":"value1","table":"product$brand","br_id":60}
|
|
|
|
|
- private BrandSimpleInfo parseBrand(JSONObject jsonObject) throws JSONException {
|
|
|
|
|
- Long brandid = jsonObject.getLong("br_id");
|
|
|
|
|
- BrandSimpleInfo brand = brandDao.findById(brandid);
|
|
|
|
|
- if (jsonObject.getString("method").equals("delete")) {
|
|
|
|
|
- if (brand != null) {
|
|
|
|
|
- return null;
|
|
|
|
|
- } else {
|
|
|
|
|
- brand = new BrandSimpleInfo();
|
|
|
|
|
- brand.setId(brandid);
|
|
|
|
|
|
|
+ // {"method":"insert","table":"product$brand","ids":[124]}
|
|
|
|
|
+ private BrandSimpleInfo[] parseBrand(JSONObject jsonObject) throws JSONException {
|
|
|
|
|
+ Object[] ids = jsonObject.getJSONArray("ids").toArray();
|
|
|
|
|
+ BrandSimpleInfo[] brands = new BrandSimpleInfo[ids.length];
|
|
|
|
|
+ for (int i = 0; i < ids.length; i++) {
|
|
|
|
|
+ Long brandid = Long.parseLong(ids[i].toString());
|
|
|
|
|
+ BrandSimpleInfo brand = brandDao.findById(brandid);
|
|
|
|
|
+ if (jsonObject.getString("method").equals("delete")) {
|
|
|
|
|
+ if (brand != null) {
|
|
|
|
|
+ brand = null;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ brand = new BrandSimpleInfo();
|
|
|
|
|
+ brand.setId(brandid);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+ brands[i] = brand;
|
|
|
}
|
|
}
|
|
|
- return brand;
|
|
|
|
|
|
|
+ return brands;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 对component器件进行解析
|
|
* 对component器件进行解析
|
|
|
*
|
|
*
|
|
|
* @param jsonObject
|
|
* @param jsonObject
|
|
|
- * @return component器件对象
|
|
|
|
|
|
|
+ * @return component器件对象数组
|
|
|
* @throws JSONException
|
|
* @throws JSONException
|
|
|
*/
|
|
*/
|
|
|
- // {"method":"value1","table":"product$component","cmp_id":2029}
|
|
|
|
|
- private ComponentSimpleInfo parseComponent(JSONObject jsonObject) throws JSONException {
|
|
|
|
|
- Long componentid = jsonObject.getLong("cmp_id");
|
|
|
|
|
- ComponentSimpleInfo component = componentDao.findById(componentid);
|
|
|
|
|
- if (jsonObject.getString("method").equals("delete")) {
|
|
|
|
|
- if (component != null) {
|
|
|
|
|
- return null;
|
|
|
|
|
- } else {
|
|
|
|
|
- component = new ComponentSimpleInfo();
|
|
|
|
|
- component.setId(componentid);
|
|
|
|
|
|
|
+ // {"method":"value1","table":"product$component","ids":[1024]}
|
|
|
|
|
+ private ComponentSimpleInfo[] parseComponent(JSONObject jsonObject) throws JSONException {
|
|
|
|
|
+ Object[] ids = jsonObject.getJSONArray("ids").toArray();
|
|
|
|
|
+ ComponentSimpleInfo[] components = new ComponentSimpleInfo[ids.length];
|
|
|
|
|
+ for (int i = 0; i < ids.length; i++) {
|
|
|
|
|
+ Long componentid = Long.parseLong(ids[i].toString());
|
|
|
|
|
+ ComponentSimpleInfo component = componentDao.findById(componentid);
|
|
|
|
|
+ if (jsonObject.getString("method").equals("delete")) {
|
|
|
|
|
+ if (component != null) {
|
|
|
|
|
+ component = null;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ component = new ComponentSimpleInfo();
|
|
|
|
|
+ component.setId(componentid);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+ components[i] = component;
|
|
|
}
|
|
}
|
|
|
- return component;
|
|
|
|
|
|
|
+ return components;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|