ComPlayerDisasterLogTests.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. package com.td.boss;
  2. import cn.hutool.core.convert.Convert;
  3. import cn.hutool.core.date.DateField;
  4. import cn.hutool.core.date.DateUtil;
  5. import cn.hutool.json.JSONUtil;
  6. import com.td.boss.common.pojo.Result;
  7. import com.td.boss.game.comcnttosnb.service.ComCntToSnbService;
  8. import com.td.boss.game.complayerland.pojo.ComPlayerDisasterLog;
  9. import com.td.boss.game.complayerland.service.ComPlayerDisasterProtectedService;
  10. import com.td.boss.game.complayerland.service.ComPlayerDisasterLogService;
  11. import com.td.boss.game.complayerland.vo.ComPlayerDisasterEnum;
  12. import com.td.boss.game.complayerland.vo.ComPlayerDisasterProtectedVo;
  13. import org.junit.jupiter.api.Test;
  14. import org.junit.runner.RunWith;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.boot.test.context.SpringBootTest;
  17. import org.springframework.test.context.junit4.SpringRunner;
  18. import java.util.Date;
  19. import java.util.List;
  20. @RunWith(SpringRunner.class)
  21. @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
  22. class ComPlayerDisasterLogTests {
  23. @Autowired
  24. private ComPlayerDisasterLogService comPlayerDisasterLogService;
  25. @Autowired
  26. private ComPlayerDisasterProtectedService comPlayerDisasterProtectedService;
  27. @Autowired
  28. private ComCntToSnbService comCntToSnbService;
  29. private String userId = "1002";
  30. /**
  31. * 防护灾难
  32. */
  33. @Test
  34. void playerAddProtected() {
  35. ComPlayerDisasterProtectedVo comPlayerDisasterProtected = new ComPlayerDisasterProtectedVo();
  36. comPlayerDisasterProtected.setCreateTime(new Date());
  37. comPlayerDisasterProtected.setUserId(userId);
  38. comPlayerDisasterProtected.setDsasterType(ComPlayerDisasterEnum.ziran.getCode());
  39. comPlayerDisasterProtected.setDsasterName(ComPlayerDisasterEnum.ziran.getMsg());
  40. comPlayerDisasterProtected.setProtectTime(DateUtil.date(new Date()).offset(DateField.DAY_OF_WEEK, 30));
  41. comPlayerDisasterProtectedService.save(comPlayerDisasterProtected);
  42. comPlayerDisasterProtected = new ComPlayerDisasterProtectedVo();
  43. comPlayerDisasterProtected.setCreateTime(new Date());
  44. comPlayerDisasterProtected.setUserId(userId);
  45. comPlayerDisasterProtected.setDsasterType(ComPlayerDisasterEnum.yeshou.getCode());
  46. comPlayerDisasterProtected.setDsasterName(ComPlayerDisasterEnum.yeshou.getMsg());
  47. comPlayerDisasterProtected.setProtectTime(DateUtil.date(new Date()).offset(DateField.DAY_OF_WEEK, -30));
  48. comPlayerDisasterProtectedService.save(comPlayerDisasterProtected);
  49. }
  50. /**
  51. * 获取灾难经历
  52. */
  53. @Test
  54. void getHistory() {
  55. List<ComPlayerDisasterLog> history = comPlayerDisasterLogService.getHistory(userId);
  56. System.out.println(history);
  57. }
  58. /**
  59. * 测试灾难模式
  60. */
  61. @Test
  62. void ComPlayerDisasterWeekTask() {
  63. comPlayerDisasterLogService.asyncDisaster(userId);
  64. }
  65. @Test
  66. void ComPlayerDisasterDayTask() {
  67. for (ComPlayerDisasterLog disasterLog : comPlayerDisasterLogService.getTodayDisasterUnEnabledList()) {
  68. comPlayerDisasterLogService.ComPlayerDisasterDayTask(disasterLog);
  69. }
  70. }
  71. /**
  72. * 获取userid snb领取情况,如果不在特定的列表,data为null
  73. */
  74. @Test
  75. void getCntToSnb() {
  76. // 情况一,在名单中
  77. String json = JSONUtil.toJsonStr(Result.of(comCntToSnbService.findByUserId("952")));
  78. System.out.println(json);
  79. // 情况二,不在名单中
  80. String json2 = JSONUtil.toJsonStr(Result.of(comCntToSnbService.findByUserId("9527")));
  81. System.out.println(json2);
  82. }
  83. /**
  84. * userid领取snb
  85. */
  86. @Test
  87. void receiveCntToSnb() {
  88. // Date begin = DateUtil.parse("2022-03-01");
  89. // Date end = DateUtil.parse("2022-03-05");
  90. //
  91. // Integer day = Convert.toInt(DateUtil.betweenDay(begin, end, true));
  92. // System.out.println(DateUtil.format(begin, "yyyy-MM-dd") + " 至 " + DateUtil.format(end, "yyyy-MM-dd") + "相差:" + day + "天");
  93. String json = JSONUtil.toJsonStr(comCntToSnbService.receiveByUserId("952"));
  94. System.out.println(json);
  95. }
  96. }