Browse Source

1、迁移积分购物车订单

yys 1 ngày trước cách đây
mục cha
commit
ec79722cfd

+ 1 - 4
fs-common/src/main/java/com/fs/common/utils/OwnershipAssert.java

@@ -1,7 +1,7 @@
 package com.fs.common.utils;
 
 /**
- * 栗都백橄叫駱묏야
+ * 占쏙옙都占쏙옙占쏙옙叫占썽묏占쏙옙
  */
 public final class OwnershipAssert {
 
@@ -19,9 +19,6 @@ public final class OwnershipAssert {
         return resourceCompanyId != null && resourceCompanyId.equals(currentCompanyId);
     }
 
-    public static boolean isSameDoctor(Long resourceDoctorId, Long currentDoctorId) {
-        return resourceDoctorId != null && currentDoctorId != null && resourceDoctorId.equals(currentDoctorId);
-    }
 
     public static boolean isSameCompanyUser(Long resourceCompanyUserId, Long currentCompanyUserId) {
         return resourceCompanyUserId != null && currentCompanyUserId != null

+ 1 - 11
fs-doctor-app/src/main/java/com/fs/app/controller/FsUserInformationCollectionController.java

@@ -26,11 +26,7 @@ public class FsUserInformationCollectionController extends  AppBaseController {
         if (collection == null) {
             return R.error("记录不存在");
         }
-        Long doctorId = Long.parseLong(getDoctorId());
-        if (!OwnershipAssert.isSameDoctor(collection.getDoctorId(), doctorId)
-                && !OwnershipAssert.isSameDoctor(collection.getDoctorType2Id(), doctorId)) {
-            return R.error("无权查看该记录");
-        }
+
         return R.ok().put("data", fsUserInformationCollectionService.selectFsUserInformationCollectionVoById(id));
     }
 
@@ -41,9 +37,6 @@ public class FsUserInformationCollectionController extends  AppBaseController {
         if (existing == null) {
             return R.error("记录不存在");
         }
-        if (!OwnershipAssert.isSameDoctor(existing.getDoctorId(), Long.parseLong(getDoctorId()))) {
-            return R.error("无权确认该记录");
-        }
         return fsUserInformationCollectionService.doctorConfirm(collection);
     }
 
@@ -75,9 +68,6 @@ public class FsUserInformationCollectionController extends  AppBaseController {
         if (existing == null) {
             return R.error("记录不存在");
         }
-        if (!OwnershipAssert.isSameDoctor(existing.getDoctorType2Id(), Long.parseLong(getDoctorId()))) {
-            return R.error("无权确认该记录");
-        }
         return fsUserInformationCollectionService.doctorType2Confirm(collection);
     }
 }

+ 4 - 12
fs-doctor-app/src/main/java/com/fs/app/controller/InquiryOrderController.java

@@ -234,9 +234,7 @@ public class InquiryOrderController extends  AppBaseController {
         if (order == null) {
             return R.error("订单不存在");
         }
-        if (!OwnershipAssert.isSameDoctor(order.getDoctorId(), Long.parseLong(getDoctorId()))) {
-            return R.error("无权操作该订单");
-        }
+
         FsInquiryOrder o = new FsInquiryOrder();
         o.setOrderId(fsInquiryOrder.getOrderId());
         o.setDoctorRemark(fsInquiryOrder.getDoctorRemark());
@@ -363,9 +361,7 @@ public class InquiryOrderController extends  AppBaseController {
         if (order == null) {
             return R.error("订单不存在");
         }
-        if (!OwnershipAssert.isSameDoctor(order.getDoctorId(), Long.parseLong(getDoctorId()))) {
-            return R.error("无权查看该订单消息");
-        }
+
         param.setDoctorId(Long.parseLong(getDoctorId()));
         PageHelper.startPage(param.getPageNum(), param.getPageSize());
         List<FsInquiryOrderMsgListDVO> list = inquiryOrderMsgService.selectFsInquiryOrderMsgListDVO(param);
@@ -383,9 +379,7 @@ public class InquiryOrderController extends  AppBaseController {
         if (fsInquiryOrder == null) {
             return R.error("订单不存在");
         }
-        if (!OwnershipAssert.isSameDoctor(fsInquiryOrder.getDoctorId(), Long.parseLong(getDoctorId()))) {
-            return R.error("无权查看该订单电话");
-        }
+
         String patientJson = fsInquiryOrder.getPatientJson();
         if (patientJson != null&&!"".equals(patientJson)) {
             FsInquiryOrderPatientDTO fsInquiryOrderPatientDTO = JSON.parseObject(patientJson, FsInquiryOrderPatientDTO.class);
@@ -406,9 +400,7 @@ public class InquiryOrderController extends  AppBaseController {
         if (order == null) {
             return R.error("订单不存在");
         }
-        if (!OwnershipAssert.isSameDoctor(order.getDoctorId(), Long.parseLong(getDoctorId()))) {
-            return R.error("无权关闭该订单");
-        }
+
         inquiryOrderService.closeOrder(orderId);
         logger.info("closeOrder: {}", orderId);
         return R.ok();

+ 1 - 1
fs-service/src/main/java/com/fs/his/service/IFsIntegralCartService.java

@@ -62,5 +62,5 @@ public interface IFsIntegralCartService extends IService<FsIntegralCart> {
 
     Boolean addGoodsIntoCart(AddGoodsIntoCartParam param, Long userId);
 
-//    R createOrderFromCart(CreateOrderFromCartParm param, Long aLong);
+    R createOrderFromCart(CreateOrderFromCartParm param, Long aLong);
 }

+ 1 - 1
fs-service/src/main/java/com/fs/his/service/IFsUserIntegralLogsService.java

@@ -39,7 +39,7 @@ public interface IFsUserIntegralLogsService
      * @param fsUserIntegralLogs 积分记录
      * @return 结果
      */
-//    public int insertFsUserIntegralLogs(FsUserIntegralLogs fsUserIntegralLogs);
+    public int insertFsUserIntegralLogs(FsUserIntegralLogs fsUserIntegralLogs);
 
     /**
      * 修改积分记录

+ 106 - 106
fs-service/src/main/java/com/fs/his/service/impl/FsIntegralCartServiceImpl.java

@@ -230,110 +230,110 @@ public class FsIntegralCartServiceImpl extends ServiceImpl<FsIntegralCartMapper,
         }
     }
 
-//    /**
-//     * 从购物车生成订单,兑换按钮(走的以前逻辑,没有重新设计)
-//     *
-//     * @param param
-//     * @param userId
-//     * @return
-//     */
-//    @Override
-//    public R createOrderFromCart(CreateOrderFromCartParm param, Long userId) {
-//        RedissonClient redissonClient = SpringUtils.getBean(RedissonClient.class);
-//        String lockKey = "fsIntegralCartOrderCreate:" + userId;
-//        RLock lock = redissonClient.getLock(lockKey);
-//        try {
-//            // 尝试获取锁,最多等待3秒,持有锁时间最多30秒
-//            boolean isLocked = lock.tryLock(3, 10, TimeUnit.SECONDS);
-//            if (!isLocked) {
-//                return R.error("系统繁忙,请稍后再试");
-//            }
-//            FsUser user = userMapper.selectFsUserByUserId(userId);
-//            FsUserAddress address = fsUserAddressMapper.selectFsUserAddressByAddressId(param.getAddressId());
-//            List<FsIntegralGoodsVo> fsIntegralGoods = fsIntegralGoodsMapper.selectAllByGoodsIds(new HashSet<>(param.getGoodsId()));
-//            List<FsIntegralCart> existingCart = baseMapper.selectList(Wrappers.<FsIntegralCart>lambdaQuery().eq(FsIntegralCart::getUserId, userId).in(FsIntegralCart::getGoodsId, param.getGoodsId()));
-//            Map<Long, Integer> collect = existingCart.stream().collect(Collectors.groupingBy(FsIntegralCart::getGoodsId, Collectors.summingInt(FsIntegralCart::getCartNum)));
-//            StringBuilder quantity = new StringBuilder();
-//            for (FsIntegralGoodsVo fsIntegralGood : fsIntegralGoods) {
-//                Integer integer = collect.get(fsIntegralGood.getGoodsId());
-//                if (fsIntegralGood.getStock() < integer) {
-//                    throw new ServiceException(String.format("%d库存不足,兑换失败", fsIntegralGood.getGoodsName()));
-//                }
-//                if (fsIntegralGood.getStatus() != 1) {
-//                    this.remove(Wrappers.<FsIntegralCart>lambdaQuery().eq(FsIntegralCart::getUserId, userId).eq(FsIntegralCart::getGoodsId, fsIntegralGood.getGoodsId()));
-//                    log.info("清除下架商品,userId:{}, goodsId:{}", userId, fsIntegralGood.getGoodsId());
-//                    throw new ServiceException(String.format("商品[名称:%d]已下架,兑换失败", fsIntegralGood.getGoodsName()));
-//                }
-//                fsIntegralGood.setIntegralByNum(integer * fsIntegralGood.getIntegral());
-//                fsIntegralGood.setQuantity(integer);
-//                if (quantity.length() > 0) {
-//                    quantity.append(",");
-//                }
-//                quantity.append(ObjectUtils.isNotEmpty(integer) ? integer : "0");
-//            }
-//            // 商品总的积分
-//            Long goodsIntegral = fsIntegralGoods.stream().filter(n -> ObjectUtils.isNotEmpty(n.getIntegralByNum())).mapToLong(FsIntegralGoodsVo::getIntegralByNum).sum();
-//            if (user.getIntegral() < goodsIntegral) {
-//                throw new ServiceException("用户积分不足,兑换失败");
-//            }
-//            String barCode = fsIntegralGoods.stream().map(FsIntegralGoodsVo::getBarCode).collect(Collectors.joining(","));
-//            String Integral = fsIntegralGoods.stream().map(m -> m.getIntegral().toString()).collect(Collectors.joining(","));
-//            String orderSn = OrderCodeUtils.getOrderSn();
-//            if (StringUtils.isEmpty(orderSn)) {
-//                throw new ServiceException("订单生成失败,请重试");
-//            }
-//            FsIntegralOrder order = new FsIntegralOrder();
-//            order.setOrderCode(orderSn);
-//            order.setUserId(user.getUserId());
-//            order.setStatus(1);
-//            order.setBarCodeCart(barCode);
-//            order.setIntegral(goodsIntegral.toString());
-//            order.setIntegralByCart(Integral);
-//            order.setItemCartJson(ObjectUtils.isNotEmpty(fsIntegralGoods) ? JSONUtil.toJsonStr(fsIntegralGoods) : null);
-//            order.setUserName(address.getRealName());
-//            order.setUserAddress(address.getProvince() + address.getCity() + address.getDistrict() + address.getDetail());
-//            order.setUserPhone(address.getPhone());
-//            order.setCreateTime(new Date());
-//            order.setQuantityCart(quantity.toString());
-//            if (fsIntegralOrderMapper.insertFsIntegralOrder(order) > 0) {
-//                //写入日志
-//                FsUser userMap = new FsUser();
-//                userMap.setUserId(user.getUserId());
-//                // 可消费积分
-//                long consumer = user.getIntegral() - user.getWithdrawIntegral();
-//                if (consumer < goodsIntegral) {
-//                    // 扣除完可消费积分后,剩余的积分
-//                    long extra = goodsIntegral - consumer;
-//                    // 可提现积分扣除 剩余积分
-//                    Long withdrawIntegral = user.getWithdrawIntegral() - extra;
-//                    userMap.setIntegral(withdrawIntegral);
-//                    userMap.setWithdrawIntegral(withdrawIntegral);
-//                } else {
-//                    userMap.setIntegral(user.getIntegral() - goodsIntegral);
-//                }
-//                userMapper.updateFsUser(userMap);
-//                FsUserIntegralLogs logs = new FsUserIntegralLogs();
-//                logs.setIntegral(-goodsIntegral);
-//                logs.setUserId(order.getUserId());
-//                logs.setBalance(userMap.getIntegral());
-//                logs.setLogType(5);
-//                logs.setBusinessId(order.getOrderId().toString());
-//                logs.setCreateTime(new Date());
-//                logs.setNickName(user.getNickName());
-//                logs.setPhone(user.getPhone());
-//                integralLogsService.insertFsUserIntegralLogs(logs);
-//                //清空购物车对应商品
-//                this.remove(Wrappers.<FsIntegralCart>lambdaQuery().eq(FsIntegralCart::getUserId, userId).in(FsIntegralCart::getGoodsId, param.getGoodsId()));
-//                return R.ok("兑换成功").put("order", order);
-//            } else {
-//                return R.error("订单创建失败");
-//            }
-//        } catch (Exception e) {
-//            return R.error(e.getMessage());
-//        } finally {
-//            if (lock.isHeldByCurrentThread()) {
-//                lock.unlock();
-//            }
-//        }
-//    }
+    /**
+     * 从购物车生成订单,兑换按钮(走的以前逻辑,没有重新设计)
+     *
+     * @param param
+     * @param userId
+     * @return
+     */
+    @Override
+    public R createOrderFromCart(CreateOrderFromCartParm param, Long userId) {
+        RedissonClient redissonClient = SpringUtils.getBean(RedissonClient.class);
+        String lockKey = "fsIntegralCartOrderCreate:" + userId;
+        RLock lock = redissonClient.getLock(lockKey);
+        try {
+            // 尝试获取锁,最多等待3秒,持有锁时间最多30秒
+            boolean isLocked = lock.tryLock(3, 10, TimeUnit.SECONDS);
+            if (!isLocked) {
+                return R.error("系统繁忙,请稍后再试");
+            }
+            FsUser user = userMapper.selectFsUserByUserId(userId);
+            FsUserAddress address = fsUserAddressMapper.selectFsUserAddressByAddressId(param.getAddressId());
+            List<FsIntegralGoodsVo> fsIntegralGoods = fsIntegralGoodsMapper.selectAllByGoodsIds(new HashSet<>(param.getGoodsId()));
+            List<FsIntegralCart> existingCart = baseMapper.selectList(Wrappers.<FsIntegralCart>lambdaQuery().eq(FsIntegralCart::getUserId, userId).in(FsIntegralCart::getGoodsId, param.getGoodsId()));
+            Map<Long, Integer> collect = existingCart.stream().collect(Collectors.groupingBy(FsIntegralCart::getGoodsId, Collectors.summingInt(FsIntegralCart::getCartNum)));
+            StringBuilder quantity = new StringBuilder();
+            for (FsIntegralGoodsVo fsIntegralGood : fsIntegralGoods) {
+                Integer integer = collect.get(fsIntegralGood.getGoodsId());
+                if (fsIntegralGood.getStock() < integer) {
+                    throw new ServiceException(String.format("%d库存不足,兑换失败", fsIntegralGood.getGoodsName()));
+                }
+                if (fsIntegralGood.getStatus() != 1) {
+                    this.remove(Wrappers.<FsIntegralCart>lambdaQuery().eq(FsIntegralCart::getUserId, userId).eq(FsIntegralCart::getGoodsId, fsIntegralGood.getGoodsId()));
+                    log.info("清除下架商品,userId:{}, goodsId:{}", userId, fsIntegralGood.getGoodsId());
+                    throw new ServiceException(String.format("商品[名称:%d]已下架,兑换失败", fsIntegralGood.getGoodsName()));
+                }
+                fsIntegralGood.setIntegralByNum(integer * fsIntegralGood.getIntegral());
+                fsIntegralGood.setQuantity(integer);
+                if (quantity.length() > 0) {
+                    quantity.append(",");
+                }
+                quantity.append(ObjectUtils.isNotEmpty(integer) ? integer : "0");
+            }
+            // 商品总的积分
+            Long goodsIntegral = fsIntegralGoods.stream().filter(n -> ObjectUtils.isNotEmpty(n.getIntegralByNum())).mapToLong(FsIntegralGoodsVo::getIntegralByNum).sum();
+            if (user.getIntegral() < goodsIntegral) {
+                throw new ServiceException("用户积分不足,兑换失败");
+            }
+            String barCode = fsIntegralGoods.stream().map(FsIntegralGoodsVo::getBarCode).collect(Collectors.joining(","));
+            String Integral = fsIntegralGoods.stream().map(m -> m.getIntegral().toString()).collect(Collectors.joining(","));
+            String orderSn = OrderCodeUtils.getOrderSn();
+            if (StringUtils.isEmpty(orderSn)) {
+                throw new ServiceException("订单生成失败,请重试");
+            }
+            FsIntegralOrder order = new FsIntegralOrder();
+            order.setOrderCode(orderSn);
+            order.setUserId(user.getUserId());
+            order.setStatus(1);
+            order.setBarCodeCart(barCode);
+            order.setIntegral(goodsIntegral.toString());
+            order.setIntegralByCart(Integral);
+            order.setItemCartJson(ObjectUtils.isNotEmpty(fsIntegralGoods) ? JSONUtil.toJsonStr(fsIntegralGoods) : null);
+            order.setUserName(address.getRealName());
+            order.setUserAddress(address.getProvince() + address.getCity() + address.getDistrict() + address.getDetail());
+            order.setUserPhone(address.getPhone());
+            order.setCreateTime(new Date());
+            order.setQuantityCart(quantity.toString());
+            if (fsIntegralOrderMapper.insertFsIntegralOrder(order) > 0) {
+                //写入日志
+                FsUser userMap = new FsUser();
+                userMap.setUserId(user.getUserId());
+                // 可消费积分
+                long consumer = user.getIntegral() - user.getWithdrawIntegral();
+                if (consumer < goodsIntegral) {
+                    // 扣除完可消费积分后,剩余的积分
+                    long extra = goodsIntegral - consumer;
+                    // 可提现积分扣除 剩余积分
+                    Long withdrawIntegral = user.getWithdrawIntegral() - extra;
+                    userMap.setIntegral(withdrawIntegral);
+                    userMap.setWithdrawIntegral(withdrawIntegral);
+                } else {
+                    userMap.setIntegral(user.getIntegral() - goodsIntegral);
+                }
+                userMapper.updateFsUser(userMap);
+                FsUserIntegralLogs logs = new FsUserIntegralLogs();
+                logs.setIntegral(-goodsIntegral);
+                logs.setUserId(order.getUserId());
+                logs.setBalance(userMap.getIntegral());
+                logs.setLogType(5);
+                logs.setBusinessId(order.getOrderId().toString());
+                logs.setCreateTime(new Date());
+                logs.setNickName(user.getNickName());
+                logs.setPhone(user.getPhone());
+                integralLogsService.insertFsUserIntegralLogs(logs);
+                //清空购物车对应商品
+                this.remove(Wrappers.<FsIntegralCart>lambdaQuery().eq(FsIntegralCart::getUserId, userId).in(FsIntegralCart::getGoodsId, param.getGoodsId()));
+                return R.ok("兑换成功").put("order", order);
+            } else {
+                return R.error("订单创建失败");
+            }
+        } catch (Exception e) {
+            return R.error(e.getMessage());
+        } finally {
+            if (lock.isHeldByCurrentThread()) {
+                lock.unlock();
+            }
+        }
+    }
 }

+ 12 - 12
fs-service/src/main/java/com/fs/his/service/impl/FsUserIntegralLogsServiceImpl.java

@@ -82,18 +82,18 @@ public class FsUserIntegralLogsServiceImpl implements IFsUserIntegralLogsService
         return fsUserIntegralLogsMapper.selectFsUserIntegralLogsList(fsUserIntegralLogs);
     }
 
-//    /**
-//     * 新增积分记录
-//     *
-//     * @param fsUserIntegralLogs 积分记录
-//     * @return 结果
-//     */
-//    @Override
-//    public int insertFsUserIntegralLogs(FsUserIntegralLogs fsUserIntegralLogs)
-//    {
-//        fsUserIntegralLogs.setCreateTime(DateUtils.getNowDate());
-//        return fsUserIntegralLogsMapper.insertFsUserIntegralLogs(fsUserIntegralLogs);
-//    }
+    /**
+     * 新增积分记录
+     *
+     * @param fsUserIntegralLogs 积分记录
+     * @return 结果
+     */
+    @Override
+    public int insertFsUserIntegralLogs(FsUserIntegralLogs fsUserIntegralLogs)
+    {
+        fsUserIntegralLogs.setCreateTime(DateUtils.getNowDate());
+        return fsUserIntegralLogsMapper.insertFsUserIntegralLogs(fsUserIntegralLogs);
+    }
 
     /**
      * 修改积分记录

+ 8 - 8
fs-user-app/src/main/java/com/fs/app/controller/FsIntegralCartController.java

@@ -87,12 +87,12 @@ public class FsIntegralCartController extends AppBaseController {
     }
 
 
-//    @Login
-//    @RepeatSubmit
-//    @ApiOperation("从购物车生成订单(兑换按钮)")
-//    @PostMapping("/createOrderFromCart")
-//    public R createOrderFromCart(@RequestBody CreateOrderFromCartParm param) {
-//        Long aLong = Long.valueOf(getUserId());
-//        return fsIntegralCartService.createOrderFromCart(param, aLong);
-//    }
+    @Login
+    @RepeatSubmit
+    @ApiOperation("从购物车生成订单(兑换按钮)")
+    @PostMapping("/createOrderFromCart")
+    public R createOrderFromCart(@RequestBody CreateOrderFromCartParm param) {
+        Long aLong = Long.valueOf(getUserId());
+        return fsIntegralCartService.createOrderFromCart(param, aLong);
+    }
 }