| | |
| | | package com.ks; |
| | | |
| | | import com.ks.lijin.LiJinApplication; |
| | | import com.ks.lijin.dao.LijinConfigDao; |
| | | import com.ks.lijin.job.LijinOrderJob; |
| | | import com.ks.lijin.pojo.DO.LiJinProviderTaoKeAccount; |
| | | import com.ks.lijin.pojo.DO.LijinConfig; |
| | | import com.ks.lijin.service.LiJinProviderAccountService; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.springframework.boot.test.context.SpringBootTest; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.test.context.ContextConfiguration; |
| | | import org.yeshi.utils.TimeUtil; |
| | | import redis.clients.jedis.Jedis; |
| | | import redis.clients.jedis.JedisPool; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | @SpringBootTest(classes = LiJinApplication.class) |
| | | public class LuckyTest { |
| | | |
| | | |
| | | @Resource |
| | | private RedisTemplate redisTemplate; |
| | | @Resource |
| | | private LijinOrderJob lijinOrderJob; |
| | | |
| | | @Resource |
| | | private LijinConfigDao lijinConfigDao; |
| | | @Resource |
| | | private LiJinProviderAccountService liJinProviderAccountService; |
| | | |
| | | @Resource |
| | | private JedisPool jedisPool; |
| | | |
| | | @Test |
| | | public void test() { |
| | | Map<Long, Integer> map = new HashMap<>(); |
| | | int total = 0; |
| | | int personCount = 1000000; |
| | | for (int i = 0; i < personCount; i++) { |
| | | map.put(10000L + i, i == 0 ? 0 : (int) (1 + 10 * Math.random())); |
| | | total += map.get(10000L + i); |
| | | String key = "createtblijin-tejia-6872490"; |
| | | |
| | | Jedis jedis = jedisPool.getResource(); |
| | | try { |
| | | System.out.println(jedis.setnx(key, "1")); |
| | | jedis.expire(key, 120); |
| | | } finally { |
| | | jedis.close(); |
| | | } |
| | | Set<Long> sets = choujiang(map, 100); |
| | | int percent = total / personCount; |
| | | int upCount = 0; |
| | | for (Long uid : sets) { |
| | | if (map.get(uid) > percent) |
| | | upCount += 1; |
| | | System.out.println(uid + "-" + map.get(uid) + "是否大于均值:" + (map.get(uid) > percent)); |
| | | } |
| | | System.out.println("大于均值数量:" + upCount); |
| | | System.out.println("数量:" + sets.size()); |
| | | |
| | | } |
| | | |
| | | private Set<Long> choujiang(Map<Long, Integer> map, int number) { |
| | | @Test |
| | | public void job() throws Exception { |
| | | lijinOrderJob.saveTaoBaoOrder("6"); |
| | | } |
| | | |
| | | List<Long> mList = new ArrayList<>(); |
| | | for (Iterator<Long> its = map.keySet().iterator(); its.hasNext(); ) { |
| | | Long uid = its.next(); |
| | | int c = map.get(uid); |
| | | for (int i = 0; i < c; i++) { |
| | | mList.add(uid); |
| | | } |
| | | } |
| | | @Test |
| | | public void config() throws Exception { |
| | | LijinConfig config = new LijinConfig(); |
| | | config.setCreateTime(new Date()); |
| | | config.setId("newer-hour"); |
| | | config.setKey("newer-hour"); |
| | | config.setName("新手的判断时间(小时)"); |
| | | config.setValue("48"); |
| | | lijinConfigDao.save(config); |
| | | |
| | | Set<Long> luckyUids = new HashSet<>(); |
| | | for (int i = 0; i < number; i++) { |
| | | if(mList.size()==0) |
| | | break; |
| | | long startTime = System.currentTimeMillis(); |
| | | int p = (int) (mList.size() * Math.random()); |
| | | long uid = mList.get(p); |
| | | luckyUids.add(uid); |
| | | config = new LijinConfig(); |
| | | config.setCreateTime(new Date()); |
| | | config.setId("newer-everyday-plus-lijin-count"); |
| | | config.setKey("newer-everyday-plus-lijin-count"); |
| | | config.setName("新手每天额外的礼金创建次数"); |
| | | config.setValue("2"); |
| | | lijinConfigDao.save(config); |
| | | } |
| | | |
| | | //移除列表右面的相同uid |
| | | while (mList.size() > p && mList.get(p) == uid) { |
| | | mList.remove(p); |
| | | } |
| | | @Test |
| | | public void redis() { |
| | | String auctionId = 600889742753L+""; |
| | | String day = TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyyMMdd"); |
| | | String key = String.format("lijingoodslimit-%s-%s", day, auctionId); |
| | | Boolean hasKey = redisTemplate.hasKey(key); |
| | | System.out.println(hasKey); |
| | | } |
| | | |
| | | //查询相同uid的列表左侧起点 |
| | | for (int j = p - 1; j >= 0; j--) { |
| | | if (mList.get(j).longValue() != uid) { |
| | | p = j + 1; |
| | | break; |
| | | } else if (j == 0) { |
| | | p = 0; |
| | | } |
| | | } |
| | | @Test |
| | | public void syncLijinReportData() throws Exception { |
| | | lijinOrderJob.syncLijinReportData(""); |
| | | } |
| | | |
| | | //删除左侧相同uid |
| | | while (mList.size() > p && mList.get(p) == uid) { |
| | | mList.remove(p); |
| | | } |
| | | |
| | | System.out.println("运行时间:" + (System.currentTimeMillis() - startTime)); |
| | | } |
| | | |
| | | |
| | | System.out.println(luckyUids); |
| | | return luckyUids; |
| | | @Test |
| | | public void getTaoKeAccount() { |
| | | List<LiJinProviderTaoKeAccount> list = liJinProviderAccountService.listValidByProviderId(1L, null); |
| | | System.out.println(list); |
| | | } |
| | | |
| | | |