package com.junmp.jyzb.controller;

import com.junmp.jyzb.api.bean.dto.InventorySumDto;
import com.junmp.jyzb.api.bean.dto.largeScreenDto.*;
import com.junmp.jyzb.api.bean.dto.tjDto.*;
import com.junmp.jyzb.api.bean.query.OrderMainReq;
import com.junmp.jyzb.api.bean.query.QueryBusFormReq;
import com.junmp.jyzb.api.bean.query.tjReq.*;
import com.junmp.jyzb.api.bean.query.WarehouseReq;
import com.junmp.jyzb.api.bean.req.WarrantyReq;
import com.junmp.jyzb.entity.*;
import com.junmp.jyzb.entity.Temp.HumidityAndtemperature;
import com.junmp.jyzb.service.TjService;
import com.junmp.jyzb.service.VieWarrantyGroupService;
import com.junmp.jyzb.service.WarehouseService;
import com.junmp.jyzb.service.WarrantyInventoryService;
import com.junmp.v2.common.bean.request.ValidationApi;
import com.junmp.v2.common.bean.response.ApiRes;
import com.junmp.v2.db.api.page.PageResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

@RestController
@Slf4j
@RequestMapping("/Tj")
@Api(tags = "[报表]统计报表模块")
public class TjController {

   @Resource
   private TjService tjService;

    @Resource
    public WarehouseService warehouseService;
    @Resource
    public VieWarrantyGroupService vieWarrantyGroupService;

    @Resource
    public WarrantyInventoryService warrantyInventoryService;
    /**
     * ------------------------------------装备统计报表--------------------------------------------
     */


    /**
  * 根据组织机构统计装备的报表数据（外层数据）
  */
    @PostMapping("/GetTjData")
    @ApiOperation("/装备统计报表")
    public ApiRes<PageResult<TjOrgEqsDto>> GetTjData(@RequestBody TjOrgEqsReq req){
        return ApiRes.success(tjService.GetTjData(req));
    }

    @PostMapping("/TjOrgDataSum")
    @ApiOperation("/装备统计报表汇总")
    public ApiRes<FinalTjOrgEqsDto> TjOrgDataSum(@RequestBody TjOrgEqsReq req){
        return ApiRes.success(tjService.TjOrgDataSum(req));
    }


    //第二层数据
    @PostMapping("/TjOrgEqsDetail")
    @ApiOperation("装备统计报表二层数据")
    public ApiRes<List<TjOrgEqsDto>> TjOrgEqsDetail(@RequestBody TjOrgEqsReq req){
        return ApiRes.success(tjService.GetTjDataDetail(req));
    }
    @PostMapping("/TjOrgEqsDetailList")
    @ApiOperation("/查询组织机构下的装备统计明细列表")
    public ApiRes<List<InventorySumDto>> TjOrgEqsDetailList(@RequestBody TjOrgEqsReq req){
        return ApiRes.success(tjService.TjOrgEqsDetailList(req));
    }

    @PostMapping(path="/TjOrgEqsExport",name="装备报表导出#logType=30")
    @ApiOperation("装备报表导出")
    public void TjOrgEqsExport(@RequestBody TjOrgEqsReq req){
     tjService.TjOrgEqsExport(req);
    }


    /**
     * -------------------------------------号型维度统计报表------------------------------------------
     */
    @PostMapping("/TjEqsSizeByOrg")
    @ApiOperation("号型维度统计报表")
    public ApiRes<PageResult<TjOrgEqsSizeDto>> TjEqsSizeByOrg(@RequestBody TjOrgEqsSizeReq req){
        return ApiRes.success(tjService.TjEqsSizeByOrg(req));
    }

    @PostMapping("/TjEqsSizeByOrgSum")
    @ApiOperation("/号型维度统计报表汇总")
    public ApiRes<FinalTjOrgEqsDto> TjEqsSizeByOrgSum(@RequestBody TjOrgEqsSizeReq req){
        return ApiRes.success(tjService.TjEqsSizeByOrgSum(req));
    }


