From cbd6e9a23465f66e18d6a36fe7022d1384b164a2 Mon Sep 17 00:00:00 2001 From: Burce Date: Tue, 27 Aug 2019 14:17:13 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=9F=E6=97=A5=E7=A7=AF=E5=88=86=E5=AE=9A?= =?UTF-8?q?=E6=97=B6=E4=BB=BB=E5=8A=A1=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/WxCouponSendServiceImpl.java | 47 ++++++++++--------- 1 file changed, 25 insertions(+), 22 deletions(-) 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 f1c57d16c..9040be663 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponSendServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponSendServiceImpl.java @@ -489,19 +489,8 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { public void saveOrUpdateConfig(Integer beforeDays, Integer sendType, String tenantId) { 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(); - couponSendQuery.setId(idWorker.nextId()); - couponSendQuery.setStatus(EnumCouponSendStatus.INVALID.getCode()); - couponSendQuery.setCreateDate(new Date()); - JSONObject couponSendJo = new JSONObject(); - couponSendJo.put(WxCouponSend.KEY_BEFOREDAYS, beforeDays); - couponSendQuery.setConditions(couponSendJo.toJSONString()); - wxCouponSendMapper.insertSelective(couponSendQuery); + WxCouponSend couponSendQuery = createCouponSendQuery(sendType, tenantId) ; + insertCouponSend(beforeDays, couponSendQuery); } else { JSONObject couponSendJo = JSONObject.parseObject(config.getConditions()); if (Objects.isNull(couponSendJo)) { @@ -514,25 +503,39 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { } } + private void insertCouponSend(Integer beforeDays, WxCouponSend couponSendQuery) { + couponSendQuery.setTitle(EnumCouponSendSendType.BIRTHDAY.getMessage() + "配置信息 "); + final IdWorker idWorker = IdWorker.get(); + couponSendQuery.setId(idWorker.nextId()); + couponSendQuery.setCreateDate(new Date()); + JSONObject couponSendJo = new JSONObject(); + couponSendJo.put(WxCouponSend.KEY_BEFOREDAYS, beforeDays); + couponSendQuery.setConditions(couponSendJo.toJSONString()); + wxCouponSendMapper.insertSelective(couponSendQuery); + } + @Override public WxCouponSend getConfig(Integer sendType, String tenantId) { - WxCouponSend couponSendQuery = new WxCouponSend(); - couponSendQuery.setSendType(sendType); - couponSendQuery.setTenantId(tenantId); - couponSendQuery.setCouponId(0L); + WxCouponSend couponSendQuery = createCouponSendQuery(sendType, tenantId) ; //读取会员生日券配置信息 - couponSendQuery.setStatus(EnumCouponSendStatus.INVALID.getCode()); List wxCouponSendList = wxCouponSendMapper.select(couponSendQuery); if (CollectionUtils.isEmpty(wxCouponSendList)) { - //默认配置 - JSONObject couponSendJo = new JSONObject(); - couponSendJo.put(WxCouponSend.KEY_BEFOREDAYS, 0); - couponSendQuery.setConditions(couponSendJo.toJSONString()); + //配置不存在,添加默认配置 + insertCouponSend(0, couponSendQuery); return couponSendQuery; } return wxCouponSendList.get(0); } + private WxCouponSend createCouponSendQuery(Integer sendType, String tenantId) { + WxCouponSend couponSendQuery = new WxCouponSend(); + couponSendQuery.setSendType(sendType); + couponSendQuery.setTenantId(tenantId); + couponSendQuery.setCouponId(0L); + couponSendQuery.setStatus(EnumCouponSendStatus.INVALID.getCode()); + return couponSendQuery ; + } + @Override public void reduceMerchantRemainInventory(Long id, Integer remainInventory, Integer number) { int num = wxCouponSendMapper.reduceMerchantRemainInventory(id, remainInventory, number);