|
|
@@ -3,9 +3,19 @@ package com.java110.order.smo.impl;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.java110.core.client.RestTemplate;
|
|
|
+import com.java110.dto.businessDatabus.BusinessDatabusDto;
|
|
|
import com.java110.dto.businessTableHis.BusinessTableHisDto;
|
|
|
+import com.java110.dto.order.OrderDto;
|
|
|
import com.java110.dto.order.OrderItemDto;
|
|
|
+import com.java110.entity.order.Business;
|
|
|
+import com.java110.intf.job.IDataBusInnerServiceSMO;
|
|
|
+import com.java110.order.dao.ICenterServiceDAO;
|
|
|
import com.java110.order.smo.IAsynNotifySubService;
|
|
|
+import com.java110.utils.cache.DatabusCache;
|
|
|
+import com.java110.utils.cache.MappingCache;
|
|
|
+import com.java110.utils.constant.DomainContant;
|
|
|
+import com.java110.utils.util.StringUtil;
|
|
|
+import com.java110.vo.ResultVo;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -15,13 +25,27 @@ import org.springframework.http.HttpMethod;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
@Service
|
|
|
public class AsynNotifySubServiceImpl implements IAsynNotifySubService {
|
|
|
private static Logger logger = LoggerFactory.getLogger(AsynNotifySubServiceImpl.class);
|
|
|
-
|
|
|
+ //databus 业务类型
|
|
|
+ private static final String DATABUS_SWITCH = "DATABUS_SWITCH";
|
|
|
+ private static final String DATABUS_SWITCH_ON = "ON"; // 开关打开
|
|
|
@Autowired
|
|
|
private RestTemplate restTemplate;
|
|
|
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ICenterServiceDAO centerServiceDAOImpl;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IDataBusInnerServiceSMO dataBusInnerServiceSMOImpl;
|
|
|
+
|
|
|
public static final String FALLBACK_URL = "http://SERVICE_NAME/businessApi/fallBack";
|
|
|
|
|
|
public static final String SERVICE_NAME = "SERVICE_NAME";
|
|
|
@@ -42,6 +66,102 @@ public class AsynNotifySubServiceImpl implements IAsynNotifySubService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void notifyDatabus(List<Map> orderItemMaps, OrderDto orderDto) {
|
|
|
+
|
|
|
+
|
|
|
+ if (orderItemMaps == null || orderItemMaps.size() < 1) {
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ //触发databug
|
|
|
+ //查询 事务项
|
|
|
+ Map orderItem = new HashMap();
|
|
|
+ orderItem.put("oId", orderDto.getoId());
|
|
|
+ List<Map> businesses = centerServiceDAOImpl.getBusinessByOId(orderItem);
|
|
|
+ if (businesses == null || businesses.size() < 1) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ String databusSwitch = MappingCache.getValue(DomainContant.COMMON_DOMAIN, DATABUS_SWITCH);
|
|
|
+
|
|
|
+ if (!DATABUS_SWITCH_ON.equals(databusSwitch)) {
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ List<BusinessDatabusDto> databusDtos = DatabusCache.getDatabuss();
|
|
|
+
|
|
|
+ if (!hasTypeCd(databusDtos, businesses)) {
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ //同步databus
|
|
|
+ dataBusInnerServiceSMOImpl.exchange(freshBusesses(businesses, orderItemMaps));
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("传输databus 失败", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param businesses
|
|
|
+ * @param orderItemMaps
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<Business> freshBusesses(List<Map> businesses, List<Map> orderItemMaps) {
|
|
|
+ List<Business> businessObjs = new ArrayList<>();
|
|
|
+ Business businessObj = null;
|
|
|
+ /**
|
|
|
+ * select t.b_id bId,t.o_id oId,t.create_time createTime,t.action,t.action_obj actionObj,
|
|
|
+ * t.finish_time finishTime,t.remark,ul.service_name serviceName,ul.log_text logText
|
|
|
+ * from c_order_item t
|
|
|
+ * LEFT JOIN unitem_log ul on t.b_id = ul.b_id and t.o_id = ul.o_id and ul.status_cd = '0'
|
|
|
+ * where 1=1
|
|
|
+ *
|
|
|
+ * {"afterValue":[{"share_id":"'502021080429730002'","start_time":"'2021-08-01 00:00:35'","ad_type":"'10000'",
|
|
|
+ * "advert_type":"'3'","ads_id":"'782021080454590009'","ad_name":"'广告'","end_time":"'2022-02-03 02:10:35'",
|
|
|
+ * "state":"'2000'","seq":"'1'","url":"'img/20210804/01a629f9-a267-43b8-8d74-9c83b00ed2a7.png'"}],"preValue":[]}
|
|
|
+ */
|
|
|
+ JSONObject data = null;
|
|
|
+ for (Map business : businesses) {
|
|
|
+ for (Map orderItem : orderItemMaps) {
|
|
|
+ if (!business.get("b_id").equals(orderItem.get("bId"))) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ businessObj = new Business();
|
|
|
+ businessObj.setoId(business.get("o_id").toString());
|
|
|
+ businessObj.setbId(business.get("b_id").toString());
|
|
|
+ businessObj.setBusinessTypeCd(business.get("business_type_cd").toString());
|
|
|
+ JSONObject logText = JSONObject.parseObject(orderItem.get("logText").toString());
|
|
|
+ if ("ADD".equals(orderItem.get("action")) || "MOD".equals(orderItem.get("action"))) {
|
|
|
+ data = logText.getJSONArray("afterValue").getJSONObject(0);
|
|
|
+ StringUtil.lineToHump(data);
|
|
|
+ businessObj.setData(data);
|
|
|
+ }
|
|
|
+ if ("DEL".equals(orderItem.get("action"))) {
|
|
|
+ data = logText.getJSONArray("preValue").getJSONObject(0);
|
|
|
+ StringUtil.lineToHump(data);
|
|
|
+ businessObj.setData(data);
|
|
|
+ }
|
|
|
+ businessObjs.add(businessObj);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return businessObjs;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private boolean hasTypeCd(List<BusinessDatabusDto> databusDtos, List<Map> businesses) {
|
|
|
+
|
|
|
+ for (BusinessDatabusDto databusDto : databusDtos) {
|
|
|
+ for (Map business : businesses) {
|
|
|
+ if (databusDto.getBusinessTypeCd().equals(business.get("business_type_cd"))) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 生成回滚sql
|
|
|
*
|