后端bug修复

This commit is contained in:
yovinchen 2024-05-09 14:08:19 +08:00
parent 1e0827b60a
commit 423ae62e51
9 changed files with 118 additions and 83 deletions

View File

@ -34,10 +34,10 @@ public class CodeGet {
// 3数据源配置
DataSourceConfig dsc = new DataSourceConfig();
dsc.setUrl("jdbc:mysql://82.157.68.223:3306/shequ-user?serverTimezone=GMT%2B8&useSSL=false");
dsc.setUrl("jdbc:mysql://82.157.68.223:3306/xlcs-user?serverTimezone=GMT%2B8&useSSL=false");
dsc.setDriverName("com.mysql.cj.jdbc.Driver");
dsc.setUsername("shequ-user");
dsc.setPassword("shequ-user");
dsc.setUsername("xlcs-user");
dsc.setPassword("xlcs-user");
dsc.setDbType(DbType.MYSQL);
mpg.setDataSource(dsc);

View File

@ -8,4 +8,4 @@ spring:
username: nacos
password: nacos
enabled: true
file-extension: yml
file-extension: yml

View File

@ -1,5 +1,10 @@
package com.yovinchen.xlcs.activity.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yovinchen.xlcs.activity.mapper.ActivityInfoMapper;
import com.yovinchen.xlcs.activity.mapper.ActivityRuleMapper;
import com.yovinchen.xlcs.activity.mapper.ActivitySkuMapper;
@ -16,11 +21,6 @@ import com.yovinchen.xlcs.model.product.SkuInfo;
import com.yovinchen.xlcs.vo.activity.ActivityRuleVo;
import com.yovinchen.xlcs.vo.order.CartInfoVo;
import com.yovinchen.xlcs.vo.order.OrderConfirmVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -70,10 +70,10 @@ public class ActivityInfoServiceImpl extends ServiceImpl<ActivityInfoMapper, Act
IPage<ActivityInfo> page = activityInfoMapper.selectPage(pageParam, queryWrapper);
page.getRecords()
.forEach(item -> {
item.setActivityTypeString(item.getActivityType()
.getComment());
});
.forEach(item -> {
item.setActivityTypeString(item.getActivityType()
.getComment());
});
return page;
}
@ -96,8 +96,8 @@ public class ActivityInfoServiceImpl extends ServiceImpl<ActivityInfoMapper, Act
activitySkuQueryWrapper.eq(ActivitySku::getActivityId, activityId);
List<ActivitySku> activitySkuList = activitySkuMapper.selectList(activitySkuQueryWrapper);
List<Long> skuIdList = activitySkuList.stream()
.map(ActivitySku::getSkuId)
.collect(Collectors.toList());
.map(ActivitySku::getSkuId)
.collect(Collectors.toList());
List<SkuInfo> skuInfoList = null;
if (!skuIdList.isEmpty()) {
@ -159,8 +159,8 @@ public class ActivityInfoServiceImpl extends ServiceImpl<ActivityInfoMapper, Act
//从skuInfoList集合获取所有skuId
List<Long> skuIdList = skuInfoList.stream()
.map(SkuInfo::getId)
.collect(Collectors.toList());
.map(SkuInfo::getId)
.collect(Collectors.toList());
//第二步 判断添加商品之前是否参加过活动
// 如果之前参加过活动正在进行中排除商品
@ -436,22 +436,10 @@ public class ActivityInfoServiceImpl extends ServiceImpl<ActivityInfoMapper, Act
optimalActivityRule.setReduceAmount(new BigDecimal("0"));
optimalActivityRule.setSelectType(1);
String ruleDesc = "" +
optimalActivityRule.getConditionNum() +
"元打" +
optimalActivityRule.getBenefitDiscount() +
"折,还差" +
(totalNum - optimalActivityRule.getConditionNum()) +
"";
String ruleDesc = "" + optimalActivityRule.getConditionNum() + "元打" + optimalActivityRule.getBenefitDiscount() + "折,还差" + (totalNum - optimalActivityRule.getConditionNum()) + "";
optimalActivityRule.setRuleDesc(ruleDesc);
} else {
String ruleDesc = "" +
optimalActivityRule.getConditionNum() +
"元打" +
optimalActivityRule.getBenefitDiscount() +
"折,已减" +
optimalActivityRule.getReduceAmount() +
"";
String ruleDesc = "" + optimalActivityRule.getConditionNum() + "元打" + optimalActivityRule.getBenefitDiscount() + "折,已减" + optimalActivityRule.getReduceAmount() + "";
optimalActivityRule.setRuleDesc(ruleDesc);
optimalActivityRule.setSelectType(2);
}
@ -483,22 +471,10 @@ public class ActivityInfoServiceImpl extends ServiceImpl<ActivityInfoMapper, Act
optimalActivityRule.setReduceAmount(new BigDecimal("0"));
optimalActivityRule.setSelectType(1);
String ruleDesc = "" +
optimalActivityRule.getConditionAmount() +
"元减" +
optimalActivityRule.getBenefitAmount() +
"元,还差" +
totalAmount.subtract(optimalActivityRule.getConditionAmount()) +
"";
String ruleDesc = "" + optimalActivityRule.getConditionAmount() + "元减" + optimalActivityRule.getBenefitAmount() + "元,还差" + totalAmount.subtract(optimalActivityRule.getConditionAmount()) + "";
optimalActivityRule.setRuleDesc(ruleDesc);
} else {
String ruleDesc = "" +
optimalActivityRule.getConditionAmount() +
"元减" +
optimalActivityRule.getBenefitAmount() +
"元,已减" +
optimalActivityRule.getReduceAmount() +
"";
String ruleDesc = "" + optimalActivityRule.getConditionAmount() + "元减" + optimalActivityRule.getBenefitAmount() + "元,已减" + optimalActivityRule.getReduceAmount() + "";
optimalActivityRule.setRuleDesc(ruleDesc);
optimalActivityRule.setSelectType(2);
}

