| @@ -65,6 +65,13 @@ public class WxCouponChannelController extends BaseController | |||
| public ResultData findById(Long id) { | |||
| return new ResultData(Result.SUCCESS,"查询成功",wxCouponChannelService.getById(id)); | |||
| } | |||
| /*@ApiOperation("根据") | |||
| @GetMapping("/add") | |||
| @ApiImplicitParam(name="id",value="id",dataType="Long", paramType = "query",required=true) | |||
| public ResultData findById(Long id) { | |||
| return new ResultData(Result.SUCCESS,"查询成功",wxCouponChannelService.getById(id)); | |||
| }*/ | |||
| @@ -1,12 +1,12 @@ | |||
| package com.simple.domain.po; | |||
| import javax.persistence.*; | |||
| import java.util.*; | |||
| import java.math.*; | |||
| import javax.persistence.Transient; | |||
| import java.util.List; | |||
| import javax.persistence.Id; | |||
| import javax.persistence.Table; | |||
| import javax.persistence.Transient; | |||
| import java.io.Serializable; | |||
| import java.util.ArrayList; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| @Table(name = "wx_coupon_channel") | |||
| public class WxCouponChannel implements Serializable { | |||
| @@ -50,14 +50,17 @@ public class WxCouponChannel implements Serializable { | |||
| /*卡券id**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="卡券id",name="couponId") | |||
| private Long couponId; | |||
| /*券状态,判断是否在前端展示**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="券状态,判断是否在前端展示",name="couponStatus") | |||
| private Integer couponStatus; | |||
| /*券类型(1.满减券,2.代金券,3.团购券,4.礼品券,5.停车券)**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="券类型(1.满减券,2.代金券,3.团购券,4.礼品券,5.停车券)",name="type") | |||
| private Integer type; | |||
| /*券名称**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="券名称",name="title") | |||
| private String title; | |||
| /*投放频道位置(1.banner图,2.限时抢购)**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="投放频道位置(1.banner图,2.限时抢购)",name="targetAd") | |||
| /*投放频道位置(1.列表, 2.限时抢购)**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="投放频道位置(1.列表, 2.限时抢购)",name="targetAd") | |||
| private Integer targetAd; | |||
| /*创建时间**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createDate") | |||
| @@ -83,6 +86,12 @@ public class WxCouponChannel implements Serializable { | |||
| public void setCouponId(Long _couponId) { | |||
| couponId = _couponId; | |||
| } | |||
| public Integer getCouponStatus() { | |||
| return couponStatus; | |||
| } | |||
| public void setCouponStatus(Integer _couponStatus) { | |||
| couponStatus = _couponStatus; | |||
| } | |||
| public Integer getType() { | |||
| return type; | |||
| } | |||
| @@ -122,6 +131,7 @@ public class WxCouponChannel implements Serializable { | |||
| ,TenantId_ASC("`tenantId` ASC"),TenantId_DESC("`tenantId` DESC") | |||
| ,MerchantId_ASC("`merchantId` ASC"),MerchantId_DESC("`merchantId` DESC") | |||
| ,CouponId_ASC("`couponId` ASC"),CouponId_DESC("`couponId` DESC") | |||
| ,CouponStatus_ASC("`couponStatus` ASC"),CouponStatus_DESC("`couponStatus` DESC") | |||
| ,Type_ASC("`type` ASC"),Type_DESC("`type` DESC") | |||
| ,Title_ASC("`title` ASC"),Title_DESC("`title` DESC") | |||
| ,TargetAd_ASC("`targetAd` ASC"),TargetAd_DESC("`targetAd` DESC") | |||
| @@ -159,9 +169,9 @@ public class WxCouponChannel implements Serializable { | |||
| sb.append(","); | |||
| sb.append(fields[k].toString()); | |||
| } | |||
| } | |||
| public void setSortColumns(String sortColumns) | |||
| { | |||
| if (sortColumns == null || "".equals(sortColumns.trim())) { | |||
| @@ -169,7 +179,7 @@ public class WxCouponChannel implements Serializable { | |||
| } | |||
| if (sortColumns.contains(",")) { | |||
| String[] cols = sortColumns.split(","); | |||
| java.util.List<Field> fList = new java.util.ArrayList(); | |||
| List<Field> fList = new ArrayList(); | |||
| for (int k = 0; k < cols.length; k++) { | |||
| fList.add(Field.valueOf(cols[k])); | |||
| } | |||
| @@ -0,0 +1,67 @@ | |||
| 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; | |||
| } | |||
| } | |||
| @@ -6,6 +6,7 @@ | |||
| <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" /> | |||
| <result column="merchant_id" jdbcType="BIGINT" property="merchantId" /> | |||
| <result column="coupon_id" jdbcType="BIGINT" property="couponId" /> | |||
| <result column="coupon_status" jdbcType="INTEGER" property="couponStatus" /> | |||
| <result column="type" jdbcType="INTEGER" property="type" /> | |||
| <result column="title" jdbcType="VARCHAR" property="title" /> | |||
| <result column="target_ad" jdbcType="INTEGER" property="targetAd" /> | |||
| @@ -14,7 +15,7 @@ | |||
| </resultMap> | |||
| <sql id="allColumns"> | |||
| `id`,`tenant_id`,`merchant_id`,`coupon_id`,`type`,`title`,`target_ad`,`create_date`,`update_date` | |||
| `id`,`tenant_id`,`merchant_id`,`coupon_id`,`coupon_status`,`type`,`title`,`target_ad`,`create_date`,`update_date` | |||
| </sql> | |||
| <sql id="dynamicWhereConditions"> | |||
| @@ -40,6 +41,11 @@ | |||
| </if> | |||
| <if test=" null != couponStatus "> | |||
| and `coupon_status` = #{couponStatus} | |||
| </if> | |||
| <if test=" null != type "> | |||
| and `type` = #{type} | |||