社区微信群开通啦,扫一扫抢先加入社区官方微信群
社区微信群
2019.7.22著
算算十天没写博客了,武汉是真的热,上周做了两个报表,也有一点小总结
大致需求就是根据查询条件,查询出数据并显示到页面。
做这类需求,一般先是找一个维度,比如我就是找的延保订单表做的维度,先查询延保订单表里面没有的查询条件,然后组合获取所以的订单编号orderIds。
再把orderIds放到延保订单里面作为查询条件,并把延保订单表里面的查询条件一并添加,最终结果查询出延保订单数据,在组装数据,延保订单数据直接set,不是延保单数据,根据组合获取订单编号orderIds的方式,set值。
根据分页条件把数据返回给页面。
需要注意的是我们公司延保数据都存在mangodb里面,所以查询的时候出了很多问题。
在mangodb里面,查询方式有准确查询is,批量in,以及模糊查询regex。查询时需要注意在mongodb中进行分页查询时需要从0页开始查起,而数据库进行分页时是从1页开始查询的。
总结:写代码逻辑一定要严谨,判断条件一定要添加,这样即使报错,也不会有太大的影响。
本次我是这么进行非延保数据条件筛选的
/**
* 根据页面传入的查询条件组装orderUuids
* @param qm
* @return
*/
private List<String> getOrderIdsByQm(ShoppingOrderMgrQueryDTO qm){
List<String> orderFromIds = new ArrayList<String>();
List<String> orderPayTimeIds = new ArrayList<String>();
List<String> orderReceiverIds = new ArrayList<String>();
List<String> orderRefundTimeIds = new ArrayList<String>();
List<String> orderConditionIds = new ArrayList<String>();
List<String> orderUuids = new ArrayList<String>();
List<String> mobileIds = new ArrayList<>();
//1.获取满足订单来源的订单编号list
if(StringUtils.isNotEmpty(qm.getOrderFrom())){
orderFromIds = this.getOrderFromIds(qm.getOrderFrom());
}
//2.获取满足支付日期的订单编号list
if(StringUtils.isNotEmpty(qm.getOrderPayTime())){
orderPayTimeIds = this.getOrderPayTimeIds(qm.getOrderPayTime());
}
//3.获取满足退款时间的订单编号list
if(StringUtils.isNotEmpty(qm.getOrderRefundTime())){
orderRefundTimeIds = this.getOrderRefundTimeIds(qm.getOrderRefundTime());
}
//4.获取满足下单人(客户名称)的订单编号list
if(StringUtils.isNotEmpty(qm.getOrderReceiver()) || StringUtils.isNotEmpty(qm.getMobile())){
orderReceiverIds = this.getOrderReceiverIds(qm.getOrderReceiver(),qm.getMobile());
}
//
// if(StringUtils.isNotEmpty(qm.getMobile())){
// mobileIds = this.getMobileIds(qm.getMobile());
// }
//5.根据订单来源,订单编号,退款时间进行交集去重处理,并返回订单的uuids
if(CollectionUtils.isNotEmpty(orderFromIds) || CollectionUtils.isNotEmpty(orderPayTimeIds) || CollectionUtils.isNotEmpty(orderRefundTimeIds)){
orderConditionIds = this.getOrderIds(orderFromIds, orderPayTimeIds, orderRefundTimeIds);
}
//6.根据前3个条件获取的订单uuids和第4个条件获取的订单uuids进行交集处理
if(CollectionUtils.isNotEmpty(orderConditionIds) && CollectionUtils.isNotEmpty(orderReceiverIds)){
orderUuids = (List<String>) CollectionUtils.intersection(orderReceiverIds, orderConditionIds);
}else{
orderUuids.addAll(orderReceiverIds);
orderUuids.addAll(orderConditionIds);
}
return orderUuids;
}
/**
* 根据以上3个条件查询出来的订单编号list进行交集去重处理,并返回订单uuids
* @param orderFromIds
* @param payTimeOrderIds
* @param orderRefundTimeIds
* @returni
*/
private List<String> getOrderIds(List<String> orderFromIds,List<String> payTimeOrderIds,List<String> orderRefundTimeIds){
List<String> newOrderIds = new ArrayList<String>();
if(CollectionUtils.isNotEmpty(orderFromIds) && CollectionUtils.isNotEmpty(payTimeOrderIds) && CollectionUtils.isNotEmpty(orderRefundTimeIds)){
newOrderIds = (List<String>) CollectionUtils.intersection(orderRefundTimeIds, CollectionUtils.intersection(orderFromIds, payTimeOrderIds));
}else if((CollectionUtils.isNotEmpty(orderFromIds) && CollectionUtils.isNotEmpty(payTimeOrderIds))){
newOrderIds = (List<String>)CollectionUtils.intersection(orderFromIds, payTimeOrderIds);
}else if(CollectionUtils.isNotEmpty(orderFromIds) && CollectionUtils.isNotEmpty(orderRefundTimeIds)){
newOrderIds = (List<String>)CollectionUtils.intersection(orderFromIds, orderRefundTimeIds);
}else if(CollectionUtils.isNotEmpty(payTimeOrderIds) && CollectionUtils.isNotEmpty(orderRefundTimeIds)){
newOrderIds = (List<String>)CollectionUtils.intersection(payTimeOrderIds, orderRefundTimeIds);
}else{
newOrderIds.addAll(orderFromIds);
newOrderIds.addAll(payTimeOrderIds);
newOrderIds.addAll(orderRefundTimeIds);
}
return newOrderIds;
}
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!