SpringSimpleOperationApplicationTests.java 7.25 KB
Newer Older
kk committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
//package cn.kk.spring_simple_operation;
//
//import cn.kk.spring_simple_operation.entity.SyncProductPublish;
//import cn.kk.spring_simple_operation.mapper.SyncProductPublishMapper;
//import cn.kk.spring_simple_operation.mapper.VideoProductMapper;
//import com.alibaba.fastjson.JSONObject;
//import com.baomidou.mybatisplus.core.toolkit.StringUtils;
//import com.baomidou.mybatisplus.core.toolkit.Wrappers;
//import org.apache.commons.compress.utils.Lists;
//import org.junit.jupiter.api.Test;
//import org.springframework.boot.test.context.SpringBootTest;
//import org.springframework.util.CollectionUtils;
//
//import javax.annotation.Resource;
//import java.math.BigDecimal;
//import java.util.*;
//import java.util.stream.Collectors;
//
//@SpringBootTest
//class SpringSimpleOperationApplicationTests {
//
//	private static final BigDecimal               TWENTY = new BigDecimal("20");
//	private static final BigDecimal               FORTY  = new BigDecimal("40");
//	@Resource
//	private              SyncProductPublishMapper syncProductPublishMapper;
//
//	@Resource
//	private VideoProductMapper videoProductMapper;
//
//
//	@Test
//	void contextLoads() {
//	}
//
//	/**
//	 * 1.已开售时间大于1个月 常规产品 无简易和精细化视频产品(正常销售)
//	 * ① 单价<20美金,SKU或变体总月销100+
//	 * ② 单价在20~40美金,SKU或变体总月销80+
//	 * ③单价>40美金,SKU或变体总月销50+
//	 * 2.已开售时间大于1个月 节气产品热卖期在1-6月 无简易和精细化视频产品(正常销售+保留页面)
//	 * ① 单价<20美金,SKU或变体总月销100+
//	 * ② 单价在20~40美金,SKU或变体总月销80+
//	 * ③单价>40美金,SKU或变体总月销50+
//	 */
//	@Test
//	void testSyncProductPublish() {
//		//List<String> shortUrlSkuList = videoProductMapper.selectHaveTask();
//
//		Map<String, Integer> salesMap = new HashMap<>();
//		salesMap.put("0~20", 0);
//		salesMap.put("20~40", 0);
//		salesMap.put(">40", 0);
//
//		Set<String> haveSkuSet = new HashSet<>();
//
//		// 母体sku
//		List<SyncProductPublish> syncProductPublishes = syncProductPublishMapper.selectMotherSku();
//		List<SyncProductPublish> syncProductPublishes_2 = new LinkedList<>();
//
//		syncProductPublishes.forEach(item -> {
//			List<SyncProductPublish> subList = syncProductPublishMapper.selectList(Wrappers.<SyncProductPublish>lambdaQuery().eq(SyncProductPublish::getParentAsin, item.getRelationKey()).select(SyncProductPublish::getSku, SyncProductPublish::getThirtyDaySales));
//			subList.add(item);
//
//			String s = checkPriceAndSales(subList, item.getLowestPrice());
//			if (StringUtils.isBlank(s)) {
//				return;
//			}
//			salesMap.put(s, salesMap.get(s) + 1);
//			haveSkuSet.addAll(subList.stream().map(SyncProductPublish::getSku).collect(Collectors.toList()));
//			syncProductPublishes_2.addAll(subList);
//		});
//		//System.out.println(JSONObject.toJSONString(salesMap));
//		printSkuList(syncProductPublishes_2);
//		printMap(salesMap);
//
//		try {
//			Thread.sleep(1000);
//		} catch (InterruptedException e) {
//			e.printStackTrace();
//		}
//
//		Map<String, Integer> salesMap_2 = new HashMap<>();
//		salesMap_2.put("0~20", 0);
//		salesMap_2.put("20~40", 0);
//		salesMap_2.put(">40", 0);
//
//		List<SyncProductPublish> publishList = syncProductPublishMapper.selectChildSku();
//		List<SyncProductPublish> publishList_2 = new LinkedList<>();
//
//		publishList.forEach(item -> {
//			if (haveSkuSet.contains(item.getSku())) {
//				return;
//			}
//			ArrayList<SyncProductPublish> list = new ArrayList<>();
//			list.add(item);
//			String s = checkPriceAndSales(list, item.getLowestPrice());
//			if (StringUtils.isBlank(s)) {
//				return;
//			}
//			salesMap_2.put(s, salesMap_2.get(s) + 1);
//			publishList_2.add(item);
//		});
//		//System.out.println(JSONObject.toJSONString(salesMap_2));
//		printSkuList(publishList_2);
//		printMap(salesMap_2);
//	}
//
//	private String checkPriceAndSales(List<SyncProductPublish> subList, BigDecimal lowestPrice) {
//		if (CollectionUtils.isEmpty(subList) || lowestPrice.compareTo(BigDecimal.ZERO) < 0) {
//			return null;
//		}
//		int sum = subList.stream().map(SyncProductPublish::getThirtyDaySales).reduce(Integer::sum).get();
//		if (lowestPrice.compareTo(TWENTY) <= 0 && sum >= 100) {
//			return "0~20";
//		}
//		else if (lowestPrice.compareTo(TWENTY) > 0 && lowestPrice.compareTo(FORTY) <= 0 && sum >= 80) {
//			return "20~40";
//		}
//		else if (lowestPrice.compareTo(FORTY) > 0 && sum >= 50) {
//			return ">40";
//		}
//		return null;
//	}
//
//	private void printSkuList(List<SyncProductPublish> list) {
//		list.forEach(item -> {
//			String content = String.format("sku: %s, 30天销量: %d, price: %s, relationKey: %s, parentAsin: %s", item.getSku(), item.getThirtyDaySales(), item.getLowestPrice(), item.getRelationKey(), item.getParentAsin());
//			System.out.println(content);
//		});
//	}
//
//	private void printMap(Map<String, Integer> salesMap) {
//		System.out.println("0~20: " + salesMap.get("0~20"));
//		System.out.println("20~40: " + salesMap.get("20~40"));
//		System.out.println(">40: " + salesMap.get(">40"));
//	}
//
//	@Test
//	void testSyncProductPublish_2() {
//		//List<String> shortUrlSkuList = videoProductMapper.selectHaveTask();
//
//		Map<String, Integer> salesMap = new HashMap<>();
//		salesMap.put("0~20", 0);
//		salesMap.put("20~40", 0);
//		salesMap.put(">40", 0);
//
//		Set<String> haveSkuSet = new HashSet<>();
//
//		// 母体sku
//		List<SyncProductPublish> syncProductPublishes = syncProductPublishMapper.selectMotherSku_2();
//		List<SyncProductPublish> syncProductPublishes_2 = new LinkedList<>();
//
//		syncProductPublishes.forEach(item -> {
//			List<SyncProductPublish> subList = syncProductPublishMapper.selectList(Wrappers.<SyncProductPublish>lambdaQuery().eq(SyncProductPublish::getParentAsin, item.getRelationKey()).select(SyncProductPublish::getSku, SyncProductPublish::getThirtyDaySales));
//			subList.add(item);
//
//			String s = checkPriceAndSales(subList, item.getLowestPrice());
//			if (StringUtils.isBlank(s)) {
//				return;
//			}
//			salesMap.put(s, salesMap.get(s) + 1);
//			haveSkuSet.addAll(subList.stream().map(SyncProductPublish::getSku).collect(Collectors.toList()));
//			syncProductPublishes_2.addAll(subList);
//		});
//		//System.out.println(JSONObject.toJSONString(salesMap));
//		printSkuList(syncProductPublishes_2);
//		printMap(salesMap);
//
//		try {
//			Thread.sleep(1000);
//		} catch (InterruptedException e) {
//			e.printStackTrace();
//		}
//
//		Map<String, Integer> salesMap_2 = new HashMap<>();
//		salesMap_2.put("0~20", 0);
//		salesMap_2.put("20~40", 0);
//		salesMap_2.put(">40", 0);
//
//		List<SyncProductPublish> publishList = syncProductPublishMapper.selectChildSku_2();
//		List<SyncProductPublish> publishList_2 = new LinkedList<>();
//
//		publishList.forEach(item -> {
//			if (haveSkuSet.contains(item.getSku())) {
//				return;
//			}
//			ArrayList<SyncProductPublish> list = new ArrayList<>();
//			list.add(item);
//			String s = checkPriceAndSales(list, item.getLowestPrice());
//			if (StringUtils.isBlank(s)) {
//				return;
//			}
//			salesMap_2.put(s, salesMap_2.get(s) + 1);
//			publishList_2.add(item);
//		});
//		//System.out.println(JSONObject.toJSONString(salesMap_2));
//		printSkuList(publishList_2);
//		printMap(salesMap_2);
//	}
//
//}