package com.blueland.service.impl;


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

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.TPubUser;
import com.blueland.service.IPubUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.blueland.bo.PubUserEntity;
import com.blueland.bo.RoleUserRest;
import com.blueland.dao.PubUserDao;
import com.google.common.collect.Maps;

@Service
public class PubUserServiceImpl extends ServiceImpl<PubUserDao, TPubUser> implements IPubUserService {
	
	@Autowired
	private PubUserDao pubUserDao;

	/**
	 * 
	 * @param appId
	 * @param roleId
	 * @param companyId
	 * @param deptId
	 * @param orgId
	 * @param curPage
	 * @param curPageSize
	 * @return
	 * @author gaoc
	 */
	@Override
	public Page<RoleUserRest> getAppRoleUser(String appId, String roleId, String companyId, String deptId,
			String orgId, Integer curPage, Integer curPageSize) {
		// TODO Auto-generated method stub
		Map<String, Object> params = Maps.newHashMap();
		Page<RoleUserRest> page = new Page<>(curPage, curPageSize);
		params.put("appId", appId);
		params.put("roleId", roleId);
		params.put("companyId", companyId);
		params.put("deptId", deptId);
		params.put("orgId", orgId);
		Page<RoleUserRest> result = pubUserDao.getAppRoleUserPage(page, params);
		return result;
	}


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

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

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

	private LambdaQueryWrapper<TPubUser> buildQueryWrapper(PubUserEntity bo) {
		LambdaQueryWrapper<TPubUser> lqw = Wrappers.lambdaQuery();
		lqw.eq(ObjectUtil.isNotEmpty(bo.getUserId()), TPubUser::getUserId, bo.getUserId());
		lqw.eq(ObjectUtil.isNotEmpty(bo.getUserCode()), TPubUser::getUserCode, bo.getUserCode());
		lqw.like(ObjectUtil.isNotEmpty(bo.getUserName()), TPubUser::getUserName, bo.getUserName());
		lqw.eq(ObjectUtil.isNotEmpty(bo.getUserSex()), TPubUser::getUserSex, bo.getUserSex());
		lqw.eq(ObjectUtil.isNotEmpty(bo.getUserAge()), TPubUser::getUserAge, bo.getUserAge());
		lqw.eq(ObjectUtil.isNotEmpty(bo.getCompanyId()), TPubUser::getCompanyId, bo.getCompanyId());
		lqw.eq(ObjectUtil.isNotEmpty(bo.getOrgId()), TPubUser::getOrgId, bo.getOrgId());
		lqw.like(ObjectUtil.isNotEmpty(bo.getUserMobile()), TPubUser::getUserMobile, bo.getUserMobile());
		lqw.like(ObjectUtil.isNotEmpty(bo.getUserMail()), TPubUser::getUserMail, bo.getUserMail());
		lqw.like(ObjectUtil.isNotEmpty(bo.getUserHomeAddree()), TPubUser::getUserHomeAddree, bo.getUserHomeAddree());
		lqw.like(ObjectUtil.isNotEmpty(bo.getUserWorkAddress()), TPubUser::getUserWorkAddress, bo.getUserWorkAddress());
		lqw.like(ObjectUtil.isNotEmpty(bo.getUserHomePhone()), TPubUser::getUserHomePhone, bo.getUserHomePhone());
		lqw.like(ObjectUtil.isNotEmpty(bo.getUserWorkPhone()), TPubUser::getUserWorkPhone, bo.getUserWorkPhone());
		lqw.eq(ObjectUtil.isNotEmpty(bo.getPositionId()), TPubUser::getPositionId, bo.getPositionId());
		lqw.eq(ObjectUtil.isNotEmpty(bo.getPluralityPositionId()), TPubUser::getPluralityPositionId, bo.getPluralityPositionId());
		lqw.eq(ObjectUtil.isNotEmpty(bo.getTitleId()), TPubUser::getTitleId, bo.getTitleId());
		lqw.eq(ObjectUtil.isNotEmpty(bo.getPluralityTitleId()), TPubUser::getPluralityTitleId, bo.getPluralityTitleId());
		lqw.eq(ObjectUtil.isNotEmpty(bo.getUserStatus()), TPubUser::getUserStatus, bo.getUserStatus());
		lqw.eq(ObjectUtil.isNotEmpty(bo.getSalt()), TPubUser::getSalt, bo.getSalt());
		lqw.eq(ObjectUtil.isNotEmpty(bo.getPassword()), TPubUser::getPassword, bo.getPassword());
		lqw.eq(ObjectUtil.isNotEmpty(bo.getUserCreator()), TPubUser::getUserCreator, bo.getUserCreator());
		lqw.eq(ObjectUtil.isNotEmpty(bo.getDeptId()), TPubUser::getDeptId, bo.getDeptId());
		lqw.like(ObjectUtil.isNotEmpty(bo.getRemark()), TPubUser::getRemark, bo.getRemark());
		lqw.like(ObjectUtil.isNotEmpty(bo.getDeptName()), TPubUser::getDeptName, bo.getDeptName());
		lqw.like(ObjectUtil.isNotEmpty(bo.getCompanyName()), TPubUser::getCompanyName, bo.getCompanyName());
		lqw.like(ObjectUtil.isNotEmpty(bo.getOrgName()), TPubUser::getOrgName, bo.getOrgName());
		return lqw;
	}

}