    //--------------------------------    装备维度的报表数据   ------------------------------
    @PostMapping("/TjEqsSumByOrg")
    @ApiOperation("装备维度数据统计")
    public ApiRes<PageResult<TjEqsSumDto>> TjEqsSumByOrg(@RequestBody TjEqsSumReq req){
        return ApiRes.success(tjService.TjEqsSumByOrg(req));
    }

    @PostMapping("/TjEqsSumByOrgDetail")
    @ApiOperation("装备维度数据统计")
    public ApiRes<List<TjEqsSumDto>> TjEqsSumByOrgDetail(@RequestBody TjEqsSumReq req){
        return ApiRes.success(tjService.TjEqsSumByOrgDetail(req));
    }

    @PostMapping("/TjEqsSumByOrgSum")
    @ApiOperation("/装备统计报表汇总")
    public ApiRes<FinalTjRqsSumDto> TjEqsSumByOrgSum(@RequestBody TjEqsSumReq req){
        return ApiRes.success(tjService.TjEqsSumByOrgSum(req));
    }

    @PostMapping("/TjEqsSumByOrder")
    @ApiOperation("装备维度统计按照出入库单据查询")
    public ApiRes<PageResult<OrderMain>> TjEqsSumByOrder(@RequestBody OrderMainReq req){
        return ApiRes.success(tjService.TjEqsSumByOrder(req));
    }

    @PostMapping("/TjEqsSumByBusForm")
    @ApiOperation("装备维度统计按照出入库单据查询")
    public ApiRes<PageResult<BusForm>> TjEqsSumByBusForm(@RequestBody QueryBusFormReq req){
        return ApiRes.success(tjService.TjEqsSumByBusForm(req));
    }


    /**
     *-------------------------------------财务统计报表------------------------------------------
     */

    //财务统计报表
    @PostMapping("/TjOrgPrice")
    @ApiOperation("/财务统计报表")
    public ApiRes<PageResult<TjOrgPriceDto>> TjOrgPrice(@RequestBody TjOrgPriceReq req){
        PageResult<TjOrgPriceDto> tjOrgPriceDtoPageResult = tjService.TjOrgPrice(req);
        return ApiRes.success(tjOrgPriceDtoPageResult);
    }
    @PostMapping("/TjOrgPriceSum")
    @ApiOperation("/财务统计报表汇总")
    public ApiRes<FinalTjOrgPriceDto> TjOrgPriceSum(@RequestBody TjOrgPriceReq req){
        return ApiRes.success(tjService.TjOrgPriceSum(req));
    }


    @PostMapping("/TjOrgPriceDetail")
    @ApiOperation("/查询组织机构下的财务统计明细二层结构(改)")
    public ApiRes<List<TjOrgPriceDto>> TjOrgPriceDetail(@RequestBody TjOrgPriceReq req){
        return ApiRes.success(tjService.TjOrgPriceDetail(req));
    }


//    @PostMapping("/TjOrgPriceDetailList")
//    @ApiOperation("/查询组织机构下的财务统计明细(改)")
//    public ApiRes<List<TjOrgPriceDto>> TjOrgPriceDetailList(@RequestBody TjOrgPriceReq req){
//        return ApiRes.success(tjService.TjOrgPriceDetailList(req));
//    }


    @PostMapping(path="/TjOrgPriceExport",name="财务报表导出#logType=30")
    @ApiOperation("财务报表导出")
    public void TjOrgPriceExport(@RequestBody TjOrgPriceReq req){
        tjService.TjOrgPriceExport(req);
    }




    /**
     * --------------------------------------使用统计报表-------------------------------------------
     */

