package com.mortals.xhx.module.check.service.impl;

import com.mortals.framework.util.StringUtils;
import com.mortals.xhx.module.check.dao.CheckAllRecordDao;
import com.mortals.xhx.module.check.model.CheckAllRecordQuery;
import com.mortals.xhx.module.check.model.vo.CheckAllRecordVo;
import com.mortals.xhx.module.check.service.CheckAllRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;

@Service("checkAllRecordService")
@Slf4j
public class CheckAllRecordServiceImpl implements CheckAllRecordService {

    @Autowired
    private CheckAllRecordDao checkAllRecordDao;

    @Override
    public List<CheckAllRecordVo> getAllCheckRecord(CheckAllRecordQuery query) {
        if(StringUtils.isEmpty(query.getCheckTimeStart())||StringUtils.isEmpty(query.getCheckTimeStart())){
            SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");
            Calendar calendar=Calendar.getInstance();
            calendar.set(Calendar.DAY_OF_MONTH, 1);
            String startTime = format.format(calendar.getTime());
            calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
            String endTime = format.format(calendar.getTime());
            query.setCheckTimeStart(startTime);
            query.setCheckTimeEnd(endTime);
        }
        return checkAllRecordDao.getAllCheckRecord(query);
    }
}
