package com.qy.worksheetsystem.controller;

import com.qy.worksheetsystem.model.MessageResult;
import com.qy.worksheetsystem.model.MessageResultV2;
import com.qy.worksheetsystem.service.impl.ProjectServiceImpl;
import com.qy.worksheetsystem.util.JWTUtil;
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.web.bind.annotation.*;


/**
 * description: ProjectController <br>
 * date: 2022/3/12 10:15 <br>
 * author: lhbj <br>
 * version: 1.0 <br>
 */
@Slf4j
@RestController
@RequestMapping("/timeSheet")
@Api(value = "员工项目",tags="员工项目")
public class ProjectController {

    @Autowired
    private ProjectServiceImpl service;

    @ApiOperation(value = "员工项目", notes = "员工项目")
    @RequestMapping(value ="/getProjectList",method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name="token",value="token",required=true,paramType="header",dataType="String"),
            @ApiImplicitParam(name="id",value="项目id;不传查询员工所有项目信息",defaultValue="",paramType="query",dataType="String"),
            @ApiImplicitParam(name="month",value="月份(yyyy-MM)",defaultValue="",paramType="query",dataType="String"),

    })
    public MessageResult getProjectList(@RequestHeader("token") String token,String id,String month) {
        MessageResult result=null;
        try {
            String number = JWTUtil.getNumber(token);
            if(StringUtils.isEmpty(number)){
                return MessageResult.error("token异常");
            }
            MessageResultV2 messageResult= MessageResultV2.success();
            messageResult.setData(service.getProjectList(number,id,month));
            return messageResult;
        }catch (Exception e){
            log.error(e.getMessage(),e);
            result = MessageResult.error(e.getMessage());
        }
        return result;
    }
}
