hejianhao
2026-08-18 70c320ed7109672c8bb7262b7773b8fa849754d9
feat0806: 封装创建门店的公共方法
1个文件已添加
1个文件已修改
72 ■■■■■ 已修改文件
tcm-training-admin-backend/src/main/java/com/tcm/training/admin/member/dto/UserBatchClinicUpdateRequest.java 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
tcm-training-admin-backend/src/main/java/com/tcm/training/admin/utils/VzanHttpUtil.java 55 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
tcm-training-admin-backend/src/main/java/com/tcm/training/admin/member/dto/UserBatchClinicUpdateRequest.java
New file
@@ -0,0 +1,17 @@
package com.tcm.training.admin.member.dto;
import lombok.Getter;
import lombok.Setter;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;
@Getter
@Setter
public class UserBatchClinicUpdateRequest {
    @NotEmpty(message = "请选择用户")
    private List<Long> userIds;
    @NotNull(message = "请选择诊所")
    private Long clinicId;
}
tcm-training-admin-backend/src/main/java/com/tcm/training/admin/utils/VzanHttpUtil.java
@@ -171,52 +171,79 @@
     * @return 微赞返回的代理业务数据
     */
    public JsonNode createAgent(String agentMobile, String agentName, Integer levelCode,
                                String parentMobile, String storeName) {
        String token = getToken();
                               String parentMobile, String storeName) {
        Map<String, Object> body = new LinkedHashMap<String, Object>();
        body.put("agent_mobile", requireText(agentMobile, "代理手机号不能为空"));
        body.put("agent_name", requireText(agentName, "代理名称不能为空"));
        if (levelCode == null) {
            throw new IllegalArgumentException("代理等级不能为空");
        if (levelCode == null || levelCode < 1 || levelCode > 3) {
            throw new IllegalArgumentException("代理等级必须是1、2或3");
        }
        body.put("level_code", levelCode);
        putIfHasText(body, "parent_mobile", parentMobile);
        putIfHasText(body, "store_name", storeName);
        return postForSuccessfulData(
                "https://openapi.njyqkj0ksyz.com/api/v2/agent/createAgent", body, "创建代理");
    }
    /**
     * 创建微赞门店。接口返回顶层code或data.result非成功时抛出运行时异常。
     *
     * @return 微赞返回的门店业务数据
     */
    public JsonNode createStore(String title, Integer provinceCode, Integer cityCode,
                               Integer areaCode, String address, String telephone) {
        Map<String, Object> body = new LinkedHashMap<String, Object>();
        body.put("title", requireText(title, "门店名称不能为空"));
        body.put("province_code", requireValue(provinceCode, "省编码不能为空"));
        body.put("city_code", requireValue(cityCode, "市编码不能为空"));
        body.put("area_code", requireValue(areaCode, "区县编码不能为空"));
        body.put("address", requireText(address, "详细地址不能为空"));
        body.put("telephone", requireText(telephone, "联系电话不能为空"));
        return postForSuccessfulData(
                "https://openapi.njyqkj0ksyz.com/api/v2/agent/createStore", body, "创建门店");
    }
    private JsonNode postForSuccessfulData(String url, Map<String, Object> body, String operationName) {
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        headers.setBearerAuth(token);
        headers.setBearerAuth(getToken());
        try {
            ResponseEntity<String> response = restOperations.postForEntity(
                    "https://openapi.njyqkj0ksyz.com/api/v2/agent/createAgent",
                    new HttpEntity<Map<String, Object>>(body, headers), String.class);
            return parseCreateAgentResponse(response.getBody());
                    url, new HttpEntity<Map<String, Object>>(body, headers), String.class);
            return parseBusinessResponse(response.getBody(), operationName);
        } catch (RestClientException ex) {
            throw new IllegalStateException("调用微赞创建代理接口失败", ex);
            throw new IllegalStateException("调用微赞" + operationName + "接口失败", ex);
        }
    }
    private JsonNode parseCreateAgentResponse(String responseBody) {
    private JsonNode parseBusinessResponse(String responseBody, String operationName) {
        if (!StringUtils.hasText(responseBody)) {
            throw new IllegalStateException("微赞创建代理接口返回为空");
            throw new IllegalStateException("微赞" + operationName + "接口返回为空");
        }
        try {
            JsonNode root = objectMapper.readTree(responseBody);
            if (!"0".equals(root.path("code").asText())) {
                throw new IllegalStateException("微赞创建代理失败: " + root.path("msg").asText("未知错误"));
                throw new IllegalStateException(
                        "微赞" + operationName + "失败: " + root.path("msg").asText("未知错误"));
            }
            JsonNode data = root.path("data");
            if (!data.isObject() || data.path("result").asInt(-1) != 0) {
                throw new IllegalStateException("微赞创建代理失败: 业务处理未成功");
                throw new IllegalStateException("微赞" + operationName + "失败: 业务处理未成功");
            }
            return data;
        } catch (IllegalStateException ex) {
            throw ex;
        } catch (Exception ex) {
            throw new IllegalStateException("解析微赞创建代理响应失败", ex);
            throw new IllegalStateException("解析微赞" + operationName + "响应失败", ex);
        }
    }
    private static <T> T requireValue(T value, String message) {
        if (value == null) {
            throw new IllegalArgumentException(message);
        }
        return value;
    }
    private static String requireText(String value, String message) {
        if (!StringUtils.hasText(value)) {
            throw new IllegalArgumentException(message);