View File

@ -153,7 +153,8 @@ public class CartInfoServiceImpl implements CartInfoService {
BoundHashOperations<String, String, CartInfo> hashOperations = redisTemplate.boundHashOps(cartKey);
List<CartInfo> cartInfoList = hashOperations.values();
for (CartInfo cartInfo : cartInfoList) {
hashOperations.delete(cartInfo.getSkuId().toString());
hashOperations.delete(cartInfo.getSkuId()
.toString());
}
}
@ -192,7 +193,8 @@ public class CartInfoServiceImpl implements CartInfoService {
cartInfoList = boundHashOperations.values();
if (!CollectionUtils.isEmpty(cartInfoList)) {
//根据商品添加时间降序
cartInfoList.sort((o1, o2) -> o1.getCreateTime().compareTo(o2.getCreateTime()));
cartInfoList.sort((o1, o2) -> o1.getCreateTime()
.compareTo(o2.getCreateTime()));
}
return cartInfoList;
}
@ -234,7 +236,8 @@ public class CartInfoServiceImpl implements CartInfoService {
List<CartInfo> cartInfoList = boundHashOperations.values();
cartInfoList.forEach(cartInfo -> {
cartInfo.setIsChecked(isChecked);
boundHashOperations.put(cartInfo.getSkuId().toString(), cartInfo);
boundHashOperations.put(cartInfo.getSkuId()
.toString(), cartInfo);
});
this.setCartKeyExpire(cartKey);
}
@ -253,7 +256,8 @@ public class CartInfoServiceImpl implements CartInfoService {
skuIdList.forEach(skuId -> {
CartInfo cartInfo = boundHashOperations.get(skuId.toString());
cartInfo.setIsChecked(isChecked);
boundHashOperations.put(cartInfo.getSkuId().toString(), cartInfo);
boundHashOperations.put(cartInfo.getSkuId()
.toString(), cartInfo);
});
this.setCartKeyExpire(cartKey);
}
@ -270,9 +274,9 @@ public class CartInfoServiceImpl implements CartInfoService {
BoundHashOperations<String, String, CartInfo> boundHashOperations = redisTemplate.boundHashOps(cartKey);
List<CartInfo> cartInfoList = boundHashOperations.values();
//isChecked = 1购物项选中
return cartInfoList.stream().filter(cartInfo -> {
return cartInfo.getIsChecked().intValue() == 1;
}).collect(Collectors.toList());
return cartInfoList != null ? cartInfoList.stream()
.filter(cartInfo -> cartInfo.getIsChecked() == 1)
.collect(Collectors.toList()) : null;
}
/**
@ -286,7 +290,9 @@ public class CartInfoServiceImpl implements CartInfoService {
List<CartInfo> cartInfoList = this.getCartCheckedList(userId);
//查询list数据处理得到skuId集合
List<Long> skuIdList = cartInfoList.stream().map(item -> item.getSkuId()).collect(Collectors.toList());
List<Long> skuIdList = cartInfoList.stream()
.map(item -> item.getSkuId())
.collect(Collectors.toList());
//构建redis的key值
// hash类型 key filed-value

View File

@ -28,6 +28,7 @@ import com.yovinchen.xlcs.order.service.OrderItemService;
import com.yovinchen.xlcs.vo.order.*;
import com.yovinchen.xlcs.vo.product.SkuStockLockVo;
import com.yovinchen.xlcs.vo.user.LeaderAddressVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.BoundHashOperations;
import org.springframework.data.redis.core.RedisTemplate;
@ -39,7 +40,7 @@ import org.springframework.util.StringUtils;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.*;
import java.util.stream.Collectors;
/**
@ -51,6 +52,7 @@ import java.util.stream.Collectors;
* @since 2023-10-12
*/
@Service
@Slf4j
public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo> implements OrderInfoService {
@Autowired
private UserFeignClient userFeignClient;
@ -83,29 +85,66 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
*/
@Override
public OrderConfirmVo confirmOrder() {
//获取用户id
Long userId = AuthContextHolder.getUserId();
// 创建一个线程池
ExecutorService executorService = Executors.newFixedThreadPool(4);
//获取用户对应配送员信息
LeaderAddressVo leaderAddressVo = userFeignClient.getUserAddressByUserId(userId);
// 创建一个ScheduledExecutorService用于处理超时
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(4);
//获取购物车里面选中的商品
List<CartInfo> cartInfoList = cartFeignClient.getCartCheckedList(userId);
// 使用CompletableFuture进行多线程异步处理并设置超时时间为1秒
CompletableFuture<LeaderAddressVo> leaderAddressFuture = CompletableFuture.supplyAsync(() -> {
// 获取用户id
Long userId = AuthContextHolder.getUserId();
// 获取用户对应配送员信息
return userFeignClient.getUserAddressByUserId(userId);
}, executorService);
//唯一标识订单
CompletableFuture<List<CartInfo>> cartInfoFuture = CompletableFuture.supplyAsync(() -> {
// 获取用户id
Long userId = AuthContextHolder.getUserId();
// 获取购物车里面选中的商品
return cartFeignClient.getCartCheckedList(userId);
}, executorService);
// 使用ScheduledExecutorService设置超时
scheduler.schedule(() -> {
leaderAddressFuture.complete(null);
log.info("获取地址信息任务超时");
}, 1, TimeUnit.SECONDS);
scheduler.schedule(() -> {
cartInfoFuture.complete(null);
log.info("获取购物车选中商品任务超时");
}, 1, TimeUnit.SECONDS);
// 等待上述所有异步任务完成
CompletableFuture<Void> allFutures = CompletableFuture.allOf(leaderAddressFuture, cartInfoFuture);
try {
allFutures.get(); // 等待所有任务完成
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
} finally {
executorService.shutdown(); // 关闭线程池
scheduler.shutdown(); // 关闭调度器
}
// 唯一标识订单
String orderNo = System.currentTimeMillis() + "";
redisTemplate.opsForValue()
.set(RedisConst.ORDER_REPEAT + orderNo, orderNo, 24, TimeUnit.HOURS);
//获取购物车满足条件活动和优惠卷信息
OrderConfirmVo orderConfirmVo = activityFeignClient.findCartActivityAndCoupon(cartInfoList, userId);
//封装其他值
orderConfirmVo.setLeaderAddressVo(leaderAddressVo);
// 获取购物车满足条件活动和优惠卷信息
OrderConfirmVo orderConfirmVo = activityFeignClient.findCartActivityAndCoupon(cartInfoFuture.join(), AuthContextHolder.getUserId());
// 封装其他值
orderConfirmVo.setLeaderAddressVo(leaderAddressFuture.join());
orderConfirmVo.setOrderNo(orderNo);
return orderConfirmVo;
}
/**
* 生成订单
*
@ -371,16 +410,14 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
*/
@Override
public IPage<OrderInfo> getOrderInfoByUserIdPage(Page<OrderInfo> pageParam, OrderUserQueryVo orderUserQueryVo) {
IPage<OrderInfo> pageModel = baseMapper.selectPage(pageParam, new LambdaQueryWrapper<OrderInfo>()
.eq(OrderInfo::getUserId, orderUserQueryVo.getUserId())
IPage<OrderInfo> pageModel = baseMapper.selectPage(pageParam, new LambdaQueryWrapper<OrderInfo>().eq(OrderInfo::getUserId, orderUserQueryVo.getUserId())
.eq(OrderInfo::getOrderStatus, orderUserQueryVo.getOrderStatus()));
//获取每个订单把每个订单里面订单项查询封装
List<OrderInfo> orderInfoList = pageModel.getRecords();
for (OrderInfo orderInfo : orderInfoList) {
//根据订单id查询里面所有订单项列表
List<OrderItem> orderItemList = orderItemMapper.selectList(new LambdaQueryWrapper<OrderItem>()
.eq(OrderItem::getOrderId, orderInfo.getId()));
List<OrderItem> orderItemList = orderItemMapper.selectList(new LambdaQueryWrapper<OrderItem>().eq(OrderItem::getOrderId, orderInfo.getId()));
//把订单项集合封装到每个订单里面
orderInfo.setOrderItemList(orderItemList);
//封装订单状态名称
@ -427,8 +464,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
List<OrderInfo> orderInfoList = pageModel.getRecords();
for (OrderInfo orderInfo : orderInfoList) {
//根据订单id查询里面所有订单项列表
List<OrderItem> orderItemList = orderItemMapper.selectList(new LambdaQueryWrapper<OrderItem>()
.eq(OrderItem::getOrderId, orderInfo.getId()));
List<OrderItem> orderItemList = orderItemMapper.selectList(new LambdaQueryWrapper<OrderItem>().eq(OrderItem::getOrderId, orderInfo.getId()));
//把订单项集合封装到每个订单里面
orderInfo.setOrderItemList(orderItemList);
//封装订单状态名称

View File

@ -101,6 +101,7 @@ public class WeXinServiceImpl implements WeixinService {
result.put("signType", "MD5");
result.put("paySign", sign);
result.put("package", packages);
result.put("out_trade_no", paymentInfo.getOrderNo());
//6 返回结果
return result;

View File

@ -4,9 +4,9 @@ package com.yovinchen.xlcs.user.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yovinchen.xlcs.common.result.Result;
import com.yovinchen.xlcs.model.user.Leader;
import com.yovinchen.xlcs.user.service.LeaderService;
import com.yovinchen.xlcs.vo.user.LeaderQueryVo;
import com.yovinchen.xlcs.vo.user.LeaderVo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
@ -17,7 +17,7 @@ import org.springframework.web.bind.annotation.RestController;
/**
* <p>
* 团长表 前端控制器
* 配送员 前端控制器
* </p>
*
* @author yovinchen
@ -34,12 +34,12 @@ public class LeaderController {
// getPageCheckList
@ApiOperation(value = "获取页面列表")
@GetMapping("getPageCheckList/{page}/{limit}")
public Result<IPage<LeaderVo>> getPageCheckList(@ApiParam(name = "page", value = "当前页码", required = true) @PathVariable Long page,
public Result getPageCheckList(@ApiParam(name = "page", value = "当前页码", required = true) @PathVariable Long page,
@ApiParam(name = "limit", value = "每页记录数", required = true) @PathVariable Long limit,
@ApiParam(name = "LeaderQueryVo", value = "查询对象", required = false) LeaderQueryVo leaderQueryVo) {
try {
Page<LeaderVo> pageParam = new Page<>(page, limit);
IPage<LeaderVo> pageModel = leaderService.selectPage(pageParam, leaderQueryVo);
Page<Leader> pageParam = new Page<>(page, limit);
IPage<Leader> pageModel = leaderService.selectPage(pageParam, leaderQueryVo);
return Result.ok(pageModel);
} catch (Exception e) {
throw new RuntimeException("获取sku分页列表异常", e);

View File

@ -5,11 +5,10 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yovinchen.xlcs.model.user.Leader;
import com.yovinchen.xlcs.vo.user.LeaderQueryVo;
import com.yovinchen.xlcs.vo.user.LeaderVo;
/**
* <p>
* 团长表 服务类
* 配送员 服务类
* </p>
*
* @author yovinchen
@ -17,5 +16,5 @@ import com.yovinchen.xlcs.vo.user.LeaderVo;
*/
public interface LeaderService extends IService<Leader> {
IPage<LeaderVo> selectPage(Page<LeaderVo> pageParam, LeaderQueryVo leaderQueryVo);
IPage<Leader> selectPage(Page<Leader> pageParam, LeaderQueryVo leaderQueryVo);
}

View File

@ -1,5 +1,6 @@
package com.yovinchen.xlcs.user.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@ -7,22 +8,38 @@ import com.yovinchen.xlcs.model.user.Leader;
import com.yovinchen.xlcs.user.mapper.LeaderMapper;
import com.yovinchen.xlcs.user.service.LeaderService;
import com.yovinchen.xlcs.vo.user.LeaderQueryVo;
import com.yovinchen.xlcs.vo.user.LeaderVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
/**
* <p>
* 团长表 服务实现类
* 配送员 服务实现类
* </p>
*
* @author yovinchen
* @since 2024-01-30
*/
@Slf4j
@Service
public class LeaderServiceImpl extends ServiceImpl<LeaderMapper, Leader> implements LeaderService {
/**
* 分页查询配送员
*
* @param pageParam
* @param leaderQueryVo
* @return
*/
@Override
public IPage<LeaderVo> selectPage(Page<LeaderVo> pageParam, LeaderQueryVo leaderQueryVo) {
return null;
public IPage<Leader> selectPage(Page<Leader> pageParam, LeaderQueryVo leaderQueryVo) {
log.info("获取配送员分页列表入参{}", pageParam.toString() + leaderQueryVo.toString());
LambdaQueryWrapper<Leader> wrapper = new LambdaQueryWrapper<>();
String keyword = leaderQueryVo.getKeyword();
if (!StringUtils.isEmpty(keyword)) {
//封装条件
wrapper.like(Leader::getName, keyword);
}
return baseMapper.selectPage(pageParam, wrapper);
}
}