fix:logback日志错误配置

This commit is contained in:
haoxr 2021-03-21 14:16:32 +08:00
parent a652073ff8
commit 8f74ae5bd0
15 changed files with 102 additions and 136 deletions

View File

@ -22,7 +22,7 @@ public enum PayTypeEnum {
@Getter
private String text;
public static PayTypeEnum getValue(Integer code){
public static PayTypeEnum getByCode(Integer code){
for (PayTypeEnum value : values()) {
if (value.getCode().equals(code)) {
return value;
@ -30,5 +30,4 @@ public enum PayTypeEnum {
}
return null;
}
}

View File

@ -42,7 +42,7 @@ public class RabbitMQConfig {
Map<String, Object> args = new HashMap<>();
args.put("x-dead-letter-exchange", "order.exchange");
args.put("x-dead-letter-routing-key", "order:close"); // 死信路由Key
args.put("x-message-ttl", 60000); // 单位毫秒1分钟测试使用
args.put("x-message-ttl", 10000); // 单位毫秒1分钟测试使用
return new Queue("order.delay.queue", true, false, false, args);
}

View File

@ -46,7 +46,7 @@ public class OmsListener {
log.info("=======================系统自动关闭订单消息消费失败,重新入队=======================");
try {
channel.basicReject(message.getMessageProperties().getDeliveryTag(), true);
} catch (IOException ioException) {
} catch (Exception ioException) {
log.error("系统关单失败");
}
}

View File

@ -1,20 +0,0 @@
package com.youlai.mall.oms.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.youlai.mall.oms.pojo.domain.OmsOrderPay;
/**
* 支付信息表
*
* @author huawei
* @email huawei_code@163.com
* @date 2020-12-30 22:31:10
*/
public interface IOrderPayService extends IService<OmsOrderPay> {
boolean pay(Long orderId);
}

View File

@ -27,10 +27,16 @@ public interface IOrderService extends IService<OmsOrder> {
OrderConfirmVO confirm(OrderConfirmDTO orderConfirmDTO);
/**
* 提交订单
* 订单提交
*/
OrderSubmitVO submit(OrderSubmitDTO orderSubmitDTO) ;
/**
* 订单支付
*/
boolean pay(Long orderId);
/**
* 系统关闭订单
*/

View File

@ -93,7 +93,7 @@ public class CartServiceImpl implements ICartService {
cartItem.setPrice(sku.getPrice());
cartItem.setPic(sku.getPic());
cartItem.setSkuId(sku.getId());
cartItem.setTitle(sku.getTitle());
cartItem.setTitle(sku.getName());
cartItem.setStock(sku.getStock());
cartItem.setChecked(true);
}

View File

@ -1,69 +0,0 @@
package com.youlai.mall.oms.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youlai.common.result.Result;
import com.youlai.common.web.exception.BizException;
import com.youlai.common.web.util.RequestUtils;
import com.youlai.mall.oms.enums.OrderStatusEnum;
import com.youlai.mall.oms.enums.PayTypeEnum;
import com.youlai.mall.oms.mapper.OrderPayMapper;
import com.youlai.mall.oms.pojo.domain.OmsOrder;
import com.youlai.mall.oms.pojo.domain.OmsOrderPay;
import com.youlai.mall.oms.service.ICartService;
import com.youlai.mall.oms.service.IOrderPayService;
import com.youlai.mall.oms.service.IOrderService;
import com.youlai.mall.pms.api.app.PmsSkuFeignService;
import com.youlai.mall.ums.api.UmsMemberFeignService;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.Date;
@Slf4j
@Service
@AllArgsConstructor
public class OrderPayServiceImpl extends ServiceImpl<OrderPayMapper, OmsOrderPay> implements IOrderPayService {
private IOrderService orderService;
private UmsMemberFeignService memberFeignService;
private PmsSkuFeignService skuFeignService;
private ICartService cartService;
@Override
@GlobalTransactional(rollbackFor = Exception.class)
public boolean pay(Long orderId) {
OmsOrder order = orderService.getById(orderId);
if (order != null && !OrderStatusEnum.PENDING_PAYMENT.getCode().equals(order.getStatus())) {
throw new BizException("支付失败,请检查订单状态");
}
// 扣减余额
Long userId = RequestUtils.getUserId();
Long payAmount = order.getPayAmount();
Result deductBalanceResult = memberFeignService.deductBalance(userId, payAmount);
if (!Result.isSuccess(deductBalanceResult)) {
throw new BizException("扣减账户余额失败");
}
// 扣减库存
Result deductStockResult = skuFeignService.deductStock(order.getOrderSn());
if (!Result.isSuccess(deductStockResult)) {
throw new BizException("扣减商品库存失败");
}
// 更新订单状态
order.setStatus(OrderStatusEnum.PAID.getCode());
order.setPayType(PayTypeEnum.BALANCE.getCode());
order.setPayTime(new Date());
orderService.updateById(order);
// 支付成功删除购物车已勾选的商品
cartService.removeCheckedItem();
return true;
}
}

View File

@ -14,6 +14,7 @@ import com.youlai.common.web.util.BeanMapperUtils;
import com.youlai.common.web.util.RequestUtils;
import com.youlai.mall.oms.enums.OrderStatusEnum;
import com.youlai.mall.oms.enums.OrderTypeEnum;
import com.youlai.mall.oms.enums.PayTypeEnum;
import com.youlai.mall.oms.mapper.OrderMapper;
import com.youlai.mall.oms.pojo.domain.OmsOrder;
import com.youlai.mall.oms.pojo.domain.OmsOrderItem;
@ -29,6 +30,7 @@ import com.youlai.mall.pms.pojo.domain.PmsSku;
import com.youlai.mall.pms.pojo.domain.PmsSpu;
import com.youlai.mall.pms.pojo.dto.SkuLockDTO;
import com.youlai.mall.ums.api.UmsAddressFeignService;
import com.youlai.mall.ums.api.UmsMemberFeignService;
import com.youlai.mall.ums.pojo.domain.UmsAddress;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.AllArgsConstructor;
@ -58,6 +60,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OmsOrder> impleme
private RabbitTemplate rabbitTemplate;
private StringRedisTemplate redisTemplate;
private ThreadPoolExecutor threadPoolExecutor;
private UmsMemberFeignService memberFeignService;
/**
* 订单确认
@ -78,7 +81,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OmsOrder> impleme
PmsSku sku = skuFeignService.getSkuById(orderConfirmDTO.getSkuId()).getData();
orderItemDTO.setPrice(sku.getPrice());
orderItemDTO.setPic(sku.getPic());
orderItemDTO.setTitle(sku.getTitle());
orderItemDTO.setTitle(sku.getName());
orderItems.add(orderItemDTO);
} else { // 购物车中商品结算
List<CartVO.CartItem> cartItems = cartService.getCartItems(memberId);
@ -134,7 +137,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OmsOrder> impleme
List<OrderItemDTO> orderItems = submitDTO.getOrderItems();
if (CollectionUtil.isEmpty(orderItems)) {
throw new BizException("订单");
throw new BizException("订单没有商品,请选择商品后提交");
}
// 订单验价
@ -175,7 +178,6 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OmsOrder> impleme
.setTotalQuantity(orderItems.stream().map(item -> item.getCount()).reduce(0, (x, y) -> x + y))
.setTotalAmount(orderItems.stream().map(item -> item.getPrice() * item.getCount()).reduce(0l, (x, y) -> x + y))
.setGmtCreate(new Date());
;
this.save(order);
// 创建订单商品
@ -190,6 +192,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OmsOrder> impleme
orderItemService.saveBatch(orderItemList);
// 将订单放入延时队列超时未支付由交换机order.exchange切换到死信队列完成系统自动关单
log.info("订单超时取消RabbitMQ消息发送订单SN{}",orderToken);
rabbitTemplate.convertAndSend("order.exchange", "order.create", orderToken);
OrderSubmitVO submitVO = new OrderSubmitVO();
@ -200,12 +203,52 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OmsOrder> impleme
}
/**
* 订单支付
* @param orderId
* @return
*/
@Override
@GlobalTransactional(rollbackFor = Exception.class)
public boolean pay(Long orderId) {
OmsOrder order = this.getById(orderId);
if (order != null && !OrderStatusEnum.PENDING_PAYMENT.getCode().equals(order.getStatus())) {
throw new BizException("支付失败,请检查订单状态");
}
// 扣减余额
Long userId = RequestUtils.getUserId();
Long payAmount = order.getPayAmount();
Result deductBalanceResult = memberFeignService.deductBalance(userId, payAmount);
if (!Result.isSuccess(deductBalanceResult)) {
throw new BizException("扣减账户余额失败");
}
// 扣减库存
Result deductStockResult = skuFeignService.deductStock(order.getOrderSn());
if (!Result.isSuccess(deductStockResult)) {
throw new BizException("扣减商品库存失败");
}
// 更新订单状态
order.setStatus(OrderStatusEnum.PAID.getCode());
order.setPayType(PayTypeEnum.BALANCE.getCode());
order.setPayTime(new Date());
this.updateById(order);
// 支付成功删除购物车已勾选的商品
cartService.removeCheckedItem();
return true;
}
@Override
public boolean closeOrder(String orderToken) {
log.info("=======================订单关闭订单SN{}=======================", orderToken);
OmsOrder order = this.getOne(new LambdaQueryWrapper<OmsOrder>()
.eq(OmsOrder::getOrderSn, orderToken));
if (!OrderStatusEnum.PENDING_PAYMENT.getCode().equals(order.getStatus())) {
if (order==null||!OrderStatusEnum.PENDING_PAYMENT.getCode().equals(order.getStatus())) {
return false;
}
order.setStatus(OrderStatusEnum.AUTO_CANCEL.getCode());

View File

@ -1,4 +1,4 @@
package com.youlai.mall.oms.controller.app;
package com.youlai.mall.oms.test.app;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.youlai.common.result.Result;

View File

@ -1,4 +1,4 @@
package com.youlai.mall.oms.controller.app;
package com.youlai.mall.oms.test.app;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -9,7 +9,6 @@ import com.youlai.mall.oms.pojo.dto.OrderConfirmDTO;
import com.youlai.mall.oms.pojo.vo.OrderConfirmVO;
import com.youlai.mall.oms.pojo.vo.OrderSubmitVO;
import com.youlai.mall.oms.pojo.dto.OrderSubmitDTO;
import com.youlai.mall.oms.service.IOrderPayService;
import com.youlai.mall.oms.service.IOrderService;
import io.swagger.annotations.*;
import lombok.AllArgsConstructor;
@ -32,7 +31,6 @@ import javax.validation.Valid;
public class OrderController {
private IOrderService orderService;
private IOrderPayService orderPayService;
@ApiOperation("订单列表")
@GetMapping
@ -73,11 +71,11 @@ public class OrderController {
@ApiImplicitParam(name = "payType", value = "支付方式", paramType = "query", dataType = "Integer")
})
public Result pay(@PathVariable Long orderId, Integer payType) {
PayTypeEnum payTypeEnum = PayTypeEnum.getValue(payType);
PayTypeEnum payTypeEnum = PayTypeEnum.getByCode(payType);
switch (payTypeEnum) {
case BALANCE:
orderPayService.pay(orderId);
orderService.pay(orderId);
break;
default:
return Result.failed("系统暂不支持该支付方式~");

View File

@ -0,0 +1,22 @@
package com.youlai.mall.oms.test;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
@Slf4j
public class RabbitMQTest {
@Autowired
private RabbitTemplate rabbitTemplate;
@Test
public void createOrderTest() {
rabbitTemplate.convertAndSend("order.exchange", "order.create", "4acd475a-c6aa-4d9a-a3a5-40da7472cbee");
}
}

View File

@ -68,10 +68,10 @@ public class SpuController {
@ApiOperation(value = "新增商品")
@ApiImplicitParam(name = "spuBO", value = "实体JSON对象", required = true, paramType = "body", dataType = "PmsSpuBO")
@ApiImplicitParam(name = "productBO", value = "实体JSON对象", required = true, paramType = "body", dataType = "ProductBO")
@PostMapping
public Result add(@RequestBody ProductBO spuBO) {
boolean status = iPmsSpuService.add(spuBO);
public Result add(@RequestBody ProductBO productBO) {
boolean status = iPmsSpuService.add(productBO);
return Result.judge(status);
}

View File

@ -12,13 +12,13 @@ public interface IPmsSpuService extends IService<PmsSpu> {
IPage<PmsSpu> list(Page<PmsSpu> page, PmsSpu spu);
boolean add(com.youlai.mall.pms.pojo.bo.admin.ProductBO spuBO);
boolean add(com.youlai.mall.pms.pojo.bo.admin.ProductBO productBO);
com.youlai.mall.pms.pojo.bo.admin.ProductBO getBySpuId(Long id);
boolean removeBySpuIds(List<Long> spuIds);
boolean updateById(com.youlai.mall.pms.pojo.bo.admin.ProductBO spuBO);
boolean updateById(com.youlai.mall.pms.pojo.bo.admin.ProductBO productBO);
ProductBO getProductByIdForApp(Long id);
}

View File

@ -43,11 +43,11 @@ public class PmsSpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> impleme
@Override
@Transactional
public boolean add(ProductBO spuBO) {
SpuDTO SpuDTO = spuBO.getSpu();
List<PmsSpuAttributeValue> attrValues = spuBO.getAttrs();
List<PmsSpuSpecValue> specs = spuBO.getSpecs();
List<PmsSku> skuList = spuBO.getSkus();
public boolean add(ProductBO productBO) {
SpuDTO SpuDTO = productBO.getSpu();
List<PmsSpuAttributeValue> attrValues = productBO.getAttrs();
List<PmsSpuSpecValue> specs = productBO.getSpecs();
List<PmsSku> skuList = productBO.getSkus();
// spu保存
PmsSpu spu = new PmsSpu();
@ -101,18 +101,18 @@ public class PmsSpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> impleme
List<PmsSku> skus = iPmsSkuService.list(new LambdaQueryWrapper<PmsSku>().eq(PmsSku::getSpuId, id));
// 组合
ProductBO spuBO = new ProductBO(spuDTO, attrs, specs, skus);
return spuBO;
ProductBO productBO = new ProductBO(spuDTO, attrs, specs, skus);
return productBO;
}
@Override
public boolean updateById(com.youlai.mall.pms.pojo.bo.admin.ProductBO spuBO) {
SpuDTO SpuDTO = spuBO.getSpu();
public boolean updateById(com.youlai.mall.pms.pojo.bo.admin.ProductBO productBO) {
SpuDTO SpuDTO = productBO.getSpu();
List<PmsSpuAttributeValue> attrValues = spuBO.getAttrs();
List<PmsSpuSpecValue> specs = spuBO.getSpecs();
List<PmsSku> skuList = spuBO.getSkus();
List<PmsSpuAttributeValue> attrValues = productBO.getAttrs();
List<PmsSpuSpecValue> specs = productBO.getSpecs();
List<PmsSku> skuList = productBO.getSkus();
// spu保存
PmsSpu spu = new PmsSpu();

View File

@ -59,21 +59,8 @@
<appender-ref ref="LOGIN_LOGSTASH"/>
</logger>
<logger name="com.alibaba.nacos" level="ERROR" additivity="true">
<appender-ref ref="CONSOLE"/>
</logger>
<logger name="org.springframework.data.redis" level="ERROR" additivity="true">
<appender-ref ref="CONSOLE"/>
</logger>
<logger name="io.lettuce" level="ERROR" additivity="true">
<appender-ref ref="CONSOLE"/>
</logger>
<!-- 根logger -->
<root>
<level>INFO</level>
<root level="INFO">
<appender-ref ref="CONSOLE"/>
</root>
</configuration>