yujian
2019-03-06 ef926f0a53f25444854cb4c2acbafa68cefc6e9d
系统券查询加入缓存
5个文件已修改
43 ■■■■■ 已修改文件
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/SystemCouponMapper.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/mapping/SystemCouponMapper.xml 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/config/SystemCouponServiceImpl.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/config/SystemCouponService.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/resource/ehcache.xml 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/SystemCouponMapper.java
@@ -1,5 +1,6 @@
package com.yeshi.fanli.dao.mybatis;
import java.math.BigDecimal;
import java.util.List;
import org.apache.ibatis.annotations.Param;
@@ -29,6 +30,12 @@
     */
    SystemCoupon getCouponByType(@Param("type") String type);
    
    /**
     * 根据类型/比例查询
     * @param type
     * @return
     */
    SystemCoupon getCouponByTypeAndPercent(@Param("type") String type, @Param("percent") BigDecimal percent);
    
}
fanli/src/main/java/com/yeshi/fanli/mapping/SystemCouponMapper.xml
@@ -84,7 +84,7 @@
    </set> where sc_id = #{id,jdbcType=BIGINT}
  </update>
  
   <delete id="deleteBatchByPrimaryKey"  parameterType="java.util.List">
  <delete id="deleteBatchByPrimaryKey"  parameterType="java.util.List">
    delete FROM yeshi_ec_system_coupon WHERE sc_id in
    <foreach collection="list" item="item" open="(" close=")"
        separator=",">#{item}</foreach>
@@ -104,4 +104,10 @@
    limit 1
  </select>
  
  <select id="getCouponByTypeAndPercent" resultMap="BaseResultMap" >
    select * FROM yeshi_ec_system_coupon
    WHERE sc_type = #{type} AND sc_percent = #{percent}
    limit 1
  </select>
</mapper>
fanli/src/main/java/com/yeshi/fanli/service/impl/config/SystemCouponServiceImpl.java
@@ -1,10 +1,12 @@
package com.yeshi.fanli.service.impl.config;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import com.yeshi.fanli.dao.mybatis.SystemCouponMapper;
@@ -25,6 +27,7 @@
    }
    @Override
    @Cacheable(value = "systemCouponCache",key="'selectByPrimaryKey-'+#id")
    public SystemCoupon selectByPrimaryKey(Long id) {
        return systemCouponMapper.selectByPrimaryKey(id);
    }
@@ -45,11 +48,13 @@
    }
    
    @Override
    @Cacheable(value = "systemCouponCache",key="'getCouponByType-'+#type")
    public SystemCoupon getCouponByType(String type) {
        return systemCouponMapper.getCouponByType(type);
    }
    
    @Override
    @Cacheable(value = "systemCouponCache",key="'getOrderCouponList")
    public List<SystemCoupon> getOrderCouponList() {
        List<String> listType = new ArrayList<String>();
        listType.add(CouponTypeEnum.rebatePercentCoupon.name());
@@ -58,6 +63,7 @@
    }
    
    @Override
    @Cacheable(value = "systemCouponCache",key="'getGoodsCouponList'")
    public List<SystemCoupon> getGoodsCouponList() {
        List<String> listType = new ArrayList<String>();
        listType.add(CouponTypeEnum.freeCoupon.name());
@@ -65,4 +71,10 @@
        
        return systemCouponMapper.getCouponListByType(listType);
    }
    @Override
    @Cacheable(value = "systemCouponCache",key="'getCouponByTypeAndPercent-'+#type +'-'+#percent")
    public SystemCoupon getCouponByTypeAndPercent( String type, BigDecimal percent) {
        return systemCouponMapper.getCouponByTypeAndPercent(type, percent);
    }
}
fanli/src/main/java/com/yeshi/fanli/service/inter/config/SystemCouponService.java
@@ -1,5 +1,6 @@
package com.yeshi.fanli.service.inter.config;
import java.math.BigDecimal;
import java.util.List;
import com.yeshi.fanli.entity.system.SystemCoupon;
@@ -40,5 +41,13 @@
     * @return
     */
    public SystemCoupon getCouponByType(String type);
    /**
     * 根据类型、比例查询
     * @param type
     * @param percent
     * @return
     */
    public SystemCoupon getCouponByTypeAndPercent(String type, BigDecimal percent);
    
}
fanli/src/main/resource/ehcache.xml
@@ -178,4 +178,11 @@
        maxElementsOnDisk="10000" eternal="false" timeToIdleSeconds="120"
        timeToLiveSeconds="120" overflowToDisk="true"
        memoryStoreEvictionPolicy="LRU" />    
        <!-- 系统自定义券缓存 -->
    <cache name="systemCouponCache" maxElementsInMemory="1000"
        maxElementsOnDisk="10000" eternal="false" timeToIdleSeconds="120"
        timeToLiveSeconds="120" overflowToDisk="true"
        memoryStoreEvictionPolicy="LRU" />
</ehcache>