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

import com.xisc.pm.domain.entity.PmPdBlockPos;
import com.xisc.pm.domain.entity.PmPdBlockPosTra;
import com.xisc.pm.domain.repository.PmPdBlockPosTraRepository;
import com.xisc.pm.infra.mapper.PmPdBlockPosTraMapper;
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;

/**
 * 组合子板位置表-履历表(PmPdBlockPosTra)资源库
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-11-26 10:54:19
 */
@Component
public class PmPdBlockPosTraRepositoryImpl extends BaseRepositoryImpl<PmPdBlockPosTra> implements PmPdBlockPosTraRepository {
    @Resource
    private PmPdBlockPosTraMapper pmPdBlockPosTraMapper;

    @Override
    public List<PmPdBlockPosTra> selectList(PmPdBlockPosTra pmPdBlockPosTra) {
        return pmPdBlockPosTraMapper.selectList(pmPdBlockPosTra);
    }

    @Override
    public PmPdBlockPosTra selectByPrimary(Long traId) {
        PmPdBlockPosTra pmPdBlockPosTra = new PmPdBlockPosTra();
        pmPdBlockPosTra.setTraId(traId);
        List<PmPdBlockPosTra> pmPdBlockPosTras = pmPdBlockPosTraMapper.selectList(pmPdBlockPosTra);
        if (CollectionUtils.isEmpty(pmPdBlockPosTras)) {
            return null;
        }
        return pmPdBlockPosTras.get(0);
    }

    @Override
    public List<PmPdBlockPosTra> buildPmPdBlockPosTraList(List<PmPdBlockPos> pmPdBlockPosList, String operationType, Date operationTime, String operationUser) {
        List<PmPdBlockPosTra> insertPmPdBlockPosTraList = new ArrayList<>();
        pmPdBlockPosList.forEach(item -> {
            PmPdBlockPosTra pmPdBlockPosTra = new PmPdBlockPosTra();
            BeanUtils.copy(item, pmPdBlockPosTra);
            pmPdBlockPosTra.setPdBlockPosId(item.getPdBlockPosId());
            pmPdBlockPosTra.setOperationType(operationType);
            pmPdBlockPosTra.setOperationTime(operationTime);
            pmPdBlockPosTra.setOperationUser(operationUser);
            insertPmPdBlockPosTraList.add(pmPdBlockPosTra);
        });
        return insertPmPdBlockPosTraList;
    }
}

