package com.td.boss; import cn.hutool.core.convert.Convert; import cn.hutool.core.date.DateField; import cn.hutool.core.date.DateUtil; import cn.hutool.json.JSONUtil; import com.td.boss.common.pojo.Result; import com.td.boss.game.comcnttosnb.service.ComCntToSnbService; import com.td.boss.game.complayerland.pojo.ComPlayerDisasterLog; import com.td.boss.game.complayerland.service.ComPlayerDisasterProtectedService; import com.td.boss.game.complayerland.service.ComPlayerDisasterLogService; import com.td.boss.game.complayerland.vo.ComPlayerDisasterEnum; import com.td.boss.game.complayerland.vo.ComPlayerDisasterProtectedVo; import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; import java.util.Date; import java.util.List; @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) class ComPlayerDisasterLogTests { @Autowired private ComPlayerDisasterLogService comPlayerDisasterLogService; @Autowired private ComPlayerDisasterProtectedService comPlayerDisasterProtectedService; @Autowired private ComCntToSnbService comCntToSnbService; private String userId = "1002"; /** * 防护灾难 */ @Test void playerAddProtected() { ComPlayerDisasterProtectedVo comPlayerDisasterProtected = new ComPlayerDisasterProtectedVo(); comPlayerDisasterProtected.setCreateTime(new Date()); comPlayerDisasterProtected.setUserId(userId); comPlayerDisasterProtected.setDsasterType(ComPlayerDisasterEnum.ziran.getCode()); comPlayerDisasterProtected.setDsasterName(ComPlayerDisasterEnum.ziran.getMsg()); comPlayerDisasterProtected.setProtectTime(DateUtil.date(new Date()).offset(DateField.DAY_OF_WEEK, 30)); comPlayerDisasterProtectedService.save(comPlayerDisasterProtected); comPlayerDisasterProtected = new ComPlayerDisasterProtectedVo(); comPlayerDisasterProtected.setCreateTime(new Date()); comPlayerDisasterProtected.setUserId(userId); comPlayerDisasterProtected.setDsasterType(ComPlayerDisasterEnum.yeshou.getCode()); comPlayerDisasterProtected.setDsasterName(ComPlayerDisasterEnum.yeshou.getMsg()); comPlayerDisasterProtected.setProtectTime(DateUtil.date(new Date()).offset(DateField.DAY_OF_WEEK, -30)); comPlayerDisasterProtectedService.save(comPlayerDisasterProtected); } /** * 获取灾难经历 */ @Test void getHistory() { List history = comPlayerDisasterLogService.getHistory(userId); System.out.println(history); } /** * 测试灾难模式 */ @Test void ComPlayerDisasterWeekTask() { comPlayerDisasterLogService.asyncDisaster(userId); } @Test void ComPlayerDisasterDayTask() { for (ComPlayerDisasterLog disasterLog : comPlayerDisasterLogService.getTodayDisasterUnEnabledList()) { comPlayerDisasterLogService.ComPlayerDisasterDayTask(disasterLog); } } /** * 获取userid snb领取情况,如果不在特定的列表,data为null */ @Test void getCntToSnb() { // 情况一,在名单中 String json = JSONUtil.toJsonStr(Result.of(comCntToSnbService.findByUserId("952"))); System.out.println(json); // 情况二,不在名单中 String json2 = JSONUtil.toJsonStr(Result.of(comCntToSnbService.findByUserId("9527"))); System.out.println(json2); } /** * userid领取snb */ @Test void receiveCntToSnb() { // Date begin = DateUtil.parse("2022-03-01"); // Date end = DateUtil.parse("2022-03-05"); // // Integer day = Convert.toInt(DateUtil.betweenDay(begin, end, true)); // System.out.println(DateUtil.format(begin, "yyyy-MM-dd") + " 至 " + DateUtil.format(end, "yyyy-MM-dd") + "相差:" + day + "天"); String json = JSONUtil.toJsonStr(comCntToSnbService.receiveByUserId("952")); System.out.println(json); } }