feat:(REQ-2186) 角色查询接口增加角色的用户信息返回

This commit is contained in:
lilong 2024-05-06 14:27:27 +08:00
parent bfa2cb9f4d
commit 007e84a31c
15 changed files with 329 additions and 20 deletions

View File

@ -26,5 +26,12 @@
<groupId>cn.axzo.basics</groupId>
<artifactId>basics-common</artifactId>
</dependency>
<dependency>
<groupId>cn.axzo.foundation</groupId>
<artifactId>dao-support-lib</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

View File

@ -66,4 +66,9 @@ public class ListRoleReq {
* 是否需要角色对应的角色分组信息
*/
private Boolean needRoleGroup;
/**
* 是否需要角色对应的用户信息
*/
private Boolean needRoleUser;
}

View File

@ -1,5 +1,6 @@
package cn.axzo.tyr.client.model.res;
import cn.axzo.tyr.client.model.roleuser.dto.SaasRoleUserV2DTO;
import cn.axzo.tyr.client.model.vo.SaasPermissionGroupVO;
import lombok.AllArgsConstructor;
import lombok.Builder;
@ -107,4 +108,26 @@ public class SaasRoleRes {
* 角色权限
*/
private List<SaasPermissionRes> saasPermissions;
/**
* 角色对应的人员信息
*/
private List<SaasRoleUserV2DTO.SaasRoleUser> saasRoleUsers;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class SaasRoleUser {
/**
* 用户id
*/
private Long personId;
/**
* 用户名字
*/
private String realName;
}
}

View File

@ -0,0 +1,37 @@
package cn.axzo.tyr.client.model.roleuser.dto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class SaasRoleUserV2DTO {
/**
* 角色Id
*/
private Long roleId;
private SaasRoleUser saasRoleUser;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class SaasRoleUser {
/**
* 用户id
*/
private Long personId;
/**
* 用户名字
*/
private String realName;
}
}

View File

@ -0,0 +1,23 @@
package cn.axzo.tyr.client.model.roleuser.req;
import cn.axzo.foundation.dao.support.wrapper.CriteriaField;
import cn.axzo.foundation.dao.support.wrapper.Operator;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import java.util.List;
@SuperBuilder
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ListRoleUserRelationParam {
@CriteriaField(field = "roleId", operator = Operator.IN)
private List<Long> roleIds;
@CriteriaField(ignore = true)
private Boolean needUsers;
}

View File

@ -0,0 +1,29 @@
package cn.axzo.tyr.client.model.roleuser.req;
import cn.axzo.foundation.dao.support.wrapper.CriteriaField;
import cn.axzo.foundation.page.IPageReq;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import java.util.List;
@SuperBuilder
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PageRoleUserRelationParam extends ListRoleUserRelationParam implements IPageReq {
@CriteriaField(ignore = true)
Integer page;
@CriteriaField(ignore = true)
Integer pageSize;
/**
* 排序使用示例createTime__DESC
*/
@CriteriaField(ignore = true)
List<String> sort;
}

View File

@ -102,8 +102,9 @@
</dependency>
<dependency>
<groupId>cn.axzo.pokonyan</groupId>
<artifactId>pokonyan</artifactId>
<groupId>cn.axzo.foundation</groupId>
<artifactId>dao-support-lib</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
@ -121,6 +122,10 @@
<type>pom</type>
</dependency>
<dependency>
<groupId>cn.axzo.basics</groupId>
<artifactId>basics-profiles-api</artifactId>
</dependency>
</dependencies>
<build>
<plugins>

View File

