| | |
| | | package com.tcm.training.admin.agent.service; |
| | | |
| | | import cn.hutool.json.JSONUtil; |
| | | import cn.idev.excel.FastExcel; |
| | | import com.fasterxml.jackson.databind.JsonNode; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | |
| | | import com.tcm.training.admin.app.register.entity.SysRegion; |
| | | import com.tcm.training.admin.app.register.mapper.SysRegionMapper; |
| | | import com.tcm.training.admin.common.PageResponse; |
| | | import com.tcm.training.admin.common.PhoneMasker; |
| | | import com.tcm.training.admin.live.entity.Clinic; |
| | | import com.tcm.training.admin.live.mapper.ClinicMapper; |
| | | import com.tcm.training.admin.utils.VzanHttpUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import com.tcm.training.admin.common.enums.EnabledStatusEnum; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | |
| | | @Slf4j |
| | | @Service |
| | | public class ProvincialAgentAppService { |
| | | private final ProvincialAgentMapper agentMapper; |
| | | private final AgentRegionMapper regionMapper; |
| | | private final SysRegionMapper sysRegionMapper; |
| | | private final ClinicMapper clinicMapper; |
| | | private final VzanHttpUtil vzanHttpUtil; |
| | | |
| | | public ProvincialAgentAppService(ProvincialAgentMapper agentMapper, AgentRegionMapper regionMapper, |
| | | SysRegionMapper sysRegionMapper, ClinicMapper clinicMapper) { |
| | | SysRegionMapper sysRegionMapper, ClinicMapper clinicMapper, VzanHttpUtil vzanHttpUtil) { |
| | | this.agentMapper = agentMapper; |
| | | this.regionMapper = regionMapper; |
| | | this.sysRegionMapper = sysRegionMapper; |
| | | this.clinicMapper = clinicMapper; |
| | | this.vzanHttpUtil = vzanHttpUtil; |
| | | } |
| | | |
| | | public PageResponse<ProvincialAgentListItemVO> page(int page, int pageSize, String regionCode, |
| | |
| | | } |
| | | IPage<ProvincialAgent> result = agentMapper.selectPage(new Page<ProvincialAgent>(page, pageSize), query); |
| | | List<ProvincialAgentListItemVO> list = new ArrayList<ProvincialAgentListItemVO>(); |
| | | for (ProvincialAgent item : result.getRecords()) list.add(toList(item)); |
| | | for (ProvincialAgent item : result.getRecords()) { |
| | | list.add(toList(item)); |
| | | } |
| | | return PageResponse.of(list, result.getTotal(), result.getCurrent(), result.getSize()); |
| | | } |
| | | |
| | |
| | | return toDetail(require(id)); |
| | | } |
| | | |
| | | @Transactional |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public ProvincialAgentDetailVO create(ProvincialAgentSaveRequest request) { |
| | | boolean firstAgent = agentMapper.selectCount(new LambdaQueryWrapper<ProvincialAgent>() |
| | | .eq(ProvincialAgent::getDeleted, 0)) == 0; |
| | |
| | | if (firstAgent) { |
| | | clinicMapper.update(null, new LambdaUpdateWrapper<Clinic>().set(Clinic::getAgentId, agent.getId())); |
| | | } |
| | | log.info("调用微赞创建代理,入参 agentMobile={}, agentName={}, levelCode={}, parentMobile={}, storeName={}", |
| | | request.getContactInfo(), request.getAgentName(), 2, null, null); |
| | | try { |
| | | JsonNode vzanResponse = vzanHttpUtil.createAgent( |
| | | request.getContactInfo(), request.getAgentName(), 2, null, null); |
| | | log.info("微赞创建代理成功,出参={}", vzanResponse); |
| | | } catch (RuntimeException ex) { |
| | | log.error("微赞创建代理失败,本地事务将回滚,入参 agentMobile={}, agentName={}, levelCode={}, parentMobile={}, storeName={}", |
| | | request.getContactInfo(), request.getAgentName(), 1, null, request.getAgentName(), ex); |
| | | // throw ex; |
| | | throw new IllegalStateException("微赞创建代理失败", ex); |
| | | } |
| | | return detail(agent.getId()); |
| | | } |
| | | |
| | | @Transactional |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public ProvincialAgentDetailVO update(Long id, ProvincialAgentSaveRequest request) { |
| | | ProvincialAgent agent = require(id); |
| | | fill(agent, request); |
| | |
| | | return detail(id); |
| | | } |
| | | |
| | | @Transactional |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void delete(Long id) { |
| | | require(id); |
| | | agentMapper.deleteById(id); |
| | |
| | | agent.setAccountHolder(trim(request.getAccountHolder())); |
| | | agent.setBranchName(trim(request.getBranchName())); |
| | | agent.setContactInfo(trim(request.getContactInfo())); |
| | | agent.setStatus(request.getStatus() == null ? 1 : request.getStatus()); |
| | | agent.setStatus(request.getStatus() == null ? EnabledStatusEnum.ENABLED.getValue() : request.getStatus()); |
| | | agent.setAddress(trim(request.getAddress())); |
| | | } |
| | | |
| | |
| | | ProvincialAgentListItemVO vo = new ProvincialAgentListItemVO(); |
| | | vo.setId(agent.getId()); |
| | | vo.setAgentName(agent.getAgentName()); |
| | | vo.setContactInfo(agent.getContactInfo()); |
| | | vo.setContactInfo(PhoneMasker.mask(agent.getContactInfo())); |
| | | vo.setAddress(agent.getAddress()); |
| | | vo.setCreatedAt(agent.getCreatedAt()); |
| | | vo.setStatus(agent.getStatus()); |
| | |
| | | this.name = name; |
| | | } |
| | | } |
| | | } |
| | | } |