Browse Source

1.修改有效客户列表接口,增加hasManager和hasRootAgency字段返回

dev_shibei_match
wxz 5 years ago
parent
commit
5846f60b05
  1. 6
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/aspect/BaseRequestLogAspect.java
  2. 29
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/AgencyController.java
  3. 7
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerAgencyDao.java
  4. 7
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/AgencyService.java
  5. 5
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/AgencyServiceImpl.java
  6. 8
      epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerAgencyDao.xml
  7. 15
      epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/dto/result/ValidCustomerResultDTO.java
  8. 34
      epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/feign/EpmetUserFeignClient.java
  9. 25
      epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/feign/GovOrgFeignClient.java
  10. 25
      epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/feign/fallback/EpmetUserFeignClientFallBack.java
  11. 20
      epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/feign/fallback/GovOrgFeignClientFallBack.java
  12. 63
      epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/impl/CustomerServiceImpl.java
  13. 11
      epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/StaffRoleFormDTO.java
  14. 22
      epmet-user/epmet-user-server/src/main/java/com/epmet/controller/StaffRoleController.java

6
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/aspect/BaseRequestLogAspect.java

@ -70,9 +70,11 @@ public abstract class BaseRequestLogAspect {
long execTimeMillis = Duration.between(startTime, endTime).toMillis(); long execTimeMillis = Duration.between(startTime, endTime).toMillis();
if (exception != null) { if (exception != null) {
log.info("<<<<<<<<异常响应<<<<<<<<:线程ID:{},执行时长:{}ms, 异常信息:{}", id, execTimeMillis, ExceptionUtils.getErrorStackTrace(exception)); log.info("<<<<<<<<异常响应<<<<<<<<:线程ID:{},执行时长:{}ms, 响应数据:{}, 异常信息:{}",
id, execTimeMillis, result == null ? result : result.toString(), ExceptionUtils.getErrorStackTrace(exception));
} else { } else {
log.info("<<<<<<<<正常响应<<<<<<<<:线程ID:{},执行时长:{}ms, 响应数据:{}", id, execTimeMillis, result == null ? result : result.toString()); log.info("<<<<<<<<正常响应<<<<<<<<:线程ID:{},执行时长:{}ms, 响应数据:{}",
id, execTimeMillis, result == null ? result : result.toString());
} }
} }
return result; return result;

29
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/AgencyController.java

@ -38,7 +38,9 @@ import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
@ -177,4 +179,31 @@ public class AgencyController {
return new Result<CustomerAgencyDTO>(); return new Result<CustomerAgencyDTO>();
} }
/**
* 查询客户根级组织
* @param customerId
* @return
*/
@PostMapping("customerrootagency/{customerId}")
public Result<CustomerAgencyDTO> getCustomerRootAgency(@PathVariable String customerId) {
CustomerAgencyDTO customerRootAgency = agencyService.getCustomerRootAgency(customerId);
return new Result().ok(customerRootAgency);
}
/**
* 批量查询客户根级组织
* @param customerIds
* @return
*/
@PostMapping("customerrootagencybatch")
public Result<Map<String, CustomerAgencyDTO>> getCustomerRootAgencyBatch(@RequestBody List<String> customerIds) {
Map<String, CustomerAgencyDTO> customerRootAgencies = new HashMap<>();
customerIds.stream().forEach(customerId -> {
CustomerAgencyDTO rootAgency = agencyService.getCustomerRootAgency(customerId);
customerRootAgencies.put(customerId, rootAgency);
});
return new Result().ok(customerRootAgencies);
}
} }

7
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerAgencyDao.java

@ -100,4 +100,11 @@ public interface CustomerAgencyDao extends BaseDao<CustomerAgencyEntity> {
* @Description 查询当前组织的下一级组织列表 * @Description 查询当前组织的下一级组织列表
**/ **/
List<AgencySubResultDTO> selectSubAgencyList(@Param("subAgencyPids") String subAgencyPids); List<AgencySubResultDTO> selectSubAgencyList(@Param("subAgencyPids") String subAgencyPids);
/**
* 查询客户根级组织
* @param customerId
* @return
*/
CustomerAgencyDTO getCustomerRootAgency(@Param("customerId") String customerId);
} }

7
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/AgencyService.java

@ -18,6 +18,7 @@
package com.epmet.service; package com.epmet.service;
import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.utils.Result;
import com.epmet.dto.CustomerAgencyDTO;
import com.epmet.dto.form.*; import com.epmet.dto.form.*;
import com.epmet.dto.result.AddAgencyResultDTO; import com.epmet.dto.result.AddAgencyResultDTO;
import com.epmet.dto.result.AgencyListResultDTO; import com.epmet.dto.result.AgencyListResultDTO;
@ -90,4 +91,10 @@ public interface AgencyService {
CustomerAgencyEntity getAgencyById(String agencyId); CustomerAgencyEntity getAgencyById(String agencyId);
CustomerAgencyEntity getAgencyByStaff(String staffId); CustomerAgencyEntity getAgencyByStaff(String staffId);
/**
* 查询客户根级组织
* @param customerId
*/
CustomerAgencyDTO getCustomerRootAgency(String customerId);
} }

