|
@ -25,20 +25,27 @@ import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
import com.epmet.commons.tools.constant.FieldConstant; |
|
|
import com.epmet.commons.tools.constant.FieldConstant; |
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
import com.epmet.dao.CustomerDao; |
|
|
import com.epmet.dao.CustomerDao; |
|
|
|
|
|
import com.epmet.dto.CustomerAgencyDTO; |
|
|
import com.epmet.dto.CustomerDTO; |
|
|
import com.epmet.dto.CustomerDTO; |
|
|
import com.epmet.dto.form.CustomerFormDTO; |
|
|
import com.epmet.dto.form.CustomerFormDTO; |
|
|
|
|
|
import com.epmet.dto.form.StaffRoleFormDTO; |
|
|
|
|
|
import com.epmet.dto.result.GovStaffRoleResultDTO; |
|
|
import com.epmet.dto.result.ValidCustomerResultDTO; |
|
|
import com.epmet.dto.result.ValidCustomerResultDTO; |
|
|
import com.epmet.entity.CustomerEntity; |
|
|
import com.epmet.entity.CustomerEntity; |
|
|
|
|
|
import com.epmet.feign.EpmetUserFeignClient; |
|
|
|
|
|
import com.epmet.feign.GovOrgFeignClient; |
|
|
import com.epmet.redis.CustomerRedis; |
|
|
import com.epmet.redis.CustomerRedis; |
|
|
import com.epmet.service.CustomerService; |
|
|
import com.epmet.service.CustomerService; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
|
|
import org.slf4j.Logger; |
|
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
import java.util.*; |
|
|
import java.util.List; |
|
|
import java.util.stream.Collectors; |
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 客户表 |
|
|
* 客户表 |
|
@ -49,9 +56,17 @@ import java.util.Map; |
|
|
@Service |
|
|
@Service |
|
|
public class CustomerServiceImpl extends BaseServiceImpl<CustomerDao, CustomerEntity> implements CustomerService { |
|
|
public class CustomerServiceImpl extends BaseServiceImpl<CustomerDao, CustomerEntity> implements CustomerService { |
|
|
|
|
|
|
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(CustomerServiceImpl.class); |
|
|
|
|
|
|
|
|
@Autowired |
|
|
@Autowired |
|
|
private CustomerRedis customerRedis; |
|
|
private CustomerRedis customerRedis; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private EpmetUserFeignClient epmetUserFeignClient; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private GovOrgFeignClient govOrgFeignClient; |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public PageData<CustomerDTO> page(Map<String, Object> params) { |
|
|
public PageData<CustomerDTO> page(Map<String, Object> params) { |
|
|
IPage<CustomerEntity> page = baseDao.selectPage( |
|
|
IPage<CustomerEntity> page = baseDao.selectPage( |
|
@ -113,7 +128,47 @@ public class CustomerServiceImpl extends BaseServiceImpl<CustomerDao, CustomerEn |
|
|
*/ |
|
|
*/ |
|
|
@Override |
|
|
@Override |
|
|
public Result<List<ValidCustomerResultDTO>> getValidCustomerList() { |
|
|
public Result<List<ValidCustomerResultDTO>> getValidCustomerList() { |
|
|
return new Result<List<ValidCustomerResultDTO>>().ok(baseDao.selectListValidCustomerResultDTO()); |
|
|
List<ValidCustomerResultDTO> validCustomers = baseDao.selectListValidCustomerResultDTO(); |
|
|
|
|
|
List<String> customerIds = validCustomers.stream().map(customer -> customer.getCustomerId()).collect(Collectors.toList()); |
|
|
|
|
|
Result<Map<String, CustomerAgencyDTO>> rootAgencyResult = govOrgFeignClient.getCustomerRootAgencyBatch(customerIds); |
|
|
|
|
|
|
|
|
|
|
|
// 1.查询客户的根级组织,批量查询
|
|
|
|
|
|
ArrayList<String> rootAgencyIds = new ArrayList<>(); |
|
|
|
|
|
if (rootAgencyResult.success()) { |
|
|
|
|
|
Map<String, CustomerAgencyDTO> rootAgencies = rootAgencyResult.getData(); |
|
|
|
|
|
validCustomers.stream().forEach(customer -> { |
|
|
|
|
|
CustomerAgencyDTO rootAgency = rootAgencies.get(customer.getCustomerId()); |
|
|
|
|
|
customer.setHasRootAgency(rootAgency == null ? false : true); |
|
|
|
|
|
customer.setRootAgencyId(rootAgency == null ? null : rootAgency.getId()); |
|
|
|
|
|
if (rootAgency != null) { |
|
|
|
|
|
rootAgencyIds.add(rootAgency.getId()); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} else { |
|
|
|
|
|
log.error("查询有效客户列表:查询客户的根级组织失败:{}", rootAgencyResult.toString()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!CollectionUtils.isEmpty(rootAgencyIds)) { |
|
|
|
|
|
//2.查询客户的根级组织对应的管理员角色列表,批量查询
|
|
|
|
|
|
StaffRoleFormDTO staffRoleFormDTO = new StaffRoleFormDTO(); |
|
|
|
|
|
staffRoleFormDTO.setOrgIds(rootAgencyIds); |
|
|
|
|
|
staffRoleFormDTO.setRoleKey("manager");// TODO ,此处应该将所有的角色key放到EpmetUser的client中
|
|
|
|
|
|
Result<Map<String, List<GovStaffRoleResultDTO>>> managersResult = epmetUserFeignClient.getStaffsInRoleOfOrgs(staffRoleFormDTO); |
|
|
|
|
|
if (managersResult.success()) { |
|
|
|
|
|
Map<String, List<GovStaffRoleResultDTO>> rootAgencyManagerMap = managersResult.getData(); |
|
|
|
|
|
validCustomers.stream().forEach(customer -> { |
|
|
|
|
|
List<GovStaffRoleResultDTO> rootAgencyManagers = null; |
|
|
|
|
|
if (customer.getRootAgencyId() != null) { |
|
|
|
|
|
rootAgencyManagers = rootAgencyManagerMap.get(customer.getRootAgencyId()); |
|
|
|
|
|
} |
|
|
|
|
|
customer.setHasManager(CollectionUtils.isEmpty(rootAgencyManagers) ? false : true); |
|
|
|
|
|
}); |
|
|
|
|
|
} else { |
|
|
|
|
|
log.error("查询有效客户列表:查询客户根级组织的管理员失败:{}", managersResult.toString()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return new Result<List<ValidCustomerResultDTO>>().ok(validCustomers); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|