fix0806: 创建门店时到微赞创建门店、1及代理,并默认绑定到18510939636这个2级代理上面
2个文件已修改
90 ■■■■■ 已修改文件
tcm-training-admin-backend/src/main/java/com/tcm/training/admin/app/register/service/AppRegisterService.java 31 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
tcm-training-admin-backend/src/main/java/com/tcm/training/admin/member/service/ClinicAppService.java 59 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
tcm-training-admin-backend/src/main/java/com/tcm/training/admin/app/register/service/AppRegisterService.java
@@ -194,19 +194,24 @@
        user.setClinicId(clinic.getId());
        userMapper.insert(user);
//        Integer provinceCode = parseRegionCode(clinic.getProvinceCode(), "省编码");
//        Integer cityCode = parseRegionCode(clinic.getCityCode(), "市编码");
//        Integer areaCode = parseRegionCode(clinic.getDistrictCode(), "区县编码");
//        log.info("调用微赞创建门店,入参 title={}, provinceCode={}, cityCode={}, areaCode={}, address={}, telephone={}",
//                clinic.getName(), provinceCode, cityCode, areaCode, clinic.getAddress(), clinic.getContactPhone());
//        try {
//            JsonNode vzanResponse = vzanHttpUtil.createStore(clinic.getName(), provinceCode, cityCode, areaCode, clinic.getAddress(), clinic.getContactPhone());
//            log.info("微赞创建门店成功,出参={}", vzanResponse);
//        } catch (RuntimeException ex) {
//            log.error("微赞创建门店失败,本地事务将回滚,入参 title={}, provinceCode={}, cityCode={}, areaCode={}, address={}, telephone={}",
//                    clinic.getName(), provinceCode, cityCode, areaCode, clinic.getAddress(), clinic.getContactPhone(), ex);
//            throw new IllegalStateException("微赞创建门店失败", ex);
//        }
        Integer provinceCode = parseRegionCode(clinic.getProvinceCode(), "省编码");
        Integer cityCode = parseRegionCode(clinic.getCityCode(), "市编码");
        Integer areaCode = parseRegionCode(clinic.getDistrictCode(), "区县编码");
        log.info("调用微赞创建门店,入参 title={}, provinceCode={}, cityCode={}, areaCode={}, address={}, telephone={}"
                , clinic.getName(), provinceCode, cityCode, areaCode, clinic.getAddress(), clinic.getContactPhone());
        try {
            JsonNode vzanResponse = vzanHttpUtil.createStore(clinic.getName(), provinceCode, cityCode, areaCode, clinic.getAddress(), clinic.getContactPhone());
            log.info("微赞创建门店成功,出参={}", vzanResponse);
            // 注册阶段暂未绑定区域代理,parentMobile 传空,由微赞按一级代理处理。
            log.info("调用微赞创建一级代理,入参 agentMobile={}, agentName={}, levelCode=1, storeName={}, parentMobile=null",
                    clinic.getContactPhone(), clinic.getName(), clinic.getName());
            JsonNode vzanAgentResponse = vzanHttpUtil.createAgent(
                    clinic.getContactPhone(), clinic.getName(), 1, "18510939636", clinic.getName());
            log.info("微赞创建一级代理成功,出参={}", vzanAgentResponse);
        } catch (RuntimeException ex) {
            log.error("微赞创建门店或一级代理失败,本地事务将回滚,clinicId={}", clinic.getId(), ex);
            throw new IllegalStateException("微赞门店或一级代理创建失败", ex);
        }
        clearDraft(request.getRegisterTicket());
        return createLoginResponse(user);