@ -35,7 +35,8 @@ public class FeignConfig implements RequestInterceptor, EnvironmentAware {
@Value("${maokaiEnvUrl:http://dev-app.axzo.cn/maokai}")
private String maokaiEnvUrl;
@Value("${pudgeEnvUrl:http://dev-app.axzo.cn/pudge}")
private String pudgeEnvUrl;
private static String POD_NAMESPACE;
static {
@ -57,6 +58,7 @@ public class FeignConfig implements RequestInterceptor, EnvironmentAware {
url = url.replace("http://workflow-engine:8080", workflowEnvUrl);
url = url.replace("http://thrones", thronesEnvUrl);
url = url.replace("http://maokai:8080", maokaiEnvUrl);
url = url.replace("http://pudge:10099", pudgeEnvUrl);
String profile = environment.getProperty("spring.profiles.active");
if(Objects.equals(profile, "test") && url.contains("dev-app.axzo.cn")) {
url = url.replace("dev-app", "test-api");

View File

@ -18,7 +18,8 @@ import static cn.axzo.tyr.server.config.GlobalConfig.FeignClientConstant.*;
@Configuration
@EnableFeignClients(basePackages = {
WORKFLOW_ENGINE,
INNER_FEIGN
INNER_FEIGN,
"cn.axzo"
})
public class GlobalConfig {
/**

View File

@ -43,7 +43,6 @@ import cn.axzo.tyr.server.service.RoleService;
import cn.axzo.tyr.server.service.SaasCommonDictService;
import cn.axzo.tyr.server.service.SaasRoleGroupRelationService;
import cn.axzo.tyr.server.service.SaasRoleGroupService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import lombok.RequiredArgsConstructor;
@ -294,8 +293,8 @@ public class SaasRoleController implements TyrSaasRoleApi {
public ApiPageResult<SaasRoleRes> page(PageRoleReq request) {
RoleService.PageSaasRoleParam param = RoleService.PageSaasRoleParam.builder().build();
BeanUtils.copyProperties(request, param);
Page<SaasRoleRes> page = roleService.page(param);
return ApiPageResult.ok(page.getRecords(), page.getTotal(), (int) page.getCurrent(), (int) page.getSize());
cn.axzo.foundation.page.PageResp<SaasRoleRes> page = roleService.page(param);
return ApiPageResult.ok(page.getData(), page.getTotal(), (int) page.getCurrent(), (int) page.getSize());
}
@Override

View File

@ -1,9 +1,9 @@
package cn.axzo.tyr.server.service;
import cn.axzo.foundation.dao.support.wrapper.CriteriaField;
import cn.axzo.foundation.dao.support.wrapper.Operator;
import cn.axzo.foundation.page.IPageReq;
import cn.axzo.framework.domain.page.PageResp;
import cn.axzo.pokonyan.dao.page.IPageParam;
import cn.axzo.pokonyan.dao.wrapper.CriteriaField;
import cn.axzo.pokonyan.dao.wrapper.Operator;
import cn.axzo.tyr.client.model.enums.IdentityType;
import cn.axzo.tyr.client.model.req.ChangeGroupLeaderRoleReq;
import cn.axzo.tyr.client.model.req.FeatureRoleRelationReq;
@ -120,7 +120,7 @@ public interface RoleService extends IService<SaasRole> {
List<SaasRoleRes> list(ListSaasRoleParam param);
Page<SaasRoleRes> page(PageSaasRoleParam param);
cn.axzo.foundation.page.PageResp<SaasRoleRes> page(PageSaasRoleParam param);
void saveOrUpdateFeatureRoleRelation(List<FeatureRoleRelationReq.RelationRoleSettings> req, Long operatorId);
@ -164,13 +164,16 @@ public interface RoleService extends IService<SaasRole> {
@CriteriaField(ignore = true)
private Boolean needRoleGroup;
@CriteriaField(ignore = true)
private Boolean needRoleUser;
}
@SuperBuilder
@Data
@NoArgsConstructor
@AllArgsConstructor
class PageSaasRoleParam extends ListSaasRoleParam implements IPageParam {
class PageSaasRoleParam extends ListSaasRoleParam implements IPageReq {
@CriteriaField(ignore = true)
Integer page;

View File

@ -2,7 +2,14 @@ package cn.axzo.tyr.server.service;
import cn.axzo.framework.domain.page.PageResp;
import cn.axzo.tyr.client.model.roleuser.dto.SaasRoleUserDTO;
import cn.axzo.tyr.client.model.roleuser.dto.SaasRoleUserV2DTO;
import cn.axzo.tyr.client.model.roleuser.req.ListRoleUserRelationParam;
import cn.axzo.tyr.client.model.roleuser.req.PageRoleUserRelationParam;
import cn.axzo.tyr.client.model.roleuser.req.RoleUserParam;
import cn.axzo.tyr.server.repository.entity.SaasRole;
import cn.axzo.tyr.server.repository.entity.SaasRoleUserRelation;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
@ -10,8 +17,12 @@ import java.util.List;
* @author haiyangjin
* @date 2023/9/14
*/
public interface SaasRoleUserRelationService {
public interface SaasRoleUserRelationService extends IService<SaasRoleUserRelation> {
List<SaasRoleUserDTO> list(RoleUserParam param);
PageResp<SaasRoleUserDTO> pageQuery(RoleUserParam param);
List<SaasRoleUserV2DTO> listV2(ListRoleUserRelationParam param);
cn.axzo.foundation.page.PageResp<SaasRoleUserV2DTO> page(PageRoleUserRelationParam param);
}

View File

@ -2,10 +2,10 @@ package cn.axzo.tyr.server.service.impl;
import cn.axzo.basics.common.constant.enums.TableIsDeleteEnum;
import cn.axzo.basics.common.exception.ServiceException;
import cn.axzo.foundation.dao.support.converter.PageConverter;
import cn.axzo.foundation.dao.support.mysql.QueryWrapperHelper;
import cn.axzo.framework.domain.page.PageResp;
import cn.axzo.pokonyan.config.mybatisplus.BaseEntity;
import cn.axzo.pokonyan.dao.converter.PageConverter;
import cn.axzo.pokonyan.dao.mysql.QueryWrapperHelper;
import cn.axzo.tyr.client.common.enums.RoleResourceTypeEnum;
import cn.axzo.tyr.client.common.enums.RoleTypeEnum;
import cn.axzo.tyr.client.model.enums.IdentityType;
@ -27,6 +27,8 @@ import cn.axzo.tyr.client.model.res.RoleWithUserRes;
import cn.axzo.tyr.client.model.res.SaasPermissionRes;
import cn.axzo.tyr.client.model.res.SaasRoleGroupRes;
import cn.axzo.tyr.client.model.res.SaasRoleRes;
import cn.axzo.tyr.client.model.roleuser.dto.SaasRoleUserV2DTO;
import cn.axzo.tyr.client.model.roleuser.req.ListRoleUserRelationParam;
import cn.axzo.tyr.client.model.vo.DeleteRoleVO;
import cn.axzo.tyr.client.model.vo.SaasPermissionGroupVO;
import cn.axzo.tyr.client.model.vo.SaasRoleAndGroupVO;
@ -64,14 +66,17 @@ import cn.axzo.tyr.server.service.SaasFeatureResourceService;
import cn.axzo.tyr.server.service.SaasPgroupPermissionRelationService;
import cn.axzo.tyr.server.service.SaasRoleGroupRelationService;
import cn.axzo.tyr.server.service.SaasRoleGroupService;
import cn.axzo.tyr.server.service.SaasRoleUserRelationService;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.lang.Pair;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
@ -154,6 +159,9 @@ public class RoleServiceImpl extends ServiceImpl<SaasRoleMapper, SaasRole>
SaasRoleGroupRelationDao saasRoleGroupRelationDao;
@Autowired
SaasFeatureResourceService saasFeatureResourceService;
@Autowired
private SaasRoleUserRelationService saasRoleUserRelationService;
@Value("${groupLeader.code:projectTeamGPLeader}")
private String groupLeaderCode;
@ -1164,28 +1172,33 @@ public class RoleServiceImpl extends ServiceImpl<SaasRoleMapper, SaasRole>
}
@Override
public Page<SaasRoleRes> page(PageSaasRoleParam param) {
public cn.axzo.foundation.page.PageResp<SaasRoleRes> page(PageSaasRoleParam param) {
QueryWrapper<SaasRole> wrapper = QueryWrapperHelper.fromBean(param, SaasRole.class);
wrapper.eq("is_delete", 0);
Page<SaasRole> page = this.page(PageConverter.convertToMybatis(param, SaasRole.class), wrapper);
IPage<SaasRole> page = this.page(PageConverter.toMybatis(param, SaasRole.class), wrapper);
Map<Long, List<SaasRoleGroupRes>> saasRoleGroups = listRoleGroups(param, page.getRecords());
Map<Long, List<SaasPermissionRes>> saasPermissions = listRolePermissions(param, page.getRecords());
Map<Long, List<SaasRoleUserV2DTO.SaasRoleUser>> saasRoleUsers = listSaasRoleUser(param, page.getRecords());
return PageConverter.convert(page, (record) -> from(record,
saasRoleGroups,
saasPermissions));
saasPermissions,
saasRoleUsers));
}
private SaasRoleRes from(SaasRole saasRole,
Map<Long, List<SaasRoleGroupRes>> saasRoleGroups,
Map<Long, List<SaasPermissionRes>> saasPermissions) {
Map<Long, List<SaasPermissionRes>> saasPermissions,
Map<Long, List<SaasRoleUserV2DTO.SaasRoleUser>> saasRoleUsers) {
SaasRoleRes saasRoleRes = SaasRoleRes.builder().build();
BeanUtils.copyProperties(saasRole, saasRoleRes);
saasRoleRes.setSaasRoleGroups(saasRoleGroups.get(saasRoleRes.getId()));
saasRoleRes.setSaasPermissions(saasPermissions.get(saasRoleRes.getId()));
saasRoleRes.setSaasRoleUsers(saasRoleUsers.get(saasRoleRes.getId()));
return saasRoleRes;
}
@ -1378,4 +1391,23 @@ public class RoleServiceImpl extends ServiceImpl<SaasRoleMapper, SaasRole>
throw new ServiceException(String.format("权限点 %s 信息错误", permissionIds));
}
}
private Map<Long, List<SaasRoleUserV2DTO.SaasRoleUser>> listSaasRoleUser(PageSaasRoleParam param,
List<SaasRole> saasRoles) {
if (CollectionUtils.isEmpty(saasRoles) || BooleanUtils.isNotTrue(param.getNeedRoleUser())) {
return Collections.emptyMap();
}
List<Long> roleIds = Lists.transform(saasRoles, SaasRole::getId);
ListRoleUserRelationParam listRoleUserRelationParam = ListRoleUserRelationParam.builder()
.roleIds(roleIds)
.needUsers(param.getNeedRoleUser())
.build();
List<SaasRoleUserV2DTO> saasRoleUserV2DTOS = saasRoleUserRelationService.listV2(listRoleUserRelationParam);
return saasRoleUserV2DTOS.stream()
.map(e -> Pair.of(e.getRoleId(), e.getSaasRoleUser()))
.collect(Collectors.groupingBy(Pair::getKey, Collectors.mapping(Pair::getValue, Collectors.toList())));
}
}

View File

@ -2,24 +2,41 @@ package cn.axzo.tyr.server.service.impl;
import cn.axzo.basics.common.BeanMapper;
import cn.axzo.basics.common.constant.enums.TableIsDeleteEnum;
import cn.axzo.basics.profiles.api.UserProfileServiceApi;
import cn.axzo.basics.profiles.dto.basic.PersonProfileDto;
import cn.axzo.foundation.dao.support.converter.PageConverter;
import cn.axzo.foundation.dao.support.mysql.QueryWrapperHelper;
import cn.axzo.framework.domain.page.PageResp;
import cn.axzo.pokonyan.config.mybatisplus.BaseEntity;
import cn.axzo.tyr.client.common.enums.RoleTypeEnum;
import cn.axzo.tyr.client.model.roleuser.dto.SaasRoleUserDTO;
import cn.axzo.tyr.client.model.roleuser.dto.SaasRoleUserV2DTO;
import cn.axzo.tyr.client.model.roleuser.req.ListRoleUserRelationParam;
import cn.axzo.tyr.client.model.roleuser.req.PageRoleUserRelationParam;
import cn.axzo.tyr.client.model.roleuser.req.RoleUserParam;
import cn.axzo.tyr.server.repository.dao.SaasRoleDao;
import cn.axzo.tyr.server.repository.dao.SaasRoleUserRelationDao;
import cn.axzo.tyr.server.repository.entity.SaasRole;
import cn.axzo.tyr.server.repository.entity.SaasRoleUserRelation;
import cn.axzo.tyr.server.repository.mapper.SaasRoleUserRelationMapper;
import cn.axzo.tyr.server.service.SaasRoleUserRelationService;
import cn.axzo.tyr.server.util.RpcInternalUtil;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.BooleanUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@ -33,7 +50,8 @@ import java.util.stream.Collectors;
*/
@Slf4j
@Service
public class SaasRoleUserRelationServiceImpl implements SaasRoleUserRelationService {
public class SaasRoleUserRelationServiceImpl extends ServiceImpl<SaasRoleUserRelationMapper, SaasRoleUserRelation>
implements SaasRoleUserRelationService {
@Resource
private SaasRoleUserRelationDao saasRoleUserRelationDao;
@ -41,6 +59,9 @@ public class SaasRoleUserRelationServiceImpl implements SaasRoleUserRelationServ
@Resource
private SaasRoleDao saasRoleDao;
@Autowired
private UserProfileServiceApi userProfileServiceApi;
@Override
public List<SaasRoleUserDTO> list(RoleUserParam param) {
// TODO jhy 角色查询 需要验证标准角色和自定义角色的查询逻辑
@ -99,4 +120,73 @@ public class SaasRoleUserRelationServiceImpl implements SaasRoleUserRelationServ
.collect(Collectors.toList());
return PageResp.list(param.getPage(), param.getPageSize(), page.getTotal(), list);
}
@Override
public List<SaasRoleUserV2DTO> listV2(ListRoleUserRelationParam param) {
return PageConverter.drainAll(pageNumber -> {
PageRoleUserRelationParam pageParam = PageRoleUserRelationParam.builder().build();
BeanUtils.copyProperties(param, pageParam);
pageParam.setPage(pageNumber);
pageParam.setPageSize(500);
return page(pageParam);
});
}
@Override
public cn.axzo.foundation.page.PageResp<SaasRoleUserV2DTO> page(PageRoleUserRelationParam param) {
QueryWrapper<SaasRoleUserRelation> wrapper = QueryWrapperHelper.fromBean(param, SaasRoleUserRelation.class);
wrapper.eq("is_delete", 0);
IPage<SaasRoleUserRelation> page = this.page(PageConverter.toMybatis(param, SaasRoleUserRelation.class), wrapper);
Map<Long, SaasRoleUserV2DTO.SaasRoleUser> saasRoleUsers = listSaasRoleUser(param, page.getRecords());
return PageConverter.convert(page, (record) -> from(record, saasRoleUsers));
}
private Map<Long, SaasRoleUserV2DTO.SaasRoleUser> listSaasRoleUser(PageRoleUserRelationParam param,
List<SaasRoleUserRelation> saasRoleUserRelations) {
if (CollectionUtils.isEmpty(saasRoleUserRelations) || BooleanUtils.isNotTrue(param.getNeedUsers())) {
return Collections.emptyMap();
}
List<Long> personIds = saasRoleUserRelations.stream()
.map(SaasRoleUserRelation::getNaturalPersonId)
.distinct()
.collect(Collectors.toList());
if (CollectionUtils.isEmpty(personIds)) {
return Collections.emptyMap();
}
List<List<Long>> partition = Lists.partition(personIds, 1000);
// 返回字段太多所以截取部分字段返回后续需要新增的手动增加
return partition.stream()
.map(e -> RpcInternalUtil.rpcListProcessor(() -> userProfileServiceApi.postPersonProfiles(e), "查询用户信息", e).getData())
.filter(Objects::nonNull)
.flatMap(Collection::stream)
.collect(Collectors.toMap(PersonProfileDto::getId, this::from, (f, s) -> f));
}
private SaasRoleUserV2DTO.SaasRoleUser from(PersonProfileDto personProfileDto) {
if (personProfileDto == null) {
return null;
}
return SaasRoleUserV2DTO.SaasRoleUser.builder()
.personId(personProfileDto.getId())
.realName(personProfileDto.getRealName())
.build();
}
private SaasRoleUserV2DTO from(SaasRoleUserRelation saasRoleUserRelation,
Map<Long, SaasRoleUserV2DTO.SaasRoleUser> saasRoleUsers) {
return SaasRoleUserV2DTO.builder()
.roleId(saasRoleUserRelation.getRoleId())
.saasRoleUser(saasRoleUsers.get(saasRoleUserRelation.getNaturalPersonId()))
.build();
}
}

View File

@ -3,14 +3,18 @@ package cn.axzo.tyr.server.util;
import cn.axzo.basics.common.util.AssertUtil;
import cn.axzo.framework.domain.ServiceException;
import cn.axzo.framework.domain.web.BizException;
import cn.axzo.framework.domain.web.result.ApiListResult;
import cn.axzo.framework.domain.web.result.ApiPageResult;
import cn.axzo.framework.domain.web.result.ApiResult;
import cn.azxo.framework.common.model.CommonResponse;
import cn.hutool.core.date.StopWatch;
import cn.hutool.core.lang.Assert;
import cn.hutool.http.HttpStatus;
import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.function.Supplier;
@ -100,5 +104,43 @@ public class RpcInternalUtil {
return data;
}
/**
* 常用的RPC请求返回值解析如果 被请求方 返回非200会抛出异常
*/
public static <T> CommonResponse<List<T>> rpcListProcessor(Supplier<CommonResponse<List<T>>> supplier, String operationType, Object... param) {
return rpcListProcessorMayThrow(supplier, operationType, (msg) -> {
throw new ServiceException(msg);
}, param);
}
public static <T> CommonResponse<List<T>> rpcListProcessorMayThrow(Supplier<CommonResponse<List<T>>> supplier, String operationType, Consumer<String> throwConsumer, Object... param) {
AssertUtil.notNull(throwConsumer, "自定义的异常处理不可为空");
log.info(operationType + "-Param: " + JSONUtil.toJsonStr(param));
CommonResponse<List<T>> result = null;
try {
result = printLatency(supplier, operationType);
} catch (Throwable e) {
log.warn("rpc process error:{}", e.getMessage());
throwConsumer.accept("服务调用异常");
}
log.info(operationType + "-Result: " + JSONUtil.toJsonStr(result));
Assert.notNull(result, "服务调用异常");
// 200自定义处理
if (HttpStatus.HTTP_OK != result.getCode()) {
throwConsumer.accept(result.getMsg());
}
return result;
}
public static <R> R printLatency(Supplier<R> function, String optType) {
StopWatch stopWatch = new StopWatch(optType);
stopWatch.start(optType);
R r = function.get();
stopWatch.stop();
log.info(stopWatch.shortSummary(TimeUnit.MILLISECONDS));
return r;
}
}