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

import com.xisc.pm.domain.entity.PmSmallPltPos;
import com.xisc.pm.domain.entity.PmSmallPltPosTra;
import com.xisc.pm.domain.repository.PmSmallPltPosTraRepository;
import com.xisc.pm.infra.mapper.PmSmallPltPosTraMapper;
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;

/**
 * 组板小板位置表-履历表(PmSmallPltPosTra)资源库
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-11-26 10:58:31
 */
@Component
public class PmSmallPltPosTraRepositoryImpl extends BaseRepositoryImpl<PmSmallPltPosTra> implements PmSmallPltPosTraRepository {
    @Resource
    private PmSmallPltPosTraMapper pmSmallPltPosTraMapper;

    @Override
    public List<PmSmallPltPosTra> selectList(PmSmallPltPosTra pmSmallPltPosTra) {
        return pmSmallPltPosTraMapper.selectList(pmSmallPltPosTra);
    }

    @Override
    public PmSmallPltPosTra selectByPrimary(Long traId) {
        PmSmallPltPosTra pmSmallPltPosTra = new PmSmallPltPosTra();
        pmSmallPltPosTra.setTraId(traId);
        List<PmSmallPltPosTra> pmSmallPltPosTras = pmSmallPltPosTraMapper.selectList(pmSmallPltPosTra);
        if (CollectionUtils.isEmpty(pmSmallPltPosTras)) {
            return null;
        }
        return pmSmallPltPosTras.get(0);
    }

    @Override
    public List<PmSmallPltPosTra> buildPmSmallPltPosTraList(List<PmSmallPltPos> pmSmallPltPosList, String operationType, Date operationTime, String operationUser) {
        List<PmSmallPltPosTra> insertPmSmallPltPosTraList = new ArrayList<>();
        pmSmallPltPosList.forEach(item -> {
            PmSmallPltPosTra pmSmallPltPosTra = new PmSmallPltPosTra();
            BeanUtils.copy(item, pmSmallPltPosTra);
            pmSmallPltPosTra.setPsppId(item.getPsppId());
            pmSmallPltPosTra.setOperationType(operationType);
            pmSmallPltPosTra.setOperationTime(operationTime);
            pmSmallPltPosTra.setOperationUser(operationUser);
            insertPmSmallPltPosTraList.add(pmSmallPltPosTra);
        });
        return insertPmSmallPltPosTraList;
    }
}

