package com.chinaweal.aiccs.aiccs.system.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chinaweal.aiccs.aiccs.system.entity.TRVerifyCommon;
import com.chinaweal.aiccs.aiccs.system.mapper.TRVerifyCommonMapper;
import com.chinaweal.aiccs.aiccs.system.service.TRVerifyCommonService;
import com.chinaweal.aiccs.common.constant.Constant;
import com.chinaweal.youfool.framework.springboot.mybatis.plus.BaseServiceImpl;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 待办列表 服务实现类
 * </p>
 *
 * @author <a href="https://blog.lroyia.top">lroyia</a>
 * @since 2021-01-22
 */
@Service
public class TRVerifyCommonServiceImpl extends BaseServiceImpl<TRVerifyCommonMapper, TRVerifyCommon> implements TRVerifyCommonService {

    @Resource
    private TRVerifyCommonMapper trVerifyCommonMapper;

    @Override
    public IPage<TRVerifyCommon> searchTRVerifyCommonByPage(Page<TRVerifyCommon> trverifycommon, String primaryKey) {
        return trVerifyCommonMapper.searchTRVerifyCommonByPage(trverifycommon,primaryKey);
    }

    @Override
    public void deletaBycommonId(String commonId) {
        trVerifyCommonMapper.deletaBycommonId(commonId);
    }

    @Override
    public List<TRVerifyCommon> selectWithModule(String userId, String module) {
        List<TRVerifyCommon> list = new ArrayList<>();
        LambdaQueryWrapper<TRVerifyCommon> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(TRVerifyCommon::getUserid,userId)
                .eq(TRVerifyCommon::getDstate, Constant.FALSE_0_STR)
                .eq(TRVerifyCommon::getModule,module)
                .orderByDesc(TRVerifyCommon::getLauptime);
        List<TRVerifyCommon> verifyCommons = list(wrapper);
        if(CollectionUtils.isNotEmpty(verifyCommons)){
            return verifyCommons;
        }
        return list;
    }

    @Override
    public List<TRVerifyCommon> selectWithNoModule(String userId, String module) {
        List<TRVerifyCommon> list = new ArrayList<>();
        LambdaQueryWrapper<TRVerifyCommon> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(TRVerifyCommon::getUserid,userId)
                .eq(TRVerifyCommon::getDstate, Constant.FALSE_0_STR)
                .isNull(TRVerifyCommon::getModule)
                .orderByDesc(TRVerifyCommon::getLauptime);
        List<TRVerifyCommon> verifyCommons = list(wrapper);
        if(CollectionUtils.isNotEmpty(verifyCommons)){
            return verifyCommons;
        }
        return list;
    }
}
