Sfoglia il codice sorgente

定时任务 、 出价相关接口修改

hr~ 1 mese fa
parent
commit
75c7fd5792

+ 1 - 1
auc/src/main/java/cn/hobbystocks/auc/web/SyncController.java

@@ -5,7 +5,6 @@ import cn.hobbystocks.auc.common.constant.Constants;
 import cn.hobbystocks.auc.common.core.domain.AjaxResult;
 import cn.hobbystocks.auc.common.core.redis.Locker;
 import cn.hobbystocks.auc.common.utils.UserType;
-import cn.hobbystocks.auc.domain.Lot;
 import cn.hobbystocks.auc.service.SyncService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -15,6 +14,7 @@ import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+
 @RestController
 @RequestMapping("/auction/admin/sync")
 @Api(tags = "同步拍品直播数据和缓存")

+ 28 - 2
bid/src/main/java/cn/hobbystocks/auc/web/BidingController.java

@@ -19,10 +19,12 @@ import cn.hobbystocks.auc.handle.RuleHandlerHolder;
 import cn.hobbystocks.auc.handle.context.Live;
 import cn.hobbystocks.auc.handle.context.LiveContext;
 import cn.hobbystocks.auc.mapper.BidRecordMapper;
+import cn.hobbystocks.auc.mapper.DepositOrderMapper;
 import cn.hobbystocks.auc.service.IBidService;
 import cn.hobbystocks.auc.service.ILotService;
 import cn.hobbystocks.auc.vo.BidVO;
 import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.github.pagehelper.Page;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Sets;
