AI在开发过程中的

1.描述需求

写一个定时任务,清除表里面的记录信息

2.自己简单书写

/**
     * 校验记录结果清理
     */
    @Scheduled(cron =  "0 0 1 * * ?")
    public void deleteRetrievalLogTask(){
        logger.info("deleteRetrievalLogTask start time,{}",System.currentTimeMillis());
        //上上个月开始时间
        String startDate = new SimpleDateFormat("yyyy-MM-dd").format();
        //上上个月结束时间
        String endDate = new SimpleDateFormat("yyyy-MM-dd").format();
        //查询记录
        enpRetrievalLogMapper.deleteByRetTime(startDate, endDate);
        logger.info("deleteRetrievalLogTask end time,{}",System.currentTimeMillis());
    } 

3.AI帮写

优化后的结果

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

@Component
public class LogCleanupService {

    private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(LogCleanupService.class);

    @Scheduled(cron = "0 0 0 1 * ?") // 每个月的第一天凌晨0点执行
    public void deleteRetrievalLogTask() {
        long startTime = System.currentTimeMillis();
        logger.info("deleteRetrievalLogTask started at {}", startTime);

        // 计算上上个月的第一天和最后一天
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.MONTH, -2); // 上上个月
        cal.set(Calendar.DAY_OF_MONTH, 1); // 月份的第一天
        Date startDate = cal.getTime();

        cal.add(Calendar.MONTH, 1); // 月份的最后一天
        Date endDate = cal.getTime();

        // 使用格式化器格式化日期
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String formattedStartDate = sdf.format(startDate);
        String formattedEndDate = sdf.format(endDate);

        // 执行删除操作
        enpRetrievalLogMapper.deleteByRetTime(formattedStartDate, formattedEndDate);

        long endTime = System.currentTimeMillis();
        logger.info("deleteRetrievalLogTask completed at {} in {} ms", endTime, (endTime - startTime));
    }

    // 假设这是你的Mapper接口,你需要实现deleteByRetTime方法
    public interface EnpRetrievalLogMapper {
        void deleteByRetTime(String startDate, String endDate);
    }
}

4.总结

(1)支持错误信息修改

(2)信息完善

(3)自动添加注释

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值