| @@ -0,0 +1,39 @@ | |||||
| package com.simple.controller; | |||||
| import com.simple.common.Result; | |||||
| import com.simple.common.ResultData; | |||||
| import com.simple.domain.po.WxOrder; | |||||
| import com.simple.service.WxCUserService; | |||||
| import com.simple.service.WxOrderService; | |||||
| import com.simple.service.WxUserCouponService; | |||||
| import com.simple.service.dto.WxUserCoupon; | |||||
| import io.swagger.annotations.ApiOperation; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.web.bind.annotation.PostMapping; | |||||
| import org.springframework.web.bind.annotation.RequestBody; | |||||
| import org.springframework.web.bind.annotation.RequestMapping; | |||||
| import org.springframework.web.bind.annotation.RestController; | |||||
| /** | |||||
| * Created by syf on 2018/8/10. | |||||
| */ | |||||
| @RestController | |||||
| @RequestMapping("wxUserCoupon") | |||||
| public class WxUserCouponController { | |||||
| @Autowired | |||||
| private WxUserCouponService wxUserCouponService; | |||||
| @ApiOperation("查询用户卡券接口") | |||||
| @PostMapping("findByStatus") | |||||
| public ResultData findByStatus(@RequestBody WxUserCoupon wxUserCoupon) { | |||||
| //根据用户id,用户卡券状态查找 | |||||
| if(wxUserCoupon==null||wxUserCoupon.getcUserId()==null||wxUserCoupon.getCouponStatus()==null){ | |||||
| return new ResultData(Result.ERROR,"查询失败"); | |||||
| } | |||||
| return new ResultData(Result.SUCCESS,"查询成功",wxUserCouponService.findList(wxUserCoupon.getcUserId(),wxUserCoupon.getCouponStatus())); | |||||
| } | |||||
| } | |||||
| @@ -52,6 +52,13 @@ public interface WxOrderService { | |||||
| * @param id | * @param id | ||||
| */ | */ | ||||
| void deleteById(Long id); | void deleteById(Long id); | ||||
| /** | |||||
| * 条件查询不分页 | |||||
| * @param record | |||||
| * @return | |||||
| */ | |||||
| List<WxOrder> findList(WxOrder record); | |||||
| @@ -0,0 +1,13 @@ | |||||
| package com.simple.service; | |||||
| import com.simple.service.dto.WxUserCoupon; | |||||
| import java.util.List; | |||||
| /** | |||||
| * Created by syf on 2018/8/10. | |||||
| */ | |||||
| public interface WxUserCouponService { | |||||
| List<WxUserCoupon> findList(Long userId,int status); | |||||
| } | |||||
| @@ -0,0 +1,71 @@ | |||||
| package com.simple.service.dto; | |||||
| import com.simple.domain.po.WxOrder; | |||||
| import java.io.Serializable; | |||||
| import java.util.Date; | |||||
| /** | |||||
| * Created by syf on 2018/8/10. | |||||
| * 用户卡券 | |||||
| */ | |||||
| public class WxUserCoupon implements Serializable { | |||||
| private static final long serialVersionUID = 1L; | |||||
| private Integer couponStatus; | |||||
| private Long orderId; | |||||
| private Long cUserId; | |||||
| private Long couponId; | |||||
| private String couponTitle; | |||||
| private Date validDate; | |||||
| public WxUserCoupon(){ | |||||
| } | |||||
| public Integer getCouponStatus() { | |||||
| return couponStatus; | |||||
| } | |||||
| public void setCouponStatus(Integer couponStatus) { | |||||
| this.couponStatus = couponStatus; | |||||
| } | |||||
| public Long getOrderId() { | |||||
| return orderId; | |||||
| } | |||||
| public void setOrderId(Long orderId) { | |||||
| this.orderId = orderId; | |||||
| } | |||||
| public Long getcUserId() { | |||||
| return cUserId; | |||||
| } | |||||
| public void setcUserId(Long cUserId) { | |||||
| this.cUserId = cUserId; | |||||
| } | |||||
| public Long getCouponId() { | |||||
| return couponId; | |||||
| } | |||||
| public void setCouponId(Long couponId) { | |||||
| this.couponId = couponId; | |||||
| } | |||||
| public String getCouponTitle() { | |||||
| return couponTitle; | |||||
| } | |||||
| public void setCouponTitle(String couponTitle) { | |||||
| this.couponTitle = couponTitle; | |||||
| } | |||||
| public Date getValidDate() { | |||||
| return validDate; | |||||
| } | |||||
| public void setValidDate(Date validDate) { | |||||
| this.validDate = validDate; | |||||
| } | |||||
| } | |||||
| @@ -114,12 +114,11 @@ public class WxOrderServiceImpl implements WxOrderService { | |||||
| public void deleteById(Long id) { | public void deleteById(Long id) { | ||||
| wxOrderMapper.deleteByPrimaryKey(id); | wxOrderMapper.deleteByPrimaryKey(id); | ||||
| } | } | ||||
| @Override | |||||
| public List<WxOrder> findList(WxOrder record) { | |||||
| return wxOrderMapper.findList(record); | |||||
| } | |||||
| } | } | ||||
| @@ -0,0 +1,65 @@ | |||||
| package com.simple.service.impl; | |||||
| 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 com.simple.service.dto.WxUserCoupon; | |||||
| 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<WxUserCoupon> findList(Long userId, int status) { | |||||
| //TODO 待测试优化 | |||||
| List<WxUserCoupon> 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 WxUserCoupon getWxUserCoupon(WxOrder wxOrder,String title){ | |||||
| WxUserCoupon wxUserCoupon = new WxUserCoupon(); | |||||
| 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; | |||||
| } | |||||
| } | |||||