Merge remote-tracking branch 'origin/master'

This commit is contained in:
zjf committed 2025-05-28 11:39:22 +08:00
commit 642083b78e
10 files changed
+94 -33

No files matched your search

@@ -36,6 +36,11 @@ public enum HardPayTypeEnum {
CASH
);
public static final List<HardPayTypeEnum> isNotPay = List.of(
STRIDE_DEPT_QR_CODE,
FOREIGN_TICKET_QR_CODE
);
public static HardPayTypeEnum valueOfByType(String type) {
if (ObjectUtil.isEmpty(type)) return null;
return Arrays.stream(values()).filter(v -> ObjectUtil.equals(type, v.getType())).findFirst().get();
@@ -142,8 +142,8 @@ public class HardCarServiceImpl extends ServiceImpl<HardCarMapper, HardCarEntity
case CANTEEN -> {
// 查询食堂商品
AtomicInteger canteenTotalPrice = new AtomicInteger();
// 线上
if (ObjectUtil.equals(HardOrderTypeEnum.RESERVE, orderType)) {
// 线上
List<CanteenOnlineSpuAppVO> supList = onlineCanteenSpuService.getSpuListByIds(productIds).getData();
for (HardCreateCarDto v : list) {
supList.stream().filter(i -> ObjectUtil.equals(i.getId(), v.getProductId())).findFirst().ifPresent(spu -> {
@@ -151,9 +151,8 @@ public class HardCarServiceImpl extends ServiceImpl<HardCarMapper, HardCarEntity
canteenTotalPrice.addAndGet(itemTotalPrice);
});
}
}
// 线下
if (ObjectUtil.equals(HardOrderTypeEnum.BELOW, orderType)) {
} else {
// 线下
List<CanteenSpuEntity> supList = canteenSpuService.getSpuListByIds(productIds).getData();
for (HardCreateCarDto v : list) {
supList.stream().filter(i -> ObjectUtil.equals(i.getId(), v.getProductId())).findFirst().ifPresent(spu -> {
@@ -216,6 +216,10 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
if (ObjectUtil.isEmpty(wallet)) {
throw new RuntimeException("用户钱包不存在");
}
} else {
// 判断该二维码有没有被核销
boolean isCancel = validateCodeIsCancel(dto.getOrderType(), dto.getOrderSourceTypeId());
if (isCancel) throw new RuntimeException("该二维码已被核销");
}
int totalPrice = 0, extraPrice = 0, payPrice = 0;
totalPrice = hardCarService.computerCarTotalPrice(dto.getSysType(), dto.getOrderType(), dto.getList());
@@ -254,12 +258,18 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
.isOfflineOrder(YesNoEnum.NO.getCode())
.productDesc(subject)
.build();
if (isPay) orderObj.setWalletId(wallet.getId());
if (isPay) {
orderObj.setWalletId(wallet.getId());
}
baseMapper.insert(orderObj);
// 扣减库存
getSelf().fastenerInventory(orderObj, YesNoEnum.YES);
// 钱包扣款
if (isPay) getSelf().fastReduceBalance(orderObj);
getSelf().fastReduceBalance(orderObj);
if (!isPay) {
// 核销二维码
getSelf().cancelCode(orderObj, userDetail);
}
// 发送mq消息
getSelf().createOrderAfterSendMqMsg(orderObj.getId(), userDetail);
return orderObj.getId();
@@ -516,28 +526,27 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
@Transactional(rollbackFor = Exception.class)
public void fastReduceBalance(HardOrderEntity order) {
boolean isPay = isPay(HardOrderTypeEnum.valueOfByType(order.getOrderType()), HardPayTypeEnum.valueOfByType(order.getPayType()));
WalletBalanceTransactionDto reduceBuild = new WalletBalanceTransactionDto();
reduceBuild.setWalletId(order.getWalletId());
reduceBuild.setPrice(order.getPayPrice());
reduceBuild.setBizId(String.valueOf(order.getId()));
reduceBuild.setBizType(WalletBizEnum.PAYMENT);
reduceBuild.setForce(true);
R<WalletTransactionEntity> reduceRes = walletTransactionService.reduceWalletBalance(reduceBuild);
if (reduceRes.getCode() != 0 || ObjectUtil.isEmpty(reduceRes.getData())) {
throw new RuntimeException("钱包扣款错误");
}
WalletTransactionEntity walletTransaction = reduceRes.getData();
if (ObjectUtil.isNotEmpty(walletTransaction)) {
// 订单表订单状态
Integer payPrice = isPay ? order.getTotalPrice() + order.getExtraPrice() : 0;
HardOrderEntity update = HardOrderEntity.builder().id(order.getId()).payTime(LocalDateTime.now()).orderStatus(HardOrderStatusEnum.PAY.getType()).payPrice(payPrice).build();
baseMapper.updateById(update);
// 父购物车订单表订单状态
if (ObjectUtil.isNotEmpty(order.getParentCarId())) {
HardParentCarEntity updateParentCar = HardParentCarEntity.builder().id(order.getParentCarId()).orderStatus(HardOrderStatusEnum.PAY.getType()).build();
hardParentCarServiceImpl.updateById(updateParentCar);
if (isPay) {
WalletBalanceTransactionDto reduceBuild = new WalletBalanceTransactionDto();
reduceBuild.setWalletId(order.getWalletId());
reduceBuild.setPrice(order.getPayPrice());
reduceBuild.setBizId(String.valueOf(order.getId()));
reduceBuild.setBizType(WalletBizEnum.PAYMENT);
reduceBuild.setForce(true);
R<WalletTransactionEntity> reduceRes = walletTransactionService.reduceWalletBalance(reduceBuild);
if (reduceRes.getCode() != 0 || ObjectUtil.isEmpty(reduceRes.getData())) {
throw new RuntimeException("钱包扣款错误");
}
}
// 订单表订单状态
Integer payPrice = isPay ? order.getTotalPrice() + order.getExtraPrice() : 0;
HardOrderEntity update = HardOrderEntity.builder().id(order.getId()).payTime(LocalDateTime.now()).orderStatus(HardOrderStatusEnum.PAY.getType()).payPrice(payPrice).build();
baseMapper.updateById(update);
// 父购物车订单表订单状态
if (ObjectUtil.isNotEmpty(order.getParentCarId())) {
HardParentCarEntity updateParentCar = HardParentCarEntity.builder().id(order.getParentCarId()).orderStatus(HardOrderStatusEnum.PAY.getType()).build();
hardParentCarServiceImpl.updateById(updateParentCar);
}
}
@Override
@@ -625,8 +634,12 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
@Transactional(rollbackFor = Exception.class)
public void cancelCode(HardOrderEntity order, UserInfo userInfo) {
HardOrderTypeEnum orderTypeEnum = HardOrderTypeEnum.valueOfByType(order.getOrderType());
if (!ObjectUtil.isAllNotEmpty(orderTypeEnum)) return;
HardPayTypeEnum payType = HardPayTypeEnum.valueOfByType(order.getPayType());
if (!ObjectUtil.isAllNotEmpty(orderTypeEnum, payType)) return;
Long id = order.getId();
if (HardPayTypeEnum.isNotPay.contains(payType) && ObjectUtil.isNotEmpty(order.getOrderSourceTypeId())) {
id = order.getOrderSourceTypeId();
}
switch (orderTypeEnum) {
// 线下购买
case BELOW -> {
@@ -818,6 +831,9 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
if (!HardOrderTypeEnum.isPay(type)) {
return false;
}
if (HardPayTypeEnum.isNotPay.contains(payType)) {
return false;
}
return true;
}
@@ -16,4 +16,9 @@ public class WalletForeignDto extends WalletForeignEntity {
private Boolean isFindCheckUser = false;
/**
* 是否查询已使用完的
*/
private Boolean isFindUsed = true;
}
@@ -14,4 +14,9 @@ public class WalletStrideDto extends WalletStrideEntity {
private Boolean isFindCheckUser = false;
/**
* 是否查询已使用完的
*/
private Boolean isFindUsed = true;
}
@@ -62,6 +62,7 @@ public class WalletForeignController {
public R<Page<WalletForeignVo>> appPageJoin(@ParameterObject Page page, @ParameterObject WalletForeignDto dto) {
PjcloudUser user = SecurityUtils.getUser();
dto.setUserId(user.getId());
dto.setIsFindUsed(false);
return R.ok(walletForeignService.pageJoin(page, dto));
}
@@ -58,6 +58,7 @@ public class WalletStrideController {
public R appPageJoin(@ParameterObject Page page, @ParameterObject WalletStrideDto dto) {
PjcloudUser user = SecurityUtils.getUser();
dto.setUserId(user.getId());
dto.setIsFindUsed(false);
return R.ok(walletStrideService.pageJoin(page, dto));
}
@@ -23,6 +23,7 @@ public interface WalletForeignMapper extends PjcloudBaseMapper<WalletForeignEnti
.eqIfExists(WalletForeignEntity::getProcessStatus, dto.getProcessStatus())
.in(ObjectUtil.isNotEmpty(dto.getDeptIds()), WalletForeignEntity::getDeptId, dto.getDeptIds())
.in(ObjectUtil.isNotEmpty(dto.getUserIds()), WalletForeignEntity::getUserId, dto.getUserIds())
.ne(!dto.getIsFindUsed(), WalletForeignEntity::getCount, WalletForeignEntity::getUseCount)
.orderByDesc(WalletForeignEntity::getCreateTime)
.orderByDesc(WalletForeignEntity::getId);
return selectJoinPage(page, WalletForeignVo.class, wrapper);
@@ -8,6 +8,7 @@ import com.bsd.pjcloud.common.core.util.BeanUtils;
import com.bsd.pjcloud.common.data.datascope.DataScope;
import com.bsd.pjcloud.common.data.datascope.PjcloudBaseMapper;
import com.bsd.pjcloud.wallet.api.dto.WalletStrideDto;
import com.bsd.pjcloud.wallet.api.entity.WalletForeignEntity;
import com.bsd.pjcloud.wallet.api.entity.WalletStrideEntity;
import com.bsd.pjcloud.wallet.api.vo.WalletStrideVo;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
@@ -23,6 +24,7 @@ public interface WalletStrideMapper extends PjcloudBaseMapper<WalletStrideEntity
.eqIfExists(WalletStrideEntity::getProcessStatus, dto.getProcessStatus())
.in(ObjectUtil.isNotEmpty(dto.getDeptIds()), WalletStrideEntity::getDeptId, dto.getDeptIds())
.in(ObjectUtil.isNotEmpty(dto.getUserIds()), WalletStrideEntity::getUserId, dto.getUserIds())
.ne(!dto.getIsFindUsed(), WalletForeignEntity::getCount, WalletForeignEntity::getUseCount)
.orderByDesc(WalletStrideEntity::getCreateTime)
.orderByDesc(WalletStrideEntity::getId);
return selectJoinPage(page, WalletStrideVo.class, wrapper);
@@ -21,17 +21,17 @@ import com.bsd.pjcloud.hard.api.dto.code.QRCodeExtraDto;
import com.bsd.pjcloud.wallet.api.constant.WalletCodeBizEnum;
import com.bsd.pjcloud.wallet.api.dto.WalletCodeUseDto;
import com.bsd.pjcloud.wallet.api.entity.WalletCodeUseEntity;
import com.bsd.pjcloud.wallet.api.entity.WalletForeignEntity;
import com.bsd.pjcloud.wallet.api.entity.WalletManageEntity;
import com.bsd.pjcloud.wallet.api.entity.WalletStrideEntity;
import com.bsd.pjcloud.wallet.api.vo.WalletCodeUseVo;
import com.bsd.pjcloud.wallet.api.vo.WalletSettingVo;
import com.bsd.pjcloud.wallet.mapper.WalletCodeUseMapper;
import com.bsd.pjcloud.wallet.service.WalletCodeUseService;
import com.bsd.pjcloud.wallet.service.*;
import com.bsd.pjcloud.hard.api.constant.order.HardOrderTypeEnum;
import com.bsd.pjcloud.hard.api.constant.order.HardPayTypeEnum;
import com.bsd.pjcloud.hard.api.dto.code.QRCodeDto;
import com.bsd.pjcloud.hard.api.utils.HardUtil;
import com.bsd.pjcloud.wallet.service.WalletManageService;
import com.bsd.pjcloud.wallet.service.WalletSettingService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;
@@ -67,6 +67,10 @@ public class WalletCodeUseServiceImpl extends ServiceImpl<WalletCodeUseMapper, W
@Lazy
private final WalletManageService walletManageService;
private final WalletSettingService walletSettingService;
@Lazy
private final WalletStrideService walletStrideService;
@Lazy
private final WalletForeignService walletForeignService;
private final RemoteUserService userService;
private final RemoteFileService remoteFileService;
@@ -196,21 +200,43 @@ public class WalletCodeUseServiceImpl extends ServiceImpl<WalletCodeUseMapper, W
public Boolean cancelCode(Long id) {
WalletCodeUseEntity codeUse = baseMapper.selectOne(new LambdaQueryWrapper<WalletCodeUseEntity>()
.eq(WalletCodeUseEntity::getBizId, id)
.eq(WalletCodeUseEntity::getStatus, YesNoEnum.NO.getCode())
.last(" limit 1")
.orderByDesc(WalletCodeUseEntity::getCreateTime)
.orderByDesc(WalletCodeUseEntity::getId)
);
if (ObjectUtil.isEmpty(codeUse)) return null;
if (ObjectUtil.equals(codeUse.getStatus(), YesNoEnum.YES.getCode())) return false;
WalletCodeUseEntity updateObj = WalletCodeUseEntity.builder().id(codeUse.getId()).status(YesNoEnum.YES.getCode()).useTime(LocalDateTime.now()).build();
// 如果是跨单位或者外来人员增加使用数量
// 跨单位
if (ObjectUtil.equals(codeUse.getBizType(), WalletCodeBizEnum.STRIDE.getCode())) {
WalletStrideEntity strideDetail = walletStrideService.getById(codeUse.getBizId());
if (ObjectUtil.isNotEmpty(strideDetail)) {
WalletStrideEntity useUpdateObj = WalletStrideEntity.builder().id(strideDetail.getId()).useCount(strideDetail.getUseCount() + 1).build();
walletStrideService.updateById(useUpdateObj);
}
}
// 外来人员
if (ObjectUtil.equals(codeUse.getBizType(), WalletCodeBizEnum.FOREIGN.getCode())) {
WalletForeignEntity foreignDetail = walletForeignService.getById(codeUse.getBizId());
if (ObjectUtil.isNotEmpty(foreignDetail)) {
WalletForeignEntity useUpdateObj = WalletForeignEntity.builder().id(foreignDetail.getId()).useCount(foreignDetail.getUseCount() + 1).build();
walletForeignService.updateById(useUpdateObj);
}
}
return baseMapper.updateById(updateObj) > 0;
}
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean isCancelCode(Long id) {
WalletCodeUseEntity codeUse = baseMapper.selectOne(new LambdaQueryWrapper<WalletCodeUseEntity>()
// 跨单位和外来人员有多张二维码
Long count = baseMapper.selectCount(new LambdaQueryWrapper<WalletCodeUseEntity>()
.eq(WalletCodeUseEntity::getBizId, id)
.eq(WalletCodeUseEntity::getStatus, YesNoEnum.NO.getCode())
);
if (ObjectUtil.isEmpty(codeUse)) return null;
return ObjectUtil.equals(codeUse.getStatus(), YesNoEnum.YES.getCode());
return count <= 0;
}
/**