From f65552fcfd5386ad3e753ae0f6091f69bb735df3 Mon Sep 17 00:00:00 2001 From: Burce Date: Thu, 22 Aug 2019 14:48:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E6=88=B7=E6=B3=A8=E5=88=B8->=E8=BF=87?= =?UTF-8?q?=E6=BB=A4=E5=95=86=E6=88=B7=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../market/WxCouponSendConfigController.java | 7 ++- .../market/WxCouponSendController.java | 25 ++++++----- .../controller/WxCouponSendController.java | 35 ++++++++++++--- .../iformall/schedule/CouponSendSchedule.java | 43 +++++++++++-------- .../com/iformall/domain/po/WxCouponSend.java | 7 ++- .../iformall/service/WxCouponSendService.java | 6 +++ .../resources/mapper/WxCouponSendMapper.xml | 15 ++++--- 7 files changed, 93 insertions(+), 45 deletions(-) diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponSendConfigController.java b/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponSendConfigController.java index b3b4558a8..d14b77756 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponSendConfigController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponSendConfigController.java @@ -6,6 +6,7 @@ import com.iformall.common.ErrorCode; import com.iformall.common.ResultData; import com.iformall.controller.base.BaseController; import com.iformall.domain.po.WxCouponSendConfig; +import com.iformall.enums.EnumCouponSendSendType; import com.iformall.service.WxCouponSendConfigService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -37,8 +38,12 @@ public class WxCouponSendConfigController extends BaseController { PageInfo page = wxCouponSendConfigService.listAsPage(wxCouponSendConfig, 1, 1); if (page.getSize() > 0) { return new ResultData(page.getList().get(0)); + } else { + //默认停用 + wxCouponSendConfig.setRemark(EnumCouponSendSendType.getEnum(wxCouponSendConfig.getSendType()).getMessage() + "开关"); + wxCouponSendConfig.setValue(0); + return new ResultData(wxCouponSendConfig); } - return new ResultData(); } diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponSendController.java b/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponSendController.java index df6b53d09..eda708e9c 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponSendController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponSendController.java @@ -126,15 +126,15 @@ public class WxCouponSendController extends BaseController { return new ResultData(); } - @ApiOperation("根据id更新接口") - @PostMapping("update") - @SystemControllerLog(description = "注券-更新") - public ResultData update(@RequestBody WxCouponSend wxCouponSend) { - logger.debug("[" + getIpAddr() + "] WxCouponSendController::update"); - wxCouponSend.setTenantId(getTenantId()); - wxCouponSendService.saveOrUpdate(wxCouponSend); - return new ResultData(); - } +// @ApiOperation("根据id更新接口") +// @PostMapping("update") +// @SystemControllerLog(description = "注券-更新") +// public ResultData update(@RequestBody WxCouponSend wxCouponSend) { +// logger.debug("[" + getIpAddr() + "] WxCouponSendController::update"); +// wxCouponSend.setTenantId(getTenantId()); +// wxCouponSendService.saveOrUpdate(wxCouponSend); +// return new ResultData(); +// } @ApiOperation("根据id删除接口") @GetMapping("/del") @@ -146,11 +146,10 @@ public class WxCouponSendController extends BaseController { public ResultData delete(Long id) { logger.debug("[" + getIpAddr() + "] WxCouponSendController::delete"); WxCouponSend wxCouponSend = wxCouponSendService.getById(id); - if (wxCouponSend == null) + if (wxCouponSend == null) { return new ResultData(ErrorCode.COUPON_SEND_IS_INVALID); - wxCouponSend.setStatus(EnumCouponSendStatus.INVALID.getCode()); - wxCouponSend.setUpdateDate(new Date()); - wxCouponSendService.saveOrUpdate(wxCouponSend); + } + wxCouponSendService.updateInvalid(wxCouponSend); return new ResultData(); } diff --git a/mallinkBApi/src/main/java/com/iformall/controller/WxCouponSendController.java b/mallinkBApi/src/main/java/com/iformall/controller/WxCouponSendController.java index 1b319a30d..62e4fc38e 100644 --- a/mallinkBApi/src/main/java/com/iformall/controller/WxCouponSendController.java +++ b/mallinkBApi/src/main/java/com/iformall/controller/WxCouponSendController.java @@ -1,17 +1,20 @@ package com.iformall.controller; import com.github.pagehelper.PageInfo; +import com.iformall.common.ErrorCode; import com.iformall.common.ResultData; import com.iformall.domain.po.BaseEntity; import com.iformall.domain.po.WxCouponSend; import com.iformall.domain.vo.WxCouponSendVo; import com.iformall.enums.EnumCouponSendStatus; +import com.iformall.exception.MallinkException; import com.iformall.service.WxCouponActionLogService; import com.iformall.service.WxCouponSendService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; +import org.apache.commons.lang3.ArrayUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -19,9 +22,12 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import javax.validation.constraints.NotNull; +import java.util.Objects; + @RestController @RequestMapping("/api/couponSend") -@Api(description = "商户卡券相关接口") +@Api(description = "商户注券相关接口") public class WxCouponSendController extends BaseController { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @@ -30,19 +36,20 @@ public class WxCouponSendController extends BaseController { @Autowired private WxCouponActionLogService wxCouponActionLogService; - @ApiOperation("查询商户卡券列表") + @ApiOperation("查询商户注券列表") @GetMapping("/list") @ApiImplicitParams({ @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true), - @ApiImplicitParam(name = "sendType", value = "2:停车发券 3:核销发券 4: B端刷卡发券 5:商户发卷 6:定时发券 7:商户发券", dataType = "int", paramType = "query",required = true), + @ApiImplicitParam(name = "merchantId", value = "商户ID", dataType = "long", paramType = "query",required = true), }) - public ResultData list(Integer sendType, Integer pageNum, Integer pageSize) { + public ResultData list(WxCouponSend wxCouponSend, Integer pageNum, Integer pageSize) { logger.debug("[" + getIpAddr() + "] WxCouponSendController::list"); - WxCouponSend wxCouponSend = new WxCouponSend(); - wxCouponSend.setSendType(sendType); + if (Objects.isNull(wxCouponSend.getMerchantId()) || Objects.equals(wxCouponSend.getMerchantId(), 0) || Objects.isNull(wxCouponSend.getSendType())) { + throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL); + } wxCouponSend.setTenantId(getTenantId()); - wxCouponSend.setStatus(EnumCouponSendStatus.VALID.getCode()); + wxCouponSend.setStatus(Objects.isNull(wxCouponSend.getStatus()) ? null : wxCouponSend.getStatus()); //库存大于0 wxCouponSend.setMerchantLnventory(0); wxCouponSend.setSortColumns(BaseEntity.SortField.CreateDate_DESC); @@ -54,4 +61,18 @@ public class WxCouponSendController extends BaseController { return new ResultData(page); } + @ApiOperation("商户注券") + @GetMapping("/handsel") + @ApiImplicitParams({ + @ApiImplicitParam(name = "wxCouponSendId", value = "wxCouponSendId", dataType = "long", paramType = "query",required = true), + @ApiImplicitParam(name = "cUserId", value = "用户ID", dataType = "long", paramType = "query",required = true), + }) + public ResultData handsel(Long[] wxCouponSendIds,Long cUserId) { + if(ArrayUtils.isEmpty(wxCouponSendIds)||Objects.isNull(cUserId)) { + throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL); + } + return new ResultData(); + } + + } diff --git a/mallinkSchedule/src/main/java/com/iformall/schedule/CouponSendSchedule.java b/mallinkSchedule/src/main/java/com/iformall/schedule/CouponSendSchedule.java index b4ba40ce7..8981125bf 100644 --- a/mallinkSchedule/src/main/java/com/iformall/schedule/CouponSendSchedule.java +++ b/mallinkSchedule/src/main/java/com/iformall/schedule/CouponSendSchedule.java @@ -257,20 +257,27 @@ public class CouponSendSchedule { return; } - WxCouponSend config = wxCouponSendService.getConfig(EnumCouponSendSendType.BIRTHDAY.getCode(), cu.getTenantId()); - if (Objects.isNull(config) || Objects.isNull(config.getConditions())) { - logger.info("生日发券: 会员生日券配置不存在 config = {}, 任务跳过不执行", config); - return; - } - - //默认生日当天发送 - int beforeDays = 0; - JSONObject configJo = JSONObject.parseObject(config.getConditions()); - if (configJo.containsKey(WxCouponSend.KEY_BEFOREDAYS)) { - beforeDays = configJo.getIntValue(WxCouponSend.KEY_BEFOREDAYS); - } +// WxCouponSend config = wxCouponSendService.getConfig(EnumCouponSendSendType.BIRTHDAY.getCode(), cu.getTenantId()); +// + boolean sent = false; for (WxCouponSendVo cs : couponSendList) { + String conditions = cs.getConditions(); + JSONObject configJo = null; + try { + configJo = JSONObject.parseObject(conditions); + } catch (Exception e) { + logger.error("生日发券: 解析conditions异常: {}",e.getMessage()); + } + if (Objects.isNull(conditions)||Objects.isNull(configJo)) { + logger.info("生日发券: 会员生日券配置不存在 conditions = {}, 任务跳过不执行", conditions); + return; + } + //默认生日当天发送 + int beforeDays = 0; + if (configJo.containsKey(WxCouponSend.KEY_BEFOREDAYS)) { + beforeDays = configJo.getIntValue(WxCouponSend.KEY_BEFOREDAYS); + } Map params = new HashMap<>(); params.put("tenantId", cs.getTenantId()); params.put("cUserId", cu.getId()); @@ -287,7 +294,8 @@ public class CouponSendSchedule { continue; } //提前n天发送生日券,不满足跳过不执行 - if (DateUtils.birthdaysBetween(cu.getBirthdate()) == beforeDays) { + if (DateUtils.birthdaysBetween(cu.getBirthdate()) != beforeDays) { + logger.info("生日发券: [会员={},生日={}不满足提前{}天发券]", cu.getNickName(), cu.getBirthdate(),beforeDays); continue; } if (cs.getRemainInventory() <= 0) { @@ -297,14 +305,12 @@ public class CouponSendSchedule { // 发放免费券 try { WxCouponOrder couponOrder = wxOrderService.sendFreeCouponToUser(cu.getId(), cs.getCouponId()); - sendSMS(cu, mall); wxCouponActionLogService.addOne(cu.getTenantId(), cs.getCouponId(), couponOrder.getId(), cs.getSendType(), cs.getId()); } catch (Exception e) { logger.error("定时发券:发券失败 levelId=" + cu.getId() + " couponId=" + cs.getCouponId() + " userId=" + cu.getId() + e.getMessage()); - logger.info("定时发券:发券失败 levelId=" + cu.getId() + " couponId=" + cs.getCouponId() + " userId=" + cu.getId() + e.getMessage()); continue; } - + sent = true ; logger.info("定时发券:商场[" + mall.getName() + "]会员生日[" + cu.getBirthdate().toInstant() + "]发送券[" + cs.getTitle() + @@ -312,6 +318,9 @@ public class CouponSendSchedule { " 电话-" + cu.getPhone() + " id-" + cu.getId()); } + if(sent) { + sendSMS(cu, mall); + } }); }); logger.info("生日发券: 任务结束"); @@ -352,7 +361,7 @@ public class CouponSendSchedule { //没有配置积分规则 wxMsgRecord.setModelType(EnumMsgModel.COUPON_BIRTHDAY_OPENED_NO.getCode()); } - dynamicContentMap.put("userName", cUserBasicInfo.getNickName()); + dynamicContentMap.put("userName", Objects.isNull(cUserBasicInfo.getNickName()) ? "" : cUserBasicInfo.getNickName()); dynamicContentMap.put("mallName", mall.getName()); wxMsgRecord.setDynamicContentMap(dynamicContentMap); mqBaseProducer.sendMessage(wxMsgRecord, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxCouponSend.java b/mallinkService/src/main/java/com/iformall/domain/po/WxCouponSend.java index db1964939..a05388604 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxCouponSend.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxCouponSend.java @@ -47,6 +47,11 @@ public class WxCouponSend extends BaseEntity { /**发卷所属商户名**/ @Transient private String merchantName; + /** + * 商户ID + */ + @Transient + private Long merchantId; @io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId") private String tenantId; @@ -59,7 +64,7 @@ public class WxCouponSend extends BaseEntity { private Integer sendType; @io.swagger.annotations.ApiModelProperty(value="发券条件",name="condition") private String conditions; - @io.swagger.annotations.ApiModelProperty(value="0:有效 1:无效",name="status") + @io.swagger.annotations.ApiModelProperty(value="0:有效 1:无效,全部时不传",name="status") private Integer status; @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createDate") diff --git a/mallinkService/src/main/java/com/iformall/service/WxCouponSendService.java b/mallinkService/src/main/java/com/iformall/service/WxCouponSendService.java index eed2e76e2..e3416082e 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxCouponSendService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxCouponSendService.java @@ -34,6 +34,12 @@ public interface WxCouponSendService { */ void saveOrUpdate(WxCouponSend record); + /** + * 更新为无效 + * @param record + */ + void updateInvalid(WxCouponSend record) ; + /** * 根据Id删除实体 * diff --git a/mallinkService/src/main/resources/mapper/WxCouponSendMapper.xml b/mallinkService/src/main/resources/mapper/WxCouponSendMapper.xml index ba52c30cb..9feb9b823 100644 --- a/mallinkService/src/main/resources/mapper/WxCouponSendMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxCouponSendMapper.xml @@ -77,6 +77,15 @@ and cs.update_date = #{updateDate} + + and cs.conditions -> '$.title' like concat('%',#{merchantName},'%') + + + and cs.conditions->'$.id' = concat(#{merchantId},'') + + + and cs.conditions -> '$.merchantLnventory'> #{merchantLnventory} + and id in @@ -87,9 +96,6 @@ and cs.send_sms = #{sendSms} - - and c.remain_inventory > #{merchantLnventory} - order by ${sortColumns} @@ -104,9 +110,6 @@ from wx_coupon_send cs left join wx_coupon c on c.id = cs.coupon_id ) as tt where 1=1 - - and tt.conditions like concat('%', #{merchantName},'%') - and