|
|
|
@@ -1,65 +0,0 @@ |
|
|
|
package com.simple.service.impl; |
|
|
|
import com.simple.domain.dto.WxUserCouponDto; |
|
|
|
import com.simple.domain.po.WxCoupon; |
|
|
|
import com.simple.domain.po.WxOrder; |
|
|
|
import com.simple.mapper.WxCouponMapper; |
|
|
|
import com.simple.service.WxOrderService; |
|
|
|
import com.simple.service.WxUserCouponService; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
|
* Created by syf on 2018/8/10. |
|
|
|
*/ |
|
|
|
@Service |
|
|
|
public class WxUserCouponServiceImpl implements WxUserCouponService { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private WxOrderService wxOrderService; |
|
|
|
@Autowired |
|
|
|
private WxCouponMapper wxCouponMapper; |
|
|
|
|
|
|
|
/** |
|
|
|
* |
|
|
|
* @param userId 用户id |
|
|
|
* @param status 用户卡券状态 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public List<WxUserCouponDto> findList(Long userId, int status) { |
|
|
|
//TODO 待测试优化 |
|
|
|
List<WxUserCouponDto> wxUserCoupons = new ArrayList<>(); |
|
|
|
//查询订单表 |
|
|
|
WxOrder wxOrder = new WxOrder(); |
|
|
|
wxOrder.setCUserId(userId); |
|
|
|
wxOrder.setCouponStatus(status); |
|
|
|
List<WxOrder> orders = wxOrderService.findList(wxOrder); |
|
|
|
List<String> ids = orders.stream().map(p->p.getCouponId()+"").distinct().collect(Collectors.toList()); |
|
|
|
if(ids.size()>0){ |
|
|
|
//查询WxCoupon |
|
|
|
WxCoupon wxCoupon = new WxCoupon(); |
|
|
|
wxCoupon.setIds(ids); |
|
|
|
List<WxCoupon> wxCoupons = wxCouponMapper.findList(wxCoupon); |
|
|
|
Map<Long,String> couponNamesMap = wxCoupons.stream().collect(Collectors.toMap(WxCoupon::getId,p->p.getTitle())); |
|
|
|
for (WxOrder temp:orders) { |
|
|
|
wxUserCoupons.add(getWxUserCoupon(temp,couponNamesMap.get(temp.getCouponId()))); |
|
|
|
} |
|
|
|
} |
|
|
|
return wxUserCoupons; |
|
|
|
} |
|
|
|
public WxUserCouponDto getWxUserCoupon(WxOrder wxOrder, String title){ |
|
|
|
WxUserCouponDto wxUserCoupon = new WxUserCouponDto(); |
|
|
|
wxUserCoupon.setOrderId(wxOrder.getId()); |
|
|
|
wxUserCoupon.setcUserId(wxOrder.getCUserId()); |
|
|
|
wxUserCoupon.setCouponId(wxOrder.getCouponId()); |
|
|
|
wxUserCoupon.setCouponStatus(wxOrder.getCouponStatus()); |
|
|
|
wxUserCoupon.setValidDate(wxOrder.getValidDate()); |
|
|
|
wxUserCoupon.setCouponTitle(title); |
|
|
|
return wxUserCoupon; |
|
|
|
} |
|
|
|
} |