package com.qy.worksheetsystem.controller;

import com.qy.worksheetsystem.model.MessageResult;
import com.qy.worksheetsystem.model.MessageResultV2;
import com.qy.worksheetsystem.service.impl.CTWORAttendanceTypeServiceImpl;
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 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.util.List;
import java.util.Map;

@Api(tags = "获取考勤类型:报工接口:3.4")
@RestController
@RequestMapping("/timeSheet")
public class CTWORAttendanceTypeController {
    @Autowired
    private CTWORAttendanceTypeServiceImpl attendanceTypeServiceImpl;

    @ApiOperation(value = "获取考勤类型")
    @GetMapping("/getAttendanceTypeList")
    @ApiImplicitParams({
            @ApiImplicitParam(name="token",value="token",required=true,paramType="header",dataType="String"),
    })
    public MessageResult selectIDName(@RequestHeader("token") String token, String state) {
        String number = JWTUtil.getNumber(token);
        if(StringUtils.isEmpty(number)){
            return MessageResult.error("token异常");
        }
        if(StringUtils.isEmpty(state)){
            state="2";
        }
        List<Map<String, String>> ctworAttendanceTypes = attendanceTypeServiceImpl.getAttendanceTypeV2(number,state);
        if (ctworAttendanceTypes.size() == 0) {
            return MessageResult.error("暂无数据");
        } else {
            MessageResultV2 messageResult= MessageResultV2.success();
            messageResult.setData(ctworAttendanceTypes);
            return messageResult;
        }
    }
}
