package com.zbf.system.service.impl;

import com.zbf.common.utils.DateUtils;
import com.zbf.system.service.ISysConfigService;
import com.zbf.system.service.ITOverdueService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
 * 参数配置 服务层
 *
 * @author ruoyi
 */
@Service
public class TOverdueServiceImpl implements ITOverdueService {

    @Resource
    ISysConfigService sysConfigService;

    /**
     * 查询参数配置信息中的 overdue.stagnation 参数值
     *
     * @return 参数配置信息
     */
    public int getOverdue() {
        //获取超期呆滞天数
        String overdueStagnationStr = sysConfigService.selectConfigByKey("overdue.stagnation");
        int overdue = 0;
        if (StringUtils.isNotEmpty(overdueStagnationStr)) {
            overdue = Integer.valueOf(overdueStagnationStr);
        }
        return overdue;
    }

    /***
     * 获取当前日期与超期呆滞参数的数量，如果不存在呆滞天数，则返回0
     * */
    public String getOverdueFromToday() {
        int overdueDays = getOverdue();
        //获取超期呆滞日期前的日期
        if (overdueDays != 0) {
            Date overdueDate = DateUtils.addDays(new Date(), -overdueDays);
            String overdueDateStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, overdueDate);
            return overdueDateStr;
        }
        return "";
    }


}
