LotServiceImpl.java 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060
  1. package cn.hobbystocks.auc.service.impl;
  2. import cn.hobbystocks.auc.cache.CacheMap;
  3. import cn.hobbystocks.auc.common.constant.Constants;
  4. import cn.hobbystocks.auc.common.core.redis.Locker;
  5. import cn.hobbystocks.auc.common.core.redis.RedisCache;
  6. import cn.hobbystocks.auc.common.core.text.Convert;
  7. import cn.hobbystocks.auc.common.enums.LotStatusEnum;
  8. import cn.hobbystocks.auc.common.enums.PubStatusEnum;
  9. import cn.hobbystocks.auc.common.enums.RuleTypeEnum;
  10. import cn.hobbystocks.auc.common.exception.ServiceException;
  11. import cn.hobbystocks.auc.common.user.UserInfo;
  12. import cn.hobbystocks.auc.common.user.UserUtils;
  13. import cn.hobbystocks.auc.common.utils.CloneUtils;
  14. import cn.hobbystocks.auc.common.utils.DateUtils;
  15. import cn.hobbystocks.auc.common.utils.PageUtils;
  16. import cn.hobbystocks.auc.common.utils.SensitiveDataUtils;
  17. import cn.hobbystocks.auc.common.utils.StringUtils;
  18. import cn.hobbystocks.auc.convert.LotConvert;
  19. import cn.hobbystocks.auc.domain.*;
  20. import cn.hobbystocks.auc.dto.LotExportDTO;
  21. import cn.hobbystocks.auc.event.ChangeEvent;
  22. import cn.hobbystocks.auc.event.EventPublisher;
  23. import cn.hobbystocks.auc.event.JPushEvent;
  24. import cn.hobbystocks.auc.event.StartBiddingEvent;
  25. import cn.hobbystocks.auc.handle.RuleHandlerHolder;
  26. import cn.hobbystocks.auc.handle.context.Live;
  27. import cn.hobbystocks.auc.handle.context.LiveContext;
  28. import cn.hobbystocks.auc.handle.context.tradition.TraditionRule;
  29. import cn.hobbystocks.auc.mapper.*;
  30. import cn.hobbystocks.auc.request.LotQueryRequest;
  31. import cn.hobbystocks.auc.request.LotRequest;
  32. import cn.hobbystocks.auc.response.LotDetailResponse;
  33. import cn.hobbystocks.auc.response.LotFansResponse;
  34. import cn.hobbystocks.auc.service.ILotService;
  35. import cn.hobbystocks.auc.task.DynamicTaskService;
  36. import cn.hobbystocks.auc.vo.LiveVO;
  37. import cn.hobbystocks.auc.vo.LotVO;
  38. import cn.hobbystocks.auc.vo.SelfVO;
  39. import com.alibaba.fastjson.JSON;
  40. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  41. import com.baomidou.mybatisplus.core.metadata.IPage;
  42. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  43. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  44. import com.google.common.collect.Lists;
  45. import lombok.extern.slf4j.Slf4j;
  46. import org.springframework.beans.BeanUtils;
  47. import org.springframework.beans.factory.annotation.Autowired;
  48. import org.springframework.stereotype.Service;
  49. import org.springframework.transaction.annotation.Isolation;
  50. import org.springframework.transaction.annotation.Transactional;
  51. import org.springframework.util.CollectionUtils;
  52. import java.math.BigDecimal;
  53. import java.util.*;
  54. import java.util.concurrent.TimeUnit;
  55. import java.util.concurrent.atomic.AtomicLong;
  56. import java.util.regex.Matcher;
  57. import java.util.regex.Pattern;
  58. import java.util.stream.Collectors;
  59. @Service
  60. @Slf4j
  61. public class LotServiceImpl extends ServiceImpl<LotMapper,Lot> implements ILotService
  62. {
  63. @Autowired
  64. private LotMapper lotMapper;
  65. @Autowired
  66. private BidMapper bidMapper;
  67. @Autowired
  68. private Locker locker;
  69. @Autowired
  70. private RuleHandlerHolder ruleHandlerHolder;
  71. @Autowired
  72. private RedisCache redisCache;
  73. @Autowired
  74. private AuctionMapper auctionMapper;
  75. @Autowired
  76. public EventPublisher eventPublisher;
  77. @Autowired(required = false)
  78. private CacheMap cacheMap;
  79. @Autowired
  80. private DynamicTaskService dynamicTaskService;
  81. @Autowired
  82. private LotServiceImpl _thiz;
  83. @Autowired
  84. private LotGroupMapper lotGroupMapper;
  85. @Autowired
  86. private LotFansMapper lotFansMapper;
  87. @Autowired
  88. private SpuCategoryMapper spuCategoryMapper;
  89. @Autowired
  90. private DepositOrderMapper depositOrderMapper;
  91. @Override
  92. public Lot selectLotById(Long id) {
  93. return lotMapper.selectLotById(id);
  94. }
  95. @Override
  96. public LotGroup selectLotGroupById(Long id) {
  97. return lotGroupMapper.selectLotGroupById(id);
  98. }
  99. @Override
  100. public List<Lot> selectLotList(Lot lot) {
  101. IPage<Lot> lotIPage=new Page<>(lot.getPageNum(),lot.getPageSize());
  102. return lotMapper.selectLotList(lotIPage,lot);
  103. }
  104. @Override
  105. public List<Lot> selectBiddingLotByAucId(Long aucId) {
  106. return lotMapper.selectNotEndLotList(aucId);
  107. }
  108. @Override
  109. public List<Lot> selectLotByGroupIds(Long[] groupIds) {
  110. return null;
  111. }
  112. @Override
  113. public List<LotGroup> selectLotGroupList(LotGroup lotGroup) {
  114. return lotGroupMapper.selectLotGroupList(lotGroup);
  115. }
  116. @Override
  117. public void cancelLotGroup(Long id) {
  118. LotGroup dbLotGroup = lotGroupMapper.selectLotGroupById(id);
  119. dbLotGroup.setStatus(Constants.GROUP_STATUS_WAITING);
  120. dbLotGroup.setPubStatus(Constants.PUB_STATUS_NO_PUBLISHED);
  121. lotGroupMapper.updateLotGroup(dbLotGroup);
  122. }
  123. @Override
  124. public List<Lot> selectLotByGroupId(Long id) {
  125. return lotMapper.selectLotByGroupId(id);
  126. }
  127. @Override
  128. public List<LotGroup> canCreateLive(Long merchantId) {
  129. return lotGroupMapper.canCreateLive(merchantId);
  130. }
  131. @Override
  132. public List<LotGroup> findPubbedLotGroupByIds(Long[] lotGroupIds,Long merchantId) {
  133. return lotGroupMapper.findPubbedLotGroupByLotIds(lotGroupIds,merchantId);
  134. }
  135. @Override
  136. @Transactional(isolation = Isolation.READ_COMMITTED, rollbackFor = Exception.class)
  137. public Long party(LotGroup lotGroup) {
  138. AtomicLong result = new AtomicLong(0);
  139. locker.tryLock(String.format(Constants.REDIS_GROUP_LOCK_LOT_TEMPLATE, lotGroup.getId()), () -> {
  140. LotGroup dbLotGroup = lotGroupMapper.selectLotGroupById(lotGroup.getId());
  141. Lot currLot = lotMapper.selectLotById(dbLotGroup.getNextLotId());
  142. Lot nextLot = new Lot();
  143. BeanUtils.copyProperties(dbLotGroup, nextLot, "id");
  144. nextLot.setStatus(Constants.LOT_STATUS_WAITING);
  145. nextLot.setStartTime(null);
  146. nextLot.setCreateTime(new Date());
  147. nextLot.setUpdateTime(null);
  148. nextLot.setPubTime(new Date());
  149. nextLot.setPubStatus(Constants.PUB_STATUS_PUBLISHED);
  150. nextLot.setGroupId(lotGroup.getId());
  151. nextLot.setAuctionId(2L);
  152. String name = currLot.getName();
  153. int i = name.lastIndexOf("#");
  154. if (i > 0 && i != name.length() -1) {
  155. String numStr = name.substring(i + 1);
  156. String nextNum = "";
  157. try {
  158. long l = Long.parseLong(numStr);
  159. nextNum = "#" + (l + 1);
  160. }catch (Exception ignored) {}
  161. nextLot.setName(nextLot.getName() + nextNum);
  162. }
  163. lotMapper.updateLot(
  164. Lot.builder()
  165. .id(currLot.getId())
  166. .startTime(new Date())
  167. .build());
  168. currLot.setStartTime(new Date());
  169. long l = Objects.isNull(dbLotGroup.getFinishNum()) ? 0 : dbLotGroup.getFinishNum();
  170. if (l >= dbLotGroup.getNum()) {
  171. throw new RuntimeException("商品库存已经用完");
  172. }else if (l<dbLotGroup.getNum()-1){
  173. lotMapper.insertLot(nextLot);
  174. }
  175. lotGroupMapper.updateLotGroup(LotGroup.builder()
  176. .id(lotGroup.getId())
  177. .lotId(currLot.getId())
  178. .nextLotId(nextLot.getId())
  179. .finishNum(Objects.isNull(dbLotGroup.getFinishNum()) ? 0 : dbLotGroup.getFinishNum() + 1)
  180. .status(Constants.LOT_STATUS_STARTING)
  181. .build()
  182. );
  183. pubLot(currLot);
  184. result.set(currLot.getId());
  185. eventPublisher.publishStartBiddingEvent(new StartBiddingEvent(dbLotGroup.getId()));
  186. }, true, "开启失败,请重试!");
  187. return result.get();
  188. }
  189. @Override
  190. public List<LotGroup> findStartingGroupByLotIds(Long[] lotIds) {
  191. return lotGroupMapper.findStartingGroupByIds(lotIds);
  192. }
  193. @Override
  194. @Transactional(isolation = Isolation.READ_COMMITTED, rollbackFor = Exception.class)
  195. public void updateExpire(LotFans fans) {
  196. lotFansMapper.updateLotFans(
  197. LotFans.builder()
  198. .id(fans.getId())
  199. .type("pay_expire")
  200. .expire(DateUtils.addDays(DateUtils.toDate(fans.getCreateTime()), 1))
  201. .build());
  202. lotMapper.updateLot(Lot.builder().id(fans.getLotId()).status(Constants.LOT_STATUS_PASS).build());
  203. }
  204. @Override
  205. @Transactional(isolation = Isolation.READ_COMMITTED, rollbackFor = Exception.class)
  206. public void updateSoldAndPaid(LotFans fans, Long groupId) {
  207. lotFansMapper.deleteLotFansById(fans.getId());
  208. lotMapper.updatePay(fans.getLotId(), 1);
  209. lotGroupMapper.addSold(groupId);
  210. }
  211. @Override
  212. @Transactional(isolation = Isolation.READ_COMMITTED, rollbackFor = Exception.class)
  213. public void handleEndLotGroup(LotGroup lotGroup, String status) {
  214. LotGroup dbLotGroup = lotGroupMapper.selectLotGroupById(lotGroup.getId());
  215. lotGroupMapper.updateLotGroupSold(dbLotGroup.getId());
  216. }
  217. @Override
  218. @Transactional(isolation = Isolation.READ_COMMITTED, rollbackFor = Exception.class)
  219. public int insertLot(Lot lot) {
  220. lot.setCreateTime(DateUtils.getNowDate());
  221. int result = lotMapper.insertLot(lot);
  222. dynamicTask(lot);
  223. return result;
  224. }
  225. @Override
  226. @Transactional(isolation = Isolation.READ_COMMITTED, rollbackFor = Exception.class)
  227. public int insertLotGroup(LotGroup lotGroup) {
  228. final int i = lotGroupMapper.insertLotGroup(lotGroup);
  229. Lot lot = new Lot();
  230. BeanUtils.copyProperties(lotGroup, lot, "id");
  231. lot.setStatus(Constants.LOT_STATUS_WAITING);
  232. lot.setStartTime(null);
  233. lot.setCreateTime(new Date());
  234. lot.setUpdateTime(null);
  235. lot.setPubTime(new Date());
  236. lot.setPubStatus(Constants.PUB_STATUS_PUBLISHED);
  237. lot.setGroupId(lotGroup.getId());
  238. lot.setNum(1L);
  239. lot.setName(lot.getName() + "#1");
  240. lotMapper.insertLot(lot);
  241. lotGroupMapper.updateLotGroup(LotGroup.builder().id(lotGroup.getId()).nextLotId(lot.getId()).build());
  242. return i;
  243. }
  244. @Override
  245. public int updateLot(Lot lot) {
  246. lot.setUpdateTime(DateUtils.getNowDate());
  247. return lotMapper.updateLot(lot);
  248. }
  249. @Override
  250. @Transactional(isolation = Isolation.READ_COMMITTED, rollbackFor = Exception.class)
  251. public int updateLotGroup(LotGroup lotGroup) {
  252. LotGroup dbLotGroup = lotGroupMapper.selectLotGroupById(lotGroup.getId());
  253. if (Objects.nonNull(lotGroup.getNum()) && dbLotGroup.getNum() > lotGroup.getNum()) {
  254. int count = lotMapper.selectLotByGroupId(lotGroup.getId()).size() - 1;
  255. if (count > lotGroup.getNum()) {
  256. throw new RuntimeException("数量不合法");
  257. }
  258. }
  259. lotGroup.setUpdateTime(DateUtils.getNowDate());
  260. int result = lotGroupMapper.updateLotGroup(lotGroup);
  261. dbLotGroup = lotGroupMapper.selectLotGroupById(lotGroup.getId());
  262. Lot lot = lotMapper.selectLotById(dbLotGroup.getNextLotId());
  263. if (Constants.LOT_STATUS_WAITING.equals(lot.getStatus())) {
  264. String name = lot.getName();
  265. String nextNum = "";
  266. int i = name.lastIndexOf("#");
  267. if (i > 0 && i != name.length() -1) {
  268. String numStr = name.substring(i + 1);
  269. try {
  270. long l = Long.parseLong(numStr);
  271. nextNum = "#" + l;
  272. }catch (Exception ignored) {}
  273. }
  274. BeanUtils.copyProperties(dbLotGroup, lot, "id","createTime", "name");
  275. lot.setStatus(Constants.LOT_STATUS_WAITING);
  276. lot.setStartTime(null);
  277. lot.setPubTime(new Date());
  278. lot.setPubStatus(Constants.PUB_STATUS_PUBLISHED);
  279. lot.setGroupId(lotGroup.getId());
  280. lot.setName(dbLotGroup.getName() + nextNum);
  281. updateLot(lot);
  282. }
  283. return result;
  284. }
  285. @Override
  286. @Transactional(isolation = Isolation.READ_COMMITTED, rollbackFor = Exception.class)
  287. public int updateLotGroup0(LotGroup lotGroup) {
  288. return lotGroupMapper.updateLotGroup(lotGroup);
  289. }
  290. @Override
  291. public int updateLotView(Lot lot) {
  292. lot.setUpdateTime(DateUtils.getNowDate());
  293. int result = lotMapper.updateLotView(lot);
  294. dynamicTask(lot);
  295. return result;
  296. }
  297. @Override
  298. @Transactional(isolation = Isolation.READ_COMMITTED, rollbackFor = Exception.class)
  299. public int updateLotEx(Lot lot) {
  300. lot.setUpdateTime(DateUtils.getNowDate());
  301. int result = lotMapper.updateLotEx(lot);
  302. dynamicTask(lot);
  303. return result;
  304. }
  305. @Override
  306. public List<Lot> selectBidding() {
  307. return lotMapper.selectBidding();
  308. }
  309. @Override
  310. public List<Lot> selectCancel() {
  311. return lotMapper.selectCancel();
  312. }
  313. @Override
  314. public int deleteLotByIds(String ids) {
  315. return lotMapper.deleteLotByIds(Convert.toLongArray(ids));
  316. }
  317. @Override
  318. public int deleteLotById(Long id) {
  319. return lotMapper.deleteLotById(id);
  320. }
  321. @Override
  322. @Transactional(isolation = Isolation.READ_COMMITTED, rollbackFor = Exception.class)
  323. public void pubLot(Lot lot) {
  324. locker.tryLock(String.format(Constants.REDIS_LOCK_LOT_TEMPLATE, lot.getId()), () ->{
  325. lot.setPubTime(new Date());
  326. lot.setPubStatus(Constants.PUB_STATUS_PUBLISHED);
  327. lot.setUpdateTime(new Date());
  328. lotMapper.updateLot(lot);
  329. //构建竞价拍卖上下文
  330. LiveContext liveContext = ruleHandlerHolder.pubLive(lot);
  331. if (liveContext.isLotUpdate()) {
  332. lotMapper.updateLot(lot);
  333. }
  334. redisCache.setCacheMapValue(String.format(Constants.REDIS_MAP_AUC_LOT_TEMPLATE, lot.getAuctionId()), lot.getId().toString(), liveContext.getLive());
  335. // 保存拍品分类关联
  336. saveLotCategoryRelation(lot);
  337. }, true);
  338. }
  339. private void saveLotCategoryRelation(Lot lot) {
  340. List<String> names = new ArrayList<>();
  341. if (StringUtils.isNotEmpty(lot.getCategory())) {
  342. names.add(lot.getCategory());
  343. }
  344. if (StringUtils.isNotEmpty(lot.getSubCategory())) {
  345. names.add(lot.getSubCategory());
  346. }
  347. if (!names.isEmpty()) {
  348. List<Long> categoryIds = spuCategoryMapper.selectCategoryIdsByNames(names);
  349. if (!CollectionUtils.isEmpty(categoryIds)) {
  350. spuCategoryMapper.deleteLotCategoryRelation(lot.getId());
  351. spuCategoryMapper.insertLotCategoryRelation(lot.getId(), categoryIds);
  352. }
  353. }
  354. }
  355. @Override
  356. @Transactional(isolation = Isolation.READ_COMMITTED, rollbackFor = Exception.class)
  357. public void pubLots(Auction auction) {
  358. List<Lot> lots = lotMapper.selectLotByAucId(auction.getId());
  359. for (Lot lot : lots) {
  360. lot.setUpdateBy(auction.getUpdateBy());
  361. pubLot(lot);
  362. }
  363. }
  364. @Override
  365. @Transactional(isolation = Isolation.READ_COMMITTED, rollbackFor = Exception.class)
  366. public void insertLotAndPub(Lot lot) {
  367. insertLot(lot);
  368. pubLot(lot);
  369. }
  370. @Override
  371. @Transactional(isolation = Isolation.READ_COMMITTED, rollbackFor = Exception.class)
  372. public void updateLotAndPub(Lot lot) {
  373. updateLot(lot);
  374. pubLot(lot);
  375. }
  376. @Override
  377. public void removeLot(Lot lot) {
  378. Lot condition = new Lot();
  379. condition.setId(lot.getId());
  380. condition.setDelFlag(Constants.DEL_FLAG_DELETED);
  381. lotMapper.updateLot(condition);
  382. }
  383. @Override
  384. public void cancelLot(Lot lot) {
  385. lot.setUpdateTime(new Date());
  386. lot.setStatus(Constants.LOT_STATUS_CANCELLED);
  387. lot.setPubStatus(Constants.PUB_STATUS_NO_PUBLISHED);
  388. lotMapper.updateLot(lot);
  389. ruleHandlerHolder.cancelLot(lot);
  390. }
  391. @Override
  392. @Transactional(isolation = Isolation.READ_COMMITTED, rollbackFor = Exception.class)
  393. public void live(Live live) {
  394. live = redisCache.getCacheMapValue(String.format(Constants.REDIS_MAP_AUC_LOT_TEMPLATE, live.getLot().getAuctionId()), live.getLot().getId().toString());
  395. // 1秒的轮询 会存在失效数据 判断是否是失效数据
  396. if (Objects.isNull(live)) {
  397. //是失效数据
  398. return;
  399. }
  400. cacheMap.putLive(live);
  401. List<Bid> bidList = redisCache.getCacheList(String.format(Constants.REDIS_MAP_AUC_LOT_BID_TEMPLATE, live.getLot().getId()));
  402. // 创建当前 context
  403. LiveContext liveContext = LiveContext.builder()
  404. .live(live)
  405. .dbLot(Lot.builder()
  406. .id(live.getLot().getId())
  407. .auctionId(live.getLot().getAuctionId())
  408. .build())
  409. .bidList(bidList)
  410. .dbBid(getLastBid(bidList))
  411. .build();
  412. // 分析并设置当前状态
  413. ruleHandlerHolder.live(liveContext);
  414. // 更新当前状态 到数据库和缓存
  415. updateToRedisAndDb(liveContext);
  416. // 发送极光推送
  417. jPush(liveContext);
  418. }
  419. private void jPush(LiveContext liveContext) {
  420. Live live = liveContext.getLive();
  421. if (live.getCurrentEndTime() < (System.currentTimeMillis() + 1000 * 60 * 5)) {
  422. Long expire = redisCache.redisTemplate.getExpire(String.format(Constants.REDIS_LOCK_PUSH_LOT_TEMPLATE, live.getLot().getId()));
  423. if (Objects.isNull(expire) || expire < 0L) {
  424. eventPublisher.publishJPush(JPushEvent.builder().live(live).build());
  425. redisCache.setCacheObject(String.format(Constants.REDIS_LOCK_PUSH_LOT_TEMPLATE, live.getLot().getId()), "jPush", 10, TimeUnit.MINUTES);
  426. }
  427. }
  428. }
  429. private Bid getLastBid(List<Bid> bidList) {
  430. if (!CollectionUtils.isEmpty(bidList)) {
  431. return bidList.get(0);
  432. }
  433. return null;
  434. }
  435. private void updateToRedisAndDb(LiveContext liveContext) {
  436. Live live = liveContext.getLive();
  437. List<Bid> dataList = liveContext.getBidList();
  438. ChangeEvent changeEvent = new ChangeEvent(live);
  439. if (liveContext.isLotUpdate()) {
  440. liveContext.getDbLot().setUpdateTime(new Date());
  441. lotMapper.updateLot(liveContext.getDbLot());
  442. }
  443. if (liveContext.isBidUpdate()) {
  444. bidMapper.updateBid(liveContext.getDbBid());
  445. redisCache.setList(String.format(Constants.REDIS_MAP_AUC_LOT_BID_TEMPLATE, live.getLot().getId()), dataList);
  446. changeEvent.setBid(liveContext.getDbBid());
  447. }
  448. Lot lot = live.getLot();
  449. lot.setProperties(null);
  450. if (liveContext.isLiveUpdate()) {
  451. if (Constants.LOT_STATUS_SOLD.equals(live.getLot().getStatus()) ||
  452. Constants.LOT_STATUS_PASS.equals(live.getLot().getStatus())) {
  453. redisCache.delCacheMapValue(String.format(Constants.REDIS_MAP_AUC_LOT_TEMPLATE, live.getLot().getAuctionId()), live.getLot().getId().toString());
  454. redisCache.deleteObject(String.format(Constants.REDIS_MAP_AUC_LOT_BID_TEMPLATE, live.getLot().getId()));
  455. if (Constants.LOT_STATUS_SOLD.equals(live.getLot().getStatus())) {
  456. if(live.getBidId()==null){
  457. long bidid = bidMapper.getCurrentBid(live.getLot().getId());
  458. live.setBidId(bidid);
  459. }
  460. eventPublisher.publishSoldEvent(live, dataList);
  461. }
  462. eventPublisher.publishEndEvent(live);
  463. }else {
  464. redisCache.setCacheMapValue(String.format(Constants.REDIS_MAP_AUC_LOT_TEMPLATE, live.getLot().getAuctionId()), live.getLot().getId().toString(), live);
  465. }
  466. eventPublisher.publishChangeEvent(changeEvent);
  467. }
  468. }
  469. @Override
  470. public List<Lot> live(Long auctionId) {
  471. LambdaQueryWrapper<Lot> queryWrapper=new LambdaQueryWrapper<>();
  472. queryWrapper.eq(Lot::getAuctionId,auctionId).eq(Lot::getDelFlag,Constants.DEL_FLAG_NO_DELETE);
  473. return lotMapper.selectList(queryWrapper);
  474. }
  475. @Override
  476. public List<LiveVO> selfLive(SelfVO selfVO) {
  477. UserInfo userInfo = UserUtils.getSimpleUserInfo();
  478. if (userInfo == null) {
  479. throw new ServiceException("璇峰厛鐧诲綍");
  480. }
  481. List<DepositOrder> depositOrders = selectPaidDepositOrders(userInfo.getId());
  482. List<Bid> userBidList = bidMapper.selectBidList(Bid.builder()
  483. .accountId(userInfo.getId().toString())
  484. .build());
  485. List<Lot> candidateLots = selectSelfCandidateLots(depositOrders, userBidList.stream()
  486. .map(Bid::getLotId)
  487. .filter(Objects::nonNull)
  488. .collect(Collectors.toSet()));
  489. Map<String, Live> cacheLive = new HashMap<>();
  490. candidateLots.stream()
  491. .map(Lot::getAuctionId)
  492. .filter(Objects::nonNull)
  493. .distinct()
  494. .forEach(auctionId -> {
  495. Map<String, Live> auctionLive = CloneUtils.clone(cacheMap.viewAuction(auctionId));
  496. if (!CollectionUtils.isEmpty(auctionLive)) {
  497. cacheLive.putAll(auctionLive);
  498. }
  499. });
  500. return cacheLive.values().stream()
  501. .filter(live -> live.getAccountList().contains(UserUtils.getSimpleUserInfo().getId().toString()) &&
  502. Constants.LOT_STATUS_BIDDING.equals(live.getLot().getStatus()))
  503. .map(live -> {
  504. List<Bid> bidList = bidMapper.selectBidByLotId(live.getLot().getId());
  505. LiveVO liveVO = new LiveVO(live);
  506. if (!CollectionUtils.isEmpty(bidList)) {
  507. liveVO.setLastPriceTime(bidList.get(0).getCreateTime().getTime());
  508. }
  509. liveVO.setCurrUserBids(
  510. Objects.requireNonNull(bidList).stream()
  511. .filter(bid -> bid.getAccountId().equals(UserUtils.getSimpleUserInfo().getId().toString()))
  512. .collect(Collectors.toList())
  513. );
  514. return SensitiveDataUtils.handleViewDataSafe(liveVO);
  515. }).sorted(this::sort)
  516. .collect(Collectors.toList());
  517. }
  518. private int sort(LiveVO live1, LiveVO live2) {
  519. return (int)(live2.getLastPriceTime() - live1.getLastPriceTime());
  520. }
  521. @Override
  522. public List<LotVO> selfFinish(SelfVO selfVO) {
  523. return finishOrWin(null);
  524. }
  525. @Override
  526. public List<LotVO> selfWin(SelfVO selfVO) {
  527. return finishOrWin(1);
  528. }
  529. @Override
  530. public List<LotVO> selfList(SelfVO selfVO) {
  531. UserInfo userInfo = UserUtils.getSimpleUserInfo();
  532. if (userInfo == null) {
  533. throw new ServiceException("请先登录");
  534. }
  535. String userId = userInfo.getId().toString();
  536. List<DepositOrder> depositOrders = selectPaidDepositOrders(userInfo.getId());
  537. List<Bid> userBidList = bidMapper.selectBidList(Bid.builder()
  538. .accountId(userId)
  539. .build());
  540. Map<Long, List<Bid>> userBidMap = userBidList.stream()
  541. .filter(bid -> Objects.nonNull(bid.getLotId()))
  542. .collect(Collectors.groupingBy(Bid::getLotId));
  543. List<Lot> lotList = selectSelfCandidateLots(depositOrders, userBidMap.keySet());
  544. String type = StringUtils.isEmpty(selfVO.getType()) ? "all" : selfVO.getType();
  545. List<LotVO> result = new ArrayList<>();
  546. for (Lot lot : lotList) {
  547. List<Bid> userBids = userBidMap.getOrDefault(lot.getId(), Collections.emptyList());
  548. boolean hasUserBid = !CollectionUtils.isEmpty(userBids);
  549. boolean hasWinBid = hasUserBid && userBids.stream().anyMatch(bid -> Objects.equals(bid.getStatus(), 1));
  550. boolean hasDeposit = hasDepositQualification(lot, depositOrders);
  551. String selfStatus = resolveSelfStatus(lot, hasDeposit, hasUserBid, hasWinBid);
  552. if (matchSelfScene(type, selfStatus)) {
  553. result.add(buildSelfLotVo(lot, userBids, selfStatus));
  554. }
  555. }
  556. sortSelfLots(type, result);
  557. return result;
  558. }
  559. private List<DepositOrder> selectPaidDepositOrders(Integer userId) {
  560. return depositOrderMapper.selectList(new LambdaQueryWrapper<DepositOrder>()
  561. .eq(DepositOrder::getUserId, userId)
  562. .eq(DepositOrder::getStatus, 1));
  563. }
  564. private List<Lot> selectSelfCandidateLots(List<DepositOrder> depositOrders, Collection<Long> bidLotIds) {
  565. Map<Long, Lot> lotMap = new LinkedHashMap<>();
  566. if (!CollectionUtils.isEmpty(depositOrders)) {
  567. depositOrders.stream()
  568. .map(DepositOrder::getAuctionId)
  569. .filter(Objects::nonNull)
  570. .distinct()
  571. .forEach(auctionId -> addLots(lotMap, lotMapper.selectLotByAucId(auctionId)));
  572. }
  573. Set<Long> lotIds = new LinkedHashSet<>();
  574. if (!CollectionUtils.isEmpty(bidLotIds)) {
  575. lotIds.addAll(bidLotIds);
  576. }
  577. if (!CollectionUtils.isEmpty(depositOrders)) {
  578. depositOrders.stream()
  579. .map(DepositOrder::getLotId)
  580. .filter(Objects::nonNull)
  581. .forEach(lotIds::add);
  582. }
  583. if (!CollectionUtils.isEmpty(lotIds)) {
  584. addLots(lotMap, lotMapper.selectLotListByLotIds(new ArrayList<>(lotIds)));
  585. }
  586. return new ArrayList<>(lotMap.values());
  587. }
  588. private void addLots(Map<Long, Lot> lotMap, List<Lot> lots) {
  589. if (CollectionUtils.isEmpty(lots)) {
  590. return;
  591. }
  592. lots.stream()
  593. .filter(lot -> Objects.nonNull(lot.getId()))
  594. .forEach(lot -> lotMap.put(lot.getId(), lot));
  595. }
  596. private boolean hasDepositQualification(Lot lot, List<DepositOrder> depositOrders) {
  597. if (CollectionUtils.isEmpty(depositOrders)) {
  598. return false;
  599. }
  600. if (Objects.nonNull(lot.getDeposit())) {
  601. return depositOrders.stream().anyMatch(order -> Objects.equals("拍品", order.getDepositType())
  602. && Objects.equals(order.getLotId(), lot.getId()));
  603. }
  604. return depositOrders.stream().anyMatch(order -> Objects.equals("拍卖会", order.getDepositType())
  605. && Objects.equals(order.getAuctionId(), lot.getAuctionId()));
  606. }
  607. private String resolveSelfStatus(Lot lot, boolean hasDeposit, boolean hasUserBid, boolean hasWinBid) {
  608. if (isWaitingLot(lot, hasDeposit)) {
  609. return "waiting";
  610. }
  611. if (isLiveLot(lot, hasDeposit, hasUserBid)) {
  612. return "live";
  613. }
  614. if (isWinLot(lot, hasWinBid)) {
  615. return "win";
  616. }
  617. if (isLoseLot(lot, hasUserBid, hasWinBid)) {
  618. return "lose";
  619. }
  620. return null;
  621. }
  622. private boolean matchSelfScene(String type, String selfStatus) {
  623. if (StringUtils.isEmpty(selfStatus)) {
  624. return false;
  625. }
  626. if ("all".equals(type)) {
  627. return true;
  628. }
  629. if ("lose".equals(type) || "pass".equals(type) || "finish".equals(type)) {
  630. return "lose".equals(selfStatus);
  631. }
  632. if ("win".equals(type)) {
  633. return "win".equals(selfStatus);
  634. }
  635. return type.equals(selfStatus);
  636. }
  637. private boolean isWaitingLot(Lot lot, boolean hasDeposit) {
  638. return Constants.LOT_STATUS_WAITING.equals(lot.getStatus()) && hasDeposit;
  639. }
  640. private boolean isLiveLot(Lot lot, boolean hasDeposit, boolean hasUserBid) {
  641. return (Constants.LOT_STATUS_STARTING.equals(lot.getStatus()) || Constants.LOT_STATUS_BIDDING.equals(lot.getStatus()))
  642. && (hasDeposit || hasUserBid);
  643. }
  644. private boolean isWinLot(Lot lot, boolean hasWinBid) {
  645. return Constants.LOT_STATUS_SOLD.equals(lot.getStatus()) && hasWinBid;
  646. }
  647. private boolean isLoseLot(Lot lot, boolean hasUserBid, boolean hasWinBid) {
  648. if (!hasUserBid) {
  649. return false;
  650. }
  651. if (Constants.LOT_STATUS_PASS.equals(lot.getStatus())) {
  652. return true;
  653. }
  654. return Constants.LOT_STATUS_SOLD.equals(lot.getStatus()) && !hasWinBid;
  655. }
  656. private LotVO buildSelfLotVo(Lot lot, List<Bid> userBids, String selfStatus) {
  657. LotVO lotVO = new LotVO();
  658. BeanUtils.copyProperties(lot, lotVO);
  659. lotVO.setBids(userBids);
  660. TraditionRule rule = StringUtils.isEmpty(lot.getRuleContent())
  661. ? null
  662. : JSON.parseObject(lot.getRuleContent(), TraditionRule.class);
  663. lotVO.setStartPrice(Objects.isNull(rule) ? null : rule.getStartPrice());
  664. lotVO.setCurrentPrice(Objects.nonNull(lot.getLastPrice()) ? lot.getLastPrice() : null);
  665. lotVO.setSelfStatus(selfStatus);
  666. return SensitiveDataUtils.handleViewDataSafe(lotVO);
  667. }
  668. private void sortSelfLots(String type, List<LotVO> lots) {
  669. lots.sort(Comparator.comparing(Lot::getCreateTime, Comparator.nullsLast(Comparator.reverseOrder())));
  670. }
  671. private List<LotVO> finishOrWin(Integer win) {
  672. String account = UserUtils.getSimpleUserInfo().getId().toString();
  673. List<LotVO> resultList = new ArrayList<>();
  674. List<Lot> lotList = lotMapper.selectLotFinishOrWin(win, account);
  675. lotList.forEach(lot -> {
  676. if (Constants.LOT_STATUS_PASS.equals(lot.getStatus()) || Constants.LOT_STATUS_SOLD.equals(lot.getStatus())) {
  677. Bid condition = new Bid();
  678. condition.setLotId(lot.getId());
  679. condition.setAccountId(account);
  680. condition.setStatus(win);
  681. List<Bid> bids = bidMapper.selectBidList(condition);
  682. if (!CollectionUtils.isEmpty(bids)) {
  683. LotVO lotVO = new LotVO();
  684. BeanUtils.copyProperties(lot, lotVO);
  685. lotVO.setBids(bids);
  686. resultList.add(SensitiveDataUtils.handleViewDataSafe(lotVO));
  687. }
  688. }
  689. });
  690. return resultList;
  691. }
  692. @Override
  693. @Transactional(isolation = Isolation.READ_COMMITTED, rollbackFor = Exception.class)
  694. public void handleDelay(Long id) {
  695. Lot dbLot = lotMapper.selectLotById(id);
  696. Lot update = new Lot();
  697. BeanUtils.copyProperties(dbLot, update);
  698. update.setCreateBy("SYSTEM");
  699. update.setCreateTime(new Date());
  700. update.setPubStatus(Constants.PUB_STATUS_NO_PUBLISHED);
  701. update.setStatus(Constants.LOT_STATUS_WAITING);
  702. update.setDelFlag(Constants.DEL_FLAG_NO_DELETE);
  703. update.setStartTime(DateUtils.addDays(dbLot.getStartTime(), 1));
  704. update.setEndTime(DateUtils.addDays(dbLot.getEndTime(), 1));
  705. String name = update.getName();
  706. if (!StringUtils.isEmpty(name)) {
  707. Pattern pattern = Pattern.compile("第(\\d+)期");
  708. Matcher matcher = pattern.matcher(name);
  709. if (matcher.find()) {
  710. String group = matcher.group(0);
  711. String noStr = matcher.group(1);
  712. int no = (Integer.parseInt(noStr)) + 1;
  713. name = name.replace(group, "第" + no + "期");
  714. update.setName(name);
  715. }
  716. }
  717. lotMapper.insertLotClone(update);
  718. dbLot.setDelayPublish(null);
  719. lotMapper.updateLotView(dbLot);
  720. if (!Objects.equals(dbLot.getPubStatus(), Constants.PUB_STATUS_PUBLISHED)) {
  721. pubLot(dbLot);
  722. }
  723. dynamicTask(update);
  724. }
  725. @Override
  726. public void dynamicTasks() {
  727. lotMapper.dynamicLot().forEach(this::dynamicTask);
  728. }
  729. @Override
  730. public void dynamicTask(Lot lot) {
  731. //延时发布时间
  732. String delayPublish = lot.getDelayPublish();
  733. if (!StringUtils.isEmpty(delayPublish)) {
  734. dynamicTaskService.updateTask(lot.getId().toString(), DateUtils.getNextExecutionTime(delayPublish), () -> {
  735. _thiz.handleDelay(lot.getId());
  736. });
  737. }else {
  738. dynamicTaskService.removeTask(lot.getId().toString());
  739. }
  740. }
  741. @Override
  742. public List<Lot> selectLotListByAucId(Long aucId) {
  743. return getBaseMapper().selectLotByAucId(aucId);
  744. }
  745. @Override
  746. public void calculatorAndUpdateLotHot() {
  747. //查询正在竞价中的拍品
  748. List<Lot> lots = lotMapper.selectBidding();
  749. lots.forEach(lot -> {
  750. //计算出价权重
  751. double bidWeight = lot.getBidCount() * 0.5;
  752. //计算收藏权重
  753. LambdaQueryWrapper<LotFans> lotFansLambdaQueryWrapper = new LambdaQueryWrapper<>();
  754. Long lotFansCount = lotFansMapper.selectCount(lotFansLambdaQueryWrapper.eq(LotFans::getLotId, lot.getId()));
  755. double lotFansWeight = lotFansCount * 0.2;
  756. //计算时间权重,竞拍结束时间-当前时间=剩余时间
  757. Date endTime = lot.getEndTime();
  758. int timeWeight;
  759. Date date = new Date();
  760. Date date1 = DateUtils.addHours(date, 2);
  761. if (date1.after(endTime)){
  762. }
  763. //计算涨价幅度权重
  764. Long currentBid = bidMapper.getCurrentBid(lot.getId());
  765. });
  766. }
  767. @Override
  768. public List<Lot> selectBiddingLotList() {
  769. return getBaseMapper().selectBiddingLotList();
  770. }
  771. @Override
  772. public List<LotFansResponse> queryLotByCategory(LotQueryRequest request) {
  773. // 1. 构建最终要查询的分类ID
  774. List<Long> categoryIds = Lists.newArrayList();
  775. if (Objects.nonNull(request.getChildCategoryId())) {
  776. // 传了二级分类 → 直接用
  777. categoryIds.add(request.getChildCategoryId());
  778. } else if (Objects.nonNull(request.getMainCategoryId())) {
  779. // 只传一级 → 查询该一级下所有二级ID
  780. categoryIds = spuCategoryMapper.listChildByParentId(request.getMainCategoryId());
  781. }
  782. IPage<Lot> lotIPage =new Page<>(request.getPageNum(),request.getPageSize());
  783. Lot lot = new Lot();
  784. if (!CollectionUtils.isEmpty(categoryIds)) {
  785. // 3. 查询拍品ID
  786. List<Long> lotIds = spuCategoryMapper.listLotIdsByCategoryIds(categoryIds);
  787. if (CollectionUtils.isEmpty(lotIds)) {
  788. return emptyLotFansResponsePage(request);
  789. }
  790. lot.setIds(lotIds);
  791. }
  792. lot.setName(request.getName());
  793. lot.setPubStatus(request.getPubStatus());
  794. lot.setStatus(request.getStatus());
  795. lot.setStartTime(request.getStartTime());
  796. lot.setEndTime(request.getEndTime());
  797. lot.setRealEndTime(request.getRealEndTime());
  798. PageUtils.startPage(request);
  799. List<Lot> diamondPositions = baseMapper.selectLotList(lotIPage, lot);
  800. return toLotFansResponsePage(diamondPositions);
  801. }
  802. private List<LotFansResponse> toLotFansResponsePage(List<Lot> lots) {
  803. List<LotFansResponse> responses = lots.stream()
  804. .map(LotConvert.INSTANCE::toLotFansResponse)
  805. .collect(Collectors.toList());
  806. if (lots instanceof com.github.pagehelper.Page) {
  807. com.github.pagehelper.Page<Lot> lotPage = (com.github.pagehelper.Page<Lot>) lots;
  808. com.github.pagehelper.Page<LotFansResponse> responsePage =
  809. new com.github.pagehelper.Page<>(lotPage.getPageNum(), lotPage.getPageSize());
  810. responsePage.setTotal(lotPage.getTotal());
  811. responsePage.addAll(responses);
  812. return responsePage;
  813. }
  814. return responses;
  815. }
  816. private List<LotFansResponse> emptyLotFansResponsePage(LotQueryRequest request) {
  817. int pageNum = Objects.isNull(request.getPageNum()) ? 1 : request.getPageNum();
  818. int pageSize = Objects.isNull(request.getPageSize()) ? 100 : request.getPageSize();
  819. com.github.pagehelper.Page<LotFansResponse> page = new com.github.pagehelper.Page<>(pageNum, pageSize);
  820. page.setTotal(0);
  821. return page;
  822. }
  823. @Override
  824. public LotDetailResponse queryLotDetail(Long lotId) {
  825. Lot lot = lotMapper.selectLotById(lotId);
  826. if (Objects.isNull(lot)) {
  827. throw new ServiceException("未找到拍品数据");
  828. }
  829. Auction auction = auctionMapper.selectAuctionById(lot.getAuctionId());
  830. if (Objects.isNull(auction)) {
  831. throw new ServiceException("未找到拍卖会相关数据");
  832. }
  833. Date currentEndTime = lot.getEndTime();
  834. if (Objects.equals(Constants.LOT_STATUS_BIDDING, lot.getStatus())) {
  835. Live live = redisCache.getCacheMapValue(
  836. String.format(Constants.REDIS_MAP_AUC_LOT_TEMPLATE, lot.getAuctionId()),
  837. lot.getId().toString());
  838. if (Objects.nonNull(live) && Objects.nonNull(live.getCurrentEndTime())) {
  839. currentEndTime = new Date(live.getCurrentEndTime());
  840. }
  841. }
  842. TraditionRule rule = StringUtils.isEmpty(lot.getRuleContent())
  843. ? null
  844. : JSON.parseObject(lot.getRuleContent(), TraditionRule.class);
  845. BigDecimal startPrice = Objects.isNull(rule) ? null : rule.getStartPrice();
  846. BigDecimal markupAmount = Objects.isNull(rule) ? null : rule.getDefaultOnceAddPrice();
  847. Long depositAmount = lot.getDeposit();
  848. BigDecimal serviceTariff = lot.getServiceTariff();;
  849. String depositType = "LOT";
  850. if (Objects.isNull(depositAmount)) {
  851. depositAmount = auction.getDeposit();
  852. depositType = "AUCTION";
  853. serviceTariff = auction.getServiceTariff();
  854. }
  855. LotDetailResponse response = new LotDetailResponse();
  856. response.setLotId(lot.getId());
  857. response.setAuctionId(lot.getAuctionId());
  858. response.setName(lot.getName());
  859. response.setAuctionName(auction.getName());
  860. response.setAuctionDesc(auction.getDescription());
  861. response.setRuleContent(lot.getRuleContent());
  862. response.setAuctionImgs(auction.getImgs());
  863. response.setImgs(lot.getImgs());
  864. response.setCarouselImgs(lot.getCarouselImgs());
  865. response.setStatus(lot.getStatus());
  866. response.setStartTime(lot.getStartTime());
  867. response.setEndTime(lot.getEndTime());
  868. response.setCurrentEndTime(currentEndTime);
  869. response.setRealEndTime(lot.getRealEndTime());
  870. response.setStartPrice(startPrice);
  871. response.setCurrentPrice(Objects.nonNull(lot.getLastPrice()) ? lot.getLastPrice() : startPrice);
  872. response.setBidCount(lot.getBidCount());
  873. response.setDepositAmount(depositAmount);
  874. response.setDepositType(depositType);
  875. response.setServiceTariff(serviceTariff);
  876. response.setRuleType(lot.getRuleType());
  877. response.setMarkupAmount(markupAmount);
  878. response.setDetail(lot.getDetail());
  879. response.setProperties(lot.getProperties());
  880. response.setIsFans(Boolean.FALSE);
  881. response.setHasDeposit(Boolean.FALSE);
  882. response.setPayTimeLimit(lot.getPayTimeLimit());
  883. if (Objects.equals("Waiting", lot.getStatus()) && Objects.nonNull(lot.getStartTime())) {
  884. response.setTimestamp(lot.getStartTime().getTime() - System.currentTimeMillis());
  885. } else if (Objects.equals("Bidding", lot.getStatus()) && Objects.nonNull(currentEndTime)) {
  886. response.setTimestamp(currentEndTime.getTime() - System.currentTimeMillis());
  887. }
  888. //TODO 成交用户暂时无
  889. fillUserFlags(lot, response, depositType);
  890. return response;
  891. }
  892. // private Date toBeijingTime(Date date) {
  893. // return Objects.isNull(date) ? null : DateUtils.addHours(date, 8);
  894. // }
  895. private void fillUserFlags(Lot lot, LotDetailResponse response, String depositType) {
  896. UserInfo userInfo = UserUtils.getSimpleUserInfo();
  897. if (Objects.isNull(userInfo)) {
  898. return;
  899. }
  900. Long favoriteCount = lotFansMapper.selectCount(new LambdaQueryWrapper<LotFans>()
  901. .eq(LotFans::getLotId, lot.getId())
  902. .eq(LotFans::getDelFlag, 0)
  903. .eq(LotFans::getUserId, userInfo.getId().longValue())
  904. .eq(LotFans::getType, "user_like"));
  905. response.setIsFans(favoriteCount > 0);
  906. LambdaQueryWrapper<DepositOrder> depositQuery = new LambdaQueryWrapper<DepositOrder>()
  907. .eq(DepositOrder::getUserId, userInfo.getId())
  908. .in(DepositOrder::getStatus, 1);
  909. if (Objects.equals("LOT", depositType)) {
  910. depositQuery.eq(DepositOrder::getLotId, lot.getId())
  911. .eq(DepositOrder::getDepositType, "拍品");
  912. } else {
  913. depositQuery.eq(DepositOrder::getAuctionId, lot.getAuctionId())
  914. .eq(DepositOrder::getDepositType, "拍卖会");
  915. }
  916. Long depositCount = depositOrderMapper.selectCount(depositQuery);
  917. response.setHasDeposit(depositCount > 0);
  918. }
  919. @Override
  920. public List<LotExportDTO> exportLotList(LotRequest request) {
  921. if (Objects.isNull(request.getPageNum()) && Objects.isNull(request.getPageSize())) {
  922. request.setPageNum(1);
  923. request.setPageSize(1000);
  924. }
  925. request.setDelFlag(Constants.DEL_FLAG_NO_DELETE);
  926. IPage<Lot> lotIPage=new Page<>(request.getPageNum(),request.getPageSize());
  927. List<Lot> lotList = lotMapper.selectLotList(lotIPage, request);
  928. List<LotExportDTO> lotExportDTOS = lotList.stream().map(l -> {
  929. LotExportDTO lotExportDTO = new LotExportDTO();
  930. lotExportDTO.setId(String.valueOf(l.getId()));
  931. lotExportDTO.setGoodsId(l.getGoodsId());
  932. lotExportDTO.setGoodsName(l.getGoodsName());
  933. lotExportDTO.setGoodsType(l.getGoodsType());
  934. lotExportDTO.setSort(String.valueOf(l.getSort()));
  935. lotExportDTO.setBidCount(String.valueOf(l.getBidCount()));
  936. lotExportDTO.setPubStatus(PubStatusEnum.of(l.getPubStatus()).getDesc());
  937. lotExportDTO.setStatus(LotStatusEnum.of(l.getStatus()).getDesc());
  938. lotExportDTO.setCreateTime(DateUtils.parseDateToStr(l.getCreateTime()));
  939. lotExportDTO.setStartTime(DateUtils.parseDateToStr(l.getStartTime()));
  940. lotExportDTO.setEndTime(DateUtils.parseDateToStr(l.getEndTime()));
  941. lotExportDTO.setDeposit(String.valueOf(l.getDeposit() == null ? 0 : l.getDeposit()));
  942. lotExportDTO.setServiceTariff(String.valueOf(l.getServiceTariff()));
  943. lotExportDTO.setRuleType(RuleTypeEnum.getByCode(l.getRuleType()).getDesc());
  944. // 起拍价
  945. if (StringUtils.isNotEmpty(l.getRuleContent())) {
  946. TraditionRule traditionRule = JSON.parseObject(l.getRuleContent(), TraditionRule.class);
  947. lotExportDTO.setLastPrice(String.valueOf(traditionRule.getStartPrice()));
  948. }
  949. return lotExportDTO;
  950. }).collect(Collectors.toList());
  951. return lotExportDTOS;
  952. }
  953. @Override
  954. public List<Lot> selectLotListByLotIds(List<Long> lotIds) {
  955. return baseMapper.selectLotListByLotIds(lotIds);
  956. }
  957. }