doum
4 天以前 3c7399c25c0f35c8aa7cb6af1935e31d1a3f0102
server/visits/dmvisit_service/src/main/java/com/doumee/core/conditoner/ConditionerUtil.java
@@ -18,6 +18,8 @@
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.math.BigDecimal;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -283,11 +285,54 @@
    }
    public static ConditionerBaseResponse<Object> addGs(CompanyGsManageRequest req) {
        return postJson("/addGs", req, Object.class);
        if (req == null) {
            return null;
        }
        req.fillSessionDefaults();
        JSONObject body = new JSONObject(true);
        putSessionFields(body, req);
        body.put("is_pwr", req.getIs_pwr() != null ? req.getIs_pwr() : 1);
        body.put("li_dev", req.getLi_dev() != null ? req.getLi_dev() : Collections.emptyList());
        body.put("d_dev", req.getD_dev() != null ? req.getD_dev() : Collections.emptyMap());
        body.put("gs_name", req.getGs_name());
        body.put("is_rest_stop", req.getIs_rest_stop() != null ? req.getIs_rest_stop() : 0);
        body.put("gs_bz", StringUtils.defaultString(req.getGs_bz()));
        putStopMoney(body, req.getStop_money());
        return postJsonBody("/addGs", body, Object.class);
    }
    public static ConditionerBaseResponse<Object> changeGs(CompanyGsManageRequest req) {
        return postJson("/changeGs", req, Object.class);
        if (req == null || req.getId() == null) {
            return null;
        }
        req.fillSessionDefaults();
        JSONObject body = new JSONObject(true);
        putSessionFields(body, req);
        body.put("id", req.getId());
        body.put("is_pwr", req.getIs_pwr() != null ? req.getIs_pwr() : 1);
        body.put("is_rest_stop", req.getIs_rest_stop() != null ? req.getIs_rest_stop() : 0);
        body.put("gs_name", req.getGs_name());
        if (req.getLeft_money() != null) {
            body.put("left_money", req.getLeft_money());
        }
        body.put("is_stop", req.getIs_stop() != null ? req.getIs_stop() : 0);
        body.put("li_dev", req.getLi_dev() != null ? req.getLi_dev() : Collections.emptyList());
        body.put("d_dev", req.getD_dev() != null ? req.getD_dev() : Collections.emptyMap());
        body.put("gs_bz", StringUtils.defaultString(req.getGs_bz()));
        putStopMoney(body, req.getStop_money());
        return postJsonBody("/changeGs", body, Object.class);
    }
    private static void putStopMoney(JSONObject body, Object stopMoney) {
        if (stopMoney == null) {
            body.put("stop_money", "0");
            return;
        }
        if (stopMoney instanceof BigDecimal) {
            body.put("stop_money", ((BigDecimal) stopMoney).toPlainString());
        } else {
            body.put("stop_money", String.valueOf(stopMoney));
        }
    }
    public static ConditionerBaseResponse<Object> delGs(CompanyGsManageRequest req) {
@@ -299,11 +344,26 @@
    }
    public static ConditionerBaseResponse<Object> addMoney(AddMoneyRequest req) {
        return postJson("/addMoney", req, Object.class);
        if (req == null) {
            return null;
        }
        req.fillSessionDefaults();
        JSONObject body = new JSONObject(true);
        putSessionFields(body, req);
        body.put("id", req.getId());
        body.put("cz_money", req.getCz_money());
        return postJsonBody("/addMoney", body, Object.class);
    }
    public static ConditionerBaseResponse<Object> cleanMoney(CompanyGsManageRequest req) {
        return postJson("/cleanMoney", req, Object.class);
        if (req == null || req.getId() == null) {
            return null;
        }
        req.fillSessionDefaults();
        JSONObject body = new JSONObject(true);
        putSessionFields(body, req);
        body.put("id", req.getId());
        return postJsonBody("/cleanMoney", body, Object.class);
    }
    public static ConditionerBaseResponse<List<Object>> getCzLog(LogQueryRequest req) {
@@ -381,6 +441,23 @@
        }
    }
    private static <T> ConditionerBaseResponse<T> postJsonBody(String path, JSONObject body, Class<T> dataClass) {
        try {
            String raw = doPostRaw(path, body.toJSONString());
            return parseObjectResponse(raw, dataClass);
        } catch (Exception e) {
            log.error("conditioner POST {} failed", path, e);
            return null;
        }
    }
    private static void putSessionFields(JSONObject body, ConditionerSessionRequest req) {
        body.put("kt_token", req.getKt_token());
        body.put("kt_dwid", req.getKt_dwid());
        body.put("kt_unit", StringUtils.defaultIfBlank(req.getKt_unit(), ConditionerConstant.DEFAULT_KT_UNIT));
        body.put("kt_sonid", req.getKt_sonid());
    }
    private static String resolveUrl(String path) {
        String base = StringUtils.defaultIfBlank(ConditionerConstant.base_url, ConditionerConstant.DEFAULT_BASE_URL);
        if (base.endsWith("/")) {