| | |
| | | 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.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.LinkedHashMap; |
| | | |
| | | @Slf4j |
| | | @Service |
| | |
| | | private final SysRegionMapper sysRegionMapper; |
| | | private final ClinicMapper clinicMapper; |
| | | private final VzanHttpUtil vzanHttpUtil; |
| | | private volatile Map<String, SysRegion> regionCache; |
| | | |
| | | public ProvincialAgentAppService(ProvincialAgentMapper agentMapper, AgentRegionMapper regionMapper, |
| | | SysRegionMapper sysRegionMapper, ClinicMapper clinicMapper, VzanHttpUtil vzanHttpUtil) { |
| | |
| | | } |
| | | 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; |
| | |
| | | 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())); |
| | | } |
| | | |
| | | private void saveRegions(ProvincialAgent agent, ProvincialAgentSaveRequest request) { |
| | | if (request.getRegions() == null) return; |
| | | List<AgentRegion> regions = new ArrayList<AgentRegion>(); |
| | | for (ProvincialAgentSaveRequest.RegionItem item : request.getRegions()) { |
| | | if (item == null || trim(item.getRegionCode()) == null) continue; |
| | | RegionInfo info = resolveRegion(item.getRegionCode()); |
| | |
| | | region.setRegionCode(trim(item.getRegionCode())); |
| | | region.setRegionName(info.name); |
| | | region.setRegionLevel(info.path.size()); |
| | | regionMapper.insert(region); |
| | | regions.add(region); |
| | | } |
| | | if (!regions.isEmpty()) { |
| | | regionMapper.insertBatch(regions); |
| | | } |
| | | } |
| | | |
| | |
| | | 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()); |
| | |
| | | private RegionInfo resolveRegion(String code) { |
| | | List<String> path = new ArrayList<String>(); |
| | | List<String> names = new ArrayList<String>(); |
| | | SysRegion current = sysRegionMapper.selectByCode(code); |
| | | SysRegion current = getRegionCache().get(code); |
| | | while (current != null) { |
| | | path.add(0, current.getCode()); |
| | | names.add(0, current.getName()); |
| | | current = current.getParentId() == null || current.getParentId() == 0 ? null : sysRegionMapper.selectById(current.getParentId()); |
| | | current = current.getParentId() == null || current.getParentId() == 0 ? null : getRegionById(current.getParentId()); |
| | | } |
| | | if (path.isEmpty()) { |
| | | path.add(code); |
| | |
| | | return new RegionInfo(path, String.join("", names)); |
| | | } |
| | | |
| | | private Map<String, SysRegion> getRegionCache() { |
| | | Map<String, SysRegion> cache = regionCache; |
| | | if (cache == null) { |
| | | synchronized (this) { |
| | | cache = regionCache; |
| | | if (cache == null) { |
| | | cache = new LinkedHashMap<String, SysRegion>(); |
| | | for (SysRegion region : sysRegionMapper.selectAllOrdered()) cache.put(region.getCode(), region); |
| | | regionCache = cache; |
| | | } |
| | | } |
| | | } |
| | | return cache; |
| | | } |
| | | |
| | | private SysRegion getRegionById(Long id) { |
| | | for (SysRegion region : getRegionCache().values()) if (id.equals(region.getId())) { |
| | | return region; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | private String trim(String value) { |
| | | if (value == null) return null; |
| | | String trimmed = value.trim(); |