用狐狸做logo的网站,企业网站建设的可行性,建工网校官网登录入口,网站如何进行代码优化大家好#xff0c;我是雄雄#xff0c;欢迎关注微信公众号#xff1a;雄雄的小课堂 现在是#xff1a;2022年7月7日13:46:07
前言
今天有个这样的需求#xff0c;PC端需要查看一下哪些天有数据#xff0c;但是哪些有有没有数据我这边还看不出来#xff0c;得请求别的系… 大家好我是雄雄欢迎关注微信公众号雄雄的小课堂 现在是2022年7月7日13:46:07
前言
今天有个这样的需求PC端需要查看一下哪些天有数据但是哪些有有没有数据我这边还看不出来得请求别的系统的接口去看。且团组和会员请求的接口和请求方式均不一样。 前端说为了方便团组和个人都走一个接口吧让我这边封装一下……
实现
如何区分前台请求的是会员的还是团组的
让前台这样传如果不传groupId,传memberId则我就知道了请求的是查询会员的信息。反之则请求的是团组的接口。 代码如下 if(Strings.isNotBlank(groupId)){//是团组//查询这个团组下面的人LambdaQueryWrapperGroupUser groupUserLambdaQueryWrapper new LambdaQueryWrapper();groupUserLambdaQueryWrapper.eq(GroupUser::getGroupId, groupId);ListGroupUser groupUserList groupUserService.list(groupUserLambdaQueryWrapper);ListLong userList new ArrayList();groupUserList.forEach(group-{userList.add(group.getUserId());});//集合去重ListLong memberIdList userList.stream().distinct().collect(Collectors.toList());url ServicePathConstant.HBV_GATAWAY/doctor/api/doctor/getMemberDataDays;body HttpUtil.createPost(url).contentType(application/json).body(JSON.toJSONString(memberIdList)).execute().body();}else if(Strings.isNotBlank(memberId)){//是会员url ServicePathConstant.HBV_GATAWAY/doctor/api/doctor/getMemberDataDays/memberId;body HttpUtil.createGet(url).execute().body();}里面涉及到了些别的代码集合去重 //集合去重ListLong memberIdList userList.stream().distinct().collect(Collectors.toList());还别说这个地方用的还挺多的不过每次用到了之后都是翻之前的代码。。。。。
完整代码如下 /*** 获取有日期的报告吗返回一个集合* param groupId* return*/GetMapping(/getReportHaveDateList)public Object getReportHaveDateList(String groupId,String memberId) {cn.hutool.json.JSONObject jsonObjectResult new cn.hutool.json.JSONObject();//请求接口地址String url ;String body ;if(Strings.isNotBlank(groupId)){//是团组//查询这个团组下面的人LambdaQueryWrapperGroupUser groupUserLambdaQueryWrapper new LambdaQueryWrapper();groupUserLambdaQueryWrapper.eq(GroupUser::getGroupId, groupId);ListGroupUser groupUserList groupUserService.list(groupUserLambdaQueryWrapper);ListLong userList new ArrayList();groupUserList.forEach(group-{userList.add(group.getUserId());});//集合去重ListLong memberIdList userList.stream().distinct().collect(Collectors.toList());url ServicePathConstant.HBV_GATAWAY/doctor/api/doctor/getMemberDataDays;body HttpUtil.createPost(url).contentType(application/json).body(JSON.toJSONString(memberIdList)).execute().body();}else if(Strings.isNotBlank(memberId)){//是会员url ServicePathConstant.HBV_GATAWAY/doctor/api/doctor/getMemberDataDays/memberId;body HttpUtil.createGet(url).execute().body();}if (StringUtils.isBlank(body)) {jsonObjectResult.putOpt(code, 500);jsonObjectResult.putOpt(data, null);jsonObjectResult.putOpt(msg, 操作失败);return jsonObjectResult;}cn.hutool.json.JSONObject obj JSONUtil.parseObj(body);if (obj null) {jsonObjectResult.putOpt(code, 500);jsonObjectResult.putOpt(data, null);jsonObjectResult.putOpt(msg, 操作失败);return jsonObjectResult;}String code obj.get(code).toString();String msg obj.get(msg).toString();System.out.println(调用doctor系统返回的信息msg);if (200.equals(code)) {jsonObjectResult.putOpt(code, 200);jsonObjectResult.putOpt(data, obj.get(data));jsonObjectResult.putOpt(msg, 操作成功);//标记有没有记录jsonObjectResult.putOpt(count, obj.getJSONArray(data).size());return jsonObjectResult;}else{jsonObjectResult.putOpt(code, 200);jsonObjectResult.putOpt(data, new ArrayListString());jsonObjectResult.putOpt(msg, 操作成功);//标记有没有记录jsonObjectResult.putOpt(count, 0);return jsonObjectResult;}}顺便在记录一下糊涂工具类请求接口的几种方式吧
post方法form传参 //接口地址String url ;//请求参数MapString, Object paramMap new HashMap();map.put(groupId, 1506254142554785);//请求头HashMapString, String headers new HashMap();headers.put(Authorization, token);String result HttpUtil.createPost(url).addHeaders(headers).form(map).execute().body();
post方法json传参 //接口地址String url ;//请求参数MapString, Object paramMap new HashMap();map.put(groupId, 1506254142554785);//请求头HashMapString, String headers new HashMap();headers.put(Authorization, token);String body HttpUtil.createPost(url).contentType(application/json).body(JSON.toJSONString(projectVo)).execute().body();
projectVo就是一个json格式的数据。
get方法form传参 //接口地址String url ;//请求参数MapString, Object paramMap new HashMap();map.put(groupId, 1506254142554785);//请求头HashMapString, String headers new HashMap();headers.put(Authorization, token);String body HttpUtil.createGet(url).header(Authorization, token).form(paramMap).execute().body();
这就是今天分享的内容谢谢大家的捧场