bug fix
This commit is contained in:
@@ -5,27 +5,24 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.peanut.common.utils.PageUtils;
|
||||
import com.peanut.common.utils.Query;
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.config.Constants;
|
||||
import com.peanut.config.DelayQueueConfig;
|
||||
import com.peanut.modules.book.entity.*;
|
||||
import com.peanut.modules.book.service.*;
|
||||
import com.peanut.modules.book.vo.UserAddressVo;
|
||||
import com.peanut.modules.book.vo.request.BuyOrderListRequestVo;
|
||||
import com.peanut.modules.book.vo.request.ModifyOrderAddressRequestVo;
|
||||
import com.peanut.modules.book.vo.request.ProductRequestVo;
|
||||
import com.peanut.modules.book.vo.request.ProductTransportVo;
|
||||
import com.peanut.modules.book.vo.response.BuyOrderResponseVo;
|
||||
import com.peanut.modules.book.vo.response.ExpressQueryResponseVo;
|
||||
import com.peanut.modules.book.vo.ShippingAddressRequestVo;
|
||||
import com.peanut.modules.book.vo.UserAddressVo;
|
||||
import com.peanut.modules.book.vo.response.OrderAddressResponseVo;
|
||||
import com.peanut.modules.pay.weChatPay.dto.WechatPaymentInfo;
|
||||
import com.peanut.modules.pay.weChatPay.service.WxpayService;
|
||||
import com.peanut.modules.sys.entity.SysConfigEntity;
|
||||
import com.peanut.modules.sys.service.SysConfigService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.ss.formula.functions.Count;
|
||||
import org.springframework.amqp.core.MessagePostProcessor;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -182,7 +179,7 @@ public class BuyOrderController {
|
||||
buyOrderService.save(buyOrder);
|
||||
|
||||
for (BuyOrderDetail buyOrderDetail : buyOrderDetails) {
|
||||
buyOrderDetail.setOrderId(buyOrder.getOrderId());
|
||||
buyOrderDetail.setOrderId(buyOrder.getId());
|
||||
buyOrderDetail.setUserId(buyOrder.getUserId());
|
||||
if (Constants.BUY_TYPE_CART.equals(buyOrder.getBuyType())) {
|
||||
handleBuyCart(buyOrder, buyOrderDetail);
|
||||
@@ -207,12 +204,12 @@ public class BuyOrderController {
|
||||
rabbitTemplate.convertAndSend(
|
||||
DelayQueueConfig.ORDER_TO_BE_PAY_EXCHANGE,
|
||||
DelayQueueConfig.ORDER_TO_BE_PAY_ROUTING_KEY,
|
||||
buyOrder.getOrderId(),
|
||||
buyOrder.getId(),
|
||||
messagePostProcessor()
|
||||
);
|
||||
WechatPaymentInfo paymentInfo = new WechatPaymentInfo();
|
||||
paymentInfo.setOrderSn(orderSn);
|
||||
paymentInfo.setBuyOrderId(buyOrder.getOrderId());
|
||||
paymentInfo.setBuyOrderId(buyOrder.getId());
|
||||
paymentInfo.setTotalAmount(totalPrice);
|
||||
wxpayService.prepay(paymentInfo);
|
||||
}
|
||||
@@ -229,9 +226,9 @@ public class BuyOrderController {
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
@RequestMapping(value = "placeOrder", method = RequestMethod.POST)
|
||||
@RequestMapping(value = "/placeOrder", method = RequestMethod.POST)
|
||||
public R placeOrder(@RequestBody BuyOrder buyOrder) throws IOException {
|
||||
List<BuyOrderProduct> buyOrderProductList = buyOrder.getProductInfoList();
|
||||
List<BuyOrderProduct> buyOrderProductList = buyOrder.getProductList();
|
||||
// 订单总金额
|
||||
BigDecimal totalPrice = new BigDecimal(0);
|
||||
// 遍历商品总价计算
|
||||
@@ -244,8 +241,6 @@ public class BuyOrderController {
|
||||
return R.error(500, "库存不足");
|
||||
}
|
||||
totalPrice = totalPrice.add(price.multiply(BigDecimal.valueOf(quantity)));
|
||||
//buyOrderDetail.setProductName(product.getProductName());
|
||||
//buyOrderDetail.setProductPrice(product.getPrice());
|
||||
int originWeight = product.getWeight();
|
||||
int originWeightIntValue = originWeight / 100;
|
||||
int originWeightDecimalValue = originWeightIntValue % 100;
|
||||
@@ -272,7 +267,7 @@ public class BuyOrderController {
|
||||
buyOrderService.save(buyOrder);
|
||||
|
||||
for (BuyOrderProduct buyOrderDetail : buyOrderProductList) {
|
||||
buyOrderDetail.setOrderId(buyOrder.getOrderId());
|
||||
buyOrderDetail.setOrderId(buyOrder.getId());
|
||||
//buyOrderDetail.setUserId(buyOrder.getUserId());
|
||||
if (Constants.BUY_TYPE_CART.equals(buyOrder.getBuyType())) {
|
||||
handleBuyCart(buyOrder, buyOrderDetail);
|
||||
@@ -298,12 +293,12 @@ public class BuyOrderController {
|
||||
rabbitTemplate.convertAndSend(
|
||||
DelayQueueConfig.ORDER_TO_BE_PAY_EXCHANGE,
|
||||
DelayQueueConfig.ORDER_TO_BE_PAY_ROUTING_KEY,
|
||||
buyOrder.getOrderId(),
|
||||
buyOrder.getId(),
|
||||
messagePostProcessor()
|
||||
);
|
||||
WechatPaymentInfo paymentInfo = new WechatPaymentInfo();
|
||||
paymentInfo.setOrderSn(orderSn);
|
||||
paymentInfo.setBuyOrderId(buyOrder.getOrderId());
|
||||
paymentInfo.setBuyOrderId(buyOrder.getId());
|
||||
paymentInfo.setTotalAmount(totalPrice);
|
||||
wxpayService.prepay(paymentInfo);
|
||||
}
|
||||
@@ -347,6 +342,40 @@ public class BuyOrderController {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param orderSn 订单号
|
||||
* @return R
|
||||
*/
|
||||
@RequestMapping(value = "/cancelOrder", method = RequestMethod.GET)
|
||||
@Transactional
|
||||
public R appDelete(@RequestParam("orderSn") String orderSn) {
|
||||
QueryWrapper<BuyOrder> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("order_sn", orderSn);
|
||||
BuyOrder buyOrder = buyOrderService.getOne(queryWrapper);
|
||||
|
||||
if (buyOrder == null) {
|
||||
return R.error("订单不存在");
|
||||
}
|
||||
if (buyOrder.getCouponId() != null) {
|
||||
Integer couponId = buyOrder.getCouponId();
|
||||
CouponHistoryEntity couponHistory = couponHistoryService.getById(couponId);
|
||||
couponHistory.setUseStatus(0);
|
||||
couponHistoryService.updateById(couponHistory);
|
||||
}
|
||||
// 库存回滚
|
||||
QueryWrapper<BuyOrderProduct> buyOrderProductQueryWrapper = new QueryWrapper<>();
|
||||
buyOrderProductQueryWrapper.eq("order_id",buyOrder.getId());
|
||||
List<BuyOrderProduct> buyOrderProductList = buyOrderProductService.list(buyOrderProductQueryWrapper);
|
||||
for (BuyOrderProduct buyOrderProduct : buyOrderProductList) {
|
||||
Integer productId = buyOrderProduct.getProductId();
|
||||
ShopProduct product = shopProductService.getById(productId);
|
||||
product.setProductStock(product.getProductStock() + buyOrderProduct.getQuantity());
|
||||
shopProductService.updateById(product);
|
||||
}
|
||||
buyOrderService.removeById(buyOrder.getId());
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
@@ -389,7 +418,7 @@ public class BuyOrderController {
|
||||
}
|
||||
// 库存回滚
|
||||
List<BuyOrderDetail> buyOrderDetailEntities = buyOrderDetailService.getBaseMapper().selectList(new QueryWrapper<BuyOrderDetail>()
|
||||
.eq("order_id", byId.getOrderId()));
|
||||
.eq("order_id", byId.getId()));
|
||||
for (BuyOrderDetail buyOrderDetailEntity : buyOrderDetailEntities) {
|
||||
Integer productId = buyOrderDetailEntity.getProductId();
|
||||
ShopProduct product = shopProductService.getById(productId);
|
||||
@@ -401,39 +430,6 @@ public class BuyOrderController {
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param orderSn 订单号
|
||||
* @return R
|
||||
*/
|
||||
@RequestMapping("/cancelOrder")
|
||||
@Transactional
|
||||
public R appDelete(@RequestParam("orderSn") String orderSn) {
|
||||
QueryWrapper<BuyOrder> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("order_sn", orderSn);
|
||||
BuyOrder buyOrder = buyOrderService.getOne(queryWrapper);
|
||||
|
||||
if (buyOrder == null) {
|
||||
return R.error("订单不存在");
|
||||
}
|
||||
if (buyOrder.getCouponId() != null) {
|
||||
Integer couponId = buyOrder.getCouponId();
|
||||
CouponHistoryEntity couponHistory = couponHistoryService.getById(couponId);
|
||||
couponHistory.setUseStatus(0);
|
||||
couponHistoryService.updateById(couponHistory);
|
||||
}
|
||||
// 库存回滚
|
||||
List<BuyOrderProduct> buyOrderProductList = buyOrderProductService.getBaseMapper().selectList(new QueryWrapper<BuyOrderProduct>()
|
||||
.eq("order_id", buyOrder.getOrderId()));
|
||||
for (BuyOrderProduct buyOrderProduct : buyOrderProductList) {
|
||||
Integer productId = buyOrderProduct.getProductId();
|
||||
ShopProduct product = shopProductService.getById(productId);
|
||||
product.setProductStock(product.getProductStock() + buyOrderProduct.getQuantity());
|
||||
shopProductService.updateById(product);
|
||||
}
|
||||
buyOrderService.removeById(buyOrder.getOrderId());
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 充值专用订单生成接口
|
||||
@@ -464,7 +460,7 @@ public class BuyOrderController {
|
||||
@RequestMapping("/getOrderDetail")
|
||||
public R getOrderDetail(@RequestParam Integer orderId) {
|
||||
LambdaQueryWrapper<BuyOrder> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(BuyOrder::getOrderId, orderId);
|
||||
wrapper.eq(BuyOrder::getId, orderId);
|
||||
BuyOrder one = buyOrderService.getOne(wrapper);
|
||||
if (one.equals(null)) {
|
||||
return R.error("order error:order is null");
|
||||
@@ -509,10 +505,11 @@ public class BuyOrderController {
|
||||
* @param addressRequestVo 地址请求 value object
|
||||
* @return R
|
||||
*/
|
||||
@RequestMapping(value = "/modifyOrderAddress", method = RequestMethod.POST)
|
||||
public R modifyOrderAddress(@RequestBody ShippingAddressRequestVo addressRequestVo) {
|
||||
BuyOrder buyOrder = buyOrderService.getById(addressRequestVo.getOrderId());
|
||||
|
||||
@RequestMapping(value = "/modifyConsigneeAddress", method = RequestMethod.POST)
|
||||
public R modifyOrderAddress(@RequestBody ModifyOrderAddressRequestVo addressRequestVo) {
|
||||
QueryWrapper<BuyOrder> buyOrderQueryWrapper = new QueryWrapper<>();
|
||||
buyOrderQueryWrapper.eq("order_sn", addressRequestVo.getOrderSn());
|
||||
BuyOrder buyOrder = buyOrderService.getOne(buyOrderQueryWrapper);
|
||||
String provinceCode = addressRequestVo.getProvinceCode();
|
||||
QueryWrapper<Province> provinceQueryWrapper = new QueryWrapper<>();
|
||||
provinceQueryWrapper.eq("region_code", provinceCode);
|
||||
@@ -528,8 +525,8 @@ public class BuyOrderController {
|
||||
countyQueryWrapper.eq("region_code", countyCode);
|
||||
County county = countyService.getOne(countyQueryWrapper);
|
||||
buyOrder.setDistrict(county.getCountyName());
|
||||
buyOrder.setShippingUser(addressRequestVo.getName());
|
||||
buyOrder.setUserPhone(addressRequestVo.getMobile());
|
||||
buyOrder.setShippingUser(addressRequestVo.getConsigneeName());
|
||||
buyOrder.setUserPhone(addressRequestVo.getConsigneeMobile());
|
||||
buyOrder.setAddress(addressRequestVo.getAddress());
|
||||
buyOrderService.updateById(buyOrder);
|
||||
return R.ok();
|
||||
@@ -541,7 +538,7 @@ public class BuyOrderController {
|
||||
* @param orderSn 订单号
|
||||
* @return R
|
||||
*/
|
||||
@RequestMapping(value = "/getOrderAddress", method = RequestMethod.GET)
|
||||
@RequestMapping(value = "/getConsigneeAddress", method = RequestMethod.GET)
|
||||
public R getOrderAddress(@RequestParam("orderSn") String orderSn) {
|
||||
QueryWrapper<BuyOrder> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("order_sn", orderSn);
|
||||
@@ -584,7 +581,7 @@ public class BuyOrderController {
|
||||
QueryWrapper<BuyOrder> buyOrderQueryWrapper = new QueryWrapper<>();
|
||||
buyOrderQueryWrapper.eq("order_sn", orderSn);
|
||||
BuyOrder buyOrder = buyOrderService.getOne(buyOrderQueryWrapper);
|
||||
Integer orderId = buyOrder.getOrderId();
|
||||
Integer orderId = buyOrder.getId();
|
||||
|
||||
QueryWrapper<BuyOrderProduct> buyOrderProductQueryWrapper = new QueryWrapper<>();
|
||||
buyOrderProductQueryWrapper.eq("order_id", orderId);
|
||||
@@ -629,13 +626,13 @@ public class BuyOrderController {
|
||||
* 分包发货
|
||||
*
|
||||
* @param expressCompanyCode 快递公司编码
|
||||
* @param buyOrderDetailId 订单详情列表
|
||||
* @param buyOrderProductId 订单商品
|
||||
* @return R
|
||||
*/
|
||||
@RequestMapping(value = "/delivery", method = RequestMethod.POST)
|
||||
public R delivery(@RequestParam("expressCompanyCode") String expressCompanyCode,
|
||||
@RequestBody List<Integer> buyOrderDetailId) throws Exception {
|
||||
buyOrderService.delivery(expressCompanyCode, buyOrderDetailId);
|
||||
@RequestBody List<Integer> buyOrderProductId) throws Exception {
|
||||
buyOrderService.delivery(expressCompanyCode, buyOrderProductId);
|
||||
return R.ok();
|
||||
|
||||
}
|
||||
@@ -700,7 +697,7 @@ public class BuyOrderController {
|
||||
CouponHistoryEntity couponHistory = couponHistoryService.getById(couponId);
|
||||
couponHistory.setUseStatus(1);
|
||||
couponHistory.setUseTime(new Date());
|
||||
couponHistory.setOrderId(Long.valueOf(buyOrder.getOrderId()));
|
||||
couponHistory.setOrderId(Long.valueOf(buyOrder.getId()));
|
||||
couponHistory.setOrderSn(buyOrder.getOrderSn());
|
||||
CouponEntity coupon = couponService.getById(couponHistory.getCouponId());
|
||||
|
||||
@@ -709,21 +706,6 @@ public class BuyOrderController {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
@RequestMapping("/modifyConsigneeAddress")
|
||||
public R modifyConsigneeAddress(@RequestBody ModifyOrderAddressRequestVo requestVo) {
|
||||
QueryWrapper<BuyOrder> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("order_sn", requestVo.getOrderSn());
|
||||
BuyOrder buyOrder = buyOrderService.getOne(queryWrapper);
|
||||
buyOrder.setShippingUser(requestVo.getConsigneeName());
|
||||
buyOrder.setUserPhone(requestVo.getConsigneeMobile());
|
||||
buyOrder.setProvince(requestVo.getProvince());
|
||||
buyOrder.setCity(requestVo.getCity());
|
||||
buyOrder.setDistrict(requestVo.getCounty());
|
||||
buyOrder.setAddress(requestVo.getAddress());
|
||||
buyOrder.setAddressModified(1);
|
||||
buyOrderService.updateById(buyOrder);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算运费
|
||||
|
||||
@@ -1,91 +1,91 @@
|
||||
package com.peanut.modules.book.controller;
|
||||
|
||||
import com.peanut.common.utils.PageUtils;
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.modules.book.entity.ShopSeckillEntity;
|
||||
import com.peanut.modules.book.service.ShopSeckillService;
|
||||
import com.peanut.modules.book.to.SeckillRedisTo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* 秒杀库存表
|
||||
*
|
||||
* @author yl
|
||||
* @email yl328572838@163.com
|
||||
* @date 2022-10-28 11:24:05
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("book/shopseckill")
|
||||
public class ShopSeckillController {
|
||||
@Autowired
|
||||
private ShopSeckillService shopSeckillService;
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
@RequestMapping("/list")
|
||||
public R list(@RequestParam Map<String, Object> params) {
|
||||
PageUtils page = shopSeckillService.queryPage(params);
|
||||
return R.ok().put("page", page);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 信息
|
||||
*/
|
||||
@RequestMapping("/info/{seckillId}")
|
||||
public R info(@PathVariable("seckillId") Long seckillId) {
|
||||
ShopSeckillEntity shopSeckill = shopSeckillService.getById(seckillId);
|
||||
return R.ok().put("shopSeckill", shopSeckill);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存
|
||||
*/
|
||||
@RequestMapping("/save")
|
||||
public R save(@RequestBody ShopSeckillEntity shopSeckill) {
|
||||
shopSeckillService.save(shopSeckill);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
@RequestMapping("/update")
|
||||
public R update(@RequestBody ShopSeckillEntity shopSeckill) {
|
||||
shopSeckillService.updateById(shopSeckill);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@RequestMapping("/delete")
|
||||
public R delete(@RequestBody Long[] seckillIds) {
|
||||
shopSeckillService.removeByIds(Arrays.asList(seckillIds));
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@GetMapping("/getSeckillProd")
|
||||
public R getSeckillProd() {
|
||||
List<SeckillRedisTo> list = shopSeckillService.getCurrentSeckillProd();
|
||||
return R.ok().put("list", list);
|
||||
}
|
||||
|
||||
@GetMapping("/kill")
|
||||
public R kill(@RequestParam("killId") String killId,
|
||||
@RequestParam("key") String key,
|
||||
@RequestParam("num") Integer num,
|
||||
@RequestParam("userId") Integer userId) {
|
||||
String orderId = shopSeckillService.kill(killId, key, num, userId);
|
||||
return R.ok().put("orderId", orderId);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
//package com.peanut.modules.book.controller;
|
||||
//
|
||||
//import com.peanut.common.utils.PageUtils;
|
||||
//import com.peanut.common.utils.R;
|
||||
//import com.peanut.modules.book.entity.ShopSeckillEntity;
|
||||
//import com.peanut.modules.book.service.ShopSeckillService;
|
||||
//import com.peanut.modules.book.to.SeckillRedisTo;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.web.bind.annotation.*;
|
||||
//
|
||||
//import java.util.Arrays;
|
||||
//import java.util.List;
|
||||
//import java.util.Map;
|
||||
//
|
||||
//
|
||||
///**
|
||||
// * 秒杀库存表
|
||||
// *
|
||||
// * @author yl
|
||||
// * @email yl328572838@163.com
|
||||
// * @date 2022-10-28 11:24:05
|
||||
// */
|
||||
//@RestController
|
||||
//@RequestMapping("book/shopseckill")
|
||||
//public class ShopSeckillController {
|
||||
// @Autowired
|
||||
// private ShopSeckillService shopSeckillService;
|
||||
//
|
||||
// /**
|
||||
// * 列表
|
||||
// */
|
||||
// @RequestMapping("/list")
|
||||
// public R list(@RequestParam Map<String, Object> params) {
|
||||
// PageUtils page = shopSeckillService.queryPage(params);
|
||||
// return R.ok().put("page", page);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 信息
|
||||
// */
|
||||
// @RequestMapping("/info/{seckillId}")
|
||||
// public R info(@PathVariable("seckillId") Long seckillId) {
|
||||
// ShopSeckillEntity shopSeckill = shopSeckillService.getById(seckillId);
|
||||
// return R.ok().put("shopSeckill", shopSeckill);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 保存
|
||||
// */
|
||||
// @RequestMapping("/save")
|
||||
// public R save(@RequestBody ShopSeckillEntity shopSeckill) {
|
||||
// shopSeckillService.save(shopSeckill);
|
||||
// return R.ok();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 修改
|
||||
// */
|
||||
// @RequestMapping("/update")
|
||||
// public R update(@RequestBody ShopSeckillEntity shopSeckill) {
|
||||
// shopSeckillService.updateById(shopSeckill);
|
||||
// return R.ok();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 删除
|
||||
// */
|
||||
// @RequestMapping("/delete")
|
||||
// public R delete(@RequestBody Long[] seckillIds) {
|
||||
// shopSeckillService.removeByIds(Arrays.asList(seckillIds));
|
||||
// return R.ok();
|
||||
// }
|
||||
//
|
||||
// @GetMapping("/getSeckillProd")
|
||||
// public R getSeckillProd() {
|
||||
// List<SeckillRedisTo> list = shopSeckillService.getCurrentSeckillProd();
|
||||
// return R.ok().put("list", list);
|
||||
// }
|
||||
//
|
||||
// @GetMapping("/kill")
|
||||
// public R kill(@RequestParam("killId") String killId,
|
||||
// @RequestParam("key") String key,
|
||||
// @RequestParam("num") Integer num,
|
||||
// @RequestParam("userId") Integer userId) {
|
||||
// String orderId = shopSeckillService.kill(killId, key, num, userId);
|
||||
// return R.ok().put("orderId", orderId);
|
||||
// }
|
||||
//
|
||||
//
|
||||
//}
|
||||
|
||||
@@ -115,7 +115,7 @@ public class UserFollowUpController {
|
||||
.eq("order_sn", orderSn).last("LIMIT 1")
|
||||
);
|
||||
|
||||
Integer orderId = buyOrder.getOrderId();
|
||||
Integer orderId = buyOrder.getId();
|
||||
Integer bookid = userRecord.getBookid();
|
||||
Integer userid = userRecord.getUserid();
|
||||
Integer id1 = userRecord.getId();
|
||||
|
||||
@@ -176,7 +176,7 @@ public class UserRecordController {
|
||||
return error("您已评价过了,请勿重复评论");
|
||||
//
|
||||
} else {
|
||||
userRecord.setId(buyOrder.getOrderId());
|
||||
userRecord.setId(buyOrder.getId());
|
||||
userRecord.setContent(comment);
|
||||
//商品评价
|
||||
userRecord.setBookid(bookid);
|
||||
@@ -201,7 +201,7 @@ public class UserRecordController {
|
||||
QueryWrapper<BuyOrder> buyOrderQueryWrapper = new QueryWrapper<>();
|
||||
buyOrderQueryWrapper.eq("order_sn", recordEntity.getOrderSn());
|
||||
BuyOrder buyOrder = buyOrderService.getOne(buyOrderQueryWrapper);
|
||||
Integer orderId = buyOrder.getOrderId();
|
||||
Integer orderId = buyOrder.getId();
|
||||
QueryWrapper<BuyOrderProduct> buyOrderProductQueryWrapper = new QueryWrapper<>();
|
||||
buyOrderProductQueryWrapper.eq("order_id", orderId);
|
||||
buyOrderProductQueryWrapper.eq("product_id", recordEntity.getProductId());
|
||||
|
||||
@@ -22,7 +22,7 @@ public class BuyOrder implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId
|
||||
private Integer orderId;
|
||||
private Integer id;
|
||||
/**
|
||||
* 订单编号
|
||||
*/
|
||||
@@ -130,7 +130,7 @@ public class BuyOrder implements Serializable {
|
||||
private List<BuyOrderDetail> products;
|
||||
|
||||
@TableField(exist = false)
|
||||
private List<BuyOrderProduct> productInfoList;
|
||||
private List<BuyOrderProduct> productList;
|
||||
|
||||
@TableField(exist = false)
|
||||
private String buyType;
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
package com.peanut.modules.book.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.peanut.common.utils.PageUtils;
|
||||
import com.peanut.modules.book.entity.ShopSeckillEntity;
|
||||
import com.peanut.modules.book.to.SeckillRedisTo;
|
||||
import com.peanut.modules.book.vo.SeckillProdVo;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 秒杀库存表
|
||||
*
|
||||
* @author yl
|
||||
* @email yl328572838@163.com
|
||||
* @date 2022-10-28 11:24:05
|
||||
*/
|
||||
public interface ShopSeckillService extends IService<ShopSeckillEntity> {
|
||||
|
||||
PageUtils queryPage(Map<String, Object> params);
|
||||
|
||||
List<ShopSeckillEntity> getSeckilProd3Days();
|
||||
|
||||
void uploadSeckilProd3Days();
|
||||
|
||||
List<SeckillRedisTo> getCurrentSeckillProd();
|
||||
|
||||
String kill(String killId,String key,Integer num,Integer userId);
|
||||
}
|
||||
|
||||
//package com.peanut.modules.book.service;
|
||||
//
|
||||
//import com.baomidou.mybatisplus.extension.service.IService;
|
||||
//import com.peanut.common.utils.PageUtils;
|
||||
//import com.peanut.modules.book.entity.ShopSeckillEntity;
|
||||
//import com.peanut.modules.book.to.SeckillRedisTo;
|
||||
//import com.peanut.modules.book.vo.SeckillProdVo;
|
||||
//
|
||||
//import java.util.List;
|
||||
//import java.util.Map;
|
||||
//
|
||||
///**
|
||||
// * 秒杀库存表
|
||||
// *
|
||||
// * @author yl
|
||||
// * @email yl328572838@163.com
|
||||
// * @date 2022-10-28 11:24:05
|
||||
// */
|
||||
//public interface ShopSeckillService extends IService<ShopSeckillEntity> {
|
||||
//
|
||||
// PageUtils queryPage(Map<String, Object> params);
|
||||
//
|
||||
// List<ShopSeckillEntity> getSeckilProd3Days();
|
||||
//
|
||||
// void uploadSeckilProd3Days();
|
||||
//
|
||||
// List<SeckillRedisTo> getCurrentSeckillProd();
|
||||
//
|
||||
// String kill(String killId,String key,Integer num,Integer userId);
|
||||
//}
|
||||
//
|
||||
|
||||
@@ -97,7 +97,7 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrder> impl
|
||||
if (!ObjectUtils.isEmpty(myUserEntity)) {
|
||||
record.setUserName(myUserEntity.getName());
|
||||
record.setProducts(buyOrderDetailService.list(new QueryWrapper<BuyOrderDetail>()
|
||||
.eq("order_id", record.getOrderId())));
|
||||
.eq("order_id", record.getId())));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -121,7 +121,7 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrder> impl
|
||||
page = this.page(page, queryWrapper);
|
||||
List<BuyOrder> records = page.getRecords();
|
||||
for (BuyOrder buyOrder : records) {
|
||||
Integer orderId = buyOrder.getOrderId();
|
||||
Integer orderId = buyOrder.getId();
|
||||
QueryWrapper<BuyOrderDetail> buyOrderDetailQueryWrapper = new QueryWrapper<>();
|
||||
buyOrderDetailQueryWrapper.eq("order_id", orderId);
|
||||
List<BuyOrderDetail> buyOrderDetailList = buyOrderDetailService.list(buyOrderDetailQueryWrapper);
|
||||
@@ -179,14 +179,14 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrder> impl
|
||||
);
|
||||
for (BuyOrder order : buyOrderList) {
|
||||
order.setProducts(buyOrderDetailService.list(new QueryWrapper<BuyOrderDetail>()
|
||||
.eq("order_id", order.getOrderId())));
|
||||
.eq("order_id", order.getId())));
|
||||
orderList.add(order);
|
||||
}
|
||||
// 清洗数据 (与前端传来的id对比后)
|
||||
List<BuyOrder> washOrderList = new ArrayList<>();
|
||||
for (BuyOrder order : orderList) {
|
||||
for (int o : orderIds) {
|
||||
if (o == order.getOrderId()) {
|
||||
if (o == order.getId()) {
|
||||
washOrderList.add(order);
|
||||
}
|
||||
}
|
||||
@@ -268,7 +268,7 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrder> impl
|
||||
);
|
||||
for (BuyOrder order : buyOrderList.getRecords()) {
|
||||
order.setProducts(buyOrderDetailService.list(new QueryWrapper<BuyOrderDetail>()
|
||||
.eq("order_id", order.getOrderId())));
|
||||
.eq("order_id", order.getId())));
|
||||
orderList.add(order);
|
||||
}
|
||||
// 获取有订单的所有用户
|
||||
@@ -334,26 +334,29 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrder> impl
|
||||
|
||||
|
||||
@Override
|
||||
public void delivery(String expressCompanyCode, List<Integer> buyOrderDetailId) {
|
||||
QueryWrapper<BuyOrderDetail> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.in("id", buyOrderDetailId);
|
||||
List<BuyOrderDetail> buyOrderDetailList = buyOrderDetailService.list(queryWrapper);
|
||||
public void delivery(String expressCompanyCode, List<Integer> buyOrderProductId) {
|
||||
QueryWrapper<BuyOrderProduct> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.in("id", buyOrderProductId);
|
||||
List<BuyOrderProduct> buyOrderProductList = buyOrderProductService.list(queryWrapper);
|
||||
BigDecimal totalWeight = new BigDecimal(0);
|
||||
List<ExpressCommodity> commodityList = new ArrayList<>();
|
||||
for (BuyOrderDetail buyOrderDetail : buyOrderDetailList) {
|
||||
for (BuyOrderProduct buyOrderProduct : buyOrderProductList) {
|
||||
int productId = buyOrderProduct.getProductId();
|
||||
ShopProduct product = shopProductService.getById(productId);
|
||||
ExpressCommodity commodity = new ExpressCommodity();
|
||||
commodity.setGoodsName(buyOrderDetail.getProductName());
|
||||
commodity.setGoodsquantity(buyOrderDetail.getQuantity());
|
||||
commodity.setGoodsWeight(buyOrderDetail.getWeight().doubleValue());
|
||||
commodity.setGoodsName(product.getProductName());
|
||||
commodity.setGoodsquantity(buyOrderProduct.getQuantity());
|
||||
commodity.setGoodsWeight(product.getWeight().doubleValue());
|
||||
totalWeight = totalWeight.add(
|
||||
BigDecimal.valueOf(buyOrderDetail.getWeight().doubleValue()).multiply(new BigDecimal(buyOrderDetail.getQuantity()))
|
||||
BigDecimal.valueOf(product.getWeight().doubleValue()).multiply(new BigDecimal(buyOrderProduct.getQuantity()))
|
||||
);
|
||||
totalWeight = totalWeight.setScale(0, RoundingMode.UP);
|
||||
commodityList.add(commodity);
|
||||
}
|
||||
|
||||
// 获取用户地址
|
||||
Integer orderId = buyOrderDetailList.get(0).getOrderId();
|
||||
Integer orderId = buyOrderProductList.get(0).getOrderId();
|
||||
|
||||
BuyOrder buyOrder = getById(orderId);
|
||||
QueryWrapper<County> countyQueryWrapper = new QueryWrapper<>();
|
||||
countyQueryWrapper.eq("county_name", buyOrder.getDistrict());
|
||||
@@ -374,14 +377,11 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrder> impl
|
||||
expressOrder.setAddress(buyOrder.getAddress());
|
||||
// 生成快递面单
|
||||
ExpressOrderResponseVo response = expressOrderService.placeExpressOrder(expressOrder);
|
||||
String expressBillNo = response.getOrder().getLogisticCode();
|
||||
String expressBillTemplate = response.getPrintTemplate();
|
||||
for (BuyOrderDetail buyOrderDetail : buyOrderDetailList) {
|
||||
buyOrderDetail.setExpressBillNo(expressBillNo);
|
||||
buyOrderDetail.setExpressBillTemplate(expressBillTemplate);
|
||||
buyOrderDetail.setExpressCompanyCode(expressCompanyCode);
|
||||
}
|
||||
buyOrderDetailService.saveBatch(buyOrderDetailList);
|
||||
String expressOrderSn = response.getOrder().getLogisticCode();
|
||||
String printTemplate = response.getPrintTemplate();
|
||||
expressOrder.setExpressOrderSn(expressOrderSn);
|
||||
expressOrder.setPrintTemplate(printTemplate);
|
||||
expressOrderService.save(expressOrder);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -425,7 +425,7 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrder> impl
|
||||
consigneeVo.setAddress(buyOrder.getAddress());
|
||||
responseVo.setConsignee(consigneeVo);
|
||||
QueryWrapper<BuyOrderProduct> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("order_id", buyOrder.getOrderId());
|
||||
queryWrapper.eq("order_id", buyOrder.getId());
|
||||
List<BuyOrderProduct> buyOrderProductList = buyOrderProductService.list(queryWrapper);
|
||||
List<GoodsResponseVo> goodsResponseVoList = new ArrayList<>();
|
||||
for (BuyOrderProduct buyOrderProduct : buyOrderProductList) {
|
||||
|
||||
@@ -1,255 +1,255 @@
|
||||
package com.peanut.modules.book.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.peanut.modules.book.entity.SeckillProdRelationEntity;
|
||||
import com.peanut.modules.book.entity.ShopProduct;
|
||||
import com.peanut.modules.book.service.SeckillProdRelationService;
|
||||
import com.peanut.modules.book.service.ShopProductService;
|
||||
import com.peanut.modules.book.to.SeckillRedisTo;
|
||||
import com.peanut.modules.book.vo.ProdInfoVo;
|
||||
import com.peanut.modules.book.vo.SeckillSessionWithProdVo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.redisson.api.RSemaphore;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.BoundHashOperations;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.peanut.common.utils.PageUtils;
|
||||
import com.peanut.common.utils.Query;
|
||||
|
||||
import com.peanut.modules.book.dao.ShopSeckillDao;
|
||||
import com.peanut.modules.book.entity.ShopSeckillEntity;
|
||||
import com.peanut.modules.book.service.ShopSeckillService;
|
||||
|
||||
@Slf4j
|
||||
@Service("shopSeckillService")
|
||||
public class ShopSeckillServiceImpl extends ServiceImpl<ShopSeckillDao, ShopSeckillEntity> implements ShopSeckillService {
|
||||
|
||||
@Autowired
|
||||
private SeckillProdRelationService seckillProdRelationService;
|
||||
@Autowired
|
||||
StringRedisTemplate stringRedisTemplate;
|
||||
@Autowired
|
||||
private ShopProductService shopProductService;
|
||||
@Autowired
|
||||
RedissonClient redissonClient;
|
||||
|
||||
private final String SESSIONS_CACHE_PREFIX = "seckill:sessions:";
|
||||
private final String PROKILL_CACHE_PREFIX = "prokill:pro";
|
||||
private final String PRO_STOCK_SEMAPHORE = "seckill:stock:";
|
||||
|
||||
@Override
|
||||
public PageUtils queryPage(Map<String, Object> params) {
|
||||
IPage<ShopSeckillEntity> page = this.page(
|
||||
new Query<ShopSeckillEntity>().getPage(params),
|
||||
new QueryWrapper<ShopSeckillEntity>()
|
||||
|
||||
);
|
||||
|
||||
return new PageUtils(page);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ShopSeckillEntity> getSeckilProd3Days() {
|
||||
List<ShopSeckillEntity> list = this.baseMapper.selectList(new QueryWrapper<ShopSeckillEntity>().between("start_time", startTime(), endTime()));
|
||||
if (list != null && list.size() > 0) {
|
||||
list.stream().map(session -> {
|
||||
Long seckillId = session.getSeckillId();
|
||||
List<SeckillProdRelationEntity> seckillList = seckillProdRelationService.list(new QueryWrapper<SeckillProdRelationEntity>().eq("promotion_seckill_id", seckillId));
|
||||
session.setRelationProd(seckillList);
|
||||
return session;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uploadSeckilProd3Days() {
|
||||
List<ShopSeckillEntity> seckilProd = this.getSeckilProd3Days();
|
||||
List<SeckillSessionWithProdVo> seckilProdVo = JSON.parseObject(JSON.toJSONString(seckilProd), new TypeReference<List<SeckillSessionWithProdVo>>() {
|
||||
});
|
||||
saveSessionInfo(seckilProdVo);
|
||||
saveSessionProdInfo(seckilProdVo);
|
||||
|
||||
Set<String> keys = stringRedisTemplate.keys(SESSIONS_CACHE_PREFIX + "*");
|
||||
long time = new Date().getTime();
|
||||
for(String key : keys){
|
||||
String replace = key.replace(SESSIONS_CACHE_PREFIX, "");
|
||||
String[] s = replace.split("_");
|
||||
long endTime = Long.parseLong(s[1]);
|
||||
if(endTime <= time){
|
||||
stringRedisTemplate.delete(key);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SeckillRedisTo> getCurrentSeckillProd() {
|
||||
long time = new Date().getTime();
|
||||
|
||||
Set<String> keys = stringRedisTemplate.keys(SESSIONS_CACHE_PREFIX + "*");
|
||||
|
||||
for (String key : keys) {
|
||||
String replace = key.replace(SESSIONS_CACHE_PREFIX, "");
|
||||
String[] s = replace.split("_");
|
||||
long startTime = Long.parseLong(s[0]);
|
||||
long endTime = Long.parseLong(s[1]);
|
||||
|
||||
|
||||
if (time >= startTime && time <= endTime ) {
|
||||
|
||||
List<String> list = stringRedisTemplate.opsForList().range(key, -100, 100);
|
||||
BoundHashOperations<String, String, Object> operations = stringRedisTemplate.boundHashOps(PROKILL_CACHE_PREFIX);
|
||||
List<Object> objects = operations.multiGet(list);
|
||||
if (objects.size() > 0) {
|
||||
List<SeckillRedisTo> collect = objects.stream().map(item -> {
|
||||
SeckillRedisTo seckillRedisTo = JSON.parseObject(item.toString(), SeckillRedisTo.class);
|
||||
// seckillRedisTo.setRandomCode(null);
|
||||
return seckillRedisTo;
|
||||
}).collect(Collectors.toList());
|
||||
return collect;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String kill(String killId, String key, Integer num , Integer userId) {
|
||||
|
||||
|
||||
BoundHashOperations<String, String, String> hashOps = stringRedisTemplate.boundHashOps(PROKILL_CACHE_PREFIX);
|
||||
String o = hashOps.get(killId);
|
||||
if (StringUtils.isEmpty(o)){
|
||||
return null;
|
||||
}else {
|
||||
SeckillRedisTo seckillRedisTo = JSON.parseObject(o, SeckillRedisTo.class);
|
||||
Long startTime = seckillRedisTo.getStartTime();
|
||||
Long endTime = seckillRedisTo.getEndTime();
|
||||
|
||||
long time = new Date().getTime();
|
||||
|
||||
long ttl = endTime - time;
|
||||
if ( time >= startTime && time <= endTime){
|
||||
String randomCode = seckillRedisTo.getRandomCode();
|
||||
String prodId = seckillRedisTo.getPromotionSeckillId() + "_" + seckillRedisTo.getProdId();
|
||||
if( randomCode.equals(key) && killId.equals(prodId)){
|
||||
if (num <= Integer.valueOf(seckillRedisTo.getSeckillLimit())) {
|
||||
String redisKey = userId + "_" + prodId;
|
||||
Boolean aBoolean = stringRedisTemplate.opsForValue().setIfAbsent(redisKey, num.toString(), ttl, TimeUnit.MILLISECONDS);
|
||||
if (aBoolean) {
|
||||
RSemaphore semaphore = redissonClient.getSemaphore(PRO_STOCK_SEMAPHORE + randomCode);
|
||||
try {
|
||||
boolean b = semaphore.tryAcquire(num, 100, TimeUnit.MILLISECONDS);
|
||||
// 秒杀成功
|
||||
String timeId = IdWorker.getTimeId();
|
||||
return timeId;
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
return null;
|
||||
}
|
||||
}else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}else {
|
||||
return null;
|
||||
}
|
||||
}else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private void saveSessionInfo(List<SeckillSessionWithProdVo> seckilProdVo) {
|
||||
seckilProdVo.stream().forEach(session -> {
|
||||
long startTime = session.getStartTime().getTime();
|
||||
long endTime = session.getEndTime().getTime();
|
||||
String key = SESSIONS_CACHE_PREFIX + startTime + "_" + endTime;
|
||||
|
||||
Boolean aBoolean = stringRedisTemplate.hasKey(key);
|
||||
if (!aBoolean) {
|
||||
List<String> collect = session.getRelationProd().stream().map(item -> item.getPromotionSeckillId() + "_" + item.getProdId().toString()).collect(Collectors.toList());
|
||||
stringRedisTemplate.opsForList().leftPushAll(key, collect);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void saveSessionProdInfo(List<SeckillSessionWithProdVo> seckilProdVos) {
|
||||
|
||||
seckilProdVos.stream().forEach(seckilProdVo -> {
|
||||
|
||||
BoundHashOperations<String, Object, Object> ops = stringRedisTemplate.boundHashOps(PROKILL_CACHE_PREFIX);
|
||||
|
||||
seckilProdVo.getRelationProd().stream().forEach(seckilProd -> {
|
||||
String token = UUID.randomUUID().toString().replace("-", "");
|
||||
if (!ops.hasKey(seckilProd.getPromotionSeckillId().toString() + "_" + seckilProd.getProdId().toString())) {
|
||||
SeckillRedisTo seckillRedisTo = new SeckillRedisTo();
|
||||
|
||||
ShopProduct productEntity = shopProductService.getById(seckilProd.getProdId());
|
||||
ProdInfoVo prodInfoVo = JSON.parseObject(JSON.toJSONString(productEntity), new TypeReference<ProdInfoVo>() {
|
||||
});
|
||||
seckillRedisTo.setProdInfo(prodInfoVo);
|
||||
BeanUtils.copyProperties(seckilProd, seckillRedisTo);
|
||||
|
||||
seckillRedisTo.setStartTime(seckilProdVo.getStartTime().getTime());
|
||||
seckillRedisTo.setEndTime(seckilProdVo.getEndTime().getTime());
|
||||
|
||||
seckillRedisTo.setRandomCode(token);
|
||||
|
||||
|
||||
String string = JSON.toJSONString(seckillRedisTo);
|
||||
ops.put(seckilProd.getPromotionSeckillId().toString() + "_" + seckilProd.getProdId().toString(), string);
|
||||
|
||||
RSemaphore semaphore = redissonClient.getSemaphore(PRO_STOCK_SEMAPHORE + token);
|
||||
semaphore.trySetPermits(Integer.valueOf(seckilProd.getSeckillCount()));
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
private String startTime() {
|
||||
LocalDate now = LocalDate.now();
|
||||
LocalTime min = LocalTime.MIN;
|
||||
LocalDateTime start = LocalDateTime.of(now, min);
|
||||
String format = start.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
return format;
|
||||
}
|
||||
|
||||
private String endTime() {
|
||||
LocalDate now = LocalDate.now();
|
||||
LocalDate localDate = now.plusDays(2);
|
||||
LocalDateTime of = LocalDateTime.of(localDate, LocalTime.MAX);
|
||||
String format = of.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
return format;
|
||||
}
|
||||
}
|
||||
//package com.peanut.modules.book.service.impl;
|
||||
//
|
||||
//import com.alibaba.fastjson.JSON;
|
||||
//import com.alibaba.fastjson.TypeReference;
|
||||
//import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
//import com.peanut.modules.book.entity.SeckillProdRelationEntity;
|
||||
//import com.peanut.modules.book.entity.ShopProduct;
|
||||
//import com.peanut.modules.book.service.SeckillProdRelationService;
|
||||
//import com.peanut.modules.book.service.ShopProductService;
|
||||
//import com.peanut.modules.book.to.SeckillRedisTo;
|
||||
//import com.peanut.modules.book.vo.ProdInfoVo;
|
||||
//import com.peanut.modules.book.vo.SeckillSessionWithProdVo;
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import org.apache.commons.lang.StringUtils;
|
||||
//import org.redisson.api.RSemaphore;
|
||||
//import org.redisson.api.RedissonClient;
|
||||
//import org.springframework.beans.BeanUtils;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.data.redis.core.BoundHashOperations;
|
||||
//import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
//import org.springframework.stereotype.Service;
|
||||
//
|
||||
//import java.time.LocalDate;
|
||||
//import java.time.LocalDateTime;
|
||||
//import java.time.LocalTime;
|
||||
//import java.time.format.DateTimeFormatter;
|
||||
//import java.util.*;
|
||||
//import java.util.concurrent.TimeUnit;
|
||||
//import java.util.stream.Collectors;
|
||||
//
|
||||
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
//import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
//import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
//import com.peanut.common.utils.PageUtils;
|
||||
//import com.peanut.common.utils.Query;
|
||||
//
|
||||
//import com.peanut.modules.book.dao.ShopSeckillDao;
|
||||
//import com.peanut.modules.book.entity.ShopSeckillEntity;
|
||||
//import com.peanut.modules.book.service.ShopSeckillService;
|
||||
//
|
||||
//@Slf4j
|
||||
//@Service("shopSeckillService")
|
||||
//public class ShopSeckillServiceImpl extends ServiceImpl<ShopSeckillDao, ShopSeckillEntity> implements ShopSeckillService {
|
||||
//
|
||||
// @Autowired
|
||||
// private SeckillProdRelationService seckillProdRelationService;
|
||||
// @Autowired
|
||||
// StringRedisTemplate stringRedisTemplate;
|
||||
// @Autowired
|
||||
// private ShopProductService shopProductService;
|
||||
// @Autowired
|
||||
// RedissonClient redissonClient;
|
||||
//
|
||||
// private final String SESSIONS_CACHE_PREFIX = "seckill:sessions:";
|
||||
// private final String PROKILL_CACHE_PREFIX = "prokill:pro";
|
||||
// private final String PRO_STOCK_SEMAPHORE = "seckill:stock:";
|
||||
//
|
||||
// @Override
|
||||
// public PageUtils queryPage(Map<String, Object> params) {
|
||||
// IPage<ShopSeckillEntity> page = this.page(
|
||||
// new Query<ShopSeckillEntity>().getPage(params),
|
||||
// new QueryWrapper<ShopSeckillEntity>()
|
||||
//
|
||||
// );
|
||||
//
|
||||
// return new PageUtils(page);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public List<ShopSeckillEntity> getSeckilProd3Days() {
|
||||
// List<ShopSeckillEntity> list = this.baseMapper.selectList(new QueryWrapper<ShopSeckillEntity>().between("start_time", startTime(), endTime()));
|
||||
// if (list != null && list.size() > 0) {
|
||||
// list.stream().map(session -> {
|
||||
// Long seckillId = session.getSeckillId();
|
||||
// List<SeckillProdRelationEntity> seckillList = seckillProdRelationService.list(new QueryWrapper<SeckillProdRelationEntity>().eq("promotion_seckill_id", seckillId));
|
||||
// session.setRelationProd(seckillList);
|
||||
// return session;
|
||||
// }).collect(Collectors.toList());
|
||||
// }
|
||||
// return list;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void uploadSeckilProd3Days() {
|
||||
// List<ShopSeckillEntity> seckilProd = this.getSeckilProd3Days();
|
||||
// List<SeckillSessionWithProdVo> seckilProdVo = JSON.parseObject(JSON.toJSONString(seckilProd), new TypeReference<List<SeckillSessionWithProdVo>>() {
|
||||
// });
|
||||
// saveSessionInfo(seckilProdVo);
|
||||
// saveSessionProdInfo(seckilProdVo);
|
||||
//
|
||||
// Set<String> keys = stringRedisTemplate.keys(SESSIONS_CACHE_PREFIX + "*");
|
||||
// long time = new Date().getTime();
|
||||
// for(String key : keys){
|
||||
// String replace = key.replace(SESSIONS_CACHE_PREFIX, "");
|
||||
// String[] s = replace.split("_");
|
||||
// long endTime = Long.parseLong(s[1]);
|
||||
// if(endTime <= time){
|
||||
// stringRedisTemplate.delete(key);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public List<SeckillRedisTo> getCurrentSeckillProd() {
|
||||
// long time = new Date().getTime();
|
||||
//
|
||||
// Set<String> keys = stringRedisTemplate.keys(SESSIONS_CACHE_PREFIX + "*");
|
||||
//
|
||||
// for (String key : keys) {
|
||||
// String replace = key.replace(SESSIONS_CACHE_PREFIX, "");
|
||||
// String[] s = replace.split("_");
|
||||
// long startTime = Long.parseLong(s[0]);
|
||||
// long endTime = Long.parseLong(s[1]);
|
||||
//
|
||||
//
|
||||
// if (time >= startTime && time <= endTime ) {
|
||||
//
|
||||
// List<String> list = stringRedisTemplate.opsForList().range(key, -100, 100);
|
||||
// BoundHashOperations<String, String, Object> operations = stringRedisTemplate.boundHashOps(PROKILL_CACHE_PREFIX);
|
||||
// List<Object> objects = operations.multiGet(list);
|
||||
// if (objects.size() > 0) {
|
||||
// List<SeckillRedisTo> collect = objects.stream().map(item -> {
|
||||
// SeckillRedisTo seckillRedisTo = JSON.parseObject(item.toString(), SeckillRedisTo.class);
|
||||
//// seckillRedisTo.setRandomCode(null);
|
||||
// return seckillRedisTo;
|
||||
// }).collect(Collectors.toList());
|
||||
// return collect;
|
||||
// }
|
||||
//
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String kill(String killId, String key, Integer num , Integer userId) {
|
||||
//
|
||||
//
|
||||
// BoundHashOperations<String, String, String> hashOps = stringRedisTemplate.boundHashOps(PROKILL_CACHE_PREFIX);
|
||||
// String o = hashOps.get(killId);
|
||||
// if (StringUtils.isEmpty(o)){
|
||||
// return null;
|
||||
// }else {
|
||||
// SeckillRedisTo seckillRedisTo = JSON.parseObject(o, SeckillRedisTo.class);
|
||||
// Long startTime = seckillRedisTo.getStartTime();
|
||||
// Long endTime = seckillRedisTo.getEndTime();
|
||||
//
|
||||
// long time = new Date().getTime();
|
||||
//
|
||||
// long ttl = endTime - time;
|
||||
// if ( time >= startTime && time <= endTime){
|
||||
// String randomCode = seckillRedisTo.getRandomCode();
|
||||
// String prodId = seckillRedisTo.getPromotionSeckillId() + "_" + seckillRedisTo.getProdId();
|
||||
// if( randomCode.equals(key) && killId.equals(prodId)){
|
||||
// if (num <= Integer.valueOf(seckillRedisTo.getSeckillLimit())) {
|
||||
// String redisKey = userId + "_" + prodId;
|
||||
// Boolean aBoolean = stringRedisTemplate.opsForValue().setIfAbsent(redisKey, num.toString(), ttl, TimeUnit.MILLISECONDS);
|
||||
// if (aBoolean) {
|
||||
// RSemaphore semaphore = redissonClient.getSemaphore(PRO_STOCK_SEMAPHORE + randomCode);
|
||||
// try {
|
||||
// boolean b = semaphore.tryAcquire(num, 100, TimeUnit.MILLISECONDS);
|
||||
// // 秒杀成功
|
||||
// String timeId = IdWorker.getTimeId();
|
||||
// return timeId;
|
||||
//
|
||||
// } catch (InterruptedException e) {
|
||||
// return null;
|
||||
// }
|
||||
// }else {
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// }else {
|
||||
// return null;
|
||||
// }
|
||||
// }else {
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// private void saveSessionInfo(List<SeckillSessionWithProdVo> seckilProdVo) {
|
||||
// seckilProdVo.stream().forEach(session -> {
|
||||
// long startTime = session.getStartTime().getTime();
|
||||
// long endTime = session.getEndTime().getTime();
|
||||
// String key = SESSIONS_CACHE_PREFIX + startTime + "_" + endTime;
|
||||
//
|
||||
// Boolean aBoolean = stringRedisTemplate.hasKey(key);
|
||||
// if (!aBoolean) {
|
||||
// List<String> collect = session.getRelationProd().stream().map(item -> item.getPromotionSeckillId() + "_" + item.getProdId().toString()).collect(Collectors.toList());
|
||||
// stringRedisTemplate.opsForList().leftPushAll(key, collect);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// private void saveSessionProdInfo(List<SeckillSessionWithProdVo> seckilProdVos) {
|
||||
//
|
||||
// seckilProdVos.stream().forEach(seckilProdVo -> {
|
||||
//
|
||||
// BoundHashOperations<String, Object, Object> ops = stringRedisTemplate.boundHashOps(PROKILL_CACHE_PREFIX);
|
||||
//
|
||||
// seckilProdVo.getRelationProd().stream().forEach(seckilProd -> {
|
||||
// String token = UUID.randomUUID().toString().replace("-", "");
|
||||
// if (!ops.hasKey(seckilProd.getPromotionSeckillId().toString() + "_" + seckilProd.getProdId().toString())) {
|
||||
// SeckillRedisTo seckillRedisTo = new SeckillRedisTo();
|
||||
//
|
||||
// ShopProduct productEntity = shopProductService.getById(seckilProd.getProdId());
|
||||
// ProdInfoVo prodInfoVo = JSON.parseObject(JSON.toJSONString(productEntity), new TypeReference<ProdInfoVo>() {
|
||||
// });
|
||||
// seckillRedisTo.setProdInfo(prodInfoVo);
|
||||
// BeanUtils.copyProperties(seckilProd, seckillRedisTo);
|
||||
//
|
||||
// seckillRedisTo.setStartTime(seckilProdVo.getStartTime().getTime());
|
||||
// seckillRedisTo.setEndTime(seckilProdVo.getEndTime().getTime());
|
||||
//
|
||||
// seckillRedisTo.setRandomCode(token);
|
||||
//
|
||||
//
|
||||
// String string = JSON.toJSONString(seckillRedisTo);
|
||||
// ops.put(seckilProd.getPromotionSeckillId().toString() + "_" + seckilProd.getProdId().toString(), string);
|
||||
//
|
||||
// RSemaphore semaphore = redissonClient.getSemaphore(PRO_STOCK_SEMAPHORE + token);
|
||||
// semaphore.trySetPermits(Integer.valueOf(seckilProd.getSeckillCount()));
|
||||
// }
|
||||
//
|
||||
//
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// }
|
||||
//
|
||||
//
|
||||
// private String startTime() {
|
||||
// LocalDate now = LocalDate.now();
|
||||
// LocalTime min = LocalTime.MIN;
|
||||
// LocalDateTime start = LocalDateTime.of(now, min);
|
||||
// String format = start.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
// return format;
|
||||
// }
|
||||
//
|
||||
// private String endTime() {
|
||||
// LocalDate now = LocalDate.now();
|
||||
// LocalDate localDate = now.plusDays(2);
|
||||
// LocalDateTime of = LocalDateTime.of(localDate, LocalTime.MAX);
|
||||
// String format = of.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
// return format;
|
||||
// }
|
||||
//}
|
||||
@@ -1,33 +1,33 @@
|
||||
package com.peanut.modules.book.task;
|
||||
|
||||
import com.peanut.modules.book.service.ShopSeckillService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class SeckillProdScheduled {
|
||||
@Autowired
|
||||
ShopSeckillService shopSeckillService;
|
||||
|
||||
@Scheduled(cron = "0 0/1 * * * ?")
|
||||
public void uploadSeckilProd3Days() {
|
||||
Lock l = new ReentrantLock();
|
||||
l.lock();
|
||||
try {
|
||||
shopSeckillService.uploadSeckilProd3Days();
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
l.unlock();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
//package com.peanut.modules.book.task;
|
||||
//
|
||||
//import com.peanut.modules.book.service.ShopSeckillService;
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.scheduling.annotation.Scheduled;
|
||||
//import org.springframework.stereotype.Service;
|
||||
//
|
||||
//import java.util.concurrent.locks.Lock;
|
||||
//import java.util.concurrent.locks.ReentrantLock;
|
||||
//
|
||||
//@Slf4j
|
||||
//@Service
|
||||
//public class SeckillProdScheduled {
|
||||
// @Autowired
|
||||
// ShopSeckillService shopSeckillService;
|
||||
//
|
||||
// @Scheduled(cron = "0 0/1 * * * ?")
|
||||
// public void uploadSeckilProd3Days() {
|
||||
// Lock l = new ReentrantLock();
|
||||
// l.lock();
|
||||
// try {
|
||||
// shopSeckillService.uploadSeckilProd3Days();
|
||||
// }catch (Exception e){
|
||||
// e.printStackTrace();
|
||||
// }finally {
|
||||
// l.unlock();
|
||||
// }
|
||||
//
|
||||
//
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
||||
@@ -16,15 +16,15 @@ public class ModifyOrderAddressRequestVo {
|
||||
/**
|
||||
* 省
|
||||
*/
|
||||
private String province;
|
||||
private String provinceCode;
|
||||
/**
|
||||
* 市
|
||||
*/
|
||||
private String city;
|
||||
private String cityCode;
|
||||
/**
|
||||
* 区县
|
||||
*/
|
||||
private String county;
|
||||
private String countyCode;
|
||||
/**
|
||||
* 收货人姓名
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user