package cn.iocoder.yudao.module.system.controller.admin.biz;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.materialio.outbound.MaterialOutboundDetailPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.materialio.outbound.MaterialOutboundDetailRespVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.materialio.outbound.MaterialOutboundSummaryPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.materialio.outbound.MaterialOutboundSummaryRespVO;
import cn.iocoder.yudao.module.system.service.biz.MaterialIoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 物资出库统计")
@RestController
@RequestMapping("/material-io/stats/outbound")
@Validated
public class MaterialOutboundStatController {

    @Resource
    private MaterialIoService materialIoService;

    @GetMapping("/summary")
    @Operation(summary = "出库统计汇总")
    @TenantIgnore
    public CommonResult<PageResult<MaterialOutboundSummaryRespVO>> summary(@Valid MaterialOutboundSummaryPageReqVO reqVO) {
        if (reqVO.getTenantIds() == null || reqVO.getTenantIds().length == 0) {
            reqVO.setTenantIds(new Long[]{TenantContextHolder.getTenantId()});
        }
        return success(materialIoService.pageOutboundSummary(reqVO));
    }

    @GetMapping("/detail")
    @Operation(summary = "出库统计明细")
    @TenantIgnore
    public CommonResult<PageResult<MaterialOutboundDetailRespVO>> detail(@Valid MaterialOutboundDetailPageReqVO reqVO) {
        if (reqVO.getTenantIds() == null || reqVO.getTenantIds().length == 0) {
            reqVO.setTenantIds(new Long[]{TenantContextHolder.getTenantId()});
        }
        return success(materialIoService.pageOutboundDetail(reqVO));
    }

}

