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

import com.xisc.pm.domain.entity.PmPdSlab;
import com.xisc.pm.domain.entity.PmPdSlabTra;
import com.xisc.pm.domain.repository.PmPdSlabTraRepository;
import com.xisc.pm.infra.mapper.PmPdSlabTraMapper;
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;

/**
 * 组板板坯表-履历表(PmPdSlabTra)资源库
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-11-26 11:12:46
 */
@Component
public class PmPdSlabTraRepositoryImpl extends BaseRepositoryImpl<PmPdSlabTra> implements PmPdSlabTraRepository {
    @Resource
    private PmPdSlabTraMapper pmPdSlabTraMapper;

    @Override
    public List<PmPdSlabTra> selectList(PmPdSlabTra pmPdSlabTra) {
        return pmPdSlabTraMapper.selectList(pmPdSlabTra);
    }

    @Override
    public PmPdSlabTra selectByPrimary(Long traId) {
        PmPdSlabTra pmPdSlabTra = new PmPdSlabTra();
        pmPdSlabTra.setTraId(traId);
        List<PmPdSlabTra> pmPdSlabTras = pmPdSlabTraMapper.selectList(pmPdSlabTra);
        if (CollectionUtils.isEmpty(pmPdSlabTras)) {
            return null;
        }
        return pmPdSlabTras.get(0);
    }

    @Override
    public List<PmPdSlabTra> buildPmPdSlabTraList(List<PmPdSlab> pmPdSlabList, String operationType, Date operationTime, String operationUser) {
        List<PmPdSlabTra> insertPmPdSlabTraList = new ArrayList<>();
        pmPdSlabList.forEach(item -> {
            PmPdSlabTra pmPdSlabTra = new PmPdSlabTra();
            BeanUtils.copy(item, pmPdSlabTra);
            pmPdSlabTra.setPmPdSlabTraId(item.getPmPdSlabId());
            pmPdSlabTra.setOperationType(operationType);
            pmPdSlabTra.setOperationTime(operationTime);
            pmPdSlabTra.setOperationUser(operationUser);
            insertPmPdSlabTraList.add(pmPdSlabTra);
        });
        return insertPmPdSlabTraList;
    }

}

