Browse Source

[/api/wxCoupon/detail][修改]:优化detail访问

release_toaliyun_real
Stormeye Wu 6 years ago
parent
commit
65324de93d
6 changed files with 76 additions and 4 deletions
  1. +18
    -0
      mallinkCApi/src/main/java/com/iformall/config/RedisConfig.java
  2. +38
    -4
      mallinkCApi/src/main/java/com/iformall/controller/WxCouponController.java
  3. +2
    -0
      mallinkService/src/main/java/com/iformall/mapper/WxCouponChannelMapper.java
  4. +2
    -0
      mallinkService/src/main/java/com/iformall/service/WxCouponChannelService.java
  5. +5
    -0
      mallinkService/src/main/java/com/iformall/service/impl/WxCouponChannelServiceImpl.java
  6. +11
    -0
      mallinkService/src/main/resources/mapper/WxCouponChannelMapper.xml

+ 18
- 0
mallinkCApi/src/main/java/com/iformall/config/RedisConfig.java View File

@@ -4,6 +4,7 @@ import com.iformall.domain.po.PushLimit;
import com.iformall.domain.po.WxCUser; import com.iformall.domain.po.WxCUser;
import com.iformall.domain.po.WxMall; import com.iformall.domain.po.WxMall;
import com.iformall.domain.po.WxScoreRules; import com.iformall.domain.po.WxScoreRules;
import com.iformall.domain.vo.WxCouponCVo;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.cache.CacheManager; import org.springframework.cache.CacheManager;
@@ -122,4 +123,21 @@ public class RedisConfig extends CachingConfigurerSupport {
return template; return template;
} }


@Bean("couponDetailRedisTemplate")
public RedisTemplate<String, WxCouponCVo> getCouponDetailRedisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<String, WxCouponCVo> template = new RedisTemplate<String, WxCouponCVo>();

Jackson2JsonRedisSerializer<WxCouponCVo> j = new Jackson2JsonRedisSerializer<WxCouponCVo>(WxCouponCVo.class);
// value值的序列化
template.setValueSerializer(j);
template.setHashKeySerializer(j);

// key的序列化
template.setKeySerializer(new StringRedisSerializer());
template.setHashKeySerializer(new StringRedisSerializer());

template.setConnectionFactory(connectionFactory);
return template;
}

} }

+ 38
- 4
mallinkCApi/src/main/java/com/iformall/controller/WxCouponController.java View File

@@ -17,9 +17,13 @@ import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; 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.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;


import java.util.Date; import java.util.Date;
import java.util.concurrent.TimeUnit;


@RestController @RestController
@RequestMapping("/api/wxCoupon") @RequestMapping("/api/wxCoupon")
@@ -29,8 +33,10 @@ public class WxCouponController extends BaseController {


@Autowired @Autowired
private WxCouponChannelService wxCouponChannelService; private WxCouponChannelService wxCouponChannelService;

@Autowired @Autowired
private WxCouponService wxCouponService;
@Qualifier("couponDetailRedisTemplate")
RedisTemplate<String, WxCouponCVo> cdRedisTemplate;




@ApiOperation("根据id(couponChannel)查询接口") @ApiOperation("根据id(couponChannel)查询接口")
@@ -49,10 +55,40 @@ public class WxCouponController extends BaseController {
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponChannelId转换失败" + couponChannelId); return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponChannelId转换失败" + couponChannelId);
} }


String key = "cc:" + couponChannelId;

ValueOperations<String, WxCouponCVo> operations = cdRedisTemplate.opsForValue();
// 缓存
boolean hasKey = cdRedisTemplate.hasKey(key);
if(hasKey) {
// 从缓存获取用户信息
WxCouponCVo wxCouponCVo = operations.get(key);
// 更新状态
WxCouponCVo couponCVo = wxCouponChannelService.findVoStatusDetail(couponChannelIdL);
if (wxCouponCVo == null) {
return new ResultData(ErrorCode.COUPON_IS_EMPTY);
}
wxCouponCVo.setRemainInventory(couponCVo.getRemainInventory());
wxCouponCVo.setStatus(couponCVo.getStatus());
// end of 更新状态
updateActivityStatus(wxCouponCVo);
return new ResultData(wxCouponCVo);
}

WxCouponCVo wxCouponCVo = wxCouponChannelService.findDetailVo(couponChannelIdL); WxCouponCVo wxCouponCVo = wxCouponChannelService.findDetailVo(couponChannelIdL);
if (wxCouponCVo == null)
if (wxCouponCVo == null) {
return new ResultData(ErrorCode.COUPON_IS_EMPTY); return new ResultData(ErrorCode.COUPON_IS_EMPTY);
}

