package thyyxxk.webserver.controller.singlepage;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import thyyxxk.webserver.config.auth.PassToken;
import thyyxxk.webserver.dao.his.singlepage.TodayClinicResourceDao;
import thyyxxk.webserver.entity.ResultVo;
import thyyxxk.webserver.entity.singlepage.todayclinicresource.ClinicResource;
import thyyxxk.webserver.utils.ResultVoUtil;

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

@RestController
@RequestMapping("/todayClinicResource")
public class TodayClinicResourceController {
    private final TodayClinicResourceDao dao;

    @Autowired
    public TodayClinicResourceController(TodayClinicResourceDao dao) {
        this.dao = dao;
    }

    @PassToken
    @GetMapping("/selectTodayClinicResource")
    public ResultVo<List<ClinicResource>> selectTodayClinicResource() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DAY_OF_YEAR, 1);
        Date date = calendar.getTime();
        String currentDay = sdf.format(new Date());
        String nextDay = sdf.format(date);
        return ResultVoUtil.success(dao.selectTodayClinicResource(currentDay, nextDay));
    }
}
