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

[标签][修改]:打标签优化,减少查询次数

release_toaliyun_real
Stormeye Wu 6 лет назад
Родитель
Сommit
836bf3df64
5 измененных файлов: 307 добавлений и 8 удалений
  1. +3
    -0
      mallinkService/src/main/java/com/iformall/mapper/WxCardSpendMapper.java
  2. +2
    -0
      mallinkService/src/main/java/com/iformall/mapper/WxCouponOrderMapper.java
  3. +36
    -8
      mallinkService/src/main/java/com/iformall/service/impl/WxCUserTagsServiceImpl.java
  4. +88
    -0
      mallinkService/src/main/resources/mapper/WxCardSpendMapper.xml
  5. +178
    -0
      mallinkService/src/main/resources/mapper/WxCouponOrderMapper.xml

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

@@ -13,6 +13,9 @@ public interface WxCardSpendMapper extends CommonMapper<WxCardSpend, Long> {

int findCount(WxCardSpend wxCardSpend);

List<Map<String,Object>> getCountByBusinessId(WxCardSpend wxCardSpend);
List<Map<String,Object>> getCountByBusinessIdAndSubId(WxCardSpend wxCardSpend);

List<WxCardSpendVo> findCardSpendVoList(WxCardSpendVo wxCardSpend);

List<Map<String,Object>> sumCardSpendVoForMerchant(WxCardSpendVo wxCardSpend);


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

@@ -26,6 +26,8 @@ public interface WxCouponOrderMapper extends CommonMapper<WxCouponOrder, Long> {

//统一的计数接口
int findCount(WxCouponOrder wxCouponOrder);
List<Map<String, Object>> getCountByBusinessId(WxCouponOrder wxCouponOrder);
List<Map<String, Object>> getCountByBusinessIdAndSubId(WxCouponOrder wxCouponOrder);
//统一额度统计接口
int queryPriceTotal(WxCouponOrder wxCouponOrder);



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

@@ -368,11 +368,25 @@ public class WxCUserTagsServiceImpl implements WxCUserTagsService {
WxBusiness business = new WxBusiness();
List<WxBusiness> list = wxBusinessMapper.findList(business);

List<Map<String, Object>> cardSpendCountList = wxCardSpendMapper.getCountByBusinessId(wxCardSpend);
List<Map<String, Object>> cardOrderCountList = wxCouponOrderMapper.getCountByBusinessId(wxCouponOrder);

list.stream().forEach(b->{
wxCardSpend.setBusinessId(b.getId());
wxCouponOrder.setBusinessId(b.getId());
int count = wxCardSpendMapper.findCount(wxCardSpend);
count += wxCouponOrderMapper.findCount(wxCouponOrder);
int count = 0;
if(cardSpendCountList.size() > 0) {
for (Map<String, Object> cardSpendCount : cardSpendCountList) {
if (cardSpendCount.get("businessId").equals(b.getId().toString())) {
count += (Integer) cardSpendCount.get("buCount");
}
}
}
if(cardOrderCountList.size() > 0) {
for (Map<String, Object> cardOrderCount : cardOrderCountList) {
if (cardOrderCount.get("business").equals(b.getId().toString())) {
count += (Integer) cardOrderCount.get("buCount");
}
}
}
if (count > 0) {
EnumTag tag = null;
if (b.getId().intValue() >= EnumBusiness.BUSINESS_ID1.getCode() &&
@@ -419,11 +433,25 @@ public class WxCUserTagsServiceImpl implements WxCUserTagsService {
subBusiness.setBusinessId(EnumBusiness.BUSINESS_ID1.getCode());
List<WxSubBusiness> list = wxSubBusinessMapper.findList(subBusiness);

List<Map<String, Object>> cardSpendCountList = wxCardSpendMapper.getCountByBusinessId(wxCardSpend);
List<Map<String, Object>> cardOrderCountList = wxCouponOrderMapper.getCountByBusinessId(wxCouponOrder);

list.stream().forEach(sb->{
wxCardSpend.setSubBusinessId(sb.getId());
wxCouponOrder.setSubBusinessId(sb.getId());
int count = wxCardSpendMapper.findCount(wxCardSpend);
count += wxCouponOrderMapper.findCount(wxCouponOrder);
int count = 0;
if(cardSpendCountList.size() > 0) {
for (Map<String, Object> cardSpendCount : cardSpendCountList) {
if (cardSpendCount.get("subBusinessId").equals(sb.getId().toString())) {
count += (Integer) cardSpendCount.get("buCount");
}
}
}
if(cardOrderCountList.size() > 0) {
for (Map<String, Object> cardOrderCount : cardOrderCountList) {
if (cardOrderCount.get("subBusiness").equals(sb.getId().toString())) {
count += (Integer) cardOrderCount.get("buCount");
}
}
}
if (count > 0) {
EnumTag tag = null;
if (sb.getId().intValue() >= EnumSubBusiness.SUB_BUSINESS_ID1.getCode() &&


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

@@ -165,6 +165,94 @@
</if>
</select>

<select id="getCountByBusinessId" parameterType="com.iformall.domain.po.WxCardSpend" resultType="hashmap">
select m.business_id, count(m.business_id) bu_count
from wx_card_spend cs
inner join wx_merchant m on m.id = cs.merchant_id
where 1 = 1
<if test=" null != ownerId ">
and cs.`owner_id` = #{ownerId}
</if>
<if test=" null != tenantId ">
and cs.`tenant_id` = #{tenantId}
</if>
<if test=" null != startdate and null!=enddate">
and cs.`create_date` between #{startdate} and #{enddate}
</if>
<if test=" 0 == timeSlot">
and date_format(cs.create_date,'%H:%m') &gt;= '06:00'
and date_format(cs.create_date,'%H:%m') &lt; '18:00'
and date_format(cs.create_date,'%w') in (1,2,3,4,5)
</if>

<if test=" 1 == timeSlot">
and ((date_format(cs.create_date,'%H:%m') &gt;= '18:00'
and date_format(cs.create_date,'%w') in (1,2,3,4))
or
((date_format(cs.create_date,'%H:%m') &lt; '06:00')
and date_format(cs.create_date,'%w') in (1,2,3,4,5)))
</if>

<if test=" 2 == timeSlot">
and date_format(cs.create_date,'%H:%m') &gt;= '06:00'
and date_format(cs.create_date,'%H:%m') &lt; '18:00'
and date_format(cs.create_date,'%w') in (0,6)
</if>

<if test=" 3 == timeSlot">
and ((date_format(cs.create_date,'%H:%m') &gt;= '18:00'
and date_format(cs.create_date,'%w') in (5,6,0))
or
((date_format(cs.create_date,'%H:%m') &lt; '06:00')
and date_format(cs.create_date,'%w') in (6,0)))
</if>
group by m.business_id
</select>

<select id="getCountByBusinessIdAndSubId" parameterType="com.iformall.domain.po.WxCardSpend" resultType="hashmap">
select m.business_id, m.sub_business_id, count(m.business_id + '' + m.sub_business_id) bu_count
from wx_card_spend cs
inner join wx_merchant m on m.id = cs.merchant_id
where 1 = 1
<if test=" null != ownerId ">
and cs.`owner_id` = #{ownerId}
</if>
<if test=" null != tenantId ">
and cs.`tenant_id` = #{tenantId}
</if>
<if test=" null != startdate and null!=enddate">
and cs.`create_date` between #{startdate} and #{enddate}
</if>
<if test=" 0 == timeSlot">
and date_format(cs.create_date,'%H:%m') &gt;= '06:00'
and date_format(cs.create_date,'%H:%m') &lt; '18:00'
and date_format(cs.create_date,'%w') in (1,2,3,4,5)
</if>

<if test=" 1 == timeSlot">
and ((date_format(cs.create_date,'%H:%m') &gt;= '18:00'
and date_format(cs.create_date,'%w') in (1,2,3,4))
or
((date_format(cs.create_date,'%H:%m') &lt; '06:00')
and date_format(cs.create_date,'%w') in (1,2,3,4,5)))
</if>

<if test=" 2 == timeSlot">
and date_format(cs.create_date,'%H:%m') &gt;= '06:00'
and date_format(cs.create_date,'%H:%m') &lt; '18:00'
and date_format(cs.create_date,'%w') in (0,6)
</if>

<if test=" 3 == timeSlot">
and ((date_format(cs.create_date,'%H:%m') &gt;= '18:00'
and date_format(cs.create_date,'%w') in (5,6,0))
or
((date_format(cs.create_date,'%H:%m') &lt; '06:00')
and date_format(cs.create_date,'%w') in (6,0)))
</if>
group by m.business_id, m.sub_business_id
</select>


<resultMap id="VoResultMap" type="com.iformall.domain.vo.WxCardSpendVo">
<id column="id" jdbcType="BIGINT" property="id"/>


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

@@ -329,6 +329,184 @@
</if>
</select>

<select id="getCountByBusinessId" parameterType="com.iformall.domain.po.WxCouponOrder" resultType="hashmap">
select c.business, COUNT(c.business) bu_count
FROM wx_coupon_order co
inner join wx_coupon c on c.id = co.coupon_id
where 1=1
<if test=" null != tenantId">
and co.tenant_id = #{tenantId}
</if>
<if test=" null != couponOrderStatus">
and co.coupon_order_status = #{couponOrderStatus}
</if>
<if test=" null != cUserId">
and co.c_user_id = #{cUserId}
</if>
<if test=" null != couponId ">
and co.coupon_id = #{couponId}
</if>
<if test=" null != couponType ">
and co.coupon_type = #{couponType}
</if>

<if test=" 1 == couponOrderStatus">
<if test=" null != startTime">
and co.update_date &gt;= #{startTime}
</if>
<if test=" null != endTime">
and co.update_date &lt;= #{endTime}
</if>
<if test=" 0 == timeSlot">
and date_format(co.update_date,'%H:%m') &gt;= '06:00'
and date_format(co.update_date,'%H:%m') &lt; '18:00'
and date_format(co.update_date,'%w') in (1,2,3,4,5)
</if>
<if test=" 1 == timeSlot">
and ((date_format(co.update_date,'%H:%m') &gt;= '18:00'
and date_format(co.update_date,'%w') in (1,2,3,4))
or
((date_format(co.update_date,'%H:%m') &lt; '06:00')
and date_format(co.update_date,'%w') in (1,2,3,4,5)))
</if>
<if test=" 2 == timeSlot">
and date_format(co.update_date,'%H:%m') &gt;= '06:00'
and date_format(co.update_date,'%H:%m') &lt; '18:00'
and date_format(co.update_date,'%w') in (0,6)
</if>
<if test=" 3 == timeSlot">
and ((date_format(co.update_date,'%H:%m') &gt;= '18:00'
and date_format(co.update_date,'%w') in (5,6,0))
or
((date_format(co.update_date,'%H:%m') &lt; '06:00')
and date_format(co.update_date,'%w') in (6,0)))
</if>
</if>

<if test=" 1 != couponOrderStatus">
<if test=" null != startTime">
and co.create_date &gt;= #{startTime}
</if>
<if test=" null != endTime">
and co.create_date &lt;= #{endTime}
</if>
<if test=" 0 == timeSlot">
and date_format(co.create_date,'%H:%m') &gt;= '06:00'
and date_format(co.create_date,'%H:%m') &lt; '18:00'
and date_format(co.create_date,'%w') in (1,2,3,4,5)
</if>
<if test=" 1 == timeSlot">
and ((date_format(co.create_date,'%H:%m') &gt;= '18:00'
and date_format(co.create_date,'%w') in (1,2,3,4))
or
((date_format(co.create_date,'%H:%m') &lt; '06:00')
and date_format(co.create_date,'%w') in (1,2,3,4,5)))
</if>
<if test=" 2 == timeSlot">
and date_format(co.create_date,'%H:%m') &gt;= '06:00'
and date_format(co.create_date,'%H:%m') &lt; '18:00'
and date_format(co.create_date,'%w') in (0,6)
</if>
<if test=" 3 == timeSlot">
and ((date_format(co.create_date,'%H:%m') &gt;= '18:00'
and date_format(co.create_date,'%w') in (5,6,0))
or
((date_format(co.create_date,'%H:%m') &lt; '06:00')
and date_format(co.create_date,'%w') in (6,0)))
</if>
</if>
group by c.business
</select>

<select id="getCountByBusinessIdAndSubId" parameterType="com.iformall.domain.po.WxCouponOrder" resultType="hashmap">
select c.business, c.sub_business, COUNT(c.business+''+c.sub_business) bu_count
FROM wx_coupon_order co
inner join wx_coupon c on c.id = co.coupon_id
where 1=1
<if test=" null != tenantId">
and co.tenant_id = #{tenantId}
</if>
<if test=" null != couponOrderStatus">
and co.coupon_order_status = #{couponOrderStatus}
</if>
<if test=" null != cUserId">
and co.c_user_id = #{cUserId}
</if>
<if test=" null != couponId ">
and co.coupon_id = #{couponId}
</if>
<if test=" null != couponType ">
and co.coupon_type = #{couponType}
</if>

<if test=" 1 == couponOrderStatus">
<if test=" null != startTime">
and co.update_date &gt;= #{startTime}
</if>
<if test=" null != endTime">
and co.update_date &lt;= #{endTime}
</if>
<if test=" 0 == timeSlot">
and date_format(co.update_date,'%H:%m') &gt;= '06:00'
and date_format(co.update_date,'%H:%m') &lt; '18:00'
and date_format(co.update_date,'%w') in (1,2,3,4,5)
</if>
<if test=" 1 == timeSlot">
and ((date_format(co.update_date,'%H:%m') &gt;= '18:00'
and date_format(co.update_date,'%w') in (1,2,3,4))
or
((date_format(co.update_date,'%H:%m') &lt; '06:00')
and date_format(co.update_date,'%w') in (1,2,3,4,5)))
</if>
<if test=" 2 == timeSlot">
and date_format(co.update_date,'%H:%m') &gt;= '06:00'
and date_format(co.update_date,'%H:%m') &lt; '18:00'
and date_format(co.update_date,'%w') in (0,6)
</if>
<if test=" 3 == timeSlot">
and ((date_format(co.update_date,'%H:%m') &gt;= '18:00'
and date_format(co.update_date,'%w') in (5,6,0))
or
((date_format(co.update_date,'%H:%m') &lt; '06:00')
and date_format(co.update_date,'%w') in (6,0)))
</if>
</if>

<if test=" 1 != couponOrderStatus">
<if test=" null != startTime">
and co.create_date &gt;= #{startTime}
</if>
<if test=" null != endTime">
and co.create_date &lt;= #{endTime}
</if>
<if test=" 0 == timeSlot">
and date_format(co.create_date,'%H:%m') &gt;= '06:00'
and date_format(co.create_date,'%H:%m') &lt; '18:00'
and date_format(co.create_date,'%w') in (1,2,3,4,5)
</if>
<if test=" 1 == timeSlot">
and ((date_format(co.create_date,'%H:%m') &gt;= '18:00'
and date_format(co.create_date,'%w') in (1,2,3,4))
or
((date_format(co.create_date,'%H:%m') &lt; '06:00')
and date_format(co.create_date,'%w') in (1,2,3,4,5)))
</if>
<if test=" 2 == timeSlot">
and date_format(co.create_date,'%H:%m') &gt;= '06:00'
and date_format(co.create_date,'%H:%m') &lt; '18:00'
and date_format(co.create_date,'%w') in (0,6)
</if>
<if test=" 3 == timeSlot">
and ((date_format(co.create_date,'%H:%m') &gt;= '18:00'
and date_format(co.create_date,'%w') in (5,6,0))
or
((date_format(co.create_date,'%H:%m') &lt; '06:00')
and date_format(co.create_date,'%w') in (6,0)))
</if>
</if>
group by c.business, c.sub_business
</select>

<select id="queryPriceTotalGroup" resultType="com.iformall.domain.vo.CUserDateAmountVo" >
SELECT DATE_FORMAT(create_date,'%Y-%m-%d') as xTime,IFNULL(SUM(coupon_price),0) as price from wx_coupon_order
where tenant_id=#{tenantId} AND create_date &gt;= #{startTime} and create_date &lt; #{endTime} GROUP BY xTime


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