import com.red.circle.other.infra.database.mongo.service.team.TeamBillCycleUtils; import com.red.circle.tool.core.date.ZonedDateTimeAsiaRiyadhUtils; import com.red.circle.tool.crypto.SecurityUtils; import org.junit.Test; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import static com.red.circle.other.infra.database.mongo.service.team.TeamBillCycleUtils.getCalcBillBelong; public class ApiTest { @Test public void testPassword() { System.out.println(new BCryptPasswordEncoder().encode("123456")); } @Test public void test() { String[] strings = TeamBillCycleUtils.parseBillBelongToDateRange(20251001); System.out.println(strings[0]); System.out.println(strings[1]); System.out.println(LocalDateTime.now()); } @Test public void test1() { System.out.println(SecurityUtils.md5("1957345312961527809")); } @Test public void test2() { System.out.println(ZonedDateTimeAsiaRiyadhUtils.nowFormat("yyyyMMddHH")); } @Test public void test3() { // 计算当前账期的 billBelong Integer currentBillBelong = 20251101; Integer billBelong = calculateSettlementBillBelong(currentBillBelong); System.out.println(billBelong); } /** * 计算需要结算的账期 * 规则: * - 如果当前账期是本月1号(如20250101),则结算上个月16号的账期(如20241216) * - 如果当前账期是本月16号(如20250116),则结算本月1号的账期(如20250101) */ private Integer calculateSettlementBillBelong(Integer currentBillBelong) { String billStr = String.valueOf(currentBillBelong); int year = Integer.parseInt(billStr.substring(0, 4)); int month = Integer.parseInt(billStr.substring(4, 6)); int day = Integer.parseInt(billStr.substring(6, 8)); LocalDate settlementDate; if (day == 1) { // 当前是本月1号,结算上个月16号 settlementDate = LocalDate.of(year, month, 1).minusMonths(1).withDayOfMonth(16); } else { // 当前是本月16号,结算本月1号 settlementDate = LocalDate.of(year, month, 1); } return Integer.parseInt(settlementDate.format(DateTimeFormatter.ofPattern("yyyyMMdd"))); } }