Просмотр исходного кода

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

release_toaliyun_real
Stormeye Wu 6 лет назад
Родитель
Сommit
8f3f3e9c00
5 измененных файлов: 48 добавлений и 12 удалений
  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 Просмотреть файл

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


@Autowired
private WxCouponService couponService;

@Autowired @Autowired
@Qualifier("couponDetailRedisTemplate") @Qualifier("couponDetailRedisTemplate")
RedisTemplate<String, WxCouponCVo> cdRedisTemplate; RedisTemplate<String, WxCouponCVo> cdRedisTemplate;
@@ -42,14 +45,18 @@ public class WxCouponController extends BaseController {
@ApiOperation("根据id(couponChannel)查询接口") @ApiOperation("根据id(couponChannel)查询接口")
@GetMapping("/detail") @GetMapping("/detail")
@ApiImplicitParams({ @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)) { 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 { try {
couponChannelIdL = Long.valueOf(couponChannelId); couponChannelIdL = Long.valueOf(couponChannelId);
if (StringUtils.isNotBlank(couponId) && !couponId.equalsIgnoreCase(Constant.UNDEFINED)) {
couponIdL = Long.valueOf(couponId);
}
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
logger.error("id转换失败" + couponChannelId); logger.error("id转换失败" + couponChannelId);
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponChannelId转换失败" + 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(); ValueOperations<String, WxCouponCVo> operations = cdRedisTemplate.opsForValue();
// 缓存 // 缓存
boolean hasKey = cdRedisTemplate.hasKey(key); boolean hasKey = cdRedisTemplate.hasKey(key);
if(hasKey) {
if (hasKey) {
// 从缓存获取用户信息 // 从缓存获取用户信息
WxCouponCVo wxCouponCVo = operations.get(key); 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 更新状态 // end of 更新状态
updateActivityStatus(wxCouponCVo); updateActivityStatus(wxCouponCVo);
return new ResultData(wxCouponCVo); return new ResultData(wxCouponCVo);
@@ -89,7 +106,7 @@ public class WxCouponController extends BaseController {
} }


private void updateActivityStatus(WxCouponCVo 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();




+ 1
- 0
mallinkService/src/main/java/com/iformall/mapper/WxCouponMapper.java Просмотреть файл

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




WxCouponCVo findVoDetail(@Param("id")Long id); 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); 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 Просмотреть файл

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




WxCouponCVo getVoById(Long id); WxCouponCVo getVoById(Long id);

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


+ 6
- 0
mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java Просмотреть файл

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


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



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


+ 10
- 0
mallinkService/src/main/resources/mapper/WxCouponMapper.xml Просмотреть файл

@@ -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 `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>


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

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


@@ -510,6 +514,12 @@
where id = #{id} where id = #{id}
</select> </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 id="reduceInventory">
update wx_coupon SET remain_inventory = remain_inventory - #{number} where id = #{id} and remain_inventory= #{remainInventory} update wx_coupon SET remain_inventory = remain_inventory - #{number} where id = #{id} and remain_inventory= #{remainInventory}


Загрузка…
Отмена
Сохранить