package com.qmth.sop.server.api;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qmth.boot.api.annotation.Aac;
import com.qmth.boot.api.constant.ApiConstant;
import com.qmth.sop.business.service.SopScheduleService;
import com.qmth.sop.common.contant.SystemConstant;
import com.qmth.sop.common.enums.SopAnalyseGroupEnum;
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;
import java.util.List;
import java.util.Map;

/**
 * 项目进度监控 控制器
 *
 * @author: shudonghui
 * @date: 2023-08-14 15:55:18
 * @version: 1.0
 * @email: shudonghui@qmth.com.cn
 * @Company: www.qmth.com.cn
 */
@Api(tags = "项目进度监控 Controller")
@RestController
@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + "/sop/schedule")
public class SopScheduleController {


    @Resource
    SopScheduleService sopScheduleService;

    /**
     * 1.项目进度监控是对当前项目的执行阶段的分布和整体项目的完成情况进行不同维度的洞察；
     * 2.动态查询条件：时间周期（年度等）、服务单元（已发布状态）；
     * 3.大区项目阶段分布及对比：
     * ①准备：扫描前的准备阶段；
     * ②扫描：扫描仪配置产出物提交，到扫描收尾产出物提交；
     * ③评卷：阅卷参数提交、评卷收尾；
     * ④收尾：项目总结提交前；
     * ⑤已完结：SOP完结。
     * ⑥全部大区进度展示；
     * ⑦【数据下钻】点击大区行数据，可查看该服务单元下该大区下的SOP明细；
     * 4.供应商项目阶段分布及对比
     * 同上
     * 5.项目进度阶段总体分布对比
     * 服务单元下所有项目的进度阶段总体分布对比，各阶段统计解释同上。
     */
    @Aac(auth = false)
    @ApiOperation(value = "项目阶段分布")
    @RequestMapping(value = "/progress", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "项目阶段分布", response = Map.class)})
    public Result progress(@ApiParam(value = "服务单元", required = true) @RequestParam Long serviceId,
                           @ApiParam(value = "分组", required = true) @RequestParam SopAnalyseGroupEnum group) {
        Map<String, Map<String, Object>> list = sopScheduleService.progress(serviceId, group);
        return ResultUtil.ok(list);
    }

    /*
    SOP明细
     */

    @ApiOperation(value = "SOP明细")
    @RequestMapping(value = "/detail", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "SOP明细", response = Map.class)})
    public Result detail(@ApiParam(value = "服务单元", required = true) @RequestParam Long serviceId,
                         @ApiParam(value = "大区") @RequestParam(required = false) Long regionId,
                         @ApiParam(value = "供应商") @RequestParam(required = false) Long supplierId,
                         @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) {
        IPage<Map<String, Object>> resultIPage = sopScheduleService.detail(new Page<>(pageNumber, pageSize), serviceId, regionId, supplierId);
        return ResultUtil.ok(resultIPage);
    }

    //项目燃尽图
    @ApiOperation(value = "项目燃尽图")
    @RequestMapping(value = "/projectProgress", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "项目燃尽图", response = Map.class)})
    public Result projectProgress(@ApiParam(value = "服务单元", required = true) @RequestParam Long serviceId) {
        Map<String, List<Map<String, Object>>> list = sopScheduleService.projectProgress(serviceId);
        return ResultUtil.ok(list);
    }

}
