package com.gxwebsoft.oa.service.impl;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.oa.mapper.OaAssetsSslMapper;
import com.gxwebsoft.oa.service.OaAssetsSslService;
import com.gxwebsoft.oa.entity.OaAssetsSsl;
import com.gxwebsoft.oa.param.OaAssetsSslParam;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * ssl证书Service实现
 *
 * @author 科技小王子
 * @since 2024-10-18 19:25:40
 */
@Service
public class OaAssetsSslServiceImpl extends ServiceImpl<OaAssetsSslMapper, OaAssetsSsl> implements OaAssetsSslService {

    @Override
    public PageResult<OaAssetsSsl> pageRel(OaAssetsSslParam param) {
        PageParam<OaAssetsSsl, OaAssetsSslParam> page = new PageParam<>(param);
        page.setDefaultOrder("create_time desc");
        List<OaAssetsSsl> list = baseMapper.selectPageRel(page, param);
        list.forEach(d -> {
          // 即将过期(一周内过期的)
          d.setSoon(DateUtil.offsetDay(d.getEndTime(), -7).compareTo(DateUtil.date()));
          // 是否过期 -1已过期 大于0 未过期
          d.setStatus(d.getEndTime().compareTo(DateUtil.date()));
        });
        return new PageResult<>(list, page.getTotal());
    }

    @Override
    public List<OaAssetsSsl> listRel(OaAssetsSslParam param) {
        List<OaAssetsSsl> list = baseMapper.selectListRel(param);
        // 排序
        PageParam<OaAssetsSsl, OaAssetsSslParam> page = new PageParam<>();
        page.setDefaultOrder("create_time desc");
        return page.sortRecords(list);
    }

    @Override
    public OaAssetsSsl getByIdRel(Integer sslId) {
        OaAssetsSslParam param = new OaAssetsSslParam();
        param.setSslId(sslId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
