package cn.wisenergy.web.admin.controller.app;

import cn.wisenergy.common.utils.exception.BASE_RESP_CODE_ENUM;
import cn.wisenergy.common.utils.exception.BaseCustomException;
import cn.wisenergy.common.utils.exception.Result;
import cn.wisenergy.service.WorkTimeOrderService;
import cn.wisenergy.web.admin.controller.common.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @description:
 * @author: nh
 * @create: 2021-01-19 16:05
 **/
@RestController
@RequestMapping(value = "/workOrder")
@Slf4j
@Api(tags = "工单模块")
public class WorkOrderController extends BaseController {
    @Autowired
    WorkTimeOrderService workOrderService;

    @ApiOperation(value = "获取本月工时统计", notes = "获取本月工时统计")
    @ApiImplicitParam(name = "userId", value = "用户主键",dataType = "integer", required = true)
    @GetMapping("getMonthlyWorkingHours")
    public Result<ArrayList<Object>> getMonthlyWorkingHours(Integer userId){
        log.info("WorkOrderController[]getMonthlyWorkingHours[]input.param" + userId);
        if (userId == null) {
            throw new BaseCustomException(BASE_RESP_CODE_ENUM.INPUT_PARAM_IS_NULL);
        }
        List<Object> monthlyStatistics = workOrderService.getMonthlyStatistics(userId);
        return getResult(monthlyStatistics);
    }
}
