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

[砍价营销数据][修改]:砍价查询数据优化

release_toaliyun_real
Stormeye Wu 7 лет назад
Родитель
Сommit
eaf6adbea2
6 измененных файлов: 89 добавлений и 50 удалений
  1. +6
    -0
      mallinkAdmin/src/main/resources/db/migration/V201906282030__COUPON_PRESS_DATA.sql
  2. +3
    -0
      mallinkService/src/main/java/com/iformall/domain/po/WxOrderPress.java
  3. +6
    -9
      mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java
  4. +1
    -0
      mallinkService/src/main/java/com/iformall/service/impl/WxOrderPressServiceImpl.java
  5. +1
    -0
      mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java
  6. +72
    -41
      mallinkService/src/main/resources/mapper/WxCouponMapper.xml

+ 6
- 0
mallinkAdmin/src/main/resources/db/migration/V201906282030__COUPON_PRESS_DATA.sql Просмотреть файл

@@ -0,0 +1,6 @@
ALTER TABLE `wx_order_press`
ADD COLUMN `coupon_id` bigint(20) null default null AFTER `tenant_id`;

UPDATE `wx_order_press` op, `wx_order` o
SET op.coupon_id = o.product_id
WHERE op.order_id = o.id and op.coupon_id is null;

+ 3
- 0
mallinkService/src/main/java/com/iformall/domain/po/WxOrderPress.java Просмотреть файл

