|
|
|
|
@@ -1,10 +1,12 @@
|
|
|
|
|
package cn.ysk.cashier.service.impl.order;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
import cn.ysk.cashier.cons.rabbit.RabbitConstants;
|
|
|
|
|
import cn.ysk.cashier.dto.order.TbOrderInfoDto;
|
|
|
|
|
import cn.ysk.cashier.dto.order.TbOrderInfoQueryCriteria;
|
|
|
|
|
import cn.ysk.cashier.dto.order.TbPayCountQueryCriteria;
|
|
|
|
|
import cn.ysk.cashier.exception.BadRequestException;
|
|
|
|
|
import cn.ysk.cashier.mapper.order.TbOrderInfoMapper;
|
|
|
|
|
import cn.ysk.cashier.mapper.product.TbProductMapper;
|
|
|
|
|
import cn.ysk.cashier.mapper.product.TbProductSkuMapper;
|
|
|
|
|
@@ -96,6 +98,36 @@ public class TbOrderInfoServiceImpl implements TbOrderInfoService {
|
|
|
|
|
if (StringUtils.isBlank(criteria.getStatus()) && StringUtils.isBlank(criteria.getSource())) {
|
|
|
|
|
predicate = criteriaBuilder.and(predicate, criteriaBuilder.notEqual(root.get("orderType"), "return"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(criteria.getProductName())) {
|
|
|
|
|
Date startTime, endTime;
|
|
|
|
|
DateTime offsetMonth = cn.hutool.core.date.DateUtil.offsetMonth(new Date(), 3);
|
|
|
|
|
if (criteria.getCreatedAt() != null && criteria.getCreatedAt().size() == 2) {
|
|
|
|
|
Long startLong = criteria.getCreatedAt().get(0);
|
|
|
|
|
Long endLong = criteria.getCreatedAt().get(1);
|
|
|
|
|
|
|
|
|
|
startTime = new Date(startLong);
|
|
|
|
|
endTime = new Date(endLong);
|
|
|
|
|
|
|
|
|
|
// 如果开始时间小于三个月前,不查询
|
|
|
|
|
if (startTime.before(offsetMonth)) {
|
|
|
|
|
throw new BadRequestException("查询时间范围不能超过三个月");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
startTime = offsetMonth;
|
|
|
|
|
endTime = new Date();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<Integer> productIds = tbOrderDetailRepository.findOrderIdsByProductNameLike(criteria.getProductName(),
|
|
|
|
|
criteria.getShopId(), startTime, endTime);
|
|
|
|
|
|
|
|
|
|
if (productIds.isEmpty()) {
|
|
|
|
|
predicate = criteriaBuilder.and(predicate, criteriaBuilder.equal(root.get("id"), 0));
|
|
|
|
|
} else {
|
|
|
|
|
predicate = criteriaBuilder.and(predicate, root.get("id").in(productIds));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return predicate;
|
|
|
|
|
}, pageable);
|
|
|
|
|
|
|
|
|
|
@@ -121,7 +153,7 @@ public class TbOrderInfoServiceImpl implements TbOrderInfoService {
|
|
|
|
|
detail.setRefundNumber(refundNumber);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}else {
|
|
|
|
|
} else {
|
|
|
|
|
details.parallelStream().forEach(detail -> {
|
|
|
|
|
detail.setRefundNumber(detail.getNum());
|
|
|
|
|
});
|
|
|
|
|
@@ -151,10 +183,10 @@ public class TbOrderInfoServiceImpl implements TbOrderInfoService {
|
|
|
|
|
end = createdAt.get(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(ObjectUtil.isEmpty(criteria.getTableName())){
|
|
|
|
|
if (ObjectUtil.isEmpty(criteria.getTableName())) {
|
|
|
|
|
criteria.setTableName(null);
|
|
|
|
|
}
|
|
|
|
|
List<TbOrderPayCountVo> payCountVoList = tbOrderInfoRepository.queryTbOrderPayCount(criteria.getShopId(),criteria.getTableName(), start, end);
|
|
|
|
|
List<TbOrderPayCountVo> payCountVoList = tbOrderInfoRepository.queryTbOrderPayCount(criteria.getShopId(), criteria.getTableName(), start, end);
|
|
|
|
|
BigDecimal totalPayAmount = BigDecimal.ZERO;
|
|
|
|
|
for (TbOrderPayCountVo payCount : payCountVoList) {
|
|
|
|
|
totalPayAmount = totalPayAmount.add(new BigDecimal(payCount.getPayAmount().toString()));
|
|
|
|
|
@@ -171,7 +203,7 @@ public class TbOrderInfoServiceImpl implements TbOrderInfoService {
|
|
|
|
|
result.add(payCount);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
TbOrderPayCountVo payRufund = tbOrderInfoRepository.queryTbOrderRefund(criteria.getShopId(),criteria.getTableName(), start, end);
|
|
|
|
|
TbOrderPayCountVo payRufund = tbOrderInfoRepository.queryTbOrderRefund(criteria.getShopId(), criteria.getTableName(), start, end);
|
|
|
|
|
if (payRufund != null) {
|
|
|
|
|
totalPayAmount = totalPayAmount.subtract(new BigDecimal(payRufund.getPayAmount().toString()));
|
|
|
|
|
payRufund.setPayType("退单");
|
|
|
|
|
@@ -231,7 +263,7 @@ public class TbOrderInfoServiceImpl implements TbOrderInfoService {
|
|
|
|
|
dto.setIsRefund(0);
|
|
|
|
|
dto.setRefundAmount(BigDecimal.ZERO);
|
|
|
|
|
List<TbOrderInfo> tbOrderInfos = tbOrderInfoRepository.selTbOrdersBysource(tbOrderInfo.getId(), tbOrderInfo.getShopId());
|
|
|
|
|
if(!CollectionUtils.isEmpty(tbOrderInfos)){
|
|
|
|
|
if (!CollectionUtils.isEmpty(tbOrderInfos)) {
|
|
|
|
|
dto.setIsRefund(1);
|
|
|
|
|
dto.setRefundAmount(tbOrderInfos.stream().map(TbOrderInfo::getOrderAmount).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
|
|
}
|
|
|
|
|
@@ -250,15 +282,15 @@ public class TbOrderInfoServiceImpl implements TbOrderInfoService {
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public void expired(String orderId) {
|
|
|
|
|
//修改耗材数据
|
|
|
|
|
JSONObject jsonObject1=new JSONObject();
|
|
|
|
|
jsonObject1.put("type","delete");
|
|
|
|
|
JSONObject jsonObject1 = new JSONObject();
|
|
|
|
|
jsonObject1.put("type", "delete");
|
|
|
|
|
|
|
|
|
|
Optional<TbOrderInfo> byId = tbOrderInfoRepository.findById(Integer.valueOf(orderId));
|
|
|
|
|
if (byId != null && byId.isPresent()) {
|
|
|
|
|
TbOrderInfo tbOrderInfo = byId.get();
|
|
|
|
|
if (tbOrderInfo.getStatus().equals("unpaid")) {
|
|
|
|
|
upOrderStatus(tbOrderInfo);
|
|
|
|
|
jsonObject1.put("orderId",tbOrderInfo.getId());
|
|
|
|
|
jsonObject1.put("orderId", tbOrderInfo.getId());
|
|
|
|
|
// 发送取消订单mq消息
|
|
|
|
|
rabbitTemplate.convertAndSend(RabbitConstants.CONS_COLLECT_PUT, RabbitConstants.CONS_COLLECT_ROUTINGKEY_PUT,
|
|
|
|
|
jsonObject1.toJSONString(), new CorrelationData(UUID.randomUUID().toString()));
|
|
|
|
|
@@ -274,7 +306,7 @@ public class TbOrderInfoServiceImpl implements TbOrderInfoService {
|
|
|
|
|
redisUtils.set(CacheKey.ORDER_EXPIRED + tbOrderInfo.getId(), tbOrderInfo.getId(), 60 * 2);
|
|
|
|
|
} else {
|
|
|
|
|
upOrderStatus(tbOrderInfo);
|
|
|
|
|
jsonObject1.put("orderId",tbOrderInfo.getId());
|
|
|
|
|
jsonObject1.put("orderId", tbOrderInfo.getId());
|
|
|
|
|
|
|
|
|
|
// 发送取消订单mq消息
|
|
|
|
|
rabbitTemplate.convertAndSend(RabbitConstants.CONS_COLLECT_PUT, RabbitConstants.CONS_COLLECT_ROUTINGKEY_PUT,
|
|
|
|
|
@@ -360,7 +392,7 @@ public class TbOrderInfoServiceImpl implements TbOrderInfoService {
|
|
|
|
|
public void download(List<TbOrderInfoDto> all, HttpServletResponse response) throws IOException {
|
|
|
|
|
List<Map<String, Object>> list = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
all=all.stream().sorted(Comparator.comparing(TbOrderInfoDto::getId).reversed()).collect(Collectors.toList());
|
|
|
|
|
all = all.stream().sorted(Comparator.comparing(TbOrderInfoDto::getId).reversed()).collect(Collectors.toList());
|
|
|
|
|
for (TbOrderInfoDto tbOrderInfo : all) {
|
|
|
|
|
Map<String, Object> map = new LinkedHashMap<>();
|
|
|
|
|
map.put("订单编号", tbOrderInfo.getOrderNo());
|
|
|
|
|
@@ -408,8 +440,8 @@ public class TbOrderInfoServiceImpl implements TbOrderInfoService {
|
|
|
|
|
map.put("商品信息", productNames);
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
if(ObjectUtil.isNotEmpty(tbOrderInfo.getPayType())&&ObjectUtil.isNotNull(tbOrderInfo.getPayType())){
|
|
|
|
|
switch (tbOrderInfo.getPayType()){
|
|
|
|
|
if (ObjectUtil.isNotEmpty(tbOrderInfo.getPayType()) && ObjectUtil.isNotNull(tbOrderInfo.getPayType())) {
|
|
|
|
|
switch (tbOrderInfo.getPayType()) {
|
|
|
|
|
case "scanCode":
|
|
|
|
|
tbOrderInfo.setPayType("收款码支付");
|
|
|
|
|
break;
|
|
|
|
|
@@ -424,7 +456,7 @@ public class TbOrderInfoServiceImpl implements TbOrderInfoService {
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}else {
|
|
|
|
|
} else {
|
|
|
|
|
tbOrderInfo.setPayType("");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -471,7 +503,7 @@ public class TbOrderInfoServiceImpl implements TbOrderInfoService {
|
|
|
|
|
map.put("状态", tbOrderInfo.getStatus());
|
|
|
|
|
map.put("创建日期", DateUtil.timeStampFormatyMdHms(tbOrderInfo.getCreatedAt()));
|
|
|
|
|
map.put("备注", tbOrderInfo.getRemark());
|
|
|
|
|
map.put("台桌",tbOrderInfo.getTableName());
|
|
|
|
|
map.put("台桌", tbOrderInfo.getTableName());
|
|
|
|
|
list.add(map);
|
|
|
|
|
}
|
|
|
|
|
FileUtil.downloadExcel(list, response);
|
|
|
|
|
|