5
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/AgencyServiceImpl.java

@ -249,4 +249,9 @@ public class AgencyServiceImpl implements AgencyService {
public CustomerAgencyEntity getAgencyByStaff(String staffId) { public CustomerAgencyEntity getAgencyByStaff(String staffId) {
return customerAgencyDao.getAgencyByStaffId(staffId); return customerAgencyDao.getAgencyByStaffId(staffId);
} }
@Override
public CustomerAgencyDTO getCustomerRootAgency(String customerId) {
return customerAgencyDao.getCustomerRootAgency(customerId);
}
} }

8
epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerAgencyDao.xml

@ -136,4 +136,12 @@
ORDER BY created_time DESC ORDER BY created_time DESC
</select> </select>
<select id="getCustomerRootAgency" resultType="com.epmet.dto.CustomerAgencyDTO">
SELECT *
FROM customer_agency ca
WHERE ca.PID = '0'
AND ca.CUSTOMER_ID = #{customerId}
AND ca.DEL_FLAG = 0
</select>
</mapper> </mapper>

15
epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/dto/result/ValidCustomerResultDTO.java

@ -22,4 +22,19 @@ public class ValidCustomerResultDTO implements Serializable {
* 客户名称 * 客户名称
*/ */
private String customerName; private String customerName;
/**
* 是否有管理员
*/
private Boolean hasManager;
/**
* 是否有根级组织
*/
private Boolean hasRootAgency;
/**
* 根级组织ID
*/
private String rootAgencyId;
} }

34
epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/feign/EpmetUserFeignClient.java

@ -0,0 +1,34 @@
package com.epmet.feign;
import com.epmet.commons.tools.constant.ServiceConstant;
import com.epmet.commons.tools.utils.Result;
import com.epmet.dto.form.StaffRoleFormDTO;
import com.epmet.dto.result.GovStaffRoleResultDTO;
import com.epmet.feign.fallback.EpmetUserFeignClientFallBack;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.List;
import java.util.Map;
@FeignClient(name = ServiceConstant.EPMET_USER_SERVER, fallback = EpmetUserFeignClientFallBack.class, url = "localhost:8087")
public interface EpmetUserFeignClient {
/**
* 根据机构Id查询机构下是网格长角色的用户
* @param staffRoleFormDTO
* @return
* @Author sun
*/
@PostMapping("/epmetuser/staffrole/staffsinrole")
Result<List<GovStaffRoleResultDTO>> getStaffsInRole(@RequestBody StaffRoleFormDTO staffRoleFormDTO);
/**
* 一次性查询多个机构下指定角色的用户列表
* @param staffRoleFormDTO
* @return
*/
@PostMapping("/epmetuser/staffrole/staffsinroleoforgs")
Result<Map<String, List<GovStaffRoleResultDTO>>> getStaffsInRoleOfOrgs(@RequestBody StaffRoleFormDTO staffRoleFormDTO);
}

25
epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/feign/GovOrgFeignClient.java

@ -0,0 +1,25 @@
package com.epmet.feign;
import com.epmet.commons.tools.constant.ServiceConstant;
import com.epmet.commons.tools.utils.Result;
import com.epmet.dto.CustomerAgencyDTO;
import com.epmet.feign.fallback.GovOrgFeignClientFallBack;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.List;
import java.util.Map;
@FeignClient(name = ServiceConstant.GOV_ORG_SERVER, fallback = GovOrgFeignClientFallBack.class, url = "localhost:8092")
public interface GovOrgFeignClient {
/**
* 批量查询客户根级组织
* @param customerIds
* @return
*/
@PostMapping("/gov/org/agency/customerrootagencybatch")
Result<Map<String, CustomerAgencyDTO>> getCustomerRootAgencyBatch(List<String> customerIds);
}

25
epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/feign/fallback/EpmetUserFeignClientFallBack.java

@ -0,0 +1,25 @@
package com.epmet.feign.fallback;
import com.epmet.commons.tools.constant.ServiceConstant;
import com.epmet.commons.tools.utils.ModuleUtils;
import com.epmet.commons.tools.utils.Result;
import com.epmet.dto.form.StaffRoleFormDTO;
import com.epmet.dto.result.GovStaffRoleResultDTO;
import com.epmet.feign.EpmetUserFeignClient;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
@Component
public class EpmetUserFeignClientFallBack implements EpmetUserFeignClient {
@Override
public Result<List<GovStaffRoleResultDTO>> getStaffsInRole(StaffRoleFormDTO staffRoleFormDTO) {
return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "getStaffsInRole", staffRoleFormDTO);
}
@Override
public Result<Map<String, List<GovStaffRoleResultDTO>>> getStaffsInRoleOfOrgs(StaffRoleFormDTO staffRoleFormDTO) {
return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "getStaffsInRoleOfOrgs", staffRoleFormDTO);
}
}

