|
|
@@ -60,10 +60,12 @@ public class AssetService {
|
|
|
|
|
|
|
|
|
public Page<Asset> all(PageQuery pageQuery) {
|
|
|
- Page<Asset> all = assetRepo.findAll(JpaUtils.toSpecification(pageQuery, Asset.class), JpaUtils.toPageRequest(pageQuery));
|
|
|
+ Page<Asset> all = assetRepo
|
|
|
+ .findAll(JpaUtils.toSpecification(pageQuery, Asset.class), JpaUtils.toPageRequest(pageQuery));
|
|
|
Map<String, Object> query = pageQuery.getQuery();
|
|
|
if (query.containsKey("userId")) {
|
|
|
- List<Long> orderId = orderRepo.findAllByUserIdAndOpenedFalse(Convert.convert(Long.class, query.get("userId")));
|
|
|
+ List<Long> orderId = orderRepo
|
|
|
+ .findAllByUserIdAndOpenedFalse(Convert.convert(Long.class, query.get("userId")));
|
|
|
return all.map(asset -> {
|
|
|
if (orderId.contains(asset.getOrderId())) {
|
|
|
asset.setOpened(false);
|
|
|
@@ -427,10 +429,12 @@ public class AssetService {
|
|
|
|
|
|
public Page<UserHistory> userHistory(Long userId, PageQuery pageQuery) {
|
|
|
Page<TokenHistory> page = tokenHistoryRepo.findAll(((root, criteriaQuery, criteriaBuilder) -> {
|
|
|
- List<Predicate> and = JpaUtils.toPredicates(pageQuery, TokenHistory.class, root, criteriaQuery, criteriaBuilder);
|
|
|
+ List<Predicate> and = JpaUtils
|
|
|
+ .toPredicates(pageQuery, TokenHistory.class, root, criteriaQuery, criteriaBuilder);
|
|
|
Map<String, Object> query = pageQuery.getQuery();
|
|
|
if (ObjectUtils.isEmpty(query.get("toUserId")) && ObjectUtils.isEmpty(query.get("fromUserId"))) {
|
|
|
- and.add(criteriaBuilder.or(criteriaBuilder.equal(root.get("toUserId"), userId), criteriaBuilder.equal(root.get("fromUserId"), userId)));
|
|
|
+ and.add(criteriaBuilder.or(criteriaBuilder.equal(root.get("toUserId"), userId), criteriaBuilder
|
|
|
+ .equal(root.get("fromUserId"), userId)));
|
|
|
} else {
|
|
|
if (ObjectUtils.isNotEmpty(query.get("toUserId"))) {
|
|
|
and.add(criteriaBuilder.and(criteriaBuilder.equal(root.get("toUserId"), userId)));
|
|
|
@@ -530,14 +534,30 @@ public class AssetService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- // @Scheduled(cron = "0 0 0/2 * * ?")
|
|
|
- @Scheduled(cron = "0 */1 * * * ?")
|
|
|
+ @Scheduled(cron = "0 0 0/1 * * ?")
|
|
|
public void offTheShelf() {
|
|
|
LocalDateTime lastTime = LocalDateTime.now().minusHours(1);
|
|
|
Set<Long> assetIds = collectionRepo
|
|
|
.findResaleCollectionPriceOver20K(BigDecimal
|
|
|
.valueOf(20000L), CollectionSource.TRANSFER, lastTime, true);
|
|
|
- assetIds.forEach(this::cancelConsignment);
|
|
|
+ assetIds.forEach(this::cancelConsignmentBySystem);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public void cancelConsignmentBySystem(Long id) {
|
|
|
+ Asset asset = assetRepo.findById(id).orElseThrow(new BusinessException("无记录"));
|
|
|
+ if (asset.getPublicCollectionId() != null) {
|
|
|
+ List<Order> orders = orderRepo.findByCollectionId(asset.getPublicCollectionId());
|
|
|
+ if (orders.stream().anyMatch(o -> o.getStatus() != OrderStatus.CANCELLED)) {
|
|
|
+ throw new BusinessException("已有订单不可取消");
|
|
|
+ }
|
|
|
+ collectionRepo.findById(asset.getPublicCollectionId())
|
|
|
+ .ifPresent(collection -> {
|
|
|
+ collection.setSalable(false);
|
|
|
+ collectionRepo.save(collection);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ asset.setConsignment(false);
|
|
|
+ assetRepo.save(asset);
|
|
|
+ }
|
|
|
}
|