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

import com.xisc.pm.api.dto.PmProContFilterRequestDTO;
import com.xisc.pm.api.dto.PmProContPoolRequestDTO;
import com.xisc.pm.domain.repository.PmCtMainRepository;
import com.xisc.pm.domain.vo.CtMainVO;
import com.xisc.pm.domain.vo.CtMainVO1;
import com.xisc.pm.domain.vo.QeTjWitnessProOrderVO;
import com.xisc.pm.infra.constant.Constants.StatusCode;
import com.xisc.pm.infra.mapper.CtMainMapper;
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.List;

/**
 * 合同跟踪主表(CtMain)资源库
 *
 * @author 蒋雨航 yuhang.jiang02@hand-china.com
 * @since 2024-08-14 15:46:42
 */
@Component
public class PmCtMainRepositoryImpl extends BaseRepositoryImpl<CtMainVO1> implements PmCtMainRepository {
    @Resource
    private CtMainMapper ctMainMapper;

    @Override
    public List<CtMainVO1> selectList(CtMainVO1 ctMain) {
        return ctMainMapper.selectList(ctMain);
    }

    @Override
    public CtMainVO1 selectByPrimary(Long mainId) {
        CtMainVO1 ctMain = new CtMainVO1();
        ctMain.setMainId(mainId);
        List<CtMainVO1> ctMains = ctMainMapper.selectList(ctMain);
        if (CollectionUtils.isEmpty(ctMains)) {
            return null;
        }
        return ctMains.get(0);
    }

    @Override
    public List<String> selectPdReleRaseByCtMain(PmProContPoolRequestDTO request) {
        return ctMainMapper.selectByCtMain(request, StatusCode.STATUS_CODE_38, null, null);
    }

    @Override
    public List<com.xisc.pm.domain.vo.CtMainVO> selectCtMainByOrderList(List<String> orderNoList, Long tenantId) {
        return ctMainMapper.selectCtMainByOrderList(tenantId, orderNoList);
    }

    @Override
    public List<String> selectCanPdByCtMain(PmProContFilterRequestDTO pmProContFilterRequest) {
        PmProContPoolRequestDTO pmProContPoolRequestDTO = BeanUtils.copy(pmProContFilterRequest,
                PmProContPoolRequestDTO.class);
        return ctMainMapper.selectByCtMain(pmProContPoolRequestDTO, null, StatusCode.STATUS_CODE_40,
                StatusCode.STATUS_CODE_66);
    }

    @Override
    public List<CtMainVO> selectCanPdByOrderStatus(PmProContFilterRequestDTO pmProContFilterRequest) {
        if(pmProContFilterRequest.getOrderNoList() != null && pmProContFilterRequest.getOrderNoList().isEmpty()) {
            return new ArrayList<CtMainVO>();
        }
        return ctMainMapper.selectCanPdByOrderStatus(pmProContFilterRequest);
    }

    @Override
    public  List<QeTjWitnessProOrderVO>  queryQdWitnessProNo(List<String> allOrderNoList, Long tenantId) {
       return ctMainMapper.queryQdWitnessProNo(allOrderNoList, tenantId);
    }
}
