2025-11-21 22:04:26 +08:00

74 lines
2.3 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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")));
}
}