增加订单过期耗材消息发送
This commit is contained in:
parent
44844eded6
commit
b32b24a608
|
|
@ -1,10 +1,13 @@
|
|||
package cn.ysk.cashier.config;
|
||||
|
||||
import cn.ysk.cashier.cons.rabbit.RabbitConstants;
|
||||
import cn.ysk.cashier.service.order.TbOrderInfoService;
|
||||
import cn.ysk.cashier.service.shop.TbShopInfoService;
|
||||
import cn.ysk.cashier.system.service.UserService;
|
||||
import cn.ysk.cashier.utils.CacheKey;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.rabbit.connection.CorrelationData;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
|
@ -18,6 +21,7 @@ import org.springframework.transaction.annotation.Propagation;
|
|||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.UUID;
|
||||
|
||||
@Slf4j
|
||||
@Configuration
|
||||
|
|
@ -35,6 +39,12 @@ public class RedisKeyExpirationListener implements MessageListener {
|
|||
@Autowired
|
||||
private TbOrderInfoService tbOrderInfoService;
|
||||
|
||||
private final RabbitTemplate rabbitTemplate;
|
||||
|
||||
public RedisKeyExpirationListener(RabbitTemplate rabbitTemplate) {
|
||||
this.rabbitTemplate = rabbitTemplate;
|
||||
}
|
||||
|
||||
//redis key失效监听
|
||||
@Bean
|
||||
public RedisMessageListenerContainer redisMessageListenerContainer(RedisConnectionFactory connectionFactory) {
|
||||
|
|
@ -55,6 +65,7 @@ public class RedisKeyExpirationListener implements MessageListener {
|
|||
log.info("商户到期 账户名为:{}",account);
|
||||
shopInfoService.update(account);
|
||||
userServiceu.upEnableByusername(account);
|
||||
|
||||
}else if(expiredKey.startsWith(CacheKey.ORDER_EXPIRED)){
|
||||
log.info("监听到订单过期,{}",expiredKey);
|
||||
String orderId = expiredKey.substring(CacheKey.ORDER_EXPIRED.length());
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
package cn.ysk.cashier.cons.rabbit;
|
||||
|
||||
public interface RabbitConstants {
|
||||
String CONS_COLLECT_PUT="cons_collect_put";
|
||||
String CONS_COLLECT_ROUTINGKEY_PUT = "cons_collect_routingkey_put";
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
package cn.ysk.cashier.service.impl.order;
|
||||
|
||||
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;
|
||||
|
|
@ -24,10 +25,13 @@ import cn.ysk.cashier.thirdpay.service.ThirdPayService;
|
|||
import cn.ysk.cashier.utils.*;
|
||||
import cn.ysk.cashier.vo.TbOrderInfoVo;
|
||||
import cn.ysk.cashier.vo.TbOrderPayCountVo;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.amqp.rabbit.connection.CorrelationData;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.domain.*;
|
||||
|
|
@ -66,6 +70,7 @@ public class TbOrderInfoServiceImpl implements TbOrderInfoService {
|
|||
private final RedisUtils redisUtils;
|
||||
private final ThirdPayService thirdPayService;
|
||||
private final TbCashierCartRepository cartRepository;
|
||||
private final RabbitTemplate rabbitTemplate;
|
||||
|
||||
@Value("${thirdPay.url}")
|
||||
private String url;
|
||||
|
|
@ -232,11 +237,20 @@ public class TbOrderInfoServiceImpl implements TbOrderInfoService {
|
|||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void expired(String orderId) {
|
||||
//修改耗材数据
|
||||
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());
|
||||
|
||||
// 发送取消订单mq消息
|
||||
rabbitTemplate.convertAndSend(RabbitConstants.CONS_COLLECT_PUT, RabbitConstants.CONS_COLLECT_ROUTINGKEY_PUT,
|
||||
jsonObject1.toJSONString(), new CorrelationData(UUID.randomUUID().toString()));
|
||||
} else if (tbOrderInfo.getStatus().equals("paying") &&
|
||||
(StringUtils.isBlank(tbOrderInfo.getPayType()) ||
|
||||
!tbOrderInfo.getPayType().equals("deposit"))) {
|
||||
|
|
@ -249,6 +263,11 @@ public class TbOrderInfoServiceImpl implements TbOrderInfoService {
|
|||
redisUtils.set(CacheKey.ORDER_EXPIRED + tbOrderInfo.getId(), tbOrderInfo.getId(), 60 * 2);
|
||||
} else {
|
||||
upOrderStatus(tbOrderInfo);
|
||||
jsonObject1.put("orderId",tbOrderInfo.getId());
|
||||
|
||||
// 发送取消订单mq消息
|
||||
rabbitTemplate.convertAndSend(RabbitConstants.CONS_COLLECT_PUT, RabbitConstants.CONS_COLLECT_ROUTINGKEY_PUT,
|
||||
jsonObject1.toJSONString(), new CorrelationData(UUID.randomUUID().toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ public class TbProductStocktakinServiceImpl implements TbProductStocktakinServic
|
|||
// 查询单位
|
||||
TbShopUnit tbShopUnit = tbShopUnitRepository.findById(product.getUnitId()).orElse(null);
|
||||
|
||||
int phaseNum = productStocktakinDTO.getStocktakinNum() - product.getStockNumber();
|
||||
int phaseNum;
|
||||
|
||||
long times = Instant.now().toEpochMilli();
|
||||
TbProductStockOperate stockOperate = new TbProductStockOperate();
|
||||
|
|
@ -125,12 +125,12 @@ public class TbProductStocktakinServiceImpl implements TbProductStocktakinServic
|
|||
snap.put("coverImg", product.getCoverImg());
|
||||
snap.put("productId", product.getId());
|
||||
snap.put("name", product.getName());
|
||||
snap.put("number", phaseNum);
|
||||
snap.put("unitName", tbShopUnit == null ? null : tbShopUnit.getName());
|
||||
// snap.put("specSnap", tbShopUnit == null ? null : tbShopUnit.getName());
|
||||
|
||||
// 共享库存
|
||||
if (product.getIsDistribute() == 1) {
|
||||
phaseNum = productStocktakinDTO.getStocktakinNum() - product.getStockNumber();
|
||||
round = (int) Math.floor( product.getStockNumber());
|
||||
productStocktakin.setPhasePrice(
|
||||
productStocktakinDTO.getPrice().multiply(BigDecimal.valueOf(phaseNum))
|
||||
|
|
@ -148,13 +148,13 @@ public class TbProductStocktakinServiceImpl implements TbProductStocktakinServic
|
|||
snap.put("stockNumber", product.getStockNumber());
|
||||
|
||||
}else {
|
||||
|
||||
if (productStocktakinDTO.getSkuId() == null) {
|
||||
throw new BadRequestException("非共享库存必须传入skuId");
|
||||
}
|
||||
|
||||
TbProductSku productSku = producSkutMapper.selectByProIdAndId(productStocktakinDTO.getSkuId(),
|
||||
productStocktakinDTO.getProductId());
|
||||
phaseNum = (int) (productStocktakinDTO.getStocktakinNum() - productSku.getStockNumber());
|
||||
|
||||
productStocktakinDTO.setPrice(productSku.getSalePrice());
|
||||
|
||||
|
|
@ -177,6 +177,7 @@ public class TbProductStocktakinServiceImpl implements TbProductStocktakinServic
|
|||
snap.put("stockNumber", productSku.getStockNumber());
|
||||
|
||||
}
|
||||
snap.put("number", phaseNum);
|
||||
productStocktakin.setPrice(productStocktakinDTO.getPrice());
|
||||
productStockDetail.setStockNumber((double) phaseNum);
|
||||
productStockDetail.setCostAmount(productStocktakinDTO.getPrice().multiply(BigDecimal.valueOf(Math.abs(phaseNum))));
|
||||
|
|
|
|||
Loading…
Reference in New Issue