CollectionRepoTest.java 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package com.izouma.nineth.repo;
  2. import com.izouma.nineth.ApplicationTests;
  3. import com.izouma.nineth.domain.Collection;
  4. import com.izouma.nineth.enums.OrderStatus;
  5. import com.izouma.nineth.exception.BusinessException;
  6. import com.izouma.nineth.service.AssetService;
  7. import org.apache.commons.lang3.StringUtils;
  8. import org.junit.Test;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import java.util.Arrays;
  11. import java.util.List;
  12. import java.util.concurrent.atomic.AtomicInteger;
  13. public class CollectionRepoTest extends ApplicationTests {
  14. @Autowired
  15. private CollectionRepo collectionRepo;
  16. @Autowired
  17. private AssetService assetService;
  18. @Autowired
  19. private TagRepo tagRepo;
  20. @Autowired
  21. private UserPropertyRepo userPropertyRepo;
  22. @Autowired
  23. private OrderRepo orderRepo;
  24. @Test
  25. public void updateCDN() {
  26. List<List<String>> list = collectionRepo.selectResource(83346L);
  27. for (int i = 0; i < list.get(0).size(); i++) {
  28. list.get(0).set(i, assetService.replaceCDN(list.get(0).get(i)));
  29. }
  30. collectionRepo.updateCDN(Long.parseLong(list.get(0).get(0)),
  31. list.get(0).get(1),
  32. list.get(0).get(2),
  33. list.get(0).get(3),
  34. list.get(0).get(4),
  35. list.get(0).get(5));
  36. }
  37. @Test
  38. public void testMaxCount() {
  39. Collection collection = collectionRepo.findById(8017401L).orElse(null);
  40. AtomicInteger userMax = new AtomicInteger();
  41. userPropertyRepo.findById(9972L).ifPresent(userProperty -> userMax.set(userProperty.getMaxCount()));
  42. if (collection.getMaxCount() > 0) {
  43. int count;
  44. if (StringUtils.isNotBlank(collection.getCountId())) {
  45. count = orderRepo.countByUserIdAndCountIdAndStatusIn(9972L, collection.getCountId(), Arrays
  46. .asList(OrderStatus.FINISH, OrderStatus.NOT_PAID, OrderStatus.PROCESSING));
  47. } else {
  48. count = orderRepo.countByUserIdAndCollectionIdAndStatusIn(9972L, 8017401L, Arrays
  49. .asList(OrderStatus.FINISH, OrderStatus.NOT_PAID, OrderStatus.PROCESSING));
  50. }
  51. if (userMax.get() > 0) {
  52. if (count >= userMax.get()) {
  53. throw new BusinessException("限购" + userMax.get() + "件");
  54. }
  55. } else {
  56. if (count >= collection.getMaxCount()) {
  57. throw new BusinessException("限购" + collection.getMaxCount() + "件");
  58. }
  59. }
  60. }
  61. }
  62. }