签到以一个时间段 为周期,取周期内连续签到日期及签到状态 经典算法

 不习惯废话,直接上干货。

第一种方法: 

/**
 *
 * 获取周期内连续日期
 *
 * @param days 连续周期内第几天(或 连续天数)
 * @param count 周期天数
 * @param date 日期
 *
 * @return List<Map<String, Object>>
 *
 */
private static List<Map<String, Object>> getCompDate(Integer days, Integer count, String date) {
    String nowDate = DateTimeUtil.getNowTime("yyyy-MM-dd");
    List<Map<String, Object>> reList = new ArrayList<Map<String,Object>>();
    days= days== 0 ? 1 : days;
	days= days % count == 0 ? count : (days % count) ;
	days--;
    for (int i = 1; i <= count; i++) {
        Map<String, Object> reMap  = new HashMap<String, Object>();
        String tempDate = DateTimeUtil.getBeforeOrAfterDate(date, -count, 1);
        reMap.put("today", nowDate.equals(tempDate) ? true : false); // true:今天
        reMap.put("date", tempDate);
        reMap.put("flag", days >= 0 ? 0 : 1); // flag = 0: 当前日期之前(包括当前日期)
        --count ;
		reList.add(reMap);
    }
    return reList;
}


/**
 *
 *  获取当前时间
 *
 * @param dateformat
 * 
 * @return String 
 *
 */
private static String getNowTime(String dateformat) {
    Date nowDate = new Date();
    SimpleDateFormat dateFormat = new SimpleDateFormat(dateformat);
    String nowime= dateFormat.format(nowDate );
    return nowTime;
}

/**
 *
 * 获取date前(或者后)第几天的日期
 * 
 * @param date 日期
 * @param day 负数: date前第几天日期, 正数: date 后第几天日期
 * @param dateformat
 *
 * @return String 
 *
 */
public static String getBeforeOrAfterDate(String date, Integer day, String dateformat) {
    try {
        SimpleDateFormat sdf = new SimpleDateFormat(dateformat);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(sdf.parse(date));
			
        calendar.add(Calendar.DAY_OF_MONTH, day); 
        Date dBefore = calendar.getTime();
        String str=sdf.format(dBefore);
        return str;
    } catch (Exception e) {
        return null;
    }
}

 测试:


public static void main(String[] args) {
    //10天为周期,当前日期为连续第1天
    List list0 = getCompDate1(1, 10, "2018-12-26");
    System.out.println("//10天为周期,当前日期为连续第1天 结果");
    for (int i = 0; i < list0.size(); i++) {
        Map map = (Map)list0.get(i);
        System.out.println(map.toString());
    }

    //10天为周期,当前日期为连续第8天
    List list1 = getCompDate1(8, 10, "2018-12-26");
    System.out.println("//10天为周期,当前日期为连续第8天 结果");
    for (int i = 0; i < list1.size(); i++) {
        Map map = (Map)list1.get(i);
        System.out.println(map.toString());
    }

    //10天为周期,当前日期为连续第14天
    List list2 = getCompDate1(14, 10, "2018-12-26");
    System.out.println("//10天为周期,当前日期为连续第14天 结果");
    for (int i = 0; i < list2.size(); i++) {
        Map map = (Map)list2.get(i);
        System.out.println(map.toString());
    }

    //10天为周期,当前日期为连续第25天
    List list3 = getCompDate1(25, 10, "2018-12-26");
    System.out.println("//10天为周期,当前日期为连续第25天 结果");
    for (int i = 0; i < list3.size(); i++) {
        Map map = (Map)list3.get(i);
        System.out.println(map.toString());
    }
}

 

测试结果:

