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

import com.xisc.pm.domain.entity.PmCmdSmallPlt;
import com.xisc.pm.domain.entity.PmCmdSmallPltTra;
import com.xisc.pm.domain.repository.PmCmdSmallPltTraRepository;
import com.xisc.pm.infra.mapper.PmCmdSmallPltTraMapper;
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;

/**
 * 命令小板表(PmCmdSmallPltTra)资源库
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-11-28 17:20:09
 */
@Component
public class PmCmdSmallPltTraRepositoryImpl extends BaseRepositoryImpl<PmCmdSmallPltTra> implements PmCmdSmallPltTraRepository {
    @Resource
    private PmCmdSmallPltTraMapper pmCmdSmallPltTraMapper;

    @Override
    public List<PmCmdSmallPltTra> selectList(PmCmdSmallPltTra pmCmdSmallPltTra) {
        return pmCmdSmallPltTraMapper.selectList(pmCmdSmallPltTra);
    }

    @Override
    public PmCmdSmallPltTra selectByPrimary(Long traId) {
        PmCmdSmallPltTra pmCmdSmallPltTra = new PmCmdSmallPltTra();
        pmCmdSmallPltTra.setTraId(traId);
        List<PmCmdSmallPltTra> pmCmdSmallPltTras = pmCmdSmallPltTraMapper.selectList(pmCmdSmallPltTra);
        if (CollectionUtils.isEmpty(pmCmdSmallPltTras)) {
            return null;
        }
        return pmCmdSmallPltTras.get(0);
    }

    @Override
    public List<PmCmdSmallPltTra> buildPmCmdSmallPltTraList(List<PmCmdSmallPlt> pmCmdSmallPltList, String operationType, Date operationTime, String operationUser) {
        List<PmCmdSmallPltTra> insertPmCmdSmallPltTraList = new ArrayList<>();
        if (CollectionUtils.isEmpty(pmCmdSmallPltList)) {
            return insertPmCmdSmallPltTraList;
        }
        pmCmdSmallPltList.forEach(item -> {
            PmCmdSmallPltTra pmCmdSmallPltTra = new PmCmdSmallPltTra();
            BeanUtils.copy(item, pmCmdSmallPltTra);
            pmCmdSmallPltTra.setPmCmdSmallPltId(item.getPmCmdSmallPltId());
            pmCmdSmallPltTra.setOperationType(operationType);
            pmCmdSmallPltTra.setOperationTime(operationTime);
            pmCmdSmallPltTra.setOperationUser(operationUser);
            insertPmCmdSmallPltTraList.add(pmCmdSmallPltTra);
        });
        return insertPmCmdSmallPltTraList;
    }

    @Override
    public List<PmCmdSmallPltTra> selectByPonoSlabList(List<String> ponoSlabList, Long tenantId) {
        return pmCmdSmallPltTraMapper.selectByPonoSlabList(ponoSlabList, tenantId);
    }
}

