package com.xisc.pm.infra.repository.impl;

import com.xisc.pm.domain.entity.PmPdContSum;
import com.xisc.pm.domain.entity.PmPdContSumTra;
import com.xisc.pm.domain.repository.PmPdContSumTraRepository;
import com.xisc.pm.infra.mapper.PmPdContSumTraMapper;
import com.xisc.pm.infra.util.BeanUtils;
import org.apache.commons.collections.CollectionUtils;
import org.hzero.mybatis.base.impl.BaseRepositoryImpl;
import org.springframework.stereotype.Component;

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

/**
 * 组板合同总量表(PmPdContSumTra)资源库
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-11-26 10:56:19
 */
@Component
public class PmPdContSumTraRepositoryImpl extends BaseRepositoryImpl<PmPdContSumTra> implements PmPdContSumTraRepository {
    @Resource
    private PmPdContSumTraMapper pmPdContSumTraMapper;

    @Override
    public List<PmPdContSumTra> selectList(PmPdContSumTra pmPdContSumTra) {
        return pmPdContSumTraMapper.selectList(pmPdContSumTra);
    }

    @Override
    public PmPdContSumTra selectByPrimary(Long traId) {
        PmPdContSumTra pmPdContSumTra = new PmPdContSumTra();
        pmPdContSumTra.setTraId(traId);
        List<PmPdContSumTra> pmPdContSumTras = pmPdContSumTraMapper.selectList(pmPdContSumTra);
        if (CollectionUtils.isEmpty(pmPdContSumTras)) {
            return null;
        }
        return pmPdContSumTras.get(0);
    }

    @Override
    public List<PmPdContSumTra> buildPmPdContSumTraList(List<PmPdContSum> pdContSumList, String operationType, Date operationTime, String operationUser) {
        List<PmPdContSumTra> insertPmPdContSumTraList = new ArrayList<>();
        pdContSumList.forEach(item -> {
            PmPdContSumTra pmPdContSumTra = new PmPdContSumTra();
            BeanUtils.copy(item, pmPdContSumTra);
            pmPdContSumTra.setPpcsId(item.getPpcsId());
            pmPdContSumTra.setOperationType(operationType);
            pmPdContSumTra.setOperationTime(operationTime);
            pmPdContSumTra.setOperationUser(operationUser);
            insertPmPdContSumTraList.add(pmPdContSumTra);
        });
        return insertPmPdContSumTraList;
    }
}

