package com.qy.worksheetsystem.controller;


import com.qy.worksheetsystem.entity.AppProJect;
import com.qy.worksheetsystem.entity.Poject;
import com.qy.worksheetsystem.model.MessageResult;
import com.qy.worksheetsystem.model.MessageResultV2;
import com.qy.worksheetsystem.service.impl.EmployeeReportingServiceImpl;
import com.qy.worksheetsystem.util.JWTUtil;

import com.qy.worksheetsystem.vo.InsertJobBookingEnteyVO;
import com.qy.worksheetsystem.vo.InsertJobBookingVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.time.LocalDate;

import java.time.Month;
import java.time.format.DateTimeFormatter;
import java.util.*;

/**
 * description: EmployeeReportingController <br>
 * date: 2022/3/10 14:42 <br>
 * author: lhbj <br>
 * version: 1.0 <br>
 */
@Slf4j
@RestController
@RequestMapping("/timeSheet")
@Api(value = "员工报工", tags = "员工报工")
public class EmployeeReportingController {

    @Value("${HR.AttendanceType}")
    private String AttendanceType;

    @Autowired
    private EmployeeReportingServiceImpl service;
    @ApiOperation(value = "员工报工专员新增", notes = "员工报工专员新增")
    @RequestMapping(value = "/insertV3", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"),
    })
    public MessageResult insertV3(@RequestHeader("token") String token, @RequestBody InsertJobBookingVO param
    ) {
        try {
            String beginTime = param.getBeginTime();
            String endTime = param.getEndTime();
            String workingHours = param.getWorkingHours();
            String state = param.getState();

//        List<InsertJobBookingEnteyVO> attendanceList = param.getTimes();
//        String projectId = param.getProjectId();

            Map<String, Object> map = new HashMap<>();
            String number = JWTUtil.getNumber(token);
            if (StringUtils.isEmpty(number)) {
                return MessageResult.error("token异常");
            }

            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            //校验日期
            Date beginDate = format.parse(beginTime);
            map.put("beginDate", beginDate);
            Date endDate = format.parse(endTime);
            map.put("endDate", endDate);
            Map<String, Object> person = service.getShrPersonInfo(number);
            Date enterDate = (Date) person.get("enterDate");
            if(enterDate.compareTo(beginDate)>0){
                return MessageResult.error("不能填报，入职日期之前的日期！");
            }

            Integer Hours = 0;

            List<InsertJobBookingEnteyVO> attendanceList = param.getTimes();
            for (InsertJobBookingEnteyVO enteyVO : attendanceList) {
                String attendanceType = enteyVO.getAttendanceType();
                param.setAttendanceType(attendanceType);
                if(StringUtils.isEmpty(param.getAttendanceType())){
                    return MessageResult.error("考勤类型为空异常！");
                }
                map.put("attendanceType", attendanceType);
                int Hour = Integer.valueOf(enteyVO.getWorkingHours());
                Hours += Hour;
                if (AttendanceType.equals(param.getAttendanceType())) {
                    MessageResult result = service.checkAttWinter(number, beginTime, endTime, Hour);
                    if (result.getCode() != 200) {
                        return result;
                    }
                }

            }
            if (Hours > 8) {
                return MessageResult.error("报工小时数不能大于8小时");
            }
            workingHours = Hours.toString();
            param.setWorkingHours(workingHours);
            String projectId = param.getProjectId();
            if (StringUtils.isBlank(projectId)) {
                return MessageResult.error("项目id为空");
            }
            map.put("number", number);
            map.put("beginTime", beginTime);
            map.put("endTime", endTime);
            //每月7号24点为工时申报截点，不能申报上个月的工时

//            if (!service.checkAvailableDate(beginTime)) {
//                return MessageResult.error("已过7号，不能填报上个月！");
//            }
            map.put("workingHours", workingHours);
            map.put("projectId", projectId);
            map.put("state", state);
            System.out.println(param);
            List<Map<String, Object>> list = service.getPPWorkDetail(map);
            StringBuilder errMsg = new StringBuilder();
            for (Map<String, Object> temp : list) {
                if (null != temp.get("workingHours")) {
                    String cfcalendarType = temp.get("cfcalendarType").toString();
                    String working = temp.get("workingHours").toString();
                    if (!("0".equals(cfcalendarType))) {
                        errMsg.append("\r\n");
                        errMsg.append(temp.get("CFYsName") + "_" + temp.get("CFReportDate") + "员工：" + temp.get("CFNameAndNumber") + ",已填报(休息日/节假日)!");
                    }
                    if ((Integer.parseInt(working) + Hours) > 8) {
                        errMsg.append("\r\n");
                        errMsg.append(temp.get("CFYsName") + "_" + temp.get("CFReportDate") + "员工：" + temp.get("CFNameAndNumber") + ",已填报" + working + "小时,不能再填报" + workingHours + "; ");
                    }
                }
            }
            if (errMsg.length() > 1) {
                MessageResult result = new MessageResult();
                result.setCode(500);
                result.setMsg(errMsg.toString());
                return result;
            }

            return service.insertV3(number, param);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
            return MessageResult.error(e.getMessage());
        }
    }

    @ApiOperation(value = "员工报工新增", notes = "员工报工新增")
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"),
    })
    public MessageResult insert(@RequestHeader("token") String token, @RequestBody InsertJobBookingVO param
    ) {
        try {
            String beginTime = param.getBeginTime();
            String endTime = param.getEndTime();
            String workingHours = param.getWorkingHours();
            String state = param.getState();

//        List<InsertJobBookingEnteyVO> attendanceList = param.getTimes();
//        String projectId = param.getProjectId();

            Map<String, Object> map = new HashMap<>();
            String number = JWTUtil.getNumber(token);
            if (StringUtils.isEmpty(number)) {
                return MessageResult.error("token异常");
            }

            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            //校验日期
            Date beginDate = format.parse(beginTime);
            map.put("beginDate", beginDate);
            Date endDate = format.parse(endTime);
            map.put("endDate", endDate);
            Map<String, Object> person = service.getShrPersonInfo(number);
            Date enterDate = (Date) person.get("enterDate");
            if(enterDate.compareTo(beginDate)>0){
                return MessageResult.error("不能填报，入职日期之前的日期！");
            }

            Integer Hours = 0;

            List<InsertJobBookingEnteyVO> attendanceList = param.getTimes();
            for (InsertJobBookingEnteyVO enteyVO : attendanceList) {
                String attendanceType = enteyVO.getAttendanceType();
                param.setAttendanceType(attendanceType);
                if(StringUtils.isEmpty(param.getAttendanceType())){
                    return MessageResult.error("考勤类型为空异常！");
                }
                map.put("attendanceType", attendanceType);
                int Hour = Integer.valueOf(enteyVO.getWorkingHours());
                Hours += Hour;
                if (AttendanceType.equals(param.getAttendanceType())) {
                    MessageResult result = service.checkAttWinter(number, beginTime, endTime, Hour);
                    if (result.getCode() != 200) {
                        return result;
                    }
                }

            }
            if (Hours > 8) {
                return MessageResult.error("报工小时数不能大于8小时");
            }
            workingHours = Hours.toString();
            param.setWorkingHours(workingHours);
            String projectId = param.getProjectId();
            if (StringUtils.isBlank(projectId)) {
                return MessageResult.error("项目id为空");
            }
            map.put("number", number);
            map.put("beginTime", beginTime);
            map.put("endTime", endTime);
            //每月7号24点为工时申报截点，不能申报上个月的工时

            if (!service.checkAvailableDate(beginTime)) {
               return MessageResult.error("已过7号，不能填报上个月！");
            }
            map.put("workingHours", workingHours);
            map.put("projectId", projectId);
            map.put("state", state);
            System.out.println(param);
            List<Map<String, Object>> list = service.getPPWorkDetail(map);
            StringBuilder errMsg = new StringBuilder();
            for (Map<String, Object> temp : list) {
                if (null != temp.get("workingHours")) {
                    String cfcalendarType = temp.get("cfcalendarType").toString();
                    String working = temp.get("workingHours").toString();
                    if (!("0".equals(cfcalendarType))) {
                        errMsg.append("\r\n");
                        errMsg.append(temp.get("CFYsName") + "_" + temp.get("CFReportDate") + "员工：" + temp.get("CFNameAndNumber") + ",已填报(休息日/节假日)!");
                    }
                    if ((Integer.parseInt(working) + Hours) > 8) {
                        errMsg.append("\r\n");
                        errMsg.append(temp.get("CFYsName") + "_" + temp.get("CFReportDate") + "员工：" + temp.get("CFNameAndNumber") + ",已填报" + working + "小时,不能再填报" + workingHours + "; ");
                    }
                }
            }
            if (errMsg.length() > 1) {
                MessageResult result = new MessageResult();
                result.setCode(500);
                result.setMsg(errMsg.toString());
                return result;
            }

            return service.insertV2(number, param);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
            return MessageResult.error(e.getMessage());
        }


    }

    @ApiOperation(value = "3.9 指定日期驳回、通过", notes = "只需要传：detailId，state")
    @PostMapping("/approvalProject")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"),
    })
    public MessageResult approvalProject(@RequestHeader("token") String token, @RequestBody AppProJect appProJect) {
        try {
            String number = JWTUtil.getNumber(token);
            if (StringUtils.isEmpty(number)) {
                return MessageResult.error("请登录！");
            }
            switch (appProJect.getStatus()) {
                case "3":
                    break;
                case "4":
                    break;
                default:
                    return MessageResult.error("提交状态异常:只能提交（3：通过；4：驳回;）;");
            }

            return service.approvalProject(number, appProJect);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
            return MessageResult.error(e.getMessage());
        }
    }


    @ApiOperation(value = "获取员工月份报工明细", notes = "获取员工月份报工明细")
    @RequestMapping(value = "/getPersonWorkDetail", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"),
            @ApiImplicitParam(name = "month", value = "报工月份字符串，格式：yyyy-MM", required = true, paramType = "query", dataType = "String")
    })
    public MessageResult getPersonWorkDetail(@RequestHeader("token") String token, String month) {
        try {
            Map<String, Object> map = new HashMap<>();
            String number = JWTUtil.getNumber(token);
            if (StringUtils.isEmpty(number)) {
                return MessageResult.error("token异常");
            }
            if (StringUtils.isEmpty(month)) {
                return MessageResult.error("month为空");
            }
            if (!(month.length() == 7)) {
                return MessageResult.error("month(yyyy-MM)格式异常:" + month);
            }
            String[] monthArr = month.split("-");
            if (null == monthArr[0] || null == monthArr[0]) {
                return MessageResult.error("month格式异常:" + month);
            }
            if (Integer.parseInt(monthArr[0]) <= 1000 || Integer.parseInt(monthArr[1]) < 1 || Integer.parseInt(monthArr[1]) > 12) {
                return MessageResult.error("month格式异常:" + month);
            }
            Map<String, Object> result = service.getPersonWorkDetail(number, month);
            MessageResult messageResult = MessageResult.success();
            messageResult.setData(result);
            return messageResult;
        } catch (Exception e) {
            log.error(e.getMessage(),e);
            return MessageResult.error(e.getMessage());
        }
    }

    @ApiOperation(value = "获取报工明细数据(审核)", notes = "获取报工明细数据(审核)")
    @RequestMapping(value = "/getTimeSheetDetail", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"),
            @ApiImplicitParam(name = "projectId", value = "项目id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "month", value = "月份(yyyy-MM)", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "audited", value = "是否审核", paramType = "query", dataType = "Boolean")

    })
    public MessageResult getTimeSheetDetail(@RequestHeader("token") String token, String projectId, String month, Boolean audited) {
        try {
            String number = JWTUtil.getNumber(token);
            if (StringUtils.isEmpty(number)) {
                return MessageResult.error("token异常");
            }
            if (StringUtils.isEmpty(month)) {
                return MessageResult.error("month为空");
            }
            if (!(month.length() == 7)) {
                return MessageResult.error("month(yyyy-MM)格式异常:" + month);
            }
            String[] monthArr = month.split("-");
            if (null == monthArr[0] || null == monthArr[0]) {
                return MessageResult.error("month格式异常:" + month);
            }
            if (Integer.parseInt(monthArr[0]) <= 1000 || Integer.parseInt(monthArr[1]) < 1 || Integer.parseInt(monthArr[1]) > 12) {
                return MessageResult.error("month格式异常:" + month);
            }
            String state = "";
            if (null != audited) {
                if (audited) {
                    state = "1";
                } else {
                    state = "0";
                }
            }
            Poject poject = service.getTimeSheetDetailV2(number, projectId, month, state);
            MessageResultV2 messageResult = MessageResultV2.success();
            messageResult.setData(poject);
            return messageResult;
        } catch (Exception e) {
            log.error(e.getMessage(),e);
            return MessageResultV2.error(e.getMessage());
        }
    }

    @ApiOperation(value = "获取员工当前月份报工单", notes = "获取员工当前月份报工单")
    @RequestMapping(value = "/getMonthWorkSheet", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"),
            @ApiImplicitParam(name = "month", value = "月份(yyyy-MM)", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "committed", value = "", paramType = "query", dataType = "Boolean")

    })
    public MessageResult getMonthWorkSheet(@RequestHeader("token") String token, String month, Boolean committed) {
        try {


            String number = JWTUtil.getNumber(token);
            if (StringUtils.isEmpty(number)) {
                return MessageResult.error("token异常");
            }
            if (StringUtils.isEmpty(month)) {
                return MessageResult.error("month为空");
            }
            if (!(month.length() == 7)) {
                return MessageResult.error("month(yyyy-MM)格式异常:" + month);
            }
            String[] monthArr = month.split("-");
            if (null == monthArr[0] || null == monthArr[0]) {
                return MessageResult.error("month格式异常:" + month);
            }
            if (Integer.parseInt(monthArr[0]) <= 1000 || Integer.parseInt(monthArr[1]) < 1 || Integer.parseInt(monthArr[1]) > 12) {
                return MessageResult.error("month格式异常:" + month);
            }
            String state = "";
            if (null != committed) {
                if (committed) {
                    state = "1";
                } else {
                    state = "0";
                }
            }
            List<Map<String, Object>> list = service.getMonthWorkSheet(number, month, state);
            MessageResultV2 messageResult = MessageResultV2.success();
            messageResult.setData(list);
            return messageResult;
        } catch (Exception e) {
            log.error(e.getMessage(),e);
            return MessageResult.error(e.getMessage());
        }
    }

    @ApiOperation(value = "删除员工当前月份报工单", notes = "删除员工当前月份报工单")
    @RequestMapping(value = "/deleteSheet", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"),
    })
    public MessageResult deleteSheet(@RequestHeader("token") String token, @RequestBody Map<String, String> timeSheetId) {
        try {


            String number = JWTUtil.getNumber(token);
            if (StringUtils.isEmpty(number)) {
                return MessageResult.error("token异常");
            }
            String id = (String) timeSheetId.get("timeSheetId");
            if (StringUtils.isEmpty(id)) {
                return MessageResult.error("timeSheetId异常");
            }
            return service.deleteSheet(number, id);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
            return MessageResult.error(e.getMessage());
        }
    }

    @ApiOperation(value = "获取审核员待办、已办", notes = "获取审核员待办、已办")
    @RequestMapping(value = "/getAudited", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"),
            @ApiImplicitParam(name = "audited", value = "是否已经审核", required = true, paramType = "query", dataType = "Boolean"),
            @ApiImplicitParam(name = "month", value = "月份(yyyy-MM)",  paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "page", value = "页码", paramType = "query", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "size", value = "每页条数", paramType = "query", required = true, dataType = "Integer")
    })
    public MessageResult getAudited(@RequestHeader("token") String token, Boolean audited,String month, Integer page, Integer size) {
        try {

            String number = JWTUtil.getNumber(token);
            if (StringUtils.isEmpty(number)) {
                return MessageResult.error("token异常");
            }
            String audit = "";
            if (null != audited) {
                if (audited) {
                    audit = "1";
                } else {
                    audit = "0";
                }
            }
            if (StringUtils.isEmpty(month)) {
                return MessageResult.error("month为空");
            }
            if (!(month.length() == 7)) {
                return MessageResult.error("month(yyyy-MM)格式异常:" + month);
            }
            String[] monthArr = month.split("-");
            if (null == monthArr[0] || null == monthArr[0]) {
                return MessageResult.error("month格式异常:" + month);
            }
            if (Integer.parseInt(monthArr[0]) <= 1000 || Integer.parseInt(monthArr[1]) < 1 || Integer.parseInt(monthArr[1]) > 12) {
                return MessageResult.error("month格式异常:" + month);
            }
            return service.getAudited(number, month,audit, page, size);

        } catch (Exception e) {
            log.error(e.getMessage(),e);
            return MessageResult.error(e.getMessage());
        }
    }
    @ApiOperation(value = "new]获取指定员工的审核员待办、已办列表", notes = "new]获取指定员工的审核员待办、已办列表(判断当前审核员是否有该员工的审核权限)")
    @RequestMapping(value = "/getEmpAudited", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"),
            @ApiImplicitParam(name = "audited", value = "是否未经审核",  paramType = "query", dataType = "Boolean"),
            @ApiImplicitParam(name = "empNumber", value = "指定员工工号",  paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "month", value = "月份(yyyy-MM)", required = true,  paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "page", value = "页码", paramType = "query", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "size", value = "每页条数", paramType = "query", required = true, dataType = "Integer")
    })
    public MessageResult getEmpAudited(@RequestHeader("token") String token, Boolean audited,String empNumber,String month, Integer page, Integer size) {
        try {

            String number = JWTUtil.getNumber(token);
            if (StringUtils.isEmpty(number)) {
                return MessageResult.error("token异常");
            }
            String audit = "";
            if (null != audited) {
                if ( audited) {
                    audit = "1";
                } else {
                    audit = "0";
                }
            }
            if (StringUtils.isEmpty(month)) {
                return MessageResult.error("month为空");
            }
            if (!(month.length() == 7)) {
                return MessageResult.error("month(yyyy-MM)格式异常:" + month);
            }
            String[] monthArr = month.split("-");
            if (null == monthArr[0] || null == monthArr[0]) {
                return MessageResult.error("month格式异常:" + month);
            }
            if (Integer.parseInt(monthArr[0]) <= 1000 || Integer.parseInt(monthArr[1]) < 1 || Integer.parseInt(monthArr[1]) > 12) {
                return MessageResult.error("month格式异常:" + month);
            }
            return service.getEmpAudited(number,empNumber, audit,month, page, size);

        } catch (Exception e) {
            log.error(e.getMessage(),e);
            return MessageResult.error(e.getMessage());
        }
    }

    @ApiOperation(value = "[new]获取审核员待办相关的员工列表", notes = "[new]获取审核员待办相关的员工列表(判断当前审核员是否有该员工的审核权限)")
    @RequestMapping(value = "/getEmpList", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"),
            @ApiImplicitParam(name = "audited", value = "是否已经审核", paramType = "query", dataType = "Boolean"),
            @ApiImplicitParam(name = "month", value = "月份(yyyy-MM)", required = true,  paramType = "query", dataType = "String"),

    })
    public MessageResult getEmpList(@RequestHeader("token") String token, Boolean audited,String month) {
        try {

            String number = JWTUtil.getNumber(token);
            if (StringUtils.isEmpty(number)) {
                return MessageResult.error("token异常");
            }
            String audit = "";
            if (null != audited) {
                if (audited) {
                    audit = "1";
                } else {
                    audit = "0";
                }
            }
            if (StringUtils.isEmpty(month)) {
                return MessageResult.error("month为空");
            }
            if (!(month.length() == 7)) {
                return MessageResult.error("month(yyyy-MM)格式异常:" + month);
            }
            String[] monthArr = month.split("-");
            if (null == monthArr[0] || null == monthArr[0]) {
                return MessageResult.error("month格式异常:" + month);
            }
            if (Integer.parseInt(monthArr[0]) <= 1000 || Integer.parseInt(monthArr[1]) < 1 || Integer.parseInt(monthArr[1]) > 12) {
                return MessageResult.error("month格式异常:" + month);
            }
            return service.getEmpList(number, audit,month, 0, 0);

        } catch (Exception e) {
            log.error(e.getMessage(),e);
            return MessageResult.error(e.getMessage());
        }
    }

    @ApiOperation(value = "根据id获取员工报工信息", notes = "根据id获取员工报工信息")
    @RequestMapping(value = "/getWorkSheetById", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"),
            @ApiImplicitParam(name = "timeSheetId", value = "报工id", required = true, paramType = "query", dataType = "String"),
    })
    public MessageResult getWorkSheetById(@RequestHeader("token") String token, String timeSheetId) {
        try {


            String number = JWTUtil.getNumber(token);
            if (StringUtils.isEmpty(number)) {
                return MessageResult.error("token异常");
            }
            if (StringUtils.isEmpty(timeSheetId)) {
                return MessageResult.error("timeSheetId异常");
            }
            return service.getWorkSheetById(number, timeSheetId);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
            return MessageResult.error(e.getMessage());
        }
    }

    @ApiOperation(value = "校验年假", notes = "校验年假")
    @RequestMapping(value = "/checkAttWinter", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"),
            @ApiImplicitParam(name = "beginTime", value = "开始时间yyyy-MM-dd", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "endTime", value = "结束时间yyyy-MM-dd", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "workingHour", value = "工时", required = true, paramType = "query", dataType = "Integer"),
    })
    public MessageResult checkAttWinter(@RequestHeader("token") String token, String beginTime, String endTime, Integer workingHour) {
        try {

            String number = JWTUtil.getNumber(token);
            if (StringUtils.isEmpty(number)) {
                return MessageResult.error("token异常");
            }
            return service.checkAttWinter(number, beginTime, endTime, workingHour);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
            return MessageResult.error(e.getMessage());
        }
    }

    @ApiOperation(value = "校验可填报日期", notes = "校验可填报日期")
    @RequestMapping(value = "/checkAvailableDate", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"),
            @ApiImplicitParam(name = "beginTime", value = "开始时间yyyy-MM-dd", required = true, paramType = "query", dataType = "String"),
    })
    public MessageResult checkAvailableDate(@RequestHeader("token") String token, String beginTime) {
        try {

            String number = JWTUtil.getNumber(token);
            if (StringUtils.isEmpty(number)) {
                return MessageResult.error("token异常");
            }
            MessageResultV2 resultV2 = MessageResultV2.success();
            resultV2.setData(service.checkAvailableDate(beginTime));
            return resultV2;
        } catch (Exception e) {
            log.error(e.getMessage(),e);
            return MessageResult.error(e.getMessage());
        }
    }

    @ApiOperation(value = "获取员工报工合计", notes = "获取员工报工合计")
    @RequestMapping(value = "/getJobDayByPerson", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"),
            @ApiImplicitParam(name = "month", value = "月份(yyyy-MM)", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "projectId", value = "项目id", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "type", value = "考勤类型id", paramType = "query", dataType = "String"),
    })
    public MessageResult getJobDayByPerson(@RequestHeader("token") String token, String month, String projectId, String type) {
        try {
            String number = JWTUtil.getNumber(token);
            if (StringUtils.isEmpty(number)) {
                return MessageResult.error("token异常");
            }
            if (StringUtils.isEmpty(month)) {
                return MessageResult.error("月份不能为空");
            }
            String[] monthArr = month.split("-");
            int year = Integer.parseInt(monthArr[0]);
            Month month1 = Month.of(Integer.parseInt(monthArr[1]));
            LocalDate beginDate = LocalDate.of(year, month1, 1);
            LocalDate endDate = LocalDate.of(Integer.parseInt(monthArr[0]), month1, month1.length(beginDate.isLeapYear()));
            return service.getJobDayByPerson(number,
                    beginDate.format(DateTimeFormatter.ISO_LOCAL_DATE),
                    endDate.format(DateTimeFormatter.ISO_LOCAL_DATE),
                    projectId, type);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
            return MessageResult.error(e.getMessage());
        }
    }



}
