Browse Source

optimize wx_coupon_order sql

release_toaliyun_real
xhxuc 6 years ago
parent
commit
7ca48ca776
4 changed files with 89 additions and 26 deletions
  1. +18
    -2
      mallinkService/src/main/java/com/iformall/domain/vo/WxCouponOrderBVo.java
  2. +15
    -15
      mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java
  3. +2
    -1
      mallinkService/src/main/resources/mapper/WxCardInfoMapper.xml
  4. +54
    -8
      mallinkService/src/main/resources/mapper/WxCouponOrderMapper.xml

+ 18
- 2
mallinkService/src/main/java/com/iformall/domain/vo/WxCouponOrderBVo.java View File

@@ -130,7 +130,16 @@ public class WxCouponOrderBVo extends WxCouponOrder {
@io.swagger.annotations.ApiModelProperty(value="使用券商户名",name="merchantName")
private String merchantName;

@Excel(name = "商铺号", width = 50, orderNum = "5")
// public String getMerchantName() {
// if(this.getCmCount() != null && this.getCmCount() > 1){
// this.merchantName = "[多商户通用]";
// }
// return merchantName;
// }

// private Integer cmCount;

// @Excel(name = "商铺号", width = 50, orderNum = "5")
@TableField(exist = false)
private String shopNumber;

@@ -151,6 +160,13 @@ public class WxCouponOrderBVo extends WxCouponOrder {
@TableField(exist = false)
private Long merchantId;

// public Long getmerchantId(){
// if(this.getCmCount() != null && this.getCmCount() > 1){
// this.merchantId = Long.valueOf(0);
// }
// return merchantId;
// }

@TableField(exist = false)
private Date verifyStartDate;

@@ -173,7 +189,7 @@ public class WxCouponOrderBVo extends WxCouponOrder {
@TableField(exist = false)
private Integer building;

@Excel(name = "楼层楼座", width = 50, orderNum = "12")
// @Excel(name = "楼层楼座", width = 50, orderNum = "12")
@TableField(exist = false)
private String buildingStr;



+ 15
- 15
mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java View File

@@ -312,21 +312,21 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService {
if (c.getCouponOrderStatus().equals(EnumCouponOrderStatus.COUPON_ORDER_USE_WAIT.getCode())) {
c.setUpdateDate(null);
}
if (!c.getMerchantId().equals(0L)) {
List<WxMerchantVo> merchantVoList = c.getMerchantVoList();
if (!CollectionUtils.isEmpty(merchantVoList)) {
StringBuilder shopNumber = new StringBuilder();
StringBuilder building = new StringBuilder();
WxMerchantVo wxMerchantVo = merchantVoList.get(0);
List<WxShopVo> shopVoList = wxMerchantVo.getShopVoList();
for (WxShopVo wxShopVo : shopVoList) {
shopNumber.append(wxShopVo.getShopNumber()).append(";");
building.append(wxShopVo.getBuildingName()).append(wxShopVo.getFloorName()).append(";");
}
c.setShopNumber(shopNumber.toString());
c.setBuildingStr(building.toString());
}
}
// if (!c.getMerchantId().equals(0L)) {
// List<WxMerchantVo> merchantVoList = c.getMerchantVoList();
// if (!CollectionUtils.isEmpty(merchantVoList)) {
// StringBuilder shopNumber = new StringBuilder();
// StringBuilder building = new StringBuilder();
// WxMerchantVo wxMerchantVo = merchantVoList.get(0);
// List<WxShopVo> shopVoList = wxMerchantVo.getShopVoList();
// for (WxShopVo wxShopVo : shopVoList) {
// shopNumber.append(wxShopVo.getShopNumber()).append(";");
// building.append(wxShopVo.getBuildingName()).append(wxShopVo.getFloorName()).append(";");
// }
// c.setShopNumber(shopNumber.toString());
// c.setBuildingStr(building.toString());
// }
// }
});
excelService.exportCsv(list, null, filename, WxCouponOrderBVo.class, filename + ".csv", response, false);
}


+ 2
- 1
mallinkService/src/main/resources/mapper/WxCardInfoMapper.xml View File

@@ -198,7 +198,8 @@

<select id="findVoList" parameterType="com.iformall.domain.vo.WxCardVo" resultMap="VoBaseResultMap">
select <include refid="allVoColumns" />
from wx_card_info ci
from (select ci.`id`, ci.`tenant_id`, ci.`coupon_id`, ci.`transaction_id`, ci.`amount`, ci.`sale_amount`, ci.`remaining_amount`, ci.`service_fee_amount`, ci.`share_fee_amount`, ci.`remaining_share_fee_amount`, ci.`rate_amount`, ci.`create_date`, ci.`update_date` from wx_card_info ci where ci.`tenant_id` = #{tenantId}) ci
<!--from wx_card_info ci -->
left join wx_coupon c on c.id = ci.coupon_id
left join wx_coupon_order co on co.id = ci.id
left join wx_c_user cu on cu.id = co.c_user_id


+ 54
- 8
mallinkService/src/main/resources/mapper/WxCouponOrderMapper.xml View File

@@ -634,14 +634,29 @@
</resultMap>

<sql id="allAdminCouponOrderListColumns">
<!--
co.id,co.tenant_id,co.coupon_id,co.coupon_type,co.expired_time,co.coupon_order_status,co.create_date,co.update_date,co.coupon_price,
c.title,c.sale_price,c.use_price,c.price,c.unit,c.auto_refund,c.business,c.subsidy_type,ms.subsidy subsidy_num,

(case when com.mc=1 then
(select m.name from wx_merchant m, wx_coupon_merchant cm
where m.id = cm.merchant_id and cm.product_id=co.coupon_id and cm.status = 0) else '[多商户通用]' end) as merchant_name,
(case when com.mc = 1 then (select m.id from wx_merchant m,
wx_coupon_merchant cm where m.id = cm.merchant_id and cm.product_id = co.coupon_id
and cm.status = 0) else 0 end) as merchant_id,cu.phone,bu.verify_merchant_name,cal.channel_type
and cm.status = 0) else 0 end) as merchant_id,
cu.phone,bu.verify_merchant_name,cal.channel_type

