| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | private final ProvincialAgentMapper provincialAgentMapper; |
| | | private final UserMapper userMapper; |
| | | private final SysRegionMapper sysRegionMapper; |
| | | private final VzanHttpUtil vzanHttpUtil; |
| | | private final DataSourceTransactionManager transactionManager; |
| | | |
| | | public ClinicAppService(ClinicQueryMapper clinicQueryMapper, |
| | |
| | | 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; |
| | | } |
| | | |
| | |
| | | String regionCode, |
| | | String name, |
| | | String phone, |
| | | String agentName, |
| | | LocalDateTime createdFrom, |
| | | LocalDateTime createdTo, |
| | | Integer status) { |
| | |
| | | trimToNull(regionCode), |
| | | trimToNull(name), |
| | | trimToNull(phone), |
| | | trimToNull(agentName), |
| | | createdFrom, |
| | | createdTo, |
| | | status |
| | |
| | | public void export(String regionCode, |
| | | String name, |
| | | String phone, |
| | | String agentName, |
| | | LocalDateTime createdFrom, |
| | | LocalDateTime createdTo, |
| | | Integer status, |
| | |
| | | trimToNull(regionCode), |
| | | trimToNull(name), |
| | | trimToNull(phone), |
| | | trimToNull(agentName), |
| | | createdFrom, |
| | | createdTo, |
| | | status |
| | |
| | | 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) { |
| | |
| | | item.setPhone(row.getPhone() == null ? "-" : PhoneMasker.mask(row.getPhone())); |
| | | item.setRegionName(defaultText(row.getRegionName())); |
| | | item.setStatus(row.getStatus()); |
| | | item.setAgentName(defaultText(row.getAgentName())); |
| | | item.setUserCount(row.getUserCount() == null ? 0 : row.getUserCount()); |
| | | item.setCreatedAt(row.getCreatedAt()); |
| | | item.setBusinessLicenseUrl(trimToNull(row.getBusinessLicenseUrl())); |