From c8d337dd34c66c9cfdcd41f0324a0aa3a253ba68 Mon Sep 17 00:00:00 2001 From: "Stormeye.Wu" Date: Thu, 27 Sep 2018 15:57:02 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=9C=BA=E6=99=AF=E5=8F=91=E5=88=B8=E7=96=B2?= =?UTF-8?q?=E5=8A=B3=E5=BA=A6=E7=94=9F=E6=95=88][=E6=96=B0=E5=A2=9E]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iformall/domain/po/WxCouponActionLog.java | 29 +++++------ .../iformall/service/PushLimitService.java | 5 +- .../service/impl/PushLimitServiceImpl.java | 9 ++-- .../impl/WxCouponActionLogServiceImpl.java | 2 +- .../service/impl/WxCouponSendServiceImpl.java | 14 ++++++ .../mapper/WxCouponActionLogMapper.xml | 48 +++++++++---------- 6 files changed, 62 insertions(+), 45 deletions(-) diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxCouponActionLog.java b/mallinkService/src/main/java/com/iformall/domain/po/WxCouponActionLog.java index cadc3664d..8f90dbb4f 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxCouponActionLog.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxCouponActionLog.java @@ -79,8 +79,8 @@ public class WxCouponActionLog implements Serializable { @io.swagger.annotations.ApiModelProperty(value="",name="channelId") private Long channelId; /***/ - @io.swagger.annotations.ApiModelProperty(value="",name="createtime") - private Date createtime; + @io.swagger.annotations.ApiModelProperty(value="",name="createTime") + private Date createTime; public String getTenantId() { return tenantId; } @@ -111,24 +111,24 @@ public class WxCouponActionLog implements Serializable { public void setChannelId(Long _channelId) { channelId = _channelId; } - public Date getCreatetime() { - return createtime; - } - public void setCreatetime(Date _createtime) { - createtime = _createtime; - } + public Date getCreateTime() { + return createTime; + } + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } public static enum Field { Id_ASC("`id` ASC"),Id_DESC("`id` DESC") - ,TenantId_ASC("`tenantId` ASC"),TenantId_DESC("`tenantId` DESC") - ,CouponId_ASC("`couponId` ASC"),CouponId_DESC("`couponId` DESC") - ,CouponOrderId_ASC("`couponOrderId` ASC"),CouponOrderId_DESC("`couponOrderId` DESC") - ,ChannelType_ASC("`channelType` ASC"),ChannelType_DESC("`channelType` DESC") - ,ChannelId_ASC("`channelId` ASC"),ChannelId_DESC("`channelId` DESC") - ,Createtime_ASC("`createtime` ASC"),Createtime_DESC("`createtime` DESC") + ,TenantId_ASC("`tenant_id` ASC"),TenantId_DESC("`tenant_id` DESC") + ,CouponId_ASC("`coupon_id` ASC"),CouponId_DESC("`coupon_id` DESC") + ,CouponOrderId_ASC("`coupon_order_id` ASC"),CouponOrderId_DESC("`coupon_order_id` DESC") + ,ChannelType_ASC("`channel_type` ASC"),ChannelType_DESC("`channel_type` DESC") + ,ChannelId_ASC("`channel_id` ASC"),ChannelId_DESC("`channel_id` DESC") + ,CreateTime_ASC("`create_time` ASC"),CreateTime_DESC("`create_time` DESC") ; private String value; Field(String value){ @@ -161,6 +161,7 @@ public class WxCouponActionLog implements Serializable { sb.append(","); sb.append(fields[k].toString()); } + this.sortColumns = sb.toString(); } diff --git a/mallinkService/src/main/java/com/iformall/service/PushLimitService.java b/mallinkService/src/main/java/com/iformall/service/PushLimitService.java index 97a6e1f14..fc664cd40 100644 --- a/mallinkService/src/main/java/com/iformall/service/PushLimitService.java +++ b/mallinkService/src/main/java/com/iformall/service/PushLimitService.java @@ -57,10 +57,11 @@ public interface PushLimitService { /** * 主动发券检查 - * @param user + * @param tenantId + * @param cUserId * @param coupon * @return */ - boolean checkCoupon(WxCUser user, WxCoupon coupon); + boolean checkCoupon(String tenantId, Long cUserId, Long couponId); } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/PushLimitServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/PushLimitServiceImpl.java index 864142dff..84db70eda 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/PushLimitServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/PushLimitServiceImpl.java @@ -92,10 +92,10 @@ public class PushLimitServiceImpl implements PushLimitService { } @Override - public boolean checkCoupon(WxCUser user, WxCoupon coupon) { + public boolean checkCoupon(String tenantId, Long cUserId, Long couponId) { Date curDate = new Date(); // 1. get tenant limit - PushLimit pushLimit = getPushLimit(user.getTenantId()); + PushLimit pushLimit = getPushLimit(tenantId); // 2. check time 是否在给定的时间段内 boolean isInDate = DateUtils.isInDate(curDate, pushLimit.getTimeStart(), pushLimit.getTimeEnd()); if (!isInDate) { @@ -103,13 +103,14 @@ public class PushLimitServiceImpl implements PushLimitService { } // 3. check 每人每天多少张券 Map params = new HashMap(); - params.put("tenantId", user.getTenantId()); - params.put("c_user_id", user.getId()); + params.put("tenantId", tenantId); + params.put("cUserId", cUserId); int countForUser = wxCouponActionLogMapper.getCountByUser(params); if (countForUser >= pushLimit.getCouponAmount()) { throw new MallinkException(ErrorCode.COUPON_SEND_UP_TO_COUPONLIMIT); } // 4. check 每人多少天内不会重复收到一张券 + params.put("couponId", couponId); params.put("dayNum", pushLimit.getCouponDay()); int countForUserCoupon = wxCouponActionLogMapper.getCountByUserAndCoupon(params); if (countForUserCoupon >= pushLimit.getCouponDay()) { diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponActionLogServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponActionLogServiceImpl.java index b4fd31849..4f20aafe2 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponActionLogServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponActionLogServiceImpl.java @@ -55,7 +55,7 @@ public class WxCouponActionLogServiceImpl implements WxCouponActionLogService { actionLog.setChannelId(channelId); actionLog.setCouponOrderId(coupon_order_id); actionLog.setChannelType(channelType); - actionLog.setCreatetime(new Date()); + actionLog.setCreateTime(new Date()); saveOrUpdate(actionLog); } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponSendServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponSendServiceImpl.java index 4830ac13f..aa496ae17 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponSendServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponSendServiceImpl.java @@ -5,6 +5,7 @@ import com.github.pagehelper.PageInfo; import com.iformall.common.IdWorker; import com.iformall.domain.po.*; import com.iformall.enums.*; +import com.iformall.exception.MallinkException; import com.iformall.mapper.WxCouponOrderMapper; import com.iformall.mapper.WxCouponSendMapper; import com.iformall.service.*; @@ -37,6 +38,9 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { @Autowired WxCouponOrderMapper wxCouponOrderMapper; + @Autowired + PushLimitService pushLimitService; + @Override public PageInfo listAsPage(WxCouponSend record, Integer pageIndex, Integer pageSize) { @@ -72,6 +76,7 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { //查询停车或者核销的券 stopCarCouponSwitch verifyConponSwitch WxCouponSend wxCouponSendQuery = new WxCouponSend(); wxCouponSendQuery.setTenantId(tenantId); + wxCouponSendQuery.setStatus(EnumCouponSendStatus.VALID.getCode()); int actionType = EnumCouponSendSendType.UNKNOWN.getCode(); String configKey = ""; if (type == EnumCouponSendSendType.CAR_STOP) { @@ -101,6 +106,15 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { List wxCouponSends = wxCouponSendMapper.findList(wxCouponSendQuery); for (WxCouponSend send : wxCouponSends) { + boolean checkLimit = false; + try { + checkLimit = pushLimitService.checkCoupon(tenantId, cUserId, send.getCouponId()); + } catch (MallinkException e) { + logger.error(e.getMessage()); + } + if (!checkLimit) { + continue; + } // 发放免费券 WxCouponOrder couponOrder = wxOrderService.sendFreeCouponToUser(cUserId, send.getCouponId()); if (couponOrder != null) { diff --git a/mallinkService/src/main/resources/mapper/WxCouponActionLogMapper.xml b/mallinkService/src/main/resources/mapper/WxCouponActionLogMapper.xml index c8a0a2c4f..d04687d74 100644 --- a/mallinkService/src/main/resources/mapper/WxCouponActionLogMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxCouponActionLogMapper.xml @@ -8,11 +8,11 @@ - + - `id`,`tenant_id`,`coupon_id`,`coupon_order_id`,`channel_type`,`channel_id`,`createtime` + `id`,`tenant_id`,`coupon_id`,`coupon_order_id`,`channel_type`,`channel_id`,`create_time` @@ -48,14 +48,14 @@ - - and `createtime` = #{createtime} + + and `create_time` = #{createTime} - and `createtime` >= #{startTime} + and `create_time` >= #{startTime} - and `createtime` <= #{endTime} + and `create_time` <= #{endTime} @@ -75,24 +75,24 @@ @@ -102,30 +102,30 @@ left join wx_coupon_order on wx_coupon_action_log.coupon_order_id=wx_coupon_order.id where wx_coupon_action_log.tenant_id=#{tenantId} and wx_coupon_order.coupon_order_status = 1 - and wx_coupon_action_log.createtime >= #{startTime} - and wx_coupon_action_log.createtime <= #{endTime} + and wx_coupon_action_log.create_time >= #{startTime} + and wx_coupon_action_log.create_time <= #{endTime} and wx_coupon_action_log.channel_type = #{channelType} group by xTime order by xTime desc