tcm-training-admin-backend/src/main/java/com/tcm/training/admin/member/service/ClinicAppService.java
@@ -4,7 +4,6 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.databind.JsonNode;
import com.tcm.training.admin.agent.entity.AgentRegion;
import com.tcm.training.admin.agent.entity.ProvincialAgent;
import com.tcm.training.admin.agent.excel.ClinicAgentImportRow;
@@ -29,7 +28,6 @@
import com.tcm.training.admin.member.vo.ClinicDetailVO;
import com.tcm.training.admin.member.vo.ClinicListItemVO;
import com.tcm.training.admin.member.vo.ClinicRegionOptionVO;
import com.tcm.training.admin.utils.VzanHttpUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.stereotype.Service;
@@ -54,7 +52,6 @@
    private final ProvincialAgentMapper provincialAgentMapper;
    private final UserMapper userMapper;
    private final SysRegionMapper sysRegionMapper;
    private final VzanHttpUtil vzanHttpUtil;
    private final DataSourceTransactionManager transactionManager;
    public ClinicAppService(ClinicQueryMapper clinicQueryMapper,
@@ -62,14 +59,12 @@
                           ProvincialAgentMapper provincialAgentMapper,
                           UserMapper userMapper,
                           SysRegionMapper sysRegionMapper,
                           VzanHttpUtil vzanHttpUtil,
                           DataSourceTransactionManager transactionManager) {
        this.clinicQueryMapper = clinicQueryMapper;
        this.clinicMapper = clinicMapper;
        this.provincialAgentMapper = provincialAgentMapper;
        this.userMapper = userMapper;
        this.sysRegionMapper = sysRegionMapper;
        this.vzanHttpUtil = vzanHttpUtil;
        this.transactionManager = transactionManager;
    }
@@ -311,61 +306,7 @@
            throw e;
        }
        if (request.getAgentId() == null) {
            return detail(id);
        }
        // 事务提交后,调用微赞接口(不回滚本地事务)
        try {
            Clinic clinic = clinicMapper.selectById(id);
            // 调用微赞创建门店
            Integer provinceCode = parseRegionCode(clinic.getProvinceCode(), "省编码");
            Integer cityCode = parseRegionCode(clinic.getCityCode(), "市编码");
            Integer areaCode = parseRegionCode(clinic.getDistrictCode(), "区县编码");
            log.info("调用微赞创建门店,入参 title={}, provinceCode={}, cityCode={}, areaCode={}, address={}, telephone={}",
                    clinic.getName(), provinceCode, cityCode, areaCode, clinic.getAddress(), clinic.getContactPhone());
            JsonNode vzanStoreResponse = vzanHttpUtil.createStore(clinic.getName(), provinceCode, cityCode, areaCode, clinic.getAddress(), clinic.getContactPhone());
            log.info("微赞创建门店成功,出参={}", vzanStoreResponse);
            // 查询代理信息获取parentMobile
            ProvincialAgent agent = provincialAgentMapper.selectById(request.getAgentId());
            String parentMobile = agent.getContactInfo();
            if (parentMobile == null || parentMobile.trim().isEmpty()) {
                throw new IllegalArgumentException("代理联系方式为空,agentId=" + request.getAgentId());
            }
            // 调用微赞创建代理
            log.info("调用微赞创建代理,入参 agentMobile={}, agentName={}, levelCode=1, storeName={}, parentMobile={}",
                    clinic.getContactPhone(), clinic.getName(), clinic.getName(), parentMobile);
            JsonNode vzanAgentResponse = vzanHttpUtil.createAgent(
                    clinic.getContactPhone(),  // agentMobile传门店的手机号
                    clinic.getName(),          // agentName传门店的名称
                    1,                        // levelCode传1
                    parentMobile,              // parentMobile传代理的contact_info
                    clinic.getName()          // storeName传门店的name
            );
            log.info("微赞创建代理成功,出参={}", vzanAgentResponse);
        } catch (Exception e) {
            // 捕获微赞接口异常,不回滚本地事务
            log.error("调用微赞接口失败,但本地数据已保存成功,clinicId={}", id, e);
            throw new IllegalStateException("调用微赞失败", e);
        }
        return detail(id);
    }
    private Integer parseRegionCode(String code, String fieldName) {
        if (code == null || code.trim().isEmpty()) {
            throw new IllegalArgumentException(fieldName + "不能为空");
        }
        try {
            return Integer.parseInt(code);
        } catch (NumberFormatException e) {
            throw new IllegalArgumentException(fieldName + "格式错误: " + code);
        }
    }
    private void addCode(Set<String> codes, String code) {