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

import com.xisc.pm.domain.entity.PmCmdSlab;
import com.xisc.pm.domain.entity.PmCmdSlabTra;
import com.xisc.pm.domain.repository.PmCmdSlabTraRepository;
import com.xisc.pm.infra.mapper.PmCmdSlabTraMapper;
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;

/**
 * 命令板坯表(PmCmdSlabTra)资源库
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-11-28 17:19:49
 */
@Component
public class PmCmdSlabTraRepositoryImpl extends BaseRepositoryImpl<PmCmdSlabTra> implements PmCmdSlabTraRepository {
    @Resource
    private PmCmdSlabTraMapper pmCmdSlabTraMapper;

    @Override
    public List<PmCmdSlabTra> selectList(PmCmdSlabTra pmCmdSlabTra) {
        return pmCmdSlabTraMapper.selectList(pmCmdSlabTra);
    }

    @Override
    public PmCmdSlabTra selectByPrimary(Long traId) {
        PmCmdSlabTra pmCmdSlabTra = new PmCmdSlabTra();
        pmCmdSlabTra.setTraId(traId);
        List<PmCmdSlabTra> pmCmdSlabTras = pmCmdSlabTraMapper.selectList(pmCmdSlabTra);
        if (CollectionUtils.isEmpty(pmCmdSlabTras)) {
            return null;
        }
        return pmCmdSlabTras.get(0);
    }

    @Override
    public List<PmCmdSlabTra> buildPmCmdSlabTraList(List<PmCmdSlab> pmCmdSlabList, String operationType, Date operationTime, String operationUser) {
        List<PmCmdSlabTra> insertPmCmdSlabTraList = new ArrayList<>();
        if (CollectionUtils.isEmpty(pmCmdSlabList)) {
            return insertPmCmdSlabTraList;
        }
        pmCmdSlabList.forEach(item -> {
            PmCmdSlabTra pmCmdSlabTra = new PmCmdSlabTra();
            BeanUtils.copy(item, pmCmdSlabTra);
            pmCmdSlabTra.setPmCmdSlabId(item.getPmCmdSlabId());
            pmCmdSlabTra.setOperationType(operationType);
            pmCmdSlabTra.setOperationTime(operationTime);
            pmCmdSlabTra.setOperationUser(operationUser);
            insertPmCmdSlabTraList.add(pmCmdSlabTra);
        });
        return insertPmCmdSlabTraList;
    }
}

