|
|
@@ -9,10 +9,7 @@ import com.izouma.nineth.domain.*;
|
|
|
import com.izouma.nineth.dto.PageQuery;
|
|
|
import com.izouma.nineth.dto.PageWrapper;
|
|
|
import com.izouma.nineth.dto.UserHistory;
|
|
|
-import com.izouma.nineth.enums.AssetStatus;
|
|
|
-import com.izouma.nineth.enums.CollectionSource;
|
|
|
-import com.izouma.nineth.enums.CollectionType;
|
|
|
-import com.izouma.nineth.enums.OrderStatus;
|
|
|
+import com.izouma.nineth.enums.*;
|
|
|
import com.izouma.nineth.event.TransferAssetEvent;
|
|
|
import com.izouma.nineth.exception.BusinessException;
|
|
|
import com.izouma.nineth.repo.*;
|
|
|
@@ -67,8 +64,7 @@ public class AssetService {
|
|
|
private ShowCollectionRepo showCollectionRepo;
|
|
|
private CollectionPrivilegeRepo collectionPrivilegeRepo;
|
|
|
private PasswordEncoder passwordEncoder;
|
|
|
- private MintActivityRepo mintActivityRepo;
|
|
|
- private TagRepo tagRepo;
|
|
|
+
|
|
|
|
|
|
public Page<Asset> all(PageQuery pageQuery) {
|
|
|
Page<Asset> all = assetRepo
|
|
|
@@ -196,10 +192,14 @@ public class AssetService {
|
|
|
}
|
|
|
|
|
|
int holdDays;
|
|
|
- if (ObjectUtils.isEmpty(asset.getHoldDays())) {
|
|
|
- holdDays = sysConfigService.getInt("hold_days");
|
|
|
+ if (asset.getSource() == AssetSource.GIFT) {
|
|
|
+ holdDays = sysConfigService.getInt("gift_days");
|
|
|
} else {
|
|
|
- holdDays = asset.getHoldDays();
|
|
|
+ if (ObjectUtils.isEmpty(asset.getHoldDays())) {
|
|
|
+ holdDays = sysConfigService.getInt("hold_days");
|
|
|
+ } else {
|
|
|
+ holdDays = asset.getHoldDays();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if (ChronoUnit.DAYS.between(asset.getCreatedAt(), LocalDateTime.now()) < holdDays) {
|
|
|
@@ -330,7 +330,11 @@ public class AssetService {
|
|
|
assetRepo.save(asset);
|
|
|
}
|
|
|
|
|
|
- public void transfer(Asset asset, BigDecimal price, User toUser, String reason, Long orderId) {
|
|
|
+ public void transfer(Asset asset, BigDecimal price, User toUser, TransferReason reason, Long orderId) {
|
|
|
+ Objects.requireNonNull(asset, "原藏品不能为空");
|
|
|
+ Objects.requireNonNull(toUser, "转让人不能为空");
|
|
|
+ Objects.requireNonNull(reason, "转让原因不能为空");
|
|
|
+
|
|
|
Asset newAsset = new Asset();
|
|
|
BeanUtils.copyProperties(asset, newAsset);
|
|
|
newAsset.setId(null);
|
|
|
@@ -347,6 +351,7 @@ public class AssetService {
|
|
|
newAsset.setOrderId(orderId);
|
|
|
newAsset.setFromAssetId(asset.getId());
|
|
|
newAsset.setType(CollectionType.DEFAULT);
|
|
|
+ newAsset.setSource(TransferReason.GIFT == reason ? AssetSource.GIFT : AssetSource.TRANSFER);
|
|
|
newAsset.setTags(new HashSet<>(asset.getTags()));
|
|
|
assetRepo.save(newAsset);
|
|
|
|
|
|
@@ -358,14 +363,14 @@ public class AssetService {
|
|
|
.toUser(toUser.getNickname())
|
|
|
.toUserId(toUser.getId())
|
|
|
.toAvatar(toUser.getAvatar())
|
|
|
- .operation(reason)
|
|
|
- .price("转赠".equals(reason) ? null : price)
|
|
|
+ .operation(reason.getDescription())
|
|
|
+ .price(TransferReason.GIFT == reason ? null : price)
|
|
|
.build());
|
|
|
|
|
|
asset.setPublicShow(false);
|
|
|
asset.setConsignment(false);
|
|
|
asset.setPublicCollectionId(null);
|
|
|
- asset.setStatus("转赠".equals(reason) ? AssetStatus.GIFTED : AssetStatus.TRANSFERRED);
|
|
|
+ asset.setStatus(TransferReason.GIFT == reason ? AssetStatus.GIFTED : AssetStatus.TRANSFERRED);
|
|
|
asset.setOwner(toUser.getNickname());
|
|
|
asset.setOwnerId(toUser.getId());
|
|
|
asset.setOwnerAvatar(toUser.getAvatar());
|