package cn.iocoder.yudao.module.bpm.api.oa;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.bpm.api.oa.vo.receipt.*;
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.receipt.ReceiptStatisticsVO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.BpmOAReceiptDO;
import cn.iocoder.yudao.module.bpm.service.oa.BpmOAReceiptService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

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

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;

/**
 * Flowable 流程实例 Api 实现类
 */
@RestController
@Validated
public class BpmOAReceiptApiImpl implements BpmOAReceiptApi{

    @Resource
    private BpmOAReceiptService receiptService;

    @Override
    public CommonResult<ReceiptStatisticsDTO> getReceiptCount(String relation) {
        ReceiptStatisticsVO respVO = receiptService.getStatistics(getLoginUserId(), relation);
        return success(BeanUtils.toBean(respVO, ReceiptStatisticsDTO.class));
    }

    @Override
    public CommonResult<List<BpmOAReceiptDTO>> getReceiptList(BpmOAReceiptVO respVO) {
        List<BpmOAReceiptDO> receiptDO = receiptService.getReceiptList(respVO);
        return success(BeanUtils.toBean(receiptDO, BpmOAReceiptDTO.class));
    }

    @Override
    public CommonResult<List<ReceiptStatisticsDTO>> getContractStatistics(List<Long> userIds, LocalDateTime[] createTime) {
        List<ReceiptStatisticsDTO> respVOS = receiptService.getReceiptStatisticsListByUserIds(userIds, createTime);
        return success(BeanUtils.toBean(respVOS, ReceiptStatisticsDTO.class));
    }

    @Override
    public CommonResult<List<ReceiptSettlementDTO>> getReceiptSettlement(ReceiptSettlementVO vo) {
        return success(receiptService.getReceiptSettlement(vo));
    }
}