20
epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/feign/fallback/GovOrgFeignClientFallBack.java

@ -0,0 +1,20 @@
package com.epmet.feign.fallback;
import com.epmet.commons.tools.constant.ServiceConstant;
import com.epmet.commons.tools.utils.ModuleUtils;
import com.epmet.commons.tools.utils.Result;
import com.epmet.dto.CustomerAgencyDTO;
import com.epmet.feign.GovOrgFeignClient;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
@Component
public class GovOrgFeignClientFallBack implements GovOrgFeignClient {
@Override
public Result<Map<String, CustomerAgencyDTO>> getCustomerRootAgencyBatch(List<String> customerIds) {
return ModuleUtils.feignConError(ServiceConstant.GOV_ORG_SERVER, "getCustomerRootAgencyBatch", customerIds);
}
}

63
epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/impl/CustomerServiceImpl.java

@ -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);
} }
/** /**

11
epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/StaffRoleFormDTO.java

@ -3,6 +3,7 @@ package com.epmet.dto.form;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import java.util.List;
@Data @Data
public class StaffRoleFormDTO { public class StaffRoleFormDTO {
@ -15,6 +16,9 @@ public class StaffRoleFormDTO {
// 查询某角色下的人员列表group // 查询某角色下的人员列表group
public interface GetStaffsInRole {} public interface GetStaffsInRole {}
// 一次性查询多个机构下,指定角色的用户列表
public interface GetStaffsInRoleOrOrgs {}
/**===========校验分组结束============*/ /**===========校验分组结束============*/
@NotBlank(message = "工作人员ID不能为空", groups = {GetRolesOfStaff.class}) @NotBlank(message = "工作人员ID不能为空", groups = {GetRolesOfStaff.class})
@ -29,6 +33,11 @@ public class StaffRoleFormDTO {
/** /**
* 角色key * 角色key
*/ */
@NotBlank(message = "角色Key不能为空", groups = {GetStaffsInRole.class}) @NotBlank(message = "角色Key不能为空", groups = {GetStaffsInRole.class, GetStaffsInRoleOrOrgs.class})
private String roleKey; private String roleKey;
/**
* 组织ID列表
*/
private List<String> orgIds;
} }

22
epmet-user/epmet-user-server/src/main/java/com/epmet/controller/StaffRoleController.java

@ -1,5 +1,6 @@
package com.epmet.controller; package com.epmet.controller;
import cn.hutool.core.collection.CollectionUtil;
import com.epmet.commons.mybatis.entity.DataScope; import com.epmet.commons.mybatis.entity.DataScope;
import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.utils.Result;
import com.epmet.commons.tools.validator.ValidatorUtils; import com.epmet.commons.tools.validator.ValidatorUtils;
@ -20,7 +21,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* @return 工作人员相关api * @return 工作人员相关api
@ -74,6 +77,25 @@ public class StaffRoleController {
return new Result<List<GovStaffRoleResultDTO>>().ok(staffRoleDTOS); return new Result<List<GovStaffRoleResultDTO>>().ok(staffRoleDTOS);
} }
/**
* 一次性查询多个机构下指定角色的用户列表
* @param staffRoleFormDTO
* @return
*/
@PostMapping("staffsinroleoforgs")
public Result<Map<String, List<GovStaffRoleResultDTO>>> getStaffsInRoleOfOrgs(@RequestBody StaffRoleFormDTO staffRoleFormDTO) {
HashMap<String, List<GovStaffRoleResultDTO>> resultMap = new HashMap<>();
ValidatorUtils.validateEntity(staffRoleFormDTO, StaffRoleFormDTO.GetStaffsInRoleOrOrgs.class);
List<String> orgIds = staffRoleFormDTO.getOrgIds();
if (!CollectionUtil.isEmpty(orgIds)) {
for (String orgId : orgIds) {
List<GovStaffRoleResultDTO> staffRole = staffRoleService.listStaffsInRole(staffRoleFormDTO.getRoleKey(), orgId, DataScope.getDefault());
resultMap.put(orgId, staffRole);
}
}
return new Result<Map<String, List<GovStaffRoleResultDTO>>>().ok(resultMap);
}
/** /**
* @return Result<StaffRolesResultDTO> * @return Result<StaffRolesResultDTO>
* @Description 查询一个员工在指定客户下的角色 * @Description 查询一个员工在指定客户下的角色

Loading…
Cancel
Save