From 059cfba630f628643b98ff16aab21d1cdcb04384 Mon Sep 17 00:00:00 2001 From: masterspirit Date: Mon, 20 Aug 2018 17:40:49 +0800 Subject: [PATCH] =?UTF-8?q?[=E7=B2=BE=E5=87=86=E6=8A=95=E6=94=BE][?= =?UTF-8?q?=E4=BF=AE=E6=94=B9]:=E6=8A=95=E6=94=BE=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E6=94=B9=E5=88=B8=E5=BA=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/CouponInjectController.java | 3 +- .../simple/domain/po/WxCouponActionLog.java | 101 ++++++++++-------- .../simple/service/CouponInjectService.java | 5 +- .../service/WxCouponActionLogService.java | 2 + .../service/impl/CouponInjectServiceImpl.java | 84 +++++++++------ .../impl/WxCouponActionLogServiceImpl.java | 21 ++-- .../mapper/WxCouponActionLogMapper.xml | 26 +++-- 7 files changed, 144 insertions(+), 98 deletions(-) diff --git a/mallinkAdmin/src/main/java/com/simple/controller/CouponInjectController.java b/mallinkAdmin/src/main/java/com/simple/controller/CouponInjectController.java index c94eaef23..1f4b43272 100644 --- a/mallinkAdmin/src/main/java/com/simple/controller/CouponInjectController.java +++ b/mallinkAdmin/src/main/java/com/simple/controller/CouponInjectController.java @@ -57,8 +57,7 @@ public class CouponInjectController extends BaseController } //Assert.notNull(couponInject.getName(), "角色名不能为空"); //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); - couponInjectService.add(couponInject); - return new ResultData(); + return couponInjectService.add(couponInject); } @ApiOperation("根据id更新接口") diff --git a/mallinkService/src/main/java/com/simple/domain/po/WxCouponActionLog.java b/mallinkService/src/main/java/com/simple/domain/po/WxCouponActionLog.java index 847a110b4..19cb885a0 100644 --- a/mallinkService/src/main/java/com/simple/domain/po/WxCouponActionLog.java +++ b/mallinkService/src/main/java/com/simple/domain/po/WxCouponActionLog.java @@ -11,15 +11,15 @@ import java.io.Serializable; @Table(name = "wx_coupon_action_log") public class WxCouponActionLog implements Serializable { private static final long serialVersionUID = 1L; - + @Id - protected Long id; - - @Transient - protected List ids; - @Transient - protected String sortColumns; - + protected Long id; + + @Transient + protected List ids; + @Transient + protected String sortColumns; + public Long getId() { return id; } @@ -27,35 +27,39 @@ public class WxCouponActionLog implements Serializable { public void setId(Long id) { this.id = id; } - + public String getSortColumns() { return sortColumns; } - - public List getIds() { + + public List getIds() { return ids; } - public void setIds(List ids) { + + public void setIds(List ids) { this.ids = ids; } - - - + + + /*租户ID**/ @io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId") private String tenantId; /*coupon id**/ @io.swagger.annotations.ApiModelProperty(value="coupon id",name="couponId") private Long couponId; - /*用户id**/ - @io.swagger.annotations.ApiModelProperty(value="用户id",name="userId") - private Long userId; - /*优惠券操作(领取、支付,使用,核销等)**/ - @io.swagger.annotations.ApiModelProperty(value="优惠券操作(领取、支付,使用,核销等)",name="action") - private String action; - /*操作时间**/ - @io.swagger.annotations.ApiModelProperty(value="操作时间",name="operationTime") - private Date operationTime; + /***/ + @io.swagger.annotations.ApiModelProperty(value="",name="couponOrderId") + private Long couponOrderId; + /*0:精准 1:主动领取 2:用户购买 3:停车 4:核销**/ + @io.swagger.annotations.ApiModelProperty(value="0:精准 1:主动领取 2:用户购买 3:停车 4:核销",name="channelType") + private Integer channelType; + /***/ + @io.swagger.annotations.ApiModelProperty(value="",name="channelId") + private Long channelId; + /***/ + @io.swagger.annotations.ApiModelProperty(value="",name="createtime") + private Date createtime; public String getTenantId() { return tenantId; } @@ -68,23 +72,29 @@ public class WxCouponActionLog implements Serializable { public void setCouponId(Long _couponId) { couponId = _couponId; } - public Long getUserId() { - return userId; + public Long getCouponOrderId() { + return couponOrderId; + } + public void setCouponOrderId(Long _couponOrderId) { + couponOrderId = _couponOrderId; + } + public Integer getChannelType() { + return channelType; } - public void setUserId(Long _userId) { - userId = _userId; + public void setChannelType(Integer _channelType) { + channelType = _channelType; } - public String getAction() { - return action; + public Long getChannelId() { + return channelId; } - public void setAction(String _action) { - action = _action; + public void setChannelId(Long _channelId) { + channelId = _channelId; } - public Date getOperationTime() { - return operationTime; + public Date getCreatetime() { + return createtime; } - public void setOperationTime(Date _operationTime) { - operationTime = _operationTime; + public void setCreatetime(Date _createtime) { + createtime = _createtime; } @@ -92,12 +102,13 @@ public class WxCouponActionLog implements Serializable { 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") - ,UserId_ASC("`userId` ASC"),UserId_DESC("`userId` DESC") - ,Action_ASC("`action` ASC"),Action_DESC("`action` DESC") - ,OperationTime_ASC("`operationTime` ASC"),OperationTime_DESC("`operationTime` 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") + ; private String value; Field(String value){ this.value = value; @@ -113,7 +124,7 @@ public class WxCouponActionLog implements Serializable { return this.getValue(); } } - + public void setSortColumns(WxCouponActionLog.Field... fields) { if (fields == null || fields.length == 0) { @@ -129,9 +140,9 @@ public class WxCouponActionLog implements Serializable { sb.append(","); sb.append(fields[k].toString()); } - + } - + public void setSortColumns(String sortColumns) { if (sortColumns == null || "".equals(sortColumns.trim())) { diff --git a/mallinkService/src/main/java/com/simple/service/CouponInjectService.java b/mallinkService/src/main/java/com/simple/service/CouponInjectService.java index 5871fba32..0dcd55fde 100644 --- a/mallinkService/src/main/java/com/simple/service/CouponInjectService.java +++ b/mallinkService/src/main/java/com/simple/service/CouponInjectService.java @@ -1,6 +1,7 @@ package com.simple.service; import com.github.pagehelper.PageInfo; +import com.simple.common.ResultData; import com.simple.domain.po.CouponInject; public interface CouponInjectService { @@ -37,11 +38,11 @@ public interface CouponInjectService { */ void deleteById(Long id); /** - * 根据Id删除实体 + * 精准投(立即投送处理) * * @param id */ - void add(CouponInject record); + ResultData add(CouponInject record); diff --git a/mallinkService/src/main/java/com/simple/service/WxCouponActionLogService.java b/mallinkService/src/main/java/com/simple/service/WxCouponActionLogService.java index 49a06cc23..9e55190be 100644 --- a/mallinkService/src/main/java/com/simple/service/WxCouponActionLogService.java +++ b/mallinkService/src/main/java/com/simple/service/WxCouponActionLogService.java @@ -37,6 +37,8 @@ public interface WxCouponActionLogService { * @param id */ void deleteById(Long id); + + void addOne(String tenantId,Long couponId,Long coupon_order_id,int channelType,Long channelId); diff --git a/mallinkService/src/main/java/com/simple/service/impl/CouponInjectServiceImpl.java b/mallinkService/src/main/java/com/simple/service/impl/CouponInjectServiceImpl.java index 62f8e9acb..5c6b61931 100644 --- a/mallinkService/src/main/java/com/simple/service/impl/CouponInjectServiceImpl.java +++ b/mallinkService/src/main/java/com/simple/service/impl/CouponInjectServiceImpl.java @@ -4,14 +4,14 @@ import com.alibaba.fastjson.JSON; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.simple.common.IdWorker; +import com.simple.common.Result; +import com.simple.common.ResultData; import com.simple.domain.po.*; import com.simple.mapper.CouponInjectMapper; -import com.simple.service.CouponInjectService; -import com.simple.service.WxCUserTagsService; -import com.simple.service.WxCouponOrderService; -import com.simple.service.WxCouponService; +import com.simple.service.*; import org.apache.commons.lang.time.DateUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -31,6 +31,9 @@ public class CouponInjectServiceImpl implements CouponInjectService { WxCouponService wxCouponService; @Autowired WxCUserTagsService wxCUserTagsService; + @Autowired + WxCouponActionLogService wxCouponActionLogService; + private Logger logger = Logger.getLogger(getClass()); @Override @@ -61,13 +64,15 @@ public class CouponInjectServiceImpl implements CouponInjectService { } @Override - public void add(CouponInject record) { + public ResultData add(CouponInject record) { + ResultData resultData = new ResultData(); WxCoupon wxCoupon = wxCouponService.getById(record.getCouponId()); if (wxCoupon.getValidType() == 1) { //时间范围 if (new Date().after(wxCoupon.getValidEndDate())) { - return; + return new ResultData(Result.ERROR,"已过期"); } } + //解析前台tags,并转换json String[] arys = record.getTags().split(","); List tagids = new ArrayList<>(); for (int i = 0; i < arys.length; i++) { @@ -75,6 +80,7 @@ public class CouponInjectServiceImpl implements CouponInjectService { } record.setTags(JSON.toJSONString(arys)); + //生成雪花id final IdWorker idWorker = new IdWorker(0, 0); record.setId(idWorker.nextId()); if(record.getSendType()==0){ @@ -84,44 +90,60 @@ public class CouponInjectServiceImpl implements CouponInjectService { record.setStatus(0); } List cUsers = wxCUserTagsService.findUserByTag(tagids); + int inventory = wxCoupon.getRemainInventory();//库存数量 + if(cUsers.size()>inventory){ + return new ResultData(Result.ERROR,"库存不足"); + } record.setSendAmount(cUsers.size()); couponInjectMapper.insertSelective(record); if(record.getSendType()==0) { - sendNow(wxCoupon,cUsers); + sendNow(wxCoupon,cUsers,record.getId()); } - - + return new ResultData(); } - private void sendNow(WxCoupon wxCoupon,List cUsers){ + private void sendNow(WxCoupon wxCoupon,List cUsers,Long couponInjectId){ //查询标签用户 + int sendRealAmount=0; for (WxCUser tempCUser : cUsers) { - sendCouponToUser(tempCUser,wxCoupon); - + int result = sendCouponToUser(tempCUser,wxCoupon,couponInjectId); + sendRealAmount=sendRealAmount+result; } + //修改卡券存库 + wxCoupon.setRemainInventory(wxCoupon.getRemainInventory()-sendRealAmount); + wxCouponService.saveOrUpdate(wxCoupon); } - private void sendCouponToUser(WxCUser tempCUser,WxCoupon wxCoupon){ + private int sendCouponToUser(WxCUser tempCUser,WxCoupon wxCoupon,Long couponInjectId) { + int injectResult = 0;//0注入不成功,1注入卡包成功 try { - WxCouponOrder wxCouponOrder = new WxCouponOrder(); - wxCouponOrder.setCouponId(wxCoupon.getId()); - wxCouponOrder.setCouponOrderStatus(0); - wxCouponOrder.setCUserId(tempCUser.getId()); - wxCouponOrder.setCouponPrice(0); - wxCouponOrder.setCreateDate(new Date()); - if (wxCoupon.getValidType() == 1) { //时间范围区间 - wxCouponOrder.setExpiredTime(wxCoupon.getValidEndDate()); - } else { - Date date = DateUtils.addDays(new Date(), wxCoupon.getValidDays()); - wxCouponOrder.setExpiredTime(date); - } - wxCouponOrder.setTenantId(wxCoupon.getTenantId()); - wxCouponOrderService.saveOrUpdate(wxCouponOrder); - //短信通知 - }catch (Exception e){ - throw e; - + WxCouponOrder wxCouponOrder = new WxCouponOrder(); + wxCouponOrder.setCouponId(wxCoupon.getId()); + wxCouponOrder.setCouponOrderStatus(0); + wxCouponOrder.setCUserId(tempCUser.getId()); + wxCouponOrder.setCouponPrice(0); + wxCouponOrder.setCreateDate(new Date()); + if (wxCoupon.getValidType() == 1) { //时间范围区间 + wxCouponOrder.setExpiredTime(wxCoupon.getValidEndDate()); + } else { + Date date = DateUtils.addDays(new Date(), wxCoupon.getValidDays()); + wxCouponOrder.setExpiredTime(date); + } + wxCouponOrder.setTenantId(wxCoupon.getTenantId()); + Long couponOrderId = wxCouponOrderService.insertOne(wxCouponOrder); + injectResult = 1; + wxCouponActionLogService.addOne(wxCoupon.getTenantId(), wxCoupon.getId(), couponOrderId, 0, couponInjectId); + return injectResult; + //短信通知 + } catch (Exception e) { + if(injectResult==0) { + logger.error("注入用户券包异常 :"+tempCUser.getId()+"|"+e.getMessage()); + return injectResult; + } + logger.error("调用短信接口异常 :"+tempCUser.getId()+"|"+e.getMessage()); + return injectResult; } } + } diff --git a/mallinkService/src/main/java/com/simple/service/impl/WxCouponActionLogServiceImpl.java b/mallinkService/src/main/java/com/simple/service/impl/WxCouponActionLogServiceImpl.java index 788336530..74a03e6a6 100644 --- a/mallinkService/src/main/java/com/simple/service/impl/WxCouponActionLogServiceImpl.java +++ b/mallinkService/src/main/java/com/simple/service/impl/WxCouponActionLogServiceImpl.java @@ -43,12 +43,17 @@ public class WxCouponActionLogServiceImpl implements WxCouponActionLogService { public void deleteById(Long id) { wxCouponActionLogMapper.deleteByPrimaryKey(id); } - - - - - - - - + + @Override + public void addOne(String tenantId, Long couponId, Long coupon_order_id, int channelType, Long channelId) { + WxCouponActionLog actionLog = new WxCouponActionLog(); + actionLog.setTenantId(tenantId); + actionLog.setChannelId(channelId); + actionLog.setCouponOrderId(coupon_order_id); + actionLog.setChannelType(channelType); + actionLog.setCreatetime(new Date()); + saveOrUpdate(actionLog); + } + + } diff --git a/mallinkService/src/main/resources/mapper/WxCouponActionLogMapper.xml b/mallinkService/src/main/resources/mapper/WxCouponActionLogMapper.xml index b98283a88..19f6d2946 100644 --- a/mallinkService/src/main/resources/mapper/WxCouponActionLogMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxCouponActionLogMapper.xml @@ -5,13 +5,14 @@ - - - + + + + - `id`,`tenant_id`,`coupon_id`,`user_id`,`action`,`operation_time` + `id`,`tenant_id`,`coupon_id`,`coupon_order_id`,`channel_type`,`channel_id`,`createtime` @@ -32,18 +33,23 @@ - - and `user_id` = #{userId} + + and `coupon_order_id` = #{couponOrderId} - - and `action` like concat('%', #{action},'%') + + and `channel_type` = #{channelType} - - and `operation_time` = #{operationTime} + + and `channel_id` = #{channelId} + + + + + and `createtime` = #{createtime}