|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import cc.mrbird.febs.common.enumerates.OrderStatusEnum; | 
|---|
|  |  |  | import cc.mrbird.febs.common.exception.FebsException; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.entity.MallGoods; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.entity.MallGoodsSku; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.entity.MallOrderInfo; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.entity.MallOrderItem; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.entity.*; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.mapper.*; | 
|---|
|  |  |  | import cn.hutool.core.collection.CollUtil; | 
|---|
|  |  |  | import cn.hutool.core.date.DateUnit; | 
|---|
|  |  |  | import cn.hutool.core.date.DateUtil; | 
|---|
|  |  |  | import cn.hutool.core.util.ObjectUtil; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | 
|---|
|  |  |  | import org.springframework.scheduling.annotation.Scheduled; | 
|---|
|  |  |  | import org.springframework.stereotype.Component; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | **/ | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | @Component | 
|---|
|  |  |  | @ConditionalOnProperty(prefix = "system", name = "job", havingValue = "true") | 
|---|
|  |  |  | public class OrderOvertimeJob { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private MallGoodsSkuMapper mallGoodsSkuMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private MallMemberCouponMapper mallMemberCouponMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Scheduled(cron = "0 0/5 * * * ? ") | 
|---|
|  |  |  | public void overtimeJob() { | 
|---|
|  |  |  | 
|---|
|  |  |  | throw new FebsException("购买商品或sku不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (sku.getStock() < mallOrderItem.getCnt()) { | 
|---|
|  |  |  | throw new FebsException(sku.getSkuName() + "库存不足"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //                        if (sku.getStock() < mallOrderItem.getCnt()) { | 
|---|
|  |  |  | //                            throw new FebsException(sku.getSkuName() + "库存不足"); | 
|---|
|  |  |  | //                        } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | MallGoods mallGoods = mallGoodsMapper.selectById(sku.getGoodsId()); | 
|---|
|  |  |  | Integer goodsResult = mallGoodsMapper.upDateStockAndVolumeByGoodsId(mallGoods.getId(), mallOrderItem.getCnt()); | 
|---|
|  |  |  | Integer goodsResult = mallGoodsMapper.updateStockAndVolumeByGoodsId(mallGoods.getId(), mallOrderItem.getCnt()); | 
|---|
|  |  |  | if(1 != goodsResult){ | 
|---|
|  |  |  | throw new FebsException(mallGoods.getGoodsName() + "库存不足"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Integer skuResult = mallGoodsSkuMapper.upDateStockAndVolumeBySkuId(sku.getId(),mallOrderItem.getCnt()); | 
|---|
|  |  |  | Integer skuResult = mallGoodsSkuMapper.updateStockAndVolumeBySkuId(sku.getId(),mallOrderItem.getCnt()); | 
|---|
|  |  |  | if(1 != skuResult){ | 
|---|
|  |  |  | throw new FebsException(sku.getSkuName() + "库存不足"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Long memberCouponId = mallOrderItem.getMemberCouponId(); | 
|---|
|  |  |  | MallMemberCoupon mallMemberCoupon = mallMemberCouponMapper.selectById(memberCouponId); | 
|---|
|  |  |  | if(ObjectUtil.isNotEmpty(mallMemberCoupon)){ | 
|---|
|  |  |  | mallMemberCoupon.setState(1); | 
|---|
|  |  |  | mallMemberCouponMapper.updateById(mallMemberCoupon); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|