    @PostMapping("/TjOrgCount")
    @ApiOperation("/使用统计报表")
    public ApiRes<PageResult<TjOrgCountDto>> TjOrgCount(@RequestBody @Validated(ValidationApi.detail.class) TjOrgCountReq req){
        return ApiRes.success(tjService.TjOrgCount(req));
    }
    @PostMapping("/TjOrgCountSum")
    @ApiOperation("/使用统计报表汇总")
    public ApiRes<FinalTjOrgCountDto> TjOrgCountSum(@RequestBody @Validated(ValidationApi.detail.class) TjOrgCountReq req){
        return ApiRes.success(tjService.TjOrgCountSum(req));
    }

   @PostMapping("/TjOrgCountDetail")
   @ApiOperation("/查询组织机构下的使用统计明细")
   public ApiRes<List<TjOrgCountDto>> TjOrgPriceDetail(@RequestBody TjOrgCountReq req){
    return ApiRes.success(tjService.TjOrgCountDetail(req));
   }


    @PostMapping(path="/TjOrgCountExport",name="使用报表导出#logType=30")
    @ApiOperation("使用报表导出")
    public void TjOrgCountExport(@RequestBody TjOrgCountReq req){
        tjService.TjOrgCountExport(req);
    }

//    @PostMapping("/TjOrgCountDetailList")
//    @ApiOperation("/查询组织机构下的使用统计明细")
//    public ApiRes<List<TjOrgCountDto>> TjOrgCountDetailList(@RequestBody TjOrgCountReq req){
//        return ApiRes.success(tjService.TjOrgCountDetailList(req));
//    }

    //------------------------------------------首页---------------------------------------------------
    //首页使用柱状图
    @PostMapping("/TjOrgCountByType")
    @ApiOperation("九大类使用统计柱状图")
    public ApiRes<List<TjOrgCountDto>> TjOrgCountByType(@RequestBody TjOrgCountReq req){
        return ApiRes.success(tjService.TjOrgCountByType(req));
    }

    //首页出入库统计
    @PostMapping("/TjOutAndInCount")
    @ApiOperation("首页出入库统计")
    public ApiRes<List<TjOutAndInDto>> TjOutAndInCount(@RequestBody @Validated(ValidationApi.list.class) TjOrgCountReq req){
        return ApiRes.success(tjService.TjOutAndInCount(req));
    }


    /**
     * --------------------------------------人员统计报表-------------------------------------------
     */
    @PostMapping("/TjOrgPolice")
    @ApiOperation("/人员统计报表")
    public ApiRes<PageResult<TjOrgPoliceDto>> TjOrgPolice(@RequestBody TjOrgPoliceReq req){
        return ApiRes.success(tjService.TjOrgPolice(req));
    }
    @PostMapping("/TjOrgPoliceSum")
    @ApiOperation("/人员统计报表汇总")
    public ApiRes<FinalTjOrgPoliceDto> TjOrgPoliceSum(@RequestBody TjOrgPoliceReq req){
        return ApiRes.success(tjService.TjOrgPoliceSum(req));
    }

    @PostMapping("/TjOrgPoliceDetailList")
    @ApiOperation("/查询组织机构下的人员统计明细")
    public ApiRes<List<TjOrgPoliceDto>> TjOrgPoliceDetailList(@RequestBody TjOrgPoliceReq req){
        return ApiRes.success(tjService.TjOrgPoliceDetailList(req));
    }

   @PostMapping(path="/TjOrgPoliceExport",name="人员报表导出#logType=30")
   @ApiOperation("人员报表导出")
   public void TjOrgPoliceExport(@RequestBody TjOrgPoliceReq req){
    tjService.TjOrgPoliceExport(req);
   }


    /**
     * --------------------------------------温湿度记录-------------------------------------------
     */

    @PostMapping("/showHumidityAndtemperature")
    @ApiOperation("展示温湿度记录")
    public ApiRes<List<HumidityAndtemperature>> showHumidityAndtemperature(@RequestBody WarehouseReq req){
        return ApiRes.success(warehouseService.showHumidityAndtemperature(req));
    }

