package com.ruoyi.ehsDocTransfer.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import com.ruoyi.common.utils.StringUtils;

import java.util.List;
import java.util.Map;

import com.ruoyi.ehsDocTransfer.mapper.EhsDocTransferMapper;
import com.ruoyi.ehsDocTransfer.domain.EhsDocTransfer;
import com.ruoyi.ehsDocTransfer.service.IEhsDocTransferService;

/**
 * 公文流转Service业务层处理
 *
 * @author ruoyi
 * @date 2023-12-07
 */
@Service
public class EhsDocTransferServiceImpl extends ServiceImpl<EhsDocTransferMapper, EhsDocTransfer> implements IEhsDocTransferService {

    @Autowired
    private EhsDocTransferMapper ehsDocTransferMapper;

    /**
     * 查询公文流转
     *
     * @param id 公文流转主键
     * @return 公文流转
     */
    @Override
    public EhsDocTransfer selectEhsDocTransferById(Long id) {
        return ehsDocTransferMapper.selectEhsDocTransferById(id);
    }

    /**
     * 查询公文流转列表
     *
     * @param ehsDocTransfer 公文流转
     * @return 公文流转
     */
    @Override
    public List<EhsDocTransfer> selectEhsDocTransferList(EhsDocTransfer ehsDocTransfer) {
        return ehsDocTransferMapper.selectEhsDocTransferList(ehsDocTransfer);
    }

    /**
     * 根据公文id获取公文流转信息
     */
    @Override
    public List<EhsDocTransfer> getTransferInfoByDocId(Long id) {
        return ehsDocTransferMapper.getTransferInfoByDocId(id);
    }

    /**
     * 删除公文同时,删除该公文的流转记录
     * @param documentIds
     * @return
     */
    @Override
    public boolean removeByDocumentIds(List<Long> documentIds) {

        return ehsDocTransferMapper.removeByDocumentIds(documentIds);
    }


    private LambdaQueryWrapper<EhsDocTransfer> buildQueryWrapper(EhsDocTransfer query) {
        Map<String, Object> params = query.getParams();
        LambdaQueryWrapper<EhsDocTransfer> lqw = Wrappers.lambdaQuery();
        lqw.like(StringUtils.isNotBlank(query.getTransferName()), EhsDocTransfer::getTransferName, query.getTransferName());
        lqw.eq(query.getTransferTime() != null, EhsDocTransfer::getTransferTime, query.getTransferTime());
        lqw.eq(query.getDocTransferStatus() != null, EhsDocTransfer::getDocTransferStatus, query.getDocTransferStatus());
        lqw.eq(query.getDocumentId() != null, EhsDocTransfer::getDocumentId, query.getDocumentId());
        lqw.orderByDesc(EhsDocTransfer::getCreateTime);
        return lqw;
    }

}
