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

import com.xisc.pm.domain.entity.PmPdCcSlab;
import com.xisc.pm.domain.entity.PmPdCcSlabTra;
import com.xisc.pm.domain.repository.PmPdCcSlabTraRepository;
import com.xisc.pm.infra.mapper.PmPdCcSlabTraMapper;
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;

/**
 * 组板连铸板坯表-履历表(PmPdCcSlabTra)资源库
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-11-26 10:45:01
 */
@Component
public class PmPdCcSlabTraRepositoryImpl extends BaseRepositoryImpl<PmPdCcSlabTra> implements PmPdCcSlabTraRepository {
    @Resource
    private PmPdCcSlabTraMapper pmPdCcSlabTraMapper;

    @Override
    public List<PmPdCcSlabTra> selectList(PmPdCcSlabTra pmPdCcSlabTra) {
        return pmPdCcSlabTraMapper.selectList(pmPdCcSlabTra);
    }

    @Override
    public PmPdCcSlabTra selectByPrimary(Long traId) {
        PmPdCcSlabTra pmPdCcSlabTra = new PmPdCcSlabTra();
        pmPdCcSlabTra.setTraId(traId);
        List<PmPdCcSlabTra> pmPdCcSlabTras = pmPdCcSlabTraMapper.selectList(pmPdCcSlabTra);
        if (CollectionUtils.isEmpty(pmPdCcSlabTras)) {
            return null;
        }
        return pmPdCcSlabTras.get(0);
    }

    @Override
    public List<PmPdCcSlabTra> PmPdCcSlabTraList(List<PmPdCcSlab> pmPdCcSlabList, String operationType, Date operationTime, String operationUser) {
        List<PmPdCcSlabTra> insertPmPdCcSlabTraList = new ArrayList<>();
        pmPdCcSlabList.forEach(item -> {
            PmPdCcSlabTra pmPdCcSlabTra = new PmPdCcSlabTra();
            BeanUtils.copy(item, pmPdCcSlabTra);
            pmPdCcSlabTra.setOperationType(operationType);
            pmPdCcSlabTra.setOperationTime(operationTime);
            pmPdCcSlabTra.setOperationUser(operationUser);
            insertPmPdCcSlabTraList.add(pmPdCcSlabTra);
        });
        return insertPmPdCcSlabTraList;
    }
}