    @PostMapping(path="/HumidityAndtemperatureExport",name="温湿度报表导出#logType=30")
    @ApiOperation("温湿度报表导出")
    public void HumidityAndtemperatureExport(@RequestBody WarehouseReq req){
        warehouseService.HumidityAndtemperatureExport(req);
    }

    @PostMapping(path="/WarrantyData",name="超期装备查询")
    @ApiOperation("超期装备查询")
    public ApiRes<PageResult<WarrantyDataDto>>  WarrantyData(@RequestBody  @Validated(ValidationApi.page.class) WarrantyReq req){
        return ApiRes.success(vieWarrantyGroupService.WarrantyData(req));
    }

    @PostMapping(path="/WarrantyInventoryDetail",name="超期装备查询")
    @ApiOperation("超期装备查询")
    public ApiRes<PageResult<WarrantyInventory>>  WarrantyInventoryDetail(@RequestBody @Validated(ValidationApi.detail.class) WarrantyReq req){
        return ApiRes.success(warrantyInventoryService.WarrantyInventoryDetail(req));
    }


    @PostMapping("/test")
    public ApiRes<FinalTjOrgEqsDto> test(@RequestBody TjOrgEqsReq req){
        return ApiRes.success(tjService.test(req));
    }



    //-----------------------------   大屏数据接口-----------------------------
    //1。装备近30天使用次数top5
    @PostMapping("/GetTop5")
    @ApiOperation("装备近30天使用次数top5")
    public ApiRes<List<Top5Dto>> GetTop5(@RequestBody TjOrgCountReq req){
        return ApiRes.success(tjService.GetTop5(req));

    }

    //2.九大类装备统计
    @PostMapping("/GetGroupByCount")
    @ApiOperation("九大类装备统计")
    public ApiRes<List<GroupByCountDto>> GetGroupByCount(@RequestBody TjOrgCountReq req){
        return ApiRes.success(tjService.GetGroupByCount(req));
    }

    //3.装备数量汇总统计
    @PostMapping("/GetCount")
    @ApiOperation("装备数量汇总统计")
    public ApiRes<List<InventorySummary>> GetCount(@RequestBody TjOrgCountReq req){
        return ApiRes.success(tjService.GetCount(req));
    }

    //4.近30天维修，使用，报废次数
    @PostMapping("GetSyWxBf")
    @ApiOperation("近30天维修，使用，报废次数")
    public ApiRes<SyWxBfDto> GetSyWxBf(@RequestBody TjOrgCountReq req){
        return ApiRes.success(tjService.GetSyWxBf(req));
    }


    //5.区域装备
    @PostMapping("/GetAreaType")
    @ApiOperation("区域装备")
    public ApiRes<AreaTypeDto> GetAreaType(@RequestBody TjOrgCountReq req){
        return ApiRes.success(tjService.GetAreaType(req));
    }

    //6。浙江省首页的装备数据
    @PostMapping("/GetPageOrgTj")
    @ApiOperation("浙江省首页的装备数据")
    public ApiRes<TjOrgDto> GetPageOrgTj(@RequestBody TjOrgCountReq req ){
        return ApiRes.success(tjService.GetPageOrgTj(req));
    }

    //7.获组织机构的经纬度
    @PostMapping("/GetOrgJWDByCode")
    @ApiOperation("获组织机构的经纬度")
    public ApiRes<List<PubOrg>> GetOrgJWDByCode(@RequestBody TjOrgCountReq req){
        return ApiRes.success(tjService.GetOrgJWDByCode(req));
    }
    //8.获取大屏本级装备数据
    @PostMapping("/GetNameList")
    @ApiOperation("获取大屏本级装备数据")
    public ApiRes<List<InventorySummary>> GetNameList(@RequestBody TjOrgCountReq req){
        return ApiRes.success(tjService.GetNameList(req));
    }

}
