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.model.app.WorkDept;
import cn.wisenergy.model.dto.GetMonthlyCollectParam;
import cn.wisenergy.model.dto.WorkTimeAndCostCollect;
import cn.wisenergy.service.StatisticsService;
import cn.wisenergy.service.WorkDeptService;
import cn.wisenergy.web.admin.controller.common.BaseController;
import com.github.pagehelper.PageInfo;
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.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * @description:
 * @author: nh
 * @create: 2021-01-19 17:13
 **/
@RestController
@RequestMapping(value = "/statistics")
@Slf4j
@Api(tags = "统计报表")
public class StatisticsController extends BaseController {
    @Autowired
    StatisticsService statisticsService;

    @Autowired
    WorkDeptService workDeptService;

    @ApiOperation(value = "获取部门员工一个月每天的工时", notes = "获取部门员工一个月每天的工时")
    @GetMapping("/getMonthlyCollect")
    public PageInfo getMonthlyCollect(GetMonthlyCollectParam param) {
        log.info("StatisticsController[]getMonthlyCollect[]input.param" + param);
        PageInfo monthlyCollect = statisticsService.getDayWorkTimeOfMonth(param);
        return monthlyCollect;
    }

    @ApiOperation(value = "获取全部部门信息或单条信息", notes = "获取全部部门信息或单条信息")
    @ApiImplicitParam(name = "deptId", value = "部门主键")
    @GetMapping("/getDeptInfo")
    public List<WorkDept> getDeptInfo( Integer deptId) {
        log.info("StatisticsController[]getDeptInfo[]input.param"  + deptId);
        List<WorkDept> workDepts = workDeptService.getDeptInfo(deptId);
        return workDepts;
    }

    @ApiOperation(value = "获取负责项目工时汇总", notes = "获取负责项目工时汇总")
    @GetMapping("/getCurrentMonthWorkTimeCollect")
    public List<WorkTimeAndCostCollect> getWorkTimeCollect(Integer userId,@DateTimeFormat(pattern = "yyyy-MM-dd") Date startTime) {
        log.info("WorkUserController[]getCurrentMonthWorkTimeCollect[]input.param" + userId,startTime);
        if (userId == null) {
            throw new BaseCustomException(BASE_RESP_CODE_ENUM.INPUT_PARAM_IS_NULL);
        }
        List<WorkTimeAndCostCollect> currentMonthWorkTimeCollect = statisticsService.getCurrentMonthWorkTimeCollect(userId,startTime);
        return currentMonthWorkTimeCollect;
    }

    @ApiOperation(value = "获取本月工时统计和审核统计", notes = "获取本月",httpMethod = "GET")
    @ApiImplicitParam(name = "userId", value = "用户主键",dataType = "int", required = true)
    @GetMapping("/getMonthlyWorkingHours")
    public Result<List<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 = statisticsService.getMonthlyStatistics(userId);
        return getResult(monthlyStatistics);
    }

}
