package com.yeshi.fanli.util; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; import com.yeshi.fanli.entity.bus.user.HongBao; import com.yeshi.fanli.entity.bus.user.HongBaoExtra; import com.yeshi.fanli.entity.bus.user.OrderItem; import com.yeshi.fanli.entity.taobao.OrderItemHongBao; import com.yeshi.fanli.entity.taobao.TaoBaoOrder; import com.yeshi.fanli.entity.taobao.TaobaoOrderHongBao; import com.yeshi.fanli.log.LogHelper; import org.yeshi.utils.JsonUtil; public class HongBaoUtil { private static final Map titleMap = new HashMap(); private static final Map infoMap = new HashMap(); static { titleMap.put(1, "hongbao_type_1_title"); titleMap.put(2, "hongbao_type_2_title"); titleMap.put(3, "hongbao_type_3_title"); titleMap.put(4, "hongbao_type_4_title"); titleMap.put(5, "hongbao_type_5_title"); titleMap.put(6, "hongbao_type_6_title"); titleMap.put(7, "hongbao_type_7_title"); titleMap.put(20, "hongbao_type_20_title"); titleMap.put(21, "hongbao_type_21_title"); titleMap.put(22, "hongbao_type_22_title"); infoMap.put(1, "hongbao_type_1_info"); infoMap.put(2, "hongbao_type_2_info"); infoMap.put(3, "hongbao_type_3_info"); infoMap.put(4, "hongbao_type_4_info"); infoMap.put(5, "hongbao_type_5_info"); infoMap.put(6, "hongbao_type_6_info"); infoMap.put(7, "hongbao_type_7_info"); infoMap.put(20, "hongbao_type_20_info"); infoMap.put(21, "hongbao_type_21_info"); infoMap.put(22, "hongbao_type_22_info"); } public static String getHongBaoTitle(int type) { Map map = PropertiesUtil.getMap(); String title = map.get(titleMap.get(type)); if (title == null) { title = map.get(titleMap.get(Constant.HB_HUODONG)); } return title; } public static String getHongBaoInfo(int type) { Map map = PropertiesUtil.getMap(); String info = map.get(infoMap.get(type)); if (info == null) { info = map.get(infoMap.get(Constant.HB_HUODONG)); } return info; } /** * 转换成包装类 * * @param hongBao * @return */ public static HongBaoExtra convert(HongBao hongBao) { HongBaoExtra hbx = new HongBaoExtra(hongBao); String param = hongBao.getParam(); if (param != null) { Map map = JsonUtil.parseData(param); if (map != null) { String picture = map.get("picture"); if (picture != null) { hbx.setPicture(picture); } else { hbx.setPicture(""); } } else { hbx.setPicture(""); } } hbx.setTitle(getHongBaoTitle(hongBao.getType())); hbx.setInfo(getHongBaoInfo(hongBao.getType())); return hbx; } public static String convertState(int state) { if (state == 1 || state == 2) { return "未到账"; } else if (state == 3) { return "已到账"; } else if (state == 4) { return "已失效"; } else { return "状态不知"; } } public static List sortHongBaoAndOrderItem(List orderItemList, List hongBaoList) { if (orderItemList.size() != hongBaoList.size()) return null; Comparator orderCM = new Comparator() { @Override public int compare(OrderItem o1, OrderItem o2) { return o1.getAuctionId().longValue() == o2.getAuctionId() ? o1.getPayMoney().compareTo(o2.getPayMoney()) : (int) ((o1.getAuctionId() - o2.getAuctionId()) / Math.abs(o1.getAuctionId() - o2.getAuctionId())); } }; Comparator hongBaoCM = new Comparator() { @Override public int compare(HongBao o1, HongBao o2) { return o1.getAuctionId().longValue() == o2.getAuctionId() ? o1.getPayMoney().compareTo(o2.getPayMoney()) : (int) ((o1.getAuctionId() - o2.getAuctionId()) / Math.abs(o1.getAuctionId() - o2.getAuctionId())); } }; Collections.sort(orderItemList, orderCM); Collections.sort(hongBaoList, hongBaoCM); List list = new ArrayList<>(); for (int i = 0; i < orderItemList.size(); i++) { list.add(new OrderItemHongBao(hongBaoList.get(i), orderItemList.get(i))); } return list; } public static List sortHongBaoAndTaoBaoOrder(List orderList, List hongBaoList) { if (orderList.size() != hongBaoList.size()) return null; List validTaoBaoOrderList = new ArrayList<>(); List validHongBaoList = new ArrayList<>(); for (int i = 0; i < orderList.size(); i++) { TaoBaoOrder taoBaoOrder = orderList.get(i); if (!taoBaoOrder.getOrderState().equalsIgnoreCase("订单失效")) { validTaoBaoOrderList.add(taoBaoOrder); orderList.remove(i); i--; } } for (int i = 0; i < validTaoBaoOrderList.size(); i++) { TaoBaoOrder taoBaoOrder = validTaoBaoOrderList.get(i); for (int n = 0; n < hongBaoList.size(); n++) { HongBao hongBao = hongBaoList.get(n); if (taoBaoOrder.getOrderState().equalsIgnoreCase("订单结算")) { if (taoBaoOrder.getAuctionId().longValue() == hongBao.getAuctionId() &&( taoBaoOrder.getSettlement().compareTo(hongBao.getPayMoney()) == 0||taoBaoOrder.getPayment().compareTo(hongBao.getPayMoney()) == 0)) { validHongBaoList.add(hongBao); hongBaoList.remove(n); break; } } else { if (taoBaoOrder.getAuctionId().longValue() == hongBao.getAuctionId() && taoBaoOrder.getPayment().compareTo(hongBao.getPayMoney()) == 0) { validHongBaoList.add(hongBao); hongBaoList.remove(n); break; } } } } if (validTaoBaoOrderList.size() != validHongBaoList.size()) { LogHelper.test("淘宝订单与红包数量不对应"); return null; } // 先排序尚未失效的商品 Comparator orderCM = new Comparator() { @Override public int compare(TaoBaoOrder o1, TaoBaoOrder o2) { return o1.getAuctionId().longValue() == o2.getAuctionId() ? o1.getPayment().compareTo(o2.getPayment()) : (int) ((o1.getAuctionId() - o2.getAuctionId()) / Math.abs(o1.getAuctionId() - o2.getAuctionId())); } }; Comparator hongBaoCM = new Comparator() { @Override public int compare(HongBao o1, HongBao o2) { return o1.getAuctionId().longValue() == o2.getAuctionId() ? o1.getPayMoney().compareTo(o2.getPayMoney()) : (int) ((o1.getAuctionId() - o2.getAuctionId()) / Math.abs(o1.getAuctionId() - o2.getAuctionId())); } }; Collections.sort(validTaoBaoOrderList, orderCM); Collections.sort(validHongBaoList, hongBaoCM); // 加入剩下的 // orderCM = new Comparator() { // // @Override // public int compare(TaoBaoOrder o1, TaoBaoOrder o2) { // // if (o1.getAuctionId() - o2.getAuctionId() != 0) // return (int) ((o1.getAuctionId() - o2.getAuctionId()) // / Math.abs(o1.getAuctionId() - o2.getAuctionId())); // else // o1.getAuctionId() // } // }; // // hongBaoCM = new Comparator() { // @Override // public int compare(HongBao o1, HongBao o2) { // return (int) ((o1.getAuctionId() - o2.getAuctionId()) // / Math.abs(o1.getAuctionId() - o2.getAuctionId())); // } // }; if (orderList.size() > 0) { Collections.sort(orderList, orderCM); validTaoBaoOrderList.addAll(orderList); } if (hongBaoList.size() > 0) { Collections.sort(hongBaoList, hongBaoCM); validHongBaoList.addAll(hongBaoList); } List list = new ArrayList<>(); for (int i = 0; i < validHongBaoList.size(); i++) { list.add(new TaobaoOrderHongBao(validHongBaoList.get(i), validTaoBaoOrderList.get(i))); } return list; } public static List convertToTiChengOrder(List hongBaoList) { List orderItemList = new ArrayList<>(); if (hongBaoList != null) for (HongBao hb : hongBaoList) { OrderItem orderItem = new OrderItem(); orderItem.setTitle("奖金订单商品"); if (hb.getParent() != null) { orderItem.setPayMoney(hb.getParent().getPayMoney()); orderItem.setOrderId(hb.getParent().getOrderId()); } else { orderItem.setPayMoney(hb.getPayMoney()); orderItem.setOrderId(hb.getOrderId()); } if (!StringUtil.isNullOrEmpty(orderItem.getOrderId())) { orderItem.setOrderId( orderItem.getOrderId().substring(0, orderItem.getOrderId().length() - 6) + "******"); } orderItem.setFanMoney(hb.getMoney()); if (hb.getState() == HongBao.STATE_BUKELINGQU || hb.getState() == HongBao.STATE_KELINGQU) { orderItem.setDesc("订单确认收货的次月25日后到账"); orderItem.setStateDesc("未到账"); } else if (hb.getState() == HongBao.STATE_YILINGQU) { orderItem.setDesc("已自动转入你的余额"); orderItem.setStateDesc("已到账"); } else if (hb.getState() == HongBao.STATE_SHIXIAO) { if (hb.getParent() != null && hb.getParent().getBalanceTime() != null) { orderItem.setDesc("售后订单无奖金"); orderItem.setStateDesc("已售后"); } else { orderItem.setDesc("退款订单无奖金"); orderItem.setStateDesc("已退款"); } } orderItem.setCreateTime(hb.getCreatetime()); orderItem.setState(hb.getState()); orderItem.setPicture(Constant.systemCommonConfig.getDefaultOrderPicture()); orderItemList.add(orderItem); } return orderItemList; } }