Browse Source

[C][修改]:coupon/detail优化

release_toaliyun_real
Stormeye Wu 6 years ago
parent
commit
8f3f3e9c00
5 changed files with 48 additions and 12 deletions
  1. +29
    -12
      mallinkCApi/src/main/java/com/iformall/controller/WxCouponController.java
  2. +1
    -0
      mallinkService/src/main/java/com/iformall/mapper/WxCouponMapper.java
  3. +2
    -0
      mallinkService/src/main/java/com/iformall/service/WxCouponService.java
  4. +6
    -0
      mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java
  5. +10
    -0
      mallinkService/src/main/resources/mapper/WxCouponMapper.xml

+ 29
- 12
mallinkCApi/src/main/java/com/iformall/controller/WxCouponController.java View File

@@ -34,6 +34,9 @@ public class WxCouponController extends BaseController {
@Autowired
private WxCouponChannelService wxCouponChannelService;

@Autowired
private WxCouponService couponService;

@Autowired
@Qualifier("couponDetailRedisTemplate")
RedisTemplate<String, WxCouponCVo> cdRedisTemplate;
@@ -42,14 +45,18 @@ public class WxCouponController extends BaseController {
@ApiOperation("根据id(couponChannel)查询接口")
@GetMapping("/detail")
@ApiImplicitParams({
@ApiImplicitParam(name = "couponChannelId", value = "couponChannelId", dataType = "String", paramType = "query", required = true)})
public ResultData detailC(String couponChannelId) {
@ApiImplicitParam(name = "couponChannelId", value = "couponChannelId", dataType = "String", paramType = "query", required = true),
@ApiImplicitParam(name = "couponId", value = "couponId", dataType = "String", paramType = "query", required = false)})
public ResultData detailC(String couponChannelId, String couponId) {
if (StringUtils.isBlank(couponChannelId) || couponChannelId.equalsIgnoreCase(Constant.UNDEFINED)) {
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponChannelId为空");
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponChannelId/couponId为空");
}
Long couponChannelIdL = 0L;
Long couponChannelIdL = 0L, couponIdL = 0L;
try {
couponChannelIdL = Long.valueOf(couponChannelId);
if (StringUtils.isNotBlank(couponId) && !couponId.equalsIgnoreCase(Constant.UNDEFINED)) {
couponIdL = Long.valueOf(couponId);
}
} catch (NumberFormatException e) {
logger.error("id转换失败" + couponChannelId);
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponChannelId转换失败" + couponChannelId);
@@ -60,16 +67,26 @@ public class WxCouponController extends BaseController {
ValueOperations<String, WxCouponCVo> operations = cdRedisTemplate.opsForValue();
// 缓存
boolean hasKey = cdRedisTemplate.hasKey(key);
if(hasKey) {
if (hasKey) {
// 从缓存获取用户信息
WxCouponCVo wxCouponCVo = operations.get(key);
// 更新状态
WxCouponCVo couponCVo = wxCouponChannelService.findVoStatusDetail(couponChannelIdL);
if (wxCouponCVo == null) {
return new ResultData(ErrorCode.COUPON_IS_EMPTY);
if (couponIdL > 0L) {
// 更新状态
WxCouponCVo couponCVo = couponService.getVoStatusById(couponIdL);
if (wxCouponCVo == null) {
return new ResultData(ErrorCode.COUPON_IS_EMPTY);
}
wxCouponCVo.setRemainInventory(couponCVo.getRemainInventory());
wxCouponCVo.setStatus(couponCVo.getStatus());
} else {
// 更新状态
WxCouponCVo couponCVo = wxCouponChannelService.findVoStatusDetail(couponChannelIdL);
if (wxCouponCVo == null) {
return new ResultData(ErrorCode.COUPON_IS_EMPTY);
}
wxCouponCVo.setRemainInventory(couponCVo.getRemainInventory());
wxCouponCVo.setStatus(couponCVo.getStatus());
}
wxCouponCVo.setRemainInventory(couponCVo.getRemainInventory());
wxCouponCVo.setStatus(couponCVo.getStatus());
// end of 更新状态
updateActivityStatus(wxCouponCVo);
return new ResultData(wxCouponCVo);
@@ -89,7 +106,7 @@ public class WxCouponController extends BaseController {
}

private void updateActivityStatus(WxCouponCVo wxCouponCVo) {
if (wxCouponCVo.getTargetAd()!= null &&
if (wxCouponCVo.getTargetAd() != null &&
wxCouponCVo.getTargetAd().equals(EnumCouponChannelType.COUPON_CHANNEL_ID_TIMED.getCode())) {
Date now = new Date();



+ 1
- 0
mallinkService/src/main/java/com/iformall/mapper/WxCouponMapper.java View File

@@ -18,6 +18,7 @@ public interface WxCouponMapper extends CommonMapper<WxCoupon, Long> {


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

Integer reduceInventory(@Param("id")Long id,@Param("number")Integer number,@Param("remainInventory")Integer remainInventory);



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

@@ -56,6 +56,8 @@ public interface WxCouponService {


WxCouponCVo getVoById(Long id);

WxCouponCVo getVoStatusById(Long id);
/**
* 保存或更新实体
*


+ 6
- 0
mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java View File

@@ -170,6 +170,12 @@ import java.util.stream.Collectors;
return wxCouponCVo;
}

@Override
public WxCouponCVo getVoStatusById(Long id) {
WxCouponCVo wxCouponCVo = wxCouponMapper.findVoStatusDetail(id);
return wxCouponCVo;
}


private Long parseMerchantId(JSONObject merchantParam){
return Long.valueOf(merchantParam.getString("id"));


+ 10
- 0
mallinkService/src/main/resources/mapper/WxCouponMapper.xml View File

@@ -98,6 +98,10 @@
`press_limit_num`, `press_limit_hours`, `auto_refund`,`credit_price`,`credit_refund`,`put_apply_status`,`stock_apply_status`,`cancle_apply_status`,`conditions`,approval_type
</sql>

<sql id="statusColumns">
`id`,`remain_inventory`,`status`
</sql>

<sql id="dynamicWhereConditions">
where 1 = 1

@@ -510,6 +514,12 @@
where id = #{id}
</select>

<select id="findVoStatusDetail" parameterType="java.lang.Long" resultMap="WxCouponCVoMap">
select
<include refid="allColumns"/>
from wx_coupon
where id = #{id}
</select>

<update id="reduceInventory">
update wx_coupon SET remain_inventory = remain_inventory - #{number} where id = #{id} and remain_inventory= #{remainInventory}


Loading…
Cancel
Save