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

import com.xisc.pm.domain.entity.PmCmdLargePlt;
import com.xisc.pm.domain.entity.PmCmdLargePltTra;
import com.xisc.pm.domain.repository.PmCmdLargePltTraRepository;
import com.xisc.pm.infra.mapper.PmCmdLargePltTraMapper;
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;

/**
 * 命令大板表(PmCmdLargePltTra)资源库
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-11-28 17:20:33
 */
@Component
public class PmCmdLargePltTraRepositoryImpl extends BaseRepositoryImpl<PmCmdLargePltTra> implements PmCmdLargePltTraRepository {
    @Resource
    private PmCmdLargePltTraMapper pmCmdLargePltTraMapper;

    @Override
    public List<PmCmdLargePltTra> selectList(PmCmdLargePltTra pmCmdLargePltTra) {
        return pmCmdLargePltTraMapper.selectList(pmCmdLargePltTra);
    }

    @Override
    public PmCmdLargePltTra selectByPrimary(Long traId) {
        PmCmdLargePltTra pmCmdLargePltTra = new PmCmdLargePltTra();
        pmCmdLargePltTra.setTraId(traId);
        List<PmCmdLargePltTra> pmCmdLargePltTras = pmCmdLargePltTraMapper.selectList(pmCmdLargePltTra);
        if (CollectionUtils.isEmpty(pmCmdLargePltTras)) {
            return null;
        }
        return pmCmdLargePltTras.get(0);
    }

    @Override
    public List<PmCmdLargePltTra> buildPmCmdLargePltTraList(List<PmCmdLargePlt> pmCmdLargePltList, String operationType, Date operationTime, String operationUser) {
        List<PmCmdLargePltTra> insertPmCmdLargePltTraList = new ArrayList<>();
        if (CollectionUtils.isEmpty(pmCmdLargePltList)) {
            return insertPmCmdLargePltTraList;
        }
        pmCmdLargePltList.forEach(item -> {
            PmCmdLargePltTra pmCmdLargePltTra = new PmCmdLargePltTra();
            BeanUtils.copy(item, pmCmdLargePltTra);
            pmCmdLargePltTra.setPmCmdLargePltId(item.getPmCmdLargePltId());
            pmCmdLargePltTra.setOperationType(operationType);
            pmCmdLargePltTra.setOperationTime(operationTime);
            pmCmdLargePltTra.setOperationUser(operationUser);
            insertPmCmdLargePltTraList.add(pmCmdLargePltTra);
        });
        return insertPmCmdLargePltTraList;
    }

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

