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 c4363da37..eda708e9c 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponSendController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponSendController.java @@ -57,13 +57,13 @@ public class WxCouponSendController extends BaseController { if (null == wxCouponSend) wxCouponSend = new WxCouponSend(); wxCouponSend.setTenantId(getTenantId()); Integer valid = EnumCouponSendStatus.VALID.getCode(); - if (Objects.equals(EnumCouponSendSendType.MERCHANT.getCode(), wxCouponSend.getSendType())) { - if (Objects.nonNull(wxCouponSend.getStatus())) { - valid = wxCouponSend.getStatus(); - } else { - wxCouponSend.setStatus(null); - } - } +// if (Objects.equals(EnumCouponSendSendType.MERCHANT.getCode(), wxCouponSend.getSendType())) { +// if (Objects.nonNull(wxCouponSend.getStatus())) { +// valid = wxCouponSend.getStatus(); +// } else { +// wxCouponSend.setStatus(null); +// } +// } wxCouponSend.setStatus(valid); wxCouponSend.setSortColumns(BaseEntity.SortField.CreateDate_DESC); PageInfo page = wxCouponSendService.listAsPage(wxCouponSend, pageNum, pageSize); @@ -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") @@ -143,14 +143,13 @@ public class WxCouponSendController extends BaseController { @ApiImplicitParam(name = "sendType", value = "注券类型(会员生日券时必传)", dataType = "int", paramType = "query") }) @SystemControllerLog(description = "注券-删除") - public ResultData delete(Long id,Integer sendType) { + 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 c3f1e8b2f..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") @@ -74,4 +79,8 @@ public class WxCouponSend extends BaseEntity { @io.swagger.annotations.ApiModelProperty(value = "1是0否", name = "是否发送短信1是0否") private Integer sendSms; + @io.swagger.annotations.ApiModelProperty(value = "0未过期1已过期,全部时不传", name = "expired" ) + @Transient + private Integer expired; + } diff --git a/mallinkService/src/main/java/com/iformall/mapper/WxCouponSendMapper.java b/mallinkService/src/main/java/com/iformall/mapper/WxCouponSendMapper.java index 4f3cca2a9..aaff7dba7 100644 --- a/mallinkService/src/main/java/com/iformall/mapper/WxCouponSendMapper.java +++ b/mallinkService/src/main/java/com/iformall/mapper/WxCouponSendMapper.java @@ -8,7 +8,7 @@ import com.iformall.domain.vo.WxCouponSendVo; public interface WxCouponSendMapper extends CommonMapper { List findListVo(WxCouponSend wxCouponSend); - List findListVoFilterName(WxCouponSend wxCouponSend); + List findListVoByNameAndDate(WxCouponSend wxCouponSend); void updateStatusByCouponId(WxCouponSend wxCouponSend); 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/java/com/iformall/service/WxCouponService.java b/mallinkService/src/main/java/com/iformall/service/WxCouponService.java index 28f15fc7b..dffc887e8 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxCouponService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxCouponService.java @@ -213,7 +213,7 @@ public interface WxCouponService { void reduceRemainInventory(Long id, Integer remainInventory, Integer number); /** - * 库存回退 + * 库存退回 * * @param id 券ID * @param remainInventory 当前库存 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 dc2ee7115..39b39c4ef 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponSendServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponSendServiceImpl.java @@ -7,7 +7,6 @@ import com.github.pagehelper.PageInfo; import com.google.common.collect.Lists; import com.iformall.common.ErrorCode; import com.iformall.common.IdWorker; -import com.iformall.common.ResultData; import com.iformall.domain.po.*; import com.iformall.domain.po.msg.AppUniformMsg; import com.iformall.domain.po.msg.MpAppMsg; @@ -26,7 +25,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Isolation; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; @@ -34,7 +32,7 @@ import java.text.SimpleDateFormat; import java.util.*; @Service -public class WxCouponSendServiceImpl implements WxCouponSendService { + public class WxCouponSendServiceImpl implements WxCouponSendService { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @Autowired @@ -71,7 +69,7 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { PageInfo pageInfo; //设置商户购买券数 if (Objects.equals(EnumCouponSendSendType.MERCHANT.getCode(), record.getSendType())) { - pageInfo = PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxCouponSendMapper.findListVoFilterName(record)); + pageInfo = PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxCouponSendMapper.findListVoByNameAndDate(record)); for (WxCouponSendVo cs : pageInfo.getList()) { JSONObject jo = JSONObject.parseObject(cs.getConditions()); int inventory = jo.getInteger(WxCouponSend.KEY_MERCHANT_LNVENTORY); @@ -98,22 +96,23 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { record.setConditions(config.getConditions()); } } - //商户卡库存校验 if(Objects.equals(record.getSendType(),EnumCouponSendSendType.MERCHANT.getCode())) { JSONObject jo = JSONObject.parseObject(record.getConditions()) ; if(Objects.isNull(jo)||!jo.containsKey(WxCouponSend.KEY_MERCHANT_LNVENTORY)) { - throw new BizMessageException(ErrorCode.COUPON_SEND_LIMIT_VERIFY.getMessage()) ; + throw new MallinkException(ErrorCode.COUPON_SEND_LIMIT_VERIFY) ; } + //查询总库存 WxCoupon queryById = new WxCoupon() ; - queryById.setId(record.getId()); + queryById.setId(record.getCouponId()); WxCoupon wxCouponOfDb = wxCouponService.findById(queryById); if(Objects.isNull(wxCouponOfDb)) { - throw new BizMessageException(ErrorCode.COUPON_IS_EMPTY.getMessage()) ; + throw new MallinkException(ErrorCode.COUPON_IS_EMPTY) ; } int merchantLnventory = jo.getInteger(WxCouponSend.KEY_MERCHANT_LNVENTORY) ; + //商家购券数不能大于总库存 if(merchantLnventory > wxCouponOfDb.getRemainInventory()) { - throw new BizMessageException(ErrorCode.REMAIN_IS_EMPTY.getMessage()) ; + throw new MallinkException(ErrorCode.REMAIN_IS_EMPTY) ; } //更新库存 wxCouponService.reduceRemainInventory(wxCouponOfDb.getId(),wxCouponOfDb.getRemainInventory(),merchantLnventory); @@ -128,52 +127,29 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { } } - /** - * 会员生日券处理 - * - * @param record - * @return - */ - private WxCouponSend buildConditions(WxCouponSend record) { - if (!Objects.equals(record.getSendType(), EnumCouponSendSendType.BIRTHDAY.getCode())) { - return record; - } - - //添加会员生日券 - JSONObject conditions = JSONObject.parseObject(record.getConditions()); - Long couponId = record.getCouponId(); - if (Objects.nonNull(couponId)) { - JSONArray couponIds; - if (Objects.isNull(record.getId())) { - //添加默认值 - if (Objects.isNull(record.getTitle())) { - record.setTitle(""); - } - if (Objects.isNull(record.getCouponId())) { - record.setCouponId(0L); - } - //添加新卡券 - couponIds = new JSONArray(); - couponIds.add(couponId); - } else { - //更新卡券列表 - WxCouponSend couponSend = wxCouponSendMapper.selectByPrimaryKey(record.getId()); - conditions = JSONObject.parseObject(couponSend.getConditions()); - couponIds = conditions.getJSONArray(WxCouponSend.KEY_COUPONIDS); - if (Objects.isNull(couponIds)) { - couponIds = new JSONArray(); - couponIds.add(couponId); - } else { - //添加新卡券 - if (!couponIds.contains(couponId)) { - couponIds.add(couponId); - } - } + @Override + @Transactional(propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) + public void updateInvalid(WxCouponSend record) { + record.setStatus(EnumCouponSendStatus.INVALID.getCode()); + record.setUpdateDate(new Date()); + if(Objects.equals(record.getSendType(),EnumCouponSendSendType.MERCHANT.getCode())) { + //查询总库存 + WxCoupon queryById = new WxCoupon() ; + queryById.setId(record.getCouponId()); + WxCoupon wxCouponOfDb = wxCouponService.findById(queryById); + if(Objects.isNull(wxCouponOfDb)) { + throw new MallinkException(ErrorCode.COUPON_IS_EMPTY) ; + } + //查询商家 + JSONObject jo = JSONObject.parseObject(record.getConditions()) ; + if(Objects.isNull(jo)||!jo.containsKey(WxCouponSend.KEY_MERCHANT_LNVENTORY)) { + throw new MallinkException(ErrorCode.COUPON_SEND_LIMIT_VERIFY) ; } - conditions.put(WxCouponSend.KEY_COUPONIDS, couponIds); + int merchantLnventory = jo.getInteger(WxCouponSend.KEY_MERCHANT_LNVENTORY) ; + //退回库存 + wxCouponService.backRemainInventory(queryById.getId(),wxCouponOfDb.getRemainInventory(),merchantLnventory); } - record.setConditions(conditions.toJSONString()); - return record; + wxCouponSendMapper.updateByPrimaryKeySelective(record); } @Override @@ -496,34 +472,30 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { @Override public void saveOrUpdateConfig(Integer beforeDays, Integer sendType, String tenantId) { - WxCouponSend couponSendQuery = new WxCouponSend(); - couponSendQuery.setSendType(sendType); - couponSendQuery.setTenantId(tenantId); - List wxCouponSendList = wxCouponSendMapper.select(couponSendQuery); - if (CollectionUtils.isEmpty(wxCouponSendList)) { - WxCouponSend couponSend = new WxCouponSend(); - couponSend.setTitle(EnumCouponSendSendType.BIRTHDAY.getMessage()+"配置信息 "); - couponSend.setCouponId(0L); - couponSend.setSendType(sendType); + WxCouponSend config = getConfig(sendType, tenantId) ; + if (Objects.isNull(config)) { + WxCouponSend couponSendQuery = new WxCouponSend(); + couponSendQuery.setSendType(sendType); + couponSendQuery.setTenantId(tenantId); + couponSendQuery.setCouponId(0L); + couponSendQuery.setTitle(EnumCouponSendSendType.BIRTHDAY.getMessage()+"配置信息 "); final IdWorker idWorker = IdWorker.get(); - couponSend.setId(idWorker.nextId()); - couponSend.setTenantId(tenantId); - couponSend.setStatus(EnumCouponSendStatus.INVALID.getCode()); - couponSend.setCreateDate(new Date()); + couponSendQuery.setId(idWorker.nextId()); + couponSendQuery.setStatus(EnumCouponSendStatus.INVALID.getCode()); + couponSendQuery.setCreateDate(new Date()); JSONObject couponSendJo = new JSONObject(); couponSendJo.put(WxCouponSend.KEY_BEFOREDAYS, beforeDays); - couponSend.setConditions(couponSendJo.toJSONString()); - wxCouponSendMapper.insertSelective(couponSend); + couponSendQuery.setConditions(couponSendJo.toJSONString()); + wxCouponSendMapper.insertSelective(couponSendQuery); } else { - WxCouponSend couponSend = wxCouponSendList.get(0); - JSONObject couponSendJo = JSONObject.parseObject(couponSend.getConditions()); + JSONObject couponSendJo = JSONObject.parseObject(config.getConditions()); if(Objects.isNull(couponSendJo)) { couponSendJo = new JSONObject(); } couponSendJo.put(WxCouponSend.KEY_BEFOREDAYS, beforeDays); - couponSend.setConditions(couponSendJo.toJSONString()); - couponSend.setUpdateDate(new Date()); - wxCouponSendMapper.updateBirthdayConfig(couponSend); + config.setConditions(couponSendJo.toJSONString()); + config.setUpdateDate(new Date()); + wxCouponSendMapper.updateBirthdayConfig(config); } } @@ -537,7 +509,11 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { couponSendQuery.setStatus(EnumCouponSendStatus.INVALID.getCode()); List wxCouponSendList = wxCouponSendMapper.select(couponSendQuery); if (CollectionUtils.isEmpty(wxCouponSendList)) { - return null; + //默认配置 + JSONObject couponSendJo = new JSONObject(); + couponSendJo.put(WxCouponSend.KEY_BEFOREDAYS, 0); + couponSendQuery.setConditions(couponSendJo.toJSONString()); + return couponSendQuery; } return wxCouponSendList.get(0); } diff --git a/mallinkService/src/main/resources/mapper/WxCouponSendMapper.xml b/mallinkService/src/main/resources/mapper/WxCouponSendMapper.xml index 9749afc6f..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} @@ -98,14 +104,22 @@ - select tt.* from (select from wx_coupon_send cs left join wx_coupon c on c.id = cs.coupon_id ) as tt - - where tt.conditions like concat('%', #{merchantName},'%') - + where 1=1 + + + and + + + and now() ]]> + + + +