...
|
...
|
@@ -2,6 +2,8 @@ package com.yoho.unions.server.service.impl; |
|
|
|
|
|
import com.alibaba.fastjson.JSONException;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.google.common.base.Function;
|
|
|
import com.google.common.collect.Maps;
|
|
|
import com.yoho.error.exception.ServiceException;
|
|
|
import com.yoho.service.model.response.PageResponseBO;
|
|
|
import com.yoho.service.model.union.request.ChannelUserBO;
|
...
|
...
|
@@ -18,7 +20,9 @@ import com.yoho.unions.common.utils.DateUtil; |
|
|
import com.yoho.unions.dal.*;
|
|
|
import com.yoho.unions.dal.model.*;
|
|
|
import com.yoho.unions.server.service.IUserOrdersService;
|
|
|
import com.yoho.unions.vo.OrderInfo;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.collections.map.HashedMap;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
...
|
...
|
@@ -28,9 +32,7 @@ import org.springframework.stereotype.Service; |
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -51,70 +53,116 @@ public class UserOrdersServiceImpl implements IUserOrdersService,IBusinessExport |
|
|
@Autowired
|
|
|
IMktMarketingUrlDAO mktMarketingUrlDAO;
|
|
|
@Autowired
|
|
|
OrdersFreightCouponsMapper ordersFreightCouponsMapper;
|
|
|
@Autowired
|
|
|
OrdersGiftCardMapper ordersGiftCardMapper;
|
|
|
@Autowired
|
|
|
OrdersAccessOryMapper ordersAccessOryMapper;
|
|
|
@Resource
|
|
|
RedisValueCache redisValueCache;
|
|
|
|
|
|
|
|
|
public PageUnionOrderRspBO queryUnionOrders(UnionOrderReqBO reqBO){
|
|
|
logger.info("queryUnionOrders param is {}",reqBO);
|
|
|
int beginTime = StringUtils.isBlank(reqBO.getBeginTime())?0:Integer.valueOf(reqBO.getBeginTime());
|
|
|
int endTime = StringUtils.isBlank(reqBO.getEndTime())?0:Integer.valueOf(reqBO.getEndTime());
|
|
|
int orderCode =StringUtils.isBlank(reqBO.getOrderCode())?0:Integer.valueOf(reqBO.getOrderCode());
|
|
|
String unionId = StringUtils.isBlank(reqBO.getUnionId())?null:reqBO.getUnionId();
|
|
|
public PageUnionOrderRspBO queryUnionOrders(UnionOrderReqBO reqBO) {
|
|
|
logger.info("queryUnionOrders param is {}", reqBO);
|
|
|
int beginTime = StringUtils.isBlank(reqBO.getBeginTime()) ? 0 : Integer.valueOf(reqBO.getBeginTime());
|
|
|
int endTime = StringUtils.isBlank(reqBO.getEndTime()) ? 0 : Integer.valueOf(reqBO.getEndTime());
|
|
|
int orderCode = StringUtils.isBlank(reqBO.getOrderCode()) ? 0 : Integer.valueOf(reqBO.getOrderCode());
|
|
|
String unionId = StringUtils.isBlank(reqBO.getUnionId()) ? null : reqBO.getUnionId();
|
|
|
String unionType = StringUtils.isBlank(reqBO.getUnionType()) ? null : reqBO.getUnionType();
|
|
|
List<String> idList = new ArrayList<>();
|
|
|
if(StringUtils.isNotBlank(reqBO.getIds())){
|
|
|
String[] ids = StringUtils.isBlank(reqBO.getIds())? null: reqBO.getIds().split(",");
|
|
|
if (StringUtils.isNotBlank(reqBO.getIds())) {
|
|
|
String[] ids = StringUtils.isBlank(reqBO.getIds()) ? null : reqBO.getIds().split(",");
|
|
|
idList = Arrays.asList(ids);
|
|
|
}
|
|
|
|
|
|
if(StringUtils.isNotEmpty(unionType)){
|
|
|
if (StringUtils.isNotEmpty(unionType)) {
|
|
|
MktMarketingUrl mktMarketingUrl = mktMarketingUrlDAO.selectByName(unionType);
|
|
|
if(null!=mktMarketingUrl){
|
|
|
if (null != mktMarketingUrl) {
|
|
|
String mktMarkeringUnionId = String.valueOf(mktMarketingUrl.getUnionType());
|
|
|
if(StringUtils.isEmpty(unionId)){
|
|
|
if (StringUtils.isEmpty(unionId)) {
|
|
|
unionId = mktMarkeringUnionId;
|
|
|
}
|
|
|
if(StringUtils.isNotEmpty(unionId)&&!unionId.equals(mktMarkeringUnionId)){
|
|
|
if (StringUtils.isNotEmpty(unionId) && !unionId.equals(mktMarkeringUnionId)) {
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
//查询总数
|
|
|
int count = userOrdersDAO.selectCount(beginTime,endTime,String.valueOf(orderCode),unionId,idList);
|
|
|
int count = userOrdersDAO.selectCount(beginTime, endTime, String.valueOf(orderCode), unionId, idList);
|
|
|
logger.info("userOrdersDAO.selectCount: size is {}", count);
|
|
|
List<UserOrders> userOrdersList = new ArrayList<>();
|
|
|
List<UnionOrderRspBO> unionOrderRspBOList = new ArrayList<>();
|
|
|
if(count>0){
|
|
|
userOrdersList = userOrdersDAO.selectUserOrderList(beginTime,endTime,String.valueOf(orderCode),unionId,idList,reqBO.getStart(),reqBO.getSize());
|
|
|
if (count < 1) {
|
|
|
return null;
|
|
|
}
|
|
|
if (count > 0) {
|
|
|
userOrdersList = userOrdersDAO.selectUserOrderList(beginTime, endTime, String.valueOf(orderCode), unionId, idList, reqBO.getStart(), reqBO.getSize());
|
|
|
}
|
|
|
List<OrdersDetailBO> ordersDetailBOList = new ArrayList<>();
|
|
|
List<Long> orderCodeList = new ArrayList<>();
|
|
|
List<UserOrderDatailBO> userOrderDatailBOList = new ArrayList<>();
|
|
|
for (UserOrders userOrders : userOrdersList) {
|
|
|
//根据查询出来的uid,ordercode,查询ERP_ORDERS.Orders
|
|
|
// Orders orders = ordersMapper.selectByUidAndOrderCode(userOrders.getuId(),Long.valueOf(userOrders.getOrderCode()));
|
|
|
List<Orders> order = ordersMapper.selectByOrderCode(Long.valueOf(userOrders.getOrderCode()));
|
|
|
for(Orders orders:order){
|
|
|
OrdersDetailBO ordersDetailBO = new OrdersDetailBO();
|
|
|
ordersDetailBO.setOrders(orders);
|
|
|
ordersDetailBO.setUnionId(userOrders.getUid());
|
|
|
MktMarketingUrl mktMarketingUrl = redisValueCache.get("yh:union:uniontype:"+userOrders.getUid(),MktMarketingUrl.class);
|
|
|
if(mktMarketingUrl==null){
|
|
|
mktMarketingUrl = mktMarketingUrlDAO.selectByPrimaryKey(Long.valueOf(userOrders.getUid()));
|
|
|
redisValueCache.set("yh:union:uniontype:"+userOrders.getUid(), mktMarketingUrl, 1, TimeUnit.HOURS);
|
|
|
}
|
|
|
if (mktMarketingUrl != null) {
|
|
|
ordersDetailBO.setUnionType(mktMarketingUrl.getName());
|
|
|
}
|
|
|
ordersDetailBOList.add(ordersDetailBO);
|
|
|
UserOrderDatailBO userOrderDatailBO = new UserOrderDatailBO();
|
|
|
userOrderDatailBO.setUnionId(userOrders.getUid());
|
|
|
MktMarketingUrl mktMarketingUrl = redisValueCache.get("yh:union:uniontype:" + userOrders.getUid(), MktMarketingUrl.class);
|
|
|
if (mktMarketingUrl == null) {
|
|
|
mktMarketingUrl = mktMarketingUrlDAO.selectByPrimaryKey(Long.valueOf(userOrders.getUid()));
|
|
|
redisValueCache.set("yh:union:uniontype:" + userOrders.getUid(), mktMarketingUrl, 1, TimeUnit.HOURS);
|
|
|
}
|
|
|
if (mktMarketingUrl != null) {
|
|
|
userOrderDatailBO.setUnionName(mktMarketingUrl.getName());
|
|
|
}
|
|
|
userOrderDatailBO.setOrderCode(Long.valueOf(userOrders.getOrderCode()));
|
|
|
userOrderDatailBOList.add(userOrderDatailBO);
|
|
|
orderCodeList.add(Long.valueOf(userOrders.getOrderCode()));
|
|
|
}
|
|
|
Map<Long, UserOrderDatailBO> userOrderDatailBOMap = Maps.uniqueIndex(userOrderDatailBOList, new Function<UserOrderDatailBO, Long>() {
|
|
|
@Override
|
|
|
public Long apply(UserOrderDatailBO userOrderDatailBO) {
|
|
|
return userOrderDatailBO.getOrderCode();
|
|
|
}
|
|
|
});
|
|
|
//批量查询erp_orders.orders表
|
|
|
List<Orders> ordersList = ordersMapper.selectByOrderCodeList(orderCodeList);
|
|
|
Map<Long, Orders> ordersMap = Maps.uniqueIndex(ordersList, new Function<Orders, Long>() {
|
|
|
@Override
|
|
|
public Long apply(Orders orders) {
|
|
|
return orders.getOrderCode();
|
|
|
}
|
|
|
});
|
|
|
List<Long> subOrderCodeList = new ArrayList<>();
|
|
|
|
|
|
for (Map.Entry<Long, Orders> map : ordersMap.entrySet()) {
|
|
|
OrdersDetailBO ordersDetailBO = new OrdersDetailBO();
|
|
|
Orders orders = map.getValue();
|
|
|
ordersDetailBO.setOrders(orders);
|
|
|
subOrderCodeList.add(map.getKey());
|
|
|
ordersDetailBOList.add(ordersDetailBO);
|
|
|
}
|
|
|
|
|
|
//批量查询优惠券金额
|
|
|
List<OrdersCoupons> ordersCouponsList = ordersCouponsMapper.selectByOrderCodeList(subOrderCodeList);
|
|
|
Map<Long, OrdersCoupons> couponsMap = Maps.uniqueIndex(ordersCouponsList, new Function<OrdersCoupons, Long>() {
|
|
|
@Override
|
|
|
public Long apply(OrdersCoupons ordersCoupons) {
|
|
|
return ordersCoupons.getOrderCode();
|
|
|
}
|
|
|
});
|
|
|
//批量查询是否新客
|
|
|
List<OrdersAccessOry> ordersAccessOryList = ordersAccessOryMapper.selectByOrderCodeList(subOrderCodeList);
|
|
|
Map<Long, OrdersAccessOry> ordersAccessOryMap = Maps.uniqueIndex(ordersAccessOryList, new Function<OrdersAccessOry, Long>() {
|
|
|
@Override
|
|
|
public Long apply(OrdersAccessOry ordersAccessOry) {
|
|
|
return ordersAccessOry.getOrderCode();
|
|
|
}
|
|
|
});
|
|
|
|
|
|
for (OrdersDetailBO ordersDetailBO : ordersDetailBOList) {
|
|
|
Orders orders = ordersDetailBO.getOrders();
|
|
|
UnionOrderRspBO orderRspBO = new UnionOrderRspBO();
|
|
|
//优惠券金额
|
|
|
OrdersCoupons ordersCoupons = ordersCouponsMapper.selectByOrderCode(Long.valueOf(orders.getOrderCode()));
|
|
|
OrdersCoupons ordersCoupons = couponsMap.get(orders.getOrderCode());
|
|
|
if (null != ordersCoupons) {
|
|
|
orderRspBO.setCouponAmount(ordersCoupons.getCouponAmount());
|
|
|
} else {
|
...
|
...
|
@@ -125,14 +173,17 @@ public class UserOrdersServiceImpl implements IUserOrdersService,IBusinessExport |
|
|
//订单金额
|
|
|
orderRspBO.setOrderAmount(orders.getOrderAmount());
|
|
|
orderRspBO.setYohoCoinNum(orders.getYohoCoinNum());
|
|
|
int yohoCoin = 0;
|
|
|
if(orders.getYohoCoinNum()>0){
|
|
|
yohoCoin = orders.getYohoCoinNum()/100;
|
|
|
}
|
|
|
|
|
|
//礼品卡抵运费--数据较少,暂时就用单个查询把
|
|
|
BigDecimal pay_shipping_amount = ordersGiftCardMapper.selectPayShippingAmount(Long.valueOf(orders.getOrderCode()));
|
|
|
|
|
|
// 免邮券--数据较少,暂时就用单个查询把
|
|
|
BigDecimal coupon_amount = ordersFreightCouponsMapper.selectCouponAmount(Long.valueOf(orders.getOrderCode()));
|
|
|
//运费
|
|
|
orderRspBO.setShipmentAmount(orders.getShippingCost());
|
|
|
BigDecimal realShipmentAmount = orders.getShippingCost().subtract(pay_shipping_amount).subtract(coupon_amount);
|
|
|
orderRspBO.setShipmentAmount(realShipmentAmount);
|
|
|
//实际支付金额
|
|
|
orderRspBO.setRealPayAmount(orders.getLastOrderAmount().subtract(orders.getShippingCost()));
|
|
|
orderRspBO.setRealPayAmount(orders.getLastOrderAmount().subtract(realShipmentAmount));
|
|
|
//订单状态
|
|
|
orderRspBO.setOrderStatus(OrderStatusEnum.getNameByCode(String.valueOf(orders.getOrderStatus())));
|
|
|
//附加信息
|
...
|
...
|
@@ -140,26 +191,20 @@ public class UserOrdersServiceImpl implements IUserOrdersService,IBusinessExport |
|
|
//支付方式
|
|
|
orderRspBO.setPayChannel(PaymentTypeEnum.getNameByCode(String.valueOf(orders.getPaymentType())));
|
|
|
//是否新客---从新的表中获取
|
|
|
OrdersAccessOry ordersAccessOry = ordersAccessOryMapper.selectByPrimaryKey(Long.valueOf(orders.getOrderCode()));
|
|
|
OrdersAccessOry ordersAccessOry = ordersAccessOryMap.get(orders.getOrderCode());
|
|
|
if (null != ordersAccessOry) {
|
|
|
orderRspBO.setIsNew(NewUserEnum.getNameByCode(ordersAccessOry.getIsNew() == null ? "N" : ordersAccessOry.getIsNew()));
|
|
|
} else {
|
|
|
orderRspBO.setIsNew(NewUserEnum.getNameByCode("N"));
|
|
|
}
|
|
|
orderRspBO.setUid(orders.getUid());
|
|
|
orderRspBO.setOrderCode(orders.getOrderCode().intValue());
|
|
|
orderRspBO.setOrderCode(orders.getOrderCode());
|
|
|
orderRspBO.setId(orders.getId());
|
|
|
orderRspBO.setOrderTime(DateUtil.long2DateStr(Long.valueOf(orders.getCreateTime()) * Long.valueOf(1000), "yyyy-MM-dd"));
|
|
|
// UserOrders userOrders = userOrdersDAO.selectByOrderCode(orders.getParentOrderCode());
|
|
|
// if(userOrders!=null){
|
|
|
// orderRspBO.setUnionId(userOrders.getUid());
|
|
|
// MktMarketingUrl mktMarketingUrl = mktMarketingUrlDAO.selectByPrimaryKey(Long.valueOf(userOrders.getUid()));
|
|
|
// if (mktMarketingUrl != null) {
|
|
|
// orderRspBO.setUnionType(mktMarketingUrl.getName());
|
|
|
// }
|
|
|
// }
|
|
|
orderRspBO.setUnionId(ordersDetailBO.getUnionId());
|
|
|
orderRspBO.setUnionType(ordersDetailBO.getUnionType());
|
|
|
//
|
|
|
UserOrderDatailBO userOrderDatailBO = userOrderDatailBOMap.get(orders.getParentOrderCode());
|
|
|
orderRspBO.setUnionId(userOrderDatailBO.getUnionId());
|
|
|
orderRspBO.setUnionType(userOrderDatailBO.getUnionName());
|
|
|
unionOrderRspBOList.add(orderRspBO);
|
|
|
}
|
|
|
PageUnionOrderRspBO pageUnionOrderRspBO = new PageUnionOrderRspBO();
|
...
|
...
|
|