package com.centreproject.system.service.sync.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.centreproject.system.domain.sync.kpi.SyncRule;
import com.centreproject.system.mapper.sync.kpi.SyncRuleMapper;
import com.centreproject.system.service.sync.ISyncRuleService;
import org.springframework.stereotype.Service;

/**
 * @author lenovo
 */
@Service
public class SyncRuleServiceImpl extends ServiceImpl<SyncRuleMapper, SyncRule>
        implements ISyncRuleService {

    @Override
    public Page<SyncRule> getPage(SyncRule syncRule, int pageNum, int pageSize) {
        return this.baseMapper.selectPage(new Page<>(pageNum, pageSize),
                new LambdaQueryWrapper<SyncRule>()
                        .like( syncRule.getRuleType()!= null, SyncRule::getRuleType, syncRule.getRuleType())
                        .like( syncRule.getModuleName()!= null, SyncRule::getModuleName, syncRule.getModuleName())
                        .like( syncRule.getFieldName()!= null, SyncRule::getFieldName, syncRule.getFieldName())
                        .eq( syncRule.getStatus()!= null, SyncRule::getStatus, syncRule.getStatus())
                        .orderByDesc(SyncRule::getCreateTime));
    }
}
