From 64c9ea149b37bf6a68393ff0740a1b7e72761e76 Mon Sep 17 00:00:00 2001 From: PoffyZhang <99775271@qq.com> Date: Mon, 10 Jul 2023 15:49:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9F=A5=E7=9C=8B=E5=A4=B4=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pmapi/user/manage/UserInfoManage.java | 21 ++++++++++- .../java/com/ningdatech/pmapi/irs/IrsTest.java | 44 ++++++++++++++++++++++ pmapi/src/test/resources/application.yml | 2 +- 3 files changed, 65 insertions(+), 2 deletions(-) diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/manage/UserInfoManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/manage/UserInfoManage.java index 2d4b1a9..611dcc6 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/user/manage/UserInfoManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/user/manage/UserInfoManage.java @@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ningdatech.basic.exception.BizException; +import com.ningdatech.basic.model.GenericResult; import com.ningdatech.basic.model.PageVo; import com.ningdatech.pmapi.common.constant.RegionConst; import com.ningdatech.pmapi.common.helper.RegionCacheHelper; @@ -31,6 +32,8 @@ import com.ningdatech.pmapi.user.model.vo.UserRoleVO; import com.ningdatech.pmapi.user.security.auth.model.UserFullInfoDTO; import com.ningdatech.pmapi.user.service.IUserInfoService; import com.ningdatech.pmapi.user.util.LoginUserUtil; +import com.ningdatech.zwdd.ZwddIntegrationProperties; +import com.ningdatech.zwdd.client.ZwddClient; import com.wflow.workflow.bean.dto.ProcessInstanceUserDto; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; @@ -57,6 +60,10 @@ public class UserInfoManage { private final UserInfoHelper userInfoHelper; private final RegionCacheHelper regionCacheHelper; + private final ZwddIntegrationProperties zwddIntegrationProperties; + + private final ZwddClient zwddClient; + public PageVo list(ReqUserInfoListPO req) { PageVo pageVo = new PageVo<>(); @@ -409,7 +416,7 @@ public class UserInfoManage { resUserDetailVO.setPhoneNo(userInfo.getMobile()); resUserDetailVO.setStatus(userInfo.getAvailable()); resUserDetailVO.setEmployeeCode(userInfo.getEmployeeCode()); - resUserDetailVO.setAvatar(userInfo.getAvatar()); + resUserDetailVO.setAvatar(makeAvatar(userInfo.getAvatar())); // 装配用户角色信息列表 List userRoleList = iUserRoleService.list(Wrappers.lambdaQuery(UserRole.class) @@ -440,6 +447,18 @@ public class UserInfoManage { return resUserDetailVO; } + //生成头像 链接 + private String makeAvatar(String avatar) { + try{ + GenericResult accessToken = zwddClient.getAccessToken(); + String token = accessToken.getData(); + String res = "https://" + zwddIntegrationProperties.getDomain() + "/media/download?" + + "access_token=" + token + "&media_id=" + avatar; + return res; + }catch (Exception e){} + return org.apache.commons.lang3.StringUtils.EMPTY; + } + public Map getUserMapByIds(Set staterUsers) { List userInfos = iUserInfoService.listByIds(staterUsers); return userInfos.stream().map(u -> { diff --git a/pmapi/src/test/java/com/ningdatech/pmapi/irs/IrsTest.java b/pmapi/src/test/java/com/ningdatech/pmapi/irs/IrsTest.java index f778df2..863e758 100644 --- a/pmapi/src/test/java/com/ningdatech/pmapi/irs/IrsTest.java +++ b/pmapi/src/test/java/com/ningdatech/pmapi/irs/IrsTest.java @@ -136,6 +136,50 @@ public class IrsTest extends AppTests { } } + @Test + public void test5(){ + CloseableHttpResponse response = null; + try { + String api = "/media/download"; + GetClient getClient = getZwddExecutableClient().newGetClient(api); + //设置参数 + getClient.addParameter("access_token", zwddClient.getAccessToken().getData()); + getClient.addParameter("media_id", "$hQHNxoECo2pwZwMGDAEN2gAsOEkvNENaMmZ5UUVncDduWERralJxRW5aem45ODN5UHpKRjErcUxFeUkvTT0"); + //调用API + //String result = getClient.get(); + //System.err.println(result); + response = getClient.getB(); + org.apache.http.HttpEntity entity = response.getEntity(); + InputStream is = entity.getContent(); + System.out.println(is); + File voice = new File("C:\\Users\\PoffyZhang\\Desktop\\log1.jpg"); + OutputStream fos = new FileOutputStream(voice); + int cache = 10 * 1024; + byte[] buffer = new byte[cache]; + int ch = 0; + StringBuffer sb = new StringBuffer(); + while ((ch = is.read(buffer)) != -1) { + fos.write(buffer, 0, ch); + sb.append(buffer); + } + System.out.println(sb.toString()); + is.close(); + fos.flush(); + fos.close(); + } catch (Exception e) { + System.out.println(e); + }finally { + if (response != null) { + try { + //特别提醒:需要调用response的close方法关闭网络连接!!! + response.close(); + } catch (Exception e) { + System.out.println(e); + } + } + } + } + private static ExecutableClient zwddExecutableClient; @Autowired private ZwddIntegrationProperties zwddProperties; diff --git a/pmapi/src/test/resources/application.yml b/pmapi/src/test/resources/application.yml index 9f96606..3d7808a 100644 --- a/pmapi/src/test/resources/application.yml +++ b/pmapi/src/test/resources/application.yml @@ -1,3 +1,3 @@ spring: profiles: - active: prod + active: dev