超时回滚;购物车商品上下架;微信支付描述超字数调整
This commit is contained in:
parent
19f64a6b35
commit
d7dae69e3f
@ -4,6 +4,8 @@ import com.cpop.common.constant.Constants;
|
||||
import com.cpop.common.utils.text.StrFormatter;
|
||||
import org.springframework.util.AntPathMatcher;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
@ -531,4 +533,30 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param aString 要截取的字符串
|
||||
* @param startIndex 开始下标
|
||||
* @param endIndex 截取长度
|
||||
*/
|
||||
public static String substringByte(String aString,int startIndex,int endIndex) {
|
||||
byte[] bytes = aString.getBytes(StandardCharsets.UTF_8);
|
||||
int subLen = endIndex - startIndex;
|
||||
if (startIndex < 0) {
|
||||
return "startIndex异常";
|
||||
}
|
||||
if (endIndex > bytes.length) {
|
||||
return "endIndex异常";
|
||||
}
|
||||
if (subLen <= 0) {
|
||||
return "startIndex或endIndex异常";
|
||||
}
|
||||
byte[] subBytes = new byte[subLen];
|
||||
int i = 0;
|
||||
while (startIndex < endIndex) {
|
||||
subBytes[i++] = bytes[startIndex++];
|
||||
}
|
||||
return new String(subBytes, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@ public class OrderPageBo implements Serializable {
|
||||
* 接收人手机号
|
||||
*/
|
||||
@ApiModelProperty("接收人手机号")
|
||||
private String receivePhone;
|
||||
private String payUserPhone;
|
||||
|
||||
/**
|
||||
* 订单状态(0:待付款;1:待发货;2:待确认;3:已完成;4:退款/售后中)
|
||||
|
||||
@ -76,6 +76,23 @@ public class BackstageOrderController {
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* @descriptions 后台确定订单完成
|
||||
* @author DB
|
||||
* @date 2023/11/07 9:37
|
||||
* @param id 订单id
|
||||
* @return: com.cpop.core.base.R<java.lang.Void>
|
||||
*/
|
||||
@PutMapping("/orderFinish")
|
||||
@ApiOperation("后台确定订单完成")
|
||||
public R<Void> orderFinish(@RequestParam("id") @ApiParam(value = "订单id",required = true) String id) {
|
||||
orderService.updateChain()
|
||||
.setRaw(ORDER.PREVIOUS_STATUS, ORDER.ORDER_STATUS)
|
||||
.set(ORDER.ORDER_STATUS, 3)
|
||||
.where(ORDER.ID.eq(id)).update();
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Description: 删除订单
|
||||
* @param id 主键
|
||||
|
||||
@ -1,55 +0,0 @@
|
||||
package com.cpop.mall.business.controller.test;
|
||||
|
||||
import com.cpop.core.base.R;
|
||||
import com.cpop.mall.business.bo.MallRoleBo;
|
||||
import com.cpop.mall.business.bo.MallRolePageBo;
|
||||
import com.cpop.mall.business.service.RoleBrandService;
|
||||
import com.cpop.mall.business.task.ProductRecordSyncStockTask;
|
||||
import com.cpop.mall.business.vo.MallRolePageVo;
|
||||
import com.cpop.system.business.bo.MenuListBo;
|
||||
import com.cpop.system.business.bo.RoleStatusBo;
|
||||
import com.cpop.system.business.service.MenuService;
|
||||
import com.cpop.system.business.vo.MenuVo;
|
||||
import com.github.binarywang.wxpay.bean.notify.WxPayNotifyResponse;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author DB
|
||||
* @createTime 2023/10/19 18:14
|
||||
* @description
|
||||
*/
|
||||
@RestController
|
||||
@Api(tags = "商城测试接口")
|
||||
@RequestMapping("/test")
|
||||
public class TestController {
|
||||
|
||||
@Autowired
|
||||
private ProductRecordSyncStockTask productRecordSyncStockTask;
|
||||
|
||||
/**
|
||||
* @descriptions 并发批量扣减库存测试
|
||||
* @author DB
|
||||
* @date 2023/11/02 9:47
|
||||
* @return: java.lang.String
|
||||
*/
|
||||
@ApiOperation("并发批量扣减库存测试")
|
||||
@PostMapping("/concurrencyDeductionStockTest")
|
||||
public R<Void> concurrencyDeductionStockTest(){
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
Map<String, Integer> map = new HashMap<>(1);
|
||||
map.put("77212443863334912", 1);
|
||||
productRecordSyncStockTask.asyncUpdateRecords(map);
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
}
|
||||
@ -114,8 +114,9 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
||||
.from(ORDER)
|
||||
.leftJoin(SYS_USER).on(SYS_USER.ID.eq(ORDER.PAY_USER_ID))
|
||||
.and(ORDER.PAY_USER_NAME.like(bo.getPayUserName()))
|
||||
.and(ORDER.RECEIVE_PHONE.like(bo.getReceivePhone()))
|
||||
.and(SYS_USER.PHONE_NUMBER.like(bo.getPayUserPhone()))
|
||||
.and(ORDER.PRODUCT_NAMES.like(bo.getProductName()))
|
||||
.and(SYS_USER.USER_TYPE.eq("MINI_USER"))
|
||||
.orderBy(ORDER.CREATE_TIME.desc()),
|
||||
OrderPageVo.class,
|
||||
//子查询
|
||||
@ -262,6 +263,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
||||
.leftJoin(PRODUCT_RECORD).on(PRODUCT_RECORD.PRODUCT_ID.eq(PRODUCT.ID))
|
||||
.where(PRODUCT_RECORD.ID.in(orderDetails.stream().map(OrderDetail::getProductRecordId).collect(Collectors.toSet())))
|
||||
.list();
|
||||
Object result;
|
||||
//微信支付
|
||||
if (bo.getPayType() == 0) {
|
||||
//微信支付统一下单
|
||||
@ -274,32 +276,41 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
||||
//需要分账
|
||||
orderRequest.setProfitSharing("Y");
|
||||
}
|
||||
String description = productList.stream().map(Product::getDescription).collect(Collectors.joining(","));
|
||||
if (description.getBytes().length > 127) {
|
||||
description = StringUtils.substringByte(description, 0, 126);
|
||||
}
|
||||
orderRequest.setSpbillCreateIp(IpUtils.getHostIp())
|
||||
.setOpenid(loginUserInfo.getString("openId"))
|
||||
//商品描述
|
||||
.setBody(productList.stream().map(Product::getDescription).collect(Collectors.joining(",")))
|
||||
.setBody(description)
|
||||
//商品详情,如果涉及到商品优惠需要重新涉及
|
||||
.setDetail(JSONObject.toJSONString(BeanUtils.mapToList(orderDetails, WxPayGoodsDetailDto.class)))
|
||||
.setOutTradeNo(order.getId())
|
||||
//元转分
|
||||
.setTotalFee(order.getTotalAmount().scaleByPowerOfTen(2).intValue())
|
||||
.setTradeType("JSAPI");
|
||||
Object result = wxPayService.createOrder(orderRequest);
|
||||
result = wxPayService.createOrder(orderRequest);
|
||||
//删除定时器任务
|
||||
QuartzUtils quartzUtils = SpringUtils.getBean(QuartzUtils.class);
|
||||
quartzUtils.deleteJob(QuartzEnums.ORDER_OVERTIME_UN_PAY_TASK.getName() + order.getId(),
|
||||
QuartzEnums.ORDER_OVERTIME_UN_PAY_TASK.getGroup());
|
||||
return result;
|
||||
} else {
|
||||
//统计支付商品情况
|
||||
Map<String, Integer> recordNumIsEnough = orderDetails.stream().collect(Collectors.toMap(OrderDetail::getProductRecordId, OrderDetail::getNumber));
|
||||
Object result = pointPay(recordNumIsEnough, order.getId());
|
||||
result = pointPay(recordNumIsEnough, order.getId());
|
||||
//删除定时器任务
|
||||
QuartzUtils quartzUtils = SpringUtils.getBean(QuartzUtils.class);
|
||||
quartzUtils.deleteJob(QuartzEnums.ORDER_OVERTIME_UN_PAY_TASK.getName() + order.getId(),
|
||||
QuartzEnums.ORDER_OVERTIME_UN_PAY_TASK.getGroup());
|
||||
return result;
|
||||
}
|
||||
//更新订单
|
||||
this.updateChain().set(ORDER.RECEIVE_PHONE,bo.getReceivePhone())
|
||||
.set(ORDER.RECEIVE_ADDRESS,bo.getReceiveAddress())
|
||||
.set(ORDER.RECEIVE_NAME,bo.getReceiveName())
|
||||
.where(ORDER.ID.eq(bo.getId()))
|
||||
.update();
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
throw new ServiceException(e.getMessage());
|
||||
} finally {
|
||||
@ -472,7 +483,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void cancelOrder(String orderId) {
|
||||
this.updateChain().setRaw(ORDER.PREVIOUS_STATUS, ORDER.ORDER_STATUS)
|
||||
.set(ORDER.ORDER_STATUS, 4).where(ORDER.ID.eq(orderId)).update();
|
||||
.set(ORDER.ORDER_STATUS, 5).where(ORDER.ID.eq(orderId)).update();
|
||||
//获取订单详情
|
||||
List<OrderDetail> orderDetails = SpringUtils.getBean(OrderDetailService.class).queryChain().where(ORDER_DETAIL.ORDER_ID.eq(orderId)).list();
|
||||
Map<String, Integer> orderReturnMap = orderDetails.stream().collect(Collectors.toMap(OrderDetail::getProductRecordId, OrderDetail::getNumber));
|
||||
|
||||
@ -52,7 +52,7 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, Sho
|
||||
//记录
|
||||
.select(PRODUCT_RECORD.RECORD_NAMES)
|
||||
//商品
|
||||
.select(PRODUCT.PRODUCT_NAME,PRODUCT.ID.as(MiniShoppingCartPageVo::getProductId),PRODUCT.PIC_URL,PRODUCT.PIC_DETAIL_URL,PRODUCT.PAY_TYPE)
|
||||
.select(PRODUCT.PRODUCT_NAME,PRODUCT.ID.as(MiniShoppingCartPageVo::getProductId),PRODUCT.PIC_URL,PRODUCT.PIC_DETAIL_URL,PRODUCT.PAY_TYPE,PRODUCT.IS_UP)
|
||||
//校区
|
||||
.select(STORE.STORE_NAME)
|
||||
.from(SHOPPING_CART)
|
||||
|
||||
@ -1,13 +1,21 @@
|
||||
package com.cpop.mall.business.task;
|
||||
|
||||
import com.cpop.core.service.RedisService;
|
||||
import com.cpop.core.utils.SpringUtils;
|
||||
import com.cpop.mall.business.entity.Order;
|
||||
import com.cpop.mall.business.entity.OrderDetail;
|
||||
import com.cpop.mall.business.service.OrderDetailService;
|
||||
import com.cpop.mall.business.service.OrderService;
|
||||
import com.cpop.mall.framework.constant.MallRedisConstant;
|
||||
import org.quartz.Job;
|
||||
import org.quartz.JobDataMap;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobExecutionException;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.cpop.mall.business.entity.table.OrderDetailTableDef.ORDER_DETAIL;
|
||||
import static com.cpop.mall.business.entity.table.OrderTableDef.ORDER;
|
||||
|
||||
/**
|
||||
@ -27,6 +35,15 @@ public class OrderOverTimeUnPayTask implements Job {
|
||||
//订单存在并且订单仍然是未支付,修改订单为超时
|
||||
if (null != order && order.getOrderStatus() == 0) {
|
||||
orderService.updateChain().set(ORDER.ORDER_STATUS, 6).set(ORDER.PREVIOUS_STATUS, 0).where(ORDER.ID.eq(orderId)).update();
|
||||
//redis库存回滚
|
||||
RedisService redisService = SpringUtils.getBean(RedisService.class);
|
||||
Map<String, Integer> orderReturnMap = SpringUtils.getBean(OrderDetailService.class).queryChain()
|
||||
.where(ORDER_DETAIL.ORDER_ID.eq(orderId))
|
||||
.list()
|
||||
.stream().collect(Collectors.toMap(OrderDetail::getProductRecordId, OrderDetail::getNumber));
|
||||
orderReturnMap.forEach((key, value) -> {
|
||||
redisService.longIncrement(MallRedisConstant.STOCK_RECORD_NUM + key, value.longValue());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -112,4 +112,10 @@ public class MiniShoppingCartPageVo implements Serializable {
|
||||
*/
|
||||
@ApiModelProperty("商品详情图地址")
|
||||
private String picDetailUrl;
|
||||
|
||||
/**
|
||||
* 上下架(0下1上)
|
||||
*/
|
||||
@ApiModelProperty("上下架")
|
||||
private Boolean isUp;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user