时间格式转换
增加注解 @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
1.在同一DTO中某list里是一个对象,不用新建文件定义子DTO的方法
@ApiModelProperty(value="配置列表") private ArrayList<proList> setPro; @JsonIgnoreProperties(ignoreUnknown = true) @Data public static class proList implements Serializable { private Integer memberCouponTx; private Integer leaderCouponId; private Integer memberCouponId; }
2.流处理例子
@Override public ImportVO importBatchShop(List<JSONObject> batchList,Integer zoneId) throws IOException { ImportVO importVO = new ImportVO(); importVO.setFailNum(0); importVO.setSuccessNum(0); if (batchList.size()==0) { throw new ServerException("数据不能为空"); } //获取原记录 List<ImsYiduZoneShop> originList = this.lambdaQuery().eq(ImsYiduZoneShop::getZoneId,zoneId).ge(ImsYiduZoneShop::getStatus,0).list(); //收集原记录ADMINID Set<Integer> collect = originList.stream().map(ImsYiduZoneShop::getAdminId).collect(Collectors.toSet()); Set<Integer> adminIdS = new HashSet<>(); batchList.forEach(item->{ ImsYiduZoneShop imsYiduZoneShop = JSONObject.parseObject(JSONObject.toJSONString(item), ImsYiduZoneShop.class); adminIdS.add(imsYiduZoneShop.getAdminId()); }); //获取所有商户信息 List<ImsYiduAdmin> admins = adminService.listByIds(adminIdS); List<ImsYiduBusAbout> busAbouts = busAboutService.findByAdminIds(adminIdS); Map<Integer, ImsYiduBusAbout> imsYiduBusAboutMap = busAbouts.stream().collect(Collectors .toMap(ImsYiduBusAbout::getAdminId, Function.identity())); Map<Integer, ImsYiduAdmin> integerImsYiduAdminMap = admins.stream().collect(Collectors.toMap(ImsYiduAdmin::getId, Function.identity())); List<ImsYiduZoneShop> list = new ArrayList<>(); batchList.stream().forEach(item->{ ImsYiduZoneShop imsYiduZoneShop = JSONObject.parseObject(JSONObject.toJSONString(item), ImsYiduZoneShop.class); Assert.notEmpty(imsYiduZoneShop.getSort().toString(), "排序填写不完整"); Assert.notEmpty(imsYiduZoneShop.getAdminId().toString(), "商家ID填写不完整"); imsYiduZoneShop.setCreateTime(new Date()); ImsYiduBusAbout imsYiduBusAbout = imsYiduBusAboutMap.get(imsYiduZoneShop.getAdminId()); ImsYiduAdmin imsYiduAdmin = integerImsYiduAdminMap.get(imsYiduZoneShop.getAdminId()); if(null!=imsYiduBusAbout && null!=imsYiduAdmin){ imsYiduZoneShop.setZoneId(zoneId); imsYiduZoneShop.setShopId(imsYiduBusAbout.getId()); imsYiduZoneShop.setShopName(imsYiduBusAbout.getName()); imsYiduZoneShop.setAdminName(imsYiduAdmin.getAdminName()); imsYiduZoneShop.setAdminPhone(imsYiduAdmin.getAccount()); //如果数据库里没有有增加 if(CollectionUtil.isEmpty(collect)){ list.add(imsYiduZoneShop); return; } if(!collect.contains(imsYiduZoneShop.getAdminId())){ list.add(imsYiduZoneShop); } } }); this.saveBatch(list); importVO.setSuccessNum(list.size()); importVO.setFailNum(batchList.size()-list.size()); return importVO; }
3.获取用户IP
class IpUtils { public static String getIpAddr(HttpServletRequest request) { String ip = request.getHeader("X-Forwarded-For"); if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("Proxy-Client-IP"); } if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("WL-Proxy-Client-IP"); } if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("HTTP_CLIENT_IP"); } if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("HTTP_X_FORWARDED_FOR"); } if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getRemoteAddr(); } return ip; } }