(case when couc.mc = 1 then m1.name else '[多商户通用]' end) as merchant_name,
(case when couc.mc = 1 then m1.id else 0 end) as merchant_id,
cu.phone,m2.name as verify_merchant_name,cal.channel_type
-->

co.id,co.tenant_id,co.coupon_id,co.coupon_type,co.expired_time,co.coupon_order_status,
co.create_date,co.update_date,co.coupon_price, c.title,c.sale_price,c.use_price,c.price,
c.unit,c.auto_refund,c.business,c.subsidy_type,ms.subsidy subsidy_num,
(CASE WHEN couc.mc = 1 THEN m1.name ELSE '[多商户通用]' END) AS merchant_name,
(CASE WHEN couc.mc = 1 THEN m1.id ELSE 0 END) AS merchant_id,
cu.phone,m2.name AS verify_merchant_name,cal.channel_type
</sql>

<sql id="allAdminCouponOrderDetailColumns">
@@ -654,6 +669,7 @@

<select id="findListOfAdmin" parameterType="com.iformall.domain.vo.WxCouponOrderBVo" resultMap="AdminBVoResultMap">
select <include refid="allAdminCouponOrderListColumns" />
<!--
from wx_coupon_order co
inner join wx_coupon c on c.id = co.coupon_id
inner join (select tco.id as tcoid,
@@ -669,6 +685,34 @@
) bu on bu.bu_id = co.b_user_id
left join wx_merchant_subsidy ms on co.id = ms.coupon_order_id and ms.type = 1
left join wx_coupon_action_log cal on co.id = cal.coupon_order_id and co.coupon_id = cal.coupon_id
-->
<!--
from (select wcm.product_id,wcm.merchant_id,count(1) as mc from wx_coupon_merchant wcm where status = 0 and wcm.tenant_id = #{tenantId} group by product_id) couc
right join (select co.id,co.tenant_id,co.coupon_id,co.c_user_id,co.b_user_id,co.coupon_type,co.expired_time,co.coupon_order_status,co.create_date,co.update_date,co.coupon_price from wx_coupon_order co where co.tenant_id = #{tenantId}) co on co.coupon_id = couc.product_id
inner join wx_c_user cu on cu.id=co.c_user_id
left join wx_coupon c on c.id = co.coupon_id
left join wx_merchant m1 on m1.id = couc.merchant_id
left join wx_merchant_subsidy ms on co.id = ms.coupon_order_id and ms.type = 1
left join wx_merchant_b_user mbu on mbu.id = co.b_user_id
left join wx_merchant m2 on m2.id = mbu.merchant_id
left join wx_coupon_action_log cal on cal.coupon_order_id = co.id and cal.coupon_id = co.coupon_id
where 1=1-->
FROM (
SELECT wcm.product_id,wcm.merchant_id,COUNT(1) AS mc
FROM wx_coupon_merchant wcm
WHERE STATUS = 0 AND wcm.tenant_id = #{tenantId} GROUP BY product_id) couc
RIGHT JOIN (
SELECT co.id,co.tenant_id,co.coupon_id,co.c_user_id,co.b_user_id,co.coupon_type,
co.expired_time,co.coupon_order_status,co.create_date,co.update_date,co.coupon_price
FROM wx_coupon_order co
WHERE co.tenant_id = #{tenantId}) co
ON co.coupon_id = couc.product_id
INNER JOIN wx_c_user cu ON cu.id=co.c_user_id
LEFT JOIN wx_coupon c ON c.id = co.coupon_id
LEFT JOIN wx_merchant m1 ON m1.id = couc.merchant_id
LEFT JOIN wx_merchant_subsidy ms ON co.id = ms.coupon_order_id AND ms.type = 1
LEFT JOIN wx_merchant_b_user mbu ON mbu.id = co.b_user_id LEFT JOIN wx_merchant m2 ON m2.id = mbu.merchant_id
LEFT JOIN wx_coupon_action_log cal ON cal.coupon_order_id = co.id AND cal.coupon_id = co.coupon_id
where 1=1
<choose>
<when test=" null != couponType">
@@ -687,14 +731,16 @@
</if>
<if test=" null != merchantName and merchantName!=''">
and (case when com.mc=1

and (case when couc.mc=1
then
(select m.name from wx_merchant m, wx_coupon_merchant cm
where m.id = cm.merchant_id
and cm.product_id=co.coupon_id
and cm.status = 0)
else'[多商户通用]' end)
like concat('%', #{merchantName},'%')
m1.name
<!--(select m.name from wx_merchant m, wx_coupon_merchant cm
where m.id = cm.merchant_id
and cm.product_id=co.coupon_id
and cm.status = 0)-->
else'[多商户通用]' end)
like concat('%', #{merchantName},'%')
</if>

<if test="startDate != null">


Loading…
Cancel
Save