diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/aspect/BaseRequestLogAspect.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/aspect/BaseRequestLogAspect.java index 54417b7117..02e26acdf9 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/aspect/BaseRequestLogAspect.java +++ b/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(); 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 { - log.info("<<<<<<<<正常响应<<<<<<<<:线程ID:{},执行时长:{}ms, 响应数据:{}", id, execTimeMillis, result == null ? result : result.toString()); + log.info("<<<<<<<<正常响应<<<<<<<<:线程ID:{},执行时长:{}ms, 响应数据:{}", + id, execTimeMillis, result == null ? result : result.toString()); } } return result; diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/AgencyController.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/AgencyController.java index 59cde8f71c..babbdf49b9 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/AgencyController.java +++ b/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.web.bind.annotation.*; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** @@ -177,4 +179,31 @@ public class AgencyController { return new Result(); } + /** + * 查询客户根级组织 + * @param customerId + * @return + */ + @PostMapping("customerrootagency/{customerId}") + public Result getCustomerRootAgency(@PathVariable String customerId) { + CustomerAgencyDTO customerRootAgency = agencyService.getCustomerRootAgency(customerId); + return new Result().ok(customerRootAgency); + } + + /** + * 批量查询客户根级组织 + * @param customerIds + * @return + */ + @PostMapping("customerrootagencybatch") + public Result> getCustomerRootAgencyBatch(@RequestBody List customerIds) { + Map customerRootAgencies = new HashMap<>(); + customerIds.stream().forEach(customerId -> { + CustomerAgencyDTO rootAgency = agencyService.getCustomerRootAgency(customerId); + customerRootAgencies.put(customerId, rootAgency); + }); + + return new Result().ok(customerRootAgencies); + } + } \ No newline at end of file diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerAgencyDao.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerAgencyDao.java index a9846b3a76..6857d9c045 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerAgencyDao.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerAgencyDao.java @@ -100,4 +100,11 @@ public interface CustomerAgencyDao extends BaseDao { * @Description 查询当前组织的下一级组织列表 **/ List selectSubAgencyList(@Param("subAgencyPids") String subAgencyPids); + + /** + * 查询客户根级组织 + * @param customerId + * @return + */ + CustomerAgencyDTO getCustomerRootAgency(@Param("customerId") String customerId); } \ No newline at end of file diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/AgencyService.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/AgencyService.java index 0f19dac336..6ebd81f812 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/AgencyService.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/AgencyService.java @@ -18,6 +18,7 @@ package com.epmet.service; import com.epmet.commons.tools.utils.Result; +import com.epmet.dto.CustomerAgencyDTO; import com.epmet.dto.form.*; import com.epmet.dto.result.AddAgencyResultDTO; import com.epmet.dto.result.AgencyListResultDTO; @@ -90,4 +91,10 @@ public interface AgencyService { CustomerAgencyEntity getAgencyById(String agencyId); CustomerAgencyEntity getAgencyByStaff(String staffId); + + /** + * 查询客户根级组织 + * @param customerId + */ + CustomerAgencyDTO getCustomerRootAgency(String customerId); } \ No newline at end of file diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/AgencyServiceImpl.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/AgencyServiceImpl.java index 72b95f4181..f5f97eea0d 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/AgencyServiceImpl.java +++ b/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) { return customerAgencyDao.getAgencyByStaffId(staffId); } + + @Override + public CustomerAgencyDTO getCustomerRootAgency(String customerId) { + return customerAgencyDao.getCustomerRootAgency(customerId); + } } \ No newline at end of file diff --git a/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerAgencyDao.xml b/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerAgencyDao.xml index d0c7b4dcf0..940b3063ac 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerAgencyDao.xml +++ b/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerAgencyDao.xml @@ -136,4 +136,12 @@ ORDER BY created_time DESC + + \ No newline at end of file diff --git a/epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/dto/result/ValidCustomerResultDTO.java b/epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/dto/result/ValidCustomerResultDTO.java index 4d21495d3f..666a45b69c 100644 --- a/epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/dto/result/ValidCustomerResultDTO.java +++ b/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 Boolean hasManager; + + /** + * 是否有根级组织 + */ + private Boolean hasRootAgency; + + /** + * 根级组织ID + */ + private String rootAgencyId; } diff --git a/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/feign/EpmetUserFeignClient.java b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/feign/EpmetUserFeignClient.java new file mode 100644 index 0000000000..9058ae2178 --- /dev/null +++ b/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> getStaffsInRole(@RequestBody StaffRoleFormDTO staffRoleFormDTO); + + /** + * 一次性查询多个机构下,指定角色的用户列表 + * @param staffRoleFormDTO + * @return + */ + @PostMapping("/epmetuser/staffrole/staffsinroleoforgs") + Result>> getStaffsInRoleOfOrgs(@RequestBody StaffRoleFormDTO staffRoleFormDTO); +} diff --git a/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/feign/GovOrgFeignClient.java b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/feign/GovOrgFeignClient.java new file mode 100644 index 0000000000..058cbdc189 --- /dev/null +++ b/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> getCustomerRootAgencyBatch(List customerIds); + +} diff --git a/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/feign/fallback/EpmetUserFeignClientFallBack.java b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/feign/fallback/EpmetUserFeignClientFallBack.java new file mode 100644 index 0000000000..4df7aedb61 --- /dev/null +++ b/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> getStaffsInRole(StaffRoleFormDTO staffRoleFormDTO) { + return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "getStaffsInRole", staffRoleFormDTO); + } + + @Override + public Result>> getStaffsInRoleOfOrgs(StaffRoleFormDTO staffRoleFormDTO) { + return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "getStaffsInRoleOfOrgs", staffRoleFormDTO); + } +} diff --git a/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/feign/fallback/GovOrgFeignClientFallBack.java b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/feign/fallback/GovOrgFeignClientFallBack.java new file mode 100644 index 0000000000..b24bc5a7f1 --- /dev/null +++ b/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> getCustomerRootAgencyBatch(List customerIds) { + return ModuleUtils.feignConError(ServiceConstant.GOV_ORG_SERVER, "getCustomerRootAgencyBatch", customerIds); + } +} diff --git a/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/impl/CustomerServiceImpl.java b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/impl/CustomerServiceImpl.java index 89bab2936a..708deb0894 100644 --- a/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/impl/CustomerServiceImpl.java +++ b/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.utils.Result; import com.epmet.dao.CustomerDao; +import com.epmet.dto.CustomerAgencyDTO; import com.epmet.dto.CustomerDTO; 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.entity.CustomerEntity; +import com.epmet.feign.EpmetUserFeignClient; +import com.epmet.feign.GovOrgFeignClient; import com.epmet.redis.CustomerRedis; import com.epmet.service.CustomerService; import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; -import java.util.Arrays; -import java.util.List; -import java.util.Map; +import java.util.*; +import java.util.stream.Collectors; /** * 客户表 @@ -49,9 +56,17 @@ import java.util.Map; @Service public class CustomerServiceImpl extends BaseServiceImpl implements CustomerService { + private static final Logger log = LoggerFactory.getLogger(CustomerServiceImpl.class); + @Autowired private CustomerRedis customerRedis; + @Autowired + private EpmetUserFeignClient epmetUserFeignClient; + + @Autowired + private GovOrgFeignClient govOrgFeignClient; + @Override public PageData page(Map params) { IPage page = baseDao.selectPage( @@ -113,7 +128,47 @@ public class CustomerServiceImpl extends BaseServiceImpl> getValidCustomerList() { - return new Result>().ok(baseDao.selectListValidCustomerResultDTO()); + List validCustomers = baseDao.selectListValidCustomerResultDTO(); + List customerIds = validCustomers.stream().map(customer -> customer.getCustomerId()).collect(Collectors.toList()); + Result> rootAgencyResult = govOrgFeignClient.getCustomerRootAgencyBatch(customerIds); + + // 1.查询客户的根级组织,批量查询 + ArrayList rootAgencyIds = new ArrayList<>(); + if (rootAgencyResult.success()) { + Map 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>> managersResult = epmetUserFeignClient.getStaffsInRoleOfOrgs(staffRoleFormDTO); + if (managersResult.success()) { + Map> rootAgencyManagerMap = managersResult.getData(); + validCustomers.stream().forEach(customer -> { + List 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>().ok(validCustomers); } /** diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/StaffRoleFormDTO.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/StaffRoleFormDTO.java index 02ffc22867..8b919d6a46 100644 --- a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/StaffRoleFormDTO.java +++ b/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 javax.validation.constraints.NotBlank; +import java.util.List; @Data public class StaffRoleFormDTO { @@ -15,6 +16,9 @@ public class StaffRoleFormDTO { // 查询某角色下的人员列表group public interface GetStaffsInRole {} + // 一次性查询多个机构下,指定角色的用户列表 + public interface GetStaffsInRoleOrOrgs {} + /**===========校验分组结束============*/ @NotBlank(message = "工作人员ID不能为空", groups = {GetRolesOfStaff.class}) @@ -29,6 +33,11 @@ public class StaffRoleFormDTO { /** * 角色key */ - @NotBlank(message = "角色Key不能为空", groups = {GetStaffsInRole.class}) + @NotBlank(message = "角色Key不能为空", groups = {GetStaffsInRole.class, GetStaffsInRoleOrOrgs.class}) private String roleKey; + + /** + * 组织ID列表 + */ + private List orgIds; } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/StaffRoleController.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/StaffRoleController.java index 54dd2f09f7..209e8fd251 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/StaffRoleController.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/StaffRoleController.java @@ -1,5 +1,6 @@ package com.epmet.controller; +import cn.hutool.core.collection.CollectionUtil; import com.epmet.commons.mybatis.entity.DataScope; import com.epmet.commons.tools.utils.Result; 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 java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * @return 工作人员相关api @@ -74,6 +77,25 @@ public class StaffRoleController { return new Result>().ok(staffRoleDTOS); } + /** + * 一次性查询多个机构下,指定角色的用户列表 + * @param staffRoleFormDTO + * @return + */ + @PostMapping("staffsinroleoforgs") + public Result>> getStaffsInRoleOfOrgs(@RequestBody StaffRoleFormDTO staffRoleFormDTO) { + HashMap> resultMap = new HashMap<>(); + ValidatorUtils.validateEntity(staffRoleFormDTO, StaffRoleFormDTO.GetStaffsInRoleOrOrgs.class); + List orgIds = staffRoleFormDTO.getOrgIds(); + if (!CollectionUtil.isEmpty(orgIds)) { + for (String orgId : orgIds) { + List staffRole = staffRoleService.listStaffsInRole(staffRoleFormDTO.getRoleKey(), orgId, DataScope.getDefault()); + resultMap.put(orgId, staffRole); + } + } + return new Result>>().ok(resultMap); + } + /** * @return Result * @Description 查询一个员工在指定客户下的角色