|
|
@@ -1,149 +0,0 @@
|
|
|
-package com.uas.search.console.jms;
|
|
|
-
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-
|
|
|
-import com.alibaba.fastjson.JSONException;
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.uas.search.console.dao.BrandSimpleInfoDao;
|
|
|
-import com.uas.search.console.dao.ComponentSimpleInfoDao;
|
|
|
-import com.uas.search.console.dao.KindSimpleInfoDao;
|
|
|
-import com.uas.search.console.model.BrandSimpleInfo;
|
|
|
-import com.uas.search.console.model.ComponentSimpleInfo;
|
|
|
-import com.uas.search.console.model.KindSimpleInfo;
|
|
|
-import com.uas.search.console.model.ParsedQueueMessage;
|
|
|
-import com.uas.search.console.util.SearchConstants;
|
|
|
-
|
|
|
-/**
|
|
|
- * 对得到的队列消息进行解析的工具
|
|
|
- *
|
|
|
- * @author sunyj
|
|
|
- * @since 2016年7月7日 下午6:14:03
|
|
|
- */
|
|
|
-@Service
|
|
|
-public class QueueMessageParser {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private KindSimpleInfoDao kindDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private BrandSimpleInfoDao brandDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private ComponentSimpleInfoDao componentDao;
|
|
|
-
|
|
|
- /**
|
|
|
- * 对得到的json消息进行解析
|
|
|
- *
|
|
|
- * @param message
|
|
|
- * @return ParsedQueueMessage对象
|
|
|
- * @throws JSONException
|
|
|
- */
|
|
|
- // {"method":"value1","table":"value2","param1":"value3","param2":"value4"}
|
|
|
- public ParsedQueueMessage parse(String message) throws JSONException {
|
|
|
- if (StringUtils.isEmpty(message) || message.equals("{}")) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- ParsedQueueMessage parsedQueueMessage = new ParsedQueueMessage();
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(message);
|
|
|
-
|
|
|
- // 解析数据库表的更改类型
|
|
|
- String method = jsonObject.getString("method");
|
|
|
- if (method.equals("insert")) {
|
|
|
- parsedQueueMessage.setMethodType(ParsedQueueMessage.INSERT);
|
|
|
- }
|
|
|
-
|
|
|
- else if (method.equals("update")) {
|
|
|
- parsedQueueMessage.setMethodType(ParsedQueueMessage.UPDATE);
|
|
|
- }
|
|
|
-
|
|
|
- else if (method.equals("delete")) {
|
|
|
- parsedQueueMessage.setMethodType(ParsedQueueMessage.DELETE);
|
|
|
- } else {
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- // 解析哪个表有更改
|
|
|
- Object object = null;
|
|
|
- String table = jsonObject.getString("table");
|
|
|
- if (table.equals(SearchConstants.KIND_TABLE_NAME)) {
|
|
|
- object = parseKind(jsonObject);
|
|
|
- } else if (table.equals(SearchConstants.BRAND_TABLE_NAME)) {
|
|
|
- object = parseBrand(jsonObject);
|
|
|
- } else if (table.equals(SearchConstants.COMPONENT_TABLE_NAME)) {
|
|
|
- object = parseComponent(jsonObject);
|
|
|
- } else {
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- if (object == null) {
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- parsedQueueMessage.setObject(object);
|
|
|
- return parsedQueueMessage;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 对kind类目进行解析
|
|
|
- *
|
|
|
- * @param jsonObject
|
|
|
- * @return kind类目对象
|
|
|
- * @throws JSONException
|
|
|
- */
|
|
|
- // {"method":"value1","table":"product$kind","ki_id":5}
|
|
|
- private KindSimpleInfo parseKind(JSONObject jsonObject) throws JSONException {
|
|
|
- KindSimpleInfo kind = new KindSimpleInfo();
|
|
|
- Long kindid = jsonObject.getLong("ki_id");
|
|
|
- kind.setId(kindid);
|
|
|
-
|
|
|
- KindSimpleInfo temp = kindDao.findById(kindid);
|
|
|
- // 如果更改是删除的话,根据id获取到的对象为null
|
|
|
- if (temp != null) {
|
|
|
- kind = temp;
|
|
|
- }
|
|
|
- return kind;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 对brand品牌进行解析
|
|
|
- *
|
|
|
- * @param jsonObject
|
|
|
- * @return brand品牌对象
|
|
|
- * @throws JSONException
|
|
|
- */
|
|
|
- // {"method":"value1","table":"product$brand","br_id":60}
|
|
|
- private BrandSimpleInfo parseBrand(JSONObject jsonObject) throws JSONException {
|
|
|
- BrandSimpleInfo brand = new BrandSimpleInfo();
|
|
|
- Long brandid = jsonObject.getLong("br_id");
|
|
|
- brand.setId(brandid);
|
|
|
-
|
|
|
- BrandSimpleInfo temp = brandDao.findById(brandid);
|
|
|
- if (temp != null) {
|
|
|
- brand = temp;
|
|
|
- }
|
|
|
- return brand;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 对component器件进行解析
|
|
|
- *
|
|
|
- * @param jsonObject
|
|
|
- * @return component器件对象
|
|
|
- * @throws JSONException
|
|
|
- */
|
|
|
- // {"method":"value1","table":"product$component","cmp_id":2029}
|
|
|
- private ComponentSimpleInfo parseComponent(JSONObject jsonObject) throws JSONException {
|
|
|
- ComponentSimpleInfo component = new ComponentSimpleInfo();
|
|
|
- Long componentid = jsonObject.getLong("cmp_id");
|
|
|
- component.setId(componentid);
|
|
|
-
|
|
|
- ComponentSimpleInfo temp = componentDao.findById(componentid);
|
|
|
- if (temp != null) {
|
|
|
- component = temp;
|
|
|
- }
|
|
|
- return component;
|
|
|
- }
|
|
|
-
|
|
|
-}
|