package com.qmth.sop.server.api;

import com.google.common.collect.ImmutableMap;
import com.qmth.boot.api.constant.ApiConstant;
import com.qmth.sop.business.bean.report.DingExceptionCountReportBean;
import com.qmth.sop.business.bean.report.SupplierCountReportBean;
import com.qmth.sop.business.service.ResourceSecurityReportService;
import com.qmth.sop.common.contant.SystemConstant;
import com.qmth.sop.common.util.Result;
import com.qmth.sop.common.util.ResultUtil;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "资源保障报表Controller")
@RestController
@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + SystemConstant.PREFIX_URL_RESOURCE_SECURITY)
public class ResourceSecurityReportController {

    public static final String TOTAL = "total";

    public static final String RECORDS = "records";

    @Resource
    ResourceSecurityReportService resourceSecurityReportService;

    @ApiOperation(value = "设备商供货数量分布")
    @RequestMapping(value = "/device_supplier/report", method = RequestMethod.POST)
    @ApiResponses({ @ApiResponse(code = 200, message = "供应商供货数量分布报表", response = SupplierCountReportBean.class) })
    public Result deviceSupplierReport(@ApiParam(value = "服务单元id", required = true) @RequestParam Long serviceId) {
        List<SupplierCountReportBean> supplierCountReportBeanList = resourceSecurityReportService.deviceSupplierReport(
                serviceId);
        Integer total = supplierCountReportBeanList.stream().mapToInt(s -> s.getCount()).sum();
        return ResultUtil.ok(ImmutableMap.of(TOTAL, total, RECORDS, supplierCountReportBeanList));
    }

    @ApiOperation(value = "人力数量分布")
    @RequestMapping(value = "/human_supplier/report", method = RequestMethod.POST)
    @ApiResponses({ @ApiResponse(code = 200, message = "供应商供货数量分布报表", response = SupplierCountReportBean.class) })
    public Result humanSupplierReport(@ApiParam(value = "服务单元id", required = true) @RequestParam Long serviceId) {
        List<SupplierCountReportBean> supplierCountReportBeanList = resourceSecurityReportService.humanSupplierReport(
                serviceId);
        Integer total = supplierCountReportBeanList.stream().mapToInt(s -> s.getCount()).sum();
        return ResultUtil.ok(ImmutableMap.of(TOTAL, total, RECORDS, supplierCountReportBeanList));
    }

    @ApiOperation(value = "大区考勤异常数统计")
    @RequestMapping(value = "/area_ding_exception/report", method = RequestMethod.POST)
    @ApiResponses({ @ApiResponse(code = 200, message = "考勤异常报表", response = DingExceptionCountReportBean.class) })
    public Result areaDingExceptionReport(@ApiParam(value = "服务单元id", required = true) @RequestParam Long serviceId) {
        return ResultUtil.ok(resourceSecurityReportService.areaDingExceptionReport(serviceId));
    }

    @ApiOperation(value = "人力供应商考勤异常数统计")
    @RequestMapping(value = "/human_ding_exception/report", method = RequestMethod.POST)
    @ApiResponses({ @ApiResponse(code = 200, message = "考勤异常报表", response = DingExceptionCountReportBean.class) })
    public Result humanDingExceptionReport(@ApiParam(value = "服务单元id", required = true) @RequestParam Long serviceId) {
        return ResultUtil.ok(resourceSecurityReportService.humanDingExceptionReport(serviceId));
    }
}
