fix:auth配置错误修复

This commit is contained in:
haoxr 2021-03-17 22:24:54 +08:00
parent 905d21999c
commit 1ebd8ba99e
18 changed files with 49 additions and 65 deletions

View File

@ -45,14 +45,14 @@ public class RabbitMQListener {
try { try {
if (orderService.closeOrder(orderId)) { if (orderService.closeOrder(orderId)) {
// 如果关单成功发送消息释放库存 // 如果关单成功发送消息释放库存
// rabbitTemplate.convertAndSend("product_event_change", "inventory:unlock", orderSn); // rabbitTemplate.convertAndSend("product_event_change", "stock:unlock", orderSn);
List<OmsOrderItem> orderItems = orderItemService.getByOrderId(orderId); List<OmsOrderItem> orderItems = orderItemService.getByOrderId(orderId);
List<InventoryDTO> inventoryList = orderItems.stream().map(orderItem -> InventoryDTO.builder() List<InventoryDTO> inventoryList = orderItems.stream().map(orderItem -> InventoryDTO.builder()
.skuId(orderItem.getSkuId()) .skuId(orderItem.getSkuId())
.count(orderItem.getSkuQuantity()) .count(orderItem.getSkuQuantity())
.build()) .build())
.collect(Collectors.toList()); .collect(Collectors.toList());
inventoryFeignService.unlockInventory(inventoryList); inventoryFeignService.unlockStock(inventoryList);
} else { } else {
// 如果关单失败则订单可能已经被处理直接手动ACK确认消息 // 如果关单失败则订单可能已经被处理直接手动ACK确认消息
channel.basicAck(message.getMessageProperties().getDeliveryTag(), true); channel.basicAck(message.getMessageProperties().getDeliveryTag(), true);

View File

@ -73,7 +73,7 @@ public class OrderPayServiceImpl extends ServiceImpl<OrderPayMapper, OmsOrderPay
.build()) .build())
.collect(Collectors.toList()); .collect(Collectors.toList());
inventoryFeignService.minusInventory(inventoryList); inventoryFeignService.deductStock(inventoryList);
// 添加订单支付记录 // 添加订单支付记录
OmsOrderPay orderPay = OmsOrderPay.builder() OmsOrderPay orderPay = OmsOrderPay.builder()

View File

@ -15,9 +15,9 @@ import com.youlai.common.web.exception.BizException;
import com.youlai.common.web.util.BeanMapperUtils; import com.youlai.common.web.util.BeanMapperUtils;
import com.youlai.common.web.util.RequestUtils; import com.youlai.common.web.util.RequestUtils;
import com.youlai.mall.oms.constant.OmsConstants; import com.youlai.mall.oms.constant.OmsConstants;
import com.youlai.mall.oms.mapper.OrderMapper;
import com.youlai.mall.oms.enums.OrderStatusEnum; import com.youlai.mall.oms.enums.OrderStatusEnum;
import com.youlai.mall.oms.enums.OrderTypeEnum; import com.youlai.mall.oms.enums.OrderTypeEnum;
import com.youlai.mall.oms.mapper.OrderMapper;
import com.youlai.mall.oms.pojo.bo.app.OrderBO; import com.youlai.mall.oms.pojo.bo.app.OrderBO;
import com.youlai.mall.oms.pojo.domain.OmsOrder; import com.youlai.mall.oms.pojo.domain.OmsOrder;
import com.youlai.mall.oms.pojo.domain.OmsOrderDelivery; import com.youlai.mall.oms.pojo.domain.OmsOrderDelivery;
@ -33,13 +33,10 @@ import com.youlai.mall.pms.pojo.dto.SkuDTO;
import com.youlai.mall.ums.api.app.UmsAddressFeignService; import com.youlai.mall.ums.api.app.UmsAddressFeignService;
import com.youlai.mall.ums.api.app.UmsMemberFeignService; import com.youlai.mall.ums.api.app.UmsMemberFeignService;
import com.youlai.mall.ums.pojo.domain.UmsAddress; import com.youlai.mall.ums.pojo.domain.UmsAddress;
import io.netty.util.concurrent.CompleteFuture;
import io.seata.spring.annotation.GlobalTransactional; import io.seata.spring.annotation.GlobalTransactional;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.task.AsyncTaskExecutor; import org.springframework.core.task.AsyncTaskExecutor;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -279,7 +276,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OmsOrder> impleme
.build()) .build())
.collect(Collectors.toList()); .collect(Collectors.toList());
Result result = inventoryFeignService.lockInventory(items); Result result = inventoryFeignService.lockStock(items);
if (!StrUtil.equals(result.getCode(), ResultCode.SUCCESS.getCode())) { if (!StrUtil.equals(result.getCode(), ResultCode.SUCCESS.getCode())) {
throw new BizException("下单失败,锁定库存错误"); throw new BizException("下单失败,锁定库存错误");
} }

View File

@ -12,7 +12,7 @@ public interface InventoryFeignService {
/** /**
* 扣减库存 * 扣减库存
*/ */
@PostMapping("/api.app/v1/skus/{id}/inventory/_deduct") @PostMapping("/api.app/v1/skus/{id}/stock/_deduct")
Result deductInventory(@PathVariable Long id, @RequestParam Integer num); Result deductInventory(@PathVariable Long id, @RequestParam Integer num);

View File

@ -27,18 +27,18 @@ public interface PmsSkuFeignService {
/** /**
* 锁定库存 * 锁定库存
*/ */
@PutMapping("/api.app/v1/skus/batch/lock_inventory") @PutMapping("/api.app/v1/skus/batch/lock_stock")
Result lockInventory(@RequestBody List<InventoryDTO> list); Result lockStock(@RequestBody List<InventoryDTO> list);
/** /**
* 解锁库存 * 解锁库存
*/ */
@PutMapping("/api.app/v1/skus/batch/unlock_inventory") @PutMapping("/api.app/v1/skus/batch/unlock_stock")
Result<Boolean> unlockInventory(@RequestBody List<InventoryDTO> list); Result<Boolean> unlockStock(@RequestBody List<InventoryDTO> list);
@PutMapping("/api.app/v1/skus/batch/minus_inventory") @PutMapping("/api.app/v1/skus/batch/deduct_stock")
Result minusInventory(@RequestBody List<InventoryDTO> list); Result deductStock(@RequestBody List<InventoryDTO> list);
} }

View File

@ -16,7 +16,7 @@ public class PmsSku extends BaseEntity {
private String pic; private String pic;
private Long originPrice; private Long originPrice;
private Long price; private Long price;
private Integer inventory; private Integer stock;
private Integer lockedInventory; private Integer lockedStock;
private String specValueIds; private String specValueIds;
} }

