package com.qmth.sop.server.api;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qmth.boot.api.constant.ApiConstant;
import com.qmth.sop.business.bean.result.ProjectMonitorResult;
import com.qmth.sop.business.bean.result.ServiceUnitOverviewResult;
import com.qmth.sop.business.bean.result.ServiceUnitProgressResult;
import com.qmth.sop.business.bean.result.ServiceUnitProvinceResult;
import com.qmth.sop.business.service.ServiceUnitAnalyseService;
import com.qmth.sop.common.annotation.OperationLog;
import com.qmth.sop.common.contant.SystemConstant;
import com.qmth.sop.common.enums.CrmProcessEnum;
import com.qmth.sop.common.enums.LogTypeEnum;
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 javax.validation.constraints.Max;
import javax.validation.constraints.Min;

/**
 * @Description 服务单元分析
 * @Author haoguanghui
 * @date 2024/09/09
 */
@Api(tags = "服务单元分析重构 Controller")
@RestController
@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + SystemConstant.PREFIX_URL_SERVICE_ANALYSE)
public class ServiceUnitAnalyseController {

    @Resource
    ServiceUnitAnalyseService serviceUnitAnalyseService;

    @ApiOperation(value = "服务单元概况")
    @RequestMapping(value = "/overview", method = RequestMethod.POST)
    @ApiResponses({ @ApiResponse(code = 200, message = "返回信息", response = ServiceUnitOverviewResult.class) })
    public Result overview(@ApiParam(value = "服务单元ID", required = true) @RequestParam(required = true) Long serviceUnitId) {
        return ResultUtil.ok(serviceUnitAnalyseService.overview(serviceUnitId));
    }

    @ApiOperation(value = "项目整体进度")
    @RequestMapping(value = "/progress", method = RequestMethod.POST)
    @ApiResponses({ @ApiResponse(code = 200, message = "返回信息", response = ServiceUnitProgressResult.class) })
    public Result progress(@ApiParam(value = "服务单元ID", required = true) @RequestParam(required = true) Long serviceUnitId) {
        return ResultUtil.ok(serviceUnitAnalyseService.progress(serviceUnitId));
    }

    @ApiOperation(value = "区域概况")
    @RequestMapping(value = "/province", method = RequestMethod.POST)
    @ApiResponses({ @ApiResponse(code = 200, message = "返回信息", response = ServiceUnitProvinceResult.class) })
    public Result province(@ApiParam(value = "服务单元ID", required = true) @RequestParam(required = true) Long serviceUnitId) {
        return ResultUtil.ok(serviceUnitAnalyseService.province(serviceUnitId));
    }

    @ApiOperation(value = "详情分页")
    @RequestMapping(value = "/detail", method = RequestMethod.POST)
    @ApiResponses({ @ApiResponse(code = 200, message = "详情分页", response = ProjectMonitorResult.class) })
    public Result page(
            @ApiParam(value = "服务单元ID", required = true) @RequestParam(required = true) Long serviceUnitId,
            @ApiParam(value = "客户经理ID", required = false) @RequestParam(required = false) Long crmUserId,
            @ApiParam(value = "客户名称", required = false) @RequestParam(required = false) String customName,
            @ApiParam(value = "当前进度", required = false) @RequestParam(required = false) CrmProcessEnum process,
            @ApiParam(value = "大区经理", required = false) @RequestParam(required = false) Long leadId,
            @ApiParam(value = "客户所在省份", required = false) @RequestParam(required = false) String province,
            @ApiParam(value = "项目经理所在人力商", required = false) @RequestParam(required = false) Long supplierId,
            @ApiParam(value = "区域协调人ID", required = false) @RequestParam(required = false) Long coordinatorId,
            @ApiParam(value = "类型", required = false) @RequestParam(required = false) String type,
            @ApiParam(value = "预警字段", required = false) @RequestParam(required = false) String fieldObj,
            @ApiParam(value = "分页页码", required = true) @RequestParam @Min(SystemConstant.PAGE_NUMBER_MIN) Integer pageNumber,
            @ApiParam(value = "分页数", required = true) @RequestParam @Min(SystemConstant.PAGE_SIZE_MIN) @Max(SystemConstant.PAGE_SIZE_MAX) Integer pageSize) {
        return ResultUtil.ok(serviceUnitAnalyseService.pageSop(new Page<>(pageNumber, pageSize), serviceUnitId, crmUserId, customName, process,
                leadId, province, supplierId, coordinatorId, type, fieldObj));
    }

    @ApiOperation(value = "详情导出")
    @RequestMapping(value = "/detail/export", method = RequestMethod.POST)
    @ApiResponses({ @ApiResponse(code = 200, message = "返回信息", response = Object.class) })
    @OperationLog(logType = LogTypeEnum.EXPORT)
    public void export(@ApiParam(value = "服务单元ID", required = true) @RequestParam(required = true) Long serviceUnitId,
            @ApiParam(value = "客户经理ID", required = false) @RequestParam(required = false) Long crmUserId,
            @ApiParam(value = "客户名称", required = false) @RequestParam(required = false) String customName,
            @ApiParam(value = "当前进度", required = false) @RequestParam(required = false) CrmProcessEnum process,
            @ApiParam(value = "大区经理", required = false) @RequestParam(required = false) Long leadId,
            @ApiParam(value = "客户所在省份", required = false) @RequestParam(required = false) String province,
            @ApiParam(value = "项目经理所在人力商", required = false) @RequestParam(required = false) Long supplierId,
            @ApiParam(value = "区域协调人ID", required = false) @RequestParam(required = false) Long coordinatorId,
            @ApiParam(value = "类型", required = false) @RequestParam(required = false) String type,
            @ApiParam(value = "预警字段", required = false) @RequestParam(required = false) String fieldObj) {
        serviceUnitAnalyseService.export(serviceUnitId, crmUserId, customName, process, leadId, province, supplierId, coordinatorId, type, fieldObj);
    }

}
