SyncZhongLiDataComponent.java 3.26 KB
package cn.com.glsx.stdinterface.modules.component;

import cn.com.glsx.stdinterface.enums.WorkOrderSourceEnum;
import cn.com.glsx.stdinterface.modules.entity.WorkOrder;
import cn.com.glsx.stdinterface.modules.model.SyncInstallDataRequest;
import cn.com.glsx.stdinterface.modules.util.zlgj.ZLUtils;
import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.glsx.plat.common.utils.HttpUtils;
import com.glsx.plat.context.utils.PropertiesUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * 同步仲利数据
 *
 * @author Yanglinlong
 * @date 2023/6/1 16:14
 */
@Slf4j
@Component
public class SyncZhongLiDataComponent {

    /**
     * 同步激活时间给仲利 异步发送不影响主流程
     *
     * @param workOrder 工单数据
     */
    @Async
    public void syncZhongLiInstallTime(WorkOrder workOrder) {
        log.info("syncZhongLiInstallTime start===" + workOrder.getPartnerOrderNo());

        if (Boolean.FALSE.equals(Boolean.valueOf(PropertiesUtils.getProperty("sync.zl.active.data.flag")))) {
            log.info("开关关闭,不推送给仲利" + workOrder.getPartnerOrderNo());
            return;
        }

        // 仲利国际的工单才会推送
        if (!WorkOrderSourceEnum.ZLGJ.getCode().equals(workOrder.getOrderSource())) {
            log.info("不是仲利国际的单===" + workOrder.getPartnerOrderNo());
            return;
        }

        SyncInstallDataRequest syncInstallDataRequest = new SyncInstallDataRequest();
        syncInstallDataRequest.setAppcode(workOrder.getPartnerOrderNo());
        syncInstallDataRequest.setInstallationEndTime(DateUtil.formatDateTime(workOrder.getFinishedTime()));
        log.info("syncInstallDataRequest:" + JSONUtil.toJsonStr(syncInstallDataRequest));

        // 2023/6/1 请求仲利的接口
        JSONObject headJson = new JSONObject();
        headJson.put(ZLUtils.ZL_DEVICEID_KEY, ZLUtils.ZL_DEVICEID_VAL);

        JSONObject bodyJson = new JSONObject();
        String syncInstallDataJsonStr = JSON.toJSONString(syncInstallDataRequest);
        long currentTime = System.currentTimeMillis();
        bodyJson.put("data", ZLUtils.parseDataByRSA(syncInstallDataJsonStr));
        bodyJson.put("time", currentTime);
        bodyJson.put("sign", ZLUtils.getSign(syncInstallDataJsonStr, currentTime));

        JSONObject paramBaseJson = new JSONObject();
        paramBaseJson.put(ZLUtils.ZL_CN_KEY, ZLUtils.ZL_CN_VAL);
        paramBaseJson.put(ZLUtils.ZL_SI_KEY, ZLUtils.ZL_SI_VAL);
        paramBaseJson.put(ZLUtils.ZL_TN_KEY, ZLUtils.ZL_TN_VAL);
        paramBaseJson.put("head", headJson);
        paramBaseJson.put("body", bodyJson);
        log.info("调用仲利上传激活时间接口 params:" + paramBaseJson.toJSONString());
        String saveGpsEndDateUrl = PropertiesUtils.getProperty("zlgj.active.saveGpsEndDate.url");
        String result = HttpUtils.post(saveGpsEndDateUrl, paramBaseJson.toJSONString());
        log.info("调用仲利上传激活时间接口 返回的结果为:" + result);
        log.info("syncZhongLiInstallTime end===" + workOrder.getPartnerOrderNo());
    }
}