package io.hmit.modules.appointment.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.hmit.common.service.impl.CrudServiceImpl;
import io.hmit.common.utils.ConvertUtils;
import io.hmit.common.utils.DateUtils;
import io.hmit.modules.appointment.dao.CalendarDao;
import io.hmit.modules.appointment.dto.CalendarDTO;
import io.hmit.modules.appointment.entity.CalendarEntity;
import io.hmit.modules.appointment.service.CalendarService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 日历表
 *
 * @author zsh 408538940@qq.com
 * @since 1.0.0 2021-03-04
 */
@Service
public class CalendarServiceImpl extends CrudServiceImpl<CalendarDao, CalendarEntity, CalendarDTO> implements CalendarService {

    @Override
    public QueryWrapper<CalendarEntity> getWrapper(Map<String, Object> params){
        String id = (String)params.get("id");

        QueryWrapper<CalendarEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(id), "id", id);

        return wrapper;
    }


    @Override
    public List<CalendarDTO> weekDayList() {
        String now = DateUtils.format(new Date());
        List<CalendarEntity> calendarList = baseDao.selectList(new QueryWrapper<CalendarEntity>().gt("day",now)
        .ne("holiday",1).ne("holiday",2));

        return ConvertUtils.sourceToTarget(calendarList,CalendarDTO.class);
    }
}
