/*
 * Copyright [2022] [https://www.xiaonuo.vip]
 *
 * Snowy采用APACHE LICENSE 2.0开源协议，您在使用过程中，需要注意以下几点：
 *
 * 1.请不要删除和修改根目录下的LICENSE文件。
 * 2.请不要删除和修改Snowy源码头部的版权声明。
 * 3.本项目代码可免费商业使用，商业使用请保留源码和相关描述文件的项目出处，作者声明等。
 * 4.分发源码时候，请注明软件出处 https://www.xiaonuo.vip
 * 5.不可二次分发开源参与同类竞品，如有想法可联系团队xiaonuobase@qq.com商议合作。
 * 6.若您的项目无法满足以上几点，需要更多功能代码，获取Snowy商业授权许可，请在官网购买授权，地址为 https://www.xiaonuo.vip
 */
package com.unis.rotationPlan.info.modular.businessrpreport.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.unis.rotationPlan.info.modular.businessrpreport.entity.BusinessQcQualityInspection;
import com.unis.rotationPlan.info.modular.businessrpreport.entity.vo.BusinessRpReportVO;
import com.unis.rotationPlan.info.modular.businessrpreport.util.Grain;
import com.unis.rotationPlan.info.modular.businessrpreport.util.Tab;
import com.unis.rotationPlan.info.modular.businessrpreport.util.TableColumn;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.unis.common.annotation.CommonLog;
import com.unis.common.pojo.CommonResult;
import com.unis.common.pojo.CommonValidList;
import com.unis.rotationPlan.info.modular.businessrpreport.entity.BusinessRpReport;
import com.unis.rotationPlan.info.modular.businessrpreport.param.BusinessRpReportAddParam;
import com.unis.rotationPlan.info.modular.businessrpreport.param.BusinessRpReportEditParam;
import com.unis.rotationPlan.info.modular.businessrpreport.param.BusinessRpReportIdParam;
import com.unis.rotationPlan.info.modular.businessrpreport.param.BusinessRpReportPageParam;
import com.unis.rotationPlan.info.modular.businessrpreport.service.BusinessRpReportService;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import java.util.List;
import java.util.Map;

/**
 * 轮换计划-上报控制器
 *
 * @author ZeroLiYi
 * @date  2024/05/14 18:05
 */
@Api(tags = "轮换计划-上报控制器")
@ApiSupport(author = "UNIS_TEAM", order = 1)
@RestController
@Validated
public class BusinessRpReportController {

    @Resource
    private BusinessRpReportService businessRpReportService;

    /**
     * 省级轮换计划接受列表分页
     *
     * @author ZeroLiYi
     * @date  2024/05/14 18:05
     */
    @ApiOperationSupport(order = 1)
    @ApiOperation("轮换计划接收列表")
    @GetMapping("/rotationPlan.info/businessrpreport/page")
    public CommonResult<IPage<Map<String,Object>>> page(BusinessRpReportPageParam businessRpReportPageParam) {
        return CommonResult.data(businessRpReportService.page(businessRpReportPageParam));
    }


    /**
     * 省级轮换计划接收详情
     *
     * @author ZeroLiYi
     * @date  2024/05/14 18:05
     */
    @ApiOperationSupport(order = 2)
    @CommonLog("轮换计划接收详情")
    @RequestMapping(value="/rotationPlan.info/businessrpreport/getRpReportRecDetail",produces = MediaType.APPLICATION_JSON_VALUE, method=RequestMethod.GET)
    @ApiOperation(value="省级轮换计划接收详情", notes = "得到轮换计划接收详情")
    public CommonResult<BusinessRpReportVO> getRpReportDetail(@RequestParam("rpReportId")String rpReportId, @RequestParam(required = false)Integer orgId) throws Exception {

        BusinessRpReportVO report = businessRpReportService.getRpReportDetail(rpReportId,orgId);
        return CommonResult.data(report);
    }

    /**
     * 根据货位查询质检报告
     * @return
     * @throws
     */
    @ApiOperationSupport(order = 3)
    @RequestMapping(value="/rotationPlan.info/businessrpreport/getQualityInspectionFindByWarehouseId",produces = MediaType.APPLICATION_JSON_VALUE, method=RequestMethod.GET)
    @ApiOperation(value="根据货位查询粮情卡质检报告", notes = "根据货位查询粮情卡质检报告")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "jylb", value = "检验类别", paramType = "form"),
            @ApiImplicitParam(name = "warehouseId", value = "货位id", paramType = "form")


    })
    public CommonResult<List<BusinessQcQualityInspection>> getQualityInspectionFindByWarehouseId(String jylb, Integer warehouseId) throws Exception {

        List<BusinessQcQualityInspection> list = businessRpReportService.getQualityInspectionFindByWarehouseId(jylb,warehouseId);
        return CommonResult.data(list);
    }




    /**
     * 轮换计划制定查询详情
     *
     * @author ZeroLiYi
     * @date  2024/05/14 18:05
     */
    @ApiOperationSupport(order = 5)
    @ApiOperation("轮换计划制定查询详情")
    @GetMapping("/rotationPlan.info/businessrpreport/createreport")
    public CommonResult< Map<String,Object>> createreport(@Valid BusinessRpReportIdParam businessRpReportIdParam) {

        Map<String,Object> map =businessRpReportService.createReport(businessRpReportIdParam);
        return CommonResult.data(map);

    }



    /**
     * 轮换计划制定查询列表
     *
     * @author ZeroLiYi
     * @date  2024/05/14 18:05
     */
    @ApiOperationSupport(order = 6)
    @ApiOperation("轮换计划制定查询列表")
    @GetMapping("/rotationPlan.info/businessrpreport/reportList")
    public CommonResult<Tab> reportList( BusinessRpReportIdParam businessRpReportIdParam) {

         Tab map =businessRpReportService.reportList(businessRpReportIdParam);
        return CommonResult.data(map);
    }

    /**
     * 计划信息查询列表
     *
     * @author ZeroLiYi
     * @date  2024/05/14 18:05
     */
    @ApiOperationSupport(order = 6)
    @ApiOperation("计划信息查询列表")
    @GetMapping("/rotationPlan.info/businessrpreport/reportPlanList")
    public CommonResult<List<Map<String,Object>>> reportPlanList(BusinessRpReportPageParam businessRpReportPageParam) {

        List<Map<String,Object>> list = businessRpReportService.getRecList(businessRpReportPageParam);

        return CommonResult.data(list);
    }


    /**
     * 计划信息查询详情
     *
     * @author ZeroLiYi
     * @date  2024/05/14 18:05
     */
    @ApiOperationSupport(order = 7)
    @CommonLog("计划信息查询详情")
    @RequestMapping(value="/rotationPlan.info/businessrpreport/getPlanRpReportDetail",produces = MediaType.APPLICATION_JSON_VALUE, method=RequestMethod.GET)
    @ApiOperation(value="计划信息查询详情", notes = "计划信息查询详情")
    public CommonResult<BusinessRpReportVO> getPlanRpReportDetail(@RequestParam("rpReportId")@NotBlank(message = "轮换计划Id") String rpReportId, @RequestParam("orgId")Integer orgId) throws Exception {

        BusinessRpReportVO report = businessRpReportService.getPlanRpReportDetail(rpReportId,orgId);
        return CommonResult.data(report);
    }







}
