业务场景:
1.需要根据路由表中运单id和数据状态(为 107妥投 ,117部分妥投, 108拒签 )的数据进行分组,并取出分组后数量
2.需要根据运单id 的集合去订单表及订单详情表查询对应的数据,并运单id 进行分组,并取出分组后数量
3.判断条件,如果路由表根据运单id和状态分组后的数量 == 订单详情表中的数量 ,做后续业务处理
数据库:
路由表: | billId | status |
---|---|---|
TESTXS20210517 | 117 | |
TESTXS20210517 | 117 | |
TESTXS20210517 | 107 | |
TESTXS20210517 | 108 | |
TESTXS20210519 | 117 | |
TESTXS20210519 | 108 | |
订单详情: | billId | mess |
---|---|---|
TESTXS20210517 | 1 | |
TESTXS20210517 | 1 | |
TESTXS20210517 | 0 | |
TESTXS20210517 | 0 | |
TESTXS20210519 | 0 | |
TESTXS20210519 | 1 | |
思路:
- 首先根据条件查询出所有数据
- 其次查询出符合状态的数据: 使用
stream().filter()
进行过滤拦截 - 然后对取的数据做处理: 需要根据账单1分组,在根据状态分组,最后取得不同账单的不同状态数据。
Map<账单1, Map<状态, List<数据vo>>> billMap
- 有了账单1,就可以根据账单1关联订单数据,查询出订单集合
- 所以需要获取账单1的集合,根据账单1集合查询账单1的所以订单
List<String> billList = whList.stream().map(WaybillStatusOutsideVo::getRelatedBill1).collect(Collectors.toList());
- 变更后进行了优化去重:
List<String> billList = whList.stream().map(AuxWaybillStatusOutsideVo::getRelatedBill1).collect(Collectors.toList()).stream().distinct().collect(Collectors.toList());
- 获取根据账单1获取订单数据
List<WayCallBackVo> orderList = WaybillStatusOutsideMapper.findWayBillDetailData(billList);
- 将订单数据按照账单1号 进行分组
Map<String, List<WayCallBackVo>> orderMap = orderList.stream().collect(Collectors.groupingBy(WayCallBackVo::getRelatedBill1));
- 最后在循环账单1 进行判断,订单数量及账单数量
billMap.forEach((billId, valueMap) -> {
valueMap.forEach((stutus,vos) ->{
// 如果条数相等
if (orderMap.get(billId).size() == vos.size()) {
// 业务处理
} else {
failCount.getAndIncrement();
map.put(billId, back.getMsgContent());
failNos.add(map);
}
}
});
});
代码:
try {
// 查询所有数据
List<WaybillStatusOutsideVo> list = WaybillStatusOutsideMapper.findWayBillData(SonyaConstant.COMP_CODE);
// 查询符合状态数据
List<WaybillStatusOutsideVo> whList = list.stream().filter(l -> !l.getXiaomiStatus().equals(SonyaConstant.XIAOMISTATUS)
&& (l.getOrderStatus().equals(SonyaConstant.GOP_WAY_SIGN)
|| l.getOrderStatus().equals(SonyaConstant.GOP_WAY_UNSIGN)
|| l.getOrderStatus().equals(SonyaConstant.GOP_WAY_PARTSIGN))
).collect(Collectors.toList());
// 路由分组Map
Map<String, Map<String, List<WaybillStatusOutsideVo>>> billMap = new HashMap<>();
whList.stream().collect(Collectors.groupingBy(WaybillStatusOutsideVo::getRelatedBill1)).forEach((bill1, billVos) -> {
Map<String, List<WaybillStatusOutsideVo>> result = new HashMap<>();
billVos.stream().collect(Collectors.groupingBy(WaybillStatusOutsideVo::getOrderStatus)).forEach((status, vos) ->
result.put(status, vos));
billMap.put(bill1, result);
});
// 查询所有订单信息
List<String> billList = whList.stream().map(WaybillStatusOutsideVo::getRelatedBill1).collect(Collectors.toList());
// 订单分组Map
List<WayCallBackVo> orderList = WaybillStatusOutsideMapper.findWayBillDetailData(billList);
Map<String, List<WayCallBackVo>> orderMap = orderList.stream().collect(Collectors.groupingBy(WayCallBackVo::getRelatedBill1));
billMap.forEach((billId, valueMap) -> {
valueMap.forEach((stutus,vos) ->{
// 如果条数相等
if (orderMap.get(billId).size() == vos.size()) {
// 业务处理
} else {
failCount.getAndIncrement();
map.put(billId, back.getMsgContent());
failNos.add(map);
}
}
});
});
} catch (Exception e) {
e.printStackTrace();
//业务处理
}
开发总是在变更中进行,心态很重要
业务场景
1.需要根据路由表中运单id和数据状态(为 107妥投 ,117部分妥投, 108拒签 )的数据进行分组,并取出分组后数量
2.需要根据运单id 的集合去订单表及订单详情表查询对应的数据,并运单id 进行分组,并取出分组后数量
3.判断条件,如果路由表根据运单id和状态分组后的数量 == 订单详情表中的数量 ,做后续业务处理
4.需求变更 1.妥投状态为(order_status=107+117,waybill_status = 107),拒签状态为(order_status=108,waybill_status = 108)
5.需求变更2:拒签数据可能存在一条拒签,一条未拒签情况,所以只要有一条拒签,我们就默认全部拒签
思路:
- 首先根据条件查询出所有数据
- 其次查询出符合状态的数据: 使用
stream().filter()
进行过滤拦截 - 然后对取的数据做处理: 需要根据账单1分组,在根据状态分组,最后取得不同账单的不同状态数据。
Map<账单1, Map<状态, List<数据vo>>> billMap
- 需求变更后,状态的类型不为107,117,108,而是变更为sign,unsign,为了区分妥投和拒签。
- 所以有了一个判断,如果状态为107或者117,存入sign,否则存入unsign,
- 有了账单1,就可以根据账单1关联订单数据,查询出订单集合
- 所以需要获取账单1的集合,根据账单1集合查询账单1的所以订单
List<String> billList = whList.stream().map(WaybillStatusOutsideVo::getRelatedBill1).collect(Collectors.toList());
- 变更后进行了优化去重:
List<String> billList = whList.stream().map(AuxWaybillStatusOutsideVo::getRelatedBill1).collect(Collectors.toList()).stream().distinct().collect(Collectors.toList());
- 获取根据账单1获取订单数据
List<WayCallBackVo> orderList = WaybillStatusOutsideMapper.findWayBillDetailData(billList);
- 将订单数据按照账单1号 进行分组
Map<String, List<WayCallBackVo>> orderMap = orderList.stream().collect(Collectors.groupingBy(WayCallBackVo::getRelatedBill1));
- 最后在循环账单1 进行判断,订单数量及账单数量
代码:
public void wayBillJob() {
AtomicInteger failCount = new AtomicInteger();
List<Map<String, String>> failNos = new ArrayList<>();
try {
//获取奥克斯客户账号
String accountNo = getKey();
// 查询所有数据
List<WaybillStatusOutsideVo> list = waybillStatusOutsideMapper.findWayBillData(accountNo);
if(!list.isEmpty()){
// 查询符合状态数据
List<WaybillStatusOutsideVo> whList = list.stream().filter(l -> !l.getXiaomiStatus().equals(SonyaConstant.XIAOMISTATUS)
&& (l.getOrderStatus().equals(SonyaConstant.GOP_WAY_SIGN)
|| l.getOrderStatus().equals(SonyaConstant.GOP_WAY_UNSIGN)
|| l.getOrderStatus().equals(SonyaConstant.GOP_WAY_PARTSIGN))
).collect(Collectors.toList());
if (!whList.isEmpty()){
// 路由分组Map
// 类型: 账单1-bill1,状态-status,数据-vos
Map<String, Map<String, List<WaybillStatusOutsideVo>>> billMap = new HashMap<>();
whList.stream().collect(Collectors.groupingBy(WaybillStatusOutsideVo::getRelatedBill1)).forEach((bill1, billVos) -> {
// 类型: 状态-status,数据-vos eg: 117,vos; 107 vos; 108 vos;
Map<String, List<WaybillStatusOutsideVo>> result = new HashMap<>();
billVos.stream().collect(Collectors.groupingBy(WaybillStatusOutsideVo::getOrderStatus)).forEach((status, vos) ->{
// 状态-status,sign=117+107; unsign= 108;
// 第11版需求变更,过滤数据 waybill_status = 108 拒签(order_status=108,waybill_status = 108)
if(status.equals(SonyaConstant.GOP_WAY_UNSIGN)){
if(result.get(unsign) != null ) {
List<WaybillStatusOutsideVo> un = result.get(unsign);
un.addAll(vos.stream().filter(v -> v.getWaybillStatus().equals(SonyaConstant.GOP_WAY_UNSIGN)).collect(Collectors.toList()));
result.put(unsign,un);
}else{
result.put(unsign, vos.stream().filter(v -> v.getWaybillStatus().equals(SonyaConstant.GOP_WAY_UNSIGN)).collect(Collectors.toList()));
}
}else{
if(result.get(sign) != null ) {
List<WaybillStatusOutsideVo> sn = result.get(sign);
sn.addAll(vos.stream().filter(v -> v.getWaybillStatus().equals(SonyaConstant.GOP_WAY_SIGN)).collect(Collectors.toList()));
result.put(sign,sn);
}else{
result.put(sign, vos.stream().filter(v -> v.getWaybillStatus().equals(SonyaConstant.GOP_WAY_SIGN)).collect(Collectors.toList()));
}
}});
billMap.put(bill1, result);
});
// 查询所有订单信息
List<String> billList = whList.stream().map(WaybillStatusOutsideVo::getRelatedBill1).collect(Collectors.toList()).stream().distinct().collect(Collectors.toList());
// 订单分组Map
if(!billList.isEmpty()){
List<WayCallBackVo> orderList = WaybillStatusOutsideMapper.findWayBillDetailData(billList);
if(!orderList.isEmpty()){
Map<String, List<WayCallBackVo>> orderMap = orderList.stream().collect(Collectors.groupingBy(WayCallBackVo::getRelatedBill1));
// 从redis获取token
String signature = OrderService.getToken();
billMap.forEach((billId, valueMap) -> {
valueMap.forEach((stutus,vos) ->{
// 第12版需求变更,拒签108, 可能存在多个商品,只有一条拒签记录的请况,所以如果这样,我们默认一条拒签为全部拒签
if ( !orderMap.get(billId).isEmpty() && !vos.isEmpty() ){
if(orderMap.get(billId).size() == vos.size() || stutus.equals(unsign)) {
// 判断条件 对比订单详情数量 和 路由表中数据数量,一致为妥投回传,不一致不回传
Map<String, String> map = new HashMap<>();
// 业务处理
if (SonyaConstant.SUCCESS_TRUE.equals(back.getSuccess())) {
// 业务处理
} else {
failCount.getAndIncrement();
map.put(billId, back.getMsgContent());
failNos.add(map);
}
}
}
});
});
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
// 业务处理
}
}
加油!