package com.qy.worksheetsystem.controller;

import com.qy.worksheetsystem.model.MessageResult;
import com.qy.worksheetsystem.model.MessageResultV2;
import com.qy.worksheetsystem.service.WorkSheetService;
import com.qy.worksheetsystem.util.JWTUtil;
import com.qy.worksheetsystem.vo.CancelOnDateVO;
import com.qy.worksheetsystem.vo.WorkSheetVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * date: 2022/3/19 14:42 <br>
 * author: hjb <br>
 * version: 1.0 <br>
 */
@RestController
@RequestMapping("/timeSheet")
@Api(tags = "报工接口:3.10;3.12")
public class WorkSheetController {

    @Autowired
    private WorkSheetService workSheetService;

    @ApiOperation(value = "3.12 员工指定日期撤回", notes = "员工撤回（包括指定日期：指定日期使用detailId,整体单据使用timeSheetId；审核员指定通过的单退回（）；status不需要传")
    @PostMapping("/cancelOnDate")
    @ApiImplicitParams({
            @ApiImplicitParam(name="token",value="token",required=true,paramType="header",dataType="String"),
    })
    public MessageResult cancelOnDate(@RequestHeader("token") String token,@RequestBody CancelOnDateVO cancelOnDateVO) {
        String number = JWTUtil.getNumber(token);
        if(StringUtils.isEmpty(number)){
            return MessageResult.error("请登录！");
        }
        System.out.println(cancelOnDateVO.toString());
        return workSheetService.cancelOnDate(number,cancelOnDateVO);
    }

    @ApiOperation(value = "3.10 指定日期驳回、通过", notes = "只需要传：detailId，state")
    @PostMapping("/appProjectOnDate")
    @ApiImplicitParams({
            @ApiImplicitParam(name="token",value="token",required=true,paramType="header",dataType="String"),
    })
    public MessageResult appProjectOnDate(@RequestHeader("token") String token, @RequestBody CancelOnDateVO cancelOnDateVO) {
        String number = JWTUtil.getNumber(token);
        if(StringUtils.isEmpty(number)){
            return MessageResult.error("请登录！");
        }
        return workSheetService.appProjectOnDate(number,cancelOnDateVO);
    }

    @ApiOperation(value = "3.13 员工修改报工数据", notes = "")
    @PostMapping("/update")
    @ApiImplicitParams({
            @ApiImplicitParam(name="token",value="token",required=true,paramType="header",dataType="String"),
    })
    public MessageResult update(@RequestHeader("token") String token, @RequestBody WorkSheetVO workSheetVO) {
        String number = JWTUtil.getNumber(token);
        if(StringUtils.isEmpty(number)){
            return MessageResult.error("请登录！");
        }
        return workSheetService.update(number,workSheetVO);
    }
}
