[代码解析0005] Hutool 工具包 DateUtil 日期类

1、代码片段

    /**
     * 查询需要提醒检验的工具集合
     */
    @ApiOperation("查询需要提醒检验的工具集合")
    @GetMapping("/expireList")
    public AjaxResult expireList(ToolCase toolCase) {
        // 提前通知提醒的天数
        int beforeDays = Integer.parseInt(ConfigUtils.getConfig("tool-check-before-days"));
        DateTime dateTime = DateUtil.offsetDay(new Date(), beforeDays);
        toolCase.setNextCheckTime(dateTime);
        return AjaxResult.success(toolCaseService.selectExpireToolCaseList(toolCase));
    }

2、涉及源码

hutool工具包 DateUtil

  	/**
  	 * 偏移天
  	 *
  	 * @param date   日期
  	 * @param offset 偏移天数,正数向未来偏移,负数向历史偏移
  	 * @return 偏移后的日期
  	 */
  	public static DateTime offsetDay(Date date, int offset) {
  		return offset(date, DateField.DAY_OF_YEAR, offset);
  	}

ConfigUtils.getConfig

package com.ruoyi.system.utils;

import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.system.service.ISysConfigService;

public class ConfigUtils {
    private static ISysConfigService configService = SpringUtils.getBean(ISysConfigService.class);

    /**
     * 依据参数键名获取键值
     *
     * @param key 键名
     * @return 键值
     */
    public static String getConfig(String key) {
        return configService.selectConfigByKey(key);
    }
}

3、涉及知识点

posted @ 2022-07-29 17:21  Code7Rain  阅读(176)  评论(0编辑  收藏  举报