@@ -24,6 +24,8 @@ public class WxOrderPress implements Serializable {

@io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId")
private String tenantId;
@io.swagger.annotations.ApiModelProperty(value="券ID",name="couponId")
private Long couponId;
@io.swagger.annotations.ApiModelProperty(value="订单ID",name="orderId")
private Long orderId;
@io.swagger.annotations.ApiModelProperty(value="砍价参与人ID",name="userId")
@@ -41,6 +43,7 @@ public class WxOrderPress implements Serializable {
{
Id_ASC("`id` ASC"),Id_DESC("`id` DESC")
,TenantId_ASC("`tenant_id` ASC"),TenantId_DESC("`tenant_id` DESC")
,CouponId_ASC("`coupon_id` ASC"),CouponId_DESC("`coupon_id` DESC")
,OrderId_ASC("`order_id` ASC"),OrderId_DESC("`order_id` DESC")
,UserId_ASC("`user_id` ASC"),UserId_DESC("`user_id` DESC")
,PressValue_ASC("`press_value` ASC"),PressValue_DESC("`press_value` DESC")


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

@@ -21,6 +21,8 @@ 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.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
@@ -62,6 +64,10 @@ public class WxCouponServiceImpl implements WxCouponService {
@Autowired
WxCouponChannelMapper wxCouponChannelMapper;

@Autowired
@Qualifier("openRedisTemplate")
RedisTemplate<String, String> openRedisTemplate;

@Override
public ResultData list(WxCoupon wxCoupon, Integer pageNum, Integer pageSize) {
if (null == wxCoupon) wxCoupon = new WxCoupon();
@@ -480,15 +486,6 @@ public class WxCouponServiceImpl implements WxCouponService {

@Override
public PageInfo<WxCouponStatisVo> findPressData(WxCoupon record, Integer pageNum, Integer pageSize) {
if(pageNum == 0) {
wxCouponMapper.delPressData(record);
wxCouponMapper.insertPressData(record);
wxCouponMapper.updatePressData1(record);
wxCouponMapper.updatePressData2(record);
wxCouponMapper.updatePressData3(record);
wxCouponMapper.updatePressData4(record);
wxCouponMapper.updatePressData5(record);
}
return PageHelper.startPage(pageNum, pageSize).doSelectPageInfo(() -> wxCouponMapper.findPressData(record));
}



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

@@ -82,6 +82,7 @@ public class WxOrderPressServiceImpl implements WxOrderPressService {
WxOrderPress orderPress = new WxOrderPress();
orderPress.setId(idWorker.nextId());
orderPress.setTenantId(order.getTenantId());
orderPress.setCouponId(order.getProductId());
orderPress.setOrderId(order.getId());
orderPress.setUserId(cUserId);
orderPress.setCreateDate(curDate);


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

@@ -1428,6 +1428,7 @@ public class WxOrderServiceImpl implements WxOrderService {
int left_total = total;
WxOrderPress orderPress = new WxOrderPress();
orderPress.setId(IdWorker.get().nextId());
orderPress.setCouponId(record.getProductId());
orderPress.setOrderId(orderNumber);
orderPress.setUserId(user.getId());
orderPress.setCreateDate(new Date());


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

@@ -274,9 +274,9 @@
where is_del = 0
<if test=" null != targetAd ">
and 0 = (select count(*) from wx_coupon_channel cc
where c.`id` = cc.coupon_id
and cc.status = 0
and cc.target_ad = #{targetAd})
where c.`id` = cc.coupon_id
and cc.status = 0
and cc.target_ad = #{targetAd})
</if>

<if test=" null != id ">
@@ -497,7 +497,7 @@
<collection column="{productId=id}" property="merchantVoList"
ofType="com.iformall.domain.vo.WxMerchantVo"
javaType="java.util.List"
select="com.iformall.mapper.WxCouponMerchantMapper.findMerchantBaseList" >
select="com.iformall.mapper.WxCouponMerchantMapper.findMerchantBaseList">
</collection>
</resultMap>

@@ -533,7 +533,8 @@
and m.status = 1) = 0
</update>

<select id="findSaleMoneyByDate" parameterType="com.iformall.domain.po.WxCoupon" resultType="com.iformall.domain.vo.WxCouponStatisVo">
<select id="findSaleMoneyByDate" parameterType="com.iformall.domain.po.WxCoupon"
resultType="com.iformall.domain.vo.WxCouponStatisVo">
select DATE_FORMAT(ci.create_date,'%Y-%m-%d') xtime,sum(round(ci.sale_amount/100,2)) xcount from wx_card_info ci
left join wx_coupon c on c.id = ci.coupon_id
where c.type = 100
@@ -541,7 +542,8 @@
group by xtime
</select>

<select id="findPaymentByDate" parameterType="com.iformall.domain.po.WxCoupon" resultType="com.iformall.domain.vo.WxCouponStatisVo">
<select id="findPaymentByDate" parameterType="com.iformall.domain.po.WxCoupon"
resultType="com.iformall.domain.vo.WxCouponStatisVo">
select DATE_FORMAT(wcs.create_date,'%Y-%m-%d') xtime,sum(round(wcs.real_payment/100,2)) xcount from wx_card_info ci
left join wx_coupon c on c.id = ci.coupon_id
left join wx_card_spend wcs on wcs.card_id = ci.id
@@ -612,17 +614,21 @@
<if test="id != null">
and c.id = #{id}
</if>
<if test=" null != sortColumns"> order by ${sortColumns} </if>
<if test=" null == sortColumns"> order by c.status asc,c.create_date desc </if>
<if test=" null != sortColumns">order by ${sortColumns}</if>
<if test=" null == sortColumns">order by c.status asc,c.create_date desc</if>

</select>

<select id="findCouponData" parameterType="com.iformall.domain.po.WxCoupon" resultMap="statisMap">
select c.*,
IFNULL(round((select count(wco.id) from wx_coupon wc,wx_coupon_order wco where wco.coupon_id = wc.id and wco.coupon_order_status = 1 and wc.id = c.id)/(select count(wco.id) from wx_coupon_order wco where wco.coupon_id = c.id)*100,2),0) payment_rate,
IFNULL(round((select count(wco.id) from wx_coupon wc,wx_coupon_order wco where wco.coupon_id = wc.id and
wco.coupon_order_status = 1 and wc.id = c.id)/(select count(wco.id) from wx_coupon_order wco where wco.coupon_id
= c.id)*100,2),0) payment_rate,
(select count(wco.id) from wx_coupon_order wco where wco.coupon_id = c.id) as sale_count,
(select count(wco.id) from wx_coupon wc,wx_coupon_order wco where wco.coupon_id = wc.id and wco.coupon_order_status = 1 and wc.id = c.id) as sum_payment,
(select count(wco.id) from wx_coupon wc,wx_coupon_order wco where wco.coupon_id = wc.id and wco.coupon_order_status = 3 and wc.id = c.id) as backpay_count,
(select count(wco.id) from wx_coupon wc,wx_coupon_order wco where wco.coupon_id = wc.id and
wco.coupon_order_status = 1 and wc.id = c.id) as sum_payment,
(select count(wco.id) from wx_coupon wc,wx_coupon_order wco where wco.coupon_id = wc.id and
wco.coupon_order_status = 3 and wc.id = c.id) as backpay_count,
(select sum(sc.subsidy) from wx_coupon wc
left join wx_coupon_order wo on wo.coupon_id = wc.id
left join wx_merchant_subsidy sc on sc.coupon_order_id = wo.id
@@ -645,35 +651,52 @@
</select>

<select id="findPressData" parameterType="com.iformall.domain.po.WxCoupon" resultMap="statisMap">
select cpd.id, cpd.`cover_img`,cpd.`title`,cpd.`sale_price`,cpd.`price`,
cpd.change_rate, cpd.press_count, cpd.press_succ_count, cpd.join_count, cpd.payment_rate
from wx_coupon_press_data cpd
left join wx_coupon c on c.id = cpd.id
<if test="id != null">
and cpd.tenant_id=#{tenantId}
select c.id, c.`cover_img`,c.`title`,c.`sale_price`,c.`price`,
IFNULL(round((select count(o.id) from wx_order o where o.tenant_id = '1006' and o.product_id = c.id and o.order_status = 1)/
(select count(op.id) from wx_order_press op where op.`tenant_id` = '1006' and op.`coupon_id` = c.`id` and op.first = 1 )*100,2),0) change_rate,
(select count(op.id) from wx_order_press op
where op.`tenant_id` = '1006' and op.first = 1 and op.coupon_id = c.id) as press_count,
(select count(o.id) from wx_order o
where o.`tenant_id` = '1006' and o.product_id = c.id and o.order_status = 1) as press_succ_count,

(select count(op.id) from wx_order_press op
where op.`tenant_id` = '1006' and op.`coupon_id` = c.`id`) as join_count,

IFNULL(round((select count(wco.id) xcount from wx_coupon_order wco
where wco.`tenant_id` = '1006' and wco.coupon_id = c.id and wco.coupon_order_status = 1
)/(select count(op.id) from wx_order_press op
where op.`tenant_id` = '1006' and op.`coupon_id` = c.`id` and op.first = 1)
*100,2),0) as payment_rate

from wx_coupon c where c.type = 8
<if test="tenantId != null">
and c.tenant_id=#{tenantId}
</if>
<if test="id != null">
and cpd.id = #{id}
and c.id = #{id}
</if>
<if test="title != null and title != ''">
and cpd.title like concat('%', #{title},'%')
and c.title like concat('%', #{title},'%')
</if>
<if test=" null != sortColumns"> order by ${sortColumns} </if>
<if test=" null == sortColumns"> order by c.status asc,c.create_date desc </if>
<if test=" null != startdate and null!=enddate">
and c.`create_date` between #{startdate} and #{enddate}
</if>
<if test=" null != sortColumns">order by ${sortColumns}</if>
<if test=" null == sortColumns">order by c.status asc,c.create_date desc</if>
</select>

<insert id="delPressData" parameterType="com.iformall.domain.po.WxCoupon" >
delete from `wx_coupon_press_data` where type = 8 and tenant_id = #{tenantId}
<insert id="delPressData" parameterType="com.iformall.domain.po.WxCoupon">
delete from `wx_coupon_press_data` where tenant_id = #{tenantId}
</insert>

<insert id="insertPressData" parameterType="com.iformall.domain.po.WxCoupon" >
<insert id="insertPressData" parameterType="com.iformall.domain.po.WxCoupon">
insert into `wx_coupon_press_data`
(`id`, `tenant_id`, `cover_img`, `title`, `sale_price`, `price`)
select `id`, `tenant_id`, `cover_img`, `title`, `sale_price`, `price`
from wx_coupon where type = 8 and tenant_id = #{tenantId}
</insert>

<update id="updatePressData1" parameterType="com.iformall.domain.po.WxCoupon" >
<update id="updatePressData1" parameterType="com.iformall.domain.po.WxCoupon">
update wx_coupon_press_data cpd set change_rate =
IFNULL(round((select count(o.id) from wx_order o
where o.tenant_id = #{tenantId} and o.order_status = 1 and o.product_id = cpd.id)/
@@ -698,12 +721,12 @@
where cpd.tenant_id=#{tenantId}
</update>

<update id="updatePressData4" parameterType="com.iformall.domain.po.WxCoupon" >
<update id="updatePressData4" parameterType="com.iformall.domain.po.WxCoupon">
update wx_coupon_press_data cpd set join_count =
(select count(wop.id) from wx_order o
left join wx_order_press wop on wop.order_id = o.id
where o.tenant_id = #{tenantId} and o.product_id = cpd.id and o.payment_type = 0)
where cpd.tenant_id=#{tenantId}
(select count(wop.id) from wx_order o
left join wx_order_press wop on wop.order_id = o.id
where o.tenant_id = #{tenantId} and o.product_id = cpd.id and o.payment_type = 0)
where cpd.tenant_id=#{tenantId}
</update>

<select id="updatePressData5" parameterType="com.iformall.domain.po.WxCoupon">
@@ -718,7 +741,8 @@ where cpd.tenant_id=#{tenantId}
where cpd.tenant_id=#{tenantId}
</select>

<select id="findCouponOrderCount" parameterType="com.iformall.domain.po.WxCoupon" resultType="com.iformall.domain.vo.WxCouponStatisVo">
<select id="findCouponOrderCount" parameterType="com.iformall.domain.po.WxCoupon"
resultType="com.iformall.domain.vo.WxCouponStatisVo">
select DATE_FORMAT(wco.create_date,'%Y-%m-%d') xtime,count(wco.id) xcount from wx_coupon c
left join wx_coupon_order wco on c.id = wco.coupon_id
where c.type not in(8,9,100)
@@ -727,8 +751,8 @@ where cpd.tenant_id=#{tenantId}
</select>


<select id="findCouponPaymentCount" parameterType="com.iformall.domain.po.WxCoupon" resultType="com.iformall.domain.vo.WxCouponStatisVo">
<select id="findCouponPaymentCount" parameterType="com.iformall.domain.po.WxCoupon"
resultType="com.iformall.domain.vo.WxCouponStatisVo">
select DATE_FORMAT(wco.create_date,'%Y-%m-%d') xtime,count(wco.id) xcount from wx_coupon c,wx_coupon_order wco
where c.type not in(8,9,100)
and wco.coupon_id = c.id and wco.coupon_order_status = 1
@@ -736,7 +760,8 @@ where cpd.tenant_id=#{tenantId}
group by xtime
</select>

<select id="priceCouponSaleCount" parameterType="com.iformall.domain.po.WxCoupon" resultType="com.iformall.domain.vo.WxCouponStatisVo">
<select id="priceCouponSaleCount" parameterType="com.iformall.domain.po.WxCoupon"
resultType="com.iformall.domain.vo.WxCouponStatisVo">
select DATE_FORMAT(wco.create_date,'%Y-%m-%d') xtime,count(wco.id) xcount from wx_coupon c,wx_coupon_order wco
where c.type not in(8,9,100)
and wco.coupon_id = c.id and wco.coupon_price > 0
@@ -744,7 +769,8 @@ where cpd.tenant_id=#{tenantId}
group by xtime
</select>

<select id="priceCouponPaymentCount" parameterType="com.iformall.domain.po.WxCoupon" resultType="com.iformall.domain.vo.WxCouponStatisVo">
<select id="priceCouponPaymentCount" parameterType="com.iformall.domain.po.WxCoupon"
resultType="com.iformall.domain.vo.WxCouponStatisVo">
select DATE_FORMAT(wco.create_date,'%Y-%m-%d') xtime,count(wco.id) xcount from wx_coupon c,wx_coupon_order wco
where c.type not in(8,9,100)
and wco.coupon_id = c.id and wco.coupon_order_status = 1 and wco.coupon_price > 0
@@ -774,7 +800,8 @@ where cpd.tenant_id=#{tenantId}


<!--砍价-->
<select id="pressSendHistory" parameterType="com.iformall.domain.po.WxCoupon" resultType="com.iformall.domain.vo.WxCouponStatisVo">
<select id="pressSendHistory" parameterType="com.iformall.domain.po.WxCoupon"
resultType="com.iformall.domain.vo.WxCouponStatisVo">
select DATE_FORMAT(wop.create_date,'%Y-%m-%d') xtime,count(wop.id) xcount from wx_coupon wc
left join wx_order wo on wo.product_id = wc.id
left join wx_order_press wop on wop.order_id = wo.id
@@ -782,14 +809,16 @@ where cpd.tenant_id=#{tenantId}
wop.create_date between #{startdate} and #{enddate}
group by xtime
</select>
<select id="pressSuccHistory" parameterType="com.iformall.domain.po.WxCoupon" resultType="com.iformall.domain.vo.WxCouponStatisVo">
<select id="pressSuccHistory" parameterType="com.iformall.domain.po.WxCoupon"
resultType="com.iformall.domain.vo.WxCouponStatisVo">
select DATE_FORMAT(wo.create_date,'%Y-%m-%d') xtime,count(wo.id) xcount from wx_coupon wc
left join wx_order wo on wo.product_id = wc.id
where wc.type = 8 and wo.order_status = 1
and wo.create_date between #{startdate} and #{enddate}
group by xtime
</select>
<select id="pressPaymentHistory" parameterType="com.iformall.domain.po.WxCoupon" resultType="com.iformall.domain.vo.WxCouponStatisVo">
<select id="pressPaymentHistory" parameterType="com.iformall.domain.po.WxCoupon"
resultType="com.iformall.domain.vo.WxCouponStatisVo">
select DATE_FORMAT(wco.create_date,'%Y-%m-%d') xtime,count(wco.id) xcount from wx_coupon wc
left join wx_coupon_order wco on wco.coupon_id = wc.id
where wc.type = 8 and wco.coupon_order_status = 1
@@ -823,7 +852,7 @@ where cpd.tenant_id=#{tenantId}
and wop.create_date between #{startdate} and #{enddate}
</select>

<select id="priceCouponCancelCount" parameterType="com.iformall.domain.po.WxCoupon" resultType="Long">
<select id="priceCouponCancelCount" parameterType="com.iformall.domain.po.WxCoupon" resultType="Long">
select count(c.id) from wx_coupon c
left join wx_coupon_order wco on c.id = wco.coupon_id
where c.type not in(8,9,100)
@@ -831,7 +860,8 @@ where cpd.tenant_id=#{tenantId}
and wco.coupon_order_status = 3
</select>

<select id="findSaleCardCountHistory" parameterType="com.iformall.domain.po.WxCoupon" resultType="com.iformall.domain.vo.WxCouponStatisVo">
<select id="findSaleCardCountHistory" parameterType="com.iformall.domain.po.WxCoupon"
resultType="com.iformall.domain.vo.WxCouponStatisVo">
select DATE_FORMAT(co.create_date,'%Y-%m-%d') xtime,count(co.id) xcount
from wx_card_info ci
left join wx_coupon c on c.id = ci.coupon_id
@@ -841,7 +871,8 @@ where cpd.tenant_id=#{tenantId}
group by xtime
</select>

<select id="findCouponByTopic" parameterType="com.iformall.domain.po.WxTopic" resultType="com.iformall.domain.po.WxCoupon">
<select id="findCouponByTopic" parameterType="com.iformall.domain.po.WxTopic"
resultType="com.iformall.domain.po.WxCoupon">
select ct.id as id,wc.id as couponId,
wc.tenant_id,wc.`type`,wc.`cover_img`,wc.`cover_picture`,wc.`detail_picture`,wc.`title`,wc.`sub_title`,wc.`sale_price`,wc.`use_price`,wc.`use_limit_quantity`,wc.`send_type`,
wc.`valid_type`,wc.`valid_start_date`,wc.`valid_end_date`,wc.`valid_days`,wc.`detail`,wc.`price`,wc.`unit`,wc.`remain_inventory`,wc.`inventory`,


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