package com.cf.imes.module.executor.service.funds.purchase;


import cn.hutool.core.collection.CollUtil;
import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.framework.common.util.date.LocalDateTimeUtils;
import com.cf.imes.framework.common.util.object.BeanUtils;
import com.cf.imes.module.executor.controller.admin.funds.purchase.vo.PurchaseRecordPageReqVO;
import com.cf.imes.module.executor.controller.admin.funds.purchase.vo.PurchaseRecordRespVO;
import com.cf.imes.module.executor.dal.dataobject.funds.purchase.PurchaseRecordDO;
import com.cf.imes.module.executor.dal.mysql.funds.purchase.PurchaseRecordMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

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

/**
 * @author 软件购买接口 实现类
 */
@Slf4j
@Service
public class PurchaseServiceImpl implements PurchaseService{


    @Resource
    private PurchaseRecordMapper purchaseRecordMapper;





    @Override
    public PageResult<PurchaseRecordRespVO> getPurchaseRecord(PurchaseRecordPageReqVO pageReqVO) {


        pageReqVO.setCreateTime(LocalDateTimeUtils.generateTimeSection(pageReqVO.getCreateTime()));

        PageResult<PurchaseRecordDO> pageResult = purchaseRecordMapper.selectPage(pageReqVO);
        List<PurchaseRecordDO> resultList = pageResult.getList();

        if(CollUtil.isEmpty(resultList)){
            return new PageResult<>();
        }

        List<PurchaseRecordRespVO> respVOS = BeanUtils.toBean(resultList, PurchaseRecordRespVO.class);

        return new PageResult<>(respVOS, pageResult.getTotal());
    }



}