//10天为周期,当前日期为连续第1天 结果
{flag=0, today=true, date=2018-12-26}
{flag=1, today=false, date=2018-12-27}
{flag=1, today=false, date=2018-12-28}
{flag=1, today=false, date=2018-12-29}
{flag=1, today=false, date=2018-12-30}
{flag=1, today=false, date=2018-12-31}
{flag=1, today=false, date=2019-01-01}
{flag=1, today=false, date=2019-01-02}
{flag=1, today=false, date=2019-01-03}
{flag=1, today=false, date=2019-01-04}
//10天为周期,当前日期为连续第8天 结果
{flag=0, today=false, date=2018-12-19}
{flag=0, today=false, date=2018-12-20}
{flag=0, today=false, date=2018-12-21}
{flag=0, today=false, date=2018-12-22}
{flag=0, today=false, date=2018-12-23}
{flag=0, today=false, date=2018-12-24}
{flag=0, today=false, date=2018-12-25}
{flag=0, today=true, date=2018-12-26}
{flag=1, today=false, date=2018-12-27}
{flag=1, today=false, date=2018-12-28}
//10天为周期,当前日期为连续第14天 结果
{flag=0, today=false, date=2018-12-23}
{flag=0, today=false, date=2018-12-24}
{flag=0, today=false, date=2018-12-25}
{flag=0, today=true, date=2018-12-26}
{flag=1, today=false, date=2018-12-27}
{flag=1, today=false, date=2018-12-28}
{flag=1, today=false, date=2018-12-29}
{flag=1, today=false, date=2018-12-30}
{flag=1, today=false, date=2018-12-31}
{flag=1, today=false, date=2019-01-01}
//10天为周期,当前日期为连续第25天 结果
{flag=0, today=false, date=2018-12-22}
{flag=0, today=false, date=2018-12-23}
{flag=0, today=false, date=2018-12-24}
{flag=0, today=false, date=2018-12-25}
{flag=0, today=true, date=2018-12-26}
{flag=1, today=false, date=2018-12-27}
{flag=1, today=false, date=2018-12-28}
{flag=1, today=false, date=2018-12-29}
{flag=1, today=false, date=2018-12-30}
{flag=1, today=false, date=2018-12-31}

第二种方法:

@org.junit.Test
public void test(){
    List<String> days = getDays(new Date(),3,7); // 7天为周期,今天是第三天
    for (String day : days) {
        System.out.println(day);
    }
}
	    
public List<String> getDays(Date date, int current, int cycle) {
    List<String> days = new ArrayList<String>();
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    Calendar calendar = getCalendar(date, current, cycle);
    for (int i = 0; i < cycle; i++) {
        days.add(format.format(calendar.getTime()));
        calendar.add(Calendar.DAY_OF_MONTH, 1);//增加一天
    }
    return days;
}
	    
public Calendar getCalendar(Date date, int current, int cycle) {
    if(current <= 0 || cycle <= 0 || date == null){
        throw new IllegalArgumentException("参数异常");
    }
	    	
    Calendar now = Calendar.getInstance();
    Calendar calendarNow = new GregorianCalendar();
    calendarNow.setTime(date);
	        
    int index = 1;
    current = current % cycle == 0 ? cycle : (current % cycle);
    index = index - current;

    calendarNow.add(Calendar.DAY_OF_MONTH, index);
    now.set(calendarNow.get(Calendar.YEAR), calendarNow.get(Calendar.MONTH), calendarNow.get(Calendar.DATE));
	        
    Calendar calendar = Calendar.getInstance();
    calendar.setFirstDayOfWeek(Calendar.MONDAY);
    calendar.set(calendarNow.get(Calendar.YEAR), calendarNow.get(Calendar.MONTH), calendarNow.get(Calendar.DATE));
    return calendar;
}

测试结果:

WebLogic和Fastjson反序列化漏洞是两个独立的漏洞,但它们都涉及到Java反序列化安全问题。我会分别给你介绍这两个漏洞原理复现方法。 1. WebLogic反序列化漏洞原理分析及复现: WebLogic反序列化漏洞是指通过利用WebLogic Server中T3协议的漏洞,攻击者可以在目标服务器上执行任意代码。这个漏洞的根本原因是WebLogic Server在处理T3协议时未正确过滤用户提供的数据,导致攻击者可以构造恶意的序列化数据,在服务器端触发反序列化漏洞复现漏洞的步骤如下: 1) 下载并配置WebLogic Server环境。 2) 使用ysoserial工具生成payload,例如利用CommonsCollections的payload。 3) 构造T3协议请求,将生成的payload嵌入到请求中。 4) 启动WebLogic Server,并发送恶意请求。 5) 成功触发反序列化漏洞后,攻击者可以执行任意代码。 2. Fastjson反序列化漏洞原理分析及复现Fastjson是一个常用的Java JSON库,该漏洞存在于Fastjson的版本1.2.24及之前的版本中。攻击者可以通过构造恶意的JSON数据,触发Fastjson反序列化漏洞,从而执行任意代码。 漏洞的原因是Fastjson反序列化JSON数据时,对默认类型进行了自动化检测和加载,并且允许调用类的默认构造函数,从而导致了代码执行漏洞。攻击者可以通过构造恶意的JSON数据,在目标服务器上执行任意代码。 复现漏洞的步骤如下: 1) 下载并配置Fastjson版本1.2.24或之前的环境。 2) 使用ysoserial工具生成payload,例如利用CommonsCollections的payload。 3) 构造恶意的JSON数据,将生成的payload嵌入到JSON中。 4) 编写测试代码,使用Fastjson进行反序列化操作。 5) 执行测试代码,成功触发反序列化漏洞后,攻击者可以执行任意代码。 请注意,漏洞利用是非法行为,仅在授权范围内进行安全测试和研究。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值