栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

springboot定时任务 修改优惠券是否有效 和过期后7天不展示优惠券 及单表条件构造器的使用

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

springboot定时任务 修改优惠券是否有效 和过期后7天不展示优惠券 及单表条件构造器的使用

 */
@Configuration
@EnableScheduling
public class TaskManger {


    @Autowired
    ZyCouponRecordServiceImpl zyCouponRecorService;



    @Scheduled(cron = "0 0 0 * * ?")
    public void billTask( ) {
        List zyCouponRecords =new ArrayList<>();
        List zyCouponRecordlist = zyCouponRecorService.lambdaQuery().eq(ZyCouponRecord::getRecordState, 0).list();
        System.out.println(zyCouponRecordlist.size()+"zyCouponRecordlist");
        for (int a=0;a

            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            String formatDate = sdf.format(zyCouponRecordlist.get(a).getCtime());
          if( DateUtil.getdatas(zyCouponRecordlist.get(a).getRecordCouponTerm()).equals(formatDate) ){
              zyCouponRecordlist.get(a).setRecordState(2);
              zyCouponRecords.add(zyCouponRecordlist.get(a));
          }
        }

        zyCouponRecorService.updateBatchById(zyCouponRecords);

    }




    
    @Scheduled(cron = "0 30 0 * * ?")
    public void Task( ) {

        zyCouponRecorService.lambdaUpdate()
                .ne(ZyCouponRecord::getRecordState,0)
                .eq(ZyCouponRecord::getRecordDisplay, 0)
                .eq(ZyCouponRecord::getEtime,DateUtil.getSevenAgo())
                .set(ZyCouponRecord::getRecordDisplay, 1).update();



    }
}

时间转换工具

import org.apache.commons.lang3.time.DateUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;


public class DateUtil {
    public static void main(String[] args) {
        System.out.println(getSixMonth());
    }

    public static String getToday() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String format = sdf.format(new Date());
        return format;
    }

    public static String getBillId() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        String format = sdf.format(new Date());
        return format;
    }

    public static String getSevenAgo() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date = DateUtils.addDays(new Date(), -2);
        String formatDate = sdf.format(date);
        return formatDate;
    }

    public static boolean getDayBetweenTwoDate(String startDateStr, String endDateStr) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        boolean b = false;
        try {
            Date startDate = simpleDateFormat.parse(startDateStr);
            Date endDate = simpleDateFormat.parse(endDateStr);
            Calendar startCalendar = Calendar.getInstance();
            startCalendar.setTime(startDate);
            Calendar endCalendar = Calendar.getInstance();
            endCalendar.setTime(endDate);
            //计算两个日期相差的天数
            //startCalendar.getTime().getTime()返回long毫秒数形式,毫秒转为秒所以除以1000
            //1天=24小时,1小时=60分,1分=60秒,所以两个时间的差再除以60 * 60 * 24换算成天的形式
            int days = ((int) (startCalendar.getTime().getTime() / 1000) - (int) (endCalendar.getTime().getTime() / 1000)) / (60 * 60 * 24);
            if (days < 7) {
                b = true;
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return b;
    }

    //获取近七天日期
    public static List getSevenDate() {
        List dateList = new ArrayList<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        for (int i = 0; i < 7; i++) {
            Date date = DateUtils.addDays(new Date(), -i);
            String formatDate = sdf.format(date);
            dateList.add(formatDate);
        }
        return dateList;
    }

    //获取近一个月日期
    public static List getOneMonth() {
        List dateList = new ArrayList<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        for (int i = 0; i < 30; i++) {
            Date date = DateUtils.addDays(new Date(), -i);
            String formatDate = sdf.format(date);
            dateList.add(formatDate);
        }
        return dateList;
    }

    //获取近半年内月份
    public static List getSixMonth() {
        List dateList = new ArrayList<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        for (int i = 0; i < 6; i++) {
            Date date = DateUtils.addMonths(new Date(), -i);
            String formatDate = sdf.format(date);
            dateList.add(formatDate);
        }
        return dateList;
    }

    public static String getLastMonth() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        Date date = DateUtils.addMonths(new Date(), -1);
        String formatDate = sdf.format(date);
        return formatDate;
    }


    public static String getdatas(int a) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date = DateUtils.addDays(new Date(), -a);
        String formatDate = sdf.format(date);
        return formatDate;
    }
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/981475.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号