From 746550967b217df79c5a360239760bd7edcb2421 Mon Sep 17 00:00:00 2001 From: Stormeye Wu Date: Wed, 23 Oct 2019 20:15:36 +0800 Subject: [PATCH] =?UTF-8?q?[C=E7=AB=AF][=E4=BC=98=E5=8C=96]:=E9=A6=96?= =?UTF-8?q?=E9=A1=B5=E5=88=B8=E5=88=97=E8=A1=A8=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/iformall/config/RedisConfig.java | 20 ++++++++ .../market/WxCouponChannelController.java | 1 + .../java/com/iformall/config/RedisConfig.java | 19 +++++++ .../java/com/iformall/config/RedisConfig.java | 20 ++++++++ .../java/com/iformall/config/RedisConfig.java | 20 ++++++++ .../java/com/iformall/config/RedisConfig.java | 20 ++++++++ .../java/com/iformall/config/RedisConfig.java | 20 ++++++++ .../java/com/iformall/config/RedisConfig.java | 20 ++++++++ .../java/com/iformall/enums/EnumCacheKey.java | 49 +++++++++++++++++++ .../java/com/iformall/enums/EnumTargetAd.java | 34 +++++++++++++ .../impl/WxCouponChannelServiceImpl.java | 46 +++++++++++++++++ .../impl/WxCouponInjectServiceImpl.java | 1 - .../impl/WxCouponPasswordServiceImpl.java | 1 - .../service/impl/WxCouponServiceImpl.java | 38 +++++++++++--- .../service/impl/WxFlowServiceImpl.java | 20 ++++++++ .../service/impl/WxOrderServiceImpl.java | 1 - .../main/resources/mapper/WxCouponMapper.xml | 6 ++- .../mapper/WxCouponPasswordMapper.xml | 2 +- .../java/com/iformall/config/RedisConfig.java | 19 +++++++ .../java/com/iformall/config/RedisConfig.java | 20 ++++++++ 20 files changed, 366 insertions(+), 11 deletions(-) create mode 100644 mallinkService/src/main/java/com/iformall/enums/EnumCacheKey.java create mode 100644 mallinkService/src/main/java/com/iformall/enums/EnumTargetAd.java diff --git a/mallinkAdmin/src/main/java/com/iformall/config/RedisConfig.java b/mallinkAdmin/src/main/java/com/iformall/config/RedisConfig.java index 1db11fb55..c42f96575 100644 --- a/mallinkAdmin/src/main/java/com/iformall/config/RedisConfig.java +++ b/mallinkAdmin/src/main/java/com/iformall/config/RedisConfig.java @@ -1,6 +1,8 @@ package com.iformall.config; +import com.github.pagehelper.PageInfo; import com.iformall.domain.po.*; +import com.iformall.domain.vo.WxCouponChannelVo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.cache.CacheManager; @@ -156,6 +158,24 @@ public class RedisConfig extends CachingConfigurerSupport { return template; } + @Bean("couponChannelRedisTemplate") + public RedisTemplate> getCouponChannelRedisTemplate(RedisConnectionFactory connectionFactory) { + RedisTemplate> template = new RedisTemplate<>(); + + Jackson2JsonRedisSerializer j = new Jackson2JsonRedisSerializer(PageInfo.class); + + // value值的序列化 + template.setValueSerializer(j); + template.setHashKeySerializer(j); + + // key的序列化 + template.setKeySerializer(new StringRedisSerializer()); + template.setHashKeySerializer(new StringRedisSerializer()); + + template.setConnectionFactory(connectionFactory); + return template; + } + @Bean("buserTokenRedisTemplate") public RedisTemplate getBuserTokenRedisTemplate(RedisConnectionFactory connectionFactory) { RedisTemplate template = new RedisTemplate(); diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponChannelController.java b/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponChannelController.java index 10999811e..967dfb24a 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponChannelController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponChannelController.java @@ -9,6 +9,7 @@ import com.iformall.controller.app.WxAppinfoController; import com.iformall.controller.base.BaseController; import com.iformall.domain.dto.WxCouponChannelDto; import com.iformall.domain.po.*; +import com.iformall.domain.vo.WxCouponChannelVo; import com.iformall.domain.po.base.BaseEntity; import com.iformall.domain.vo.WxCouponChannelVo; import com.iformall.mapper.WxCouponChannelMapper; diff --git a/mallinkBApi/src/main/java/com/iformall/config/RedisConfig.java b/mallinkBApi/src/main/java/com/iformall/config/RedisConfig.java index 4de091e49..6fbf28e07 100644 --- a/mallinkBApi/src/main/java/com/iformall/config/RedisConfig.java +++ b/mallinkBApi/src/main/java/com/iformall/config/RedisConfig.java @@ -1,6 +1,8 @@ package com.iformall.config; +import com.github.pagehelper.PageInfo; import com.iformall.domain.po.*; +import com.iformall.domain.vo.WxCouponChannelVo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.cache.CacheManager; @@ -119,6 +121,23 @@ public class RedisConfig extends CachingConfigurerSupport { return template; } + @Bean("couponChannelRedisTemplate") + public RedisTemplate> getCouponChannelRedisTemplate(RedisConnectionFactory connectionFactory) { + RedisTemplate> template = new RedisTemplate<>(); + + Jackson2JsonRedisSerializer j = new Jackson2JsonRedisSerializer(PageInfo.class); + // value值的序列化 + template.setValueSerializer(j); + template.setHashKeySerializer(j); + + // key的序列化 + template.setKeySerializer(new StringRedisSerializer()); + template.setHashKeySerializer(new StringRedisSerializer()); + + template.setConnectionFactory(connectionFactory); + return template; + } + @Bean("buserTokenRedisTemplate") public RedisTemplate getBuserTokenRedisTemplate(RedisConnectionFactory connectionFactory) { RedisTemplate template = new RedisTemplate(); diff --git a/mallinkCApi/src/main/java/com/iformall/config/RedisConfig.java b/mallinkCApi/src/main/java/com/iformall/config/RedisConfig.java index 7d4d55f7b..e7426b35c 100644 --- a/mallinkCApi/src/main/java/com/iformall/config/RedisConfig.java +++ b/mallinkCApi/src/main/java/com/iformall/config/RedisConfig.java @@ -1,7 +1,9 @@ package com.iformall.config; +import com.github.pagehelper.PageInfo; import com.iformall.domain.po.*; import com.iformall.domain.vo.WxCouponCVo; +import com.iformall.domain.vo.WxCouponChannelVo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.cache.CacheManager; @@ -137,6 +139,24 @@ public class RedisConfig extends CachingConfigurerSupport { return template; } + @Bean("couponChannelRedisTemplate") + public RedisTemplate> getCouponChannelRedisTemplate(RedisConnectionFactory connectionFactory) { + RedisTemplate> template = new RedisTemplate<>(); + + Jackson2JsonRedisSerializer j = new Jackson2JsonRedisSerializer(PageInfo.class); + + // value值的序列化 + template.setValueSerializer(j); + template.setHashKeySerializer(j); + + // key的序列化 + template.setKeySerializer(new StringRedisSerializer()); + template.setHashKeySerializer(new StringRedisSerializer()); + + template.setConnectionFactory(connectionFactory); + return template; + } + @Bean("buserTokenRedisTemplate") public RedisTemplate getBuserTokenRedisTemplate(RedisConnectionFactory connectionFactory) { RedisTemplate template = new RedisTemplate(); diff --git a/mallinkCallback/src/main/java/com/iformall/config/RedisConfig.java b/mallinkCallback/src/main/java/com/iformall/config/RedisConfig.java index 617d28f17..cd0636c2b 100644 --- a/mallinkCallback/src/main/java/com/iformall/config/RedisConfig.java +++ b/mallinkCallback/src/main/java/com/iformall/config/RedisConfig.java @@ -1,6 +1,8 @@ package com.iformall.config; +import com.github.pagehelper.PageInfo; import com.iformall.domain.po.*; +import com.iformall.domain.vo.WxCouponChannelVo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.cache.CacheManager; @@ -156,6 +158,24 @@ public class RedisConfig extends CachingConfigurerSupport { return template; } + @Bean("couponChannelRedisTemplate") + public RedisTemplate> getCouponChannelRedisTemplate(RedisConnectionFactory connectionFactory) { + RedisTemplate> template = new RedisTemplate<>(); + + Jackson2JsonRedisSerializer j = new Jackson2JsonRedisSerializer(PageInfo.class); + + // value值的序列化 + template.setValueSerializer(j); + template.setHashKeySerializer(j); + + // key的序列化 + template.setKeySerializer(new StringRedisSerializer()); + template.setHashKeySerializer(new StringRedisSerializer()); + + template.setConnectionFactory(connectionFactory); + return template; + } + @Bean("buserTokenRedisTemplate") public RedisTemplate getBuserTokenRedisTemplate(RedisConnectionFactory connectionFactory) { RedisTemplate template = new RedisTemplate(); diff --git a/mallinkMQConsumer/src/main/java/com/iformall/config/RedisConfig.java b/mallinkMQConsumer/src/main/java/com/iformall/config/RedisConfig.java index d5c680387..28d61d711 100644 --- a/mallinkMQConsumer/src/main/java/com/iformall/config/RedisConfig.java +++ b/mallinkMQConsumer/src/main/java/com/iformall/config/RedisConfig.java @@ -1,6 +1,8 @@ package com.iformall.config; +import com.github.pagehelper.PageInfo; import com.iformall.domain.po.*; +import com.iformall.domain.vo.WxCouponChannelVo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.cache.CacheManager; @@ -141,6 +143,24 @@ public class RedisConfig extends CachingConfigurerSupport { return template; } + @Bean("couponChannelRedisTemplate") + public RedisTemplate> getCouponChannelRedisTemplate(RedisConnectionFactory connectionFactory) { + RedisTemplate> template = new RedisTemplate<>(); + + Jackson2JsonRedisSerializer j = new Jackson2JsonRedisSerializer(PageInfo.class); + + // value值的序列化 + template.setValueSerializer(j); + template.setHashKeySerializer(j); + + // key的序列化 + template.setKeySerializer(new StringRedisSerializer()); + template.setHashKeySerializer(new StringRedisSerializer()); + + template.setConnectionFactory(connectionFactory); + return template; + } + @Bean("buserTokenRedisTemplate") public RedisTemplate getBuserTokenRedisTemplate(RedisConnectionFactory connectionFactory) { RedisTemplate template = new RedisTemplate(); diff --git a/mallinkPosApi/src/main/java/com/iformall/config/RedisConfig.java b/mallinkPosApi/src/main/java/com/iformall/config/RedisConfig.java index 63d0bc4ab..17179389e 100644 --- a/mallinkPosApi/src/main/java/com/iformall/config/RedisConfig.java +++ b/mallinkPosApi/src/main/java/com/iformall/config/RedisConfig.java @@ -1,6 +1,8 @@ package com.iformall.config; +import com.github.pagehelper.PageInfo; import com.iformall.domain.po.*; +import com.iformall.domain.vo.WxCouponChannelVo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.cache.CacheManager; @@ -119,6 +121,24 @@ public class RedisConfig extends CachingConfigurerSupport { return template; } + @Bean("couponChannelRedisTemplate") + public RedisTemplate> getCouponChannelRedisTemplate(RedisConnectionFactory connectionFactory) { + RedisTemplate> template = new RedisTemplate<>(); + + Jackson2JsonRedisSerializer j = new Jackson2JsonRedisSerializer(PageInfo.class); + + // value值的序列化 + template.setValueSerializer(j); + template.setHashKeySerializer(j); + + // key的序列化 + template.setKeySerializer(new StringRedisSerializer()); + template.setHashKeySerializer(new StringRedisSerializer()); + + template.setConnectionFactory(connectionFactory); + return template; + } + @Bean("buserTokenRedisTemplate") public RedisTemplate getBuserTokenRedisTemplate(RedisConnectionFactory connectionFactory) { RedisTemplate template = new RedisTemplate(); diff --git a/mallinkSchedule/src/main/java/com/iformall/config/RedisConfig.java b/mallinkSchedule/src/main/java/com/iformall/config/RedisConfig.java index 15c9b23de..83e0a9acb 100644 --- a/mallinkSchedule/src/main/java/com/iformall/config/RedisConfig.java +++ b/mallinkSchedule/src/main/java/com/iformall/config/RedisConfig.java @@ -1,6 +1,8 @@ package com.iformall.config; +import com.github.pagehelper.PageInfo; import com.iformall.domain.po.*; +import com.iformall.domain.vo.WxCouponChannelVo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.cache.CacheManager; @@ -141,6 +143,24 @@ public class RedisConfig extends CachingConfigurerSupport { return template; } + @Bean("couponChannelRedisTemplate") + public RedisTemplate> getCouponChannelRedisTemplate(RedisConnectionFactory connectionFactory) { + RedisTemplate> template = new RedisTemplate<>(); + + Jackson2JsonRedisSerializer j = new Jackson2JsonRedisSerializer(PageInfo.class); + + // value值的序列化 + template.setValueSerializer(j); + template.setHashKeySerializer(j); + + // key的序列化 + template.setKeySerializer(new StringRedisSerializer()); + template.setHashKeySerializer(new StringRedisSerializer()); + + template.setConnectionFactory(connectionFactory); + return template; + } + @Bean("buserTokenRedisTemplate") public RedisTemplate getBuserTokenRedisTemplate(RedisConnectionFactory connectionFactory) { RedisTemplate template = new RedisTemplate(); diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumCacheKey.java b/mallinkService/src/main/java/com/iformall/enums/EnumCacheKey.java new file mode 100644 index 000000000..0f9ac04f6 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/enums/EnumCacheKey.java @@ -0,0 +1,49 @@ +package com.iformall.enums; + +import java.util.HashMap; +import java.util.Map; + +/** + * Created by Stormeye on 2018/08/09. + */ +public enum EnumCacheKey { + + C_INDEX_PAGE_LIST(0, "couponChannelList_"), + + ; + private static Map map = new HashMap(); + static { + for (EnumCacheKey value : values()) { + map.put(value.code, value); + } + } + + public static EnumCacheKey getEnum(Integer code) { + if (code == null) return null; + return map.get(code); + } + + public static String getEnumMessage(Integer code) { + if (code == null) return null; + if (map.get(code) == null) + return null; + return map.get(code).getMessage(); + } + + private Integer code; + private String message; + + + EnumCacheKey(Integer code, String message) { + this.code = code; + this.message = message; + } + + public Integer getCode() { + return code; + } + + public String getMessage() { + return message; + } +} diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumTargetAd.java b/mallinkService/src/main/java/com/iformall/enums/EnumTargetAd.java new file mode 100644 index 000000000..4a8f8e2a6 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/enums/EnumTargetAd.java @@ -0,0 +1,34 @@ +package com.iformall.enums; + +public enum EnumTargetAd { + + + LIST(1, "列表"), + BUG(2, "显示抢购"), + ; + + public static EnumTargetAd getEnum(Integer code) { + for (EnumTargetAd value : values()) { + if (value.getCode().equals(code)) { + return value; + } + } + return null; + } + + private Integer code; + private String message; + + EnumTargetAd(Integer code, String message) { + this.code = code; + this.message = message; + } + + public Integer getCode() { + return code; + } + + public String getMessage() { + return message; + } +} diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponChannelServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponChannelServiceImpl.java index df5104906..b30b2faef 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponChannelServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponChannelServiceImpl.java @@ -15,12 +15,18 @@ import com.iformall.domain.vo.WxMerchantVo; import com.iformall.enums.*; import com.iformall.mapper.*; import com.iformall.service.*; +import com.iformall.utils.JsonUtil; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.core.ValueOperations; import org.springframework.stereotype.Service; import java.util.*; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @Service @@ -46,6 +52,10 @@ public class WxCouponChannelServiceImpl implements WxCouponChannelService { @Autowired WxFloatingLayerMapper wxFloatingLayerMapper; + @Autowired + @Qualifier("couponChannelRedisTemplate") + RedisTemplate> cdRedisTemplate; + /** * B端业务端 * @param record @@ -111,9 +121,23 @@ public class WxCouponChannelServiceImpl implements WxCouponChannelService { record.setUpdateDate(new Date()); wxCouponChannelMapper.updateById(record); } + + //清除缓存 + clearCache(record.getTenantId()); return new ResultData(); } + /** + * 清除c端首页卷列表缓存 + * @param tenantId + */ + public void clearCache(String tenantId){ + for (int i = 1; i <=5 ; i++) { + String key = EnumCacheKey.C_INDEX_PAGE_LIST.getMessage()+tenantId+"_" + i + ":"; + cdRedisTemplate.delete(key); + } + } + @Override public ResultData addBatch(String[] ids, String[] channelId, String tanantId, Date beginTime, Date endTime) { List errorList = new ArrayList<>(); @@ -284,6 +308,28 @@ public class WxCouponChannelServiceImpl implements WxCouponChannelService { */ @Override public PageInfo listPageCVo(WxCouponChannel record, Integer pageIndex, Integer pageSize) { + PageInfo pageInfo; + //仅c端首页走缓存 + if(EnumCouponChannelType.COUPON_CHANNEL_ID_LIST.getCode().equals(record.getTargetAd()) + && new Integer(6).equals(pageSize) + && pageIndex.intValue() <=5 + && record.getBusiness() == null) { + + logger.info("listPageCVo.chache"); + String key = EnumCacheKey.C_INDEX_PAGE_LIST.getMessage() +record.getTenantId()+"_" + pageIndex + ":"; + ValueOperations> operations = cdRedisTemplate.opsForValue(); + boolean hasKey = cdRedisTemplate.hasKey(key); + if (hasKey) { + pageInfo = operations.get(key); + logger.info("listPageCVo.chache.get:{}", pageInfo.getList()==null?0:pageInfo.getList().size()); + }else{ + pageInfo = PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxCouponChannelMapper.findVoList(record)); + } + //插入缓存 + operations.set(key, pageInfo, 60, TimeUnit.SECONDS); + return pageInfo; + } + return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxCouponChannelMapper.findVoList(record)); } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponInjectServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponInjectServiceImpl.java index a95ac83d8..bb1a5421d 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponInjectServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponInjectServiceImpl.java @@ -21,7 +21,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.*; -import java.util.stream.Collectors; @Service public class WxCouponInjectServiceImpl implements WxCouponInjectService { diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponPasswordServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponPasswordServiceImpl.java index b7f544f2e..6c8d92eb9 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponPasswordServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponPasswordServiceImpl.java @@ -11,7 +11,6 @@ import com.iformall.exception.MallinkException; import com.iformall.mapper.WxCouponPasswordMapper; import com.iformall.service.ExcelService; import com.iformall.service.WxCouponPasswordService; -import com.iformall.utils.DateUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java index 44059aac7..3617032be 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java @@ -13,6 +13,7 @@ import com.iformall.domain.dto.WxCouponMerchantDto; import com.iformall.domain.po.*; import com.iformall.domain.po.base.BaseEntity; import com.iformall.domain.vo.WxCouponCVo; +import com.iformall.domain.vo.WxCouponChannelVo; import com.iformall.domain.vo.WxCouponStatisVo; import com.iformall.domain.vo.WxMerchantVo; import com.iformall.enums.*; @@ -24,6 +25,8 @@ import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Isolation; import org.springframework.transaction.annotation.Propagation; @@ -71,6 +74,10 @@ import java.util.stream.Collectors; @Autowired WxCouponPasswordService couponPasswordService; + @Autowired + @Qualifier("couponChannelRedisTemplate") + RedisTemplate> cdRedisTemplate; + @Override public ResultData list(WxCoupon wxCoupon, Integer pageNum, Integer pageSize) { if (null == wxCoupon) wxCoupon = new WxCoupon(); @@ -429,9 +436,24 @@ import java.util.stream.Collectors; wxCouponMapper.updateById(record); } + + //清空缓存 + clearCache(record.getTenantId()); return new ResultData(record.getId()); } + + /** + * 清除c端首页卷列表缓存 + * @param tenantId + */ + public void clearCache(String tenantId){ + for (int i = 1; i <=5 ; i++) { + String key = EnumCacheKey.C_INDEX_PAGE_LIST.getMessage() +tenantId+"_" + i + ":"; + cdRedisTemplate.delete(key); + } + } + @Override public void deleteById(Long id) { wxCouponMapper.deleteById(id); @@ -590,12 +612,14 @@ import java.util.stream.Collectors; // 库存 是否改变 bChanged = true; } - if(wxCoupon.getInventory()-wxCoupon.getRemainInventory() != oldCoupon.getInventory() - oldCoupon.getRemainInventory()) { + Integer newSale = wxCoupon.getInventory()-wxCoupon.getRemainInventory(); + Integer oldSale = oldCoupon.getInventory() - oldCoupon.getRemainInventory(); + if (!newSale.equals(oldSale)) { // 已售卖数不变 - logger.error("已售卖数不变"); - return new ResultData(ErrorCode.COUPON_STOCK_ERR.getCode(), "已售卖数不变"); + logger.error("券库存要保证同增同减"); + return new ResultData(ErrorCode.COUPON_STOCK_ERR.getCode(), "券库存要保证同增同减"); } - if(wxCoupon.getValidType() != oldCoupon.getValidType()) { + if (!wxCoupon.getValidType().equals(oldCoupon.getValidType())) { // 券有效期类型不能改变 logger.error("券有效期类型不能改变"); return new ResultData(ErrorCode.COUPON_VALID_DATE_ERR.getCode(), "券有效期类型不能改变"); @@ -627,8 +651,10 @@ import java.util.stream.Collectors; wxCoupon.setOrgInventory(oldCoupon.getInventory()); wxCoupon.setOrgRemainInventory(oldCoupon.getRemainInventory()); - if((wxCoupon.getRemainInventory() - wxCoupon.getOrgRemainInventory()) != (wxCoupon.getInventory() - wxCoupon.getOrgInventory())) { - // 库存要保证,同增同减 + Integer newSale1 = wxCoupon.getRemainInventory() - wxCoupon.getOrgRemainInventory(); + Integer oldSale1 = wxCoupon.getInventory() - wxCoupon.getOrgInventory(); + if (!newSale1.equals(oldSale1)) { + // 库存要保证,同增同减 logger.error("券库存要保证同增同减"); return new ResultData(ErrorCode.COUPON_STOCK_NO_EQUAL_ERR); } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxFlowServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxFlowServiceImpl.java index d0114473c..f9f4434f7 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxFlowServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxFlowServiceImpl.java @@ -13,6 +13,7 @@ import com.iformall.domain.po.msg.WxMsgRecord; import com.iformall.domain.vo.FlowUserVo; import com.iformall.domain.vo.UserTaskVo; import com.iformall.domain.vo.WxBillAll; +import com.iformall.domain.vo.WxCouponChannelVo; import com.iformall.enums.*; import com.iformall.mapper.*; import com.iformall.mq.MqBaseProducer; @@ -38,6 +39,8 @@ import org.flowable.task.api.TaskQuery; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; @@ -90,6 +93,9 @@ public class WxFlowServiceImpl implements WxFlowService { private WxBillSettleMapper wxBillSettleMapper; @Autowired private WxBillSettleService wxBillSettleService; + @Autowired + @Qualifier("couponChannelRedisTemplate") + RedisTemplate> cdRedisTemplate; /** * 获取流程key @@ -286,6 +292,7 @@ public class WxFlowServiceImpl implements WxFlowService { wxCoupon.setRemainInventory(remainInventory); wxCoupon.setType(type); wxCoupon.setValidType(validType); + wxCoupon.setTenantId(wxCoupon.getTenantId()); wxCouponService.updateCouponStockAndEndTime(wxCoupon); } }else if(EnumCouponAppType.CANCLE.getCode().equals(operateType)){ @@ -298,6 +305,8 @@ public class WxFlowServiceImpl implements WxFlowService { } wxCoupon.setApprovalType(operateType); wxCouponMapper.updateById(wxCoupon); + //清除缓存 + clearCache(wxCoupon.getTenantId()); }else if(EnumFlowKey.SETTLE.getCode().equals(flowType)){ WxBillSettle wxBillSettle = new WxBillSettle(); wxBillSettle.setId(businessId); @@ -323,6 +332,17 @@ public class WxFlowServiceImpl implements WxFlowService { } } + /** + * 清除c端首页卷列表缓存 + * @param tenantId + */ + public void clearCache(String tenantId){ + for (int i = 1; i <=5 ; i++) { + String key = EnumCacheKey.C_INDEX_PAGE_LIST.getMessage()+tenantId+"_" + i + ":"; + cdRedisTemplate.delete(key); + } + } + public Map mallUserInfoToMap(MallUserInfo userInfo){ try { Map map = new HashMap<>(); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java index 93f5cdd85..ec4991a12 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java @@ -18,7 +18,6 @@ import com.iformall.mapper.*; import com.iformall.mq.MqBaseProducer; import com.iformall.service.*; import com.iformall.utils.*; -import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; diff --git a/mallinkService/src/main/resources/mapper/WxCouponMapper.xml b/mallinkService/src/main/resources/mapper/WxCouponMapper.xml index a77ded171..162d69e04 100644 --- a/mallinkService/src/main/resources/mapper/WxCouponMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxCouponMapper.xml @@ -271,7 +271,11 @@ SET `remain_inventory` = #{remainInventory}, `inventory` = #{inventory}, `valid_type` = #{validType}, `valid_end_date` = #{validEndDate}, `valid_days` = #{validDays} - WHERE `tenant_id` = #{tenantId} and id = #{id} and `remain_inventory` = #{orgRemainInventory} and `inventory` = #{orgInventory} + WHERE 1=1 + + and `tenant_id` = #{tenantId} + + and id = #{id} and `remain_inventory` = #{orgRemainInventory} and `inventory` = #{orgInventory} diff --git a/mallinkService/src/main/resources/mapper/WxCouponPasswordMapper.xml b/mallinkService/src/main/resources/mapper/WxCouponPasswordMapper.xml index 933ce1e89..83749cb13 100644 --- a/mallinkService/src/main/resources/mapper/WxCouponPasswordMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxCouponPasswordMapper.xml @@ -141,7 +141,7 @@ (select count(*) as coupon_count,coupon_id from wx_coupon_password where tenant_id=#{tenantId} and status=0 group by coupon_id) cp inner join wx_coupon c on cp.coupon_id = c.id - where c.tenant_id=#{tenantId} and c.status=0 + where c.tenant_id=#{tenantId} and c.status=0 and c.put_apply_status in(0,2) and cp.`coupon_id` = #{couponId} diff --git a/mallinkSysAdmin/src/main/java/com/iformall/config/RedisConfig.java b/mallinkSysAdmin/src/main/java/com/iformall/config/RedisConfig.java index 1db11fb55..ac36c58fb 100644 --- a/mallinkSysAdmin/src/main/java/com/iformall/config/RedisConfig.java +++ b/mallinkSysAdmin/src/main/java/com/iformall/config/RedisConfig.java @@ -1,6 +1,8 @@ package com.iformall.config; +import com.github.pagehelper.PageInfo; import com.iformall.domain.po.*; +import com.iformall.domain.vo.WxCouponChannelVo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.cache.CacheManager; @@ -156,6 +158,23 @@ public class RedisConfig extends CachingConfigurerSupport { return template; } + @Bean("couponChannelRedisTemplate") + public RedisTemplate> getCouponChannelRedisTemplate(RedisConnectionFactory connectionFactory) { + RedisTemplate> template = new RedisTemplate<>(); + + Jackson2JsonRedisSerializer j = new Jackson2JsonRedisSerializer(PageInfo.class); + // value值的序列化 + template.setValueSerializer(j); + template.setHashKeySerializer(j); + + // key的序列化 + template.setKeySerializer(new StringRedisSerializer()); + template.setHashKeySerializer(new StringRedisSerializer()); + + template.setConnectionFactory(connectionFactory); + return template; + } + @Bean("buserTokenRedisTemplate") public RedisTemplate getBuserTokenRedisTemplate(RedisConnectionFactory connectionFactory) { RedisTemplate template = new RedisTemplate(); diff --git a/mallinkWebSocketServer/src/main/java/com/iformall/config/RedisConfig.java b/mallinkWebSocketServer/src/main/java/com/iformall/config/RedisConfig.java index d5c680387..28d61d711 100644 --- a/mallinkWebSocketServer/src/main/java/com/iformall/config/RedisConfig.java +++ b/mallinkWebSocketServer/src/main/java/com/iformall/config/RedisConfig.java @@ -1,6 +1,8 @@ package com.iformall.config; +import com.github.pagehelper.PageInfo; import com.iformall.domain.po.*; +import com.iformall.domain.vo.WxCouponChannelVo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.cache.CacheManager; @@ -141,6 +143,24 @@ public class RedisConfig extends CachingConfigurerSupport { return template; } + @Bean("couponChannelRedisTemplate") + public RedisTemplate> getCouponChannelRedisTemplate(RedisConnectionFactory connectionFactory) { + RedisTemplate> template = new RedisTemplate<>(); + + Jackson2JsonRedisSerializer j = new Jackson2JsonRedisSerializer(PageInfo.class); + + // value值的序列化 + template.setValueSerializer(j); + template.setHashKeySerializer(j); + + // key的序列化 + template.setKeySerializer(new StringRedisSerializer()); + template.setHashKeySerializer(new StringRedisSerializer()); + + template.setConnectionFactory(connectionFactory); + return template; + } + @Bean("buserTokenRedisTemplate") public RedisTemplate getBuserTokenRedisTemplate(RedisConnectionFactory connectionFactory) { RedisTemplate template = new RedisTemplate();