hejianhao
2026-08-18 3df055ea1038e0bbcbbbf80ccbeea43c82952932
tcm-training-admin-backend/src/main/java/com/tcm/training/admin/agent/service/ProvincialAgentAppService.java
@@ -37,17 +37,27 @@
        this.clinicMapper = clinicMapper;
    }
    public PageResponse<ProvincialAgentListItemVO> page(int page, int pageSize, String agentName, String regionCode) {
    public PageResponse<ProvincialAgentListItemVO> page(int page, int pageSize, String regionCode,
                                                        String clinicName, String contactInfo, Integer status) {
        LambdaQueryWrapper<ProvincialAgent> query = new LambdaQueryWrapper<ProvincialAgent>()
                .eq(ProvincialAgent::getDeleted, 0)
                .like(trim(agentName) != null, ProvincialAgent::getAgentName, trim(agentName))
                .orderByAsc(ProvincialAgent::getCreatedAt).orderByDesc(ProvincialAgent::getId);
                .like(trim(contactInfo) != null, ProvincialAgent::getContactInfo, trim(contactInfo))
                .eq(status != null, ProvincialAgent::getStatus, status)
                .orderByAsc(ProvincialAgent::getCreatedAt).orderByAsc(ProvincialAgent::getId);
        if (trim(regionCode) != null) {
            List<Long> ids = new ArrayList<Long>();
            for (AgentRegion region : regionMapper.selectList(new LambdaQueryWrapper<AgentRegion>()
                    .eq(AgentRegion::getRegionCode, trim(regionCode))))
                ids.add(region.getAgentId());
            if (ids.isEmpty()) return PageResponse.of(new ArrayList<ProvincialAgentListItemVO>(), 0, page, pageSize);
                    .eq(AgentRegion::getRegionCode, trim(regionCode)))) ids.add(region.getAgentId());
            if (ids.isEmpty()) return emptyPage(page, pageSize);
            query.in(ProvincialAgent::getId, ids);
        }
        if (trim(clinicName) != null) {
            List<Long> ids = new ArrayList<Long>();
            for (Clinic clinic : clinicMapper.selectList(new LambdaQueryWrapper<Clinic>()
                    .like(Clinic::getName, trim(clinicName)))) {
                if (clinic.getAgentId() != null && !ids.contains(clinic.getAgentId())) ids.add(clinic.getAgentId());
            }
            if (ids.isEmpty()) return emptyPage(page, pageSize);
            query.in(ProvincialAgent::getId, ids);
        }
        IPage<ProvincialAgent> result = agentMapper.selectPage(new Page<ProvincialAgent>(page, pageSize), query);
@@ -56,6 +66,9 @@
        return PageResponse.of(list, result.getTotal(), result.getCurrent(), result.getSize());
    }
    private PageResponse<ProvincialAgentListItemVO> emptyPage(int page, int pageSize) {
        return PageResponse.of(new ArrayList<ProvincialAgentListItemVO>(), 0, page, pageSize);
    }
    public ProvincialAgentDetailVO detail(Long id) {
        return toDetail(require(id));
    }
@@ -99,6 +112,7 @@
        agent.setAccountHolder(trim(request.getAccountHolder()));
        agent.setBranchName(trim(request.getBranchName()));
        agent.setContactInfo(trim(request.getContactInfo()));
        agent.setStatus(request.getStatus() == null ? 1 : request.getStatus());
        agent.setAddress(trim(request.getAddress()));
    }
@@ -130,10 +144,14 @@
        vo.setContactInfo(agent.getContactInfo());
        vo.setAddress(agent.getAddress());
        vo.setCreatedAt(agent.getCreatedAt());
        vo.setStatus(agent.getStatus());
        vo.setClinicCount(clinicMapper.selectCount(new LambdaQueryWrapper<Clinic>().eq(Clinic::getAgentId, agent.getId())));
        List<AgentRegion> regions = regions(agent.getId());
        vo.setRegionCount(regions.size());
        List<String> names = new ArrayList<String>();
        for (AgentRegion region : regions) names.add(resolveRegion(region.getRegionCode()).name);
        for (AgentRegion region : regions) {
            names.add(resolveRegion(region.getRegionCode()).name);
        }
        vo.setRegionNames(names);
        return vo;
    }
@@ -148,6 +166,8 @@
        vo.setRegionCount(base.getRegionCount());
        vo.setRegionNames(base.getRegionNames());
        vo.setCreatedAt(base.getCreatedAt());
        vo.setStatus(base.getStatus());
        vo.setClinicCount(base.getClinicCount());
        vo.setBankName(agent.getBankName());
        vo.setAccountNumber(agent.getAccountNumber());
        vo.setAccountHolder(agent.getAccountHolder());