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

import com.xisc.pm.domain.entity.PmPdSlabInfo;
import com.xisc.pm.domain.entity.PmPdSlabInfoTra;
import com.xisc.pm.domain.repository.PmPdSlabInfoTraRepository;
import com.xisc.pm.infra.mapper.PmPdSlabInfoTraMapper;
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;

/**
 * 板坯信息表-履历表(PmPdSlabInfoTra)资源库
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-11-26 11:25:53
 */
@Component
public class PmPdSlabInfoTraRepositoryImpl extends BaseRepositoryImpl<PmPdSlabInfoTra> implements PmPdSlabInfoTraRepository {
    @Resource
    private PmPdSlabInfoTraMapper pmPdSlabInfoTraMapper;

    @Override
    public List<PmPdSlabInfoTra> selectList(PmPdSlabInfoTra pmPdSlabInfoTra) {
        return pmPdSlabInfoTraMapper.selectList(pmPdSlabInfoTra);
    }

    @Override
    public PmPdSlabInfoTra selectByPrimary(Long traId) {
        PmPdSlabInfoTra pmPdSlabInfoTra = new PmPdSlabInfoTra();
        pmPdSlabInfoTra.setTraId(traId);
        List<PmPdSlabInfoTra> pmPdSlabInfoTras = pmPdSlabInfoTraMapper.selectList(pmPdSlabInfoTra);
        if (CollectionUtils.isEmpty(pmPdSlabInfoTras)) {
            return null;
        }
        return pmPdSlabInfoTras.get(0);
    }

    @Override
    public List<PmPdSlabInfoTra> buildPmPdSlabInfoTraList(List<PmPdSlabInfo> pmPdSlabInfoList, String operationType, Date operationTime, String operationUser) {
        List<PmPdSlabInfoTra> insertPmPdSlabInfoTraList = new ArrayList<>();
        pmPdSlabInfoList.forEach(item -> {
            PmPdSlabInfoTra pmPdSlabInfoTra = new PmPdSlabInfoTra();
            BeanUtils.copy(item, pmPdSlabInfoTra);
            pmPdSlabInfoTra.setPmPdSlabInfoTraId(item.getPmPdSlabInfoId());
            pmPdSlabInfoTra.setOperationType(operationType);
            pmPdSlabInfoTra.setOperationTime(operationTime);
            pmPdSlabInfoTra.setOperationUser(operationUser);
            insertPmPdSlabInfoTraList.add(pmPdSlabInfoTra);
        });
        return insertPmPdSlabInfoTraList;
    }
}

