package com.blueland.service.impl;


import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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.bo.AppDatabaseEntity;
import com.blueland.dao.AdminUserDao;
import com.blueland.bo.AdminUserEntity;
import com.blueland.model.TPfAdminUser;
import com.blueland.model.TPfApplicationDb;
import com.blueland.service.IAdminUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

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

@Service
public class AdminUserServiceImpl extends ServiceImpl<AdminUserDao, TPfAdminUser> implements IAdminUserService {
	@Autowired
	//PfAdminUser对应的DAO类,主要用于数据库的增删改查等操作
	private AdminUserDao adminUserDao;
	
	/**
	 * 根据条件查询TagAdminUser列表(不分页)
	 */
	@Override
	public List<AdminUserEntity> findTagAdminUserListByParams(Map<String,Object> tagAdminUser){
		List<AdminUserEntity> result=adminUserDao.findAdminUserListByParams(tagAdminUser);
	   return result;
	};
	
	/**
	 * 通过bizId 删除数据
	 * @param
	 * @return
	 */
	@Override
	@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
	public int batchDeleteByAppId(String[] appIds) {
		if(appIds == null || appIds.length == 0) {
			return 0;
		}
		return adminUserDao.batchDeleteByAppId(appIds);
	}

	@Override
	public AdminUserEntity getByAppidAndUsercode(String appId, String userCode) {
		return adminUserDao.getByAppidAndUsercode(appId, userCode);
	};

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

	private LambdaQueryWrapper<TPfAdminUser> buildQueryWrapper(AdminUserEntity bo) {
		LambdaQueryWrapper<TPfAdminUser> lqw = Wrappers.lambdaQuery();
		lqw.eq(ObjectUtil.isNotEmpty(bo.getId()), TPfAdminUser:: getId, bo.getId());
		lqw.eq(ObjectUtil.isNotEmpty(bo.getAppId()), TPfAdminUser:: getAppId, bo.getAppId());
		lqw.eq(ObjectUtil.isNotEmpty(bo.getAdminType()), TPfAdminUser:: getAdminType, bo.getAdminType());
		lqw.eq(ObjectUtil.isNotEmpty(bo.getUserCode()), TPfAdminUser:: getUserCode, bo.getUserCode());
		lqw.like(ObjectUtil.isNotEmpty(bo.getUserName()), TPfAdminUser:: getUserName, bo.getUserName());
		lqw.eq(ObjectUtil.isNotEmpty(bo.getUserOrgId()), TPfAdminUser:: getUserOrgId, bo.getUserOrgId());
		lqw.like(ObjectUtil.isNotEmpty(bo.getUserOrgName()), TPfAdminUser:: getUserOrgName, bo.getUserOrgName());
		lqw.eq(ObjectUtil.isNotEmpty(bo.getUserDeptId()), TPfAdminUser:: getUserDeptId, bo.getUserDeptId());
		lqw.like(ObjectUtil.isNotEmpty(bo.getUserDeptName()), TPfAdminUser:: getUserDeptName, bo.getUserDeptName());
		return lqw;
	}
	

}
