package com.qy.worksheetsystem.controller;

import com.qy.worksheetsystem.model.MessageResult;
import com.qy.worksheetsystem.model.MessageResultV2;
import com.qy.worksheetsystem.service.WorkCalendarService;
import com.qy.worksheetsystem.service.YunzhijiaService;
import com.qy.worksheetsystem.util.DateUtil;
import com.qy.worksheetsystem.util.JWTUtil;
import com.qy.worksheetsystem.vo.WorkCalendarVo;
import io.swagger.annotations.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @BelongsProject: workSheetSystem
 * @BelongsPackage: com.qy.worksheetsystem.controller
 * @Author: lhbj
 * @CreateTime: 2024-12-03  16:45
 * @Description: TODO
 * @Version: 1.0
 */
@RestController
@RequestMapping("/work/calendar")
@Api(value = "工作日历",tags="工作日历")
public class WorkCalendarController {

    @Autowired
    private WorkCalendarService workCalendarService;

    @ApiOperation(value = "获取工作日历")
    @GetMapping("/getWorkCalendar")
    @ApiImplicitParams({
            @ApiImplicitParam(name="token",value="token",required=true,paramType="header",dataType="String"),
            @ApiImplicitParam(name="startDate",value="开始日期",required=true,paramType="query",dataType="String"),
            @ApiImplicitParam(name="endDate",value="结束日期",required=true,paramType="query",dataType="String"),
    })

    public MessageResult getWorkCalendar(@RequestHeader("token") String token, String startDate, String endDate) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String number = JWTUtil.getCacheNumber(token);
        if(StringUtils.isEmpty(number)){
            return MessageResultV2.error("token异常");
        }
        int isValid = DateUtil.isValidDate(startDate, endDate);

        if (isValid== 1) {
            return MessageResultV2.error("请输入正确的日期时间，日期格式例如2022-01-01");
        }else if (isValid== 2){
            return MessageResultV2.error("开始时间不能大于结束时间");
        }

        List<WorkCalendarVo> list = workCalendarService.getWorkCalendar(startDate,endDate);
        MessageResultV2<List<WorkCalendarVo>> messageResult= MessageResultV2.success();
        messageResult.setData(list);
        return messageResult;
    }
}
