|
|
@@ -1,20 +1,86 @@
|
|
|
package com.izouma.nineth.service;
|
|
|
|
|
|
+import com.izouma.nineth.domain.Asset;
|
|
|
import com.izouma.nineth.domain.AssetPost;
|
|
|
+import com.izouma.nineth.domain.UserAddress;
|
|
|
import com.izouma.nineth.dto.PageQuery;
|
|
|
+import com.izouma.nineth.enums.AssetStatus;
|
|
|
+import com.izouma.nineth.enums.PostStatus;
|
|
|
+import com.izouma.nineth.exception.BusinessException;
|
|
|
import com.izouma.nineth.repo.AssetPostRepo;
|
|
|
+import com.izouma.nineth.repo.AssetRepo;
|
|
|
+import com.izouma.nineth.repo.UserAddressRepo;
|
|
|
import com.izouma.nineth.utils.JpaUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.List;
|
|
|
+import java.util.Optional;
|
|
|
+
|
|
|
@Service
|
|
|
@AllArgsConstructor
|
|
|
public class AssetPostService {
|
|
|
|
|
|
- private AssetPostRepo assetPostRepo;
|
|
|
+ private AssetPostRepo assetPostRepo;
|
|
|
+ private AssetRepo assetRepo;
|
|
|
+ private UserAddressRepo userAddressRepo;
|
|
|
|
|
|
public Page<AssetPost> all(PageQuery pageQuery) {
|
|
|
return assetPostRepo.findAll(JpaUtils.toSpecification(pageQuery, AssetPost.class), JpaUtils.toPageRequest(pageQuery));
|
|
|
}
|
|
|
+
|
|
|
+ /*
|
|
|
+ 衍生品上链
|
|
|
+ 衍生品有盲盒类型
|
|
|
+ 衍生品邮寄不支付快递费
|
|
|
+ 衍生品暂不可以取消邮寄
|
|
|
+ */
|
|
|
+ public void post(Long userId, Long assetId, Long addressId) {
|
|
|
+ Asset asset = assetRepo.findById(assetId).orElseThrow(new BusinessException("无此衍生品"));
|
|
|
+ if (asset.isPublicShow()) {
|
|
|
+ if (asset.isConsignment()) {
|
|
|
+ throw new BusinessException("请先取消寄售");
|
|
|
+ }
|
|
|
+ throw new BusinessException("请先取消公开展示");
|
|
|
+ }
|
|
|
+ if (AssetStatus.POSTED.equals(asset.getStatus())) {
|
|
|
+ throw new BusinessException("已邮寄,无需再邮寄");
|
|
|
+ }
|
|
|
+ if (!AssetStatus.NORMAL.equals(asset.getStatus())) {
|
|
|
+ throw new BusinessException("当前状态不可邮寄");
|
|
|
+ }
|
|
|
+ AssetPost assetPost = assetPostRepo.findFirstByAssetIdAndDelFalseOrderByIdDesc(assetId);
|
|
|
+ if (ObjectUtils.isNotEmpty(assetPost) && !PostStatus.CANCELLED.equals(assetPost.getStatus())) {
|
|
|
+ throw new BusinessException("已邮寄,无需再邮寄");
|
|
|
+ }
|
|
|
+
|
|
|
+ UserAddress userAddress = userAddressRepo.findById(addressId).orElseThrow(new BusinessException("地址信息不存在"));
|
|
|
+
|
|
|
+ AssetPost build = AssetPost.builder()
|
|
|
+ .assetId(assetId)
|
|
|
+ .userId(userId)
|
|
|
+ .contactName(userAddress.getName())
|
|
|
+ .contactPhone(userAddress.getPhone())
|
|
|
+ .address(userAddress.getProvinceName() + " " + userAddress.getCityName() + " " +
|
|
|
+ userAddress.getDistrictName() + " " + userAddress.getAddress())
|
|
|
+ .status(PostStatus.DELIVERY)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ assetPostRepo.save(build);
|
|
|
+ asset.setStatus(AssetStatus.POSTING);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void updateStatus(Long assetPostId, PostStatus status) {
|
|
|
+ AssetPost assetPost = assetPostRepo.findById(assetPostId).orElseThrow(new BusinessException("无邮寄信息"));
|
|
|
+ assetPost.setStatus(status);
|
|
|
+ if (PostStatus.FINISH.equals(status)) {
|
|
|
+ Asset asset = assetRepo.findById(assetPost.getAssetId()).orElseThrow(new BusinessException("无衍生品"));
|
|
|
+ asset.setStatus(AssetStatus.POSTED);
|
|
|
+ assetRepo.save(asset);
|
|
|
+ }
|
|
|
+ assetPostRepo.save(assetPost);
|
|
|
+ }
|
|
|
+
|
|
|
}
|