package com.blueland.service.impl;


import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.blueland.model.TPfModule;
import com.blueland.service.IModuleService;
import org.springframework.stereotype.Service;

import com.blueland.bo.ModuleEntity;
import com.blueland.dao.ModuleDao;

import java.util.List;

@Service
public class ModuleServiceImpl extends ServiceImpl<ModuleDao, TPfModule> implements IModuleService {

	@Override
	public Page<ModuleEntity> findPage(ModuleEntity bo){
		Page<ModuleEntity> page = new Page(bo.getPageNum(), bo.getPageSize());
		return this.baseMapper.findPage(page, bo);
	}

	@Override
	public List<ModuleEntity> findList(ModuleEntity bo) {
		return this.baseMapper.findList(bo);
	}

	@Override
	public TPfModule get(ModuleEntity bo){
		return this.baseMapper.selectOne(buildQueryWrapper(bo));
	}

	private LambdaQueryWrapper<TPfModule> buildQueryWrapper(ModuleEntity bo) {
		LambdaQueryWrapper<TPfModule> lqw = Wrappers.lambdaQuery();
		lqw.eq(ObjectUtil.isNotEmpty(bo.getModuleId()), TPfModule::getModuleId, bo.getModuleId());
		lqw.eq(ObjectUtil.isNotEmpty(bo.getCode()), TPfModule::getCode, bo.getCode());
		lqw.like(ObjectUtil.isNotEmpty(bo.getName()), TPfModule::getName, bo.getName());
		lqw.eq(ObjectUtil.isNotEmpty(bo.getAppId()), TPfModule::getAppId, bo.getAppId());
		lqw.like(ObjectUtil.isNotEmpty(bo.getAppName()), TPfModule::getAppName, bo.getAppName());
		lqw.eq(ObjectUtil.isNotEmpty(bo.getAccessUrl()), TPfModule::getAccessUrl, bo.getAccessUrl());
		lqw.eq(ObjectUtil.isNotEmpty(bo.getMenuSys()), TPfModule::getMenuSys, bo.getMenuSys());
		lqw.eq(ObjectUtil.isNotEmpty(bo.getParentId()), TPfModule::getParentId, bo.getParentId());
		lqw.like(ObjectUtil.isNotEmpty(bo.getParentName()), TPfModule::getParentName, bo.getParentName());
		lqw.eq(ObjectUtil.isNotEmpty(bo.getHierarchy()), TPfModule::getHierarchy, bo.getHierarchy());
		lqw.eq(ObjectUtil.isNotEmpty(bo.getStatus()), TPfModule::getStatus, bo.getStatus());
		lqw.like(ObjectUtil.isNotEmpty(bo.getRemark()), TPfModule::getRemark, bo.getRemark());
		lqw.eq(ObjectUtil.isNotEmpty(bo.getCreateUserId()), TPfModule::getCreateUserId, bo.getCreateUserId());
		lqw.like(ObjectUtil.isNotEmpty(bo.getCreateUserName()), TPfModule::getCreateUserName, bo.getCreateUserName());
		lqw.eq(ObjectUtil.isNotEmpty(bo.getUpdateUserId()), TPfModule::getUpdateUserId, bo.getUpdateUserId());
		lqw.like(ObjectUtil.isNotEmpty(bo.getUpdateUserName()), TPfModule::getUpdateUserName, bo.getUpdateUserName());
		return lqw;
	}
}
