wuxw
2024-04-17 7e654f0bdb591ef8e7a67a4e9fc20f65fa6dd571
service-order/src/main/java/com/java110/order/smo/impl/AsynNotifySubServiceImpl.java
@@ -3,22 +3,23 @@
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.java110.core.client.RestTemplate;
import com.java110.core.context.Environment;
import com.java110.core.context.SecureInvocation;
import com.java110.dto.businessDatabus.BusinessDatabusDto;
import com.java110.dto.businessTableHis.BusinessTableHisDto;
import com.java110.dto.system.BusinessDatabusDto;
import com.java110.dto.system.BusinessTableHisDto;
import com.java110.dto.order.OrderDto;
import com.java110.dto.order.OrderItemDto;
import com.java110.entity.order.Business;
import com.java110.dto.system.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.ListUtil;
import com.java110.utils.util.StringUtil;
import com.java110.vo.ResultVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.java110.core.log.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
@@ -40,6 +41,8 @@
    @Autowired
    private RestTemplate restTemplate;
    @Autowired
    private RestTemplate outRestTemplate;
    @Autowired
    private ICenterServiceDAO centerServiceDAOImpl;
@@ -48,6 +51,9 @@
    private IDataBusInnerServiceSMO dataBusInnerServiceSMOImpl;
    public static final String FALLBACK_URL = "http://SERVICE_NAME/businessApi/fallBack";
    public static final String BOOT_FALLBACK_URL = "http://127.0.0.1:8008/businessApi/fallBack";
    public static final String SERVICE_NAME = "SERVICE_NAME";
@@ -60,7 +66,12 @@
            JSONArray params = generateBusinessParam(orderItemDto, businessTableHisDto);
            httpEntity = new HttpEntity<String>(params.toJSONString(), header);
            //通过fallBack 的方式生成Business
            restTemplate.exchange(FALLBACK_URL.replace(SERVICE_NAME, orderItemDto.getServiceName()), HttpMethod.POST, httpEntity, String.class);
            if (Environment.isStartBootWay()) {
                outRestTemplate.exchange(BOOT_FALLBACK_URL, HttpMethod.POST, httpEntity, String.class);
            } else {
                restTemplate.exchange(FALLBACK_URL.replace(SERVICE_NAME, orderItemDto.getServiceName()), HttpMethod.POST, httpEntity, String.class);
            }
        } catch (Exception e) {
            logger.error("生成business失败", e);
@@ -71,8 +82,8 @@
    public void notifyDatabus(List<Map> orderItemMaps, OrderDto orderDto) {
        if (orderItemMaps == null || orderItemMaps.size() < 1) {
            return ;
        if (ListUtil.isNull(orderItemMaps)) {
            return;
        }
        //触发databug
        //查询 事务项
@@ -86,12 +97,12 @@
        String databusSwitch = MappingCache.getValue(DomainContant.COMMON_DOMAIN, DATABUS_SWITCH);
        if (!DATABUS_SWITCH_ON.equals(databusSwitch)) {
            return ;
            return;
        }
        List<BusinessDatabusDto> databusDtos = DatabusCache.getDatabuss();
        if (!hasTypeCd(databusDtos, businesses) || !SecureInvocation.secure(this.getClass())) {
            return ;
            return;
        }
        try {
@@ -178,11 +189,11 @@
            case "MOD":
                params = new JSONArray();
                JSONArray paramDels = generateBusinessDelInsertSql(orderItemDto, businessTableHisDto);
                for(int delIndex = 0 ; delIndex < paramDels.size(); delIndex ++){
                for (int delIndex = 0; delIndex < paramDels.size(); delIndex++) {
                    params.add(paramDels.getJSONObject(delIndex));
                }
                JSONArray paramAdds = generateBusinessInsertInsertSql(orderItemDto, businessTableHisDto);
                for(int addIndex = 0 ; addIndex < paramAdds.size(); addIndex ++){
                for (int addIndex = 0; addIndex < paramAdds.size(); addIndex++) {
                    params.add(paramAdds.getJSONObject(addIndex));
                }
                break;
@@ -204,14 +215,19 @@
    private JSONArray generateBusinessInsertInsertSql(OrderItemDto orderItemDto, BusinessTableHisDto businessTableHisDto) {
        JSONArray params = new JSONArray();
        JSONObject param = null;
        JSONObject updateParam = null;
        String sql = "";
        String updateSql = "";
        String logText = orderItemDto.getLogText();
        JSONObject logTextObj = JSONObject.parseObject(logText);
        JSONArray afterValues = logTextObj.getJSONArray("afterValue");
        for (int afterValueIndex = 0; afterValueIndex < afterValues.size(); afterValueIndex++) {
            sql = "insert into " + businessTableHisDto.getActionObjHis() + " ";
            updateSql = "update " + businessTableHisDto.getActionObj() + " set b_id='" + orderItemDto.getbId() + "' where 1=1 ";
            param = new JSONObject();
            updateParam = new JSONObject();
            JSONObject keyValue = afterValues.getJSONObject(afterValueIndex);
            if (keyValue.isEmpty()) {
                continue;
@@ -224,6 +240,8 @@
                }
                keySql += (key + ",");
                valueSql += (keyValue.getString(key) + ",");
                updateSql += (" and " + key + "=" + keyValue.getString(key));
            }
            keySql += "operate,b_id";
            valueSql += "'ADD','" + orderItemDto.getbId() + "'";
@@ -235,7 +253,9 @@
            }
            sql = sql + keySql + ") " + valueSql + ") ";
            param.put("fallBackSql", sql);
            updateParam.put("fallBackSql", updateSql);
            params.add(param);
            params.add(updateParam);
        }
        return params;