Commit a97beab2 by 吕明尚

优化订单查询接口

parent 0b790f93
......@@ -70,4 +70,6 @@ public interface SOrderMapper extends BaseMapper<SOrder>
List<SOrder> selectSOrderByMaxTime(SOrder order);
List<SOrder> selectSOrderByStoreIdAndMaxTime(SOrder order);
SOrder sumPrice(SOrder sOrder);
}
package share.system.service;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.IService;
import share.system.domain.SPack;
import java.util.List;
/**
* 套餐Service接口
*
......@@ -65,4 +65,6 @@ public interface IPackService extends IService<SPack> {
Long addPack(SPack sPack);
List<SPack> pageList(SPack sPack);
List<SPack> storeNameByIds(List<Long> longs);
}
......@@ -89,4 +89,6 @@ public interface ISConsumerCouponService extends IService<SConsumerCoupon>
int removeByIdList(List<Long> expiredCoupons);
SConsumerCoupon selectSConsumerCouponByCode(String code);
List<SConsumerCoupon> storeNameByIds(List<Long> longs);
}
......@@ -108,4 +108,6 @@ public interface ISRoomService extends IService<SRoom>
List<SRoom> selectByStoreIds(List<Long> storeIds);
List<SRoomVo> convertDoListToVoList(List<SRoom> roomList);
List<SRoom> storeNameByIds(List<Long> longs);
}
......@@ -112,4 +112,7 @@ public interface ISStoreService extends IService<SStore>
int updateStoreConsumers(SStoreConsumerVo storeConsumer);
SConsumerVo queryBySStoreConsumer(SStoreConsumerVo dto);
List<SStore> storeNameByIds(List<Long> ids);
}
package share.system.service.impl;
import java.util.*;
import java.util.Arrays;
import java.util.stream.Collectors;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import share.common.enums.YesNoEnum;
import share.common.exception.base.BaseException;
import share.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import share.system.domain.SConsumer;
import share.system.domain.SOrder;
import share.system.mapper.PackMapper;
import share.system.domain.SPack;
import share.system.mapper.PackMapper;
import share.system.service.IPackService;
import share.system.service.ISOrderService;
import share.system.service.SConsumerService;
import java.util.*;
import java.util.stream.Collectors;
/**
* 套餐Service业务层处理
*
......@@ -158,4 +157,14 @@ public class PackServiceImpl extends ServiceImpl<PackMapper, SPack> implements I
public List<SPack> pageList(SPack sPack) {
return baseMapper.selectPackList(sPack);
}
@Override
public List<SPack> storeNameByIds(List<Long> longs) {
LambdaQueryWrapper<SPack> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.select(SPack::getId, SPack::getName);
if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(longs)) {
queryWrapper.in(SPack::getId, longs);
}
return this.list(queryWrapper);
}
}
......@@ -590,6 +590,17 @@ public class SConsumerCouponServiceImpl extends ServiceImpl<SConsumerCouponMappe
return baseMapper.selectOne(new LambdaQueryWrapper<>(SConsumerCoupon.class).eq(SConsumerCoupon::getCouponCode, code));
}
@Override
public List<SConsumerCoupon> storeNameByIds(List<Long> longs) {
LambdaQueryWrapper<SConsumerCoupon> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.select(SConsumerCoupon::getId, SConsumerCoupon::getName, SConsumerCoupon::getCouponPayPrice,
SConsumerCoupon::getPlatformType, SConsumerCoupon::getDealgroupId, SConsumerCoupon::getTiktokSkuId);
if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(longs)) {
queryWrapper.in(SConsumerCoupon::getId, longs);
}
return this.list(queryWrapper);
}
private void extracted(SConsumerCoupon item, BigDecimal bigDecimal, SRoom byId, BigDecimal subtract, SStore sStore) {
//计算价格
BigDecimal multiply = bigDecimal.multiply(byId.getPrice());
......
......@@ -354,20 +354,17 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
public TableDataInfoVo pageList(SOrder sOrder) {
List<SOrder> sOrders = selectSOrderList(sOrder);
List<SOrderVo> sOrderVos = convertDosToVos(sOrders);
final BigDecimal[] totalAmount = {new BigDecimal("0.00")};
final BigDecimal[] amount = {new BigDecimal("0.00")};
SOrder summedPrice = baseMapper.sumPrice(sOrder);
//优惠卷售卖总金额
final BigDecimal[] totalSalesAmount = {new BigDecimal("0.00")};
//申请退款总金额
final BigDecimal[] totalRefundAmount = {new BigDecimal("0.00")};
//实际退款总金额
final BigDecimal[] totalRealRefundAmount = {new BigDecimal("0.00")};
Map<Long, SConsumerCoupon> couponMap = consumerCouponService.listByIds(sOrders.stream().map(SOrder::getCouponId).distinct().collect(Collectors.toList()))
Map<Long, SConsumerCoupon> couponMap = consumerCouponService.storeNameByIds(sOrders.stream().map(SOrder::getCouponId).distinct().collect(Collectors.toList()))
.stream().collect(Collectors.toMap(SConsumerCoupon::getId, s -> s));
if (CollectionUtils.isNotEmpty(sOrderVos)) {
sOrderVos.stream().forEach(item -> {
totalAmount[0] = totalAmount[0].add(item.getTotalPrice());
amount[0] = amount[0].add(item.getPayPrice());
if (Objects.nonNull(item.getCouponId())) {
SConsumerCoupon userCoupon = couponMap.get(item.getCouponId());
if (userCoupon != null) {
......@@ -399,8 +396,8 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
tableDataInfo.setTotal(sOrderVos.size());
tableDataInfo.setCode(200);
tableDataInfo.setMsg("查询成功");
tableDataInfo.setTotalAmount(totalAmount[0]);
tableDataInfo.setAmount(amount[0]);
tableDataInfo.setTotalAmount(summedPrice.getTotalPrice());
tableDataInfo.setAmount(summedPrice.getPayPrice());
tableDataInfo.setTotalSalesAmount(totalSalesAmount[0]);
tableDataInfo.setTotalRefundAmount(totalRefundAmount[0]);
tableDataInfo.setTotalRealRefundAmount(totalRealRefundAmount[0]);
......@@ -757,8 +754,11 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
}
}
if (StringUtils.isNoneEmpty(item.getOutTradeNo())) {
item.setOutTradeNo(saobeiApiLogs.stream().filter(saobeiApiLog ->
saobeiApiLog.getTerminalTrace().equals(item.getOutTradeNo())).findFirst().orElse(null).getOutTradeNo());
item.setOutTradeNo(
// saobeiApiLogMap.get(item.getOutTradeNo()).getOutTradeNo()
saobeiApiLogs.stream().filter(saobeiApiLog ->
saobeiApiLog.getTerminalTrace().equals(item.getOutTradeNo())).findFirst().orElse(null).getOutTradeNo()
);
}
});
}
......@@ -1960,7 +1960,7 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
Map<Long, SStore> storeMap;
if (!storeIds.isEmpty()) {
List<SStore> stores = storeService.listByIds(storeIds);
List<SStore> stores = storeService.storeNameByIds(new ArrayList<>(storeIds));
storeMap = stores.stream().collect(Collectors.toMap(SStore::getId, s -> s));
} else {
storeMap = new HashMap<>();
......@@ -1968,7 +1968,7 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
Map<Long, SRoom> roomMap;
if (!roomIds.isEmpty()) {
List<SRoom> rooms = roomService.listByIds(roomIds);
List<SRoom> rooms = roomService.storeNameByIds(new ArrayList<>(roomIds));
roomMap = rooms.stream().collect(Collectors.toMap(SRoom::getId, s -> s));
} else {
roomMap = new HashMap<>();
......@@ -1976,7 +1976,7 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
Map<Long, SConsumerCoupon> couponMap;
if (!couponIds.isEmpty()) {
List<SConsumerCoupon> coupons = consumerCouponService.listByIds(couponIds);
List<SConsumerCoupon> coupons = consumerCouponService.storeNameByIds(new ArrayList<>(couponIds));
couponMap = coupons.stream().collect(Collectors.toMap(SConsumerCoupon::getId, s -> s));
} else {
couponMap = new HashMap<>();
......@@ -1984,7 +1984,7 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
Map<Long, SPack> packMap;
if (!packIds.isEmpty()) {
List<SPack> packs = packService.listByIds(packIds);
List<SPack> packs = packService.storeNameByIds(new ArrayList<>(packIds));
packMap = packs.stream().collect(Collectors.toMap(SPack::getId, s -> s));
} else {
packMap = new HashMap<>();
......@@ -2259,13 +2259,7 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
MemberConfig memberConfig = memberConfigService.getOne(new LambdaQueryWrapper<MemberConfig>().eq(MemberConfig::getId, consumerMember.getMemberConfigId()));
//总金额乘以折扣比例除以100
priceResponse.setPayFee(priceResponse.getPayFee().multiply(memberConfig.getDiscountRatio()).divide(new BigDecimal(100)));
priceResponse.setDiscountFee(priceResponse.getTotalFee().subtract(priceResponse.getPayFee()));
priceResponse.setCouponFee(priceResponse.getDiscountFee());
if (ObjectUtil.isNotEmpty(priceResponse.getDiscountFee()) && priceResponse.getTotalFee().compareTo(new BigDecimal(0.00)) > 0) {
priceResponse.setDiscountRatio(priceResponse.getDiscountFee().divide(priceResponse.getTotalFee(), 2, RoundingMode.HALF_UP).multiply(new BigDecimal(100)));
} else {
priceResponse.setDiscountRatio(new BigDecimal(0));
}
}
} else {
if (ObjectUtil.isNotEmpty(consumerMember)) {
......@@ -2281,6 +2275,12 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
}
}
}
priceResponse.setDiscountFee(priceResponse.getTotalFee().subtract(priceResponse.getPayFee()));
if (ObjectUtil.isNotEmpty(priceResponse.getDiscountFee()) && priceResponse.getTotalFee().compareTo(new BigDecimal(0.00)) > 0) {
priceResponse.setDiscountRatio(priceResponse.getDiscountFee().divide(priceResponse.getTotalFee(), 2, RoundingMode.HALF_UP).multiply(new BigDecimal(100)));
} else {
priceResponse.setDiscountRatio(new BigDecimal(0));
}
} else {
// 判断优惠券是否可以使用
if (Objects.nonNull(user) && Objects.nonNull(request.getCouponId())) {
......@@ -2288,6 +2288,8 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
SConsumerCoupon consumerCoupon = consumerCouponService.getById(request.getCouponId());
computedCouponPrice(request, priceResponse, user, consumerCoupon);
priceResponse.setDuration(new BigDecimal(0));
priceResponse.setBalance(new BigDecimal(0));
priceResponse.setRemainingBalance(new BigDecimal(0));
priceResponse.setRemainingDuration(new BigDecimal(0));
if (priceResponse.getPayFee().compareTo(new BigDecimal(0)) > 0) {
if (ObjectUtil.isNotEmpty(consumerWallet)) {
......@@ -2316,6 +2318,12 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
}
}
}
priceResponse.setDiscountFee(priceResponse.getTotalFee().subtract(priceResponse.getPayFee()));
if (ObjectUtil.isNotEmpty(priceResponse.getDiscountFee()) && priceResponse.getTotalFee().compareTo(new BigDecimal(0.00)) > 0) {
priceResponse.setDiscountRatio(priceResponse.getDiscountFee().divide(priceResponse.getTotalFee(), 2, RoundingMode.HALF_UP).multiply(new BigDecimal(100)));
} else {
priceResponse.setDiscountRatio(new BigDecimal(0));
}
}
return priceResponse;
}
......
......@@ -475,4 +475,14 @@ public class SRoomServiceImpl extends ServiceImpl<SRoomMapper, SRoom> implements
return voList;
}
@Override
public List<SRoom> storeNameByIds(List<Long> longs) {
LambdaQueryWrapper<SRoom> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.select(SRoom::getId, SRoom::getName, SRoom::getImages, SRoom::getRoomType);
if (CollectionUtils.isNotEmpty(longs)) {
queryWrapper.in(SRoom::getId, longs);
}
return this.list(queryWrapper);
}
}
......@@ -366,6 +366,16 @@ public class SStoreServiceImpl extends ServiceImpl<SStoreMapper, SStore> impleme
return storeConsumerMapper.queryBySStoreConsumer(dto);
}
@Override
public List<SStore> storeNameByIds(List<Long> ids) {
LambdaQueryWrapper<SStore> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.select(SStore::getId, SStore::getName, SStore::getAddress);
if (CollectionUtils.isNotEmpty(ids)) {
queryWrapper.in(SStore::getId, ids);
}
return this.list(queryWrapper);
}
/**
* 门店DO集合转换VO集合,按距离排序
*
......
......@@ -267,6 +267,69 @@
and create_time >= #{createTime}
group by store_id) t on t.id = s.id
</select>
<select id="sumPrice" resultType="share.system.domain.SOrder">
select sum(total_price) as totalPrice,
sum(pay_price) as payPrice
from s_order
where pay_status = 1
and is_delete = 0
<if test="orderNo != null and orderNo != ''">and order_no = #{orderNo}</if>
<if test="historicalOrderNo != null and historicalOrderNo != ''">and historical_order_no =
#{historicalOrderNo}
</if>
<if test="outTradeNo != null and outTradeNo != ''">and out_trade_no = #{outTradeNo}</if>
<if test="orderType != null and orderType != ''">and order_type = #{orderType}</if>
<if test="payType != null and payType != ''">and pay_type = #{payType}</if>
<!-- <if test="payStatus != null and payStatus != ''">and pay_status = #{payStatus}</if>-->
<if test="storeId != null and storeId != ''">and store_id = #{storeId}</if>
<if test="roomId != null and roomId != ''">and room_id = #{roomId}</if>
<if test="consumerId != null and consumerId != ''">and consumer_id = #{consumerId}</if>
<if test="consumerName != null and consumerName != ''">and consumer_name = #{consumerName}</if>
<if test="consumerPhone != null and consumerPhone != ''">and consumer_phone = #{consumerPhone}</if>
<if test="packId != null and packId != ''">and pack_id = #{packId}</if>
<if test="packPrice != null and packPrice != ''">and pack_price = #{packPrice}</if>
<if test="couponId != null and couponId != ''">and coupon_id = #{couponId}</if>
<if test="couponPrice != null and couponPrice != ''">and coupon_price = #{couponPrice}</if>
<if test="totalPrice != null and totalPrice != ''">and total_price = #{totalPrice}</if>
<if test="payPrice != null and payPrice != ''">and pay_price = #{payPrice}</if>
<if test="duration != null and duration != ''">and duration = #{duration}</if>
<if test="balance != null and balance != ''">and balance = #{balance}</if>
<if test="discountRatio != null and discountRatio != ''">and discount_ratio = #{discountRatio}</if>
<if test="startPayTime != null">
and DATE_FORMAT(pay_time, '%Y-%m-%d') &gt;= DATE_FORMAT(#{startPayTime}, '%Y-%m-%d')
</if>
<if test="endPayTime != null">
and DATE_FORMAT(pay_time, '%Y-%m-%d') &lt;= DATE_FORMAT(#{endPayTime}, '%Y-%m-%d')
</if>
<if test="payTime != null and payTime != ''">and pay_time = #{payTime}</if>
<if test="timeLong != null and timeLong != ''">and time_long = #{timeLong}</if>
<if test="preStartDate != null">
and DATE_FORMAT(pre_start_date, '%Y-%m-%d') &gt;= DATE_FORMAT(#{preStartDate}, '%Y-%m-%d')
</if>
<if test="preEndDate != null">
and DATE_FORMAT(pre_end_date, '%Y-%m-%d') &lt;= DATE_FORMAT(#{preEndDate}, '%Y-%m-%d')
</if>
<if test="startDate != null">
and DATE_FORMAT(create_time, '%Y-%m-%d') &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d')
</if>
<if test="endDate != null">
and DATE_FORMAT(create_time, '%Y-%m-%d') &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d')
</if>
<if test="status != null and status != '' or status==0">and status = #{status}</if>
<if test="refundStatus != null and refundStatus != ''">and refund_status = #{refundStatus}</if>
<if test="refundReason != null and refundReason != ''">and refund_reason = #{refundReason}</if>
<if test="refundReasonTime != null">and refund_reason_time =
#{refundReasonTime}
</if>
<if test="refundPrice != null and refundPrice != ''">and refund_price = #{refundPrice}</if>
<if test="isDelete != null and isDelete != ''">and is_delete = #{isDelete}</if>
<if test="createBy != null and createBy != ''">and create_by = #{createBy}</if>
<if test="createTime != null and createTime != ''">and create_time = #{createTime}</if>
<if test="updateBy != null and updateBy != ''">and update_by = #{updateBy}</if>
<if test="updateTime != null and updateTime != ''">and update_time = #{updateTime}</if>
<if test="arrivalTime != null and arrivalTime != ''">and arrival_time = #{arrivalTime}</if>
<if test="remark != null and remark != ''">and remark = #{remark}</if>
</select>
<insert id="insertSOrder" parameterType="SOrder" useGeneratedKeys="true" keyProperty="id">
insert into s_order
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment