Merge branch 'dev' into prod
This commit is contained in:
@@ -2,28 +2,21 @@ package com.czg.task;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import com.czg.account.entity.ShopInfo;
|
||||
import com.czg.account.entity.ShopUser;
|
||||
import com.czg.account.service.ShopInfoService;
|
||||
import com.czg.account.service.ShopUserService;
|
||||
import com.czg.constant.TableValueConstant;
|
||||
import com.czg.market.entity.MkDistributionDeliver;
|
||||
import com.czg.market.entity.MkDistributionFlow;
|
||||
import com.czg.market.service.MkBirthdayGiftService;
|
||||
import com.czg.market.service.MkDistributionDeliverService;
|
||||
import com.czg.market.service.MkDistributionFlowService;
|
||||
import com.czg.market.service.MkDistributionUserService;
|
||||
import com.czg.order.entity.OrderInfo;
|
||||
import com.czg.order.service.OrderInfoService;
|
||||
import com.czg.service.market.enums.OrderStatusEnums;
|
||||
import com.czg.utils.FunUtils;
|
||||
import com.itextpdf.styledxmlparser.jsoup.helper.DataUtil;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
@@ -33,13 +26,10 @@ import java.time.LocalDateTime;
|
||||
* 分销定时任务
|
||||
*
|
||||
* @author ww
|
||||
* @description
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class DistributionTask {
|
||||
@Resource
|
||||
private MkDistributionDeliverService distributionDeliverService;
|
||||
@Resource
|
||||
private MkDistributionUserService distributionUserService;
|
||||
@Resource
|
||||
@@ -53,12 +43,19 @@ public class DistributionTask {
|
||||
private ShopUserService shopUserService;
|
||||
|
||||
/**
|
||||
* 生日有礼奖励发放
|
||||
* 分销流水入账
|
||||
* AAMarketTasks 统一调用位置
|
||||
*/
|
||||
// @Scheduled(cron = "0 0 0 * * ?")
|
||||
@Scheduled(fixedRate = 30000)
|
||||
// @Scheduled(fixedRate = 30000)
|
||||
public void deliver() {
|
||||
// TODO 逻辑修改
|
||||
// 1. 订单完成支付时(判断是否分销)产生流水记录。
|
||||
// 2. 判断入账时间。
|
||||
// 3. 如果是 0 天,再去判断商户余额是否足够。够则入账,不足则不管。
|
||||
// 4. 流水增加应该入账的时间(订单产生时带入)
|
||||
// 5. 定时任务 应该是一天执行一次。查询待入账状态和应入账时间小于当前时间的记录,循环处理:并且判断商户余额是否足够,余额不足忽略处理;余额足够变为已入账并扣除商户余额。
|
||||
// 6. 订单产生退款时,去流水表查询该订单的流水记录,如果未入账改为已入账,并插入一条退款扣钱的流水。
|
||||
LocalDateTime localDateTime = DateUtil.date().toLocalDateTime();
|
||||
distributionFlowService.list(new QueryWrapper()
|
||||
.eq(MkDistributionFlow::getStatus, TableValueConstant.DistributionFlow.Status.PENDING.getCode())).forEach(item -> {
|
||||
|
||||
@@ -4,10 +4,8 @@ import cn.dev33.satoken.exception.NotLoginException;
|
||||
import cn.dev33.satoken.exception.NotPermissionException;
|
||||
import cn.dev33.satoken.exception.NotRoleException;
|
||||
import cn.hutool.core.exceptions.ValidateException;
|
||||
import cn.hutool.core.io.resource.NoResourceException;
|
||||
import com.czg.resp.CzgRespCode;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.fasterxml.jackson.databind.exc.InvalidFormatException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.support.DefaultMessageSourceResolvable;
|
||||
import org.springframework.dao.DuplicateKeyException;
|
||||
@@ -30,25 +28,6 @@ import java.util.stream.Collectors;
|
||||
@RestControllerAdvice
|
||||
@Slf4j
|
||||
public class CzgControllerAdvice {
|
||||
@ResponseBody
|
||||
@ExceptionHandler(value = Exception.class)
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public CzgResult<Object> errorHandler(Exception ex) {
|
||||
Throwable rootCause = ex;
|
||||
while (rootCause.getCause() != null) {
|
||||
rootCause = rootCause.getCause();
|
||||
if (rootCause instanceof CzgException) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// 处理自定义异常
|
||||
if (rootCause instanceof CzgException czgException) {
|
||||
return CzgResult.failure(czgException.getCode(), czgException.getMessage());
|
||||
}
|
||||
setErrorLog(ex);
|
||||
return CzgResult.failure(CzgRespCode.SYSTEM_ERROR.getCode(), ex.getMessage());
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@ExceptionHandler(value = NoResourceFoundException.class)
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@@ -113,9 +92,9 @@ public class CzgControllerAdvice {
|
||||
return CzgResult.failure(ex.getCode(), ex.getMsg());
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
// @ResponseBody
|
||||
@ExceptionHandler(OrderValidateException.class)
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
// @ResponseStatus(HttpStatus.OK)
|
||||
public CzgResult<Object> handleOrderValidateException(OrderValidateException ex) {
|
||||
log.error("订单校验异常:{}", ex.getMessage());
|
||||
return CzgResult.failure(ex.getCode(), ex.getMsg());
|
||||
@@ -161,6 +140,16 @@ public class CzgControllerAdvice {
|
||||
return CzgResult.failure(CzgRespCode.RECORD_EXISTED);
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@ExceptionHandler(value = Exception.class)
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public CzgResult<Object> errorHandler(Exception ex) {
|
||||
// setErrorLog(ex);
|
||||
// 3. 处理未捕获的异常(系统异常,隐藏敏感信息)
|
||||
log.error("系统未处理异常", ex); // 替换原有 setErrorLog,使用日志框架
|
||||
return CzgResult.failure(CzgRespCode.SYSTEM_ERROR.getCode(), "系统繁忙,请稍后再试");
|
||||
}
|
||||
|
||||
private void setErrorLog(Exception ex) {
|
||||
log.error(ex.getMessage());
|
||||
log.error("错误", ex);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.czg.order.service;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.czg.exception.OrderCancelException;
|
||||
import com.czg.exception.OrderValidateException;
|
||||
import com.czg.order.dto.*;
|
||||
import com.czg.order.entity.OrderDetail;
|
||||
import com.czg.order.entity.OrderInfo;
|
||||
@@ -36,7 +38,7 @@ public interface OrderInfoService extends IService<OrderInfo> {
|
||||
|
||||
OrderInfo createOrder(OrderInfoAddDTO param);
|
||||
|
||||
OrderInfo checkOrderPay(CheckOrderPay param);
|
||||
OrderInfo checkOrderPay(CheckOrderPay param) throws OrderValidateException, OrderCancelException;
|
||||
|
||||
CzgResult<Object> mergeOrder(MergeOrderDTO param);
|
||||
|
||||
@@ -56,7 +58,7 @@ public interface OrderInfoService extends IService<OrderInfo> {
|
||||
|
||||
Boolean removeOrderDetail(Long shopId, Long orderId, Long detailId);
|
||||
|
||||
Boolean cancelledOrder(Long shopId, Long orderId);
|
||||
Boolean cancelledOrder(Long shopId, Long orderId) throws OrderCancelException ;
|
||||
|
||||
Boolean cancelledPlaceOrder(Long shopId, Long orderId, Integer placeNum);
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.czg.exception;
|
||||
|
||||
import com.czg.resp.CzgRespCode;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 自定义异常
|
||||
*
|
||||
@@ -9,6 +11,7 @@ import com.czg.resp.CzgRespCode;
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class CzgException extends RuntimeException {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private int code;
|
||||
|
||||
@@ -21,6 +21,12 @@ public class OrderValidateException extends RuntimeException{
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public OrderValidateException(String msg, Throwable e) {
|
||||
super(msg, e);
|
||||
this.code = CzgRespCode.FAILURE.getCode();
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
@@ -572,7 +572,8 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||
|
||||
|
||||
@GlobalTransactional
|
||||
protected void deepReward(ShopUser orderSourceShopUser, MkDistributionLevelConfig parentLevel, MkDistributionConfigVO config, MkDistributionUser currentDistributionUser, BigDecimal amount, Long sourceId, String type, String orderNo, Integer currentLevel) {
|
||||
protected void deepReward(ShopUser orderSourceShopUser, MkDistributionLevelConfig parentLevel, MkDistributionConfigVO config,
|
||||
MkDistributionUser currentDistributionUser, BigDecimal amount, Long sourceId, String type, String orderNo, Integer currentLevel) {
|
||||
if (currentLevel > 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -264,7 +264,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public OrderInfo createOrder(OrderInfoAddDTO param) {
|
||||
public OrderInfo createOrder(OrderInfoAddDTO param) throws ValidateException{
|
||||
ShopInfo shopInfo = shopInfoService.getById(param.getShopId());
|
||||
AssertUtil.isNull(shopInfo, "生成订单失败,店铺信息不存在");
|
||||
if (!shopInfo.getEatModel().contains(param.getDineMode())) {
|
||||
@@ -317,7 +317,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderInfo checkOrderPay(CheckOrderPay param) {
|
||||
public OrderInfo checkOrderPay(CheckOrderPay param) throws OrderValidateException, OrderCancelException {
|
||||
AssertUtil.isNull(param.getOrderId(), "支付失败,订单id不能为空");
|
||||
OrderInfo orderInfo = getById(param.getOrderId());
|
||||
if (!orderInfo.getStatus().equals(OrderStatusEnums.UNPAID.getCode())) {
|
||||
@@ -1596,13 +1596,13 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean cancelledOrder(Long shopId, Long orderId) {
|
||||
public Boolean cancelledOrder(Long shopId, Long orderId) throws OrderCancelException {
|
||||
OrderInfo orderInfo = getById(orderId);
|
||||
if (orderInfo == null) {
|
||||
throw new ApiNotPrintException("订单不存在");
|
||||
throw new OrderCancelException("订单不存在");
|
||||
}
|
||||
if (!OrderStatusEnums.UNPAID.getCode().equals(orderInfo.getStatus())) {
|
||||
throw new ApiNotPrintException("订单不可取消");
|
||||
throw new OrderCancelException("订单不可取消");
|
||||
}
|
||||
updateChain()
|
||||
.set(OrderInfo::getStatus, OrderStatusEnums.CANCELLED.getCode())
|
||||
|
||||
Reference in New Issue
Block a user