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.inbound.MaterialInboundDetailPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.materialio.inbound.MaterialInboundDetailRespVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.materialio.inbound.MaterialInboundSummaryPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.materialio.inbound.MaterialInboundSummaryRespVO;
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;

/**
 * 管理后台 - 物资入库统计 Controller
 */
@Tag(name = "管理后台 - 物资入库统计")
@RestController
@RequestMapping("/material-io/stats/inbound")
@Validated
public class MaterialInboundStatController {

    @Resource
    private MaterialIoService materialIoService;

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

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