View File

@ -6,6 +6,6 @@ package com.youlai.mall.pms.common.constant;
*/ */
public interface PmsConstants { public interface PmsConstants {
String PRODUCT_INVENTORY_PREFIX = "pms:inventory:"; String PRODUCT_INVENTORY_PREFIX = "pms:stock:";
} }

View File

@ -1,6 +1,5 @@
package com.youlai.mall.pms.controller.app; package com.youlai.mall.pms.controller.app;
import cn.hutool.core.bean.BeanUtil;
import com.youlai.common.result.Result; import com.youlai.common.result.Result;
import com.youlai.mall.pms.pojo.domain.PmsSku; import com.youlai.mall.pms.pojo.domain.PmsSku;
import com.youlai.mall.pms.pojo.dto.SkuDTO; import com.youlai.mall.pms.pojo.dto.SkuDTO;
@ -25,49 +24,46 @@ public class SkuController {
@ApiOperation(value = "商品库存详情", httpMethod = "GET") @ApiOperation(value = "商品库存详情", httpMethod = "GET")
@ApiImplicitParam(name = "id", value = "商品库存ID", required = true, paramType = "path", dataType = "Long") @ApiImplicitParam(name = "id", value = "商品库存ID", required = true, paramType = "path", dataType = "Long")
@GetMapping("/{id}") @GetMapping("/{id}")
public Result detail(@PathVariable Long id) { public Result getById(@PathVariable Long id) {
PmsSku sku = iPmsSkuService.getById(id); PmsSku sku = iPmsSkuService.getById(id);
return Result.success(sku); return Result.success(sku);
} }
@ApiOperation("获取商品的库存数量") @ApiOperation("获取商品的库存数量")
@ApiImplicitParam(name = "id", value = "商品库存ID", required = true, paramType = "path", dataType = "Long") @ApiImplicitParam(name = "id", value = "商品库存ID", required = true, paramType = "path", dataType = "Long")
@GetMapping("/{id}/inventory") @GetMapping("/{id}/stock")
public Result<Integer> getInventoryById(@PathVariable Long id) { public Result<Integer> getStockById(@PathVariable Long id) {
Integer inventory = iPmsSkuService.getInventoryById(id); Integer stock = iPmsSkuService.getStockById(id);
return Result.success(inventory); return Result.success(stock);
} }
@ApiOperation(value = "锁定库存", httpMethod = "PUT") @ApiOperation(value = "锁定库存", httpMethod = "PUT")
@ApiImplicitParam(name = "list", value = "锁定库存", required = true, paramType = "body", dataType = "InventoryNumDTO") @ApiImplicitParam(name = "list", value = "锁定库存", required = true, paramType = "body", dataType = "InventoryNumDTO")
@PutMapping("/batch/lock_inventory") @PutMapping("/batch/lock_stock")
public Result<Boolean> lockInventory(@RequestBody List<InventoryDTO> list) { public Result<Boolean> lockStock(@RequestBody List<InventoryDTO> list) {
boolean result = iPmsSkuService.lockInventory(list); boolean result = iPmsSkuService.lockStock(list);
return Result.judge(result); return Result.judge(result);
} }
@ApiOperation(value = "解锁库存", httpMethod = "PUT") @ApiOperation(value = "解锁库存", httpMethod = "PUT")
@ApiImplicitParam(name = "list", value = "释放库存", required = true, paramType = "body", dataType = "InventoryNumDTO") @ApiImplicitParam(name = "list", value = "释放库存", required = true, paramType = "body", dataType = "InventoryNumDTO")
@PutMapping("/batch/unlock_inventory") @PutMapping("/batch/unlock_stock")
public Result<Boolean> unlockInventory(@RequestBody List<InventoryDTO> list) { public Result<Boolean> unlockStock(@RequestBody List<InventoryDTO> list) {
boolean result = iPmsSkuService.unlockInventory(list); boolean result = iPmsSkuService.unlockStock(list);
return Result.judge(result); return Result.judge(result);
} }
@ApiOperation(value = "扣减库存", httpMethod = "PUT") @ApiOperation(value = "扣减库存", httpMethod = "PUT")
@ApiImplicitParam(name = "list", value = "释放库存", required = true, paramType = "body", dataType = "InventoryNumDTO") @ApiImplicitParam(name = "list", value = "释放库存", required = true, paramType = "body", dataType = "InventoryNumDTO")
@PutMapping("/batch/minus_inventory") @PutMapping("/batch/deduct_stock")
public Result<Boolean> minusInventory(@RequestBody List<InventoryDTO> list) { public Result<Boolean> deductStock(@RequestBody List<InventoryDTO> list) {
boolean result = iPmsSkuService.minusInventory(list); boolean result = iPmsSkuService.deductStock(list);
return Result.judge(result); return Result.judge(result);
} }
@ApiOperation(value = "库存列表", httpMethod = "GET") @ApiOperation(value = "库存列表", httpMethod = "GET")
@ApiImplicitParam(name = "skuIds", value = "库存ID集合", required = true, paramType = "body", dataType = "String") @ApiImplicitParam(name = "skuIds", value = "库存ID集合", required = true, paramType = "body", dataType = "String")
@GetMapping @GetMapping

View File

@ -13,7 +13,7 @@ public class InventoryListener {
/** /**
* 支付成功减库存 * 支付成功减库存
*/ */
public void minusInventory(){ public void deductStock(){
} }

View File

@ -26,7 +26,7 @@ public interface PmsSkuMapper extends BaseMapper<PmsSku> {
" t1.pic,", " t1.pic,",
" t1.origin_price,", " t1.origin_price,",
" t1.price price,", " t1.price price,",
" t1.inventory inventory,", " t1.stock stock,",
" t2.id spu_id,", " t2.id spu_id,",
" t2.NAME product_name,", " t2.NAME product_name,",
" t2.pic product_pic,", " t2.pic product_pic,",

View File

@ -14,14 +14,14 @@ public interface IPmsSkuService extends IService<PmsSku> {
* @param list * @param list
* @return 库存锁定结果 * @return 库存锁定结果
*/ */
boolean lockInventory(List<InventoryDTO> list); boolean lockStock(List<InventoryDTO> list);
/** /**
* 解锁库存 * 解锁库存
* @param list * @param list
* @return 解锁库存结果 * @return 解锁库存结果
*/ */
boolean unlockInventory(List<InventoryDTO> list); boolean unlockStock(List<InventoryDTO> list);
/** /**
@ -29,7 +29,7 @@ public interface IPmsSkuService extends IService<PmsSku> {
* @param id 库存ID * @param id 库存ID
* @return * @return
*/ */
Integer getInventoryById(Long id); Integer getStockById(Long id);
/** /**
@ -39,5 +39,5 @@ public interface IPmsSkuService extends IService<PmsSku> {
*/ */
List<SkuDTO> listBySkuIds(List<Long> ids); List<SkuDTO> listBySkuIds(List<Long> ids);
boolean minusInventory(List<InventoryDTO> list); boolean deductStock(List<InventoryDTO> list);
} }

View File

@ -29,13 +29,13 @@ public class PmsSkuServiceImpl extends ServiceImpl<PmsSkuMapper, PmsSku> impleme
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public boolean lockInventory(List<InventoryDTO> inventories) { public boolean lockStock(List<InventoryDTO> inventories) {
log.info("锁定库存: {}", inventories); log.info("锁定库存: {}", inventories);
inventories.forEach(item -> { inventories.forEach(item -> {
boolean result = this.update(new LambdaUpdateWrapper<PmsSku>() boolean result = this.update(new LambdaUpdateWrapper<PmsSku>()
.eq(PmsSku::getId, item.getSkuId()) .eq(PmsSku::getId, item.getSkuId())
.apply("inventory >= locked_inventory + {0}", item.getCount()) .apply("stock >= locked_inventory + {0}", item.getCount())
.setSql("locked_inventory = locked_inventory + " + item.getCount()) .setSql("locked_inventory = locked_inventory + " + item.getCount())
); );
if (!result) { if (!result) {
@ -47,7 +47,7 @@ public class PmsSkuServiceImpl extends ServiceImpl<PmsSkuMapper, PmsSku> impleme
} }
@Override @Override
public boolean unlockInventory(List<InventoryDTO> inventories) { public boolean unlockStock(List<InventoryDTO> inventories) {
inventories.forEach(item -> { inventories.forEach(item -> {
boolean result = this.update(new LambdaUpdateWrapper<PmsSku>() boolean result = this.update(new LambdaUpdateWrapper<PmsSku>()
.eq(PmsSku::getId, item.getSkuId()) .eq(PmsSku::getId, item.getSkuId())
@ -62,12 +62,12 @@ public class PmsSkuServiceImpl extends ServiceImpl<PmsSkuMapper, PmsSku> impleme
@Override @Override
public boolean minusInventory(List<InventoryDTO> inventories) { public boolean deductStock(List<InventoryDTO> inventories) {
inventories.forEach(item -> { inventories.forEach(item -> {
boolean result = this.update(new LambdaUpdateWrapper<PmsSku>() boolean result = this.update(new LambdaUpdateWrapper<PmsSku>()
.eq(PmsSku::getId, item.getSkuId()) .eq(PmsSku::getId, item.getSkuId())
.setSql("locked_inventory = locked_inventory - " + item.getCount()) .setSql("locked_inventory = locked_inventory - " + item.getCount())
.setSql("inventory = inventory - " + item.getCount()) .setSql("stock = stock - " + item.getCount())
); );
if (!result) { if (!result) {
throw new BizException("扣减库存失败"); throw new BizException("扣减库存失败");
@ -86,13 +86,13 @@ public class PmsSkuServiceImpl extends ServiceImpl<PmsSkuMapper, PmsSku> impleme
* @return * @return
*/ */
@Override @Override
public Integer getInventoryById(Long id) { public Integer getStockById(Long id) {
Integer inventory = 0; Integer stock = 0;
// ->缓存 // ->缓存
Object cacheVal = redisTemplate.opsForValue().get(PmsConstants.PRODUCT_INVENTORY_PREFIX + id); Object cacheVal = redisTemplate.opsForValue().get(PmsConstants.PRODUCT_INVENTORY_PREFIX + id);
if (cacheVal != null) { if (cacheVal != null) {
inventory = Convert.toInt(cacheVal); stock = Convert.toInt(cacheVal);
return inventory; return stock;
} }
// ->数据库 // ->数据库
@ -101,12 +101,12 @@ public class PmsSkuServiceImpl extends ServiceImpl<PmsSkuMapper, PmsSku> impleme
.select(PmsSku::getInventory)); .select(PmsSku::getInventory));
if (pmsSku != null) { if (pmsSku != null) {
inventory = pmsSku.getInventory(); stock = pmsSku.getInventory();
// ->缓存 // ->缓存
redisTemplate.opsForValue().set(PmsConstants.PRODUCT_INVENTORY_PREFIX + id, inventory); redisTemplate.opsForValue().set(PmsConstants.PRODUCT_INVENTORY_PREFIX + id, stock);
} }
return inventory; return stock;
} }

View File

@ -29,7 +29,7 @@ public interface UmsMemberFeignService {
/** /**
* 修改会员积分 * 修改会员积分
*/ */
@PutMapping("/api.admin/v1/members/{id}/point") @PutMapping("/api.admin/v1/members/{id}/points")
Result updatePoint(@PathVariable Long id, @RequestParam Integer num); Result updatePoint(@PathVariable Long id, @RequestParam Integer num);
/** /**

View File

@ -17,7 +17,7 @@ public interface UmsUserMapper extends BaseMapper<UmsMember> {
@Select("<script>" + @Select("<script>" +
" SELECT * from ums_user " + " SELECT * from ums_member " +
" <if test ='user.nickname !=null and user.nickname.trim() neq \"\" ' >" + " <if test ='user.nickname !=null and user.nickname.trim() neq \"\" ' >" +
" AND nickname like concat('%',#{user.nickname},'%')" + " AND nickname like concat('%',#{user.nickname},'%')" +
" </if>" + " </if>" +

View File

@ -9,8 +9,5 @@ spring:
discovery: discovery:
server-addr: http://localhost:8848 server-addr: http://localhost:8848
config: config:
# docker启动nacos-server需要配置
server-addr: ${spring.cloud.nacos.discovery.server-addr} server-addr: ${spring.cloud.nacos.discovery.server-addr}
file-extension: yaml file-extension: yaml
group: DEFAULT_GROUP
prefix: ${spring.application.name}

View File

@ -10,9 +10,6 @@ spring:
server-addr: http://c.youlai.store:8848 server-addr: http://c.youlai.store:8848
namespace: prod_namespace_id namespace: prod_namespace_id
config: config:
# docker启动nacos-server需要配置
server-addr: ${spring.cloud.nacos.discovery.server-addr} server-addr: ${spring.cloud.nacos.discovery.server-addr}
file-extension: yaml file-extension: yaml
group: DEFAULT_GROUP
prefix: ${spring.application.name}
namespace: prod_namespace_id namespace: prod_namespace_id

View File

@ -13,5 +13,3 @@ spring:
server-addr: ${spring.cloud.nacos.discovery.server-addr} server-addr: ${spring.cloud.nacos.discovery.server-addr}
file-extension: yaml file-extension: yaml
group: DEFAULT_GROUP group: DEFAULT_GROUP
prefix: ${spring.application.name}

View File

@ -13,5 +13,4 @@ spring:
# docker启动nacos-server需要配置 # docker启动nacos-server需要配置
server-addr: ${spring.cloud.nacos.discovery.server-addr} server-addr: ${spring.cloud.nacos.discovery.server-addr}
file-extension: yaml file-extension: yaml
prefix: ${spring.application.name}
namespace: prod_namespace_id namespace: prod_namespace_id