@@ -69,6 +71,8 @@ public class BidingController extends BaseController {
     private RedisCache redisCache;
     @Autowired
     private RuleHandlerHolder ruleHandlerHolder;
+    @Autowired
+    private DepositOrderMapper depositOrderMapper;
 
 
 
@@ -86,17 +90,22 @@ public class BidingController extends BaseController {
     @ApiOperation("出价拍卖增加价格")
     @PostMapping({"/addPrice"})
     public AjaxResult addPriceV2(@RequestBody BidVO bid) {
-        //todo 判断用户是否已缴纳保证金
-
         log.info("add price {}", bid);
         // 创建bidRecord
         UserInfo userInfo = UserUtils.getUserInfo();
+        Lot dbLot = lotService.selectLotById(bid.getLotId());
+        if (!hasPaidDeposit(userInfo.getId(), dbLot)) {
+            log.warn("addPrice fail, user has no paid deposit, userId:{} auctionId:{} lotId:{}",
+                userInfo.getId(), bid.getAuctionId(), bid.getLotId());
+            return AjaxResult.error("请先缴纳保证金");
+        }
         // 创建bidRecord
         bid.setCreateBy(userInfo.getSub());
         bid.setAccount(userInfo.getAccount());
         String accountId = String.valueOf(userInfo.getId());
         bid.setAccountId(accountId);
         bid.setAvatar(userInfo.getAvatar());
+        bid.setUserCode(bidService.getOrCreateUserCode(dbLot.getAuctionId(), accountId));
         bid.setBidNo(UUID.randomUUID().toString());
         //用户出价记录日志,无论是否出价成功都记录
         Long recordId = createBidRecord(bid);
@@ -541,6 +550,23 @@ public class BidingController extends BaseController {
         return record.getId();
     }
 
+    private boolean hasPaidDeposit(Integer userId, Lot lot) {
+        if (Objects.isNull(userId) || Objects.isNull(lot)) {
+            return false;
+        }
+        LambdaQueryWrapper<DepositOrder> queryWrapper = new LambdaQueryWrapper<DepositOrder>()
+            .eq(DepositOrder::getUserId, userId)
+            .eq(DepositOrder::getStatus, 1);
+        if (Objects.nonNull(lot.getDeposit())) {
+            queryWrapper.eq(DepositOrder::getDepositType, "拍品")
+                .eq(DepositOrder::getLotId, lot.getId());
+        } else {
+            queryWrapper.eq(DepositOrder::getDepositType, "拍卖会")
+                .eq(DepositOrder::getAuctionId, lot.getAuctionId());
+        }
+        return depositOrderMapper.selectCount(queryWrapper) > 0;
+    }
+
     private void createBidRecordCache(Bid bid){
         List<BidRecord> bidList = new ArrayList<>();
         BidRecord record = BidRecord.builder()

+ 0 - 1
bid/src/main/java/cn/hobbystocks/auc/web/DepositOrderController.java

@@ -47,7 +47,6 @@ public class DepositOrderController {
         UserInfo simpleUserInfo = UserUtils.getSimpleUserInfo();
         if (Objects.isNull(simpleUserInfo))
             return AjaxResult.error("请先登录");
-        //todo 判断是否已经缴纳保证金,需要查询订单记录,
         depositOrderDTO.setUserId(simpleUserInfo.getId());
         orderService.createDepositOrder(depositOrderDTO);
         return AjaxResult.success();

+ 6 - 1
lot/src/main/java/cn/hobbystocks/auc/handle/impl/tradition/AbstractTraditionRuleHandler.java

@@ -188,7 +188,12 @@ public abstract class AbstractTraditionRuleHandler implements RuleHandler {
         TraditionLive traditionLive = (TraditionLive) liveContext.getLive();
         BigDecimal price = liveContext.getDbBid().getAmount();
         String currentStatus = getCurrentStatus(traditionLive);
-
+        log.warn("checkAddPrice price:{} currentStartPrice:{} currentOnceAddPrice:{} easyAddPrice:{} lotId:{}",
+            price,
+            traditionLive.getCurrentStartPrice(),
+            traditionLive.getCurrentOnceAddPrice(),
+            traditionLive.getEasyAddPrice(),
+            traditionLive.getLot().getId());
         if (CollectionUtil.newHashSet(Constants.LOT_STATUS_PASS, Constants.LOT_STATUS_SOLD).contains(currentStatus)) {
             log.warn("add price fail {}", liveContext.getDbBid());
             liveContext.setError("拍卖已结束");

+ 4 - 0
lot/src/main/java/cn/hobbystocks/auc/mapper/BidMapper.java

@@ -31,4 +31,8 @@ public interface BidMapper {
     Long countBidInOneHour(Long lotId);
 
     List<Bid> selectBidListLimit(@Param("lotId") Long lotId, @Param("limit") Long limit);
+
+    String selectUserCodeByAuctionAndAccount(@Param("auctionId") Long auctionId, @Param("accountId") String accountId);
+
+    Long selectMaxUserCodeByAuction(@Param("auctionId") Long auctionId);
 }

+ 2 - 0
lot/src/main/java/cn/hobbystocks/auc/service/IBidService.java

@@ -17,6 +17,8 @@ public interface IBidService
 
     void addPriceV3(BidVO bid, Runnable runnable) throws RuntimeException;
 
+    String getOrCreateUserCode(Long auctionId, String accountId);
+
     int updateBid(Bid bid);
 
     int deleteBidByIds(String ids);

+ 0 - 3
lot/src/main/java/cn/hobbystocks/auc/service/SyncService.java

@@ -3,20 +3,17 @@ package cn.hobbystocks.auc.service;
 
 import cn.hobbystocks.auc.common.constant.Constants;
 import cn.hobbystocks.auc.common.core.redis.RedisCache;
-import cn.hobbystocks.auc.domain.Auction;
 import cn.hobbystocks.auc.domain.Bid;
 import cn.hobbystocks.auc.domain.Lot;
 import cn.hobbystocks.auc.domain.LotGroup;
 import cn.hobbystocks.auc.handle.RuleHandlerHolder;
 import cn.hobbystocks.auc.handle.context.LiveContext;
 import cn.hobbystocks.auc.handle.context.tradition.TraditionLive;
-import cn.hobbystocks.auc.mapper.AuctionMapper;
 import cn.hobbystocks.auc.mapper.BidMapper;
 import cn.hobbystocks.auc.mapper.LotMapper;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
-import org.springframework.util.CollectionUtils;
 
 import java.util.List;
 

+ 25 - 8
lot/src/main/java/cn/hobbystocks/auc/service/impl/BidServiceImpl.java

@@ -1,24 +1,24 @@
 package cn.hobbystocks.auc.service.impl;
 
 import cn.hobbystocks.auc.cache.CacheMap;
-import cn.hobbystocks.auc.common.exception.AddPriceException;
-import cn.hobbystocks.auc.common.utils.CloneUtils;
-import cn.hobbystocks.auc.domain.Lot;
-import cn.hobbystocks.auc.event.ChangeEvent;
-import cn.hobbystocks.auc.event.EventPublisher;
-import cn.hobbystocks.auc.handle.context.LiveContext;
-import cn.hobbystocks.auc.handle.context.tradition.TraditionLive;
-import cn.hobbystocks.auc.service.IBidService;
 import cn.hobbystocks.auc.common.constant.Constants;
 import cn.hobbystocks.auc.common.core.redis.Locker;
 import cn.hobbystocks.auc.common.core.redis.RedisCache;
 import cn.hobbystocks.auc.common.core.text.Convert;
+import cn.hobbystocks.auc.common.exception.AddPriceException;
+import cn.hobbystocks.auc.common.utils.CloneUtils;
 import cn.hobbystocks.auc.common.utils.DateUtils;
 import cn.hobbystocks.auc.domain.Bid;
+import cn.hobbystocks.auc.domain.Lot;
+import cn.hobbystocks.auc.event.ChangeEvent;
+import cn.hobbystocks.auc.event.EventPublisher;
 import cn.hobbystocks.auc.handle.RuleHandlerHolder;
 import cn.hobbystocks.auc.handle.context.Live;
+import cn.hobbystocks.auc.handle.context.LiveContext;
+import cn.hobbystocks.auc.handle.context.tradition.TraditionLive;
 import cn.hobbystocks.auc.mapper.BidMapper;
 import cn.hobbystocks.auc.mapper.LotMapper;
+import cn.hobbystocks.auc.service.IBidService;
 import cn.hobbystocks.auc.vo.BidVO;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
@@ -29,6 +29,7 @@ import org.springframework.transaction.annotation.Isolation;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.util.*;
+import java.util.concurrent.atomic.AtomicReference;
 import java.util.stream.Collectors;
 
 @Service
@@ -87,6 +88,7 @@ public class BidServiceImpl implements IBidService
                         lotMapper.updateLot(dbUpdate);
                         List<Bid> bidList = bidMapper.selectBidListLimit(live.getLot().getId(), 20L);
                         redisCache.setList(String.format(Constants.REDIS_MAP_AUC_LOT_BID_TEMPLATE, live.getLot().getId()), bidList);
+                        live.getLot().setProperties(null);
                         redisCache.setCacheMapValue(String.format(Constants.REDIS_MAP_AUC_LOT_TEMPLATE, live.getLot().getAuctionId()), live.getLot().getId().toString(), live);
                         // 这里发送 状态变更消息 其中同步内存中的缓存和发送IM消息给APP
                         eventPublisher.publishChangeEvent(new ChangeEvent(live, null, bidList));
@@ -137,6 +139,21 @@ public class BidServiceImpl implements IBidService
         }, true);
     }
 
+    @Override
+    public String getOrCreateUserCode(Long auctionId, String accountId) {
+        AtomicReference<String> result = new AtomicReference<>();
+        locker.tryLock(String.format("LOCK:AUC:USER_CODE:%s", auctionId), () -> {
+            String userCode = bidMapper.selectUserCodeByAuctionAndAccount(auctionId, accountId);
+            if (StringUtils.isNotEmpty(userCode)) {
+                result.set(userCode);
+                return;
+            }
+            Long maxUserCode = bidMapper.selectMaxUserCodeByAuction(auctionId);
+            result.set(String.valueOf(Objects.isNull(maxUserCode) ? 1L : maxUserCode + 1));
+        }, true, "获取竞买号失败");
+        return result.get();
+    }
+
     private void insertCurrBid(BidVO bid, Long round) {
         bidMapper.clearCurrentBid(bid.getLotId());
         bid.setDelFlag(Constants.DEL_FLAG_NO_DELETE);

+ 24 - 2
lot/src/main/resources/mapper/BidMapper.xml

@@ -99,6 +99,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="status != null">status,</if>
             <if test="avatar !=null">avatar,</if>
             <if test="bidNo !=null">bid_no,</if>
+            <if test="userCode !=null">user_code,</if>
          </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="id != null">#{id},</if>
@@ -120,15 +121,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="status != null">#{status},</if>
             <if test="avatar !=null">#{avatar},</if>
             <if test="bidNo !=null">#{bidNo},</if>
+            <if test="userCode !=null">#{userCode},</if>
          </trim>
     </insert>
     <insert id="batchInsertBid" useGeneratedKeys="true" keyProperty="id">
-        INSERT INTO bid (lot_id,round,account,account_id,amount,device_type,ip,del_flag,create_by,create_time,update_by,update_time,remark,anonymous,curr,status,avatar,bid_no)
+        INSERT INTO bid (lot_id,round,account,account_id,amount,device_type,ip,del_flag,create_by,create_time,update_by,update_time,remark,anonymous,curr,status,avatar,bid_no,user_code)
         values
         <foreach collection="list" item="item" index="index" separator=",">
             (
             #{item.lotId},#{item.round},#{item.account},#{item.accountId},#{item.amount},#{item.deviceType},#{item.ip},#{item.delFlag},#{item.createBy},
-            #{item.createTime},#{item.updateBy},#{item.updateTime},#{item.remark},#{item.anonymous},#{item.curr},#{item.status},#{item.avatar},#{item.bidNo}
+            #{item.createTime},#{item.updateBy},#{item.updateTime},#{item.remark},#{item.anonymous},#{item.curr},#{item.status},#{item.avatar},#{item.bidNo},#{item.userCode}
             )
         </foreach>
     </insert>
@@ -190,6 +192,26 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
           and lot_id = #{lotId}
     </select>
 
+    <select id="selectUserCodeByAuctionAndAccount" resultType="String">
+        select b.user_code
+        from bid b
+        inner join lot l on l.id = b.lot_id
+        where l.auction_id = #{auctionId}
+          and b.account_id = #{accountId}
+          and b.user_code is not null
+          and b.user_code != ''
+        order by b.create_time asc
+        limit 1
+    </select>
+
+    <select id="selectMaxUserCodeByAuction" resultType="Long">
+        select max(cast(b.user_code as bigint))
+        from bid b
+        inner join lot l on l.id = b.lot_id
+        where l.auction_id = #{auctionId}
+          and b.user_code ~ '^[0-9]+$'
+    </select>
+
     <delete id="deleteBidById" parameterType="Long">
         delete from bid where id = #{id}
     </delete>