package com.reptileclient.jlifeapp.service;


import cn.hutool.core.date.DateUtil;
import com.reptileclient.jlifeapp.dao.hm.HmRequestMapper;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

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


@Service
public class HmRequestService {

    @Resource
    private HmRequestMapper hmRequestMapper;

    public int insert(String url) {
        String date = DateUtil.formatDate(new Date());

        //检查是否超过当日最大数量
        Integer requestNum = hmRequestMapper.selectRequestNum(null, date);
        if (requestNum != null && requestNum > 2000) return 0;

        requestNum = hmRequestMapper.selectRequestNum(url, date);
        if (requestNum == null || requestNum == 0)
            hmRequestMapper.insertNum(url, date);
        else hmRequestMapper.updateNum(url, date);

        return 1;
    }

}
