package org.linlinjava.jz.db.service;

import org.linlinjava.jz.db.dao.ContractSubTemplateMapper;
import org.linlinjava.jz.db.domain.ContractSubTemplate;
import org.linlinjava.jz.db.domain.ContractSubTemplateExample;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * @author fuxubing
 */
@Service
public class ContractSubTemplateService {
    @Resource
    private ContractSubTemplateMapper contractSubTemplateMapper;

    public ContractSubTemplate selectByOrderNo(String orderNo) {
        ContractSubTemplateExample example = new ContractSubTemplateExample();
        example.or().andOrderNoEqualTo(orderNo);
        return contractSubTemplateMapper.selectOneByExample(example);
    }

    public boolean isBefore(String orderNo, LocalDate date) {
        ContractSubTemplate contractSubTemplate = selectByOrderNo(orderNo);
        boolean isBefore = false;
        if (null != contractSubTemplate) {
            LocalDateTime serviceStartTime = contractSubTemplate.getServiceStartTime();
            if (date.isBefore(serviceStartTime.toLocalDate())) {
                isBefore = true;
            }
        }
        return isBefore;
    }
}
