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

[detail][优化]:减少数据库访问,提高并发效率

release_toaliyun_real
Stormeye Wu 6 лет назад
Родитель
Сommit
38774d8aad
5 измененных файлов: 103 добавлений и 7 удалений
  1. +1
    -0
      mallinkCApi/src/main/java/com/iformall/controller/WxCouponController.java
  2. +22
    -1
      mallinkCApi/src/main/java/com/iformall/controller/WxOrderController.java
  3. +1
    -4
      mallinkService/src/main/java/com/iformall/service/impl/WxMerchantServiceImpl.java
  4. +42
    -1
      mallinkService/src/main/resources/mapper/WxCouponChannelMapper.xml
  5. +37
    -1
      mallinkService/src/main/resources/mapper/WxCouponMapper.xml

+ 1
- 0
mallinkCApi/src/main/java/com/iformall/controller/WxCouponController.java Просмотреть файл

@@ -68,6 +68,7 @@ public class WxCouponController extends BaseController {
if (hasKey) {
// 从缓存获取用户信息
WxCouponCVo wxCouponCVo = operations.get(key);
// 库存
if (couponIdL > 0L) {
// 更新状态
WxCouponCVo couponCVo = couponService.getVoStatusById(couponIdL);


+ 22
- 1
mallinkCApi/src/main/java/com/iformall/controller/WxOrderController.java Просмотреть файл

@@ -26,6 +26,9 @@ 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.web.bind.annotation.*;

import java.util.Date;
@@ -49,6 +52,10 @@ public class WxOrderController extends BaseController {
@Autowired
private WxCUserBasicInfoService wxCUserBasicInfoService;

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

@ApiOperation(value = "下订单", notes = "{\"couponChannelId\":\"String\",\"couponId\":\"String\",\"press\":\"String\",\"orderGroupId\":\"String\",\"formId\":\"String\"}")
@PostMapping("save")
public ResultData saveOrder(@RequestBody OrderSaveDto orderSaveDto) {
@@ -71,7 +78,21 @@ public class WxOrderController extends BaseController {
return new ResultData(ErrorCode.MEMBER_IS_LOCKED);
}

resultData = couponUserCheck(user, wxCouponChannelService.findDetailVo(orderSaveDto.getCouponChannelId()));
WxCouponCVo wxCouponCVo = null;

String key = "cc:" + orderSaveDto.getCouponChannelId();
ValueOperations<String, WxCouponCVo> operations = cdRedisTemplate.opsForValue();
// 缓存
boolean hasKey = cdRedisTemplate.hasKey(key);
if (hasKey) {
// 从缓存获取用户信息
wxCouponCVo = operations.get(key);
}
if (wxCouponCVo == null) {
return new ResultData(ErrorCode.COUPON_IS_EMPTY);
}

resultData = couponUserCheck(user, wxCouponCVo);
if (resultData != null) return resultData;

Long couponId = orderSaveDto.getCouponId() == null ? wxCouponChannel.getCouponId() : orderSaveDto.getCouponId();


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

@@ -12,10 +12,7 @@ import com.iformall.domain.dto.WxMerchantDto;
import com.iformall.domain.po.*;
import com.iformall.domain.po.base.BaseEntity;
import com.iformall.domain.po.base.TenantEntity;
import com.iformall.domain.vo.WxMerchantSimpleVo;
import com.iformall.domain.vo.WxMerchantTradeDetailVo;
import com.iformall.domain.vo.WxMerchantTradeVo;
import com.iformall.domain.vo.WxMerchantVo;
import com.iformall.domain.vo.*;
import com.iformall.enums.*;
import com.iformall.exception.MallinkException;
import com.iformall.mapper.*;


+ 42
- 1
mallinkService/src/main/resources/mapper/WxCouponChannelMapper.xml Просмотреть файл

@@ -274,6 +274,47 @@
</collection>
</resultMap>

<resultMap id="WxCouponCVoMapL" type="com.iformall.domain.vo.WxCouponCVo">
<id column="id" jdbcType="BIGINT" property="id"/>
<result column="coupon_id" jdbcType="BIGINT" property="couponId" />
<result column="type" jdbcType="INTEGER" property="type" />
<result column="target_ad" jdbcType="INTEGER" property="targetAd" />
<result column="begin_time" jdbcType="TIMESTAMP" property="beginTime"/>
<result column="end_time" jdbcType="TIMESTAMP" property="endTime"/>

<result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
<result column="type" jdbcType="INTEGER" property="type"/>
<result column="cover_img" jdbcType="VARCHAR" property="coverImg"/>
<result column="cover_picture" jdbcType="VARCHAR" property="coverPicture"/>
<result column="detail_picture" jdbcType="VARCHAR" property="detailPicture"/>
<result column="title" jdbcType="VARCHAR" property="title"/>
<result column="sub_title" jdbcType="VARCHAR" property="subTitle"/>
<result column="sale_price" jdbcType="INTEGER" property="salePrice"/>
<result column="use_price" jdbcType="INTEGER" property="usePrice"/>
<result column="use_limit_quantity" jdbcType="INTEGER" property="useLimitQuantity"/>
<result column="send_type" jdbcType="INTEGER" property="sendType"/>
<result column="valid_type" jdbcType="INTEGER" property="validType"/>
<result column="valid_start_date" jdbcType="TIMESTAMP" property="validStartDate"/>
<result column="valid_end_date" jdbcType="TIMESTAMP" property="validEndDate"/>
<result column="valid_days" jdbcType="INTEGER" property="validDays"/>
<result column="detail" jdbcType="VARCHAR" property="detail"/>
<result column="price" jdbcType="INTEGER" property="price"/>
<result column="unit" jdbcType="INTEGER" property="unit"/>
<result column="remain_inventory" jdbcType="INTEGER" property="remainInventory"/>
<result column="inventory" jdbcType="INTEGER" property="inventory"/>
<result column="remark" jdbcType="VARCHAR" property="remark"/>
<result column="status" jdbcType="INTEGER" property="status"/>
<result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
<result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
<result column="business" jdbcType="INTEGER" property="business"/>
<result column="subBusiness" jdbcType="INTEGER" property="subBusiness"/>
<result column="support_transfer" jdbcType="INTEGER" property="supportTransfer"/>
<result column="press_limit_num" jdbcType="INTEGER" property="pressLimitNum"/>
<result column="auto_refund" jdbcType="INTEGER" property="autoRefund"/>
<result column="qr_code" property="qrCode"/>
<result column="conditions" jdbcType="VARCHAR" property="conditions" />
</resultMap>

<select id="findVoDetail" parameterType="java.lang.Long" resultMap="WxCouponCVoMap">
select
<include refid="WxCouponCVoColumn"/>
@@ -282,7 +323,7 @@
where cc.id = #{id}
</select>

<select id="findVoStatusDetail" parameterType="java.lang.Long" resultMap="WxCouponCVoMap">
<select id="findVoStatusDetail" parameterType="java.lang.Long" resultMap="WxCouponCVoMapL">
select
<include refid="CVoStatusColumn"/>
from wx_coupon c, wx_coupon_channel cc


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

@@ -511,6 +511,42 @@
</collection>
</resultMap>

<resultMap id="WxCouponCVoMapL" type="com.iformall.domain.vo.WxCouponCVo">
<id column="id" jdbcType="BIGINT" property="id"/>
<result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
<result column="type" jdbcType="INTEGER" property="type"/>
<result column="cover_img" jdbcType="VARCHAR" property="coverImg"/>
<result column="cover_picture" jdbcType="VARCHAR" property="coverPicture"/>
<result column="detail_picture" jdbcType="VARCHAR" property="detailPicture"/>
<result column="title" jdbcType="VARCHAR" property="title"/>
<result column="sub_title" jdbcType="VARCHAR" property="subTitle"/>
<result column="sale_price" jdbcType="INTEGER" property="salePrice"/>
<result column="use_price" jdbcType="INTEGER" property="usePrice"/>
<result column="use_limit_quantity" jdbcType="INTEGER" property="useLimitQuantity"/>
<result column="send_type" jdbcType="INTEGER" property="sendType"/>
<result column="valid_type" jdbcType="INTEGER" property="validType"/>
<result column="valid_start_date" jdbcType="TIMESTAMP" property="validStartDate"/>
<result column="valid_end_date" jdbcType="TIMESTAMP" property="validEndDate"/>
<result column="valid_days" jdbcType="INTEGER" property="validDays"/>
<result column="detail" jdbcType="VARCHAR" property="detail"/>
<result column="price" jdbcType="INTEGER" property="price"/>
<result column="unit" jdbcType="INTEGER" property="unit"/>
<result column="remain_inventory" jdbcType="INTEGER" property="remainInventory"/>
<result column="inventory" jdbcType="INTEGER" property="inventory"/>
<result column="remark" jdbcType="VARCHAR" property="remark"/>
<result column="status" jdbcType="INTEGER" property="status"/>
<result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
<result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
<result column="business" jdbcType="INTEGER" property="business"/>
<result column="sub_business" jdbcType="INTEGER" property="subBusiness"/>
<result column="support_transfer" jdbcType="INTEGER" property="supportTransfer"/>
<result column="subsidy_type" jdbcType="INTEGER" property="subsidyType"/>
<result column="subsidy_num" jdbcType="INTEGER" property="subsidyNum"/>
<result column="press_limit_num" jdbcType="INTEGER" property="pressLimitNum"/>
<result column="press_limit_hours" jdbcType="INTEGER" property="pressLimitHours"/>
<result column="conditions" jdbcType="VARCHAR" property="conditions"/>
</resultMap>

<select id="findVoDetail" parameterType="java.lang.Long" resultMap="WxCouponCVoMap">
select
<include refid="allColumns"/>
@@ -518,7 +554,7 @@
where id = #{id}
</select>

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


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