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

import com.xisc.pm.domain.entity.PmCmdCont;
import com.xisc.pm.domain.entity.PmCmdContTra;
import com.xisc.pm.domain.repository.PmCmdContTraRepository;
import com.xisc.pm.infra.mapper.PmCmdContTraMapper;
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;

/**
 * 命令参数表(PmCmdContTra)资源库
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-11-28 17:20:51
 */
@Component
public class PmCmdContTraRepositoryImpl extends BaseRepositoryImpl<PmCmdContTra> implements PmCmdContTraRepository {
    @Resource
    private PmCmdContTraMapper pmCmdContTraMapper;

    @Override
    public List<PmCmdContTra> selectList(PmCmdContTra pmCmdContTra) {
        return pmCmdContTraMapper.selectList(pmCmdContTra);
    }

    @Override
    public PmCmdContTra selectByPrimary(Long traId) {
        PmCmdContTra pmCmdContTra = new PmCmdContTra();
        pmCmdContTra.setTraId(traId);
        List<PmCmdContTra> pmCmdContTras = pmCmdContTraMapper.selectList(pmCmdContTra);
        if (CollectionUtils.isEmpty(pmCmdContTras)) {
            return null;
        }
        return pmCmdContTras.get(0);
    }

    @Override
    public List<PmCmdContTra> buildPmCmdContTraList(List<PmCmdCont> pmCmdContList, String operationType, Date operationTime, String operationUser) {
        List<PmCmdContTra> insertPmCmdContTraList = new ArrayList<>();
        if (CollectionUtils.isEmpty(pmCmdContList)) {
            return insertPmCmdContTraList;
        }
        pmCmdContList.forEach(item -> {
            PmCmdContTra pmCmdContTra = new PmCmdContTra();
            BeanUtils.copy(item, pmCmdContTra);
            pmCmdContTra.setPmCmdContId(item.getPmCmdContId());
            pmCmdContTra.setOperationType(operationType);
            pmCmdContTra.setOperationTime(operationTime);
            pmCmdContTra.setOperationUser(operationUser);
            insertPmCmdContTraList.add(pmCmdContTra);
        });
        return insertPmCmdContTraList;
    }

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