// 插入缓存
operations.set(key, wxCouponCVo, 3600, TimeUnit.SECONDS);


updateActivityStatus(wxCouponCVo);

return new ResultData(wxCouponCVo);
}

private void updateActivityStatus(WxCouponCVo wxCouponCVo) {
if (wxCouponCVo.getTargetAd()!= null && if (wxCouponCVo.getTargetAd()!= null &&
wxCouponCVo.getTargetAd().equals(EnumCouponChannelType.COUPON_CHANNEL_ID_TIMED.getCode())) { wxCouponCVo.getTargetAd().equals(EnumCouponChannelType.COUPON_CHANNEL_ID_TIMED.getCode())) {
Date now = new Date(); Date now = new Date();
@@ -65,8 +101,6 @@ public class WxCouponController extends BaseController {
wxCouponCVo.setActivityStatus(EnumCouponChannelActivityStatus.STARTED.getCode()); wxCouponCVo.setActivityStatus(EnumCouponChannelActivityStatus.STARTED.getCode());
} }
} }

return new ResultData(wxCouponCVo);
} }


} }

+ 2
- 0
mallinkService/src/main/java/com/iformall/mapper/WxCouponChannelMapper.java View File

@@ -23,6 +23,8 @@ public interface WxCouponChannelMapper extends CommonMapper<WxCouponChannel, Str


WxCouponCVo findVoDetail(@Param("id")Long id); WxCouponCVo findVoDetail(@Param("id")Long id);


WxCouponCVo findVoStatusDetail(@Param("id")Long id);

void updateStatusByCouponId(WxCouponChannel wxCouponChannel); void updateStatusByCouponId(WxCouponChannel wxCouponChannel);


int updateEndTimeByCouponId(WxCouponChannel wxCouponChannel); int updateEndTimeByCouponId(WxCouponChannel wxCouponChannel);


+ 2
- 0
mallinkService/src/main/java/com/iformall/service/WxCouponChannelService.java View File

@@ -43,6 +43,8 @@ public interface WxCouponChannelService {


WxCouponCVo findDetailVo(Long id); WxCouponCVo findDetailVo(Long id);


WxCouponCVo findVoStatusDetail(Long id);

/** /**
* 根据实体查询Vo分页列表 * 根据实体查询Vo分页列表
* *


+ 5
- 0
mallinkService/src/main/java/com/iformall/service/impl/WxCouponChannelServiceImpl.java View File

@@ -292,6 +292,11 @@ public class WxCouponChannelServiceImpl implements WxCouponChannelService {
return wxCouponChannelMapper.findVoDetail(id); return wxCouponChannelMapper.findVoDetail(id);
} }


@Override
public WxCouponCVo findVoStatusDetail(Long id) {
return wxCouponChannelMapper.findVoStatusDetail(id);
}

@Override @Override
public List<WxCouponChannelVo> listVo(WxCouponChannel record) { public List<WxCouponChannelVo> listVo(WxCouponChannel record) {
return wxCouponChannelMapper.findVoList(record); return wxCouponChannelMapper.findVoList(record);


+ 11
- 0
mallinkService/src/main/resources/mapper/WxCouponChannelMapper.xml View File

@@ -218,6 +218,10 @@
cc.qr_code cc.qr_code
</sql> </sql>


<sql id="CVoStatusColumn">
cc.id,cc.coupon_id,c.remain_inventory,c.status
</sql>

<resultMap id="WxCouponCVoMap" type="com.iformall.domain.vo.WxCouponCVo"> <resultMap id="WxCouponCVoMap" type="com.iformall.domain.vo.WxCouponCVo">
<id column="id" jdbcType="BIGINT" property="id"/> <id column="id" jdbcType="BIGINT" property="id"/>
<result column="coupon_id" jdbcType="BIGINT" property="couponId" /> <result column="coupon_id" jdbcType="BIGINT" property="couponId" />
@@ -273,6 +277,13 @@
where cc.id = #{id} where cc.id = #{id}
</select> </select>


<select id="findVoStatusDetail" parameterType="java.lang.Long" resultMap="WxCouponCVoMap">
select
<include refid="CVoStatusColumn"/>
from wx_coupon c, wx_coupon_channel cc
where cc.coupon_id = c.id and cc.id = #{id}
</select>



<select id="countCoupon" parameterType="com.iformall.domain.po.WxCouponChannel" resultType="java.lang.Integer"> <select id="countCoupon" parameterType="com.iformall.domain.po.WxCouponChannel" resultType="java.lang.Integer">
select count(distinct coupon_id) from wx_coupon_channel cc select count(distinct coupon_id) from wx_coupon_channel cc


Loading…
Cancel
Save