| @@ -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更新接口") | |||
| @@ -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<String> ids; | |||
| @Transient | |||
| protected String sortColumns; | |||
| protected Long id; | |||
| @Transient | |||
| protected List<Long> 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<String> getIds() { | |||
| public List<Long> getIds() { | |||
| return ids; | |||
| } | |||
| public void setIds(List<String> ids) { | |||
| public void setIds(List<Long> 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())) { | |||
| @@ -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); | |||
| @@ -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); | |||
| @@ -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<Long> 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<WxCUser> 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<WxCUser> cUsers){ | |||
| private void sendNow(WxCoupon wxCoupon,List<WxCUser> 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; | |||
| } | |||
| } | |||
| } | |||
| @@ -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); | |||
| } | |||
| } | |||
| @@ -5,13 +5,14 @@ | |||
| <id column="id" jdbcType="BIGINT" property="id" /> | |||
| <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" /> | |||
| <result column="coupon_id" jdbcType="BIGINT" property="couponId" /> | |||
| <result column="user_id" jdbcType="BIGINT" property="userId" /> | |||
| <result column="action" jdbcType="VARCHAR" property="action" /> | |||
| <result column="operation_time" jdbcType="TIMESTAMP" property="operationTime" /> | |||
| <result column="coupon_order_id" jdbcType="BIGINT" property="couponOrderId" /> | |||
| <result column="channel_type" jdbcType="INTEGER" property="channelType" /> | |||
| <result column="channel_id" jdbcType="BIGINT" property="channelId" /> | |||
| <result column="createtime" jdbcType="TIMESTAMP" property="createtime" /> | |||
| </resultMap> | |||
| <sql id="allColumns"> | |||
| `id`,`tenant_id`,`coupon_id`,`user_id`,`action`,`operation_time` | |||
| `id`,`tenant_id`,`coupon_id`,`coupon_order_id`,`channel_type`,`channel_id`,`createtime` | |||
| </sql> | |||
| <sql id="dynamicWhereConditions"> | |||
| @@ -32,18 +33,23 @@ | |||
| </if> | |||
| <if test=" null != userId "> | |||
| and `user_id` = #{userId} | |||
| <if test=" null != couponOrderId "> | |||
| and `coupon_order_id` = #{couponOrderId} | |||
| </if> | |||
| <if test=" null != action "> | |||
| and `action` like concat('%', #{action},'%') | |||
| <if test=" null != channelType "> | |||
| and `channel_type` = #{channelType} | |||
| </if> | |||
| <if test=" null != operationTime "> | |||
| and `operation_time` = #{operationTime} | |||
| <if test=" null != channelId "> | |||
| and `channel_id` = #{channelId} | |||
| </if> | |||
| <if test=" null != createtime "> | |||
| and `createtime` = #{createtime} | |||
| </if> | |||
| <if test=" null != ids "> | |||