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

import cn.hutool.core.bean.BeanUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.bpm.api.oa.vo.salesperformance.SalesPerformanceDTO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.BpmOASalesPerformanceDO;
import cn.iocoder.yudao.module.bpm.service.oa.BpmOASalesPerformanceService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

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

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

    @Resource
    private BpmOASalesPerformanceService salesPerformanceService;

    @Override
    public CommonResult<List<SalesPerformanceDTO>> getReceiptSettlement(String year, String month) {
        List<BpmOASalesPerformanceDO> list = salesPerformanceService.list(new LambdaQueryWrapper<BpmOASalesPerformanceDO>()
                .eq(BpmOASalesPerformanceDO::getYear, year)
                .eq(BpmOASalesPerformanceDO::getMonth, month)
                .eq(BpmOASalesPerformanceDO::getResult, 2));
        return CommonResult.success(BeanUtil.copyToList(list, SalesPerformanceDTO.class));
    }

    @Override
    public CommonResult<SalesPerformanceDTO> getBySalesPerformanceId(Long salesPerformanceId) {
        BpmOASalesPerformanceDO item = salesPerformanceService.getById(salesPerformanceId);
        return CommonResult.success(BeanUtil.copyProperties(item, SalesPerformanceDTO.class));
    }
}
